Skip to content

Commit

Permalink
Merge pull request #1339 from vojtechtrefny/main_lvm-autoactivation-fix
Browse files Browse the repository at this point in the history
lvm: Check lvm.conf for auto-activation support
  • Loading branch information
vojtechtrefny authored Feb 3, 2025
2 parents 239fd36 + ce94732 commit d1357ef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
19 changes: 12 additions & 7 deletions blivet/devicelibs/lvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#

import math
import os
import re

from collections import namedtuple
Expand Down Expand Up @@ -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"):
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 3 additions & 5 deletions blivet/devices/lvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1116,20 +1116,18 @@ 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

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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/devices_test/device_methods_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d1357ef

Please sign in to comment.