[PATCH 3/5] activate mdmember

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

 



This patch adds support for new class MDRaidContainerDevice.

Subject: [PATCH 3/5] activate mdmember

---
 storage/devices.py    |   37 ++++++++++++++++++++++++
 storage/devicetree.py |   75 +++++++++++++++++++++++++++++++++++++++++++++++++
 storage/udev.py       |    9 +++++-
 3 files changed, 120 insertions(+), 1 deletions(-)

diff --git a/storage/devices.py b/storage/devices.py
index b5e32af..2ec9b9a 100644
--- a/storage/devices.py
+++ b/storage/devices.py
@@ -2560,6 +2560,43 @@ class MDRaidArrayDevice(StorageDevice):
         # real work, but it isn't our place to do it from here.
         self.exists = False
 
+class MDRaidContainerDevice(MDRaidArrayDevice):
+    """ An mdraid container device.
+    """
+    _type = "mdcontainer"
+    _devDir = "/dev/md"
+
+    def __init__(self, name, level=None, minor=None, size=None,
+                 memberDevices=None, totalDevices=None, bitmap=False,
+                 uuid=None, format=None, exists=None,
+                 parents=None, sysfsPath=''):
+        """ Create a MDRaidContainerDevice instance.
+
+            Arguments:
+
+                name -- the device name (generally a device node's basename)
+
+            Keyword Arguments:
+
+                level -- the device's RAID level (a string, eg: '1' or 'raid1')
+                parents -- list of member devices (StorageDevice instances)
+                size -- the device's size (units/format TBD)
+                uuid -- the device's UUID
+                minor -- the device minor
+                bitmap -- whether to use a bitmap (boolean)
+                sysfsPath -- sysfs device path
+                format -- a DeviceFormat instance
+                exists -- indicates whether this is an existing device
+        """
+        MDRaidArrayDevice.__init__(self, name, format=format, exists=exists,
+                               minor=minor, size=size, uuid=uuid,
+                               parents=parents, sysfsPath=sysfsPath)
+
+    def addFirstDevice(self, path):
+        mdraid.mdadd_no_degraded(path)
+        udev_settle(timeout=10)
+        real=os.readlink(self.path).split('/')[1]
+        self.sysfsPath = "/devices/virtual/block/%s" % real
 
 class DMRaidArrayDevice(DiskDevice):
     """ A dmraid (device-mapper RAID) device """
diff --git a/storage/devicetree.py b/storage/devicetree.py
index d5b0eaf..ea64ef7 100644
--- a/storage/devicetree.py
+++ b/storage/devicetree.py
@@ -970,6 +970,73 @@ class DeviceTree(object):
 
         return device
 
+
+    def addUdevMDContainerDevice(self, info):
+        log.debug("info=%s" % info)
+        if info.has_key("MD_DEVNAME"):
+            #md container
+            log.debug("real container")
+        else:
+            #md member
+            log.debug("isw md member")
+            name = udev_device_get_name(info)
+            sysfs_path = udev_device_get_sysfs_path(info)
+            
+            device = StorageDevice(name,
+                            major=udev_device_get_major(info),
+                            minor=udev_device_get_minor(info),
+                            sysfsPath=sysfs_path, exists=True)
+            self._addDevice(device)
+
+            format_type = udev_device_get_format(info)
+            args = [format_type]
+            kwargs = {"mdUuid": udev_device_get_md_uuid(info),
+                      "uuid": udev_device_get_uuid(info),
+                  "label": udev_device_get_label(info),
+                  "device": device.path,
+                  "exists": True}
+
+            log.debug("uuid=%s" % kwargs["uuid"])
+            log.debug("mdUuid=%s" % kwargs["mdUuid"])
+            device.format = formats.getFormat(*args, **kwargs)
+            log.debug("format=%s mdUuid=%s" % (device.format, device.format.mdUuid))
+            
+            if device.format.mdUuid:
+                md_array = self.getDeviceByUuid(device.format.mdUuid)
+                if md_array:
+                    log.debug("_addDevice to array")
+                    md_array._addDevice(device)
+                else:
+                    try:
+                        md_level = udev_device_get_md_level(info)
+                        md_devices = int(udev_device_get_md_devices(info))
+                        md_uuid = udev_device_get_md_uuid(info)
+                    except (KeyError, ValueError) as e:
+                        log.warning("invalid data for %s: %s" % (name, e))
+                        return
+         
+                    minor = 0
+                    while True:
+                          if self.getDeviceByName("imsm%d" % minor):
+                                minor += 1
+                          else:
+                                break
+                    md_name = "imsm%d" % minor
+                    md_array = MDRaidContainerDevice(md_name,
+                                                 level=md_level,
+                                                 minor=minor,
+                                                 memberDevices=md_devices,
+                                                 uuid=md_uuid,
+                                                 sysfsPath=sysfs_path,
+                                                 exists=True,
+                                                 parents=[device])
+                    try: 
+                        md_array.addFirstDevice(device.path)
+                        self._addDevice(md_array)
+                        return 
+                    except MDRaidError as e:
+                          log.warning("failed to add member to md array %s" % e)
+
     def addUdevMDDevice(self, info):
         name = udev_device_get_name(info)
         log_method_call(self, name=name)
@@ -1165,6 +1232,14 @@ class DeviceTree(object):
 
             if device is None:
                 device = self.addUdevDMDevice(info)
+        elif udev_device_is_container(info):
+            log.debug("%s is an md container device" % name)
+            if device is None and uuid:
+                # try to find the device by uuid
+                device = self.getDeviceByUuid(uuid)
+
+            if device is None:
+                device = self.addUdevMDContainerDevice(info)
         elif udev_device_is_md(info):
             log.debug("%s is an md device" % name)
             if device is None and uuid:
diff --git a/storage/udev.py b/storage/udev.py
index 63cc3fd..210237e 100644
--- a/storage/udev.py
+++ b/storage/udev.py
@@ -195,9 +195,16 @@ def udev_device_is_dm(info):
     """ Return True if the device is a device-mapper device. """
     return info.has_key("DM_NAME")
 
+def udev_device_is_container(info):
+    if info.has_key("MD_LEVEL") and \
+            info["MD_LEVEL"] == "container":
+            return True
+    return False
+
 def udev_device_is_md(info):
     """ Return True is the device is an mdraid array device. """
-    return info.has_key("MD_METADATA")
+    return info.has_key("MD_DEVNAME") and \
+           info.has_key("MD_METADATA")
 
 def udev_device_is_cdrom(info):
     """ Return True if the device is an optical drive. """
-- 
1.6.3.1.54.g99dd

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux