def _create_metadata_artifact(self, size, vol_format, prealloc, disk_type, desc, parent): if self._oop.fileUtils.pathExists(self.meta_path): raise se.VolumeAlreadyExists("metadata exists: %r" % self.meta_path) if self._oop.fileUtils.pathExists(self.meta_volatile_path): raise se.DomainHasGarbage("metadata artifact exists: %r" % self.meta_volatile_path) parent_vol_id = parent.vol_id if parent else sc.BLANK_UUID # Create the metadata artifact. The metadata file is created with a # special extension to prevent these artifacts from being recognized as # a volume until FileVolumeArtifacts.commit() is called. meta = VolumeMetadata( self.sd_manifest.sdUUID, self.img_id, parent_vol_id, size / sc.BLOCK_SIZE, # Size is stored as number of blocks sc.type2name(vol_format), sc.type2name(prealloc), sc.type2name(sc.LEAF_VOL), disk_type, desc, sc.LEGAL_VOL) self._oop.writeFile(self.meta_volatile_path, meta.storage_format())
def commit(self): lv = lvm.getLV(self.sd_manifest.sdUUID, self.vol_id) if sc.TEMP_VOL_LVTAG not in lv.tags: raise se.VolumeAlreadyExists("LV %r has already been committed" % self.vol_id) lvm.changeLVTags(self.sd_manifest.sdUUID, self.vol_id, delTags=(sc.TEMP_VOL_LVTAG,))
def _create(cls, dom, imgUUID, volUUID, size, volFormat, preallocate, volParent, srcImgUUID, srcVolUUID, volPath, initialSize=None): """ Class specific implementation of volumeCreate. All the exceptions are properly handled and logged in volume.create() """ if initialSize: cls.log.error("initialSize is not supported for file-based " "volumes") raise se.InvalidParameterException("initial size", initialSize) sizeBytes = size * BLOCK_SIZE truncSize = sizeBytes if volFormat == sc.RAW_FORMAT else 0 try: oop.getProcessPool(dom.sdUUID).truncateFile( volPath, truncSize, mode=sc.FILE_VOLUME_PERMISSIONS, creatExcl=True) except OSError as e: if e.errno == errno.EEXIST: raise se.VolumeAlreadyExists(volUUID) raise if preallocate == sc.PREALLOCATED_VOL: try: operation = fallocate.allocate(volPath, sizeBytes) with vars.task.abort_callback(operation.abort): with utils.stopwatch("Preallocating volume %s" % volPath): operation.run() except exception.ActionStopped: raise except Exception: cls.log.error("Unexpected error", exc_info=True) raise se.VolumesZeroingError(volPath) if not volParent: cls.log.info("Request to create %s volume %s with size = %s " "sectors", sc.type2name(volFormat), volPath, size) if volFormat == sc.COW_FORMAT: qemuimg.create(volPath, size=sizeBytes, format=sc.fmt2str(volFormat), qcow2Compat=dom.qcow2_compat()) else: # Create hardlink to template and its meta file cls.log.info("Request to create snapshot %s/%s of volume %s/%s", imgUUID, volUUID, srcImgUUID, srcVolUUID) volParent.clone(volPath, volFormat) # Forcing the volume permissions in case one of the tools we use # (dd, qemu-img, etc.) will mistakenly change the file permissiosn. dom.oop.os.chmod(volPath, sc.FILE_VOLUME_PERMISSIONS) return (volPath,)
def _truncate_volume(cls, vol_path, capacity, vol_id, dom): try: oop.getProcessPool(dom.sdUUID).truncateFile( vol_path, capacity, mode=sc.FILE_VOLUME_PERMISSIONS, creatExcl=True) except OSError as e: if e.errno == errno.EEXIST: raise se.VolumeAlreadyExists(vol_id) raise
def commit(self): try: self._oop.os.rename(self.meta_volatile_path, self.meta_path) except OSError as e: if e.errno == errno.EEXIST: raise se.VolumeAlreadyExists("Path %r exists", self.meta_path) raise # If we created a new image directory, rename it to the correct name if not self.is_image(): self._oop.os.rename(self.artifacts_dir, self._image_dir)
def _create_lv_artifact(self, parent, lv_size): try: lv = lvm.getLV(self.sd_manifest.sdUUID, self.vol_id) except se.LogicalVolumeDoesNotExistError: pass else: if sc.TEMP_VOL_LVTAG in lv.tags: raise se.DomainHasGarbage("Logical volume artifact %s exists" % self.vol_id) else: raise se.VolumeAlreadyExists("Logical volume %s exists" % self.vol_id) parent_vol_id = parent.vol_id if parent else sc.BLANK_UUID tags = (sc.TEMP_VOL_LVTAG, sc.TAG_PREFIX_PARENT + parent_vol_id, sc.TAG_PREFIX_IMAGE + self.img_id) lvm.createLV(self.sd_manifest.sdUUID, self.vol_id, lv_size, activate=True, initialTags=tags)