From 340c2d886eb7347b0463bc52fc6acf5d740d300d Mon Sep 17 00:00:00 2001 From: Venky Shankar Date: Fri, 17 Jan 2020 04:42:58 -0500 Subject: [PATCH] mgr/volumes: fail removing subvolume with snapshots Fixes: http://tracker.ceph.com/issues/43645 Signed-off-by: Venky Shankar (cherry picked from commit c158a1334207966c9727eb1e9e2eaab756e5e08b) --- qa/tasks/cephfs/test_volumes.py | 28 +++++++++++++++++++ .../mgr/volumes/fs/operations/subvolume.py | 2 ++ 2 files changed, 30 insertions(+) diff --git a/qa/tasks/cephfs/test_volumes.py b/qa/tasks/cephfs/test_volumes.py index a21781e3e958f..54f8619a45140 100644 --- a/qa/tasks/cephfs/test_volumes.py +++ b/qa/tasks/cephfs/test_volumes.py @@ -1217,3 +1217,31 @@ class TestVolumes(CephFSTestCase): # remove group self._fs_cmd("subvolumegroup", "rm", self.volname, group) + + def test_subvolume_rm_with_snapshots(self): + subvolume = self._generate_random_subvolume_name() + snapshot = self._generate_random_snapshot_name() + + # create subvolume + self._fs_cmd("subvolume", "create", self.volname, subvolume) + + # snapshot subvolume + self._fs_cmd("subvolume", "snapshot", "create", self.volname, subvolume, snapshot) + + # remove subvolume -- should fail with ENOTEMPTY since it has snapshots + try: + self._fs_cmd("subvolume", "rm", self.volname, subvolume) + except CommandFailedError as ce: + if ce.exitstatus != errno.ENOTEMPTY: + raise RuntimeError("invalid error code returned when deleting subvolume with snapshots") + else: + raise RuntimeError("expected subvolume deletion to fail") + + # remove snapshot + self._fs_cmd("subvolume", "snapshot", "rm", self.volname, subvolume, snapshot) + + # remove subvolume + self._fs_cmd("subvolume", "rm", self.volname, subvolume) + + # verify trash dir is clean + self._wait_for_trash_empty() diff --git a/src/pybind/mgr/volumes/fs/operations/subvolume.py b/src/pybind/mgr/volumes/fs/operations/subvolume.py index 6759045b4b902..83f7ce691d4ea 100644 --- a/src/pybind/mgr/volumes/fs/operations/subvolume.py +++ b/src/pybind/mgr/volumes/fs/operations/subvolume.py @@ -39,6 +39,8 @@ def remove_subvol(fs, vol_spec, group, subvolname): :return: None """ with open_subvol(fs, vol_spec, group, subvolname) as subvolume: + if subvolume.list_snapshots(): + raise VolumeException(-errno.ENOTEMPTY, "subvolume '{0}' has snapshots".format(subvolname)) subvolume.remove() @contextmanager -- 2.39.5