[PATCH 10/11] Set and refresh BlockDev's global LVM config if needed

Vratislav Podzimek vpodzime at redhat.com
Thu Feb 12 08:51:42 UTC 2015


BlockDev now runs all the lvm utilities for us so we need to set it the global
config if we want any.

Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 blivet/devicelibs/lvm.py | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/blivet/devicelibs/lvm.py b/blivet/devicelibs/lvm.py
index 1fd22de..5d2a9cc 100644
--- a/blivet/devicelibs/lvm.py
+++ b/blivet/devicelibs/lvm.py
@@ -21,6 +21,7 @@
 #
 
 from collections import namedtuple
+from gi.repository import BlockDev
 
 import logging
 log = logging.getLogger("blivet")
@@ -54,16 +55,9 @@ KNOWN_THPOOL_PROFILES = (ThPoolProfile("thin-generic", N_("Generic")),
 config_args_data = { "filterRejects": [],    # regular expressions to reject.
                      "filterAccepts": [] }   # regexp to accept
 
-def _getConfigArgs(args):
+def _set_global_config():
     """lvm command accepts lvm.conf type arguments preceded by --config. """
 
-    # These commands are read-only, so we can run them with read-only locking.
-    # (not an exhaustive list, but these are the only ones used here)
-    READONLY_COMMANDS = ('lvs', 'pvs', 'vgs')
-
-    cmd = args[0]
-    config_args = []
-
     filter_string = ""
     rejects = config_args_data["filterRejects"]
     for reject in rejects:
@@ -82,19 +76,26 @@ def _getConfigArgs(args):
     # "preferred_names", "filter", "cache_dir", "write_cache_state",
     # "types", "sysfs_scan", "md_component_detection".  see man lvm.conf.
     config_string = " devices { %s } " % (devices_string) # strings can be added
-    if cmd in READONLY_COMMANDS:
-        config_string += "global {locking_type=4} "
     if not flags.lvm_metadata_backup:
         config_string += "backup {backup=0 archive=0} "
-    if config_string:
-        config_args = ["--config", config_string]
-    return config_args
 
+    BlockDev.lvm_set_global_config(config_string)
+
+def needs_config_refresh(fn):
+    def fn_with_refresh(*args, **kwargs):
+        ret = fn(*args, **kwargs)
+        _set_global_config()
+        return ret
+
+    return fn_with_refresh
+
+ at needs_config_refresh
 def lvm_cc_addFilterRejectRegexp(regexp):
     """ Add a regular expression to the --config string."""
     log.debug("lvm filter: adding %s to the reject list", regexp)
     config_args_data["filterRejects"].append(regexp)
 
+ at needs_config_refresh
 def lvm_cc_removeFilterRejectRegexp(regexp):
     """ Remove a regular expression from the --config string."""
     log.debug("lvm filter: removing %s from the reject list", regexp)
@@ -104,7 +105,7 @@ def lvm_cc_removeFilterRejectRegexp(regexp):
         log.debug("%s wasn't in the reject list", regexp)
         return
 
+ at needs_config_refresh
 def lvm_cc_resetFilter():
     config_args_data["filterRejects"] = []
     config_args_data["filterAccepts"] = []
-# End config_args handling code.
-- 
2.1.0



More information about the anaconda-patches mailing list