Skip to content

Commit f51228e

Browse files
fdmananamorbidrsa
authored andcommitted
btrfs: move locking into btrfs_get_reloc_bg_bytenr()
It does not make sense for the single caller to have the responsability to lock the relocation mutex before calling the function and then have the function to assert the lock is held. As this is a function in relocation.c, move the locking details into it. Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent b0d27d4 commit f51228e

3 files changed

Lines changed: 5 additions & 6 deletions

File tree

fs/btrfs/inode.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,7 @@ static void print_data_reloc_error(const struct btrfs_inode *inode, u64 file_off
226226
u32 item_size;
227227
int ret;
228228

229-
mutex_lock(&fs_info->reloc_mutex);
230229
logical = btrfs_get_reloc_bg_bytenr(fs_info);
231-
mutex_unlock(&fs_info->reloc_mutex);
232230

233231
if (logical == U64_MAX) {
234232
btrfs_warn_rl(fs_info, "has data reloc tree but no running relocation");

fs/btrfs/relocation.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5863,14 +5863,15 @@ int btrfs_reloc_post_snapshot(struct btrfs_trans_handle *trans,
58635863
*
58645864
* Return U64_MAX if no running relocation.
58655865
*/
5866-
u64 btrfs_get_reloc_bg_bytenr(const struct btrfs_fs_info *fs_info)
5866+
u64 btrfs_get_reloc_bg_bytenr(struct btrfs_fs_info *fs_info)
58675867
{
58685868
u64 logical = U64_MAX;
58695869

5870-
lockdep_assert_held(&fs_info->reloc_mutex);
5871-
5870+
mutex_lock(&fs_info->reloc_mutex);
58725871
if (fs_info->reloc_ctl && fs_info->reloc_ctl->block_group)
58735872
logical = fs_info->reloc_ctl->block_group->start;
5873+
mutex_unlock(&fs_info->reloc_mutex);
5874+
58745875
return logical;
58755876
}
58765877

fs/btrfs/relocation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int btrfs_reloc_post_snapshot(struct btrfs_trans_handle *trans,
4141
int btrfs_should_cancel_balance(const struct btrfs_fs_info *fs_info);
4242
struct btrfs_root *find_reloc_root(struct btrfs_fs_info *fs_info, u64 bytenr);
4343
bool btrfs_should_ignore_reloc_root(const struct btrfs_root *root);
44-
u64 btrfs_get_reloc_bg_bytenr(const struct btrfs_fs_info *fs_info);
44+
u64 btrfs_get_reloc_bg_bytenr(struct btrfs_fs_info *fs_info);
4545
int btrfs_translate_remap(struct btrfs_fs_info *fs_info, u64 *logical, u64 *length);
4646
int btrfs_remove_extent_from_remap_tree(struct btrfs_trans_handle *trans,
4747
struct btrfs_path *path,

0 commit comments

Comments
 (0)