Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=4902034c895d2642…
Commit: 4902034c895d26423564175c0636cff8ba4112e1
Parent: 2352ff24a55757a70869f443126d67cece0fb0a4
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Aug 24 18:29:35 2016 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Mon Aug 29 15:26:55 2016 -0500
lvmdbusd: Use udev until ExternalEvent occurs
The normal mode of operation will be to monitor for udev events until an
ExternalEvent occurs. In that case the service will disable monitoring
for udev events and use ExternalEvent exclusively.
Note: User specifies --udev the service will always monitor udev regardless
if ExternalEvent is being called too.
---
daemons/lvmdbusd/cfg.py | 14 +++++++++-----
daemons/lvmdbusd/cmdhandler.py | 24 ++++++++++++++++++------
daemons/lvmdbusd/lvm_shell_proxy.py | 6 ++++++
daemons/lvmdbusd/main.py | 28 ++++++++++++++--------------
daemons/lvmdbusd/manager.py | 9 ++++++++-
daemons/lvmdbusd/udevwatch.py | 25 ++++++++++++++++---------
daemons/lvmdbusd/utils.py | 2 +-
7 files changed, 72 insertions(+), 36 deletions(-)
diff --git a/daemons/lvmdbusd/cfg.py b/daemons/lvmdbusd/cfg.py
index 8aec8ae..1d773c3 100644
--- a/daemons/lvmdbusd/cfg.py
+++ b/daemons/lvmdbusd/cfg.py
@@ -24,14 +24,18 @@ om = None
# This is the global bus connection
bus = None
+# Command line args
+args = None
+
+# Set to true if we are depending on external events for updates
+ee = False
+
# Shared state variable across all processes
run = multiprocessing.Value('i', 1)
-# Debug
-DEBUG = True
-
-# Use lvm shell
-USE_SHELL = False
+# If this is set to true, the current setup support lvm shell and we are
+# running in that mode of operation
+SHELL_IN_USE = None
# Lock used by pprint
stdout_lock = multiprocessing.Lock()
diff --git a/daemons/lvmdbusd/cmdhandler.py b/daemons/lvmdbusd/cmdhandler.py
index 0d35782..5815031 100644
--- a/daemons/lvmdbusd/cmdhandler.py
+++ b/daemons/lvmdbusd/cmdhandler.py
@@ -13,6 +13,7 @@ import threading
from itertools import chain
import collections
import traceback
+import os
try:
from . import cfg
@@ -101,7 +102,8 @@ def call_lvm(command, debug=False):
# in different locations on the same box
command.insert(0, cfg.LVM_CMD)
- process = Popen(command, stdout=PIPE, stderr=PIPE, close_fds=True)
+ process = Popen(command, stdout=PIPE, stderr=PIPE, close_fds=True,
+ env=os.environ)
out = process.communicate()
stdout_text = bytes(out[0]).decode("utf-8")
@@ -111,7 +113,7 @@ def call_lvm(command, debug=False):
_debug_c(command, process.returncode, (stdout_text, stderr_text))
if process.returncode == 0:
- if cfg.DEBUG and out[1] and len(out[1]) and 'help' not in command:
+ if cfg.args.debug and out[1] and len(out[1]) and 'help' not in command:
log_error('WARNING: lvm is out-putting text to STDERR on success!')
_debug_c(command, process.returncode, (stdout_text, stderr_text))
@@ -123,9 +125,10 @@ def _shell_cfg():
try:
lvm_shell = LVMShellProxy()
_t_call = lvm_shell.call_lvm
- cfg.USE_SHELL = True
+ cfg.SHELL_IN_USE = lvm_shell
except Exception:
_t_call = call_lvm
+ cfg.SHELL_IN_USE = None
log_error(traceback.format_exc())
log_error("Unable to utilize lvm shell, dropping back to fork & exec")
@@ -133,6 +136,15 @@ def _shell_cfg():
def set_execution(shell):
global _t_call
with cmd_lock:
+ # If the user requested lvm shell and we are currently setup that
+ # way, just return
+ if cfg.SHELL_IN_USE and shell:
+ return
+ else:
+ if not shell and cfg.SHELL_IN_USE:
+ cfg.SHELL_IN_USE.exit_shell()
+ cfg.SHELL_IN_USE = None
+
_t_call = call_lvm
if shell:
_shell_cfg()
@@ -217,7 +229,7 @@ def pv_remove(device, remove_options):
def _qt(tag_name):
# When running in lvm shell you need to quote the tags
- if cfg.USE_SHELL:
+ if cfg.SHELL_IN_USE:
return '"%s"' % tag_name
return tag_name
@@ -440,7 +452,7 @@ def supports_json():
cmd = ['help']
rc, out, err = call(cmd)
if rc == 0:
- if cfg.USE_SHELL:
+ if cfg.SHELL_IN_USE:
return True
else:
if 'fullreport' in err:
@@ -488,7 +500,7 @@ def lvm_full_report_json():
# With the current implementation, if we are using the shell then we
# are using JSON and JSON is returned back to us as it was parsed to
# figure out if we completed OK or not
- if cfg.USE_SHELL:
+ if cfg.SHELL_IN_USE:
assert(type(out) == dict)
return out
else:
diff --git a/daemons/lvmdbusd/lvm_shell_proxy.py b/daemons/lvmdbusd/lvm_shell_proxy.py
index d4eff86..3455342 100755
--- a/daemons/lvmdbusd/lvm_shell_proxy.py
+++ b/daemons/lvmdbusd/lvm_shell_proxy.py
@@ -203,6 +203,12 @@ class LVMShellProxy(object):
return rc, json_result, error_msg
+ def exit_shell(self):
+ try:
+ self._write_cmd('exit\n')
+ except Exception as e:
+ log_error(str(e))
+
def __del__(self):
try:
self.lvm_shell.terminate()
diff --git a/daemons/lvmdbusd/main.py b/daemons/lvmdbusd/main.py
index 638323a..d76b5c3 100644
--- a/daemons/lvmdbusd/main.py
+++ b/daemons/lvmdbusd/main.py
@@ -92,6 +92,7 @@ def process_request():
def main():
+ start = time.time()
# Add simple command line handling
parser = argparse.ArgumentParser()
parser.add_argument("--udev", action='store_true',
@@ -112,16 +113,13 @@ def main():
# Ensure that we get consistent output for parsing stdout/stderr
os.environ["LC_ALL"] = "C"
- args = parser.parse_args()
+ cfg.args = parser.parse_args()
- cfg.DEBUG = args.debug
- cmdhandler.set_execution(args.use_lvm_shell)
+ cmdhandler.set_execution(cfg.args.use_lvm_shell)
# List of threads that we start up
thread_list = []
- start = time.time()
-
# Install signal handlers
for s in [signal.SIGHUP, signal.SIGINT]:
try:
@@ -144,7 +142,7 @@ def main():
cfg.load = load
- cfg.db = lvmdb.DataStore(args.use_json)
+ cfg.db = lvmdb.DataStore(cfg.args.use_json)
# Start up thread to monitor pv moves
thread_list.append(
@@ -160,23 +158,25 @@ def main():
process.damon = True
process.start()
+ # Add udev watching
+ if cfg.args.use_udev:
+ log_debug('Utilizing udev to trigger updates')
+
+ # In all cases we are going to monitor for udev until we get an
+ # ExternalEvent. In the case where we get an external event and the user
+ # didn't specify --udev we will stop monitoring udev
+ udevwatch.add()
+
end = time.time()
log_debug(
'Service ready! total time= %.4f, lvm time= %.4f count= %d' %
(end - start, cmdhandler.total_time, cmdhandler.total_count),
'bg_black', 'fg_light_green')
- # Add udev watching
- if args.use_udev:
- log_debug('Utilizing udev to trigger updates')
- udevwatch.add()
-
try:
if cfg.run.value != 0:
cfg.loop.run()
-
- if args.use_udev:
- udevwatch.remove()
+ udevwatch.remove()
for process in thread_list:
process.join()
diff --git a/daemons/lvmdbusd/manager.py b/daemons/lvmdbusd/manager.py
index 2388d8a..79254fe 100644
--- a/daemons/lvmdbusd/manager.py
+++ b/daemons/lvmdbusd/manager.py
@@ -17,7 +17,7 @@ from . import cmdhandler
from .fetch import load_pvs, load_vgs
from .request import RequestEntry
from .refresh import event_add
-
+from . import udevwatch
# noinspection PyPep8Naming
class Manager(AutomatedProperties):
@@ -181,6 +181,13 @@ class Manager(AutomatedProperties):
in_signature='s', out_signature='i')
def ExternalEvent(self, command):
+ # If a user didn't explicitly specify udev, we will turn it off now.
+ if not cfg.args.use_udev:
+ if udevwatch.remove():
+ utils.log_debug("ExternalEvent received, disabling "
+ "udev monitoring")
+ # We are dependent on external events now to stay current!
+ cfg.ee = True
event_add((command,))
return dbus.Int32(0)
diff --git a/daemons/lvmdbusd/udevwatch.py b/daemons/lvmdbusd/udevwatch.py
index c3e6e60..6d56443 100644
--- a/daemons/lvmdbusd/udevwatch.py
+++ b/daemons/lvmdbusd/udevwatch.py
@@ -8,10 +8,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pyudev
+import threading
from .refresh import event_add
from . import cfg
observer = None
+observer_lock = threading.RLock()
# noinspection PyUnusedLocal
@@ -40,15 +42,20 @@ def filter_event(action, device):
def add():
- global observer
- context = pyudev.Context()
- monitor = pyudev.Monitor.from_netlink(context)
- monitor.filter_by('block')
- observer = pyudev.MonitorObserver(monitor, filter_event)
- observer.start()
+ with observer_lock:
+ global observer
+ context = pyudev.Context()
+ monitor = pyudev.Monitor.from_netlink(context)
+ monitor.filter_by('block')
+ observer = pyudev.MonitorObserver(monitor, filter_event)
+ observer.start()
def remove():
- global observer
- observer.stop()
- observer = None
+ with observer_lock:
+ global observer
+ if observer:
+ observer.stop()
+ observer = None
+ return True
+ return False
diff --git a/daemons/lvmdbusd/utils.py b/daemons/lvmdbusd/utils.py
index 9db7857..65668fc 100644
--- a/daemons/lvmdbusd/utils.py
+++ b/daemons/lvmdbusd/utils.py
@@ -265,7 +265,7 @@ def _common_log(msg, *attributes):
# @param msg Message to output to stdout
# @return None
def log_debug(msg, *attributes):
- if cfg.DEBUG:
+ if cfg.args.debug:
_common_log(msg, *attributes)
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=a0a2c84a26a9542d…
Commit: a0a2c84a26a9542d32fa7db1f7dcae8ccb8beb88
Parent: 7e37e7fde4e683572fa3d9a640821ba9bd4bb3d0
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Fri Aug 12 15:20:49 2016 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Mon Aug 29 15:26:55 2016 -0500
lvmdbusd: Add date & ts if running in a terminal
When we are running in a terminal it's useful to have a date & ts on log
output like you get when output goes to the journal. Check if we are
running on a tty and if we are, add it in.
---
daemons/lvmdbusd/utils.py | 9 ++++++++-
1 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/daemons/lvmdbusd/utils.py b/daemons/lvmdbusd/utils.py
index 3dcb373..9db7857 100644
--- a/daemons/lvmdbusd/utils.py
+++ b/daemons/lvmdbusd/utils.py
@@ -13,6 +13,7 @@ import inspect
import ctypes
import os
import string
+import datetime
import dbus
import dbus.service
@@ -243,7 +244,13 @@ def _common_log(msg, *attributes):
cfg.stdout_lock.acquire()
tid = ctypes.CDLL('libc.so.6').syscall(186)
- msg = "%d:%d - %s" % (os.getpid(), tid, msg)
+ if STDOUT_TTY:
+ msg = "%s: %d:%d - %s" % \
+ (datetime.datetime.now().strftime("%b %d %H:%M:%S.%f"),
+ os.getpid(), tid, msg)
+
+ else:
+ msg = "%d:%d - %s" % (os.getpid(), tid, msg)
if STDOUT_TTY and attributes:
print(color(msg, *attributes))
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=7e37e7fde4e68357…
Commit: 7e37e7fde4e683572fa3d9a640821ba9bd4bb3d0
Parent: 784b46ef2a3b674def64a1185733122b300bb22c
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Fri Aug 12 15:19:03 2016 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Mon Aug 29 15:26:55 2016 -0500
lvmdbusd: Always fork & exec background commands
Our background job support requires a separate instance of lvm. Use the
full lvm command to do so.
---
daemons/lvmdbusd/background.py | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/daemons/lvmdbusd/background.py b/daemons/lvmdbusd/background.py
index 8078b66..0c0b509 100644
--- a/daemons/lvmdbusd/background.py
+++ b/daemons/lvmdbusd/background.py
@@ -15,6 +15,7 @@ from .cmdhandler import options_to_cli_args
import dbus
from .utils import pv_range_append, pv_dest_ranges, log_error, log_debug
import traceback
+import os
_rlock = threading.RLock()
_thread_list = list()
@@ -130,8 +131,16 @@ def background_execute(command, background_job):
# hit a code bug we will silently exit this thread without anyone being
# the wiser.
try:
+ # We need to execute these command stand alone by forking & exec'ing
+ # the command always!
+ command.insert(0, cfg.LVM_CMD)
process = subprocess.Popen(command, stdout=subprocess.PIPE,
+ env=os.environ,
stderr=subprocess.PIPE, close_fds=True)
+
+ log_debug("Background process for %s is %d" %
+ (str(command), process.pid))
+
lines_iterator = iter(process.stdout.readline, b"")
for line in lines_iterator:
line_str = line.decode("utf-8")
@@ -150,8 +159,12 @@ def background_execute(command, background_job):
if process.returncode == 0:
background_job.Percent = 100
+ else:
+ log_error("Failed to execute background job %s, STDERR= %s"
+ % (str(command), out[1]))
background_job.set_result(process.returncode, out[1])
+ log_debug("Background process %d complete!" % process.pid)
except Exception:
# In the unlikely event that we blow up, we need to unblock caller which
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=81970d22d8a841c1…
Commit: 81970d22d8a841c1ea69fde5c9108fc4df3759bd
Parent: b493811968b34876ef558ad04d18c1b76bd28113
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Aug 24 10:05:09 2016 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Aug 29 20:51:15 2016 +0200
cache: do not monitor cache-pool
Avoid monitoring of activated cache-pool - where the only purpose ATM
is to clear metadata volume which is actually activate in place
of cache-pool name (using public LV name).
Since VG lock is held across whole clear operation, dmeventd cannot
be used anyway - however in case of appliction crash we may
leave unmonitored device.
In future we may provide better mechanism as the current name
replacemnet is creating 'uncommon' table setups in case the metadata
LV is more complex type like raid (needs some futher thinking about
error path results).
Another point to think about is the fact we should not clear device
while holding lock (i.e. dmeventd mirror repair cannot work in cases
like this).
---
WHATS_NEW | 1 +
lib/activate/activate.c | 17 +++++++++++++++++
2 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 76e203d..6980e17 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.165 -
===================================
+ Do not monitor cache-pool metadata when LV is just being cleared.
Add allocation/cache_pool_max_chunks to prevent misuse of cache target.
Give error not segfault in lvconvert --splitmirrors when PV lies outside LV.
Fix typo in report/columns_as_rows config option name recognition (2.02.99).
diff --git a/lib/activate/activate.c b/lib/activate/activate.c
index f4d3a17..9977291 100644
--- a/lib/activate/activate.c
+++ b/lib/activate/activate.c
@@ -1724,6 +1724,23 @@ int monitor_dev_for_events(struct cmd_context *cmd, const struct logical_volume
return 1;
/*
+ * Activation of unused cache-pool activates metadata device as
+ * a public LV for clearing purpose.
+ * FIXME:
+ * As VG lock is held across whole operation unmonitored volume
+ * is usually OK since dmeventd couldn't do anything.
+ * However in case command would have crashed, such LV is
+ * left unmonitored and may potentially require dmeventd.
+ */
+ if ((lv_is_cache_pool_data(lv) || lv_is_cache_pool_metadata(lv)) &&
+ !lv_is_used_cache_pool((find_pool_seg(first_seg(lv))->lv))) {
+ log_debug_activation("Skipping %smonitor of %s.%s",
+ (monitor) ? "" : "un", display_lvname(lv),
+ (monitor) ? " Cache pool activation for clearing only." : "");
+ return 1;
+ }
+
+ /*
* Allow to unmonitor thin pool via explicit pool unmonitor
* or unmonitor before the last thin pool user deactivation
* Skip unmonitor, if invoked via deactivation of thin volume