def resize_online(self, sr_uuid, vdi_uuid, size): if not self.exists: raise xs_errors.XenError('VDIUnavailable', \ opterr='VDI %s unavailable %s' % (vdi_uuid, self.path)) if self.vdi_type != vhdutil.VDI_TYPE_VHD: raise xs_errors.XenError('Unimplemented') if self.hidden: raise xs_errors.XenError('VDIUnavailable', opterr='hidden VDI') if size < self.size: util.SMlog('vdi_resize: shrinking not supported: ' + \ '(current size: %d, new size: %d)' % (self.size, size)) raise xs_errors.XenError('VDISize', opterr='shrinking not allowed') if size == self.size: return VDI.VDI.get_params(self) # We already checked it is a VDI_TYPE_VHD size = util.roundup(VHD_SIZE_INC, long(size)) overhead = vhdutil.calcOverheadFull(long(size)) # Check we are within the limits mb = 1024L * 1024L if size < mb or (size / mb) >= MAX_VHD_SIZE: raise xs_errors.XenError('VDISize', opterr='VDI size ' + 'must be between 1 MB and %d MB' % (MAX_VHD_SIZE)) # Test the amount of actual disk space if ENFORCE_VIRT_ALLOC: self.sr._loadvdis() reserved = self.sr.virtual_allocation sr_size = self.sr._getsize() delta = long(size - self.size) if (sr_size - reserved) < delta: raise xs_errors.XenError('SRNoSpace') jFile = JOURNAL_FILE_PREFIX + self.uuid try: vhdutil.setSizeVirt(self.path, size, jFile) except: # Revert the operation vhdutil.revert(self.path, jFile) raise xs_errors.XenError('VDISize', opterr='resize operation failed') old_size = self.size self.size = vhdutil.getSizeVirt(self.path) st = util.ioretry(lambda: os.stat(self.path)) self.utilisation = long(st.st_size) self._db_update() self.sr._update(self.sr.uuid, self.size - old_size) return VDI.VDI.get_params(self)
def resize_online(self, sr_uuid, vdi_uuid, size): if not self.exists: raise xs_errors.XenError('VDIUnavailable', \ opterr='VDI %s unavailable %s' % (vdi_uuid, self.path)) if self.vdi_type != vhdutil.VDI_TYPE_VHD: raise xs_errors.XenError('Unimplemented') if self.hidden: raise xs_errors.XenError('VDIUnavailable', opterr='hidden VDI') if size < self.size: util.SMlog('vdi_resize: shrinking not supported: ' + \ '(current size: %d, new size: %d)' % (self.size, size)) raise xs_errors.XenError('VDISize', opterr='shrinking not allowed') if size == self.size: return VDI.VDI.get_params(self) # We already checked it is a VDI_TYPE_VHD size = util.roundup(VHD_SIZE_INC, long(size)) overhead = vhdutil.calcOverheadFull(long(size)) # Check we are within the limits mb = 1024L * 1024L if size < mb or (size / mb) >= MAX_VHD_SIZE: raise xs_errors.XenError('VDISize', opterr='VDI size ' + 'must be between 1 MB and %d MB' %(MAX_VHD_SIZE)) # Test the amount of actual disk space if ENFORCE_VIRT_ALLOC: self.sr._loadvdis() reserved = self.sr.virtual_allocation sr_size = self.sr._getsize() delta = long(size - self.size) if (sr_size - reserved) < delta: raise xs_errors.XenError('SRNoSpace') jFile = JOURNAL_FILE_PREFIX + self.uuid try: vhdutil.setSizeVirt(self.path, size, jFile) except: # Revert the operation vhdutil.revert(self.path, jFile) raise xs_errors.XenError('VDISize', opterr='resize operation failed') old_size = self.size self.size = vhdutil.getSizeVirt(self.path) st = util.ioretry(lambda: os.stat(self.path)) self.utilisation = long(st.st_size) self._db_update() self.sr._update(self.sr.uuid, self.size - old_size) return VDI.VDI.get_params(self)
def resize_online(self, sr_uuid, vdi_uuid, size): if not self.exists: raise xs_errors.XenError("VDIUnavailable", opterr="VDI %s unavailable %s" % (vdi_uuid, self.path)) if self.vdi_type != vhdutil.VDI_TYPE_VHD: raise xs_errors.XenError("Unimplemented") if self.hidden: raise xs_errors.XenError("VDIUnavailable", opterr="hidden VDI") if size < self.size: util.SMlog("vdi_resize: shrinking not supported: " + "(current size: %d, new size: %d)" % (self.size, size)) raise xs_errors.XenError("VDISize", opterr="shrinking not allowed") if size == self.size: return VDI.VDI.get_params(self) # We already checked it is a VDI_TYPE_VHD size = vhdutil.validate_and_round_vhd_size(long(size)) overhead = vhdutil.calcOverheadFull(long(size)) # Test the amount of actual disk space if ENFORCE_VIRT_ALLOC: self.sr._loadvdis() reserved = self.sr.virtual_allocation sr_size = self.sr._getsize() delta = long(size - self.size) if (sr_size - reserved) < delta: raise xs_errors.XenError("SRNoSpace") jFile = JOURNAL_FILE_PREFIX + self.uuid try: vhdutil.setSizeVirt(self.path, size, jFile) except: # Revert the operation vhdutil.revert(self.path, jFile) raise xs_errors.XenError("VDISize", opterr="resize operation failed") old_size = self.size self.size = vhdutil.getSizeVirt(self.path) st = util.ioretry(lambda: os.stat(self.path)) self.utilisation = long(st.st_size) self._db_update() self.sr._update(self.sr.uuid, self.size - old_size) return VDI.VDI.get_params(self)
def resize_online(self, sr_uuid, vdi_uuid, size): if not self.exists: raise xs_errors.XenError('VDIUnavailable', \ opterr='VDI %s unavailable %s' % (vdi_uuid, self.path)) if self.hidden: raise xs_errors.XenError('VDIUnavailable', opterr='hidden VDI') if size < self.size: util.SMlog('vdi_resize: shrinking not supported: ' + \ '(current size: %d, new size: %d)' % (self.size, size)) raise xs_errors.XenError('VDISize', opterr='shrinking not allowed') if size == self.size: return VDI.VDI.get_params(self) size = util.roundup(VHD_SIZE_INC, long(size)) # Test the amount of actual disk space if ENFORCE_VIRT_ALLOC: self.sr._loadvdis() reserved = self.sr.virtual_allocation sr_size = self.sr._getsize() delta = long(size - self.size) if (sr_size - reserved) < delta: raise xs_errors.XenError('SRNoSpace') jFile = JOURNAL_FILE_PREFIX + self.uuid try: vhdutil.setSizeVirt(self.path, size, jFile) except: # Revert the operation vhdutil.revert(self.path, jFile) raise xs_errors.XenError('VDISize', opterr='resize operation failed') old_size = self.size self.size = vhdutil.getSizeVirt(self.path) st = util.ioretry(lambda: os.stat(self.path)) self.utilisation = long(st.st_size) self._db_update() self.sr._update(self.sr.uuid, self.size - old_size) return VDI.VDI.get_params(self)