From a84d4b0124d49a14426c0703a204b4c64c13c936 Mon Sep 17 00:00:00 2001 From: Varsha Rao Date: Wed, 1 Apr 2020 21:31:26 +0530 Subject: [PATCH] mgr/volumes: Update nfs cluster and export interface Instead of prefixing 'fs' to the commands, type is added for easy extension to create rgw exports. $ ceph nfs cluster create [--size=1] $ ceph nfs export create [--readonly] [--path=/path/in/cephfs] [--attach=] Signed-off-by: Varsha Rao --- doc/cephfs/fs-nfs-exports.rst | 10 ++++++---- src/pybind/mgr/volumes/fs/nfs.py | 9 +++++++-- src/pybind/mgr/volumes/module.py | 21 ++++++++++++--------- src/vstart.sh | 4 ++-- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/doc/cephfs/fs-nfs-exports.rst b/doc/cephfs/fs-nfs-exports.rst index fa8bb8403c4e4..aa9f69de0f904 100644 --- a/doc/cephfs/fs-nfs-exports.rst +++ b/doc/cephfs/fs-nfs-exports.rst @@ -17,12 +17,13 @@ Create NFS Ganesha Cluster .. code:: bash - $ ceph fs nfs cluster create [--size=1] + $ ceph nfs cluster create [--size=1] This creates a common recovery pool for all Ganesha daemons, new user based on cluster_id and common ganesha config rados object. -Here size denotes the number of ganesha daemons within a cluster. +Here size denotes the number of ganesha daemons within a cluster and type is +export type. Currently only CephFS is supported. .. note:: This does not setup ganesha recovery database and start the daemons. It needs to be done manually if not using vstart for creating @@ -34,10 +35,11 @@ Create CephFS Export .. code:: bash - $ ceph fs nfs export create [--readonly] [--path=/path/in/cephfs] [--attach=] + $ ceph nfs export create [--readonly] [--path=/path/in/cephfs] [--attach=] It creates export rados objects containing the export block. Here binding is -the pseudo root name. +the pseudo root name and type is export type. Currently only CephFS is +supported. Configuring NFS-Ganesha to export CephFS with vstart ==================================================== diff --git a/src/pybind/mgr/volumes/fs/nfs.py b/src/pybind/mgr/volumes/fs/nfs.py index a6740b83503c5..b7e19f4b8822e 100644 --- a/src/pybind/mgr/volumes/fs/nfs.py +++ b/src/pybind/mgr/volumes/fs/nfs.py @@ -273,7 +273,9 @@ def _save_export(self, export): self._write_raw_config(conf_block, "export-{}".format(export.export_id)) self._update_common_conf(export.export_id) - def create_export(self, fs_name, pseudo_path, read_only, path, cluster_id): + def create_export(self, export_type, fs_name, pseudo_path, read_only, path, cluster_id): + if export_type != 'cephfs': + return -errno.EINVAL,"", f"Invalid export type: {export_type}" #TODO Check if valid cluster if cluster_id not in self.exports: self.exports[cluster_id] = [] @@ -339,7 +341,10 @@ def create_empty_rados_obj(self): "write configuration into rados object %s/%s/nfs-conf\n", self.pool_name, self.pool_ns) - def create_nfs_cluster(self, size): + def create_nfs_cluster(self, export_type, size): + if export_type != 'cephfs': + return -errno.EINVAL,"", f"Invalid export type: {export_type}" + pool_list = [p['pool_name'] for p in self.mgr.get_osdmap().dump().get('pools', [])] client = 'client.%s' % self.cluster_id diff --git a/src/pybind/mgr/volumes/module.py b/src/pybind/mgr/volumes/module.py index 75cbaf44ceecc..a5cbe960f7dc9 100644 --- a/src/pybind/mgr/volumes/module.py +++ b/src/pybind/mgr/volumes/module.py @@ -216,7 +216,8 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): 'perm': 'r' }, { - 'cmd': 'fs nfs export create ' + 'cmd': 'nfs export create ' + 'name=type,type=CephString ' 'name=fsname,type=CephString ' 'name=binding,type=CephString ' 'name=readonly,type=CephBool,req=false ' @@ -232,9 +233,10 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): 'perm': 'rw' }, { - 'cmd': 'fs nfs cluster create ' - 'name=size,type=CephInt,req=false ' - 'name=cluster_id,type=CephString ', + 'cmd': 'nfs cluster create ' + 'name=type,type=CephString ' + 'name=clusterid,type=CephString ' + 'name=size,type=CephInt,req=false ', 'desc': "Create an NFS Cluster", 'perm': 'rw' }, @@ -403,14 +405,15 @@ def _cmd_fs_clone_cancel(self, inbuf, cmd): return self.vc.clone_cancel( vol_name=cmd['vol_name'], clone_name=cmd['clone_name'], group_name=cmd.get('group_name', None)) - def _cmd_fs_nfs_export_create(self, inbuf, cmd): - return self.fs_export.create_export(fs_name=cmd['fsname'], + def _cmd_nfs_export_create(self, inbuf, cmd): + #TODO Extend export creation for rgw. + return self.fs_export.create_export(export_type=cmd['type'], fs_name=cmd['fsname'], pseudo_path=cmd['binding'], read_only=cmd.get('readonly', False), path=cmd.get('path', '/'), cluster_id=cmd.get('attach','None')) def _cmd_fs_nfs_export_delete(self, inbuf, cmd): return self.fs_export.delete_export(cmd['export_id']) - def _cmd_fs_nfs_cluster_create(self, inbuf, cmd): - nfs_cluster_obj = NFSCluster(self, cmd['cluster_id']) - return nfs_cluster_obj.create_nfs_cluster(size=cmd.get('size', 1)) + def _cmd_nfs_cluster_create(self, inbuf, cmd): + nfs_cluster_obj = NFSCluster(self, cmd['clusterid']) + return nfs_cluster_obj.create_nfs_cluster(export_type=cmd['type'], size=cmd.get('size', 1)) diff --git a/src/vstart.sh b/src/vstart.sh index ffef573b51ee3..11db9555cd817 100755 --- a/src/vstart.sh +++ b/src/vstart.sh @@ -1095,7 +1095,7 @@ start_ganesha() { osd "allow rw pool=$pool_name namespace=$namespace, allow rw tag cephfs data=a" \ mds "allow rw path=/" \ >> "$keyring_fn" - prun ceph_adm fs nfs cluster create $name + prun ceph_adm nfs cluster create cephfs $name echo "NFS_CORE_PARAM { Enable_NLM = false; @@ -1136,7 +1136,7 @@ start_ganesha() { pid file = $ganesha_dir/ganesha.pid EOF - prun ceph_adm fs nfs export create "a" "/cephfs" --attach=$name + prun ceph_adm nfs export create cephfs "a" "/cephfs" --attach=$name prun ganesha-rados-grace -p $pool_name -n $namespace add $name prun ganesha-rados-grace -p $pool_name -n $namespace