[NEW PATCH] Related to BZ#717952 - Use 'with' instead of old lock.acquire and avoid unneeded SDF.produce(sdUUID) (via gerrit-bot)

Igor Lvovsky ilvovsky at redhat.com
Mon Jul 11 10:01:57 UTC 2011


New patch submitted by Igor Lvovsky (ilvovsky at redhat.com)

You can review this change at: http://gerrit.usersys.redhat.com/680

commit a0d0fb1a2d79c7f0b4ba15a888e1fc78cc8c751f
Author: Igor Lvovsky <ilvovsky at redhat.com>
Date:   Tue Jul 5 16:03:30 2011 +0300

    Related to BZ#717952 - Use 'with' instead of old lock.acquire and avoid unneeded SDF.produce(sdUUID)
    
    Change-Id: Ia236b673cd1887b094e5a56cacaf09ee1430ffd4

diff --git a/vdsm/storage/image.py b/vdsm/storage/image.py
index 40a82c9..51e237b 100644
--- a/vdsm/storage/image.py
+++ b/vdsm/storage/image.py
@@ -50,7 +50,7 @@ class Image:
         Consist from chain of volumes.
     """
     log = logging.getLogger('Storage.Image')
-    _lock = threading.Lock()
+    _fakeTemplateLock = threading.Lock()
 
     @classmethod
     def createImageRollback(cls, taskObj, imageDir):
@@ -371,15 +371,14 @@ class Image:
                 self.log.error("Unexpected error", exc_info=True)
                 raise se.CouldNotValideTemplateOnTargetDomain("Template %s Destination domain %s: %s" % (pimg, dstSdUUID, str(e)))
 
-    def __templateRelink(self, sdUUID, imgUUID, volUUID):
+    def __templateRelink(self, destDom, imgUUID, volUUID):
         """
         Relink all hardlinks of the template 'volUUID' in all VMs based on it
         """
-        destDom = SDF.produce(sdUUID)
         # Avoid relink templates for SAN domains
         if destDom.getStorageType() in [ sd.NFS_DOMAIN ]:
             vol = destDom.produceVolume(imgUUID=imgUUID, volUUID=volUUID)
-            chList = vol.getAllChildrenList(self.repoPath, sdUUID, imgUUID, volUUID)
+            chList = vol.getAllChildrenList(self.repoPath, destDom.sdUUID, imgUUID, volUUID)
             for ch in chList:
                 # Remove hardlink of this template
                 v = destDom.produceVolume(imgUUID=ch['imgUUID'], volUUID=volUUID)
@@ -387,7 +386,7 @@ class Image:
 
                 # Now we should re-link deleted hardlink, if exists
                 newVol = destDom.produceVolume(imgUUID=imgUUID, volUUID=volUUID)
-                imageDir = self.getImageDir(sdUUID, ch['imgUUID'])
+                imageDir = self.getImageDir(destDom.sdUUID, ch['imgUUID'])
                 newVol.share(imageDir)
         else:
             self.log.debug("Doesn't relink templates non-NFS domain %s", destDom.sdUUID)
@@ -396,8 +395,7 @@ class Image:
         """
         Create fake template (relevant for Backup domain only)
         """
-        try:
-            self._lock.acquire()
+        with self._fakeTemplateLock:
             try:
                 destDom = SDF.produce(sdUUID)
                 volclass = destDom.getVolumeClass()
@@ -417,14 +415,12 @@ class Image:
                     # Mark fake volume as shared
                     vol.setShared()
                     # Now we should re-link all hardlinks of this template in all VMs based on it
-                    self.__templateRelink(sdUUID, volParams['imgUUID'], volParams['volUUID'])
+                    self.__templateRelink(destDom, volParams['imgUUID'], volParams['volUUID'])
 
                     self.log.debug("Succeeded to create fake image %s in domain %s", volParams['imgUUID'], destDom.sdUUID)
                 except Exception:
                     self.log.error("Failure to create fake image %s in domain %s", volParams['imgUUID'],
                         destDom.sdUUID, exc_info=True)
-        finally:
-            self._lock.release()
 
     def isLegal(self, sdUUID, imgUUID):
         """
@@ -763,7 +759,7 @@ class Image:
 
                 if force:
                     # Now we should re-link all deleted hardlinks, if exists
-                    self.__templateRelink(dstSdUUID, dstImgUUID, dstVolUUID)
+                    self.__templateRelink(destDom, dstImgUUID, dstVolUUID)
             except se.StorageException, e:
                 self.log.error("Unexpected error", exc_info=True)
                 raise




More information about the vdsm-patches mailing list