]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: Add "ceph fs nfs delete <export_id>" to delete exports
authorVarsha Rao <varao@redhat.com>
Thu, 19 Dec 2019 12:03:39 +0000 (17:33 +0530)
committerVarsha Rao <varao@redhat.com>
Wed, 8 Apr 2020 09:19:43 +0000 (14:49 +0530)
Fixes: https://tracker.ceph.com/issues/44193
Signed-off-by: Varsha Rao <varao@redhat.com>
src/pybind/mgr/volumes/fs/nfs.py
src/pybind/mgr/volumes/module.py

index 9ef45aa57a7b116f224e7ac447e356cc983dd77b..93c607c6c273cd98db464078e869358f2f7d30d8 100644 (file)
@@ -138,6 +138,12 @@ class GaneshaConf(object):
         for daemon_id, conf_blocks in daemon_map.items():
             self._write_raw_config(conf_blocks, "conf-{}".format(daemon_id))
 
+    def _delete_export(self, export_id):
+        self._persist_daemon_configuration()
+        with self.mgr.rados.open_ioctx(self.rados_pool) as ioctx:
+            if self.rados_namespace:
+                ioctx.set_namespace(self.rados_namespace)
+            ioctx.remove_object("export-{}".format(export_id))
 
     def _save_export(self, export):
         self.fill_keys(export)
@@ -152,9 +158,26 @@ class GaneshaConf(object):
         self._save_export(export)
         return ex_id
 
+    def remove_export(self, export_id):
+        if export_id not in self.exports:
+            return None
+        export = self.exports[export_id]
+        del self.exports[export_id]
+        self._delete_export(export_id)
+        return export
+
+    def has_export(self, export_id):
+        return export_id in self.exports
+
     def list_daemons(self):
         return [daemon_id for daemon_id in self.daemons_conf_blocks]
 
+    def reload_daemons(self, daemons):
+        with self.mgr.rados.open_ioctx(self.rados_pool) as ioctx:
+            if self.rados_namespace:
+                ioctx.set_namespace(self.rados_namespace)
+            for daemon_id in daemons:
+                ioctx.notify("conf-{}".format(daemon_id))
 
 def create_instance(orch):
     return GaneshaConf("a", "nfs-ganesha", "ganesha", orch)
@@ -178,6 +201,14 @@ def create_export(ganesha_conf):
     log.info("Export ID is {}".format(ex_id))
     return 0, "", ""
 
+def delete_export(ganesha_conf, ex_id):
+    if not ganesha_conf.has_export(ex_id):
+        return 0, "No exports available",""
+    log.info("Export detected for id:{}".format(ex_id))
+    export = ganesha_conf.remove_export(ex_id)
+    ganesha_conf.reload_daemons(export.daemons)
+    return 0, "", ""
+
 def check_fsal_valid(fs_map):
     fsmap_res = [{'id': fs['id'], 'name': fs['mdsmap']['fs_name']}
             for fs in fs_map['filesystems']]
index 45a86884ede5ce778a9a54d126f7fabf06a27f6f..f0ae8192cc01365eaa5a885bc59976ea1c813ab0 100644 (file)
@@ -5,7 +5,7 @@ from mgr_module import MgrModule
 import orchestrator
 
 from .fs.volume import VolumeClient
-from .fs.nfs import check_fsal_valid, create_instance, create_export
+from .fs.nfs import check_fsal_valid, create_instance, create_export, delete_export
 
 class Module(orchestrator.OrchestratorClientMixin, MgrModule):
     COMMANDS = [
@@ -218,6 +218,12 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
             'desc': "Create dummy exports",
             'perm': 'rw'
         },
+        {
+            'cmd': 'fs nfs delete '
+                   'name=export_id,type=CephInt,req=true ',
+            'desc': "Delete nfs exports",
+            'perm': 'rw'
+        },
 
         # volume ls [recursive]
         # subvolume ls <volume>
@@ -387,3 +393,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
         if check_fsal_valid(self.vc.mgr.get('fs_map')):
             instance = create_instance(self)
             return create_export(instance)
+
+    def _cmd_fs_nfs_delete(self, inbuf, cmd):
+            instance = create_instance(self)
+            return delete_export(instance, cmd['export_id'])