Fix os_root_dev and getUUIDDict.

getUUIDDict uses /sbin/blkid for correct detect UUID.
Fix detect device for partition, now using udev.
develop
Mike Hiretsky 13 years ago
parent a073ca298a
commit 85df3751db

@ -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:

@ -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):

Loading…
Cancel
Save