[NEW PATCH] Get dmId from device number instead of looking for it (via gerrit-bot)

Saggi Mizrahi smizrahi at redhat.com
Thu Aug 25 15:02:14 UTC 2011


New patch submitted by Saggi Mizrahi (smizrahi at redhat.com)

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

commit 3e67a863108e6ef6dea5b5e8754b434d023f6767
Author: Saggi Mizrahi <smizrahi at redhat.com>
Date:   Mon Aug 15 15:38:16 2011 +0300

    Get dmId from device number instead of looking for it
    
    Change-Id: I2fa0444e370eb65c7251e4b1afaecff93e0cf937

diff --git a/vdsm/storage/devicemapper.py b/vdsm/storage/devicemapper.py
index 2fc3f49..8ed0ef2 100644
--- a/vdsm/storage/devicemapper.py
+++ b/vdsm/storage/devicemapper.py
@@ -31,22 +31,12 @@ DMPATH_FORMAT = "/dev/mapper/%s"
 
 def getDmId(deviceMultipathName):
     devlinkPath = DMPATH_FORMAT % deviceMultipathName
-    if os.path.islink(devlinkPath):
-        dmId = os.path.realpath(devlinkPath).split("/")[-1]
-        if os.path.exists("/sys/block/%s" % dmId):
-            return dmId
-
-    # Link doesn't exists for some reason, might be a weird
-    # udev configuration. Falling back to slow but sure method
-    for nameFile in glob("/sys/block/dm-*/dm/name"):
-        try:
-            with open(nameFile, "r") as f:
-                if f.read().rstrip("\n") == deviceMultipathName:
-                    return nameFile.split("/")[3]
-        except (IOError, OSError):
-            pass
-
-    raise OSError(errno.ENOENT, "Could not find dm device named `%s`" % deviceMultipathName)
+    try:
+        devStat = os.stat(devlinkPath)
+    except OSError:
+        raise OSError(errno.ENODEV, "Could not find dm device named `%s`" % deviceMultipathName)
+
+    return "dm-%d" % os.minor(devStat.st_rdev)
 
 def findDev(major, minor):
     return os.path.basename(os.path.realpath('/sys/dev/block/%d:%d' % (major, minor)))




More information about the vdsm-patches mailing list