From 9f142246563a154e530cf0383f56029cdbdeda80 Mon Sep 17 00:00:00 2001 From: David Lehman Date: Fri, 18 Oct 2024 15:55:31 +0200 Subject: [PATCH] Don't crash in populate when blockdev plugins are missing Co-authored-by: Vojtech Trefny --- blivet/populator/helpers/disk.py | 2 ++ blivet/populator/helpers/dm.py | 2 ++ blivet/populator/helpers/loop.py | 2 ++ blivet/populator/helpers/lvm.py | 10 ++++++++-- blivet/populator/helpers/mdraid.py | 7 +++++++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/blivet/populator/helpers/disk.py b/blivet/populator/helpers/disk.py index aa10c8693..8facfbbef 100644 --- a/blivet/populator/helpers/disk.py +++ b/blivet/populator/helpers/disk.py @@ -36,6 +36,7 @@ from ...devices import NVMeNamespaceDevice, NVMeFabricsNamespaceDevice from ...devices import device_path_to_name from ...storage_log import log_method_call +from ...tasks import availability from .devicepopulator import DevicePopulator import logging @@ -151,6 +152,7 @@ class MDBiosRaidDevicePopulator(DiskDevicePopulator): _device_class = MDBiosRaidArrayDevice @classmethod + @availability.blockdev_md_required() def match(cls, data): return (super(MDBiosRaidDevicePopulator, MDBiosRaidDevicePopulator).match(data) and udev.device_get_md_container(data)) diff --git a/blivet/populator/helpers/dm.py b/blivet/populator/helpers/dm.py index 7dc15db98..908157d8f 100644 --- a/blivet/populator/helpers/dm.py +++ b/blivet/populator/helpers/dm.py @@ -23,6 +23,7 @@ from ... import udev from ...devices import DMDevice from ...storage_log import log_method_call +from ...tasks import availability from .devicepopulator import DevicePopulator import logging @@ -33,6 +34,7 @@ class DMDevicePopulator(DevicePopulator): priority = 50 @classmethod + @availability.blockdev_dm_required() def match(cls, data): return (udev.device_is_dm(data) and not udev.device_is_dm_partition(data) and diff --git a/blivet/populator/helpers/loop.py b/blivet/populator/helpers/loop.py index 956b0a52b..a084f9380 100644 --- a/blivet/populator/helpers/loop.py +++ b/blivet/populator/helpers/loop.py @@ -27,11 +27,13 @@ from ... import udev from ...devices import FileDevice, LoopDevice from ...storage_log import log_method_call +from ...tasks import availability from .devicepopulator import DevicePopulator class LoopDevicePopulator(DevicePopulator): @classmethod + @availability.blockdev_loop_required() def match(cls, data): return udev.device_is_loop(data) diff --git a/blivet/populator/helpers/lvm.py b/blivet/populator/helpers/lvm.py index 4ba51e4b8..98737fac5 100644 --- a/blivet/populator/helpers/lvm.py +++ b/blivet/populator/helpers/lvm.py @@ -33,7 +33,7 @@ from ...flags import flags from ...size import Size from ...storage_log import log_method_call -from ...tasks.availability import BLOCKDEV_LVM_PLUGIN_VDO +from ...tasks import availability from .devicepopulator import DevicePopulator from .formatpopulator import FormatPopulator @@ -45,6 +45,7 @@ class LVMDevicePopulator(DevicePopulator): @classmethod + @availability.blockdev_lvm_required() def match(cls, data): return udev.device_is_dm_lvm(data) @@ -87,6 +88,11 @@ class LVMFormatPopulator(FormatPopulator): priority = 100 _type_specifier = "lvmpv" + @classmethod + @availability.blockdev_lvm_required() + def match(cls, data, device): + return super(cls, cls).match(data, device) + def _get_kwargs(self): kwargs = super(LVMFormatPopulator, self)._get_kwargs() @@ -247,7 +253,7 @@ def add_lv(lv): lv_parents = [self._devicetree.get_device_by_device_id("LVM-" + pool_device_name)] elif lv_attr[0] == 'd': # vdo pool - if BLOCKDEV_LVM_PLUGIN_VDO.available: + if availability.BLOCKDEV_LVM_PLUGIN_VDO.available: pool_info = blockdev.lvm.vdo_info(vg_name, lv_name) if pool_info: lv_kwargs["compression"] = pool_info.compression diff --git a/blivet/populator/helpers/mdraid.py b/blivet/populator/helpers/mdraid.py index fb1b410ae..e3348c355 100644 --- a/blivet/populator/helpers/mdraid.py +++ b/blivet/populator/helpers/mdraid.py @@ -34,6 +34,7 @@ from ...errors import DeviceError, NoParentsError, MDRaidError from ...flags import flags from ...storage_log import log_method_call +from ...tasks import availability from .devicepopulator import DevicePopulator from .formatpopulator import FormatPopulator @@ -43,6 +44,7 @@ class MDDevicePopulator(DevicePopulator): @classmethod + @availability.blockdev_md_required() def match(cls, data): return (udev.device_is_md(data) and not udev.device_get_md_container(data)) @@ -99,6 +101,11 @@ class MDFormatPopulator(FormatPopulator): priority = 100 _type_specifier = "mdmember" + @classmethod + @availability.blockdev_md_required() + def match(cls, data, device): + return super(cls, cls).match(data, device) + def _get_kwargs(self): kwargs = super(MDFormatPopulator, self)._get_kwargs() kwargs["biosraid"] = udev.device_is_biosraid_member(self.data)