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):