From ce94732da0c1075f84eb021577aca9d138aaaa62 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Fri, 31 Jan 2025 12:49:17 +0100 Subject: [PATCH] lvm: Check lvm.conf for auto-activation support lvmetad is no longer used so we need to check LVM config for the auto-activation support. --- blivet/devicelibs/lvm.py | 19 ++++++++++++------- blivet/devices/lvm.py | 8 +++----- .../devices_test/device_methods_test.py | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/blivet/devicelibs/lvm.py b/blivet/devicelibs/lvm.py index 3055b2f5e..beac20bd7 100644 --- a/blivet/devicelibs/lvm.py +++ b/blivet/devicelibs/lvm.py @@ -21,7 +21,6 @@ # import math -import os import re from collections import namedtuple @@ -70,8 +69,6 @@ EXTERNAL_DEPENDENCIES = [availability.BLOCKDEV_LVM_PLUGIN] -LVMETAD_SOCKET_PATH = "/run/lvm/lvmetad.socket" - safe_name_characters = "0-9a-zA-Z._-" if hasattr(blockdev.LVMTech, "DEVICES"): @@ -87,6 +84,18 @@ LVM_DEVICES_FILE = "/etc/lvm/devices/system.devices" +if hasattr(blockdev.LVMTech, "CONFIG"): + try: + event_activation = blockdev.lvm.config_get("global", "event_activation", "full") + except (blockdev.LVMError, blockdev.BlockDevNotImplementedError): + AUTO_ACTIVATION = True + else: + AUTO_ACTIVATION = bool(int(event_activation)) +else: + # it's safer to assume LVM auto activation is enabled than disabled + # worst case scenario is we will needlessly wait for auto activation + AUTO_ACTIVATION = True + # list of devices that LVM is allowed to use # with LVM >= 2.0.13 we'll use this for the --devices option and when creating # the /etc/lvm/devices/system.devices file @@ -233,10 +242,6 @@ def determine_parent_lv(internal_lv, lvs, lv_info): return None -def lvmetad_socket_exists(): - return os.path.exists(LVMETAD_SOCKET_PATH) - - def ensure_lv_is_writable(vg_name, lv_name): lv_info = lvs_info.cache.get("%s-%s" % (vg_name, lv_name)) if lv_info is None: diff --git a/blivet/devices/lvm.py b/blivet/devices/lvm.py index 5f4c84bf4..c30d00dac 100644 --- a/blivet/devices/lvm.py +++ b/blivet/devices/lvm.py @@ -1116,10 +1116,10 @@ def check_size(self): return 0 def _pre_setup(self, orig=False): - # If the lvmetad socket exists and any PV is inactive before we call + # If auto-activation is enabled and any PV is inactive before we call # setup_parents (via _pre_setup, below), we should wait for auto- # activation before trying to manually activate this LV. - auto_activate = (lvm.lvmetad_socket_exists() and + auto_activate = (lvm.AUTO_ACTIVATION and any(not pv.format.status for pv in self.vg.pvs)) if not super(LVMLogicalVolumeBase, self)._pre_setup(orig=orig): return False @@ -1127,9 +1127,7 @@ def _pre_setup(self, orig=False): if auto_activate: log.debug("waiting for lvm auto-activation of %s", self.name) # Wait for auto-activation for up to 30 seconds. If this LV hasn't - # been activated when the timeout is reached, there may be some - # lvm.conf content preventing auto-activation of this LV, so we - # have to do it ourselves. + # been activated when the timeout is reached, we try do it ourselves. # The timeout value of 30 seconds was suggested by prajnoha. He # noted that udev uses the same value, for whatever that's worth. timeout = 30 # seconds diff --git a/tests/unit_tests/devices_test/device_methods_test.py b/tests/unit_tests/devices_test/device_methods_test.py index 093c0066f..1fd1b6e33 100644 --- a/tests/unit_tests/devices_test/device_methods_test.py +++ b/tests/unit_tests/devices_test/device_methods_test.py @@ -345,7 +345,7 @@ def test_setup(self, *args): # pylint: disable=unused-argument,arguments-differ @patch("blivet.devices.lvm.LVMLogicalVolumeBase.type_external_dependencies", return_value=set()) def test_teardown(self, *args): # pylint: disable=unused-argument,arguments-differ - with patch("blivet.devicelibs.lvm.lvmetad_socket_exists", return_value=False): + with patch("blivet.devicelibs.lvm.AUTO_ACTIVATION", return_value=False): super(LVMLogicalVolumeDeviceMethodsTestCase, self).test_teardown() with patch("blivet.devices.lvm.blockdev.lvm") as lvm: