Federico Simoncelli has uploaded a new change for review.
Change subject: image: copying a template is always allowed
......................................................................
image: copying a template is always allowed
To copy a template from a domain to another is a safe action even if
it has images that are based on it. This patch relaxes the check during
moveImage if the operation is a copy.
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
Change-Id: I9e07d569eec02ac4dcd386a7c576342f640ec242
---
M vdsm/storage/hsm.py
1 file changed, 19 insertions(+), 11 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/08/8408/1
diff --git a/vdsm/storage/hsm.py b/vdsm/storage/hsm.py
index 50d6ce1..730ee03 100644
--- a/vdsm/storage/hsm.py
+++ b/vdsm/storage/hsm.py
@@ -1288,32 +1288,39 @@
self._spmSchedule(spUUID, "deleteImage", lambda : True)
- def validateImageMove(self, srcDom, dstDom, imgUUID):
+ def validateImageCopy(self, srcDom, dstDom, imgUUID, safeToMove=False):
"""
- Determines if the image move is legal.
+ Determines if it is possible to copy (or move) the image.
- Moving an image based on a template to a data domain is only allowed if
- the template exists on the target domain.
- Moving a template from a data domain is only allowed if there are no
- images based on it in the source data domain.
+ Copying or moving an image based on a template to a data domain is
+ allowed only if the template already exists on the target domain.
+ When the option safeToMove (default: False) is active (True) an
+ extra check makes sure that if the image is a template (on a data
+ domain) then there are no other images based on it and therefore it
+ is safe to remove it.
"""
srcAllVols = srcDom.getAllVolumes()
dstAllVols = dstDom.getAllVolumes()
# Filter volumes related to this image
srcVolsImgs = sd.getVolsOfImage(srcAllVols, imgUUID)
+
# Find the template
for volName, imgsPar in srcVolsImgs.iteritems():
if len(imgsPar.imgs) > 1:
# This is the template. Should be only one.
tName, tImgs = volName, imgsPar.imgs
+
# Template self image is the 1st entry
if imgUUID != tImgs[0] and tName not in dstAllVols.keys():
- self.log.error("img %s can't be moved to dom %s because
"
- "template %s is absent on it", imgUUID, dstDom.sdUUID,
tName)
+ self.log.error("Cannot move image %s to domain %s "
+ "because the template %s is missing on the "
+ "destination", imgUUID, dstDom.sdUUID, tName)
raise se.ImageDoesNotExistInSD(imgUUID, dstDom.sdUUID)
- elif imgUUID == tImgs[0] and not srcDom.isBackup():
+ elif (safeToMove and imgUUID == tImgs[0]
+ and not srcDom.isBackup()):
raise se.MoveTemplateImageError(imgUUID)
+
break
return True
@@ -1333,7 +1340,8 @@
srcDom = self.validateSdUUID(srcDomUUID)
dstDom = self.validateSdUUID(dstDomUUID)
pool = self.getPool(spUUID) #Validates that the pool is connected. WHY?
- self.validateImageMove(srcDom, dstDom, imgUUID)
+ self.validateImageCopy(srcDom, dstDom, imgUUID,
+ safeToMove=(op != image.COPY_OP))
domains = [srcDomUUID, dstDomUUID]
domains.sort()
@@ -1364,7 +1372,7 @@
images = {}
for (imgUUID, pZero) in imgDict.iteritems():
images[imgUUID.strip()] = misc.parseBool(pZero)
- self.validateImageMove(srcDom, dstDom, imgUUID)
+ self.validateImageCopy(srcDom, dstDom, imgUUID, safeToMove=True)
domains = sorted([srcDomUUID, dstDomUUID])
for dom in domains:
--
To view, visit
http://gerrit.ovirt.org/8408
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9e07d569eec02ac4dcd386a7c576342f640ec242
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Federico Simoncelli <fsimonce(a)redhat.com>