summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2010-01-26 14:27:50 +0100
committerHans de Goede <hdegoede@redhat.com>2010-01-28 22:08:47 +0100
commit91598d0cd60f92e7a6e8c279df0a72baff31c661 (patch)
treeeb307038c89764dee20c4704a49aa58e8ad69c3b
parent19255b8abbae8ec936a5d541af1f55171ed284a3 (diff)
downloadanaconda-91598d0cd60f92e7a6e8c279df0a72baff31c661.tar.gz
anaconda-91598d0cd60f92e7a6e8c279df0a72baff31c661.tar.xz
anaconda-91598d0cd60f92e7a6e8c279df0a72baff31c661.zip
Add pure python EDD code parsing and compareDrives substitute (#478996)
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.
-rw-r--r--storage/__init__.py55
-rw-r--r--storage/devicelibs/edd.py97
2 files changed, 152 insertions, 0 deletions
diff --git a/storage/__init__.py b/storage/__init__.py
index 4c026dc77..91a75de78 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 000000000..da0391437
--- /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@redhat.com>
+#
+
+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