From 4dd80305fbf8544ac0917775553c4a857a8a5770 Mon Sep 17 00:00:00 2001 From: Ramana Raja Date: Tue, 20 Aug 2019 16:25:11 +0530 Subject: [PATCH] mgr/volumes: give useful error message ... when creating FS subvolume or subvolume group with invalid data pool layout. Fixes: https://tracker.ceph.com/issues/41337 Signed-off-by: Ramana Raja (cherry picked from commit cbe48308e9e6b7e1b673e11101fd7e1403f52019) --- qa/tasks/cephfs/test_volumes.py | 28 ++++++++++++++++++++++++++ src/pybind/mgr/volumes/fs/subvolume.py | 12 +++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/qa/tasks/cephfs/test_volumes.py b/qa/tasks/cephfs/test_volumes.py index eb94251cab9a3..c7dd3997d81c0 100644 --- a/qa/tasks/cephfs/test_volumes.py +++ b/qa/tasks/cephfs/test_volumes.py @@ -132,6 +132,20 @@ class TestVolumes(CephFSTestCase): # verify trash dir is clean self._wait_for_trash_empty() + def test_subvolume_create_with_invalid_data_pool_layout(self): + subvolume = self._generate_random_subvolume_name() + data_pool = "invalid_pool" + # create subvolume with invalid data pool layout + try: + self._fs_cmd("subvolume", "create", self.volname, subvolume, "--pool_layout", data_pool) + except CommandFailedError as ce: + if ce.exitstatus != errno.EINVAL: + raise + else: + raise + # clean up + self._fs_cmd("subvolume", "rm", self.volname, subvolume, "--force") + def test_nonexistent_subvolume_rm(self): # remove non-existing subvolume subvolume = "non_existent_subvolume" @@ -221,6 +235,20 @@ class TestVolumes(CephFSTestCase): self._fs_cmd("subvolumegroup", "rm", self.volname, group1) self._fs_cmd("subvolumegroup", "rm", self.volname, group2) + def test_subvolume_group_create_with_invalid_data_pool_layout(self): + group = self._generate_random_group_name() + data_pool = "invalid_pool" + # create group with invalid data pool layout + try: + self._fs_cmd("subvolumegroup", "create", self.volname, group, "--pool_layout", data_pool) + except CommandFailedError as ce: + if ce.exitstatus != errno.EINVAL: + raise + else: + raise + # clean up + self._fs_cmd("subvolumegroup", "rm", self.volname, group, "--force") + def test_subvolume_create_with_desired_data_pool_layout_in_group(self): subvol1 = self._generate_random_subvolume_name() subvol2 = self._generate_random_subvolume_name() diff --git a/src/pybind/mgr/volumes/fs/subvolume.py b/src/pybind/mgr/volumes/fs/subvolume.py index 6d0232c56e1fe..75fab056d4dd8 100644 --- a/src/pybind/mgr/volumes/fs/subvolume.py +++ b/src/pybind/mgr/volumes/fs/subvolume.py @@ -79,7 +79,11 @@ class SubVolume(object): self.fs.setxattr(subvolpath, 'ceph.quota.max_bytes', str(size).encode('utf-8'), 0) if pool: - self.fs.setxattr(subvolpath, 'ceph.dir.layout.pool', pool.encode('utf-8'), 0) + try: + self.fs.setxattr(subvolpath, 'ceph.dir.layout.pool', pool.encode('utf-8'), 0) + except cephfs.InvalidValue: + raise VolumeException(-errno.EINVAL, + "Invalid pool layout '{0}'. It must be a valid data pool".format(pool)) xattr_key = xattr_val = None if namespace_isolated: @@ -179,7 +183,11 @@ class SubVolume(object): self.fs.mkdirs(path, mode) if not pool: pool = self._get_ancestor_xattr(path, "ceph.dir.layout.pool") - self.fs.setxattr(path, 'ceph.dir.layout.pool', pool.encode('utf-8'), 0) + try: + self.fs.setxattr(path, 'ceph.dir.layout.pool', pool.encode('utf-8'), 0) + except cephfs.InvalidValue: + raise VolumeException(-errno.EINVAL, + "Invalid pool layout '{0}'. It must be a valid data pool".format(pool)) def remove_group(self, spec, force): path = spec.group_path -- 2.39.5