Vojtech Trefny 0abc76
From 43c5a6ef094e5f333a6dd47c467a1516488e2097 Mon Sep 17 00:00:00 2001
Vojtech Trefny 0abc76
From: Vojtech Trefny <vtrefny@redhat.com>
Vojtech Trefny 0abc76
Date: Mon, 24 May 2021 13:35:39 +0200
Vojtech Trefny 0abc76
Subject: [PATCH 1/7] Remove action device from LVM reject list
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
Because the device doesn't depend on itself the existing code
Vojtech Trefny 0abc76
won't remove the device we are trying to modify from the list.
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
Resolves: rhbz#1955942
Vojtech Trefny 0abc76
---
Vojtech Trefny 0abc76
 blivet/actionlist.py | 1 +
Vojtech Trefny 0abc76
 1 file changed, 1 insertion(+)
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
diff --git a/blivet/actionlist.py b/blivet/actionlist.py
Vojtech Trefny 0abc76
index d03e32b9..2de3fed3 100644
Vojtech Trefny 0abc76
--- a/blivet/actionlist.py
Vojtech Trefny 0abc76
+++ b/blivet/actionlist.py
Vojtech Trefny 0abc76
@@ -260,6 +260,7 @@ class ActionList(object):
Vojtech Trefny 0abc76
             log.debug("action: %s", action)
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
             # Remove lvm filters for devices we are operating on
Vojtech Trefny 0abc76
+            lvm.lvm_cc_removeFilterRejectRegexp(action.device.name)
Vojtech Trefny 0abc76
             for device in (d for d in devices if d.depends_on(action.device)):
Vojtech Trefny 0abc76
                 lvm.lvm_cc_removeFilterRejectRegexp(device.name)
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
-- 
Vojtech Trefny 0abc76
2.31.1
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
From 2db8aa0aa6ea03c182f7e8e08cd1371ded13b71c Mon Sep 17 00:00:00 2001
Vojtech Trefny 0abc76
From: Vojtech Trefny <vtrefny@redhat.com>
Vojtech Trefny 0abc76
Date: Mon, 24 May 2021 14:49:12 +0200
Vojtech Trefny 0abc76
Subject: [PATCH 2/7] Convert LVM filter lists to sets
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
To prevent devices being added multiple times and removed only
Vojtech Trefny 0abc76
once.
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
Related: rhbz#1955942
Vojtech Trefny 0abc76
---
Vojtech Trefny 0abc76
 blivet/devicelibs/lvm.py | 12 ++++++------
Vojtech Trefny 0abc76
 tests/devicetree_test.py |  6 +++---
Vojtech Trefny 0abc76
 2 files changed, 9 insertions(+), 9 deletions(-)
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
diff --git a/blivet/devicelibs/lvm.py b/blivet/devicelibs/lvm.py
Vojtech Trefny 0abc76
index 121797ce..9e396cca 100644
Vojtech Trefny 0abc76
--- a/blivet/devicelibs/lvm.py
Vojtech Trefny 0abc76
+++ b/blivet/devicelibs/lvm.py
Vojtech Trefny 0abc76
@@ -72,8 +72,8 @@ safe_name_characters = "0-9a-zA-Z._-"
Vojtech Trefny 0abc76
 # Theoretically we can handle all that can be handled with the LVM --config
Vojtech Trefny 0abc76
 # argument.  For every time we call an lvm_cc (lvm compose config) funciton
Vojtech Trefny 0abc76
 # we regenerate the config_args with all global info.
Vojtech Trefny 0abc76
-config_args_data = {"filterRejects": [],    # regular expressions to reject.
Vojtech Trefny 0abc76
-                    "filterAccepts": []}   # regexp to accept
Vojtech Trefny 0abc76
+config_args_data = {"filterRejects": set(),    # regular expressions to reject.
Vojtech Trefny 0abc76
+                    "filterAccepts": set()}    # regexp to accept
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 def _set_global_config():
Vojtech Trefny 0abc76
@@ -125,7 +125,7 @@ def needs_config_refresh(fn):
Vojtech Trefny 0abc76
 def lvm_cc_addFilterRejectRegexp(regexp):
Vojtech Trefny 0abc76
     """ Add a regular expression to the --config string."""
Vojtech Trefny 0abc76
     log.debug("lvm filter: adding %s to the reject list", regexp)
Vojtech Trefny 0abc76
-    config_args_data["filterRejects"].append(regexp)
Vojtech Trefny 0abc76
+    config_args_data["filterRejects"].add(regexp)
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 @needs_config_refresh
Vojtech Trefny 0abc76
@@ -134,15 +134,15 @@ def lvm_cc_removeFilterRejectRegexp(regexp):
Vojtech Trefny 0abc76
     log.debug("lvm filter: removing %s from the reject list", regexp)
Vojtech Trefny 0abc76
     try:
Vojtech Trefny 0abc76
         config_args_data["filterRejects"].remove(regexp)
Vojtech Trefny 0abc76
-    except ValueError:
Vojtech Trefny 0abc76
+    except KeyError:
Vojtech Trefny 0abc76
         log.debug("%s wasn't in the reject list", regexp)
Vojtech Trefny 0abc76
         return
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 @needs_config_refresh
Vojtech Trefny 0abc76
 def lvm_cc_resetFilter():
Vojtech Trefny 0abc76
-    config_args_data["filterRejects"] = []
Vojtech Trefny 0abc76
-    config_args_data["filterAccepts"] = []
Vojtech Trefny 0abc76
+    config_args_data["filterRejects"] = set()
Vojtech Trefny 0abc76
+    config_args_data["filterAccepts"] = set()
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 def determine_parent_lv(internal_lv, lvs, lv_info):
Vojtech Trefny 0abc76
diff --git a/tests/devicetree_test.py b/tests/devicetree_test.py
Vojtech Trefny 0abc76
index d1f4d8f3..ef163c0a 100644
Vojtech Trefny 0abc76
--- a/tests/devicetree_test.py
Vojtech Trefny 0abc76
+++ b/tests/devicetree_test.py
Vojtech Trefny 0abc76
@@ -125,7 +125,7 @@ class DeviceTreeTestCase(unittest.TestCase):
Vojtech Trefny 0abc76
         dt.actions._actions.append(Mock(name="fake action"))
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
         lvm.lvm_cc_addFilterRejectRegexp("xxx")
Vojtech Trefny 0abc76
-        lvm.config_args_data["filterAccepts"].append("yyy")
Vojtech Trefny 0abc76
+        lvm.config_args_data["filterAccepts"].add("yyy")
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
         dt.ignored_disks.append(names[0])
Vojtech Trefny 0abc76
         dt.exclusive_disks.append(names[1])
Vojtech Trefny 0abc76
@@ -144,8 +144,8 @@ class DeviceTreeTestCase(unittest.TestCase):
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
         self.assertEqual(dt._hidden, empty_list)
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
-        self.assertEqual(lvm.config_args_data["filterAccepts"], empty_list)
Vojtech Trefny 0abc76
-        self.assertEqual(lvm.config_args_data["filterRejects"], empty_list)
Vojtech Trefny 0abc76
+        self.assertEqual(lvm.config_args_data["filterAccepts"], set())
Vojtech Trefny 0abc76
+        self.assertEqual(lvm.config_args_data["filterRejects"], set())
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
         self.assertEqual(dt.exclusive_disks, empty_list)
Vojtech Trefny 0abc76
         self.assertEqual(dt.ignored_disks, empty_list)
Vojtech Trefny 0abc76
-- 
Vojtech Trefny 0abc76
2.31.1
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
From e2540422945586ca45848a663e391a91b2fdd714 Mon Sep 17 00:00:00 2001
Vojtech Trefny 0abc76
From: Vojtech Trefny <vtrefny@redhat.com>
Vojtech Trefny 0abc76
Date: Tue, 27 Jul 2021 14:07:05 +0200
Vojtech Trefny 0abc76
Subject: [PATCH 3/7] Switch LVM devices filter from "reject" to "accept" by
Vojtech Trefny 0abc76
 default
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
We currently use the LVM reject filter to filter out hidden and
Vojtech Trefny 0abc76
ignored devices, this commit changes the behaviour to reject all
Vojtech Trefny 0abc76
devices by default and accept only physical volumes that are not
Vojtech Trefny 0abc76
hidden or ignored. This is preparation for the switch from the
Vojtech Trefny 0abc76
existing lvm.conf based filtering to the new devices file based
Vojtech Trefny 0abc76
filtering introduced in LVM 2.03.12 which allows only listing
Vojtech Trefny 0abc76
"accepted" devices. This allows us to support both the "old" and
Vojtech Trefny 0abc76
"new" style filtering using the same code.
Vojtech Trefny 0abc76
---
Vojtech Trefny 0abc76
 blivet/actionlist.py                  |  5 +--
Vojtech Trefny 0abc76
 blivet/devicelibs/lvm.py              | 62 +++++++++++----------------
Vojtech Trefny 0abc76
 blivet/devices/lvm.py                 |  4 +-
Vojtech Trefny 0abc76
 blivet/devicetree.py                  |  8 ++--
Vojtech Trefny 0abc76
 blivet/formats/lvmpv.py               |  2 +
Vojtech Trefny 0abc76
 blivet/populator/helpers/lvm.py       |  6 +++
Vojtech Trefny 0abc76
 blivet/populator/helpers/partition.py |  8 ----
Vojtech Trefny 0abc76
 blivet/populator/populator.py         |  4 +-
Vojtech Trefny 0abc76
 tests/devicetree_test.py              | 37 ++++++++++++++--
Vojtech Trefny 0abc76
 tests/populator_test.py               |  6 ++-
Vojtech Trefny 0abc76
 10 files changed, 81 insertions(+), 61 deletions(-)
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
diff --git a/blivet/actionlist.py b/blivet/actionlist.py
Vojtech Trefny 0abc76
index 2de3fed3..f3977401 100644
Vojtech Trefny 0abc76
--- a/blivet/actionlist.py
Vojtech Trefny 0abc76
+++ b/blivet/actionlist.py
Vojtech Trefny 0abc76
@@ -259,10 +259,9 @@ class ActionList(object):
Vojtech Trefny 0abc76
         for action in self._actions:
Vojtech Trefny 0abc76
             log.debug("action: %s", action)
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
-            # Remove lvm filters for devices we are operating on
Vojtech Trefny 0abc76
-            lvm.lvm_cc_removeFilterRejectRegexp(action.device.name)
Vojtech Trefny 0abc76
             for device in (d for d in devices if d.depends_on(action.device)):
Vojtech Trefny 0abc76
-                lvm.lvm_cc_removeFilterRejectRegexp(device.name)
Vojtech Trefny 0abc76
+                if device.format.type == "lvmpv":
Vojtech Trefny 0abc76
+                    lvm.lvm_devices_add(device.path)
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
     def _post_process(self, devices=None):
Vojtech Trefny 0abc76
         """ Clean up relics from action queue execution. """
Vojtech Trefny 0abc76
diff --git a/blivet/devicelibs/lvm.py b/blivet/devicelibs/lvm.py
Vojtech Trefny 0abc76
index 9e396cca..96d037b8 100644
Vojtech Trefny 0abc76
--- a/blivet/devicelibs/lvm.py
Vojtech Trefny 0abc76
+++ b/blivet/devicelibs/lvm.py
Vojtech Trefny 0abc76
@@ -67,40 +67,29 @@ LVMETAD_SOCKET_PATH = "/run/lvm/lvmetad.socket"
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 safe_name_characters = "0-9a-zA-Z._-"
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
-# Start config_args handling code
Vojtech Trefny 0abc76
-#
Vojtech Trefny 0abc76
-# Theoretically we can handle all that can be handled with the LVM --config
Vojtech Trefny 0abc76
-# argument.  For every time we call an lvm_cc (lvm compose config) funciton
Vojtech Trefny 0abc76
-# we regenerate the config_args with all global info.
Vojtech Trefny 0abc76
-config_args_data = {"filterRejects": set(),    # regular expressions to reject.
Vojtech Trefny 0abc76
-                    "filterAccepts": set()}    # regexp to accept
Vojtech Trefny 0abc76
+# list of devices that LVM is allowed to use
Vojtech Trefny 0abc76
+# with LVM >= 2.0.13 we'll use this for the --devices option and when creating
Vojtech Trefny 0abc76
+# the /etc/lvm/devices/system.devices file
Vojtech Trefny 0abc76
+# with older versions of LVM we will use this for the --config based filtering
Vojtech Trefny 0abc76
+_lvm_devices = set()
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 def _set_global_config():
Vojtech Trefny 0abc76
     """lvm command accepts lvm.conf type arguments preceded by --config. """
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
-    filter_string = ""
Vojtech Trefny 0abc76
-    rejects = config_args_data["filterRejects"]
Vojtech Trefny 0abc76
-    for reject in rejects:
Vojtech Trefny 0abc76
-        filter_string += ("\"r|/%s$|\"," % reject)
Vojtech Trefny 0abc76
+    device_string = ""
Vojtech Trefny 0abc76
+
Vojtech Trefny 0abc76
+    # now explicitly "accept" all LVM devices
Vojtech Trefny 0abc76
+    for device in _lvm_devices:
Vojtech Trefny 0abc76
+        device_string += "\"a|%s$|\"," % device
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
-    if filter_string:
Vojtech Trefny 0abc76
-        filter_string = "filter=[%s]" % filter_string.strip(",")
Vojtech Trefny 0abc76
+    # now add all devices to the "reject" filter
Vojtech Trefny 0abc76
+    device_string += "\"r|.*|\""
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
-    # XXX consider making /tmp/blivet.lvm.XXXXX, writing an lvm.conf there, and
Vojtech Trefny 0abc76
-    #     setting LVM_SYSTEM_DIR
Vojtech Trefny 0abc76
-    devices_string = 'preferred_names=["^/dev/mapper/", "^/dev/md/", "^/dev/sd"]'
Vojtech Trefny 0abc76
-    if filter_string:
Vojtech Trefny 0abc76
-        devices_string += " %s" % filter_string
Vojtech Trefny 0abc76
+    filter_string = "filter=[%s]" % device_string
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
-    # for now ignore the LVM devices file and rely on our filters
Vojtech Trefny 0abc76
-    if availability.LVMDEVICES.available:
Vojtech Trefny 0abc76
-        devices_string += " use_devicesfile=0"
Vojtech Trefny 0abc76
+    config_string = " devices { %s } " % filter_string
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
-    # devices_string can have (inside the brackets) "dir", "scan",
Vojtech Trefny 0abc76
-    # "preferred_names", "filter", "cache_dir", "write_cache_state",
Vojtech Trefny 0abc76
-    # "types", "sysfs_scan", "md_component_detection".  see man lvm.conf.
Vojtech Trefny 0abc76
-    config_string = " devices { %s } " % (devices_string)  # strings can be added
Vojtech Trefny 0abc76
     if not flags.lvm_metadata_backup:
Vojtech Trefny 0abc76
         config_string += "backup {backup=0 archive=0} "
Vojtech Trefny 0abc76
     if flags.debug:
Vojtech Trefny 0abc76
@@ -122,27 +111,26 @@ def needs_config_refresh(fn):
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 @needs_config_refresh
Vojtech Trefny 0abc76
-def lvm_cc_addFilterRejectRegexp(regexp):
Vojtech Trefny 0abc76
-    """ Add a regular expression to the --config string."""
Vojtech Trefny 0abc76
-    log.debug("lvm filter: adding %s to the reject list", regexp)
Vojtech Trefny 0abc76
-    config_args_data["filterRejects"].add(regexp)
Vojtech Trefny 0abc76
+def lvm_devices_add(path):
Vojtech Trefny 0abc76
+    """ Add a device (PV) to the list of devices LVM is allowed to use """
Vojtech Trefny 0abc76
+    log.debug("lvm filter: device %s added to the list of allowed devices")
Vojtech Trefny 0abc76
+    _lvm_devices.add(path)
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 @needs_config_refresh
Vojtech Trefny 0abc76
-def lvm_cc_removeFilterRejectRegexp(regexp):
Vojtech Trefny 0abc76
-    """ Remove a regular expression from the --config string."""
Vojtech Trefny 0abc76
-    log.debug("lvm filter: removing %s from the reject list", regexp)
Vojtech Trefny 0abc76
+def lvm_devices_remove(path):
Vojtech Trefny 0abc76
+    """ Remove a device (PV) to the list of devices LVM is allowed to use """
Vojtech Trefny 0abc76
+    log.debug("lvm filter: device %s removed from the list of allowed devices")
Vojtech Trefny 0abc76
     try:
Vojtech Trefny 0abc76
-        config_args_data["filterRejects"].remove(regexp)
Vojtech Trefny 0abc76
+        _lvm_devices.remove(path)
Vojtech Trefny 0abc76
     except KeyError:
Vojtech Trefny 0abc76
-        log.debug("%s wasn't in the reject list", regexp)
Vojtech Trefny 0abc76
+        log.debug("%s wasn't in the devices list", path)
Vojtech Trefny 0abc76
         return
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 @needs_config_refresh
Vojtech Trefny 0abc76
-def lvm_cc_resetFilter():
Vojtech Trefny 0abc76
-    config_args_data["filterRejects"] = set()
Vojtech Trefny 0abc76
-    config_args_data["filterAccepts"] = set()
Vojtech Trefny 0abc76
+def lvm_devices_reset():
Vojtech Trefny 0abc76
+    _lvm_devices.clear()
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 def determine_parent_lv(internal_lv, lvs, lv_info):
Vojtech Trefny 0abc76
diff --git a/blivet/devices/lvm.py b/blivet/devices/lvm.py
Vojtech Trefny 0abc76
index c61eeb4b..9c230f1b 100644
Vojtech Trefny 0abc76
--- a/blivet/devices/lvm.py
Vojtech Trefny 0abc76
+++ b/blivet/devices/lvm.py
Vojtech Trefny 0abc76
@@ -273,8 +273,8 @@ class LVMVolumeGroupDevice(ContainerDevice):
Vojtech Trefny 0abc76
         log_method_call(self, self.name, status=self.status)
Vojtech Trefny 0abc76
         if not self.complete:
Vojtech Trefny 0abc76
             for pv in self.pvs:
Vojtech Trefny 0abc76
-                # Remove the PVs from the ignore filter so we can wipe them.
Vojtech Trefny 0abc76
-                lvm.lvm_cc_removeFilterRejectRegexp(pv.name)
Vojtech Trefny 0abc76
+                # add PVS to the list of LVM devices so we can wipe them.
Vojtech Trefny 0abc76
+                lvm.lvm_devices_add(pv.path)
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
             # Don't run vgremove or vgreduce since there may be another VG with
Vojtech Trefny 0abc76
             # the same name that we want to keep/use.
Vojtech Trefny 0abc76
diff --git a/blivet/devicetree.py b/blivet/devicetree.py
Vojtech Trefny 0abc76
index f4ae1968..c6c1b440 100644
Vojtech Trefny 0abc76
--- a/blivet/devicetree.py
Vojtech Trefny 0abc76
+++ b/blivet/devicetree.py
Vojtech Trefny 0abc76
@@ -96,7 +96,7 @@ class DeviceTreeBase(object):
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
         self._hidden = []
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
-        lvm.lvm_cc_resetFilter()
Vojtech Trefny 0abc76
+        lvm.lvm_devices_reset()
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
         self.exclusive_disks = exclusive_disks or []
Vojtech Trefny 0abc76
         self.ignored_disks = ignored_disks or []
Vojtech Trefny 0abc76
@@ -879,7 +879,8 @@ class DeviceTreeBase(object):
Vojtech Trefny 0abc76
         self._remove_device(device, force=True, modparent=False)
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
         self._hidden.append(device)
Vojtech Trefny 0abc76
-        lvm.lvm_cc_addFilterRejectRegexp(device.name)
Vojtech Trefny 0abc76
+        if device.format.type == "lvmpv":
Vojtech Trefny 0abc76
+            lvm.lvm_devices_remove(device.path)
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
     def unhide(self, device):
Vojtech Trefny 0abc76
         """ Restore a device's visibility.
Vojtech Trefny 0abc76
@@ -905,7 +906,8 @@ class DeviceTreeBase(object):
Vojtech Trefny 0abc76
                 self._hidden.remove(hidden)
Vojtech Trefny 0abc76
                 self._devices.append(hidden)
Vojtech Trefny 0abc76
                 hidden.add_hook(new=False)
Vojtech Trefny 0abc76
-                lvm.lvm_cc_removeFilterRejectRegexp(hidden.name)
Vojtech Trefny 0abc76
+                if hidden.format.type == "lvmpv":
Vojtech Trefny 0abc76
+                    lvm.lvm_devices_add(hidden.path)
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
     def expand_taglist(self, taglist):
Vojtech Trefny 0abc76
         """ Expands tags in input list into devices.
Vojtech Trefny 0abc76
diff --git a/blivet/formats/lvmpv.py b/blivet/formats/lvmpv.py
Vojtech Trefny 0abc76
index ea84e9e4..3b00951f 100644
Vojtech Trefny 0abc76
--- a/blivet/formats/lvmpv.py
Vojtech Trefny 0abc76
+++ b/blivet/formats/lvmpv.py
Vojtech Trefny 0abc76
@@ -124,6 +124,7 @@ class LVMPhysicalVolume(DeviceFormat):
Vojtech Trefny 0abc76
     def _create(self, **kwargs):
Vojtech Trefny 0abc76
         log_method_call(self, device=self.device,
Vojtech Trefny 0abc76
                         type=self.type, status=self.status)
Vojtech Trefny 0abc76
+        lvm.lvm_devices_add(self.device)
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
         lvm._set_global_config()
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
@@ -138,6 +139,7 @@ class LVMPhysicalVolume(DeviceFormat):
Vojtech Trefny 0abc76
         except blockdev.LVMError:
Vojtech Trefny 0abc76
             DeviceFormat._destroy(self, **kwargs)
Vojtech Trefny 0abc76
         finally:
Vojtech Trefny 0abc76
+            lvm.lvm_devices_remove(self.device)
Vojtech Trefny 0abc76
             udev.settle()
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
     @property
Vojtech Trefny 0abc76
diff --git a/blivet/populator/helpers/lvm.py b/blivet/populator/helpers/lvm.py
Vojtech Trefny 0abc76
index c7adfa4e..9e7e4630 100644
Vojtech Trefny 0abc76
--- a/blivet/populator/helpers/lvm.py
Vojtech Trefny 0abc76
+++ b/blivet/populator/helpers/lvm.py
Vojtech Trefny 0abc76
@@ -87,6 +87,12 @@ class LVMFormatPopulator(FormatPopulator):
Vojtech Trefny 0abc76
     def _get_kwargs(self):
Vojtech Trefny 0abc76
         kwargs = super(LVMFormatPopulator, self)._get_kwargs()
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
+        # new PV, add it to the LVM devices list and re-run pvs/lvs/vgs
Vojtech Trefny 0abc76
+        lvm.lvm_devices_add(self.device.path)
Vojtech Trefny 0abc76
+        pvs_info.drop_cache()
Vojtech Trefny 0abc76
+        vgs_info.drop_cache()
Vojtech Trefny 0abc76
+        lvs_info.drop_cache()
Vojtech Trefny 0abc76
+
Vojtech Trefny 0abc76
         pv_info = pvs_info.cache.get(self.device.path, None)
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
         name = udev.device_get_name(self.data)
Vojtech Trefny 0abc76
diff --git a/blivet/populator/helpers/partition.py b/blivet/populator/helpers/partition.py
Vojtech Trefny 0abc76
index f00323d1..8659bd48 100644
Vojtech Trefny 0abc76
--- a/blivet/populator/helpers/partition.py
Vojtech Trefny 0abc76
+++ b/blivet/populator/helpers/partition.py
Vojtech Trefny 0abc76
@@ -24,7 +24,6 @@ import copy
Vojtech Trefny 0abc76
 import six
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 from ... import udev
Vojtech Trefny 0abc76
-from ...devicelibs import lvm
Vojtech Trefny 0abc76
 from ...devices import PartitionDevice
Vojtech Trefny 0abc76
 from ...errors import DeviceError
Vojtech Trefny 0abc76
 from ...formats import get_format
Vojtech Trefny 0abc76
@@ -66,7 +65,6 @@ class PartitionDevicePopulator(DevicePopulator):
Vojtech Trefny 0abc76
         if disk is None:
Vojtech Trefny 0abc76
             # if the disk is still not in the tree something has gone wrong
Vojtech Trefny 0abc76
             log.error("failure finding disk for %s", name)
Vojtech Trefny 0abc76
-            lvm.lvm_cc_addFilterRejectRegexp(name)
Vojtech Trefny 0abc76
             return
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
         if not disk.partitioned or not disk.format.supported:
Vojtech Trefny 0abc76
@@ -78,12 +76,6 @@ class PartitionDevicePopulator(DevicePopulator):
Vojtech Trefny 0abc76
             # and instantiate a PartitionDevice so our view of the layout is
Vojtech Trefny 0abc76
             # complete.
Vojtech Trefny 0abc76
             if not disk.partitionable or disk.format.type == "iso9660" or disk.format.hidden:
Vojtech Trefny 0abc76
-                # there's no need to filter partitions on members of multipaths or
Vojtech Trefny 0abc76
-                # fwraid members from lvm since multipath and dmraid are already
Vojtech Trefny 0abc76
-                # active and lvm should therefore know to ignore them
Vojtech Trefny 0abc76
-                if not disk.format.hidden:
Vojtech Trefny 0abc76
-                    lvm.lvm_cc_addFilterRejectRegexp(name)
Vojtech Trefny 0abc76
-
Vojtech Trefny 0abc76
                 log.debug("ignoring partition %s on %s", name, disk.format.type)
Vojtech Trefny 0abc76
                 return
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
diff --git a/blivet/populator/populator.py b/blivet/populator/populator.py
Vojtech Trefny 0abc76
index 75bb1741..958593ec 100644
Vojtech Trefny 0abc76
--- a/blivet/populator/populator.py
Vojtech Trefny 0abc76
+++ b/blivet/populator/populator.py
Vojtech Trefny 0abc76
@@ -317,10 +317,10 @@ class PopulatorMixin(object):
Vojtech Trefny 0abc76
                 continue
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
             # Make sure lvm doesn't get confused by PVs that belong to
Vojtech Trefny 0abc76
-            # incomplete VGs. We will remove the PVs from the reject list when/if
Vojtech Trefny 0abc76
+            # incomplete VGs. We will add the PVs to the accept list when/if
Vojtech Trefny 0abc76
             # the time comes to remove the incomplete VG and its PVs.
Vojtech Trefny 0abc76
             for pv in vg.pvs:
Vojtech Trefny 0abc76
-                lvm.lvm_cc_addFilterRejectRegexp(pv.name)
Vojtech Trefny 0abc76
+                lvm.lvm_devices_remove(pv.path)
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
     def set_disk_images(self, images):
Vojtech Trefny 0abc76
         """ Set the disk images and reflect them in exclusive_disks.
Vojtech Trefny 0abc76
diff --git a/tests/devicetree_test.py b/tests/devicetree_test.py
Vojtech Trefny 0abc76
index ef163c0a..3be4d572 100644
Vojtech Trefny 0abc76
--- a/tests/devicetree_test.py
Vojtech Trefny 0abc76
+++ b/tests/devicetree_test.py
Vojtech Trefny 0abc76
@@ -124,8 +124,7 @@ class DeviceTreeTestCase(unittest.TestCase):
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
         dt.actions._actions.append(Mock(name="fake action"))
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
-        lvm.lvm_cc_addFilterRejectRegexp("xxx")
Vojtech Trefny 0abc76
-        lvm.config_args_data["filterAccepts"].add("yyy")
Vojtech Trefny 0abc76
+        lvm.lvm_devices_add("xxx")
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
         dt.ignored_disks.append(names[0])
Vojtech Trefny 0abc76
         dt.exclusive_disks.append(names[1])
Vojtech Trefny 0abc76
@@ -144,8 +143,7 @@ class DeviceTreeTestCase(unittest.TestCase):
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
         self.assertEqual(dt._hidden, empty_list)
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
-        self.assertEqual(lvm.config_args_data["filterAccepts"], set())
Vojtech Trefny 0abc76
-        self.assertEqual(lvm.config_args_data["filterRejects"], set())
Vojtech Trefny 0abc76
+        self.assertEqual(lvm._lvm_devices, set())
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
         self.assertEqual(dt.exclusive_disks, empty_list)
Vojtech Trefny 0abc76
         self.assertEqual(dt.ignored_disks, empty_list)
Vojtech Trefny 0abc76
@@ -438,6 +436,37 @@ class DeviceTreeTestCase(unittest.TestCase):
Vojtech Trefny 0abc76
         self.assertEqual(tree.get_related_disks(sda), set([sda, sdb]))
Vojtech Trefny 0abc76
         self.assertEqual(tree.get_related_disks(sdb), set([sda, sdb]))
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
+    def test_lvm_filter_hide_unhide(self):
Vojtech Trefny 0abc76
+        tree = DeviceTree()
Vojtech Trefny 0abc76
+
Vojtech Trefny 0abc76
+        sda = DiskDevice("sda", size=Size("30 GiB"))
Vojtech Trefny 0abc76
+        sdb = DiskDevice("sdb", size=Size("30 GiB"))
Vojtech Trefny 0abc76
+
Vojtech Trefny 0abc76
+        tree._add_device(sda)
Vojtech Trefny 0abc76
+        tree._add_device(sdb)
Vojtech Trefny 0abc76
+
Vojtech Trefny 0abc76
+        self.assertTrue(sda in tree.devices)
Vojtech Trefny 0abc76
+        self.assertTrue(sdb in tree.devices)
Vojtech Trefny 0abc76
+
Vojtech Trefny 0abc76
+        sda.format = get_format("lvmpv", device=sda.path)
Vojtech Trefny 0abc76
+        sdb.format = get_format("lvmpv", device=sdb.path)
Vojtech Trefny 0abc76
+
Vojtech Trefny 0abc76
+        # LVMPhysicalVolume._create would do this
Vojtech Trefny 0abc76
+        lvm.lvm_devices_add(sda.path)
Vojtech Trefny 0abc76
+        lvm.lvm_devices_add(sdb.path)
Vojtech Trefny 0abc76
+
Vojtech Trefny 0abc76
+        self.assertSetEqual(lvm._lvm_devices, {sda.path, sdb.path})
Vojtech Trefny 0abc76
+
Vojtech Trefny 0abc76
+        tree.hide(sda)
Vojtech Trefny 0abc76
+        self.assertSetEqual(lvm._lvm_devices, {sdb.path})
Vojtech Trefny 0abc76
+        tree.hide(sdb)
Vojtech Trefny 0abc76
+        self.assertSetEqual(lvm._lvm_devices, set())
Vojtech Trefny 0abc76
+
Vojtech Trefny 0abc76
+        tree.unhide(sda)
Vojtech Trefny 0abc76
+        self.assertSetEqual(lvm._lvm_devices, {sda.path})
Vojtech Trefny 0abc76
+        tree.unhide(sdb)
Vojtech Trefny 0abc76
+        self.assertSetEqual(lvm._lvm_devices, {sda.path, sdb.path})
Vojtech Trefny 0abc76
+
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 class DeviceTreeIgnoredExclusiveMultipathTestCase(unittest.TestCase):
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
diff --git a/tests/populator_test.py b/tests/populator_test.py
Vojtech Trefny 0abc76
index 2a8532f0..dd36c16a 100644
Vojtech Trefny 0abc76
--- a/tests/populator_test.py
Vojtech Trefny 0abc76
+++ b/tests/populator_test.py
Vojtech Trefny 0abc76
@@ -13,6 +13,7 @@ from gi.repository import BlockDev as blockdev
Vojtech Trefny 0abc76
 from blivet.devices import DiskDevice, DMDevice, FileDevice, LoopDevice
Vojtech Trefny 0abc76
 from blivet.devices import MDRaidArrayDevice, MultipathDevice, OpticalDevice
Vojtech Trefny 0abc76
 from blivet.devices import PartitionDevice, StorageDevice, NVDIMMNamespaceDevice
Vojtech Trefny 0abc76
+from blivet.devicelibs import lvm
Vojtech Trefny 0abc76
 from blivet.devicetree import DeviceTree
Vojtech Trefny 0abc76
 from blivet.formats import get_device_format_class, get_format, DeviceFormat
Vojtech Trefny 0abc76
 from blivet.formats.disklabel import DiskLabel
Vojtech Trefny 0abc76
@@ -393,8 +394,7 @@ class PartitionDevicePopulatorTestCase(PopulatorHelperTestCase):
Vojtech Trefny 0abc76
     @patch.object(DiskLabel, "parted_disk")
Vojtech Trefny 0abc76
     @patch.object(DiskLabel, "parted_device")
Vojtech Trefny 0abc76
     @patch.object(PartitionDevice, "probe")
Vojtech Trefny 0abc76
-    # TODO: fix the naming of the lvm filter functions
Vojtech Trefny 0abc76
-    @patch("blivet.devicelibs.lvm.lvm_cc_addFilterRejectRegexp")
Vojtech Trefny 0abc76
+    @patch("blivet.devicelibs.lvm.lvm_devices_add")
Vojtech Trefny 0abc76
     @patch("blivet.udev.device_get_major", return_value=88)
Vojtech Trefny 0abc76
     @patch("blivet.udev.device_get_minor", return_value=19)
Vojtech Trefny 0abc76
     @patch.object(DeviceTree, "get_device_by_name")
Vojtech Trefny 0abc76
@@ -973,6 +973,8 @@ class LVMFormatPopulatorTestCase(FormatPopulatorTestCase):
Vojtech Trefny 0abc76
                     self.assertTrue(vg_device is not None)
Vojtech Trefny 0abc76
                     devicetree._remove_device(vg_device)
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
+                    self.assertIn(device.path, lvm._lvm_devices)
Vojtech Trefny 0abc76
+
Vojtech Trefny 0abc76
         get_device_by_uuid.reset_mock()
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
         # pv belongs to a valid vg not in the tree with two lvs
Vojtech Trefny 0abc76
-- 
Vojtech Trefny 0abc76
2.31.1
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
From 15a63b01bd2b6e7fe197fade849f28b83407c166 Mon Sep 17 00:00:00 2001
Vojtech Trefny 0abc76
From: Vojtech Trefny <vtrefny@redhat.com>
Vojtech Trefny 0abc76
Date: Fri, 30 Jul 2021 14:01:04 +0200
Vojtech Trefny 0abc76
Subject: [PATCH 4/7] Use LVM devices for filtering LVM devices with LVM >=
Vojtech Trefny 0abc76
 2.02.13
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
---
Vojtech Trefny 0abc76
 blivet/devicelibs/lvm.py | 38 +++++++++++++++++++++++++++++---------
Vojtech Trefny 0abc76
 tests/populator_test.py  |  9 ++++-----
Vojtech Trefny 0abc76
 2 files changed, 33 insertions(+), 14 deletions(-)
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
diff --git a/blivet/devicelibs/lvm.py b/blivet/devicelibs/lvm.py
Vojtech Trefny 0abc76
index 96d037b8..3ab1540b 100644
Vojtech Trefny 0abc76
--- a/blivet/devicelibs/lvm.py
Vojtech Trefny 0abc76
+++ b/blivet/devicelibs/lvm.py
Vojtech Trefny 0abc76
@@ -67,6 +67,16 @@ LVMETAD_SOCKET_PATH = "/run/lvm/lvmetad.socket"
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 safe_name_characters = "0-9a-zA-Z._-"
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
+if hasattr(blockdev.LVMTech, "DEVICES"):
Vojtech Trefny 0abc76
+    try:
Vojtech Trefny 0abc76
+        blockdev.lvm.is_tech_avail(blockdev.LVMTech.DEVICES, 0)  # pylint: disable=no-member
Vojtech Trefny 0abc76
+    except blockdev.LVMError:
Vojtech Trefny 0abc76
+        HAVE_LVMDEVICES = False
Vojtech Trefny 0abc76
+    else:
Vojtech Trefny 0abc76
+        HAVE_LVMDEVICES = True
Vojtech Trefny 0abc76
+else:
Vojtech Trefny 0abc76
+    HAVE_LVMDEVICES = False
Vojtech Trefny 0abc76
+
Vojtech Trefny 0abc76
 # list of devices that LVM is allowed to use
Vojtech Trefny 0abc76
 # with LVM >= 2.0.13 we'll use this for the --devices option and when creating
Vojtech Trefny 0abc76
 # the /etc/lvm/devices/system.devices file
Vojtech Trefny 0abc76
@@ -79,25 +89,34 @@ def _set_global_config():
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
     device_string = ""
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
-    # now explicitly "accept" all LVM devices
Vojtech Trefny 0abc76
-    for device in _lvm_devices:
Vojtech Trefny 0abc76
-        device_string += "\"a|%s$|\"," % device
Vojtech Trefny 0abc76
+    if not HAVE_LVMDEVICES:
Vojtech Trefny 0abc76
+        # now explicitly "accept" all LVM devices
Vojtech Trefny 0abc76
+        for device in _lvm_devices:
Vojtech Trefny 0abc76
+            device_string += "\"a|%s$|\"," % device
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
-    # now add all devices to the "reject" filter
Vojtech Trefny 0abc76
-    device_string += "\"r|.*|\""
Vojtech Trefny 0abc76
+        # now add all devices to the "reject" filter
Vojtech Trefny 0abc76
+        device_string += "\"r|.*|\""
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
-    filter_string = "filter=[%s]" % device_string
Vojtech Trefny 0abc76
+        filter_string = "filter=[%s]" % device_string
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
-    config_string = " devices { %s } " % filter_string
Vojtech Trefny 0abc76
+        config_string = " devices { %s } " % filter_string
Vojtech Trefny 0abc76
+    else:
Vojtech Trefny 0abc76
+        config_string = " "
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
     if not flags.lvm_metadata_backup:
Vojtech Trefny 0abc76
         config_string += "backup {backup=0 archive=0} "
Vojtech Trefny 0abc76
-    if flags.debug:
Vojtech Trefny 0abc76
-        config_string += "log {level=7 file=/tmp/lvm.log syslog=0}"
Vojtech Trefny 0abc76
+    config_string += "log {level=7 file=/tmp/lvm.log syslog=0}"
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
     blockdev.lvm.set_global_config(config_string)
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
+def _set_lvm_devices():
Vojtech Trefny 0abc76
+    if not HAVE_LVMDEVICES:
Vojtech Trefny 0abc76
+        return
Vojtech Trefny 0abc76
+
Vojtech Trefny 0abc76
+    blockdev.lvm.set_devices_filter(list(_lvm_devices))
Vojtech Trefny 0abc76
+
Vojtech Trefny 0abc76
+
Vojtech Trefny 0abc76
 def needs_config_refresh(fn):
Vojtech Trefny 0abc76
     if not availability.BLOCKDEV_LVM_PLUGIN.available:
Vojtech Trefny 0abc76
         return lambda *args, **kwargs: None
Vojtech Trefny 0abc76
@@ -105,6 +124,7 @@ def needs_config_refresh(fn):
Vojtech Trefny 0abc76
     def fn_with_refresh(*args, **kwargs):
Vojtech Trefny 0abc76
         ret = fn(*args, **kwargs)
Vojtech Trefny 0abc76
         _set_global_config()
Vojtech Trefny 0abc76
+        _set_lvm_devices()
Vojtech Trefny 0abc76
         return ret
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
     return fn_with_refresh
Vojtech Trefny 0abc76
diff --git a/tests/populator_test.py b/tests/populator_test.py
Vojtech Trefny 0abc76
index dd36c16a..a9584319 100644
Vojtech Trefny 0abc76
--- a/tests/populator_test.py
Vojtech Trefny 0abc76
+++ b/tests/populator_test.py
Vojtech Trefny 0abc76
@@ -897,6 +897,7 @@ class LVMFormatPopulatorTestCase(FormatPopulatorTestCase):
Vojtech Trefny 0abc76
         device = Mock()
Vojtech Trefny 0abc76
         device.parents = []
Vojtech Trefny 0abc76
         device.size = Size("10g")
Vojtech Trefny 0abc76
+        device.path = "/dev/sda1"
Vojtech Trefny 0abc76
         devicetree._add_device(device)
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
         # pylint: disable=attribute-defined-outside-init
Vojtech Trefny 0abc76
@@ -924,15 +925,13 @@ class LVMFormatPopulatorTestCase(FormatPopulatorTestCase):
Vojtech Trefny 0abc76
         pv_info.pe_start = 0
Vojtech Trefny 0abc76
         pv_info.pv_free = 0
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
-        device.path = sentinel.pv_path
Vojtech Trefny 0abc76
-
Vojtech Trefny 0abc76
         vg_device = Mock()
Vojtech Trefny 0abc76
         vg_device.parents = []
Vojtech Trefny 0abc76
         vg_device.lvs = []
Vojtech Trefny 0abc76
         get_device_by_uuid.return_value = vg_device
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
         with patch("blivet.static_data.lvm_info.PVsInfo.cache", new_callable=PropertyMock) as mock_pvs_cache:
Vojtech Trefny 0abc76
-            mock_pvs_cache.return_value = {sentinel.pv_path: pv_info}
Vojtech Trefny 0abc76
+            mock_pvs_cache.return_value = {device.path: pv_info}
Vojtech Trefny 0abc76
             with patch("blivet.udev.device_get_format", return_value=self.udev_type):
Vojtech Trefny 0abc76
                 helper = self.helper_class(devicetree, data, device)
Vojtech Trefny 0abc76
                 self.assertFalse(device in vg_device.parents)
Vojtech Trefny 0abc76
@@ -957,7 +956,7 @@ class LVMFormatPopulatorTestCase(FormatPopulatorTestCase):
Vojtech Trefny 0abc76
         pv_info.vg_pv_count = 1
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
         with patch("blivet.static_data.lvm_info.PVsInfo.cache", new_callable=PropertyMock) as mock_pvs_cache:
Vojtech Trefny 0abc76
-            mock_pvs_cache.return_value = {sentinel.pv_path: pv_info}
Vojtech Trefny 0abc76
+            mock_pvs_cache.return_value = {device.path: pv_info}
Vojtech Trefny 0abc76
             with patch("blivet.static_data.lvm_info.VGsInfo.cache", new_callable=PropertyMock) as mock_vgs_cache:
Vojtech Trefny 0abc76
                 mock_vgs_cache.return_value = {pv_info.vg_uuid: Mock()}
Vojtech Trefny 0abc76
                 with patch("blivet.udev.device_get_format", return_value=self.udev_type):
Vojtech Trefny 0abc76
@@ -1007,7 +1006,7 @@ class LVMFormatPopulatorTestCase(FormatPopulatorTestCase):
Vojtech Trefny 0abc76
         get_device_by_uuid.side_effect = gdbu
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
         with patch("blivet.static_data.lvm_info.PVsInfo.cache", new_callable=PropertyMock) as mock_pvs_cache:
Vojtech Trefny 0abc76
-            mock_pvs_cache.return_value = {sentinel.pv_path: pv_info}
Vojtech Trefny 0abc76
+            mock_pvs_cache.return_value = {device.path: pv_info}
Vojtech Trefny 0abc76
             with patch("blivet.static_data.lvm_info.VGsInfo.cache", new_callable=PropertyMock) as mock_vgs_cache:
Vojtech Trefny 0abc76
                 mock_vgs_cache.return_value = {pv_info.vg_uuid: Mock()}
Vojtech Trefny 0abc76
                 with patch("blivet.static_data.lvm_info.LVsInfo.cache", new_callable=PropertyMock) as mock_lvs_cache:
Vojtech Trefny 0abc76
-- 
Vojtech Trefny 0abc76
2.31.1
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
From d4e1395de3691f30196b6b0e3b2c82e83b27afaf Mon Sep 17 00:00:00 2001
Vojtech Trefny 0abc76
From: Vojtech Trefny <vtrefny@redhat.com>
Vojtech Trefny 0abc76
Date: Fri, 30 Jul 2021 14:01:43 +0200
Vojtech Trefny 0abc76
Subject: [PATCH 5/7] Make sure PVs are added/deleted to/from the LVM device
Vojtech Trefny 0abc76
 file
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
We are using the --devices option when running LVM commands which
Vojtech Trefny 0abc76
mean the newly created PV won't be added to the device list by
Vojtech Trefny 0abc76
pvcreate so we need to do that manually.
Vojtech Trefny 0abc76
---
Vojtech Trefny 0abc76
 blivet/formats/lvmpv.py | 5 +++++
Vojtech Trefny 0abc76
 1 file changed, 5 insertions(+)
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
diff --git a/blivet/formats/lvmpv.py b/blivet/formats/lvmpv.py
Vojtech Trefny 0abc76
index 3b00951f..71ec699f 100644
Vojtech Trefny 0abc76
--- a/blivet/formats/lvmpv.py
Vojtech Trefny 0abc76
+++ b/blivet/formats/lvmpv.py
Vojtech Trefny 0abc76
@@ -131,6 +131,9 @@ class LVMPhysicalVolume(DeviceFormat):
Vojtech Trefny 0abc76
         ea_yes = blockdev.ExtraArg.new("-y", "")
Vojtech Trefny 0abc76
         blockdev.lvm.pvcreate(self.device, data_alignment=self.data_alignment, extra=[ea_yes])
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
+        if lvm.HAVE_LVMDEVICES:
Vojtech Trefny 0abc76
+            blockdev.lvm.devices_add(self.device)
Vojtech Trefny 0abc76
+
Vojtech Trefny 0abc76
     def _destroy(self, **kwargs):
Vojtech Trefny 0abc76
         log_method_call(self, device=self.device,
Vojtech Trefny 0abc76
                         type=self.type, status=self.status)
Vojtech Trefny 0abc76
@@ -141,6 +144,8 @@ class LVMPhysicalVolume(DeviceFormat):
Vojtech Trefny 0abc76
         finally:
Vojtech Trefny 0abc76
             lvm.lvm_devices_remove(self.device)
Vojtech Trefny 0abc76
             udev.settle()
Vojtech Trefny 0abc76
+            if lvm.HAVE_LVMDEVICES:
Vojtech Trefny 0abc76
+                blockdev.lvm.devices_delete(self.device)
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
     @property
Vojtech Trefny 0abc76
     def destroyable(self):
Vojtech Trefny 0abc76
-- 
Vojtech Trefny 0abc76
2.31.1
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
From c221d313bde21fb2cba701b93fe0c57336cba8ec Mon Sep 17 00:00:00 2001
Vojtech Trefny 0abc76
From: Vojtech Trefny <vtrefny@redhat.com>
Vojtech Trefny 0abc76
Date: Thu, 14 Oct 2021 15:32:24 +0200
Vojtech Trefny 0abc76
Subject: [PATCH 6/7] Ignore errors for LVM devices file actions
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
The LVM devices file feature might be disabled either locally or
Vojtech Trefny 0abc76
globally by LVM config.
Vojtech Trefny 0abc76
---
Vojtech Trefny 0abc76
 blivet/formats/lvmpv.py | 10 ++++++++--
Vojtech Trefny 0abc76
 1 file changed, 8 insertions(+), 2 deletions(-)
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
diff --git a/blivet/formats/lvmpv.py b/blivet/formats/lvmpv.py
Vojtech Trefny 0abc76
index 71ec699f..b27213cc 100644
Vojtech Trefny 0abc76
--- a/blivet/formats/lvmpv.py
Vojtech Trefny 0abc76
+++ b/blivet/formats/lvmpv.py
Vojtech Trefny 0abc76
@@ -132,7 +132,10 @@ class LVMPhysicalVolume(DeviceFormat):
Vojtech Trefny 0abc76
         blockdev.lvm.pvcreate(self.device, data_alignment=self.data_alignment, extra=[ea_yes])
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
         if lvm.HAVE_LVMDEVICES:
Vojtech Trefny 0abc76
-            blockdev.lvm.devices_add(self.device)
Vojtech Trefny 0abc76
+            try:
Vojtech Trefny 0abc76
+                blockdev.lvm.devices_add(self.device)
Vojtech Trefny 0abc76
+            except blockdev.LVMError as e:
Vojtech Trefny 0abc76
+                log.debug("Failed to add newly created PV %s to the LVM devices file: %s", self.device, str(e))
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
     def _destroy(self, **kwargs):
Vojtech Trefny 0abc76
         log_method_call(self, device=self.device,
Vojtech Trefny 0abc76
@@ -145,7 +148,10 @@ class LVMPhysicalVolume(DeviceFormat):
Vojtech Trefny 0abc76
             lvm.lvm_devices_remove(self.device)
Vojtech Trefny 0abc76
             udev.settle()
Vojtech Trefny 0abc76
             if lvm.HAVE_LVMDEVICES:
Vojtech Trefny 0abc76
-                blockdev.lvm.devices_delete(self.device)
Vojtech Trefny 0abc76
+                try:
Vojtech Trefny 0abc76
+                    blockdev.lvm.devices_delete(self.device)
Vojtech Trefny 0abc76
+                except blockdev.LVMError as e:
Vojtech Trefny 0abc76
+                    log.debug("Failed to remove PV %s from the LVM devices file: %s", self.device, str(e))
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
     @property
Vojtech Trefny 0abc76
     def destroyable(self):
Vojtech Trefny 0abc76
-- 
Vojtech Trefny 0abc76
2.31.1
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
From 6b96d4ead6890fffd95840b8935f71ecd9e310ef Mon Sep 17 00:00:00 2001
Vojtech Trefny 0abc76
From: Vojtech Trefny <vtrefny@redhat.com>
Vojtech Trefny 0abc76
Date: Tue, 19 Oct 2021 14:27:05 +0200
Vojtech Trefny 0abc76
Subject: [PATCH 7/7] Add public functions to add/remove PV to/from the LVM
Vojtech Trefny 0abc76
 system.devices
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
Anaconda needs to be able to add preexisting PVs to the file
Vojtech Trefny 0abc76
during installation.
Vojtech Trefny 0abc76
---
Vojtech Trefny 0abc76
 blivet/formats/lvmpv.py | 28 ++++++++++++++++++++--------
Vojtech Trefny 0abc76
 1 file changed, 20 insertions(+), 8 deletions(-)
Vojtech Trefny 0abc76
Vojtech Trefny 0abc76
diff --git a/blivet/formats/lvmpv.py b/blivet/formats/lvmpv.py
Vojtech Trefny 0abc76
index b27213cc..3fef667e 100644
Vojtech Trefny 0abc76
--- a/blivet/formats/lvmpv.py
Vojtech Trefny 0abc76
+++ b/blivet/formats/lvmpv.py
Vojtech Trefny 0abc76
@@ -121,6 +121,24 @@ class LVMPhysicalVolume(DeviceFormat):
Vojtech Trefny 0abc76
     def supported(self):
Vojtech Trefny 0abc76
         return super(LVMPhysicalVolume, self).supported and self._plugin.available
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
+    def lvmdevices_add(self):
Vojtech Trefny 0abc76
+        if not lvm.HAVE_LVMDEVICES:
Vojtech Trefny 0abc76
+            raise PhysicalVolumeError("LVM devices file feature is not supported")
Vojtech Trefny 0abc76
+
Vojtech Trefny 0abc76
+        try:
Vojtech Trefny 0abc76
+            blockdev.lvm.devices_add(self.device)
Vojtech Trefny 0abc76
+        except blockdev.LVMError as e:
Vojtech Trefny 0abc76
+            log.debug("Failed to add PV %s to the LVM devices file: %s", self.device, str(e))
Vojtech Trefny 0abc76
+
Vojtech Trefny 0abc76
+    def lvmdevices_remove(self):
Vojtech Trefny 0abc76
+        if not lvm.HAVE_LVMDEVICES:
Vojtech Trefny 0abc76
+            raise PhysicalVolumeError("LVM devices file feature is not supported")
Vojtech Trefny 0abc76
+
Vojtech Trefny 0abc76
+        try:
Vojtech Trefny 0abc76
+            blockdev.lvm.devices_delete(self.device)
Vojtech Trefny 0abc76
+        except blockdev.LVMError as e:
Vojtech Trefny 0abc76
+            log.debug("Failed to remove PV %s from the LVM devices file: %s", self.device, str(e))
Vojtech Trefny 0abc76
+
Vojtech Trefny 0abc76
     def _create(self, **kwargs):
Vojtech Trefny 0abc76
         log_method_call(self, device=self.device,
Vojtech Trefny 0abc76
                         type=self.type, status=self.status)
Vojtech Trefny 0abc76
@@ -132,10 +150,7 @@ class LVMPhysicalVolume(DeviceFormat):
Vojtech Trefny 0abc76
         blockdev.lvm.pvcreate(self.device, data_alignment=self.data_alignment, extra=[ea_yes])
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
         if lvm.HAVE_LVMDEVICES:
Vojtech Trefny 0abc76
-            try:
Vojtech Trefny 0abc76
-                blockdev.lvm.devices_add(self.device)
Vojtech Trefny 0abc76
-            except blockdev.LVMError as e:
Vojtech Trefny 0abc76
-                log.debug("Failed to add newly created PV %s to the LVM devices file: %s", self.device, str(e))
Vojtech Trefny 0abc76
+            self.lvmdevices_add()
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
     def _destroy(self, **kwargs):
Vojtech Trefny 0abc76
         log_method_call(self, device=self.device,
Vojtech Trefny 0abc76
@@ -148,10 +163,7 @@ class LVMPhysicalVolume(DeviceFormat):
Vojtech Trefny 0abc76
             lvm.lvm_devices_remove(self.device)
Vojtech Trefny 0abc76
             udev.settle()
Vojtech Trefny 0abc76
             if lvm.HAVE_LVMDEVICES:
Vojtech Trefny 0abc76
-                try:
Vojtech Trefny 0abc76
-                    blockdev.lvm.devices_delete(self.device)
Vojtech Trefny 0abc76
-                except blockdev.LVMError as e:
Vojtech Trefny 0abc76
-                    log.debug("Failed to remove PV %s from the LVM devices file: %s", self.device, str(e))
Vojtech Trefny 0abc76
+                self.lvmdevices_remove()
Vojtech Trefny 0abc76
 
Vojtech Trefny 0abc76
     @property
Vojtech Trefny 0abc76
     def destroyable(self):
Vojtech Trefny 0abc76
-- 
Vojtech Trefny 0abc76
2.31.1
Vojtech Trefny 0abc76