From 59cf9beb31deaf92be1bc5f0f0df9bda92fb09eb Mon Sep 17 00:00:00 2001 From: Jos Collin Date: Mon, 16 Sep 2019 18:54:24 +0530 Subject: [PATCH] mgr/volumes: protection for 'fs volume rm' command Fixes: https://tracker.ceph.com/issues/41841 Signed-off-by: Jos Collin --- src/pybind/mgr/volumes/fs/volume.py | 17 +++++++++++++---- src/pybind/mgr/volumes/module.py | 8 +++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/pybind/mgr/volumes/fs/volume.py b/src/pybind/mgr/volumes/fs/volume.py index 791eab5f33236..04066558d8d1f 100644 --- a/src/pybind/mgr/volumes/fs/volume.py +++ b/src/pybind/mgr/volumes/fs/volume.py @@ -230,11 +230,18 @@ class VolumeClient(object): 'data': data_pool} return self.mgr.mon_command(command) - def remove_filesystem(self, fs_name): + def remove_filesystem(self, fs_name, confirm): + if confirm != "--yes-i-really-mean-it": + return -errno.EPERM, "", "WARNING: this will *PERMANENTLY DESTROY* all data " \ + "stored in the filesystem '{0}'. If you are *ABSOLUTELY CERTAIN* " \ + "that is what you want, re-issue the command followed by " \ + "--yes-i-really-mean-it.".format(fs_name) + command = {'prefix': 'fs fail', 'fs_name': fs_name} r, outb, outs = self.mgr.mon_command(command) if r != 0: return r, outb, outs + command = {'prefix': 'fs rm', 'fs_name': fs_name, 'yes_i_really_mean_it': True} return self.mgr.mon_command(command) @@ -275,7 +282,7 @@ class VolumeClient(object): # create mds return self.create_mds(volname) - def delete_volume(self, volname): + def delete_volume(self, volname, confirm): """ delete the given module (tear down mds, remove filesystem) """ @@ -297,11 +304,13 @@ class VolumeClient(object): # In case orchestrator didn't tear down MDS daemons cleanly, or # there was no orchestrator, we force the daemons down. if self.volume_exists(volname): - r, outb, outs = self.remove_filesystem(volname) + r, outb, outs = self.remove_filesystem(volname, confirm) if r != 0: return r, outb, outs else: - log.warning("Filesystem already gone for volume '{0}'".format(volname)) + err = "Filesystem not found for volume '{0}'".format(volname) + log.warning(err) + return -errno.ENOENT, "", err metadata_pool, data_pool = self.gen_pool_names(volname) r, outb, outs = self.remove_pool(metadata_pool) if r != 0: diff --git a/src/pybind/mgr/volumes/module.py b/src/pybind/mgr/volumes/module.py index 3d7260577f596..5de353ca68004 100644 --- a/src/pybind/mgr/volumes/module.py +++ b/src/pybind/mgr/volumes/module.py @@ -37,8 +37,9 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): }, { 'cmd': 'fs volume rm ' - 'name=vol_name,type=CephString', - 'desc': "Delete a CephFS volume", + 'name=vol_name,type=CephString ' + 'name=yes-i-really-mean-it,type=CephString,req=false ', + 'desc': "Delete a FS volume by passing --yes-i-really-mean-it flag", 'perm': 'rw' }, { @@ -194,7 +195,8 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): def _cmd_fs_volume_rm(self, inbuf, cmd): vol_name = cmd['vol_name'] - return self.vc.delete_volume(vol_name) + confirm = cmd.get('yes-i-really-mean-it', None) + return self.vc.delete_volume(vol_name, confirm) def _cmd_fs_volume_ls(self, inbuf, cmd): return self.vc.list_volumes() -- 2.39.5