Skip to content

Commit a5e3d0b

Browse files
committed
btrfs: use super write guard in btrfs_reclaim_bgs_work()
Link: https://patch.msgid.link/20251104-work-guards-v1-2-5108ac78a171@kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 8e4d576 commit a5e3d0b

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

fs/btrfs/block-group.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,20 +1850,17 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
18501850
if (!btrfs_should_reclaim(fs_info))
18511851
return;
18521852

1853-
sb_start_write(fs_info->sb);
1853+
guard(super_write)(fs_info->sb);
18541854

1855-
if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_BALANCE)) {
1856-
sb_end_write(fs_info->sb);
1855+
if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_BALANCE))
18571856
return;
1858-
}
18591857

18601858
/*
18611859
* Long running balances can keep us blocked here for eternity, so
18621860
* simply skip reclaim if we're unable to get the mutex.
18631861
*/
18641862
if (!mutex_trylock(&fs_info->reclaim_bgs_lock)) {
18651863
btrfs_exclop_finish(fs_info);
1866-
sb_end_write(fs_info->sb);
18671864
return;
18681865
}
18691866

@@ -1947,7 +1944,7 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
19471944
/*
19481945
* Get out fast, in case we're read-only or unmounting the
19491946
* filesystem. It is OK to drop block groups from the list even
1950-
* for the read-only case. As we did sb_start_write(),
1947+
* for the read-only case. As we did take the super write lock,
19511948
* "mount -o remount,ro" won't happen and read-only filesystem
19521949
* means it is forced read-only due to a fatal error. So, it
19531950
* never gets back to read-write to let us reclaim again.
@@ -2030,7 +2027,6 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
20302027
list_splice_tail(&retry_list, &fs_info->reclaim_bgs);
20312028
spin_unlock(&fs_info->unused_bgs_lock);
20322029
btrfs_exclop_finish(fs_info);
2033-
sb_end_write(fs_info->sb);
20342030
}
20352031

20362032
void btrfs_reclaim_bgs(struct btrfs_fs_info *fs_info)

0 commit comments

Comments
 (0)