diff mbox

Btrfs: use down_read_nested to make lockdep silent

Message ID 1480628659-17731-1-git-send-email-bo.li.liu@oracle.com (mailing list archive)
State Superseded
Headers show

Commit Message

Liu Bo Dec. 1, 2016, 9:44 p.m. UTC
If @block_group is not @used_bg, it'll try to get @used_bg's lock without
droping @block_group 's lock and lockdep has throwed a scary deadlock warning
about it.
Fix it by using down_read_nested.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
 fs/btrfs/extent-tree.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

David Sterba Dec. 12, 2016, 1:15 p.m. UTC | #1
On Thu, Dec 01, 2016 at 01:44:19PM -0800, Liu Bo wrote:
> If @block_group is not @used_bg, it'll try to get @used_bg's lock without
> droping @block_group 's lock and lockdep has throwed a scary deadlock warning
> about it.
> Fix it by using down_read_nested.
> 
> Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
> ---
>  fs/btrfs/extent-tree.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index 210c94a..cdb082a 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -7394,7 +7394,8 @@ btrfs_lock_cluster(struct btrfs_block_group_cache *block_group,
>  
>  		spin_unlock(&cluster->refill_lock);
>  
> -		down_read(&used_bg->data_rwsem);
> +		/* We should only have one-level nested. */
> +		down_read_nested(&used_bg->data_rwsem, 1);

While looking what down_read_nested does, I've found
SINGLE_DEPTH_NESTING, defined to 1. I'd rather use it instead of '1', as
it gives more more pointers to the docs.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 210c94a..cdb082a 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -7394,7 +7394,8 @@  btrfs_lock_cluster(struct btrfs_block_group_cache *block_group,
 
 		spin_unlock(&cluster->refill_lock);
 
-		down_read(&used_bg->data_rwsem);
+		/* We should only have one-level nested. */
+		down_read_nested(&used_bg->data_rwsem, 1);
 
 		spin_lock(&cluster->refill_lock);
 		if (used_bg == cluster->block_group)