def deflate(lvmCache, lvName, size): """Shrink the LV and the VHD on it to 'size'. Does not change the virtual size of the VDI""" currSizeLV = lvmCache.getSize(lvName) newSize = calcSizeLV(size) if newSize >= currSizeLV: return path = os.path.join(VG_LOCATION, lvmCache.vgName, lvName) # no undo necessary if this fails at any point between now and the end vhdutil.setSizePhys(path, newSize) lvmCache.setSize(lvName, newSize)
def inflate(journaler, srUuid, vdiUuid, size): """Expand a VDI LV (and its VHD) to 'size'. If the LV is already bigger than that, it's a no-op. Does not change the virtual size of the VDI""" lvName = LV_PREFIX[vhdutil.VDI_TYPE_VHD] + vdiUuid vgName = VG_PREFIX + srUuid path = os.path.join(VG_LOCATION, vgName, lvName) lvmCache = journaler.lvmCache currSizeLV = lvmCache.getSize(lvName) newSize = calcSizeLV(size) if newSize <= currSizeLV: return journaler.create(JRN_INFLATE, vdiUuid, str(currSizeLV)) util.fistpoint.activate("LVHDRT_inflate_after_create_journal", srUuid) lvmCache.setSize(lvName, newSize) util.fistpoint.activate("LVHDRT_inflate_after_setSize", srUuid) util.zeroOut(path, newSize - vhdutil.VHD_FOOTER_SIZE, vhdutil.VHD_FOOTER_SIZE) util.fistpoint.activate("LVHDRT_inflate_after_zeroOut", srUuid) vhdutil.setSizePhys(path, newSize, False) util.fistpoint.activate("LVHDRT_inflate_after_setSizePhys", srUuid) journaler.remove(JRN_INFLATE, vdiUuid)
def resize(self, sr_uuid, vdi_uuid, size, online=False): """ Resize the given VDI to size <size>. Size can be any valid disk size greater than [or smaller than] the current value. :param sr_uuid: :param vdi_uuid: :param size: :param online: :return: """ if VERBOSE: util.SMlog( "rbdsr_vhd.RBDVHDVDI.resize: sr_uuid=%s, vdi_uuid=%s, size=%s" % (sr_uuid, vdi_uuid, size)) vdi_ref = self.session.xenapi.VDI.get_by_uuid(vdi_uuid) sm_config = self.session.xenapi.VDI.get_sm_config(vdi_ref) vdi_hostRefs = self._get_vdi_hostRefs(vdi_uuid) local_host_uuid = inventory.get_localhost_uuid() if 'attached' in sm_config and online is False: online = True raise xs_errors.XenError( 'VDIResize', opterr='Online resize is not supported in VHD mode') size = vhdutil.validate_and_round_vhd_size(long(size)) if self.sr.provision == "thin": rbdSizeNew = lvhdutil.calcSizeVHDLV(size) elif self.sr.provision == "thick": rbdSizeNew = lvhdutil.calcSizeVHDLV(size) if online: retval = super(RBDVHDVDI, self).resize_online(sr_uuid, vdi_uuid, rbdSizeNew) else: retval = super(RBDVHDVDI, self).resize(sr_uuid, vdi_uuid, rbdSizeNew) if not online: # self._map_rbd(vdi_uuid, rbdSizeNew, norefcount=True) self.attach(sr_uuid, vdi_uuid, host_uuid=local_host_uuid) else: if local_host_uuid not in vdi_hostRefs: self.attach(sr_uuid, vdi_uuid, host_uuid=local_host_uuid) vhdutil.setSizePhys(self.path, size, False) vhdutil.setSizeVirtFast(self.path, size) if online: if not blktap2.VDI.tap_refresh(self.session, self.sr.uuid, vdi_uuid, True): raise util.SMException("failed to refresh VDI %s" % vdi_uuid) if not online: # self._unmap_rbd(vdi_uuid, rbdSizeNew, norefcount=True) self.detach(sr_uuid, vdi_uuid, host_uuid=local_host_uuid) else: if local_host_uuid not in vdi_hostRefs: self.detach(sr_uuid, vdi_uuid, host_uuid=local_host_uuid) self.size = size self.session.xenapi.VDI.set_virtual_size(vdi_ref, str(size)) self.session.xenapi.VDI.set_physical_utilisation(vdi_ref, str(size)) return retval