diff mbox series

[v2,5/5] btrfs: locking: add lock assertions

Message ID 86d6b97f9a9f09b8ac2d1773295fbb1176e5a73a.1572432768.git.dsterba@suse.com (mailing list archive)
State New, archived
Headers show
Series Extent buffer locking and documentation | expand

Commit Message

David Sterba Oct. 30, 2019, 10:57 a.m. UTC
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@suse.com>
---
 fs/btrfs/locking.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

David Sterba Nov. 5, 2019, 10:31 a.m. UTC | #1
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@suse.com>
> ---
>  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
diff mbox series

Patch

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);
 	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