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.
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:
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
'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",