From 85df3751db8215580ce852f651c2a77d7d6cf2d2 Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Wed, 27 Jul 2011 15:46:36 +0400 Subject: [PATCH] Fix os_root_dev and getUUIDDict. getUUIDDict uses /sbin/blkid for correct detect UUID. Fix detect device for partition, now using udev. --- pym/cl_fill.py | 30 ++++++++++++++++-------------- pym/cl_utils.py | 41 +++++++++++++++++++---------------------- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/pym/cl_fill.py b/pym/cl_fill.py index 17039a6..082b67e 100644 --- a/pym/cl_fill.py +++ b/pym/cl_fill.py @@ -188,22 +188,24 @@ class fillVars(varsShare): rootparam=re_res.group(1) # check root for /dev/sd view if re.match("^\/dev\/[a-z]+.*$", rootparam): - return rootparam + return getUdevDeviceInfo( + name=rootparam.strip()).get('DEVNAME','') # check root set by uuid - uuidpath = '/dev/disk/by-uuid' - if os.access(uuidpath,os.R_OK): - uuidDevs = filter(path.islink, - map(lambda x: path.join(uuidpath,x), - os.listdir(uuidpath))) - mapUuidDev = dict(map(lambda x:(path.basename(x), - path.normpath(path.join(uuidpath, - os.readlink(x)))), uuidDevs)) - else: - mapUuidDev = {} if re.match("^UUID=.*$",rootparam): - uuid = rootparam[5:] - if uuid in mapUuidDev: - return mapUuidDev[uuid] + uuid = rootparam[5:].strip("\"'") + blkidProcess = process('/sbin/blkid','-c','/dev/null','-U', + uuid) + if blkidProcess.success(): + return getUdevDeviceInfo( + name=blkidProcess.read().strip()).get('DEVNAME','') + # check root set by label + if re.match("^LABEL=.*$",rootparam): + uuid = rootparam[6:].strip("\"'") + blkidProcess = process('/sbin/blkid','-c','/dev/null','-L', + uuid) + if blkidProcess.success(): + return getUdevDeviceInfo( + name=blkidProcess.read().strip()).get('DEVNAME','') # get device mounted to root dfLines = self._runos("LANG=C df /") if not dfLines: diff --git a/pym/cl_utils.py b/pym/cl_utils.py index 49af380..0ffc201 100644 --- a/pym/cl_utils.py +++ b/pym/cl_utils.py @@ -900,33 +900,30 @@ def readFile(filename): def getUUIDDict(revers=False): """Get dict UUID -> dev""" - devuuid = '/dev/disk/by-uuid' - datafunc = lambda x,y: (x,y) + blkidProcess = process("/sbin/blkid","-s","UUID","-c","/dev/null") if revers: datafunc = lambda x,y: (y,x) + else: + datafunc = lambda x,y: (x,y) + DEV,UUID = 0,1 + reSplit = re.compile('^([^:]+):.*UUID="([^"]+)"',re.S) return dict( - map(lambda x:datafunc("UUID=%s"%path.basename(x), - path.normpath(path.join(devuuid,os.readlink(x)))), - filter(path.islink, - listDirectory(devuuid,fullPath=True)))) + map(lambda x:datafunc("UUID=%s"%x[UUID], + getUdevDeviceInfo(name=x[DEV]).get('DEVNAME',x[DEV])), + map(lambda x:x.groups(), + filter(lambda x:x, + map(reSplit.search, + blkidProcess))))) def detectDeviceForPartition(dev): - """Detect parent device for partition by /sys/block (sysfs)""" - reDeviceSplit = re.compile("^(.*/)?(.*?)(\d+)$") - device = map(lambda x:filter(lambda x:x in dev, - x[1]), - os.walk('/sys/block')) - if device: - device = device[0] - parentdevices = \ - filter(lambda x: path.split(dev)[-1] in \ - reduce(lambda y,z:y+z[1], - os.walk(path.join('/sys/block',x)),[]), device) - if parentdevices: - return parentdevices[0] - res = reDeviceSplit.search(dev) - if res: - return res.groups()[1] + """Detect parent device for partition by udev and return property""" + prop = getUdevDeviceInfo(name=dev) + if prop.get('DEVTYPE','') != 'partition': + return '' + parentpath = path.dirname(prop.get('DEVPATH','')) + if parentpath: + devProp = getUdevDeviceInfo(path=parentpath) + return devProp.get('DEVNAME','') return None def getProgPath(progname):