Commit 4e4488d4 authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba

btrfs: assert commit root semaphore is held when accessing backref cache

During fiemap, when accessing the cache that stores the sharedness of an
extent, we need to either be holding a transaction handle or the commit
root semaphore. I left comments about this in the comment that precedes
store_backref_shared_cache() and lookup_backref_shared_cache(), but have
actually not enforced it through assertions. So assert that the commit
root semaphore is held if we are not holding a transaction handle.
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 2b5463fc
...@@ -1252,8 +1252,12 @@ static bool lookup_backref_shared_cache(struct btrfs_backref_share_check_ctx *ct ...@@ -1252,8 +1252,12 @@ static bool lookup_backref_shared_cache(struct btrfs_backref_share_check_ctx *ct
struct btrfs_root *root, struct btrfs_root *root,
u64 bytenr, int level, bool *is_shared) u64 bytenr, int level, bool *is_shared)
{ {
const struct btrfs_fs_info *fs_info = root->fs_info;
struct btrfs_backref_shared_cache_entry *entry; struct btrfs_backref_shared_cache_entry *entry;
if (!current->journal_info)
lockdep_assert_held(&fs_info->commit_root_sem);
if (!ctx->use_path_cache) if (!ctx->use_path_cache)
return false; return false;
...@@ -1288,7 +1292,7 @@ static bool lookup_backref_shared_cache(struct btrfs_backref_share_check_ctx *ct ...@@ -1288,7 +1292,7 @@ static bool lookup_backref_shared_cache(struct btrfs_backref_share_check_ctx *ct
* could be a snapshot sharing this extent buffer. * could be a snapshot sharing this extent buffer.
*/ */
if (entry->is_shared && if (entry->is_shared &&
entry->gen != btrfs_get_last_root_drop_gen(root->fs_info)) entry->gen != btrfs_get_last_root_drop_gen(fs_info))
return false; return false;
*is_shared = entry->is_shared; *is_shared = entry->is_shared;
...@@ -1318,9 +1322,13 @@ static void store_backref_shared_cache(struct btrfs_backref_share_check_ctx *ctx ...@@ -1318,9 +1322,13 @@ static void store_backref_shared_cache(struct btrfs_backref_share_check_ctx *ctx
struct btrfs_root *root, struct btrfs_root *root,
u64 bytenr, int level, bool is_shared) u64 bytenr, int level, bool is_shared)
{ {
const struct btrfs_fs_info *fs_info = root->fs_info;
struct btrfs_backref_shared_cache_entry *entry; struct btrfs_backref_shared_cache_entry *entry;
u64 gen; u64 gen;
if (!current->journal_info)
lockdep_assert_held(&fs_info->commit_root_sem);
if (!ctx->use_path_cache) if (!ctx->use_path_cache)
return; return;
...@@ -1336,7 +1344,7 @@ static void store_backref_shared_cache(struct btrfs_backref_share_check_ctx *ctx ...@@ -1336,7 +1344,7 @@ static void store_backref_shared_cache(struct btrfs_backref_share_check_ctx *ctx
ASSERT(level >= 0); ASSERT(level >= 0);
if (is_shared) if (is_shared)
gen = btrfs_get_last_root_drop_gen(root->fs_info); gen = btrfs_get_last_root_drop_gen(fs_info);
else else
gen = btrfs_root_last_snapshot(&root->root_item); gen = btrfs_root_last_snapshot(&root->root_item);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment