Change in vdsm[master]: createImageLinks: recreate if the link exists but it'ss broken

stirabos at redhat.com stirabos at redhat.com
Mon Feb 1 16:09:39 UTC 2016


Simone Tiraboschi has uploaded a new change for review.

Change subject: createImageLinks: recreate if the link exists but it'ss broken
......................................................................

createImageLinks: recreate if the link exists but it'ss broken

Recreate the symlink if it exists but it points to a different
outdated target.

Change-Id: Ia0eb50f57cf6f21496f7a8ef70f80693336ae803
Bug-Url: https://bugzilla.redhat.com/1300749
Signed-off-by: Simone Tiraboschi <stirabos at redhat.com>
---
M vdsm/storage/blockSD.py
M vdsm/storage/fileSD.py
2 files changed, 46 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/37/52937/1

diff --git a/vdsm/storage/blockSD.py b/vdsm/storage/blockSD.py
index 2bce63a..6036c5f 100644
--- a/vdsm/storage/blockSD.py
+++ b/vdsm/storage/blockSD.py
@@ -1161,11 +1161,32 @@
                 os.symlink(srcVol, dstVol)
             except OSError as e:
                 if e.errno == errno.EEXIST:
-                    self.log.debug("img run vol already exists: %s", dstVol)
+                    prevVol = os.path.realpath(dstVol)
+                    if prevVol == srcVol:
+                        self.log.debug(
+                            "img run vol already exists '%s' and points to "
+                            "the right target, skipping it" % dstVol
+                        )
+                    else:
+                        self.log.debug(
+                            "img run vol already exists '%s' but points to a "
+                            "different target %s, recreating it" % (
+                                dstVol,
+                                prevVol,
+                            )
+                        )
+                        try:
+                            os.remove(dstVol)
+                            os.symlink(srcVol, dstVol)
+                        except OSError:
+                            self.log.error(
+                                "Failed to re-create img run vol: %s",
+                                dstVol
+                            )
+                            raise
                 else:
                     self.log.error("Failed to create img run vol: %s", dstVol)
                     raise
-
         return imgRunDir
 
     def activateVolumes(self, imgUUID, volUUIDs):
diff --git a/vdsm/storage/fileSD.py b/vdsm/storage/fileSD.py
index 21ac276..8823bf2 100644
--- a/vdsm/storage/fileSD.py
+++ b/vdsm/storage/fileSD.py
@@ -521,7 +521,29 @@
             os.symlink(srcImgPath, imgRunDir)
         except OSError as e:
             if e.errno == errno.EEXIST:
-                self.log.debug("img run dir already exists: %s", imgRunDir)
+                prevPath = os.path.realpath(imgRunDir)
+                if prevPath == srcImgPath:
+                    self.log.debug(
+                        "img run dir already exists '%s' and points to the "
+                        "right target, skipping it" % imgRunDir
+                    )
+                else:
+                    self.log.debug(
+                        "img run dir already exists '%s' but points to a "
+                        "different target %s, recreating it" % (
+                            imgRunDir,
+                            prevPath,
+                        )
+                    )
+                    try:
+                        os.remove(imgRunDir)
+                        os.symlink(srcImgPath, imgRunDir)
+                    except OSError:
+                        self.log.error(
+                            "Failed to re-create img run dir: %s",
+                            imgRunDir
+                        )
+                        raise
             else:
                 self.log.error("Failed to create img run dir: %s", imgRunDir)
                 raise


-- 
To view, visit https://gerrit.ovirt.org/52937
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia0eb50f57cf6f21496f7a8ef70f80693336ae803
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Simone Tiraboschi <stirabos at redhat.com>


More information about the vdsm-patches mailing list