btrfs: dev-replace: set result code of cancel by status of scrub
authorAnand Jain <anand.jain@oracle.com>
Sun, 11 Nov 2018 14:22:20 +0000 (22:22 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 17 Dec 2018 13:51:35 +0000 (14:51 +0100)
The device-replace needs to check the result code of the scrub workers
in btrfs_dev_replace_cancel and distinguish if successful cancel
operation and when the there was no operation running.

If btrfs_scrub_cancel() fails, return
BTRFS_IOCTL_DEV_REPLACE_RESULT_NOT_STARTED so that user can try
to cancel the replace again.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.com>
[ update changelog ]
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/dev-replace.c

index 08092d329f666d74fea03093bbf4ed56734cb887..c0878ff8185a803e69024d5c13498855e2d594fd 100644 (file)
@@ -805,16 +805,23 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
                btrfs_dev_replace_write_unlock(dev_replace);
                break;
        case BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED:
-               result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR;
                tgt_device = dev_replace->tgtdev;
                src_device = dev_replace->srcdev;
                btrfs_dev_replace_write_unlock(dev_replace);
-               btrfs_scrub_cancel(fs_info);
-               /* btrfs_dev_replace_finishing() will handle the cleanup part */
-               btrfs_info_in_rcu(fs_info,
-                       "dev_replace from %s (devid %llu) to %s canceled",
-                       btrfs_dev_name(src_device), src_device->devid,
-                       btrfs_dev_name(tgt_device));
+               ret = btrfs_scrub_cancel(fs_info);
+               if (ret < 0) {
+                       result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NOT_STARTED;
+               } else {
+                       result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR;
+                       /*
+                        * btrfs_dev_replace_finishing() will handle the
+                        * cleanup part
+                        */
+                       btrfs_info_in_rcu(fs_info,
+                               "dev_replace from %s (devid %llu) to %s canceled",
+                               btrfs_dev_name(src_device), src_device->devid,
+                               btrfs_dev_name(tgt_device));
+               }
                break;
        case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED:
                /*