From: Dhairya Parmar Date: Mon, 17 Mar 2025 14:53:22 +0000 (+0530) Subject: mgr/volumes: accept unit with subvolume resize X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=efe11565b8596ecaaca82201b5e240e97b680e51;p=ceph.git mgr/volumes: accept unit with subvolume resize Specifying the quota or resize for a subvolume requires the value in bytes. This value can now be accepted as . Also allows floating point numbers. Fixes: https://tracker.ceph.com/issues/62673 Signed-off-by: Dhairya Parmar --- diff --git a/src/pybind/mgr/volumes/fs/operations/versions/subvolume_base.py b/src/pybind/mgr/volumes/fs/operations/versions/subvolume_base.py index 5ceb9bcc2bc3..c07d7bcfc27d 100644 --- a/src/pybind/mgr/volumes/fs/operations/versions/subvolume_base.py +++ b/src/pybind/mgr/volumes/fs/operations/versions/subvolume_base.py @@ -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: