From 87bb0896753add1da116f80c4a45c0a6233ea123 Mon Sep 17 00:00:00 2001 From: Xavi Hernandez Date: Tue, 4 Mar 2025 17:05:44 +0100 Subject: [PATCH] pybind/mgr: add option to set case sensitivity to a subvolume Add an option to explicitly set the case sensitivity of a CephFS subvolume. Signed-off-by: Xavi Hernandez --- src/pybind/mgr/volumes/fs/operations/subvolume.py | 5 +++-- .../mgr/volumes/fs/operations/versions/subvolume_v1.py | 3 ++- .../mgr/volumes/fs/operations/versions/subvolume_v2.py | 3 ++- src/pybind/mgr/volumes/fs/volume.py | 5 ++++- src/pybind/mgr/volumes/module.py | 6 ++++-- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/pybind/mgr/volumes/fs/operations/subvolume.py b/src/pybind/mgr/volumes/fs/operations/subvolume.py index bac51a42895..1656d7884d1 100644 --- a/src/pybind/mgr/volumes/fs/operations/subvolume.py +++ b/src/pybind/mgr/volumes/fs/operations/subvolume.py @@ -5,7 +5,7 @@ from .group import open_group from .template import SubvolumeOpType from .versions import loaded_subvolumes -def create_subvol(mgr, fs, vol_spec, group, subvolname, size, isolate_nspace, pool, mode, uid, gid, earmark, normalization): +def create_subvol(mgr, fs, vol_spec, group, subvolname, size, isolate_nspace, pool, mode, uid, gid, earmark, normalization, case_insensitive): """ create a subvolume (create a subvolume with the max known version). @@ -20,10 +20,11 @@ def create_subvol(mgr, fs, vol_spec, group, subvolname, size, isolate_nspace, po :param gid: the group identifier :param earmark: metadata string to identify if subvolume is associated with nfs/smb :param normalization: the unicode normalization form to use (nfd, nfc, nfkd or nfkc) + :param case_insensitive: whether to make the subvolume case insensitive or not :return: None """ subvolume = loaded_subvolumes.get_subvolume_object_max(mgr, fs, vol_spec, group, subvolname) - subvolume.create(size, isolate_nspace, pool, mode, uid, gid, earmark, normalization) + subvolume.create(size, isolate_nspace, pool, mode, uid, gid, earmark, normalization, case_insensitive) def create_clone(mgr, fs, vol_spec, group, subvolname, pool, source_volume, source_subvolume, snapname): diff --git a/src/pybind/mgr/volumes/fs/operations/versions/subvolume_v1.py b/src/pybind/mgr/volumes/fs/operations/versions/subvolume_v1.py index 019c2b878a9..e04e6eb51c7 100644 --- a/src/pybind/mgr/volumes/fs/operations/versions/subvolume_v1.py +++ b/src/pybind/mgr/volumes/fs/operations/versions/subvolume_v1.py @@ -85,7 +85,7 @@ class SubvolumeV1(SubvolumeBase, SubvolumeTemplate): """ Path to user data directory within a subvolume snapshot named 'snapname' """ return self.snapshot_path(snapname) - def create(self, size, isolate_nspace, pool, mode, uid, gid, earmark, normalization): + def create(self, size, isolate_nspace, pool, mode, uid, gid, earmark, normalization, case_insensitive): subvolume_type = SubvolumeTypes.TYPE_NORMAL try: initial_state = SubvolumeOpSm.get_init_state(subvolume_type) @@ -106,6 +106,7 @@ class SubvolumeV1(SubvolumeBase, SubvolumeTemplate): 'quota': size, 'earmark': earmark, 'normalization': normalization, + 'case_insensitive': case_insensitive, } self.set_attrs(subvol_path, attrs) diff --git a/src/pybind/mgr/volumes/fs/operations/versions/subvolume_v2.py b/src/pybind/mgr/volumes/fs/operations/versions/subvolume_v2.py index 2c4d493ec2c..85d260136ac 100644 --- a/src/pybind/mgr/volumes/fs/operations/versions/subvolume_v2.py +++ b/src/pybind/mgr/volumes/fs/operations/versions/subvolume_v2.py @@ -154,7 +154,7 @@ class SubvolumeV2(SubvolumeV1): self.metadata_mgr.update_global_section(MetadataManager.GLOBAL_META_KEY_PATH, qpath) self.metadata_mgr.update_global_section(MetadataManager.GLOBAL_META_KEY_STATE, initial_state.value) - def create(self, size, isolate_nspace, pool, mode, uid, gid, earmark, normalization): + def create(self, size, isolate_nspace, pool, mode, uid, gid, earmark, normalization, case_insensitive): subvolume_type = SubvolumeTypes.TYPE_NORMAL try: initial_state = SubvolumeOpSm.get_init_state(subvolume_type) @@ -178,6 +178,7 @@ class SubvolumeV2(SubvolumeV1): 'quota': size, 'earmark': earmark, 'normalization': normalization, + 'case_insensitive': case_insensitive, } self.set_attrs(subvol_path, attrs) diff --git a/src/pybind/mgr/volumes/fs/volume.py b/src/pybind/mgr/volumes/fs/volume.py index 0d09333463e..5a8a6111bb0 100644 --- a/src/pybind/mgr/volumes/fs/volume.py +++ b/src/pybind/mgr/volumes/fs/volume.py @@ -233,12 +233,13 @@ class VolumeClient(CephfsClient["Module"]): isolate_nspace = kwargs['namespace_isolated'] earmark = kwargs['earmark'] or '' # if not set, default to empty string --> no earmark normalization = kwargs['normalization'] + case_insensitive = kwargs['case_insensitive'] oct_mode = octal_str_to_decimal_int(mode) try: create_subvol( - self.mgr, fs_handle, self.volspec, group, subvolname, size, isolate_nspace, pool, oct_mode, uid, gid, earmark, normalization) + self.mgr, fs_handle, self.volspec, group, subvolname, size, isolate_nspace, pool, oct_mode, uid, gid, earmark, normalization, case_insensitive) except VolumeException as ve: # kick the purge threads for async removal -- note that this # assumes that the subvolume is moved to trashcan for cleanup on error. @@ -258,6 +259,7 @@ class VolumeClient(CephfsClient["Module"]): isolate_nspace = kwargs['namespace_isolated'] earmark = kwargs['earmark'] or '' # if not set, default to empty string --> no earmark normalization = kwargs['normalization'] + case_insensitive = kwargs['case_insensitive'] try: with open_volume(self, volname) as fs_handle: @@ -274,6 +276,7 @@ class VolumeClient(CephfsClient["Module"]): 'quota': size, 'earmark': earmark, 'normalization': normalization, + 'case_insensitive': case_insensitive, } subvolume.set_attrs(subvolume.path, attrs) except VolumeException as ve: diff --git a/src/pybind/mgr/volumes/module.py b/src/pybind/mgr/volumes/module.py index 9281a925b6e..212870b5944 100644 --- a/src/pybind/mgr/volumes/module.py +++ b/src/pybind/mgr/volumes/module.py @@ -145,7 +145,8 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): 'name=mode,type=CephString,req=false ' 'name=namespace_isolated,type=CephBool,req=false ' 'name=earmark,type=CephString,req=false ' - 'name=normalization,type=CephChoices,strings=nfd|nfc|nfkd|nfkc,req=false ', + 'name=normalization,type=CephChoices,strings=nfd|nfc|nfkd|nfkc,req=false ' + 'name=case_insensitive,type=CephBool,req=false ', 'desc': "Create a CephFS subvolume in a volume, and optionally, " "with a specific size (in bytes), a specific data pool layout, " "a specific mode, in a specific subvolume group and in separate " @@ -761,7 +762,8 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): mode=cmd.get('mode', '755'), namespace_isolated=cmd.get('namespace_isolated', False), earmark=cmd.get('earmark', None), - normalization=cmd.get('normalization', None)) + normalization=cmd.get('normalization', None), + case_insensitive=cmd.get('case_insensitive', False)) @mgr_cmd_wrap def _cmd_fs_subvolume_rm(self, inbuf, cmd): -- 2.39.5