def create(self, sr_uuid, vdi_uuid, size): if util.ioretry(lambda: util.pathexists(self.path)): raise xs_errors.XenError('VDIExists') overhead = 0 if self.vdi_type == vhdutil.VDI_TYPE_VHD: 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() if (sr_size - reserved) < (long(size) + overhead): raise xs_errors.XenError('SRNoSpace') if self.vdi_type == vhdutil.VDI_TYPE_VHD: try: mb = 1024L * 1024L size_mb = util.roundup(VHD_SIZE_INC, long(size)) / mb if size_mb < 1 or (size_mb + (overhead / mb)) >= MAX_DISK_MB: raise xs_errors.XenError('VDISize', opterr='VDI size ' + \ 'must be between 1 MB and %d MB' % \ ((MAX_DISK_MB - MAX_DISK_METADATA) - 1)) util.ioretry(lambda: self._create(str(size_mb), self.path)) self.size = util.ioretry(lambda: self._query_v(self.path)) except util.CommandException, inst: raise xs_errors.XenError('VDICreate', opterr='error %d' % inst.code)
def create(self, sr_uuid, vdi_uuid, size): if util.ioretry(lambda: util.pathexists(self.path)): raise xs_errors.XenError('VDIExists') overhead = 0 if self.vdi_type == vhdutil.VDI_TYPE_VHD: 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() if (sr_size - reserved) < (long(size) + overhead): raise xs_errors.XenError('SRNoSpace') if self.vdi_type == vhdutil.VDI_TYPE_VHD: try: size = vhdutil.validate_and_round_vhd_size(long(size)) mb = 1024L * 1024L size_mb = long(size) / mb util.ioretry(lambda: self._create(str(size_mb), self.path)) self.size = util.ioretry(lambda: self._query_v(self.path)) except util.CommandException, inst: raise xs_errors.XenError('VDICreate', opterr='error %d' % inst.code)
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 create(self, sr_uuid, vdi_uuid, size): if util.ioretry(lambda: util.pathexists(self.path)): raise xs_errors.XenError('VDIExists') # Test the amount of actual disk space if ENFORCE_VIRT_ALLOC: self.sr._loadvdis() reserved = self.sr.virtual_allocation sr_size = self.sr._getsize() if (sr_size - reserved) < \ (long(size) + vhdutil.calcOverheadFull(long(size))): raise xs_errors.XenError('SRNoSpace') try: mb = 1024L * 1024L size_mb = util.roundup(VHD_SIZE_INC, long(size)) / mb # round up metasize = vhdutil.calcOverheadFull(long(size)) assert(size_mb > 0) assert((size_mb + (metasize/(1024*1024))) < MAX_DISK_MB) util.ioretry(lambda: self._create(str(size_mb), self.path)) self.size = util.ioretry(lambda: self._query_v(self.path)) except util.CommandException, inst: raise xs_errors.XenError('VDICreate', opterr='error %d' % inst.code)
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 create(self, sr_uuid, vdi_uuid, size): if util.ioretry(lambda: util.pathexists(self.path)): raise xs_errors.XenError('VDIExists') overhead = 0 if self.vdi_type == vhdutil.VDI_TYPE_VHD: 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() if (sr_size - reserved) < (long(size) + overhead): raise xs_errors.XenError('SRNoSpace') if self.vdi_type == vhdutil.VDI_TYPE_VHD: try: size = vhdutil.validate_and_round_vhd_size(long(size)) mb = 1024 * 1024 size_mb = long(size) / mb util.ioretry(lambda: self._create(str(size_mb), self.path)) self.size = util.ioretry(lambda: self._query_v(self.path)) except util.CommandException as inst: raise xs_errors.XenError('VDICreate', opterr='error %d' % inst.code) else: f = open(self.path, 'w') f.truncate(long(size)) f.close() self.size = size self.sr.added_vdi(self) st = util.ioretry(lambda: os.stat(self.path)) self.utilisation = long(st.st_size) if self.vdi_type == vhdutil.VDI_TYPE_RAW: self.sm_config = {"type": self.PARAM_RAW} self._db_introduce() self.sr._update(self.sr.uuid, self.size) return super(FileVDI, self).get_params()
def getOverheadVHDFull(virtSize): return vhdutil.calcOverheadFull(virtSize)