btrfs: assert tree lock is held when linking free space
authorFilipe Manana <fdmanana@suse.com>
Thu, 4 May 2023 11:04:25 +0000 (12:04 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 19 Jun 2023 11:59:24 +0000 (13:59 +0200)
commit9649bd9a29a7da97eca456befd275ee16e3a2291
treedf7b5e0cc74b6e783a71956003e2b0165f814bd8
parent91de9e978d1c32c477e14f44a7e945f17863c66e
btrfs: assert tree lock is held when linking free space

When linking a free space entry, at link_free_space(), the caller should
be holding the spinlock 'tree_lock' of the given btrfs_free_space_ctl
argument, which is necessary for manipulating the red black tree of free
space entries (done by tree_insert_offset(), which already asserts the
lock is held) and for manipulating the 'free_space', 'free_extents',
'discardable_extents' and 'discardable_bytes' counters of the given
struct btrfs_free_space_ctl.

So assert that the spinlock 'tree_lock' of the given btrfs_free_space_ctl
is held by the current task. We have multiple code paths that end up
calling link_free_space(), and all currently take the lock before calling
it.

Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/free-space-cache.c