summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipe Manana <fdmanana@suse.com>2026-06-05 19:07:08 +0300
committerJohannes Thumshirn <johannes.thumshirn@wdc.com>2026-06-09 19:22:47 +0300
commitf51228e1bac7082ba016010c7c9eff41ccd4169d (patch)
tree456c98b02413e0ee33fb20085e9621962ec18d1c
parentb0d27d43791b7a3057c3c4aedf9b4aa033d37c46 (diff)
downloadlinux-f51228e1bac7082ba016010c7c9eff41ccd4169d.tar.xz
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>
-rw-r--r--fs/btrfs/inode.c2
-rw-r--r--fs/btrfs/relocation.c7
-rw-r--r--fs/btrfs/relocation.h2
3 files changed, 5 insertions, 6 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 0133b688ce04..16f097f58acc 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -226,9 +226,7 @@ static void print_data_reloc_error(const struct btrfs_inode *inode, u64 file_off
u32 item_size;
int ret;
- mutex_lock(&fs_info->reloc_mutex);
logical = btrfs_get_reloc_bg_bytenr(fs_info);
- mutex_unlock(&fs_info->reloc_mutex);
if (logical == U64_MAX) {
btrfs_warn_rl(fs_info, "has data reloc tree but no running relocation");
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 80aac9fcd627..e7771c4c4f38 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -5863,14 +5863,15 @@ int btrfs_reloc_post_snapshot(struct btrfs_trans_handle *trans,
*
* Return U64_MAX if no running relocation.
*/
-u64 btrfs_get_reloc_bg_bytenr(const struct btrfs_fs_info *fs_info)
+u64 btrfs_get_reloc_bg_bytenr(struct btrfs_fs_info *fs_info)
{
u64 logical = U64_MAX;
- lockdep_assert_held(&fs_info->reloc_mutex);
-
+ mutex_lock(&fs_info->reloc_mutex);
if (fs_info->reloc_ctl && fs_info->reloc_ctl->block_group)
logical = fs_info->reloc_ctl->block_group->start;
+ mutex_unlock(&fs_info->reloc_mutex);
+
return logical;
}
diff --git a/fs/btrfs/relocation.h b/fs/btrfs/relocation.h
index d647823b5d13..bb7a86e7dbe3 100644
--- a/fs/btrfs/relocation.h
+++ b/fs/btrfs/relocation.h
@@ -41,7 +41,7 @@ int btrfs_reloc_post_snapshot(struct btrfs_trans_handle *trans,
int btrfs_should_cancel_balance(const struct btrfs_fs_info *fs_info);
struct btrfs_root *find_reloc_root(struct btrfs_fs_info *fs_info, u64 bytenr);
bool btrfs_should_ignore_reloc_root(const struct btrfs_root *root);
-u64 btrfs_get_reloc_bg_bytenr(const struct btrfs_fs_info *fs_info);
+u64 btrfs_get_reloc_bg_bytenr(struct btrfs_fs_info *fs_info);
int btrfs_translate_remap(struct btrfs_fs_info *fs_info, u64 *logical, u64 *length);
int btrfs_remove_extent_from_remap_tree(struct btrfs_trans_handle *trans,
struct btrfs_path *path,