btrfs: reada: reorder dev-replace locks before radix tree preload
authorDavid Sterba <dsterba@suse.com>
Fri, 24 Aug 2018 17:35:04 +0000 (19:35 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 17 Dec 2018 13:51:44 +0000 (14:51 +0100)
The device-replace read lock is going to use rw semaphore in followup
commits. The semaphore might sleep which is not possible in the radix
tree preload section. The lock nesting is now:

* device replace
  * radix tree preload
    * readahead spinlock

Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/reada.c

index dec14b739b1016223259255d568d17017d79cc69..6f81f3e88b6d01b36b13f114fe74143dc09af4fa 100644 (file)
@@ -376,26 +376,28 @@ static struct reada_extent *reada_find_extent(struct btrfs_fs_info *fs_info,
                goto error;
        }
 
+       /* Insert extent in reada tree + all per-device trees, all or nothing */
+       btrfs_dev_replace_read_lock(&fs_info->dev_replace);
        ret = radix_tree_preload(GFP_KERNEL);
-       if (ret)
+       if (ret) {
+               btrfs_dev_replace_read_unlock(&fs_info->dev_replace);
                goto error;
+       }
 
-       /* insert extent in reada_tree + all per-device trees, all or nothing */
-       btrfs_dev_replace_read_lock(&fs_info->dev_replace);
        spin_lock(&fs_info->reada_lock);
        ret = radix_tree_insert(&fs_info->reada_tree, index, re);
        if (ret == -EEXIST) {
                re_exist = radix_tree_lookup(&fs_info->reada_tree, index);
                re_exist->refcnt++;
                spin_unlock(&fs_info->reada_lock);
-               btrfs_dev_replace_read_unlock(&fs_info->dev_replace);
                radix_tree_preload_end();
+               btrfs_dev_replace_read_unlock(&fs_info->dev_replace);
                goto error;
        }
        if (ret) {
                spin_unlock(&fs_info->reada_lock);
-               btrfs_dev_replace_read_unlock(&fs_info->dev_replace);
                radix_tree_preload_end();
+               btrfs_dev_replace_read_unlock(&fs_info->dev_replace);
                goto error;
        }
        radix_tree_preload_end();