]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/volumes: accept unit with subvolume resize
authorDhairya Parmar <dparmar@redhat.com>
Mon, 17 Mar 2025 14:53:22 +0000 (20:23 +0530)
committerDhairya Parmar <dparmar@redhat.com>
Thu, 19 Feb 2026 04:46:02 +0000 (10:16 +0530)
Specifying the quota or resize for a subvolume requires the value in bytes.
This value can now be accepted as <num><unit>. Also allows floating point numbers.

Fixes: https://tracker.ceph.com/issues/62673
Signed-off-by: Dhairya Parmar <dparmar@redhat.com>
src/pybind/mgr/volumes/fs/operations/versions/subvolume_base.py

index 5ceb9bcc2bc3cdf8f728e80c1fa1cec2c7173faf..c07d7bcfc27d1ea51a07e91caa7c2aa347aec291 100644 (file)
@@ -371,7 +371,37 @@ class SubvolumeBase(object):
                 raise VolumeException(-errno.EINVAL,
                                       "invalid fscrypt_file specified: '{0}'".format(fscrypt_file))
 
+    def convert_to_bytes(self, subvol_size):
+        import re
+        unit_map = {"B": 1,
+                    "K": pow(1024, 1),
+                    "M": pow(1024, 2),
+                    "G": pow(1024, 3),
+                    "T": pow(1024, 4),
+                    "P": pow(1024, 5),
+                    "E": pow(1024, 6)}
+        pattern = r'^(\d+\.\d+|\d+)([KMGTPE]i?B?|B)$'
+        match = re.match(pattern, subvol_size)
+        if match:
+            value = match.group(1)
+            unit = match.group(2)
+            if unit[0] == "B" and "." in value:
+                raise VolumeException(-errno.EINVAL,
+                                      f"Invalid byte value: {value}")
+            multiplier = unit_map.get(unit[0])
+            if multiplier is None:
+                raise VolumeException(-errno.EINVAL,
+                                      f"Invalid subvolume unit: {unit}")
+            else:
+                return float(value) * multiplier
+        else:
+            return None
+
     def _resize(self, path, newsize, noshrink):
+        num = self.convert_to_bytes(newsize)
+        if num is not None:
+            newsize = num
+
         try:
             newsize = int(newsize)
             if newsize <= 0: