Skip to content

Commit

Permalink
WIP: Don't crash in populate when blockdev plugins are missing.
Browse files Browse the repository at this point in the history
  • Loading branch information
dwlehman committed Apr 16, 2018
1 parent 7ae76e4 commit 9732209
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 20 deletions.
14 changes: 7 additions & 7 deletions blivet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@
else:
_REQUESTED_PLUGIN_NAMES = set(("lvm", "btrfs", "swap", "crypto", "loop", "mdraid", "mpath", "dm"))

_requested_plugins = blockdev.plugin_specs_from_names(_REQUESTED_PLUGIN_NAMES)
#_requested_plugins = blockdev.plugin_specs_from_names(_REQUESTED_PLUGIN_NAMES)
try:
# do not check for dependencies during libblockdev initializtion, do runtime
# checks instead
blockdev.switch_init_checks(False)
succ_, avail_plugs = blockdev.try_reinit(require_plugins=_requested_plugins, reload=False, log_func=log_bd_message)
#succ_, avail_plugs = blockdev.try_reinit(require_plugins=_requested_plugins, reload=False, log_func=log_bd_message)
except GLib.GError as err:
raise RuntimeError("Failed to intialize the libblockdev library: %s" % err)
else:
avail_plugs = set(avail_plugs)
#else:
#avail_plugs = set(avail_plugs)

missing_plugs = _REQUESTED_PLUGIN_NAMES - avail_plugs
for p in missing_plugs:
log.info("Failed to load plugin %s", p)
#missing_plugs = _REQUESTED_PLUGIN_NAMES - avail_plugs
#for p in missing_plugs:
# log.info("Failed to load plugin %s", p)


class _LazyImportObject(object):
Expand Down
2 changes: 1 addition & 1 deletion blivet/populator/helpers/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class MDBiosRaidDevicePopulator(DiskDevicePopulator):
@classmethod
def match(cls, data):
return (super(MDBiosRaidDevicePopulator, MDBiosRaidDevicePopulator).match(data) and
udev.device_get_md_container(data))
udev.device_get_md_container(data) and not MDBiosRaidArrayDevice.unavailable_type_dependencies())

def _get_kwargs(self):
kwargs = super(MDBiosRaidDevicePopulator, self)._get_kwargs()
Expand Down
3 changes: 2 additions & 1 deletion blivet/populator/helpers/disklabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from ... import formats
from ... import udev
from ...devices import MultipathDevice
from ...errors import InvalidDiskLabelError
from ...storage_log import log_exception_info, log_method_call
from .formatpopulator import FormatPopulator
Expand All @@ -44,7 +45,7 @@ def match(cls, data, device):
return (bool(udev.device_get_disklabel_type(data)) and
not udev.device_is_biosraid_member(data) and
udev.device_get_format(data) != "iso9660" and
not (device.is_disk and mpath_members.is_mpath_member(device.path)))
not (device.is_disk and not MultipathDevice.unavailable_type_dependencies() and mpath_members.is_mpath_member(device.path)))

def _get_kwargs(self):
kwargs = super(DiskLabelFormatPopulator, self)._get_kwargs()
Expand Down
3 changes: 2 additions & 1 deletion blivet/populator/helpers/dm.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class DMDevicePopulator(DevicePopulator):

@classmethod
def match(cls, data):
return (udev.device_is_dm(data) and
return (not DMDevice.unavailable_type_dependencies() and
udev.device_is_dm(data) and
not udev.device_is_dm_partition(data) and
not udev.device_is_dm_luks(data) and
not udev.device_is_dm_lvm(data) and
Expand Down
4 changes: 4 additions & 0 deletions blivet/populator/helpers/dmraid.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class DMRaidFormatPopulator(FormatPopulator):
priority = 100
_type_specifier = "dmraidmember"

@classmethod
def match(cls, data, device):
return super(cls, cls).match(data, device) and not DMRaidArrayDevice.unavailable_type_dependencies()

def run(self):
super(DMRaidFormatPopulator, self).run()

Expand Down
2 changes: 1 addition & 1 deletion blivet/populator/helpers/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
class LoopDevicePopulator(DevicePopulator):
@classmethod
def match(cls, data):
return udev.device_is_loop(data)
return udev.device_is_loop(data) and not LoopDevice.unavailable_type_dependencies()

def run(self):
name = udev.device_get_name(self.data)
Expand Down
6 changes: 5 additions & 1 deletion blivet/populator/helpers/luks.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
class LUKSDevicePopulator(DevicePopulator):
@classmethod
def match(cls, data):
return udev.device_is_dm_luks(data)
return not LUKSDevice.unavailable_type_dependencies() and udev.device_is_dm_luks(data)

def run(self):
parents = self._devicetree._add_slave_devices(self.data)
Expand All @@ -56,6 +56,10 @@ class LUKSFormatPopulator(FormatPopulator):
priority = 100
_type_specifier = "luks"

@classmethod
def match(cls, data, device):
return not LUKSDevice.unavailable_type_dependencies() and super(cls, cls).match(data, device)

def _get_kwargs(self):
kwargs = super(LUKSFormatPopulator, self)._get_kwargs()
kwargs["name"] = "luks-%s" % udev.device_get_uuid(self.data)
Expand Down
6 changes: 5 additions & 1 deletion blivet/populator/helpers/lvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
class LVMDevicePopulator(DevicePopulator):
@classmethod
def match(cls, data):
return udev.device_is_dm_lvm(data)
return not LVMLogicalVolumeDevice.unavailable_type_dependencies() and udev.device_is_dm_lvm(data)

def run(self):
name = udev.device_get_name(self.data)
Expand Down Expand Up @@ -84,6 +84,10 @@ class LVMFormatPopulator(FormatPopulator):
priority = 100
_type_specifier = "lvmpv"

@classmethod
def match(cls, data, device):
return not LVMVolumeGroupDevice.unavailable_type_dependencies() and super(cls, cls).match(data, device)

def _get_kwargs(self):
kwargs = super(LVMFormatPopulator, self)._get_kwargs()

Expand Down
7 changes: 6 additions & 1 deletion blivet/populator/helpers/mdraid.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class MDDevicePopulator(DevicePopulator):
@classmethod
def match(cls, data):
return (udev.device_is_md(data) and
not udev.device_get_md_container(data))
not udev.device_get_md_container(data) and
not MDRaidArrayDevice.unavailable_type_dependencies())

def run(self):
name = udev.device_get_md_name(self.data)
Expand Down Expand Up @@ -96,6 +97,10 @@ class MDFormatPopulator(FormatPopulator):
priority = 100
_type_specifier = "mdmember"

@classmethod
def match(cls, data, device):
return super(cls, cls).match(data, device) and not MDRaidArrayDevice.unavailable_type_dependencies()

def _get_kwargs(self):
kwargs = super(MDFormatPopulator, self)._get_kwargs()
try:
Expand Down
3 changes: 2 additions & 1 deletion blivet/populator/helpers/multipath.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
class MultipathDevicePopulator(DevicePopulator):
@classmethod
def match(cls, data):
return (udev.device_is_dm_mpath(data) and
return (not MultipathDevice.unavailable_type_dependencies() and
udev.device_is_dm_mpath(data) and
not udev.device_is_dm_partition(data))

def run(self):
Expand Down
4 changes: 2 additions & 2 deletions blivet/populator/helpers/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from ... import udev
from ...devicelibs import lvm
from ...devices import PartitionDevice
from ...devices import PartitionDevice, MDRaidArrayDevice
from ...errors import DeviceError
from ...formats import get_format
from ...storage_log import log_method_call
Expand All @@ -51,7 +51,7 @@ def run(self):
log_method_call(self, name=name)
sysfs_path = udev.device_get_sysfs_path(self.data)

if name.startswith("md"):
if name.startswith("md") and not MDRaidArrayDevice.unavailable_type_dependencies():
name = blockdev.md.name_from_node(name)
device = self._devicetree.get_device_by_name(name)
if device:
Expand Down
9 changes: 7 additions & 2 deletions blivet/populator/populator.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ def _handle_degraded_md(self, info, device):
# If the md name is None, then some udev info is missing. Likely,
# this is because the array is degraded, and mdadm has deactivated
# it. Try to activate it and re-get the udev info.
if flags.allow_imperfect_devices and udev.device_get_md_name(info) is None:
if flags.allow_imperfect_devices and udev.device_get_md_name(info) is None and \
MDRaidArrayDevice.unavailable_type_dependencies():
devname = udev.device_get_devname(info)
if devname:
try:
Expand Down Expand Up @@ -333,6 +334,10 @@ def set_disk_images(self, images):

def setup_disk_images(self):
""" Set up devices to represent the disk image files. """
if LoopDevice.unavailable_type_dependencies():
log.error("Cannot set up disk images without libblockdev loop plugin.")
return

for (name, path) in self.disk_images.items():
log.info("setting up disk image file '%s' as '%s'", path, name)
dmdev = self.get_device_by_name(name)
Expand Down Expand Up @@ -427,7 +432,7 @@ def _populate(self):
self.drop_lvm_cache()
mpath_members.drop_cache()

if flags.auto_dev_updates and not flags.image_install:
if flags.auto_dev_updates and not flags.image_install and MultipathDevice.unavailable_type_dependencies():
blockdev.mpath.set_friendly_names(flags.multipath_friendly_names)

self.setup_disk_images()
Expand Down
6 changes: 5 additions & 1 deletion blivet/udev.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,11 @@ def device_dm_subsystem_match(info, subsystem):
if name is None:
return False

_subsystem = blockdev.dm.get_subsystem_from_name(name)
try:
_subsystem = blockdev.dm.get_subsystem_from_name(name)
except blockdev.BlockDevNotImplementedError:
return False

if not _subsystem:
return False

Expand Down

0 comments on commit 9732209

Please sign in to comment.