def getLeaseStatus(self): sd_manifest = sdCache.produce_manifest(self.sdUUID) if not sd_manifest.hasVolumeLeases(): return sc.LEASE_UNSUPPORTED ver, host_id = sd_manifest.inquireVolumeLease(self.imgUUID, self.volUUID) return sc.LEASE_FREE if host_id is None else sc.LEASE_EXCLUSIVE
def getVolumeSize(self, bs=BLOCK_SIZE): """ Return the volume size in blocks """ # Just call the SD Manifest method getVSize() - apparently it does what # we need. We consider incurred overhead of producing the object # to be a small price for code de-duplication. manifest = sdCache.produce_manifest(self.sdUUID) return int(manifest.getVSize(self.imgUUID, self.volUUID) / bs)
def newVolumeLease(cls, metaId, sdUUID, volUUID): cls.log.debug( "Initializing volume lease volUUID=%s sdUUID=%s, " "metaId=%s", volUUID, sdUUID, metaId) manifest = sdCache.produce_manifest(sdUUID) metaSdUUID, mdSlot = metaId leasePath = manifest.getLeasesFilePath() leaseOffset = ((mdSlot + RESERVED_LEASES) * manifest.logBlkSize * sd.LEASE_BLOCKS) sanlock.init_resource(sdUUID, volUUID, [(leasePath, leaseOffset)])
def validateImagePath(self): """ Validate that the image dir exists and valid. In the file volume repositories, the image dir must exists after creation its first volume. """ manifest = sdCache.produce_manifest(self.sdUUID) imageDir = manifest.getImageDir(self.imgUUID) if not self.oop.os.path.isdir(imageDir): raise se.ImagePathError(imageDir) if not self.oop.os.access(imageDir, os.R_OK | os.W_OK | os.X_OK): raise se.ImagePathError(imageDir) self._imagePath = imageDir
def getLeaseStatus(self): sd_manifest = sdCache.produce_manifest(self.sdUUID) if not sd_manifest.hasVolumeLeases(): return None # Version is always None when a lease is not acquired, although sanlock # always report the version. The clusterlock should be fixed to match # the schema. try: version, host_id = sd_manifest.inquireVolumeLease(self.imgUUID, self.volUUID) except clusterlock.InvalidLeaseName as e: self.log.warning("Cannot get lease status: %s", e) return None # TODO: Move this logic to clusterlock and fix callers to handle list # of owners instead of None. owners = [host_id] if host_id is not None else [] return dict(owners=owners, version=version)
def validateImagePath(self): """ Block SD supports lazy image dir creation """ manifest = sdCache.produce_manifest(self.sdUUID) imageDir = manifest.getImageDir(self.imgUUID) # Image directory may be a symlink to /run/vdsm/storage/sd/image # created when preparing an image before starting a vm. if os.path.islink(imageDir) and not os.path.exists(imageDir): self.log.warning("Removing stale image directory link %r", imageDir) os.unlink(imageDir) if not os.path.isdir(imageDir): try: os.mkdir(imageDir, 0o755) except Exception: self.log.exception("Unexpected error") raise se.ImagePathError(imageDir) self._imagePath = imageDir
def release(self): dom = sdCache.produce_manifest(self._sd_id) dom.releaseVolumeLease(self._img_id, self._vol_id)
def acquire(self): dom = sdCache.produce_manifest(self._sd_id) dom.acquireVolumeLease(self._host_id, self._img_id, self._vol_id)