summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Asleson <tasleson@redhat.com>2017-06-02 12:25:01 -0500
committerTony Asleson <tasleson@redhat.com>2017-06-02 12:32:51 -0500
commit699ccc05cacc32b4707bf12dba4ccbb994469048 (patch)
treefa12e4899acae178a46ac8f626046a61620c9855
parent192d142e1cd38c1593ec76502d8424997ec01ec8 (diff)
downloadlvm2-699ccc05cacc32b4707bf12dba4ccbb994469048.tar.gz
lvmdbusd: Add background command to flight recorder
We were not adding background tasks to flight recorder. Add the meta data to the flight recorder when we start the command and update the meta data when the command is finished. Locking was added to meta data to prevent concurrent update and returning string representation as these can happen in two different threads.
-rw-r--r--daemons/lvmdbusd/background.py13
-rw-r--r--daemons/lvmdbusd/cmdhandler.py14
2 files changed, 20 insertions, 7 deletions
diff --git a/daemons/lvmdbusd/background.py b/daemons/lvmdbusd/background.py
index f7f77d586..90e8b6881 100644
--- a/daemons/lvmdbusd/background.py
+++ b/daemons/lvmdbusd/background.py
@@ -9,12 +9,13 @@
import subprocess
from . import cfg
-from .cmdhandler import options_to_cli_args
+from .cmdhandler import options_to_cli_args, LvmExecutionMeta
import dbus
from .utils import pv_range_append, pv_dest_ranges, log_error, log_debug,\
add_no_notify
import os
import threading
+import time
def pv_move_lv_cmd(move_options, lv_full_name,
@@ -47,6 +48,11 @@ def _move_merge(interface_name, command, job_state):
# Instruct lvm to not register an event with us
command = add_no_notify(command)
+ #(self, start, ended, cmd, ec, stdout_txt, stderr_txt)
+ meta = LvmExecutionMeta(time.time(), 0, command, -1000, None, None)
+
+ cfg.blackbox.add(meta)
+
process = subprocess.Popen(command, stdout=subprocess.PIPE,
env=os.environ,
stderr=subprocess.PIPE, close_fds=True)
@@ -74,6 +80,11 @@ def _move_merge(interface_name, command, job_state):
out = process.communicate()
+ with meta.lock:
+ meta.ended = time.time()
+ meta.ec = process.returncode
+ meta.stderr_txt = out[1]
+
if process.returncode == 0:
job_state.Percent = 100
else:
diff --git a/daemons/lvmdbusd/cmdhandler.py b/daemons/lvmdbusd/cmdhandler.py
index a883f1e43..4fb1670a9 100644
--- a/daemons/lvmdbusd/cmdhandler.py
+++ b/daemons/lvmdbusd/cmdhandler.py
@@ -37,6 +37,7 @@ cmd_lock = threading.RLock()
class LvmExecutionMeta(object):
def __init__(self, start, ended, cmd, ec, stdout_txt, stderr_txt):
+ self.lock = threading.RLock()
self.start = start
self.ended = ended
self.cmd = cmd
@@ -45,12 +46,13 @@ class LvmExecutionMeta(object):
self.stderr_txt = stderr_txt
def __str__(self):
- return "EC= %d for %s\n" \
- "STARTED: %f, ENDED: %f\n" \
- "STDOUT=%s\n" \
- "STDERR=%s\n" % \
- (self.ec, str(self.cmd), self.start, self.ended, self.stdout_txt,
- self.stderr_txt)
+ with self.lock:
+ return "EC= %d for %s\n" \
+ "STARTED: %f, ENDED: %f\n" \
+ "STDOUT=%s\n" \
+ "STDERR=%s\n" % \
+ (self.ec, str(self.cmd), self.start, self.ended, self.stdout_txt,
+ self.stderr_txt)
class LvmFlightRecorder(object):