From d897708adf2b1576322e4480b664bde86f2b8726 Mon Sep 17 00:00:00 2001 From: David Lehman Date: Fri, 6 Mar 2015 12:24:01 -0600 Subject: [PATCH 07/19] Add a method to return a list of names of disks used by a udev device. The purpose of this is to obtain a set of related disks on which to cancel all scheduled actions. For loop and sr devices we just want to return thei device itself, even if the device (loop) has a backing file on disk somewhere. --- blivet/discoverer.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/blivet/discoverer.py b/blivet/discoverer.py index 0f7d2a8..3df9951 100644 --- a/blivet/discoverer.py +++ b/blivet/discoverer.py @@ -261,6 +261,51 @@ class DeviceDiscoverer(object): return slave_devices + def getUdevDeviceDisks(self, info): + """ Return a list of disk names used by a udev device. + + :param :class:`pyudev.Device` info: the device's udev info + :returns: a list of the disks used by the device + :rtype: list of str + + .. note:: + + cciss names are returned in blivet-compatible form, eg: + cciss/c0d0p1 (not cciss!c0d0p1) + + """ + name = udev.device_get_name(info) + sysfs_path = udev.device_get_sysfs_path(info) + slave_dir = os.path.normpath("%s/slaves" % sysfs_path) + slave_names = self._getSlaveNames(info) + disks = [] + + # cciss in sysfs is "cciss!cXdYpZ" but we need "cciss/cXdYpZ" + name = name.replace("!", "/") + + if self.udevDeviceIsDisk(info): + # this should catch multipath, dmraid, &c + disks.append(name) + elif udev.device_is_partition(info): + disk_name = udev.device_get_partition_disk(info) + if disk_name: + disks.append(disk_name) + elif not slave_names: + # loop, sr + disks.append(name) + + for slave_name in slave_names: + path = os.path.normpath("%s/%s" % (slave_dir, slave_name)) + slave_info = udev.get_device(os.path.realpath(path)) + if not slave_info: + log.warning("unable to get udev info for %s", slave_name) + continue + + slave_disks = self.getUdevDeviceDisks(slave_info) + disks.extend(d for d in slave_disks if d not in disks) + + return disks + def addUdevLVDevice(self, info): name = udev.device_get_name(info) log_method_call(self, name=name) -- 1.9.3