There are various issues with the EDD C-code, mostly that it is way too complicated for what it does. This patch re-implements it in python, and adds a compareDrives substitute to the storage class. Note that the compareDrives substitute is a copy and paste job of the isys code (using the new storage edd_dict). The isys code will be removed in a separate patch. --- storage/__init__.py | 55 +++++++++++++++++++++++++ storage/devicelibs/edd.py | 97 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 152 insertions(+), 0 deletions(-) create mode 100644 storage/devicelibs/edd.py diff --git a/storage/__init__.py b/storage/__init__.py index 4c026dc..91a75de 100644 --- a/storage/__init__.py +++ b/storage/__init__.py @@ -48,6 +48,7 @@ from devicelibs.lvm import safeLvmName from devicelibs.dm import name_from_dm_node from devicelibs.crypto import generateBackupPassphrase from devicelibs.mpath import MultipathConfigWriter +from devicelibs.edd import get_edd_dict from udev import * import iscsi import fcoe @@ -255,6 +256,7 @@ class Storage(object): self.zeroMbr = None self.protectedDevSpecs = [] self.autoPartitionRequests = [] + self.eddDict = {} self.__luksDevs = {} @@ -373,6 +375,7 @@ class Storage(object): dasd=self.dasd) self.devicetree.populate() self.fsset = FSSet(self.devicetree, self.anaconda.rootPath) + self.eddDict = get_edd_dict(self.partitioned) self.anaconda.id.rootParts = None self.anaconda.id.upgradeRoot = None self.dumpState("initial") @@ -1163,6 +1166,58 @@ class Storage(object): def rootDevice(self): return self.fsset.rootDevice + def compareDisks(self, first, second): + if self.eddDict.has_key(first) and self.eddDict.has_key(second): + one = self.eddDict[first] + two = self.eddDict[second] + if (one < two): + return -1 + elif (one > two): + return 1 + + # if one is in the BIOS and the other not prefer the one in the BIOS + if self.eddDict.has_key(first): + return -1 + if self.eddDict.has_key(second): + return 1 + + if first.startswith("hd"): + type1 = 0 + elif first.startswith("sd"): + type1 = 1 + elif (first.startswith("vd") or first.startswith("xvd")): + type1 = -1 + else: + type1 = 2 + + if second.startswith("hd"): + type2 = 0 + elif second.startswith("sd"): + type2 = 1 + elif (second.startswith("vd") or second.startswith("xvd")): + type2 = -1 + else: + type2 = 2 + + if (type1 < type2): + return -1 + elif (type1 > type2): + return 1 + else: + len1 = len(first) + len2 = len(second) + + if (len1 < len2): + return -1 + elif (len1 > len2): + return 1 + else: + if (first < second): + return -1 + elif (first > second): + return 1 + + return 0 def getReleaseString(mountpoint): relName = None diff --git a/storage/devicelibs/edd.py b/storage/devicelibs/edd.py new file mode 100644 index 0000000..da03914 --- /dev/null +++ b/storage/devicelibs/edd.py @@ -0,0 +1,97 @@ +# +# edd.py +# BIOS EDD data parsing functions +# +# Copyright (C) 2010 Red Hat, Inc. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# Author(s): Hans de Goede <hdegoede@xxxxxxxxxx> +# + +import os +import struct + +import logging +log = logging.getLogger("storage") + +def get_edd_dict(devices): + """Given an array of devices return a dict with the BIOS ID for them.""" + edd_dict = {} + + for biosdev in range(80, 80 + 15): + sysfspath = "/sys/firmware/edd/int13_dev%d" % biosdev + if not os.path.exists(sysfspath): + break # We are done + + sysfspath = "/sys/firmware/edd/int13_dev%d/mbr_signature" % biosdev + if not os.path.exists(sysfspath): + log.warning("No mbrsig for biosdev: %d" % biosdev) + continue + + try: + file = open(sysfspath, "r") + eddsig = file.read() + file.close() + except (IOError, OSError) as e: + log.warning("Error reading EDD mbrsig for %d: %s" % + (biosdev, str(e))) + continue + + sysfspath = "/sys/firmware/edd/int13_dev%d/sectors" % biosdev + try: + file = open(sysfspath, "r") + eddsize = file.read() + file.close() + except (IOError, OSError) as e: + eddsize = None + + found = [] + for dev in devices: + try: + fd = os.open(dev.path, os.O_RDONLY) + os.lseek(fd, 440, 0) + mbrsig = struct.unpack('I', os.read(fd, 4)) + os.close(fd) + except OSError as e: + log.warning("Error reading mbrsig from disk %s: %s" % + (dev.name, str(e))) + continue + + mbrsigStr = "0x%08x\n" % mbrsig + if mbrsigStr == eddsig: + if eddsize: + sysfspath = "/sys%s/size" % dev.sysfsPath + try: + file = open(sysfspath, "r") + size = file.read() + file.close() + except (IOError, OSError) as e: + log.warning("Error getting size for: %s" % dev.name) + continue + if eddsize != size: + continue + found.append(dev.name) + + if not found: + log.error("No matching mbr signature found for biosdev %d" % + biosdev) + elif len(found) > 1: + log.error("Multiple signature matches found for biosdev %d: %s" % + (biosdev, str(found))) + else: + log.info("Found %s for biosdev %d" %(found[0], biosdev)) + edd_dict[found[0]] = biosdev + + return edd_dict -- 1.6.5.2 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list