From 451be112603f970de3cb0ca9048c88a98c034188 Mon Sep 17 00:00:00 2001 From: Venky Shankar Date: Tue, 14 Jan 2020 22:52:52 -0500 Subject: [PATCH] mgr/volumes: allow force removal of incomplete failed clones Signed-off-by: Venky Shankar --- src/pybind/mgr/volumes/fs/operations/subvolume.py | 6 ++++-- src/pybind/mgr/volumes/fs/volume.py | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/pybind/mgr/volumes/fs/operations/subvolume.py b/src/pybind/mgr/volumes/fs/operations/subvolume.py index bfd9349bb77..70e5dbb5f1d 100644 --- a/src/pybind/mgr/volumes/fs/operations/subvolume.py +++ b/src/pybind/mgr/volumes/fs/operations/subvolume.py @@ -45,7 +45,7 @@ def create_clone(fs, vol_spec, group, subvolname, pool, source_volume, source_su subvolume = loaded_subvolumes.get_subvolume_object_max(fs, vol_spec, group, subvolname) subvolume.create_clone(pool, source_volume, source_subvolume, snapname) -def remove_subvol(fs, vol_spec, group, subvolname): +def remove_subvol(fs, vol_spec, group, subvolname, force=False): """ remove a subvolume. @@ -53,9 +53,11 @@ def remove_subvol(fs, vol_spec, group, subvolname): :param vol_spec: volume specification :param group: group object for the subvolume :param subvolname: subvolume name + :param force: force remove subvolumes :return: None """ - with open_subvol(fs, vol_spec, group, subvolname) as subvolume: + nc_flag = True if not force else False + with open_subvol(fs, vol_spec, group, subvolname, need_complete=nc_flag) as subvolume: if subvolume.list_snapshots(): raise VolumeException(-errno.ENOTEMPTY, "subvolume '{0}' has snapshots".format(subvolname)) subvolume.remove() diff --git a/src/pybind/mgr/volumes/fs/volume.py b/src/pybind/mgr/volumes/fs/volume.py index 21b0dc848c3..a10488d1292 100644 --- a/src/pybind/mgr/volumes/fs/volume.py +++ b/src/pybind/mgr/volumes/fs/volume.py @@ -160,14 +160,17 @@ class VolumeClient(object): try: with open_volume(self, volname) as fs_handle: with open_group(fs_handle, self.volspec, groupname) as group: - remove_subvol(fs_handle, self.volspec, group, subvolname) + remove_subvol(fs_handle, self.volspec, group, subvolname, force) # kick the purge threads for async removal -- note that this # assumes that the subvolume is moved to trash can. # TODO: make purge queue as singleton so that trash can kicks # the purge threads on dump. self.purge_queue.queue_job(volname) except VolumeException as ve: - if not (ve.errno == -errno.ENOENT and force): + if ve.errno == -errno.EAGAIN: + ve = VolumeException(ve.errno, ve.error_str + " (use --force to override)") + ret = self.volume_exception_to_retval(ve) + elif not (ve.errno == -errno.ENOENT and force): ret = self.volume_exception_to_retval(ve) return ret -- 2.39.5