[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[PATCH 6/8] booty: make getDiskPart deal with devices instead of names



---
 bootloader.py            |    3 +--
 booty/alpha.py           |   14 +++-----------
 booty/bootloaderInfo.py  |    3 ++-
 booty/checkbootloader.py |   12 ++++--------
 booty/sparc.py           |    2 +-
 booty/util.py            |    6 ++----
 booty/x86.py             |   42 ++++++++++++++++++------------------------
 7 files changed, 31 insertions(+), 51 deletions(-)

diff --git a/bootloader.py b/bootloader.py
index 83ef5d3..37490ea 100644
--- a/bootloader.py
+++ b/bootloader.py
@@ -125,8 +125,7 @@ def fixedMdraidGrubTarget(anaconda, grubTarget):
     try:
         if float(version) < 12:
             stage1Devs = anaconda.bootloader.getPhysicalDevices(grubTarget)
-            disk = getDiskPart(stage1Devs[0].name, anaconda.storage)[0]
-            fixedGrubTarget = anaconda.storage.devicetree.getDeviceByName(disk)
+            fixedGrubTarget = getDiskPart(stage1Devs[0])[0]
             log.info("Mdraid grub upgrade: %s -> %s" % (grubTarget.name,
                                                         fixedGrubTarget.name))
     except ValueError:
diff --git a/booty/alpha.py b/booty/alpha.py
index 5f742ed..5e5216a 100644
--- a/booty/alpha.py
+++ b/booty/alpha.py
@@ -6,14 +6,6 @@ from bootloaderInfo import *
 from util import getDiskPart
 
 class alphaBootloaderInfo(bootloaderInfo):
-    def wholeDevice (self, path):
-        (device, foo) = getDiskPart(path, self.storage)
-        return device
-
-    def partitionNum (self, path):
-        (foo, partitionNumber) = getDiskPart(path, self.storage)
-        return partitionNumber
-
     def writeAboot(self, instRoot, bl, kernelList,
                    chainList, defaultDev):
         rootDevice = self.storage.rootDevice
@@ -66,7 +58,7 @@ class alphaBootloaderInfo(bootloaderInfo):
             f.write ("#         all kernel paths are relative to /boot/\n")
 
         # bpn is the boot partition number.
-        bpn = self.partitionNum(bootDevice.path)
+        bpn = getDiskPart(bootDevice)
         lines = 0
 
         # We write entries line using the following format:
@@ -101,8 +93,8 @@ class alphaBootloaderInfo(bootloaderInfo):
         # Now we're ready to write the relevant boot information. wbd
         # is the whole boot device, bdpn is the boot device partition
         # number.
-        wbd = self.wholeDevice (bootDevice.path)
-        bdpn = self.partitionNum (bootDevice.path)
+        wbd = getDiskPart(bootDevice)[0]
+        bdpn = getDiskPart(bootDevice)[1]
 
         # Calling swriteboot. The first argument is the disk to write
         # to and the second argument is a path to the bootstrap loader
diff --git a/booty/bootloaderInfo.py b/booty/bootloaderInfo.py
index edce60d..d019edf 100644
--- a/booty/bootloaderInfo.py
+++ b/booty/bootloaderInfo.py
@@ -346,7 +346,8 @@ class bootloaderInfo(object):
     def setDevice(self, device):
         self.device = device
 
-        (dev, part) = getDiskPart(device, self.storage)
+        (dev, part) = getDiskPart(
+                             self.storage.devicetree.getDeviceByName(device))
         if part is None:
             self.defaultDevice = "mbr"
         else:
diff --git a/booty/checkbootloader.py b/booty/checkbootloader.py
index b74a59a..ca70405 100644
--- a/booty/checkbootloader.py
+++ b/booty/checkbootloader.py
@@ -26,7 +26,7 @@ liloConfigFile = "/etc/lilo.conf"
 yabootConfigFile = "/etc/yaboot.conf"
 siloConfigFile = "/etc/silo.conf"
 
-def getRaidDisks(raidDevice, storage, raidLevel=None, stripPart=1):
+def getRaidDisks(raidDevice, storage, raidLevel=None):
     rc = []
     if raidLevel is not None:
         try:
@@ -52,14 +52,9 @@ def getRaidDisks(raidDevice, storage, raidLevel=None, stripPart=1):
                 dev = string.split(field, '[')[0]
                 if len(dev) == 0:
                     continue
-                if stripPart:
-                    disk = getDiskPart(dev, storage)[0]
-                    rc.append(disk)
-                else:
-                    rc.append(dev)
+                rc.append(dev)
 
     return rc
-            
 
 def getBootBlock(bootDev, instRoot, storage, seekBlocks=0):
     """Get the boot block from bootDev.  Return a 512 byte string."""
@@ -199,7 +194,8 @@ def getBootloaderTypeAndBoot(instRoot, storage):
 
         if bootDev is not None:
             # XXX SILO sucks just like grub.
-            if getDiskPart(bootDev, storage)[1] != 4:
+            dev = storage.devicetree.getDeviceByName(bootDev)
+            if getDiskPart(dev)[1] != 4:
                 block = getBootBlock(bootDev, instRoot, storage, 1)
                 if block[24:28] == "SILO":
                     return ("SILO", bootDev)
diff --git a/booty/sparc.py b/booty/sparc.py
index 871506c..645a04e 100644
--- a/booty/sparc.py
+++ b/booty/sparc.py
@@ -38,7 +38,7 @@ class sparcBootloaderInfo(bootloaderInfo):
         f.write("message=%s\n" % (mf,))
         f.write("timeout=%s\n" % (self.timeout or 50))
 
-        (name, partNum) = getDiskPart(bootDev.name, self.storage)
+        (disk, partNum) = getDiskPart(bootDev)
         f.write("partition=%s\n" % (partNum,))
 
         if self.password:
diff --git a/booty/util.py b/booty/util.py
index eab6b99..c7a6630 100644
--- a/booty/util.py
+++ b/booty/util.py
@@ -1,6 +1,4 @@
-def getDiskPart(dev, storage):
-    dev = storage.devicetree.getDeviceByName(dev)
-
+def getDiskPart(dev):
     if dev.type == "partition":
         partNum = dev.partedPartition.number
         disk = dev.disk
@@ -8,4 +6,4 @@ def getDiskPart(dev, storage):
         partNum = None
         disk = dev
     
-    return (disk.name, partNum)
+    return (disk, partNum)
diff --git a/booty/x86.py b/booty/x86.py
index 038236d..1668c56 100644
--- a/booty/x86.py
+++ b/booty/x86.py
@@ -107,7 +107,7 @@ class x86BootloaderInfo(efiBootloaderInfo):
         matches = []
         for stage1Dev in stage1Devs:
             for mdBootPart in bootDevs:
-                if getDiskPart(stage1Dev.name, self.storage)[0] == getDiskPart(mdBootPart.name, self.storage)[0]:
+                if getDiskPart(stage1Dev)[0] == getDiskPart(mdBootPart)[0]:
                     matches.append((stage1Dev, mdBootPart))
         return matches
 
@@ -116,10 +116,7 @@ class x86BootloaderInfo(efiBootloaderInfo):
         bootDevsHavingStage1Dev = [match[1] for match in matches]
         for mdBootPart in bootDevs:
             if mdBootPart not in bootDevsHavingStage1Dev:
-               updatedMatches.append((
-                   self.storage.devicetree.getDeviceByName(
-                       getDiskPart(mdBootPart.name, self.storage)[0]),
-                   mdBootPart))
+               updatedMatches.append((getDiskPart(mdBootPart)[0], mdBootPart))
         return updatedMatches
 
     def installGrub(self, instRoot, bootDev, grubTarget, grubPath, cfPath):
@@ -151,8 +148,7 @@ class x86BootloaderInfo(efiBootloaderInfo):
                              self.grubbyPartitionName(stage1Dev),
                              self.grubbyPartitionName(mdMemberBootPart))]
                 firstMdMemberDiskGrubbyName = self.grubbyDiskName(
-                    self.storage.devicetree.getDeviceByName(
-                        getDiskPart(mdMemberBootPart.name, self.storage)[0]))
+                                        getDiskPart(mdMemberBootPart)[0])
 
                 # 2) and install stage1 on other members' disks/partitions too
                 # NOTES:
@@ -169,21 +165,19 @@ class x86BootloaderInfo(efiBootloaderInfo):
                 matches = self.addMemberMbrs(matches, bootDevs)
                 for stage1Target, mdMemberBootPart in matches[1:]:
                     # prepare special device mapping corresponding to member removal
-                    mdMemberBootDisk = getDiskPart(mdMemberBootPart.name, self.storage)[0]
+                    mdMemberBootDisk = getDiskPart(mdMemberBootPart)[0]
                     # It can happen due to ks --driveorder option, but is it ok?
-                    if not mdMemberBootDisk in self.drivelist:
+                    if not mdMemberBootDisk.name in self.drivelist:
                         continue
                     mdRaidDeviceRemap = (firstMdMemberDiskGrubbyName,
-                                         mdMemberBootDisk)
+                                         mdMemberBootDisk.name)
 
                     stage1TargetGrubbyName = self.grubbyPartitionName(stage1Target)
                     rootPartGrubbyName = self.grubbyPartitionName(mdMemberBootPart)
 
                     # now replace grub disk name part according to special device
                     # mapping
-                    old = self.grubbyDiskName(
-                        self.storage.devicetree.getDeviceByName(
-                            mdMemberBootDisk)).strip('() ')
+                    old = self.grubbyDiskName(mdMemberBootDisk).strip('() ')
                     new = firstMdMemberDiskGrubbyName.strip('() ')
                     rootPartGrubbyName = rootPartGrubbyName.replace(old, new)
                     stage1TargetGrubbyName = stage1TargetGrubbyName.replace(old, new)
@@ -232,10 +226,11 @@ class x86BootloaderInfo(efiBootloaderInfo):
 
         # keep track of which devices are used for the device.map
         usedDevs = set()
-        usedDevs.update([d.name for d in self.getPhysicalDevices(
-                          self.storage.devicetree.getDeviceByName(grubTarget))])
-        usedDevs.update([d.name for d in self.getPhysicalDevices(bootDev)])
-        usedDevs.update([dev for (label, longlabel, dev) in chainList if longlabel])
+        usedDevs.update(self.getPhysicalDevices(
+                          self.storage.devicetree.getDeviceByName(grubTarget)))
+        usedDevs.update(self.getPhysicalDevices(bootDev))
+        usedDevs.update([self.storage.devicetree.getDeviceByName(dev) for
+                            (label, longlabel, dev) in chainList if longlabel])
 
         if not upgrade:
             self.writeDeviceMap(instRoot, usedDevs, upgrade)
@@ -415,7 +410,8 @@ class x86BootloaderInfo(efiBootloaderInfo):
                         (grubdisk, dev) = line.split()[:2]
                         dev = dev[5:]
                         if dev in self.drivelist:
-                            usedDevs.add(dev)
+                            usedDevs.add(
+                                self.storage.devicetree.getDeviceByName(dev))
                 f.close()
             os.rename(instRoot + "/boot/grub/device.map",
                       instRoot + "/boot/grub/device.map.rpmsave")
@@ -424,14 +420,13 @@ class x86BootloaderInfo(efiBootloaderInfo):
         f.write("# this device map was generated by anaconda\n")
         usedDiskDevs = set()
         for dev in usedDevs:
-            drive = getDiskPart(dev, self.storage)[0]
+            drive = getDiskPart(dev)[0]
             usedDiskDevs.add(drive)
         devs = list(usedDiskDevs)
-        devs.sort()
-        for drive in devs:
+        devs.sort(key=lambda d: d.name)
+        for dev in devs:
             # XXX hack city.  If they're not the sort of thing that'll
             # be in the device map, they shouldn't still be in the list.
-            dev = self.storage.devicetree.getDeviceByName(drive)
             if not dev.type == "mdarray":
                 f.write("(%s)     %s\n" % (self.grubbyDiskName(dev), dev.path))
         f.close()
@@ -460,8 +455,7 @@ class x86BootloaderInfo(efiBootloaderInfo):
         return "hd%d" % self.drivelist.index(dev.name)
 
     def grubbyPartitionName(self, dev):
-        (name, partNum) = getDiskPart(dev.name, self.storage)
-        disk = self.storage.devicetree.getDeviceByName(name)
+        (disk, partNum) = getDiskPart(dev)
         if partNum != None:
             return "(%s,%d)" % (self.grubbyDiskName(disk), partNum - 1)
         else:
-- 
1.7.0.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]