Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lvm: Check lvm.conf for auto-activation support #1339

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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