On Wed, Oct 30, 2019 at 11:57:06AM +0100, David Sterba wrote:
> Add assertions to locking functions where the we expect the lock to be
> held. This must also respect the nesting, so write lock checks 'write'
> while read lock only if the lock is held.
>
> Signed-off-by: David Sterba <dsterba@xxxxxxxx>
> ---
> fs/btrfs/locking.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/fs/btrfs/locking.c b/fs/btrfs/locking.c
> index 571c4826c428..147bf5d41962 100644
> --- a/fs/btrfs/locking.c
> +++ b/fs/btrfs/locking.c
> @@ -195,6 +195,7 @@ static void btrfs_assert_tree_write_locks_put(struct extent_buffer *eb) { }
> */
> void btrfs_set_lock_blocking_read(struct extent_buffer *eb)
> {
> + lockdep_assert_held(&eb->lock);
> trace_btrfs_set_lock_blocking_read(eb);
> /*
> * No lock is required. The lock owner may change if we have a read
> @@ -219,6 +220,7 @@ void btrfs_set_lock_blocking_read(struct extent_buffer *eb)
> */
> void btrfs_set_lock_blocking_write(struct extent_buffer *eb)
> {
> + lockdep_assert_held_write(&eb->lock);
This is "a bit noisy" during the self-tests, I'll have to investigate
why so this patch is on hold.
> trace_btrfs_set_lock_blocking_write(eb);
> /*
> * No lock is required. The lock owner may change if we have a read
> @@ -358,6 +360,7 @@ int btrfs_try_tree_write_lock(struct extent_buffer *eb)
> */
> void btrfs_tree_read_unlock(struct extent_buffer *eb)
> {
> + lockdep_assert_held(&eb->lock);
> trace_btrfs_tree_read_unlock(eb);
> /*
> * if we're nested, we have the write lock. No new locking
> --
> 2.23.0