From ab244645e1c07f490f23d4b0a98eb657bc935565 Mon Sep 17 00:00:00 2001 From: David Lehman Date: Mon, 20 Apr 2009 17:02:32 -0500 Subject: Reimplement mdexamine using a more easily parseable output format. --- storage/devicelibs/mdraid.py | 57 +++++++++++++------------------------------- storage/devices.py | 8 ------- 2 files changed, 16 insertions(+), 49 deletions(-) diff --git a/storage/devicelibs/mdraid.py b/storage/devicelibs/mdraid.py index 333fa6c5e..7b8bf2314 100644 --- a/storage/devicelibs/mdraid.py +++ b/storage/devicelibs/mdraid.py @@ -199,49 +199,24 @@ def mddeactivate(device): raise MDRaidError("mddeactivate failed for %s" % device) def mdexamine(device): - # XXX NOTUSED: we grab metadata from udev, which ran 'mdadm -E --export' - # - # FIXME: this will not work with version >= 1 metadata - # - # We should use mdadm -Eb or mdadm -E --export for a more easily - # parsed output format. - lines = iutil.execWithCapture("mdadm", - ["--examine", device], - stderr="/dev/tty5").splitlines() - - info = { - 'major': "-1", - 'minor': "-1", - 'uuid' : "", - 'level': -1, - 'nrDisks': -1, - 'totalDisks': -1, - 'mdMinor': -1, - } - - for line in lines: - (key, sep, val) = line.strip().partition(" : ") - if not sep: - continue - if key == "Version": - (major, sep, minor) = val.partition(".") - info['major'] = major - info['minor'] = minor - elif key == "UUID": - info['uuid'] = val.split()[0] - elif key == "Raid Level": - info['level'] = int(val[4:]) - elif key == "Raid Devices": - info['nrDisks'] = int(val) - elif key == "Total Devices": - info['totalDisks'] = int(val) - elif key == "Preferred Minor": - info['mdMinor'] = int(val) - else: + vars = iutil.execWithCapture("mdadm", + ["--examine", "--brief", device], + stderr="/dev/tty5").split() + + info = {} + if vars: + try: + info["device"] = vars[1] + vars = vars[2:] + except IndexError: + return {} + + for var in vars: + (name, equals, value) = var.partition("=") + if not equals: continue - if not info['uuid']: - raise MDRaidError("UUID missing from device info") + info[name.lower()] = value.strip() return info diff --git a/storage/devices.py b/storage/devices.py index 0d8fda4f9..2568ba34c 100644 --- a/storage/devices.py +++ b/storage/devices.py @@ -2234,14 +2234,6 @@ class MDRaidArrayDevice(StorageDevice): info = mdraid.mdexamine(self.devices[0].path) if self.level is None: self.level = mdraid.raidLevel(info['level']) - if self.memberDevices is None: - self.memberDevices = info['nrDisks'] - if self.totalDevices is None: - self.totalDevices = info['totalDisks'] - if self.uuid is None: - self.uuid = info['uuid'] - if self.minor is None: - self.minor = info['mdMinor'] @property def fstabSpec(self): -- cgit