From b75fdddd7f3e54822d1231ca58de374fdedb8464 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Tue, 31 Oct 2023 11:15:16 +0100 Subject: [PATCH 1/2] Move kpartx dependency from DMDevice to MultipathDevice We don't need kpartx for all DM devices (and devices that are based on it like LUKS or LVM) so we are moving the dependency to the MultipathDevice where we can expect partitions to be present on a device mapper device. --- blivet/devices/disk.py | 2 +- blivet/devices/dm.py | 5 +---- tests/unit_tests/devices_test/lvm_test.py | 8 +++----- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/blivet/devices/disk.py b/blivet/devices/disk.py index 5053f7bb8..e20fe01e0 100644 --- a/blivet/devices/disk.py +++ b/blivet/devices/disk.py @@ -225,7 +225,7 @@ class MultipathDevice(DMDevice): _packages = ["device-mapper-multipath"] _partitionable = True _is_disk = True - _external_dependencies = [availability.MULTIPATH_APP] + _external_dependencies = [availability.MULTIPATH_APP, availability.KPARTX_APP] def __init__(self, name, fmt=None, size=None, wwn=None, parents=None, sysfs_path=''): diff --git a/blivet/devices/dm.py b/blivet/devices/dm.py index 4362f821f..ddb7ea012 100644 --- a/blivet/devices/dm.py +++ b/blivet/devices/dm.py @@ -47,10 +47,7 @@ class DMDevice(StorageDevice): """ A device-mapper device """ _type = "dm" _dev_dir = "/dev/mapper" - _external_dependencies = [ - availability.KPARTX_APP, - availability.BLOCKDEV_DM_PLUGIN - ] + _external_dependencies = [availability.BLOCKDEV_DM_PLUGIN] def __init__(self, name, fmt=None, size=None, dm_uuid=None, uuid=None, target=None, exists=False, parents=None, sysfs_path=''): diff --git a/tests/unit_tests/devices_test/lvm_test.py b/tests/unit_tests/devices_test/lvm_test.py index ff38a2f47..b80335ee8 100644 --- a/tests/unit_tests/devices_test/lvm_test.py +++ b/tests/unit_tests/devices_test/lvm_test.py @@ -904,10 +904,9 @@ def test_vdo_dependencies(self): size=blivet.size.Size("40 GiB")) # Dependencies check: for VDO types these should be combination of "normal" - # LVM dependencies (LVM libblockdev plugin + kpartx and DM plugin from DMDevice) + # LVM dependencies (LVM libblockdev plugin and DM plugin from DMDevice) # and LVM VDO technology from the LVM plugin - lvm_vdo_dependencies = ["kpartx", - "libblockdev dm plugin", + lvm_vdo_dependencies = ["libblockdev dm plugin", "libblockdev lvm plugin", "libblockdev lvm plugin (vdo technology)"] pool_deps = [d.name for d in vdopool.external_dependencies] @@ -930,8 +929,7 @@ def test_vdo_dependencies(self): size=blivet.size.Size("1 GiB")) normalvl_deps = [d.name for d in normallv.external_dependencies] - six.assertCountEqual(self, normalvl_deps, ["kpartx", - "libblockdev dm plugin", + six.assertCountEqual(self, normalvl_deps, ["libblockdev dm plugin", "libblockdev lvm plugin"]) with patch("blivet.devices.lvm.LVMVDOPoolMixin._external_dependencies", From 46ac2a4c1fb22d96e73c2f0baca0bc230d36b0b6 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Tue, 31 Oct 2023 11:16:28 +0100 Subject: [PATCH 2/2] Do not fail when kpartx is not available We don't need to fail just because kpartx is missing, we can just log warning and not activate the partitions. --- blivet/devices/dm.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/blivet/devices/dm.py b/blivet/devices/dm.py index ddb7ea012..b48cd6140 100644 --- a/blivet/devices/dm.py +++ b/blivet/devices/dm.py @@ -127,6 +127,10 @@ def get_dm_node(self): def setup_partitions(self): log_method_call(self, name=self.name) + if not availability.KPARTX_APP.available: + log.warning("'kpartx' not available, not activating partitions on %s", self.path) + return + rc = util.run_program(["kpartx", "-a", "-s", self.path]) if rc: raise errors.DMError("partition activation failed for '%s'" % self.name) @@ -134,6 +138,9 @@ def setup_partitions(self): def teardown_partitions(self): log_method_call(self, name=self.name) + if not availability.KPARTX_APP.available: + log.warning("'kpartx' not available, not deactivating partitions on %s", self.path) + return rc = util.run_program(["kpartx", "-d", "-s", self.path]) if rc: raise errors.DMError("partition deactivation failed for '%s'" % self.name)