From: Jos Collin Date: Fri, 25 Oct 2019 10:19:32 +0000 (+0530) Subject: mgr/volumes: fs subvolume resize inf/infinite command X-Git-Tag: v15.1.0~927^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c809b57412b6ec978bce424dd2ac628da2804fbc;p=ceph-ci.git mgr/volumes: fs subvolume resize inf/infinite command Resize a subvolume infinitely by unsetting the subvolume quota. Fixes: https://tracker.ceph.com/issues/42479 Signed-off-by: Jos Collin --- diff --git a/src/pybind/mgr/volumes/fs/subvolume.py b/src/pybind/mgr/volumes/fs/subvolume.py index 30b69f59091..7f5780ffed3 100644 --- a/src/pybind/mgr/volumes/fs/subvolume.py +++ b/src/pybind/mgr/volumes/fs/subvolume.py @@ -172,6 +172,24 @@ class SubVolume(object): raise VolumeException(-e.args[0], "Cannot set new size for the subvolume. '{0}'".format(e.args[1])) return newsize, subvolstat.st_size + def resize_infinite(self, subvolpath, newsize): + """ + :param subvolpath: the subvolume path + :param newsize: the string inf + :return: new quota size and used bytes as a tuple + """ + + if not (newsize == "inf" or newsize == "infinite"): + raise VolumeException(-errno.EINVAL, "Invalid parameter '{0}'".format(newsize)) + + subvolstat = self.fs.stat(subvolpath) + size = 0 + try: + self.fs.setxattr(subvolpath, 'ceph.quota.max_bytes', str(size).encode('utf-8'), 0) + except Exception as e: + raise VolumeException(-errno.ENOENT, "Cannot resize the subvolume to infinite size. '{0}'".format(e.args[1])) + return size, subvolstat.st_size + def purge_subvolume(self, spec, should_cancel): """ Finish clearing up a subvolume from the trash directory. diff --git a/src/pybind/mgr/volumes/fs/volume.py b/src/pybind/mgr/volumes/fs/volume.py index a37ec1affa8..cf9bd059613 100644 --- a/src/pybind/mgr/volumes/fs/volume.py +++ b/src/pybind/mgr/volumes/fs/volume.py @@ -428,7 +428,6 @@ class VolumeClient(object): subvolname = kwargs['sub_name'] newsize = kwargs['new_size'] groupname = kwargs['group_name'] - noshrink = kwargs['no_shrink'] try: with SubVolume(self.mgr, fs_handle) as sv: @@ -442,9 +441,18 @@ class VolumeClient(object): raise VolumeException( -errno.ENOENT, "Subvolume '{0}' not found, create it with " \ "'ceph fs subvolume create' before resizing subvolumes".format(subvolname)) - nsize, usedbytes = sv.resize_subvolume(subvolpath, newsize, noshrink) - ret = 0, json.dumps([{'bytes_used': usedbytes},{'bytes_quota': nsize}, - {'bytes_pcent': '{0:.2f}'.format((float(usedbytes) / nsize) * 100.0)}], indent=2), "" + + try: + newsize = int(newsize) + except ValueError: + newsize = newsize.lower() + nsize, usedbytes = sv.resize_infinite(subvolpath, newsize) + ret = 0, json.dumps([{'bytes_used': usedbytes}, {'bytes_quota': nsize}, {'bytes_pcent': "undefined"}], indent=2), "" + else: + noshrink = kwargs['no_shrink'] + nsize, usedbytes = sv.resize_subvolume(subvolpath, newsize, noshrink) + ret = 0, json.dumps([{'bytes_used': usedbytes}, {'bytes_quota': nsize}, + {'bytes_pcent': '{0:.2f}'.format((float(usedbytes) / nsize) * 100.0)}], indent=2), "" except VolumeException as ve: ret = self.volume_exception_to_retval(ve) return ret diff --git a/src/pybind/mgr/volumes/module.py b/src/pybind/mgr/volumes/module.py index 194be3465f7..121f3f8a3db 100644 --- a/src/pybind/mgr/volumes/module.py +++ b/src/pybind/mgr/volumes/module.py @@ -153,7 +153,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): 'cmd': 'fs subvolume resize ' 'name=vol_name,type=CephString ' 'name=sub_name,type=CephString ' - 'name=new_size,type=CephInt,req=true ' + 'name=new_size,type=CephString,req=true ' 'name=group_name,type=CephString,req=false ' 'name=no_shrink,type=CephBool,req=false ', 'desc': "Resize a CephFS subvolume",