Change in vdsm[master]: XXX: All outstanding VolumeMetadata changes squashed
alitke at redhat.com
alitke at redhat.com
Sat Dec 12 02:46:24 UTC 2015
Adam Litke has uploaded a new change for review.
Change subject: XXX: All outstanding VolumeMetadata changes squashed
......................................................................
XXX: All outstanding VolumeMetadata changes squashed
Change-Id: I5db8bb8bdf405b8760ecbe103dcbb1a1907ca1db
Signed-off-by: Adam Litke <alitke at redhat.com>
---
M vdsm/storage/blockVolume.py
M vdsm/storage/fileVolume.py
M vdsm/storage/volume.py
3 files changed, 338 insertions(+), 270 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/62/50362/1
diff --git a/vdsm/storage/blockVolume.py b/vdsm/storage/blockVolume.py
index cab02e2..a8de56a 100644
--- a/vdsm/storage/blockVolume.py
+++ b/vdsm/storage/blockVolume.py
@@ -30,6 +30,7 @@
import volume
import image
import sd
+import blockSD
import misc
from misc import logskip
from misc import deprecated
@@ -196,6 +197,18 @@
"""
return lvm.lvPath(self.sdUUID, self.volUUID)
+ 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(self.sdUUID).manifest
+ return int(manifest.getVSize(self.imgUUID, self.volUUID) / bs)
+
+ getVolumeTrueSize = getVolumeSize
+
def setMetadata(self, meta, metaId=None):
"""
Set the meta data hash as the new meta data of the Volume
@@ -270,6 +283,50 @@
# tags
self.setMetaParam(volume.IMAGE, imgUUID)
+ def removeMetadata(self, metaId):
+ """
+ Just wipe meta.
+ """
+ try:
+ self._putMetadata(metaId, {"NONE": "#" * (sd.METASIZE - 10)})
+ except Exception as e:
+ self.log.error(e, exc_info=True)
+ raise se.VolumeMetadataWriteError("%s: %s" % (metaId, e))
+
+ @classmethod
+ def newVolumeLease(cls, metaId, sdUUID, volUUID):
+ cls.log.debug("Initializing volume lease volUUID=%s sdUUID=%s, "
+ "metaId=%s", volUUID, sdUUID, metaId)
+ manifest = blockSD.BlockStorageDomainManifest(sdUUID)
+ metaSdUUID, mdSlot = metaId
+
+ leasePath = manifest.getLeasesFilePath()
+ leaseOffset = ((mdSlot + RESERVED_LEASES)
+ * manifest.logBlkSize * sd.LEASE_BLOCKS)
+
+ sanlock.init_resource(sdUUID, volUUID, [(leasePath, leaseOffset)])
+
+ def refreshVolume(self):
+ lvm.refreshLVs(self.sdUUID, (self.volUUID,))
+
+ def _share(self, dstImgPath):
+ """
+ Share this volume to dstImgPath
+ """
+ dstPath = os.path.join(dstImgPath, self.volUUID)
+
+ self.log.debug("Share volume %s to %s", self.volUUID, dstImgPath)
+ os.symlink(self._md.getDevPath(), dstPath)
+
+ @classmethod
+ def getImageVolumes(cls, repoPath, sdUUID, imgUUID):
+ """
+ Fetch the list of the Volumes UUIDs, not including the shared base
+ (template)
+ """
+ lvs = lvm.lvsByTag(sdUUID, "%s%s" % (TAG_PREFIX_IMAGE, imgUUID))
+ return [lv.name for lv in lvs]
+
class BlockVolume(volume.Volume):
""" Actually represents a single volume (i.e. part of virtual disk).
@@ -287,7 +344,7 @@
return self._md.metaoff
def refreshVolume(self):
- lvm.refreshLVs(self.sdUUID, (self.volUUID,))
+ self._md.refreshVolume()
@classmethod
def halfbakedVolumeRollback(cls, taskObj, sdUUID, volUUID, volPath):
@@ -434,7 +491,7 @@
self.recheckIfLeaf()
if not force:
- self.validateDelete()
+ self._md.validateDelete()
# Mark volume as illegal before deleting
self.setLegality(volume.ILLEGAL_VOL)
@@ -577,15 +634,6 @@
def getDevPath(self):
return self._md.getDevPath()
- def _share(self, dstImgPath):
- """
- Share this volume to dstImgPath
- """
- dstPath = os.path.join(dstImgPath, self.volUUID)
-
- self.log.debug("Share volume %s to %s", self.volUUID, dstImgPath)
- os.symlink(self._md.getDevPath(), dstPath)
-
@classmethod
def shareVolumeRollback(cls, taskObj, volPath):
cls.log.info("Volume rollback for volPath=%s", volPath)
@@ -654,54 +702,10 @@
@classmethod
def getImageVolumes(cls, repoPath, sdUUID, imgUUID):
- """
- Fetch the list of the Volumes UUIDs, not including the shared base
- (template)
- """
- lvs = lvm.lvsByTag(sdUUID, "%s%s" % (TAG_PREFIX_IMAGE, imgUUID))
- return [lv.name for lv in lvs]
-
- def removeMetadata(self, metaId):
- """
- Just wipe meta.
- """
- try:
- self._putMetadata(metaId, {"NONE": "#" * (sd.METASIZE - 10)})
- except Exception as e:
- self.log.error(e, exc_info=True)
- raise se.VolumeMetadataWriteError("%s: %s" % (metaId, e))
-
- @classmethod
- def createMetadata(cls, metaId, meta):
- cls._putMetadata(metaId, meta)
+ return BlockVolumeMetadata.getImageVolumes(repoPath, sdUUID, imgUUID)
def getMetaOffset(self):
return self._md.getMetaOffset()
-
- @classmethod
- def newVolumeLease(cls, metaId, sdUUID, volUUID):
- cls.log.debug("Initializing volume lease volUUID=%s sdUUID=%s, "
- "metaId=%s", volUUID, sdUUID, metaId)
- dom = sdCache.produce(sdUUID)
- metaSdUUID, mdSlot = metaId
-
- leasePath = dom.getLeasesFilePath()
- leaseOffset = ((mdSlot + RESERVED_LEASES)
- * dom.logBlkSize * sd.LEASE_BLOCKS)
-
- sanlock.init_resource(sdUUID, volUUID, [(leasePath, leaseOffset)])
-
- def getVolumeSize(self, bs=BLOCK_SIZE):
- """
- Return the volume size in blocks
- """
- # Just call the SD method getVSize() - apparently it does what
- # we need. We consider incurred overhead of producing the SD object
- # to be a small price for code de-duplication.
- sdobj = sdCache.produce(sdUUID=self.sdUUID)
- return int(sdobj.getVSize(self.imgUUID, self.volUUID) / bs)
-
- getVolumeTrueSize = getVolumeSize
def _extendSizeRaw(self, newSize):
# Since this method relies on lvm.extendLV (lvextend) when the
diff --git a/vdsm/storage/fileVolume.py b/vdsm/storage/fileVolume.py
index 0dabaea..bdfb771 100644
--- a/vdsm/storage/fileVolume.py
+++ b/vdsm/storage/fileVolume.py
@@ -190,6 +190,21 @@
"""
return self.getVolumePath()
+ def getVolumeSize(self, bs=BLOCK_SIZE):
+ """
+ Return the volume size in blocks
+ """
+ volPath = self.getVolumePath()
+ return int(int(self.oop.os.stat(volPath).st_size) / bs)
+
+ def getVolumeTrueSize(self, bs=BLOCK_SIZE):
+ """
+ Return the size of the storage allocated for this volume
+ on underlying storage
+ """
+ volPath = self.getVolumePath()
+ return int(int(self.oop.os.stat(volPath).st_blocks) * BLOCK_SIZE / bs)
+
def setMetadata(self, meta, metaId=None):
"""
Set the meta data hash as the new meta data of the Volume
@@ -238,6 +253,89 @@
Set image UUID
"""
self.setMetaParam(volume.IMAGE, imgUUID)
+
+ def removeMetadata(self):
+ """
+ Remove the meta file
+ """
+ metaPath = self._getMetaVolumePath()
+ if self.oop.os.path.lexists(metaPath):
+ self.log.debug("Removing: %s", metaPath)
+ self.oop.os.unlink(metaPath)
+
+ @classmethod
+ def _leaseVolumePath(cls, vol_path):
+ if vol_path:
+ return vol_path + LEASE_FILEEXT
+ else:
+ return None
+
+ @classmethod
+ def newVolumeLease(cls, metaId, sdUUID, volUUID):
+ cls.log.debug("Initializing volume lease volUUID=%s sdUUID=%s, "
+ "metaId=%s", volUUID, sdUUID, metaId)
+ volPath, = metaId
+ leasePath = cls._leaseVolumePath(volPath)
+ oop.getProcessPool(sdUUID).truncateFile(leasePath, LEASE_FILEOFFSET)
+ cls.file_setrw(leasePath, rw=True)
+ sanlock.init_resource(sdUUID, volUUID, [(leasePath,
+ LEASE_FILEOFFSET)])
+
+ def _getLeaseVolumePath(self, vol_path=None):
+ """
+ Get the volume lease file/link path
+ """
+ if not vol_path:
+ vol_path = self.getVolumePath()
+ return self._leaseVolumePath(vol_path)
+
+ def _shareLease(self, dstImgPath):
+ """
+ Internal utility method used to share the template volume lease file
+ with the images based on such template.
+ """
+ self.log.debug("Share volume lease of %s to %s", self.volUUID,
+ dstImgPath)
+ dstLeasePath = self._getLeaseVolumePath(
+ os.path.join(dstImgPath, self.volUUID))
+ self.oop.utils.forceLink(self._getLeaseVolumePath(), dstLeasePath)
+
+ def _share(self, dstImgPath):
+ """
+ Share this volume to dstImgPath, including the metadata and the lease
+ """
+ dstVolPath = os.path.join(dstImgPath, self.volUUID)
+ dstMetaPath = self._getMetaVolumePath(dstVolPath)
+
+ self.log.debug("Share volume %s to %s", self.volUUID, dstImgPath)
+ self.oop.utils.forceLink(self.getVolumePath(), dstVolPath)
+
+ self.log.debug("Share volume metadata of %s to %s", self.volUUID,
+ dstImgPath)
+ self.oop.utils.forceLink(self._getMetaVolumePath(), dstMetaPath)
+
+ # Link the lease file if the domain uses sanlock
+ if sdCache.produce(self.sdUUID).hasVolumeLeases():
+ self._shareLease(dstImgPath)
+
+ @classmethod
+ def getImageVolumes(cls, repoPath, sdUUID, imgUUID):
+ """
+ Fetch the list of the Volumes UUIDs,
+ not including the shared base (template)
+ """
+ # Get Volumes of an image
+ pattern = os.path.join(repoPath, sdUUID, sd.DOMAIN_IMAGES,
+ imgUUID, "*.meta")
+ files = oop.getProcessPool(sdUUID).glob.glob(pattern)
+ volList = []
+ for i in files:
+ volid = os.path.splitext(os.path.basename(i))[0]
+ if (sdCache.produce(sdUUID).
+ produceVolume(imgUUID, volid).
+ getImage() == imgUUID):
+ volList.append(volid)
+ return volList
class FileVolume(volume.Volume):
@@ -347,10 +445,10 @@
self.log.info("Request to delete volume %s", self.volUUID)
vol_path = self.getVolumePath()
- lease_path = self.__leaseVolumePath(vol_path)
+ lease_path = self._md._leaseVolumePath(vol_path)
if not force:
- self.validateDelete()
+ self._md.validateDelete()
# Mark volume as illegal before deleting
self.setLegality(volume.ILLEGAL_VOL)
@@ -390,42 +488,13 @@
raise eFound
- def _shareLease(self, dstImgPath):
- """
- Internal utility method used to share the template volume lease file
- with the images based on such template.
- """
- self.log.debug("Share volume lease of %s to %s", self.volUUID,
- dstImgPath)
- dstLeasePath = self._getLeaseVolumePath(
- os.path.join(dstImgPath, self.volUUID))
- self.oop.utils.forceLink(self._getLeaseVolumePath(), dstLeasePath)
-
- def _share(self, dstImgPath):
- """
- Share this volume to dstImgPath, including the metadata and the lease
- """
- dstVolPath = os.path.join(dstImgPath, self.volUUID)
- dstMetaPath = self._getMetaVolumePath(dstVolPath)
-
- self.log.debug("Share volume %s to %s", self.volUUID, dstImgPath)
- self.oop.utils.forceLink(self.getVolumePath(), dstVolPath)
-
- self.log.debug("Share volume metadata of %s to %s", self.volUUID,
- dstImgPath)
- self.oop.utils.forceLink(self._getMetaVolumePath(), dstMetaPath)
-
- # Link the lease file if the domain uses sanlock
- if sdCache.produce(self.sdUUID).hasVolumeLeases():
- self._shareLease(dstImgPath)
-
@classmethod
def shareVolumeRollback(cls, taskObj, volPath):
cls.log.info("Volume rollback for volPath=%s", volPath)
procPool = oop.getProcessPool(getDomUuidFromVolumePath(volPath))
procPool.utils.rmFile(volPath)
procPool.utils.rmFile(cls.metadataClass._metaVolumePath(volPath))
- procPool.utils.rmFile(cls.__leaseVolumePath(volPath))
+ procPool.utils.rmFile(cls.metadataClass._leaseVolumePath(volPath))
def llPrepare(self, rw=False, setrw=False):
"""
@@ -447,48 +516,9 @@
if not self.oop.os.access(volPath, os.R_OK):
raise se.VolumeAccessError(volPath)
- def removeMetadata(self):
- """
- Remove the meta file
- """
- metaPath = self._getMetaVolumePath()
- if self.oop.os.path.lexists(metaPath):
- self.log.debug("Removing: %s", metaPath)
- self.oop.os.unlink(metaPath)
-
- @classmethod
- def createMetadata(cls, metaId, meta):
- cls._putMetadata(metaId, meta)
-
@classmethod
def getImageVolumes(cls, repoPath, sdUUID, imgUUID):
- """
- Fetch the list of the Volumes UUIDs,
- not including the shared base (template)
- """
- # Get Volumes of an image
- pattern = os.path.join(repoPath, sdUUID, sd.DOMAIN_IMAGES,
- imgUUID, "*.meta")
- files = oop.getProcessPool(sdUUID).glob.glob(pattern)
- volList = []
- for i in files:
- volid = os.path.splitext(os.path.basename(i))[0]
- if (sdCache.produce(sdUUID).
- produceVolume(imgUUID, volid).
- getImage() == imgUUID):
- volList.append(volid)
- return volList
-
- @classmethod
- def newVolumeLease(cls, metaId, sdUUID, volUUID):
- cls.log.debug("Initializing volume lease volUUID=%s sdUUID=%s, "
- "metaId=%s", volUUID, sdUUID, metaId)
- volPath, = metaId
- leasePath = cls.__leaseVolumePath(volPath)
- oop.getProcessPool(sdUUID).truncateFile(leasePath, LEASE_FILEOFFSET)
- cls.file_setrw(leasePath, rw=True)
- sanlock.init_resource(sdUUID, volUUID, [(leasePath,
- LEASE_FILEOFFSET)])
+ return cls.metadataClass.getImageVolumes(repoPath, sdUUID, imgUUID)
def setParentMeta(self, puuid):
"""
@@ -559,23 +589,11 @@
self._md.volUUID = newUUID
self._md.volumePath = volPath
- @classmethod
- def __leaseVolumePath(cls, vol_path):
- if vol_path:
- return vol_path + LEASE_FILEEXT
- else:
- return None
-
def _getMetaVolumePath(self, vol_path=None):
return self._md._getMetaVolumePath(vol_path)
def _getLeaseVolumePath(self, vol_path=None):
- """
- Get the volume lease file/link path
- """
- if not vol_path:
- vol_path = self.getVolumePath()
- return self.__leaseVolumePath(vol_path)
+ return self._md._getLeaseVolumePath(vol_path)
def getVolumeSize(self, bs=BLOCK_SIZE):
"""
diff --git a/vdsm/storage/volume.py b/vdsm/storage/volume.py
index 46ce337..4cd89ef 100644
--- a/vdsm/storage/volume.py
+++ b/vdsm/storage/volume.py
@@ -282,6 +282,89 @@
def isSparse(self):
return self.getType() == SPARSE_VOL
+ def metadata2info(self, meta):
+ return {
+ "uuid": self.volUUID,
+ "type": meta.get(TYPE, ""),
+ "format": meta.get(FORMAT, ""),
+ "disktype": meta.get(DISKTYPE, ""),
+ "voltype": meta.get(VOLTYPE, ""),
+ "size": int(meta.get(SIZE, "0")),
+ "parent": self.getParent(),
+ "description": meta.get(DESCRIPTION, ""),
+ "pool": meta.get(sd.DMDK_POOLS, ""),
+ "domain": meta.get(DOMAIN, ""),
+ "image": self.getImage(),
+ "ctime": meta.get(CTIME, ""),
+ "mtime": "0",
+ "legality": meta.get(LEGALITY, ""),
+ }
+
+ def getInfo(self):
+ """
+ Get volume info
+ """
+ self.log.info("Info request: sdUUID=%s imgUUID=%s volUUID = %s ",
+ self.sdUUID, self.imgUUID, self.volUUID)
+ info = {}
+ try:
+ meta = self.getMetadata()
+ info = self.metadata2info(meta)
+ info["capacity"] = str(int(info["size"]) * BLOCK_SIZE)
+ del info["size"]
+ # Get the image actual size on disk
+ vsize = self.getVolumeSize(bs=1)
+ avsize = self.getVolumeTrueSize(bs=1)
+ info['apparentsize'] = str(vsize)
+ info['truesize'] = str(avsize)
+ info['status'] = "OK"
+ except se.StorageException as e:
+ self.log.debug("exception: %s:%s" % (str(e.message), str(e.value)))
+ info['apparentsize'] = "0"
+ info['truesize'] = "0"
+ info['status'] = "INVALID"
+
+ # Both engine and dumpStorageTable don't use this option so
+ # only keeping it to not break existing scripts that look for the key
+ info['children'] = []
+
+ # If image was set to illegal, mark the status same
+ # (because of VDC constraints)
+ if info.get('legality', None) == ILLEGAL_VOL:
+ info['status'] = ILLEGAL_VOL
+ self.log.info("%s/%s/%s info is %s",
+ self.sdUUID, self.imgUUID, self.volUUID, str(info))
+ return info
+
+ def getVolumeParams(self, bs=BLOCK_SIZE):
+ volParams = {}
+ volParams['volUUID'] = self.volUUID
+ volParams['imgUUID'] = self.getImage()
+ volParams['path'] = self.getVolumePath()
+ volParams['disktype'] = self.getDiskType()
+ volParams['prealloc'] = self.getType()
+ volParams['volFormat'] = self.getFormat()
+ # TODO: getSize returns size in 512b multiples, should move all sizes
+ # to byte multiples everywhere to avoid conversion errors and change
+ # only at the end
+ volParams['size'] = self.getSize()
+ volParams['apparentsize'] = self.getVolumeSize(bs=bs)
+ volParams['truesize'] = self.getVolumeTrueSize(bs=bs)
+ volParams['parent'] = self.getParent()
+ volParams['descr'] = self.getDescription()
+ volParams['legality'] = self.getLegality()
+ return volParams
+
+ def getVmVolumeInfo(self):
+ """
+ Get volume path/info as dict.
+ Derived classes can use this if they want to represent the
+ volume to the VM in a different way than the standard 'path' way.
+ """
+ # By default, send path
+ return {'volType': VmVolumeInfo.TYPE_PATH,
+ 'path': self.getVolumePath()}
+
def setMetaParam(self, key, value):
"""
Set a value of a specific key
@@ -416,9 +499,73 @@
def setFormat(self, volFormat):
self.setMetaParam(FORMAT, type2name(volFormat))
+ def validateDelete(self):
+ """
+ Validate volume before deleting
+ """
+ try:
+ if self.isShared():
+ raise se.CannotDeleteSharedVolume("img %s vol %s" %
+ (self.imgUUID, self.volUUID))
+ except se.MetaDataKeyNotFoundError as e:
+ # In case of metadata key error, we have corrupted
+ # volume (One of metadata corruptions may be
+ # previous volume deletion failure).
+ # So, there is no reasons to avoid its deletion
+ self.log.warn("Volume %s metadata error (%s)",
+ self.volUUID, str(e))
+ if self.getChildren():
+ raise se.VolumeImageHasChildren(self)
+
+ @classmethod
+ def createMetadata(cls, metaId, meta):
+ cls._putMetadata(metaId, meta)
+
+ @classmethod
+ def newMetadata(cls, metaId, sdUUID, imgUUID, puuid, size, format, type,
+ voltype, disktype, desc="", legality=ILLEGAL_VOL):
+ meta = {
+ FORMAT: str(format),
+ TYPE: str(type),
+ VOLTYPE: str(voltype),
+ DISKTYPE: str(disktype),
+ SIZE: int(size),
+ CTIME: int(time.time()),
+ sd.DMDK_POOLS: "", # obsolete
+ DOMAIN: str(sdUUID),
+ IMAGE: str(imgUUID),
+ DESCRIPTION: cls.validateDescription(desc),
+ PUUID: str(puuid),
+ MTIME: 0,
+ LEGALITY: str(legality),
+ }
+ cls.createMetadata(metaId, meta)
+ return meta
+
+ def refreshVolume(self):
+ pass
+
+ def _shareLease(self, dstImgPath):
+ """
+ Internal utility method used during the share process and by the
+ domain V3 upgrade.
+ """
+ pass # Do not remove this method or the V3 upgrade will fail.
+
+ def getParentVolume(self):
+ """
+ Return parent volume object
+ """
+ puuid = self.getParent()
+ if puuid and puuid != BLANK_UUID:
+ return sdCache.produce(self.sdUUID).produceVolume(self.imgUUID,
+ puuid)
+ return None
+
class Volume(object):
log = logging.getLogger('Storage.Volume')
+ metadataClass = VolumeMetadata
def __init__(self, md):
self._md = md
@@ -482,6 +629,12 @@
Set the read/write permission on the volume (deprecated)
"""
self._md._setrw(rw)
+
+ def removeMetadata(self):
+ self._md.removeMetadata()
+
+ def _share(self, dstImgPath):
+ return self._md._share(dstImgPath)
@classmethod
def formatMetadata(cls, meta):
@@ -620,11 +773,7 @@
raise se.CannotCloneVolume(self.volumePath, dstPath, str(e))
def _shareLease(self, dstImgPath):
- """
- Internal utility method used during the share process and by the
- domain V3 upgrade.
- """
- pass # Do not remove this method or the V3 upgrade will fail.
+ self._md._shareLease(dstImgPath)
def share(self, dstImgPath):
"""
@@ -653,10 +802,7 @@
raise se.CannotShareVolume(self.getVolumePath(), dstPath, str(e))
def refreshVolume(self):
- """
- Refresh volume
- """
- pass
+ return self._md.refreshVolume()
@classmethod
def parentVolumeRollback(cls, taskObj, sdUUID, pimgUUID, pvolUUID):
@@ -842,24 +988,6 @@
return volUUID
- def validateDelete(self):
- """
- Validate volume before deleting
- """
- try:
- if self.isShared():
- raise se.CannotDeleteSharedVolume("img %s vol %s" %
- (self.imgUUID, self.volUUID))
- except se.MetaDataKeyNotFoundError as e:
- # In case of metadata key error, we have corrupted
- # volume (One of metadata corruptions may be
- # previous volume deletion failure).
- # So, there is no reasons to avoid its deletion
- self.log.warn("Volume %s metadata error (%s)",
- self.volUUID, str(e))
- if self.getChildren():
- raise se.VolumeImageHasChildren(self)
-
def extend(self, newsize):
"""
Extend the apparent size of logical volume (thin provisioning)
@@ -985,6 +1113,12 @@
def getSize(self):
return self._md.getSize()
+ def getVolumeSize(self, bs=BLOCK_SIZE):
+ return self._md.getVolumeSize(bs)
+
+ def getVolumeTrueSize(self, bs=BLOCK_SIZE):
+ return self._md.getVolumeTrueSize(bs)
+
def setSize(self, size):
self._md.setSize(size)
@@ -1090,91 +1224,21 @@
"""
pass
- def metadata2info(self, meta):
- return {
- "uuid": self.volUUID,
- "type": meta.get(TYPE, ""),
- "format": meta.get(FORMAT, ""),
- "disktype": meta.get(DISKTYPE, ""),
- "voltype": meta.get(VOLTYPE, ""),
- "size": int(meta.get(SIZE, "0")),
- "parent": self.getParent(),
- "description": meta.get(DESCRIPTION, ""),
- "pool": meta.get(sd.DMDK_POOLS, ""),
- "domain": meta.get(DOMAIN, ""),
- "image": self.getImage(),
- "ctime": meta.get(CTIME, ""),
- "mtime": "0",
- "legality": meta.get(LEGALITY, ""),
- }
-
@classmethod
def newMetadata(cls, metaId, sdUUID, imgUUID, puuid, size, format, type,
voltype, disktype, desc="", legality=ILLEGAL_VOL):
- meta = {
- FORMAT: str(format),
- TYPE: str(type),
- VOLTYPE: str(voltype),
- DISKTYPE: str(disktype),
- SIZE: int(size),
- CTIME: int(time.time()),
- sd.DMDK_POOLS: "", # obsolete
- DOMAIN: str(sdUUID),
- IMAGE: str(imgUUID),
- DESCRIPTION: cls.validateDescription(desc),
- PUUID: str(puuid),
- MTIME: 0,
- LEGALITY: str(legality),
- }
-
- cls.createMetadata(metaId, meta)
- return meta
+ return cls.metadataClass.newMetadata(
+ metaId, sdUUID, imgUUID, puuid, size, format, type, voltype,
+ disktype, desc, legality)
def getInfo(self):
- """
- Get volume info
- """
- self.log.info("Info request: sdUUID=%s imgUUID=%s volUUID = %s ",
- self.sdUUID, self.imgUUID, self.volUUID)
- info = {}
- try:
- meta = self.getMetadata()
- info = self.metadata2info(meta)
- info["capacity"] = str(int(info["size"]) * BLOCK_SIZE)
- del info["size"]
- # Get the image actual size on disk
- vsize = self.getVolumeSize(bs=1)
- avsize = self.getVolumeTrueSize(bs=1)
- info['apparentsize'] = str(vsize)
- info['truesize'] = str(avsize)
- info['status'] = "OK"
- except se.StorageException as e:
- self.log.debug("exception: %s:%s" % (str(e.message), str(e.value)))
- info['apparentsize'] = "0"
- info['truesize'] = "0"
- info['status'] = "INVALID"
-
- # Both engine and dumpStorageTable don't use this option so
- # only keeping it to not break existing scripts that look for the key
- info['children'] = []
-
- # If image was set to illegal, mark the status same
- # (because of VDC constraints)
- if info.get('legality', None) == ILLEGAL_VOL:
- info['status'] = ILLEGAL_VOL
- self.log.info("%s/%s/%s info is %s",
- self.sdUUID, self.imgUUID, self.volUUID, str(info))
- return info
+ return self._md.getInfo()
def getParentVolume(self):
"""
Return parent volume object
"""
- puuid = self.getParent()
- if puuid and puuid != BLANK_UUID:
- return sdCache.produce(self.sdUUID).produceVolume(self.imgUUID,
- puuid)
- return None
+ return self._md.getParentVolume()
def setParent(self, puuid):
"""
@@ -1186,16 +1250,6 @@
def getVolumePath(self):
return self._md.getVolumePath()
-
- def getVmVolumeInfo(self):
- """
- Get volume path/info as dict.
- Derived classes can use this if they want to represent the
- volume to the VM in a different way than the standard 'path' way.
- """
- # By default, send path
- return {'volType': VmVolumeInfo.TYPE_PATH,
- 'path': self.getVolumePath()}
def getMetaParam(self, key):
"""
@@ -1210,23 +1264,7 @@
self._md.setMetaParam(key, value)
def getVolumeParams(self, bs=BLOCK_SIZE):
- volParams = {}
- volParams['volUUID'] = self.volUUID
- volParams['imgUUID'] = self.getImage()
- volParams['path'] = self.getVolumePath()
- volParams['disktype'] = self.getDiskType()
- volParams['prealloc'] = self.getType()
- volParams['volFormat'] = self.getFormat()
- # TODO: getSize returns size in 512b multiples, should move all sizes
- # to byte multiples everywhere to avoid conversion errors and change
- # only at the end
- volParams['size'] = self.getSize()
- volParams['apparentsize'] = self.getVolumeSize(bs=bs)
- volParams['truesize'] = self.getVolumeTrueSize(bs=bs)
- volParams['parent'] = self.getParent()
- volParams['descr'] = self.getDescription()
- volParams['legality'] = self.getLegality()
- return volParams
+ return self._md.getVolumeParams(bs)
def shrinkToOptimalSize(self):
"""
@@ -1234,3 +1272,11 @@
by reducing the lv to minimal size required
"""
pass
+
+ @classmethod
+ def createMetadata(cls, metaId, meta):
+ return cls.metadataClass.createMetadata(metaId, meta)
+
+ @classmethod
+ def newVolumeLease(cls, metaId, sdUUID, volUUID):
+ return cls.metadataClass.newVolumeLease(metaId, sdUUID, volUUID)
--
To view, visit https://gerrit.ovirt.org/50362
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5db8bb8bdf405b8760ecbe103dcbb1a1907ca1db
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke <alitke at redhat.com>
More information about the vdsm-patches
mailing list