def shrink_share(self, share, new_size, share_server=None): server_details = share_server['backend_details'] helper = self._get_helper(share) export_location = share['export_locations'][0]['path'] mount_path = helper.get_share_path_by_export_location( server_details, export_location) consumed_space = self._get_consumed_space(mount_path, server_details) LOG.debug("Consumed space on share: %s", consumed_space) if consumed_space >= new_size: raise exception.ShareShrinkingPossibleDataLoss( share_id=share['id']) volume = self._get_volume(self.admin_context, share['id']) helper.disable_access_for_maintenance(server_details, share['name']) self._unmount_device(share, server_details) try: self._resize_filesystem(server_details, volume, new_size=new_size) except exception.Invalid: raise exception.ShareShrinkingPossibleDataLoss( share_id=share['id']) except Exception as e: msg = _("Cannot shrink share: %s") % six.text_type(e) raise exception.Invalid(msg) finally: self._mount_device(share, server_details, volume) helper.restore_access_after_maintenance(server_details, share['name'])
def shrink_share(self, share, new_size, share_server=None): """Shrink a sub-directory/share in the GlusterFS volume.""" usage = self._get_directory_usage(share) consumed_limit = int(math.ceil(usage)) if consumed_limit > new_size: raise exception.ShareShrinkingPossibleDataLoss( share_id=share['id']) self._set_directory_quota(share, new_size)
def shrink_filesystem(self, share_id, fs, new_size_gb): size = utils.gib_to_byte(new_size_gb) try: fs.shrink(size, user_cap=True) except storops_ex.UnityNothingToModifyError: LOG.debug('The size of the file system %(id)s is %(size)s ' 'bytes.', {'id': fs.get_id(), 'size': size}) except storops_ex.UnityShareShrinkSizeTooSmallError: LOG.error('The used size of the file system %(id)s is ' 'bigger than input shrink size,' 'it may cause date loss.', {'id': fs.get_id()}) raise exception.ShareShrinkingPossibleDataLoss(share_id=share_id) return size
def test_shrink_share_over_consumed(self): self.mock_object( self.driver, "_resize_share", mock.Mock(side_effect=exception.ShareShrinkingPossibleDataLoss( share_id=test_nfs_share["id"])), ) self.assertRaises( exception.ShareShrinkingPossibleDataLoss, self.driver.shrink_share, test_nfs_share, _MOCK_SHARE_SIZE / 2, )
def shrink_share(self, share, new_size, share_server=None): LOG.debug("shrink_share {id} {size}".format( id=share['id'], size=new_size)) new_bytes = self._to_bytes(new_size) used = self.volume_client.get_used_bytes(self._share_path(share)) if used > new_bytes: # While in fact we can "shrink" our volumes to less than their # used bytes (it's just a quota), raise error anyway to avoid # confusing API consumers that might depend on typical shrink # behaviour. raise exception.ShareShrinkingPossibleDataLoss( share_id=share['id']) self.volume_client.set_max_bytes(self._share_path(share), new_bytes)
def _resize_share(self, share, new_size): dataset_name = self._make_share_name(share) self._get_flashblade_filesystem_by_name(dataset_name) consumed_size = (self._sys.file_systems.list_file_systems( names=[dataset_name]).items[0].space.virtual) attr = {} if consumed_size >= new_size * units.Gi: raise exception.ShareShrinkingPossibleDataLoss( share_id=share["id"]) attr["provisioned"] = new_size * units.Gi n_attr = purity_fb.FileSystem(**attr) LOG.debug("Resizing filesystem...") self._sys.file_systems.update_file_systems(name=dataset_name, attributes=n_attr)
def shrink_share(self, share, new_size, share_server=None): """Shrinks size of existing share.""" LOG.debug( 'Shrinking share: %(name)s to %(size)sG.', { 'name': share['name'], 'size': new_size}) url = 'storage/pools/{}/filesystems/{}%2F{}'.format(self.pool_name, self.fs_prefix, share['name']) used = self.nef.get(url)['bytesUsed'] / units.Gi if used > new_size: raise exception.ShareShrinkingPossibleDataLoss( share_id=share['id']) self._set_quota(share['name'], new_size) self.provisioned_capacity += (share['size'] - new_size)
def shrink_share(self, share, new_size, share_server=None): """Shrinks size of existing share.""" LOG.debug( 'Shrinking share: %(name)s to %(size)sG.', { 'name': self._get_share_name(share), 'size': new_size}) share_path = self._get_dataset_path(share) share_data = self.nef.filesystems.get(share_path) used = share_data['bytesUsedBySelf'] / units.Gi if used > new_size: raise exception.ShareShrinkingPossibleDataLoss( share_id=self._get_share_name(share)) if not self.configuration.nexenta_thin_provisioning: self._set_reservation(share, new_size) self._set_quota(share, new_size) self.provisioned_capacity += (share['size'] - new_size)
def _set_share_size(self, share, size): volume_name = self._get_volume_name(context.get_admin_context(), share) try: if share['size'] > size: info = self._maprfs_util.get_volume_info(volume_name) used = info['totalused'] if int(used) >= int(size) * units.Ki: raise exception.ShareShrinkingPossibleDataLoss( share_id=share['id']) self._maprfs_util.set_volume_size(volume_name, size) except exception.ProcessExecutionError: msg = (_('Failed to set space quota for the share %(share_name)s.') % {'share_name': share['name']}) LOG.exception(msg) raise exception.MapRFSException(msg=msg)
def _shrink_share(self, share_id, old_size, new_size): """Shrinks a share to new size. :param share_id: ID of share that will be shrunk. :param old_size: Current size of share that will be shrunk. :param new_size: New size of share after shrink operation. """ self._ensure_share(share_id) usage = self.hnas.get_share_usage(share_id) LOG.debug("Usage space in share %(share)s: %(usage)sG", { 'share': share_id, 'usage': usage }) if new_size > usage: self.hnas.modify_quota(share_id, new_size) else: raise exception.ShareShrinkingPossibleDataLoss(share_id=share_id)
def shrink_share(self, share, new_size, share_server=None): """Shrink a share to new_size.""" lcfg = self.configuration details = self.zfssa.get_share(lcfg.zfssa_pool, lcfg.zfssa_project, share['id']) used_space = details['space_data'] new_size_byte = int(new_size) * units.Gi if used_space > new_size_byte: LOG.error('%(used).1fGB of share %(id)s is already used. ' 'Cannot shrink to %(newsize)dGB.', {'used': float(used_space) / units.Gi, 'id': share['id'], 'newsize': new_size}) raise exception.ShareShrinkingPossibleDataLoss( share_id=share['id']) arg = self.create_arg(new_size) self.zfssa.modify_share(lcfg.zfssa_pool, lcfg.zfssa_project, share['id'], arg)
def shrink_share(self, share, new_size, share_server=None): LOG.debug("Shrinking share in HSP: %(shr_id)s.", {'shr_id': share['id']}) file_system = self.hsp.get_file_system(share['id']) usage = file_system['properties']['used-capacity'] / units.Gi LOG.debug("Usage for share %(shr_id)s in HSP: %(usage)sG.", { 'shr_id': share['id'], 'usage': usage }) if new_size > usage: self.hsp.resize_file_system(file_system['id'], new_size * units.Gi) else: raise exception.ShareShrinkingPossibleDataLoss( share_id=share['id']) LOG.info("Share %(shr_id)s successfully shrunk to " "%(shr_size)sG.", { 'shr_id': share['id'], 'shr_size': new_size })
def shrink_share(self, share, new_size, share_server=None): # resize FS subvolume/share LOG.debug("[%(be)s]: shrink_share: share=%(id)s, size=%(sz)s.", { "be": self.backend_name, "id": share['id'], "sz": new_size }) argdict = { "vol_name": self.volname, "sub_name": share["id"], "new_size": self._to_bytes(new_size), "no_shrink": True, } if share["share_group_id"] is not None: argdict.update({"group_name": share["share_group_id"]}) try: rados_command(self.rados_client, "fs subvolume resize", argdict) except exception.ShareBackendException as e: if 'would be lesser than' in str(e).lower(): raise exception.ShareShrinkingPossibleDataLoss( share_id=share['id']) raise
def shrink_share(self, share, new_size, share_server=None): pool_name = share_utils.extract_host(share['host'], level='pool') pool_data = self._get_share_pool_data(pool_name) share_name = share['id'].replace('-', '') folder_name = self._extract_lv_name(pool_data) command_line = ['fquota', 'status', pool_data['id'], folder_name, '-t', 'folder'] rc, quota_status = self._execute(command_line) for share_quota in quota_status: if share_quota['name'] == share_name: used_space = round(_bi_to_gi(float(share_quota['used'])), 2) if new_size < used_space: raise exception.ShareShrinkingPossibleDataLoss( share_id=share['id']) self._set_share_size(pool_data['id'], pool_name, share_name, new_size) LOG.info('Successfully Shrink Share [%(share)s] ' 'to size [%(new_size)s G].', { 'share': share['id'], 'new_size': new_size})