On Sun, Nov 11, 2018 at 10:22:20PM +0800, Anand Jain wrote: > In btrfs_dev_replace_cancel() we should check if the > btrfs_scrub_cancel() is successful. If the btrfs_scrub_cancel() fails, return > BTRFS_IOCTL_DEV_REPLACE_RESULT_NOT_STARTED so that user can try to > cancel the replace again.
I've updated the subject and changelog as this was not easy to understand what's going on. > Signed-off-by: Anand Jain <anand.j...@oracle.com> > --- > fs/btrfs/dev-replace.c | 22 +++++++++++++--------- > 1 file changed, 13 insertions(+), 9 deletions(-) > > diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c > index d32d696d931c..9fc3cb8d3918 100644 > --- a/fs/btrfs/dev-replace.c > +++ b/fs/btrfs/dev-replace.c > @@ -799,18 +799,22 @@ 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) { This should be ret < 0, fixed. > + 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: > /* > -- > 1.8.3.1