[NEW PATCH] BZ#720981 - Don't rely on files in /dev/mapper to be symlinks (via gerrit-bot)
Saggi Mizrahi
smizrahi at redhat.com
Tue Jul 19 18:35:00 UTC 2011
New patch submitted by Saggi Mizrahi (smizrahi at redhat.com)
You can review this change at: http://gerrit.usersys.redhat.com/717
commit 68a295524660cd7d1a1e1dd64032989b21b6712f
Author: Saggi Mizrahi <smizrahi at redhat.com>
Date: Mon Jul 18 13:07:24 2011 +0300
BZ#720981 - Don't rely on files in /dev/mapper to be symlinks
Change-Id: I4e1669e994834602e7c9cb655fbac31fe666bafe
diff --git a/vdsm/storage/devicemapper.py b/vdsm/storage/devicemapper.py
index 7e2c634..8873fbd 100644
--- a/vdsm/storage/devicemapper.py
+++ b/vdsm/storage/devicemapper.py
@@ -10,9 +10,23 @@ from constants import EXT_DMSETUP
DMPATH_FORMAT = "/dev/mapper/%s"
def getDmId(deviceMultipathName):
- devPath = DMPATH_FORMAT % (deviceMultipathName,)
- mpPath = os.path.realpath(devPath)
- return os.path.basename(mpPath)
+ 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() == deviceMultipathName:
+ return nameFile.split("/")[3]
+ except (IOError, OSError):
+ pass
+
+ raise OSError(errno.ENOENT, "Could not find dm device named `%s`" % deviceMultipathName)
def findDev(major, minor):
return os.path.basename(os.path.realpath('/sys/dev/block/%d:%d' % (major, minor)))
@@ -37,7 +51,7 @@ def _parseDevFile(devFilePath):
return (int(mj), int(mn))
def getSlaves(deviceName):
- mpName = getDmId(deviceName)
+ mpName = resolveDevName(deviceName)
sysfsPath = getSysfsPath(mpName)
return os.listdir(os.path.join(sysfsPath, "slaves"))
diff --git a/vdsm/storage/multipath.py b/vdsm/storage/multipath.py
index 9ad6200..756a2ad 100644
--- a/vdsm/storage/multipath.py
+++ b/vdsm/storage/multipath.py
@@ -195,7 +195,7 @@ def pathListIter(filterGuids=None):
svdsm = supervdsm.getProxy()
pathStatuses = devicemapper.getPathsStatus()
- for guid in getMPDevNamesIter():
+ for dmId, guid in getMPDevsIter():
if devsFound == filterLen:
break
@@ -204,8 +204,6 @@ def pathListIter(filterGuids=None):
devsFound += 1
- dmId = devicemapper.getDmId(guid)
-
devInfo = {
"guid" : guid,
"dm" : dmId,
@@ -290,6 +288,10 @@ def pathinfo(guid):
TOXIC_REGEX = re.compile(r"[%s]" % re.sub(r"[\-\\\]]", lambda m : "\\" + m.group(), TOXIC_CHARS))
def getMPDevNamesIter():
+ for _, name in getMPDevsIter():
+ yield name
+
+def getMPDevsIter():
"""
Collect the list of all the multipath block devices.
Return the list of device identifiers w/o "/dev/mapper" prefix
@@ -316,7 +318,7 @@ def getMPDevNamesIter():
log.info("Device with unsupported GUID %s discarded", guid)
continue
- yield guid
+ yield dmInfoDir.split("/")[3], guid
def devIsiSCSI(type):
return type in [DEV_ISCSI, DEV_MIXED]
More information about the vdsm-patches
mailing list