[PATCH 04/11] Use BlockDev's MD plugin instead of devicelibs/mdraid.py

Vratislav Podzimek vpodzime at redhat.com
Sun Feb 1 18:15:54 UTC 2015


Except for few things that are not provided by the libblockdev library and its
MD plugin.

Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 blivet/devicefactory.py     |   4 +-
 blivet/devicelibs/mdraid.py | 372 --------------------------------------------
 blivet/devices/md.py        |  39 ++---
 blivet/devicetree.py        |  33 ++--
 blivet/formats/__init__.py  |   5 +-
 blivet/formats/mdraid.py    |   5 +-
 tests/devices_test.py       |   4 +-
 7 files changed, 44 insertions(+), 418 deletions(-)

diff --git a/blivet/devicefactory.py b/blivet/devicefactory.py
index c383b4d..813669d 100644
--- a/blivet/devicefactory.py
+++ b/blivet/devicefactory.py
@@ -33,6 +33,8 @@ from .partitioning import TotalSizeSet
 from .partitioning import doPartitioning
 from .size import Size
 
+from gi.repository import BlockDev
+
 import logging
 log = logging.getLogger("blivet")
 
@@ -1571,7 +1573,7 @@ class MDFactory(DeviceFactory):
         return self.raid_level.get_space(self.size,
            len(self._get_member_devices()),
            None,
-           mdraid.get_raid_superblock_size)
+           BlockDev.md_get_superblock_size)
 
     def _get_total_space(self):
         return self._get_device_space()
diff --git a/blivet/devicelibs/mdraid.py b/blivet/devicelibs/mdraid.py
index 810c602..bbcd02f 100644
--- a/blivet/devicelibs/mdraid.py
+++ b/blivet/devicelibs/mdraid.py
@@ -20,12 +20,6 @@
 # Author(s): Dave Lehman <dlehman at redhat.com>
 #
 
-import os
-import re
-import string
-
-from .. import util
-from ..errors import MDRaidError
 from ..size import Size
 from . import raid
 
@@ -46,369 +40,3 @@ class MDRaidLevels(raid.RAIDLevels):
            hasattr(level, 'get_size')
 
 RAID_levels = MDRaidLevels(["raid0", "raid1", "raid4", "raid5", "raid6", "raid10", "linear"])
-
-def get_raid_superblock_size(size, version=None):
-    """ mdadm has different amounts of space reserved for its use depending
-    on the metadata type and size of the array.
-
-    :param size: size of the array
-    :type size: :class:`~.size.Size`
-    :param version: metadata version
-    :type version: str
-
-    0.9 use 2.0 MiB
-    1.0 use 2.0 MiB
-    1.1 or 1.2 use the formula lifted from mdadm/super1.c to calculate it
-    based on the array size.
-    """
-    # mdadm 3.2.4 made a major change in the amount of space used for 1.1 and 1.2
-    # in order to reserve space for reshaping. See commit 508a7f16 in the
-    # upstream mdadm repository.
-    headroom = MD_SUPERBLOCK_SIZE
-    if version is None or version in ["default", "1.1", "1.2"]:
-        # MDADM: We try to leave 0.1% at the start for reshape
-        # MDADM: operations, but limit this to 128Meg (0.1% of 10Gig)
-        # MDADM: which is plenty for efficient reshapes
-        # NOTE: In the mdadm code this is in 512b sectors. Converted to use MiB
-        MIN_HEADROOM = Size("1 MiB")
-        headroom = int(Size("128 MiB"))
-        while Size(headroom << 10) > size and Size(headroom) > MIN_HEADROOM:
-            headroom >>= 1
-
-        headroom = Size(headroom)
-
-    log.info("Using %s superBlockSize", headroom)
-    return headroom
-
-def mdadm(args, capture=False):
-    """ Run mdadm with specified arguments.
-
-        :param bool capture: if True, return the output of the command
-        :returns: the output of the command or None
-        :rtype: list of str or NoneType
-        :raises: MDRaidError if command fails
-    """
-    argv = ["mdadm"] + args
-    (ret, out) = util.run_program_and_capture_output(argv)
-    if ret:
-        raise MDRaidError(ret)
-    if capture:
-        return out
-
-def mdcreate(device, level, disks, spares=0, metadataVer=None, bitmap=False):
-    """ Create an mdarray from a list of devices.
-
-        :param str device: the path for the array
-        :param level: the level of the array
-        :type level: :class:`~.devicelibs.raid.RAIDLevel` or string
-        :param disks: the members of the array
-        :type disks: list of str
-        :param int spares: the number of spares in the array
-        :param str metadataVer: one of the mdadm metadata versions
-        :param bool bitmap: whether to create an internal bitmap on the device
-
-        Note that if the level is specified as a string, rather than by means
-        of a RAIDLevel object, it is not checked for validity. It is the
-        responsibility of the invoking method to verify that mdadm recognizes
-        the string.
-    """
-    argv = ["--create", device, "--run", "--level=%s" % level]
-    raid_devs = len(disks) - spares
-    argv.append("--raid-devices=%d" % raid_devs)
-    if spares:
-        argv.append("--spare-devices=%d" % spares)
-    if metadataVer:
-        argv.append("--metadata=%s" % metadataVer)
-    if bitmap:
-        argv.append("--bitmap=internal")
-    argv.extend(disks)
-
-    try:
-        mdadm(argv)
-    except MDRaidError as msg:
-        raise MDRaidError("mdcreate failed for %s: %s" % (device, msg))
-
-def mddestroy(device):
-    args = ["--zero-superblock", device]
-
-    try:
-        mdadm(args)
-    except MDRaidError as msg:
-        raise MDRaidError("mddestroy failed for %s: %s" % (device, msg))
-
-def mdnominate(device):
-    """ Attempt to add a device to the array to which it belongs.
-
-        Belonging is determined by mdadm's rules.
-
-        May start the array once a sufficient number of devices are added
-        to the array.
-
-        :param str device: path to the device to add
-        :rtype: NoneType
-        :raises: MDRaidError
-
-        .. seealso:: mdadd
-    """
-    args = ['--incremental', '--quiet', device]
-
-    try:
-        mdadm(args)
-    except MDRaidError as msg:
-        raise MDRaidError("mdnominate failed for %s: %s" % (device, msg))
-
-def mdadd(array, device, grow_mode=False, raid_devices=None):
-    """ Add a device to an array.
-
-        :param str array: path to the array to add the device to
-        :param str device: path to the device to add to the array
-        :keyword bool grow_mode: use grow mode
-        :keyword int raid_devices: the intended number of active member devices
-        :rtype: NoneType
-        :raises: MDRaidError
-
-        The grow_devices parameter is used when adding devices to a raid
-        array that has no actual redundancy. In this case it is necessary
-        to explicitly grow the array all at once rather than manage it in
-        the sense of adding spares.
-
-        If raid_devices is set, and grow_mode is True, then the intended
-        number of devices after this device is added is specified
-        using the --raid-devices flag. If grow is not True then raid_devices
-        is ignored. For linear arrays, specifying raid_devices will result
-        in a failure.
-
-        Whether the new device will be added as a spare or an active member
-        when not in grow mode is decided by mdadm.
-
-        .. seealso:: mdnominate
-    """
-    if grow_mode:
-        args = ["--grow", array]
-        if raid_devices:
-            args.extend(["--raid-devices", str(raid_devices)])
-    else:
-        args = [array]
-    args.extend(["--add", device])
-
-    try:
-        mdadm(args)
-    except MDRaidError as msg:
-        raise MDRaidError("mdadd failed for %s: %s" % (device, msg))
-
-def mdremove(array, device, fail=False):
-    """ Remove a device from an array.
-
-        :param str array: path to the array to remove the device from
-        :param str device: path to the device to remove
-        :keyword bool fail: mark the device as failed before removing it
-
-        .. note::
-
-            Only spares and failed devices can be removed. To remove an active
-            member device you must specify fail=True.
-    """
-    args = [array]
-    if fail:
-        args.extend(["--fail", device])
-
-    args.extend(["--remove", device])
-
-    try:
-        mdadm(args)
-    except MDRaidError as msg:
-        raise MDRaidError("mdremove failed for %s: %s" % (device, msg))
-
-def mdactivate(device, members=None, array_uuid=None):
-    """Assemble devices given by members into a single device.
-
-       Use array_uuid to identify the devices in members to include in
-       the assembled array.
-
-       :param str device: the device to be assembled
-       :param members: the component devices to be considered for inclusion
-       :type members: list of str or NoneType
-       :param array_uuid: the UUID of the array
-       :type array_uuid: str or NoneType
-
-       :raises: :class:`~.errors.MDRaidError` if no array_uuid specified
-       or assembly failed
-    """
-    members = members or []
-
-    if not array_uuid:
-        raise MDRaidError("mdactivate requires a uuid")
-
-    identifier = "--uuid=%s" % array_uuid
-
-    args = ["--assemble", device, identifier, "--run"]
-    args += members
-
-    try:
-        mdadm(args)
-    except MDRaidError as msg:
-        raise MDRaidError("mdactivate failed for %s: %s" % (device, msg))
-
-def mddeactivate(device):
-    args = ["--stop", device]
-
-    try:
-        mdadm(args)
-    except MDRaidError as msg:
-        raise MDRaidError("mddeactivate failed for %s: %s" % (device, msg))
-
-def mdrun(device):
-    """Start a possibly degraded array.
-
-       :param str device: the device to be started
-
-       :raises :class:`~.errors.MDRaidError`: on failure
-    """
-    args = ["--run", device]
-
-    try:
-        mdadm(args)
-    except MDRaidError as msg:
-        raise MDRaidError("mdrun failed for %s: %s" % (device, msg))
-
-def process_UUIDS(info, UUID_keys):
-    """ Extract and convert expected UUIDs to canonical form.
-        Reassign canonicalized UUIDs to corresponding keys.
-
-        :param dict info: a dictionary of key/value pairs
-        :param tuple UUID_keys: a list of keys known to be UUIDs
-    """
-    for k, v in ((k, info[k]) for k in UUID_keys if k in info):
-        try:
-            # extract mdadm UUID, e.g., '3386ff85:f5012621:4a435f06:1eb47236'
-            the_uuid = re.match(r"(([a-f0-9]){8}:){3}([a-f0-9]){8}", v)
-
-            info[k] = util.canonicalize_UUID(the_uuid.group())
-        except (ValueError, AttributeError) as e:
-            # the unlikely event that mdadm's UUIDs change their format
-            log.warning('uuid value %s could not be canonicalized: %s', v, e)
-            info[k] = v # record the value, since mdadm provided something
-
-def mdexamine(device):
-    """ Run mdadm --examine to obtain information about an array member.
-
-        :param str device: path of the member device
-        :rtype: a dict of strings
-        :returns: a dict containing labels and values extracted from output
-    """
-    try:
-        _vars = mdadm(["--examine", "--export", device], capture=True).split()
-        _bvars = mdadm(["--examine", "--brief", device], capture=True).split()
-    except MDRaidError as e:
-        raise MDRaidError("mdexamine failed for %s: %s" % (device, e))
-
-    info = {}
-    if len(_bvars) > 1 and _bvars[1].startswith("/dev/md"):
-        info["DEVICE"] = _bvars[1]
-        _bvars = _bvars[2:]
-
-    for var in _vars:
-        (name, equals, value) = var.partition("=")
-        if not equals:
-            continue
-
-        info[name.upper()] = value.strip()
-
-    if "MD_METADATA" not in info:
-        for var in _bvars:
-            (name, equals, value) = var.partition("=")
-            if not equals:
-                continue
-
-            if name == "metadata":
-                info["MD_METADATA"] = value
-                break
-
-    process_UUIDS(info, ('MD_UUID', 'MD_DEV_UUID'))
-
-    return info
-
-def mddetail(device):
-    """Run mdadm --detail in order to read information about an array.
-
-       Note: The --export flag is not used. According to the man pages
-       the export flag just formats the output as key=value pairs for
-       easy import, but in the case of --detail it also omits the majority
-       of the information, including information of real use like the
-       number of spares in the array.
-
-       :param str device: path of the array device
-       :rtype: a dict of strings
-       :returns: a dict containing labels and values extracted from output
-    """
-    try:
-        lines = mdadm(["--detail", device], capture=True).split("\n")
-    except MDRaidError as e:
-        raise MDRaidError("mddetail failed for %s: %s" % (device, e))
-
-    info = {}
-    for (name, colon, value) in (line.strip().partition(":") for line in lines):
-        value = value.strip()
-        name = name.strip().upper()
-        if colon and value and name:
-            info[name] = value
-
-    process_UUIDS(info, ('UUID',))
-
-    return info
-
-def md_node_from_name(name):
-    named_path = "/dev/md/" + name
-    try:
-        node = os.path.basename(os.readlink(named_path))
-    except OSError as e:
-        raise MDRaidError("md_node_from_name failed: %s" % e)
-    else:
-        return node
-
-def name_from_md_node(node):
-    md_dir = "/dev/md"
-    name = None
-    if os.path.isdir(md_dir):
-        # It's sad, but it's what we've got.
-        for link in os.listdir(md_dir):
-            full_path = "%s/%s" % (md_dir, link)
-            md_name = os.path.basename(os.readlink(full_path))
-            log.debug("link: %s -> %s", link, os.readlink(full_path))
-            if md_name == node:
-                name = link
-                break
-
-    if not name:
-        raise MDRaidError("name_from_md_node(%s) failed" % node)
-
-    log.debug("returning %s", name)
-    return name
-
-def mduuid_from_canonical(a_uuid):
-    """ Change a canonicalized uuid to mdadm's preferred format.
-
-        :param str a_uuid: a string representing a UUID.
-
-        :returns: a UUID in mdadm's preferred format
-        :rtype: str
-
-        :raises MDRaidError: if it can not do the conversion
-
-        mdadm's UUIDs are actual 128 bit uuids, but it formats them strangely.
-        This converts a uuid from canonical form to mdadm's form.
-        Example:
-            mdadm UUID: '3386ff85:f5012621:4a435f06:1eb47236'
-        canonical UUID: '3386ff85-f501-2621-4a43-5f061eb47236'
-    """
-    NUM_DIGITS = 32
-    a_uuid = a_uuid.replace('-', '')
-
-    if len(a_uuid) != NUM_DIGITS:
-        raise MDRaidError("Missing digits in stripped UUID %s." % a_uuid)
-
-    if any(c not in string.hexdigits for c in a_uuid):
-        raise MDRaidError("Non-hex digits in stripped UUID %s." % a_uuid)
-
-    CHUNK_LEN = 8
-    return ":".join(a_uuid[n:n+CHUNK_LEN] for n in range(0, NUM_DIGITS, CHUNK_LEN))
diff --git a/blivet/devices/md.py b/blivet/devices/md.py
index 105ee1e..8f18b19 100644
--- a/blivet/devices/md.py
+++ b/blivet/devices/md.py
@@ -21,6 +21,8 @@
 
 import os
 
+from gi.repository import BlockDev
+
 from ..devicelibs import mdraid, raid
 
 from .. import errors
@@ -129,7 +131,7 @@ class MDRaidArrayDevice(ContainerDevice, RaidDevice):
 
         if self.uuid is not None:
             try:
-                formatted_uuid = mdraid.mduuid_from_canonical(self.uuid)
+                formatted_uuid = BlockDev.md_get_md_uuid(self.uuid)
             except errors.MDRaidError:
                 pass
 
@@ -192,7 +194,7 @@ class MDRaidArrayDevice(ContainerDevice, RaidDevice):
            :returns: estimated superblock size
            :rtype: :class:`~.size.Size`
         """
-        return mdraid.get_raid_superblock_size(raw_array_size,
+        return BlockDev.md_get_superblock_size(raw_array_size,
                                                version=self.metadataVersion)
 
     @property
@@ -421,9 +423,7 @@ class MDRaidArrayDevice(ContainerDevice, RaidDevice):
             member.setup(orig=orig)
             disks.append(member.path)
 
-        mdraid.mdactivate(self.path,
-                          members=disks,
-                          array_uuid=self.mdadmFormatUUID)
+        BlockDev.md_activate(self.path, members=disks, uuid=self.mdadmFormatUUID)
 
     def _postTeardown(self, recursive=False):
         super(MDRaidArrayDevice, self)._postTeardown(recursive=recursive)
@@ -437,14 +437,14 @@ class MDRaidArrayDevice(ContainerDevice, RaidDevice):
         log_method_call(self, self.name, status=self.status,
                         controllable=self.controllable)
         # we don't really care about the return value of _preTeardown here.
-        # see comment just above mddeactivate call
+        # see comment just above md_deactivate call
         self._preTeardown(recursive=recursive)
 
         # We don't really care what the array's state is. If the device
         # file exists, we want to deactivate it. mdraid has too many
         # states.
         if self.exists and os.path.exists(self.path):
-            mdraid.mddeactivate(self.path)
+            BlockDev.md_deactivate(self.path)
 
         self._postTeardown(recursive=recursive)
 
@@ -472,8 +472,8 @@ class MDRaidArrayDevice(ContainerDevice, RaidDevice):
 
         # update our uuid attribute with the new array's UUID
         # XXX this won't work for containers since no UUID is reported for them
-        info = mdraid.mddetail(self.path)
-        self.uuid = info.get("UUID")
+        info = BlockDev.md_detail(self.path)
+        self.uuid = info.uuid
         for member in self.devices:
             member.format.mdUuid = self.uuid
 
@@ -482,19 +482,16 @@ class MDRaidArrayDevice(ContainerDevice, RaidDevice):
         log_method_call(self, self.name, status=self.status)
         disks = [disk.path for disk in self.devices]
         spares = len(self.devices) - self.memberDevices
-        mdraid.mdcreate(self.path,
-                        self.level,
-                        disks,
-                        spares,
-                        metadataVer=self.metadataVersion,
-                        bitmap=self.createBitmap)
+        BlockDev.md_create(self.path, self.level, disks, spares,
+                           version=self.metadataVersion,
+                           bitmap=self.createBitmap)
         udev.settle()
 
     def _remove(self, member):
         self.setup()
         # see if the device must be marked as failed before it can be removed
         fail = (self.memberStatus(member) == "in_sync")
-        mdraid.mdremove(self.path, member.path, fail=fail)
+        BlockDev.md_remove(self.path, member.path, fail)
 
     def _add(self, member):
         """ Add a member device to an array.
@@ -505,17 +502,15 @@ class MDRaidArrayDevice(ContainerDevice, RaidDevice):
         """
         self.setup()
 
-        grow_mode = False
         raid_devices = None
         try:
             if not self.level.has_redundancy():
-                grow_mode = True
                 if self.level is not raid.Linear:
-                    raid_devices = int(mdraid.mddetail(self.name)['RAID DEVICES']) + 1
+                    raid_devices = int(BlockDev.md_detail(self.name).raid_devices) + 1
         except errors.RaidError:
             pass
 
-        mdraid.mdadd(self.path, member.path, grow_mode=grow_mode, raid_devices=raid_devices)
+        BlockDev.md_add(self.path, member.path, raid_devs=raid_devices)
 
     @property
     def formatArgs(self):
@@ -583,7 +578,7 @@ class MDContainerDevice(MDRaidArrayDevice):
         log_method_call(self, self.name, status=self.status,
                         controllable=self.controllable)
         # we don't really care about the return value of _preTeardown here.
-        # see comment just above mddeactivate call
+        # see comment just above md_deactivate call
         self._preTeardown(recursive=recursive)
 
         # Since BIOS RAID sets (containers in mdraid terminology) never change
@@ -641,7 +636,7 @@ class MDBiosRaidArrayDevice(MDRaidArrayDevice):
         log_method_call(self, self.name, status=self.status,
                         controllable=self.controllable)
         # we don't really care about the return value of _preTeardown here.
-        # see comment just above mddeactivate call
+        # see comment just above md_deactivate call
         self._preTeardown(recursive=recursive)
 
         # Since BIOS RAID sets (containers in mdraid terminology) never change
diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index ccad353..85b378b 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -27,7 +27,7 @@ import shutil
 import pprint
 import copy
 
-from gi.repository import BlockDev
+from gi.repository import BlockDev, GLib
 
 from .errors import CryptoError, DeviceError, DeviceTreeError, DiskLabelCommitError, DMError, FSError, InvalidDiskLabelError, LUKSError, MDRaidError, StorageError, UnusableConfigurationError
 from .devices import BTRFSDevice, BTRFSSubVolumeDevice, BTRFSVolumeDevice, BTRFSSnapShotDevice
@@ -44,7 +44,6 @@ from .deviceaction import ActionCreateDevice, ActionDestroyDevice, action_type_f
 from . import formats
 from .formats import getFormat
 from .formats.fs import nodev_filesystems
-from .devicelibs import mdraid
 from .devicelibs import dm
 from .devicelibs import lvm
 from .devicelibs import loop
@@ -893,7 +892,7 @@ class DeviceTree(object):
 
             log.error("failed to scan md array %s", name)
             try:
-                mdraid.mddeactivate(path)
+                BlockDev.md_deactivate(path)
             except MDRaidError:
                 log.error("failed to stop broken md array %s", name)
 
@@ -905,7 +904,7 @@ class DeviceTree(object):
         sysfs_path = udev.device_get_sysfs_path(info)
 
         if name.startswith("md"):
-            name = mdraid.name_from_md_node(name)
+            name = BlockDev.md_name_from_node(name)
             device = self.getDeviceByName(name)
             if device:
                 return device
@@ -914,7 +913,7 @@ class DeviceTree(object):
             disk_name = os.path.basename(os.path.dirname(sysfs_path))
             disk_name = disk_name.replace('!','/')
             if disk_name.startswith("md"):
-                disk_name = mdraid.name_from_md_node(disk_name)
+                disk_name = BlockDev.md_name_from_node(disk_name)
 
             disk = self.getDeviceByName(disk_name)
 
@@ -1023,7 +1022,7 @@ class DeviceTree(object):
             parentName = devicePathToName(parentPath)
             container = self.getDeviceByName(parentName)
             if not container:
-                parentSysName = mdraid.md_node_from_name(parentName)
+                parentSysName = BlockDev.md_node_from_name(parentName)
                 container_sysfs = "/class/block/" + parentSysName
                 container_info = udev.get_device(container_sysfs)
                 if not container_info:
@@ -1154,8 +1153,8 @@ class DeviceTree(object):
                 devname = udev.device_get_devname(info)
                 if devname:
                     try:
-                        mdraid.mdrun(devname)
-                    except MDRaidError as e:
+                        BlockDev.md_run(devname)
+                    except GLib.Error as e:
                         log.warning("Failed to start possibly degraded md array: %s", e)
                     else:
                         udev.settle()
@@ -1589,7 +1588,7 @@ class DeviceTree(object):
     def handleUdevMDMemberFormat(self, info, device):
         # pylint: disable=unused-argument
         log_method_call(self, name=device.name, type=device.format.type)
-        md_info = mdraid.mdexamine(device.path)
+        md_info = BlockDev.md_examine(device.path)
         md_array = self.getDeviceByUuid(device.format.mdUuid, incomplete=True)
         if device.format.mdUuid and md_array:
             md_array.parents.append(device)
@@ -1597,9 +1596,9 @@ class DeviceTree(object):
             # create the array with just this one member
             try:
                 # level is reported as, eg: "raid1"
-                md_level = udev.device_get_md_level(md_info)
-                md_devices = udev.device_get_md_devices(md_info)
-                md_uuid = udev.device_get_md_uuid(md_info)
+                md_level = md_info.level
+                md_devices = md_info.num_devices
+                md_uuid = md_info.uuid
             except (KeyError, ValueError) as e:
                 log.warning("invalid data for %s: %s", device.name, e)
                 return
@@ -1608,12 +1607,12 @@ class DeviceTree(object):
                 log.warning("invalid data for %s: no RAID level", device.name)
                 return
 
-            # mdexamine yields MD_METADATA only for metadata version > 0.90
+            # md_examine yields metadata (MD_METADATA) only for metadata version > 0.90
             # if MD_METADATA is missing, assume metadata version is 0.90
-            md_metadata = udev.device_get_md_metadata(md_info) or "0.90"
-            md_name = udev.device_get_md_name(md_info)
+            md_metadata = md_info.metadata or "0.90"
+            md_name = md_info.name
             if not md_name:
-                md_path = md_info.get("DEVICE", "")
+                md_path = md_info.device or ""
                 if md_path:
                     md_name = devicePathToName(md_path)
                     if re.match(r'md\d+$', md_name):
@@ -2558,7 +2557,7 @@ class DeviceTree(object):
 
                 if re.match(r'/dev/md\d+(p\d+)?$', devspec):
                     try:
-                        md_name = mdraid.name_from_md_node(devspec[5:])
+                        md_name = BlockDev.md_name_from_node(devspec[5:])
                     except StorageError as e:
                         log.info("failed to resolve %s: %s", devspec, e)
                         md_name = None
diff --git a/blivet/formats/__init__.py b/blivet/formats/__init__.py
index 0b84528..aa94f45 100644
--- a/blivet/formats/__init__.py
+++ b/blivet/formats/__init__.py
@@ -1,3 +1,4 @@
+
 # __init__.py
 # Entry point for anaconda storage formats subpackage.
 #
@@ -21,6 +22,7 @@
 #
 
 import os
+from gi.repository import BlockDev
 
 from ..util import notify_kernel
 from ..util import get_sysfs_path_by_name
@@ -29,7 +31,6 @@ from ..util import ObjectID
 from ..storage_log import log_method_call
 from ..errors import DeviceFormatError, DMError, FormatCreateError, FormatDestroyError, FormatSetupError, MDRaidError
 from ..devicelibs.dm import dm_node_from_name
-from ..devicelibs.mdraid import md_node_from_name
 from ..i18n import N_
 from ..size import Size
 
@@ -337,7 +338,7 @@ class DeviceFormat(ObjectID):
                 return
         elif self.device.startswith("/dev/md/"):
             try:
-                name = md_node_from_name(os.path.basename(self.device))
+                name = BlockDev.md_node_from_name(os.path.basename(self.device))
             except MDRaidError:
                 log.warning("failed to get md node for %s", self.device)
                 return
diff --git a/blivet/formats/mdraid.py b/blivet/formats/mdraid.py
index 5525eba..c4c3202 100644
--- a/blivet/formats/mdraid.py
+++ b/blivet/formats/mdraid.py
@@ -22,10 +22,11 @@
 
 import os
 
+from gi.repository import BlockDev
+
 from ..storage_log import log_method_call
 from parted import PARTITION_RAID
 from ..errors import MDMemberError
-from ..devicelibs import mdraid
 from . import DeviceFormat, register_device_format
 from ..flags import flags
 from ..i18n import N_
@@ -88,7 +89,7 @@ class MDRaidMember(DeviceFormat):
         if not os.access(self.device, os.W_OK):
             raise MDMemberError("device path does not exist")
 
-        mdraid.mddestroy(self.device)
+        BlockDev.md_destroy(self.device)
         self.exists = False
 
     @property
diff --git a/tests/devices_test.py b/tests/devices_test.py
index c526c74..333cc04 100644
--- a/tests/devices_test.py
+++ b/tests/devices_test.py
@@ -3,6 +3,7 @@
 
 import os
 import unittest
+from gi.repository import BlockDev
 
 from mock import Mock
 
@@ -31,7 +32,6 @@ from blivet.devices import PartitionDevice
 from blivet.devices import StorageDevice
 from blivet.devices import ParentList
 from blivet.devicelibs import btrfs
-from blivet.devicelibs import mdraid
 from blivet.size import Size
 from blivet.util import sparsetmpfile
 
@@ -520,7 +520,7 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
         self.stateCheck(self.dev19,
                         devices=xform(lambda x, m: self.assertEqual(len(x), 2, m)),
                         level=xform(lambda x, m: self.assertEqual(x.number, 1, m)),
-                        mdadmFormatUUID=xform(lambda x, m: self.assertEqual(x, mdraid.mduuid_from_canonical(self.dev19.uuid), m)),
+                        mdadmFormatUUID=xform(lambda x, m: self.assertEqual(x, BlockDev.md_get_md_uuid(self.dev19.uuid), m)),
                         parents=xform(lambda x, m: self.assertEqual(len(x), 2, m)),
                         uuid=xform(lambda x, m: self.assertEqual(x, self.dev19.uuid, m)))
 
-- 
2.1.0



More information about the anaconda-patches mailing list