Yeela Kaplan has uploaded a new change for review.
Change subject: Relink template hard links to meta and lease files
......................................................................
Relink template hard links to meta and lease files
Change-Id: Idce0f3f1812fdf45efeeeffcccb7dc22b3b0d0f0
Bug-Url:
https://bugzilla.redhat.com/show_bug.cgi?id=864073
Signed-off-by: Yeela Kaplan <ykaplan(a)redhat.com>
---
M vdsm/storage/fileSD.py
M vdsm/storage/fileVolume.py
M vdsm/storage/image.py
M vdsm/storage/sd.py
4 files changed, 63 insertions(+), 38 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/37/12837/1
diff --git a/vdsm/storage/fileSD.py b/vdsm/storage/fileSD.py
index fa837fc..1d7e7d7 100644
--- a/vdsm/storage/fileSD.py
+++ b/vdsm/storage/fileSD.py
@@ -519,6 +519,50 @@
for imageDir in removedImages:
self.oop.fileUtils.cleanupdir(imageDir)
+ def templateRelink(self, imgUUID, volUUID):
+ """
+ Relink all hardlinks of the template 'volUUID' in all VMs based on it.
+
+ This function assumes that dom is backup dom and that template image is
+ used by other volumes.
+ """
+ # Avoid relink templates for non-NFS domains
+ if self.getStorageType() not in [sd.NFS_DOMAIN]:
+ self.log.debug("Doesn't relink templates non-NFS domain %s",
+ self.sdUUID)
+ return
+
+ allVols = self.getAllVolumes()
+ tImgs = allVols[volUUID].imgs
+ if len(tImgs) < 2:
+ self.log.debug("Volume %s is an unused template or a regular "
+ "volume. Found in images: %s allVols: %s",
volUUID,
+ tImgs, allVols)
+ return
+ templateImage = tImgs[0]
+ relinkImgs = tuple(tImgs[1:])
+ for rImg in relinkImgs:
+ # This function assumes that all relevant images and template
+ # namespaces are locked.
+ repoPath = self._getRepoPath()
+ tLink = os.path.join(repoPath, self.sdUUID,
+ sd.DOMAIN_IMAGES, rImg, volUUID)
+ for ext in ['', fileVolume.META_FILEEXT]:
+ self.oop.os.unlink(tLink + ext)
+ self.oop.os.link(os.path.join(repoPath, self.sdUUID,
+ sd.DOMAIN_IMAGES, templateImage,
+ volUUID + ext), tLink + ext)
+
+ try:
+ self.oop.os.unlink(tLink + fileVolume.LEASE_FILEEXT)
+ self.oop.os.link(os.path.join(
+ repoPath, self.sdUUID, sd.DOMAIN_IMAGES,
+ templateImage, volUUID + fileVolume.LEASE_FILEEXT),
+ tLink + fileVolume.LEASE_FILEEXT)
+ except OSError as e:
+ if e.errno != os.errno.ENOENT:
+ raise
+
def getMountsList(pattern="*"):
finalPat = os.path.join(sd.StorageDomain.storage_repository,
diff --git a/vdsm/storage/fileVolume.py b/vdsm/storage/fileVolume.py
index 01575e0..6e12cd8 100644
--- a/vdsm/storage/fileVolume.py
+++ b/vdsm/storage/fileVolume.py
@@ -34,6 +34,7 @@
import task
from threadLocal import vars
+META_FILEEXT = ".meta"
LEASE_FILEEXT = ".lease"
LEASE_FILEOFFSET = 0
@@ -538,7 +539,7 @@
@classmethod
def __metaVolumePath(cls, vol_path):
if vol_path:
- return vol_path + '.meta'
+ return vol_path + META_FILEEXT
else:
return None
diff --git a/vdsm/storage/image.py b/vdsm/storage/image.py
index 025885f..3eada2b 100644
--- a/vdsm/storage/image.py
+++ b/vdsm/storage/image.py
@@ -36,7 +36,6 @@
from threadLocal import vars
import resourceFactories
import resourceManager as rm
-import outOfProcess as oop
log = logging.getLogger('Storage.Image')
rmanager = rm.ResourceManager.getInstance()
@@ -368,38 +367,6 @@
# Do not deactivate the template yet (might be in use by an other vm)
# TODO: reference counting to deactivate when unused
- def __templateRelink(self, destDom, imgUUID, volUUID):
- """
- Relink all hardlinks of the template 'volUUID' in all VMs based on it.
-
- This function assumes that dom is backup dom and that template image is
- used by other volumes.
- """
- # Avoid relink templates for non-NFS domains
- if destDom.getStorageType() not in [sd.NFS_DOMAIN]:
- self.log.debug("Doesn't relink templates non-NFS domain %s",
- destDom.sdUUID)
- return
-
- allVols = destDom.getAllVolumes()
- tImgs = allVols[volUUID].imgs
- if len(tImgs) < 2:
- self.log.debug("Volume %s is an unused template or a regular "
- "volume. Found in images: %s allVols: %s",
volUUID,
- tImgs, allVols)
- return
- templateImage = tImgs[0]
- relinkImgs = tuple(tImgs[1:])
- for rImg in relinkImgs:
- # This function assumes that all relevant images and template
- # namespaces are locked.
- tLink = os.path.join(self.repoPath, destDom.sdUUID,
- sd.DOMAIN_IMAGES, rImg, volUUID)
- oop.getProcessPool(destDom.sdUUID).os.unlink(tLink)
- oop.getProcessPool(destDom.sdUUID).os.link(os.path.join(
- self.repoPath, destDom.sdUUID, sd.DOMAIN_IMAGES, templateImage,
- volUUID), tLink)
-
def createFakeTemplate(self, sdUUID, volParams):
"""
Create fake template (relevant for Backup domain only)
@@ -431,8 +398,8 @@
vol.setShared()
# Now we should re-link all hardlinks of this template in
# all VMs based on it
- self.__templateRelink(destDom, volParams['imgUUID'],
- volParams['volUUID'])
+ destDom.templateRelink(volParams['imgUUID'],
+ volParams['volUUID'])
self.log.debug("Succeeded to create fake image %s in "
"domain %s", volParams['imgUUID'],
@@ -658,7 +625,7 @@
if force:
leafVol = chains['dstChain'][-1]
# Now we should re-link all deleted hardlinks, if exists
- self.__templateRelink(destDom, imgUUID, leafVol.volUUID)
+ destDom.templateRelink(imgUUID, leafVol.volUUID)
# At this point we successfully finished the 'copy' part of the
# operation and we can clear all recoveries.
@@ -931,7 +898,7 @@
if force:
# Now we should re-link all deleted hardlinks, if exists
- self.__templateRelink(destDom, dstImgUUID, dstVolUUID)
+ destDom.templateRelink(dstImgUUID, dstVolUUID)
except se.StorageException:
self.log.error("Unexpected error", exc_info=True)
raise
diff --git a/vdsm/storage/sd.py b/vdsm/storage/sd.py
index 9ce836b..c65abac 100644
--- a/vdsm/storage/sd.py
+++ b/vdsm/storage/sd.py
@@ -785,3 +785,16 @@
(on NFS mostly) due to lazy file removal
"""
pass
+
+ def templateRelink(self, imgUUID, volUUID):
+ """
+ Relink all hardlinks of the template 'volUUID' in all VMs based on it.
+
+ This function assumes that dom is backup dom and that template image is
+ used by other volumes.
+ """
+ # Avoid relink templates for non-NFS domains
+ if self.getStorageType() not in [NFS_DOMAIN]:
+ self.log.debug("Doesn't relink templates non-NFS domain %s",
+ self.sdUUID)
+ return
--
To view, visit
http://gerrit.ovirt.org/12837
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Idce0f3f1812fdf45efeeeffcccb7dc22b3b0d0f0
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Yeela Kaplan <ykaplan(a)redhat.com>