]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/volumes: fs subvolume resize inf/infinite command
authorJos Collin <jcollin@redhat.com>
Fri, 25 Oct 2019 10:19:32 +0000 (15:49 +0530)
committerJos Collin <jcollin@redhat.com>
Thu, 7 Nov 2019 12:38:43 +0000 (18:08 +0530)
Resize a subvolume infinitely by unsetting the
subvolume quota.

Fixes: https://tracker.ceph.com/issues/42479
Signed-off-by: Jos Collin <jcollin@redhat.com>
src/pybind/mgr/volumes/fs/subvolume.py
src/pybind/mgr/volumes/fs/volume.py
src/pybind/mgr/volumes/module.py

index 30b69f59091cbff5b4fe2893815ac21667dde8c3..7f5780ffed39506af9dd0d25e42eb334b6dcd6ab 100644 (file)
@@ -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.
index a37ec1affa8eddcc61661f201bc3edd076a5c0a8..cf9bd059613a6db889b5db97d0c5323b76b80f89 100644 (file)
@@ -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
index 194be3465f7a41afa0e5e3d565de0f1af16f9ad0..121f3f8a3db51c460c4200e6a5a848c1d308eecd 100644 (file)
@@ -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",