]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/vol: print proper message when subvolume metadata filename is too...
authorRishabh Dave <ridave@redhat.com>
Fri, 7 Feb 2025 11:41:53 +0000 (17:11 +0530)
committerRishabh Dave <ridave@redhat.com>
Mon, 24 Feb 2025 12:16:43 +0000 (17:46 +0530)
long.

When combination of subvolume group name and subvolume name is longer
than 248 characters, it leads to a failure because the metadata file is
a combination of both of these along with ":", "_" and ".meta".

Currently, when this comibnation longer than 248 characters, a bunch
stacktraces are printed along with multiple errors. This confuses the
user as well as looks bad.

Fixes: https://tracker.ceph.com/issues/69865
Signed-off-by: Rishabh Dave <ridave@redhat.com>
src/pybind/mgr/volumes/fs/operations/versions/auth_metadata.py

index b458acac4155efda6bbb4d0f634d47c1db3f45f7..88385fcd75a53f364d2ef6deafc3ccb6657c61bf 100644 (file)
@@ -1,4 +1,5 @@
 from contextlib import contextmanager
+import errno
 import os
 import fcntl
 import json
@@ -9,10 +10,14 @@ import uuid
 import cephfs
 
 from ..group import Group
+from ...exception import VolumeException
 
 log = logging.getLogger(__name__)
 
 
+FILE_NAME_MAX = 255
+
+
 class AuthMetadataError(Exception):
     pass
 
@@ -43,10 +48,17 @@ class AuthMetadataManager(object):
             return str(param).encode('utf-8')
 
     def _subvolume_metadata_path(self, group_name, subvol_name):
-        return os.path.join(self.volume_prefix, "_{0}:{1}{2}".format(
-            group_name if group_name != Group.NO_GROUP_NAME else "",
-            subvol_name,
-            self.META_FILE_EXT))
+        group_name = group_name if group_name != Group.NO_GROUP_NAME else ""
+        metadata_filename = f'_{group_name}:{subvol_name}{self.META_FILE_EXT}'
+        # in order to allow creation of this metadata file, 5 chars for ".meta"
+        # extension and 2 chars for "_" and ":" respectively. so that combina-
+        # -tion of group and subvolname should be shorter than 248 chars.
+        if len(metadata_filename) > FILE_NAME_MAX:
+            raise VolumeException(-errno.ENAMETOOLONG,
+                                 'use shorter group or subvol name, '
+                                 'combination of both should be less '
+                                 'than 249 characters')
+        return os.path.join(self.volume_prefix, metadata_filename)
 
     def _check_compat_version(self, compat_version):
         if self.version < compat_version: