From 7372ff1c7e31e726b6ebf908cdf91460a44b9d0a Mon Sep 17 00:00:00 2001 From: Ales Kozumplik Date: Wed, 2 Mar 2011 15:14:07 +0100 Subject: [booty rhel5-branch 3/3] Translate dm-0 to . (#667014) This is important so booty can match the boot/ device with the drivelist if boot/ is on a raid. The fix is based on a patch by Masahiro Matsuya . --- bootyutil.py | 20 ++++++++++++++++++++ checkbootloader.py | 6 ++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/bootyutil.py b/bootyutil.py index cbfab5c..ea48c44 100644 --- a/bootyutil.py +++ b/bootyutil.py @@ -12,8 +12,11 @@ # # +import os import string +import rhpl.executil + # return (disk, partition number) eg ('hda', 1) def getDiskPart(dev): cut = len(dev) @@ -46,3 +49,20 @@ def getDiskPart(dev): partNum = None return (name, partNum) + +def name_from_dm_node(dm_node): + """ Translate dm node to the device name. + + For instance "dm-0" to "mpath0". + """ + + full_path = "/sys/block/%s/dev" % dm_node + if not os.path.exists(full_path): + raise RuntimeError("name_from_dm_node: device does not exist: %s" % + full_path) + dev_file = open(full_path) + (major, minor) = dev_file.readline().strip().split(":") + name = rhpl.executil.execWithCapture(\ + "/sbin/dmsetup",["/sbin/dmsetup", "info", "--columns", "--noheadings", + "-o", "name", "-j", str(major), "-m", str(minor)]) + return name.strip() diff --git a/checkbootloader.py b/checkbootloader.py index 512e880..29e6a50 100644 --- a/checkbootloader.py +++ b/checkbootloader.py @@ -23,6 +23,7 @@ liloConfigFile = "/etc/lilo.conf" yabootConfigFile = "/etc/yaboot.conf" siloConfigFile = "/etc/silo.conf" +import bootyutil from bootyutil import getDiskPart def getRaidDisks(raidDevice, raidLevel=None, stripPart=1): @@ -39,7 +40,7 @@ def getRaidDisks(raidDevice, raidLevel=None, stripPart=1): f.close() except: return rc - + for line in lines: fields = string.split(line, ' ') if fields[0] == raidDevice: @@ -51,6 +52,8 @@ def getRaidDisks(raidDevice, raidLevel=None, stripPart=1): dev = string.split(field, '[')[0] if len(dev) == 0: continue + if dev.startswith("dm-"): + dev = "mapper/%s" % bootyutil.name_from_dm_node(dev) if stripPart: disk = getDiskPart(dev)[0] rc.append(disk) @@ -58,7 +61,6 @@ def getRaidDisks(raidDevice, raidLevel=None, stripPart=1): rc.append(dev) return rc - def getBootBlock(bootDev, instRoot, seekBlocks=0): """Get the boot block from bootDev. Return a 512 byte string.""" -- 1.7.3.3