Btrfs: use down_read_nested to make lockdep silent
authorLiu Bo <bo.li.liu@oracle.com>
Thu, 1 Dec 2016 00:11:04 +0000 (16:11 -0800)
committerDavid Sterba <dsterba@suse.com>
Tue, 3 Jan 2017 14:19:17 +0000 (15:19 +0100)
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>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent-tree.c

index ac7e6713033c7f1f12406ac28adec98f1d14d7e7..dcd2e798767e57a80e7f50ff791a675e394a62c0 100644 (file)
@@ -7387,7 +7387,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, SINGLE_DEPTH_NESTING);
 
                spin_lock(&cluster->refill_lock);
                if (used_bg == cluster->block_group)