btrfs: move btrfs_scratch_superblocks into btrfs_dev_replace_finishing
authorJosef Bacik <josef@toxicpanda.com>
Thu, 20 Aug 2020 15:18:26 +0000 (11:18 -0400)
committerDavid Sterba <dsterba@suse.com>
Fri, 25 Sep 2020 14:40:22 +0000 (16:40 +0200)
We need to move the closing of the src_device out of all the device
replace locking, but we definitely want to zero out the superblock
before we commit the last time to make sure the device is properly
removed.  Handle this by pushing btrfs_scratch_superblocks into
btrfs_dev_replace_finishing, and then later on we'll move the src_device
closing and freeing stuff where we need it to be.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/dev-replace.c
fs/btrfs/volumes.c
fs/btrfs/volumes.h

index db93909b25e08e1a46219bb84e6575720573477b..7cf48aeb6f14ef7e3496b454592c7b30c04b048b 100644 (file)
@@ -745,6 +745,9 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
        /* replace the sysfs entry */
        btrfs_sysfs_remove_devices_dir(fs_info->fs_devices, src_device);
        btrfs_sysfs_update_devid(tgt_device);
+       if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &src_device->dev_state))
+               btrfs_scratch_superblocks(fs_info, src_device->bdev,
+                                         src_device->name->str);
        btrfs_rm_dev_replace_free_srcdev(src_device);
 
        /* write back the superblocks */
index 117b43367629e418ae15a819c6a96b3d24488927..01ebdb69fbdb0508bef99aed9f5bdd7adf09af64 100644 (file)
@@ -1999,9 +1999,9 @@ static u64 btrfs_num_devices(struct btrfs_fs_info *fs_info)
        return num_devices;
 }
 
-static void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info,
-                                     struct block_device *bdev,
-                                     const char *device_path)
+void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info,
+                              struct block_device *bdev,
+                              const char *device_path)
 {
        struct btrfs_super_block *disk_super;
        int copy_num;
@@ -2224,12 +2224,6 @@ void btrfs_rm_dev_replace_free_srcdev(struct btrfs_device *srcdev)
        struct btrfs_fs_info *fs_info = srcdev->fs_info;
        struct btrfs_fs_devices *fs_devices = srcdev->fs_devices;
 
-       if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &srcdev->dev_state)) {
-               /* zero out the old super if it is writable */
-               btrfs_scratch_superblocks(fs_info, srcdev->bdev,
-                                         srcdev->name->str);
-       }
-
        btrfs_close_bdev(srcdev);
        synchronize_rcu();
        btrfs_free_device(srcdev);
index 5eea93916fbf116689e4b89dae746645c7b9706b..302c9234f7d08177cb149141b9e10a640154469d 100644 (file)
@@ -573,6 +573,9 @@ void btrfs_set_fs_info_ptr(struct btrfs_fs_info *fs_info);
 void btrfs_reset_fs_info_ptr(struct btrfs_fs_info *fs_info);
 bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info,
                                        struct btrfs_device *failing_dev);
+void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info,
+                              struct block_device *bdev,
+                              const char *device_path);
 
 int btrfs_bg_type_to_factor(u64 flags);
 const char *btrfs_bg_type_to_raid_name(u64 flags);