def validate(self): if self.base_id not in self.chain: raise se.VolumeIsNotInChain(self.sd_id, self.img_id, self.base_id) if self.top_id not in self.chain: raise se.VolumeIsNotInChain(self.sd_id, self.img_id, self.top_id) # Validate that top volume is the parent of the base. if self.top_vol.getParent() != self.base_id: raise se.WrongParentVolume(self.base_id, self.top_id) if self.base_vol.isShared(): raise se.SharedVolumeNonWritable(self.base_vol) if self.top_vol.isShared(): raise se.SharedVolumeNonWritable(self.top_vol)
def prepare(self, rw=True, justme=False, chainrw=False, setrw=False, force=False): """ Prepare volume for use by consumer. If justme is false, the entire COW chain is prepared. Note: setrw arg may be used only by SPM flows. """ self.log.info("Volume: preparing volume %s/%s", self.sdUUID, self.volUUID) if not force: # Cannot prepare ILLEGAL volume if not self.isLegal(): raise se.prepareIllegalVolumeError(self.volUUID) if rw and self.isShared(): if chainrw: rw = False # Shared cannot be set RW else: raise se.SharedVolumeNonWritable(self) if (not chainrw and rw and self.isInternal() and setrw and not self.recheckIfLeaf()): raise se.InternalVolumeNonWritable(self) self.llPrepare(rw=rw, setrw=setrw) self.updateInvalidatedSize() try: if justme: return True pvol = self.getParentVolume() if pvol: pvol.prepare(rw=chainrw, justme=False, chainrw=chainrw, setrw=setrw) except Exception: self.log.error("Unexpected error", exc_info=True) self.teardown(self.sdUUID, self.volUUID) raise return True