main - lvmdbusd: Remove exclusionary language
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=6b9cc7432ec70461217...
Commit: 6b9cc7432ec70461217c081b5d38065236aec887
Parent: c13efb2ffc90853884e77f0d2b28e8d1936c74d0
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Tue Aug 9 17:55:27 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Fri Sep 16 10:49:36 2022 -0500
lvmdbusd: Remove exclusionary language
---
daemons/lvmdbusd/background.py | 2 +-
daemons/lvmdbusd/cfg.py | 2 +-
daemons/lvmdbusd/cmdhandler.py | 8 ++++----
daemons/lvmdbusd/fetch.py | 2 +-
daemons/lvmdbusd/main.py | 12 ++++++------
daemons/lvmdbusd/manager.py | 2 +-
daemons/lvmdbusd/request.py | 2 +-
daemons/lvmdbusd/utils.py | 2 +-
8 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/daemons/lvmdbusd/background.py b/daemons/lvmdbusd/background.py
index 463bb20d5..21617c47a 100644
--- a/daemons/lvmdbusd/background.py
+++ b/daemons/lvmdbusd/background.py
@@ -68,7 +68,7 @@ def _move_merge(interface_name, command, job_state):
# the status of the long running operation.
meta = LvmExecutionMeta(time.time(), 0, command)
- cfg.blackbox.add(meta)
+ cfg.flightrecorder.add(meta)
ec, stdout, stderr = call_lvm(command, line_cb=_move_callback,
cb_data=job_state)
diff --git a/daemons/lvmdbusd/cfg.py b/daemons/lvmdbusd/cfg.py
index ee4e41b30..d7a653b54 100644
--- a/daemons/lvmdbusd/cfg.py
+++ b/daemons/lvmdbusd/cfg.py
@@ -92,7 +92,7 @@ vdo_support = False
db = None
# lvm flight recorder
-blackbox = None
+flightrecorder = None
# RequestEntry ctor
create_request_entry = None
diff --git a/daemons/lvmdbusd/cmdhandler.py b/daemons/lvmdbusd/cmdhandler.py
index 7b3ad528b..0422f8970 100644
--- a/daemons/lvmdbusd/cmdhandler.py
+++ b/daemons/lvmdbusd/cmdhandler.py
@@ -90,7 +90,7 @@ class LvmFlightRecorder(object):
log_error("LVM dbus flight recorder END")
-cfg.blackbox = LvmFlightRecorder()
+cfg.flightrecorder = LvmFlightRecorder()
def _debug_c(cmd, exit_code, out):
@@ -217,9 +217,9 @@ def time_wrapper(command, debug=False):
with cmd_lock:
start = time.time()
meta = LvmExecutionMeta(start, 0, command)
- # Add the partial metadata to black box, so if the command hangs
- # we will see what it was in the block box dump.
- cfg.blackbox.add(meta)
+ # Add the partial metadata to flight recorder, so if the command hangs
+ # we will see what it was.
+ cfg.flightrecorder.add(meta)
results = _t_call(command, debug)
ended = time.time()
total_time += (ended - start)
diff --git a/daemons/lvmdbusd/fetch.py b/daemons/lvmdbusd/fetch.py
index c17827b5a..740b15fdb 100644
--- a/daemons/lvmdbusd/fetch.py
+++ b/daemons/lvmdbusd/fetch.py
@@ -183,7 +183,7 @@ class StateUpdate(object):
except Exception as e:
st = traceback.format_exc()
log_error("update_thread exception: \n%s" % st)
- cfg.blackbox.dump()
+ cfg.flightrecorder.dump()
exception_count += 1
if exception_count >= 5:
for i in queued_requests:
diff --git a/daemons/lvmdbusd/main.py b/daemons/lvmdbusd/main.py
index 5e6f72cdc..5369f1dd5 100644
--- a/daemons/lvmdbusd/main.py
+++ b/daemons/lvmdbusd/main.py
@@ -55,7 +55,7 @@ def process_request():
utils.log_error("process_request exception: \n%s" % st)
-def check_bb_size(value):
+def check_fr_size(value):
v = int(value)
if v < 0:
raise argparse.ArgumentTypeError(
@@ -103,11 +103,11 @@ def process_args():
default=False,
dest='use_lvm_shell')
parser.add_argument(
- "--blackboxsize",
- help="Size of the black box flight recorder, 0 to disable",
+ "--frsize",
+ help="Size of the flight recorder (num. entries), 0 to disable (signal 12 to dump)",
default=10,
- type=check_bb_size,
- dest='bb_size')
+ type=check_fr_size,
+ dest='fr_size')
args = parser.parse_args()
@@ -142,7 +142,7 @@ def main():
# We create a flight recorder in cmdhandler too, but we replace it here
# as the user may be specifying a different size. The default one in
# cmdhandler is for when we are running other code with a different main.
- cfg.blackbox = LvmFlightRecorder(cfg.args.bb_size)
+ cfg.flightrecorder = LvmFlightRecorder(cfg.args.fr_size)
log_debug("Using lvm binary: %s" % cfg.LVM_CMD)
diff --git a/daemons/lvmdbusd/manager.py b/daemons/lvmdbusd/manager.py
index 573a3966f..e6b0718c4 100644
--- a/daemons/lvmdbusd/manager.py
+++ b/daemons/lvmdbusd/manager.py
@@ -137,7 +137,7 @@ class Manager(AutomatedProperties):
"""
Dump the flight recorder to syslog
"""
- cfg.blackbox.dump()
+ cfg.flightrecorder.dump()
@staticmethod
def _lookup_by_lvm_id(key):
diff --git a/daemons/lvmdbusd/request.py b/daemons/lvmdbusd/request.py
index eaec04c28..e069cfdc1 100644
--- a/daemons/lvmdbusd/request.py
+++ b/daemons/lvmdbusd/request.py
@@ -76,7 +76,7 @@ class RequestEntry(object):
# have gotten a job by the time we hit an error
# Lets get the stacktrace and set that to the error message
st = traceback.format_exc()
- cfg.blackbox.dump()
+ cfg.flightrecorder.dump()
log_error("Exception returned to client: \n%s" % st)
self.register_error(-1, str(e), e)
diff --git a/daemons/lvmdbusd/utils.py b/daemons/lvmdbusd/utils.py
index a10fa7864..e12c7fccf 100644
--- a/daemons/lvmdbusd/utils.py
+++ b/daemons/lvmdbusd/utils.py
@@ -351,7 +351,7 @@ def handler(signum):
dump_threads_stackframe()
# signal 12
elif signum == signal.SIGUSR2:
- cfg.blackbox.dump()
+ cfg.flightrecorder.dump()
else:
cfg.run.value = 0
log_debug('Exiting daemon with signal %d' % signum)
8 months, 1 week
main - lvmdbusd: Remove unneeded command line args
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=c13efb2ffc90853884e...
Commit: c13efb2ffc90853884e77f0d2b28e8d1936c74d0
Parent: b3d8366ff21ee69380ab5fbca48204212a64a0cd
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Tue Aug 9 17:45:04 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Fri Sep 16 10:49:36 2022 -0500
lvmdbusd: Remove unneeded command line args
---
daemons/lvmdbusd/cmdhandler.py | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/daemons/lvmdbusd/cmdhandler.py b/daemons/lvmdbusd/cmdhandler.py
index 0c4d5cb61..7b3ad528b 100644
--- a/daemons/lvmdbusd/cmdhandler.py
+++ b/daemons/lvmdbusd/cmdhandler.py
@@ -234,8 +234,7 @@ call = time_wrapper
# Default cmd
# Place default arguments for every command here.
def _dc(cmd, args):
- c = [cmd, '--noheading', '--separator', '%s' % SEP, '--nosuffix',
- '--unbuffered', '--units', 'b']
+ c = [cmd, '--nosuffix', '--unbuffered', '--units', 'b']
c.extend(args)
return c
8 months, 1 week
main - lvmdbusd: Add SIGUSR2 to dump flight recorder
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=b3d8366ff21ee69380a...
Commit: b3d8366ff21ee69380ab5fbca48204212a64a0cd
Parent: 05f7fa5a8536d37b6a711ac0baab5bfd105bb0cc
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Tue Aug 9 17:44:10 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Fri Sep 16 10:49:36 2022 -0500
lvmdbusd: Add SIGUSR2 to dump flight recorder
---
daemons/lvmdbusd/main.py | 1 +
daemons/lvmdbusd/utils.py | 4 ++++
2 files changed, 5 insertions(+)
diff --git a/daemons/lvmdbusd/main.py b/daemons/lvmdbusd/main.py
index 7b455052e..5e6f72cdc 100644
--- a/daemons/lvmdbusd/main.py
+++ b/daemons/lvmdbusd/main.py
@@ -77,6 +77,7 @@ def install_signal_handlers():
signal_add(GLib.PRIORITY_HIGH, signal.SIGHUP, utils.handler, signal.SIGHUP)
signal_add(GLib.PRIORITY_HIGH, signal.SIGINT, utils.handler, signal.SIGINT)
signal_add(GLib.PRIORITY_HIGH, signal.SIGUSR1, utils.handler, signal.SIGUSR1)
+ signal_add(GLib.PRIORITY_HIGH, signal.SIGUSR2, utils.handler, signal.SIGUSR2)
else:
log_error("GLib.unix_signal_[add|add_full] are NOT available!")
diff --git a/daemons/lvmdbusd/utils.py b/daemons/lvmdbusd/utils.py
index d24a34935..a10fa7864 100644
--- a/daemons/lvmdbusd/utils.py
+++ b/daemons/lvmdbusd/utils.py
@@ -346,8 +346,12 @@ def dump_threads_stackframe():
# noinspection PyUnusedLocal
def handler(signum):
try:
+ # signal 10
if signum == signal.SIGUSR1:
dump_threads_stackframe()
+ # signal 12
+ elif signum == signal.SIGUSR2:
+ cfg.blackbox.dump()
else:
cfg.run.value = 0
log_debug('Exiting daemon with signal %d' % signum)
8 months, 1 week
main - lvmdbusd: Re-work flight recorder data
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=05f7fa5a8536d37b6a7...
Commit: 05f7fa5a8536d37b6a711ac0baab5bfd105bb0cc
Parent: ea45ba753eaa168429b9747500e6f31f2856890f
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Tue Aug 9 17:43:00 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Fri Sep 16 10:49:36 2022 -0500
lvmdbusd: Re-work flight recorder data
Introduce a new lock for the flight recorder, so that we can dump it when
a command is block waiting for lvm to complete. Also in all paths we will
addthe metadata to the flight recorder before it's done, so we will have
it when a command hangs and we dump the flight recorder. Add the missing
bits after the command has finished.
Cleaned up the output too.
---
daemons/lvmdbusd/background.py | 9 +++------
daemons/lvmdbusd/cmdhandler.py | 38 +++++++++++++++++++++++++++++---------
2 files changed, 32 insertions(+), 15 deletions(-)
diff --git a/daemons/lvmdbusd/background.py b/daemons/lvmdbusd/background.py
index 32b2cdc38..463bb20d5 100644
--- a/daemons/lvmdbusd/background.py
+++ b/daemons/lvmdbusd/background.py
@@ -67,16 +67,13 @@ def _move_merge(interface_name, command, job_state):
# the command always as we will be getting periodic output from them on
# the status of the long running operation.
- meta = LvmExecutionMeta(time.time(), 0, command, -1000, None, None)
+ meta = LvmExecutionMeta(time.time(), 0, command)
cfg.blackbox.add(meta)
ec, stdout, stderr = call_lvm(command, line_cb=_move_callback,
cb_data=job_state)
-
- with meta.lock:
- meta.ended = time.time()
- meta.ec = ec
- meta.stderr_txt = stderr
+ ended = time.time()
+ meta.completed(ended, ec, stdout, stderr)
if ec == 0:
job_state.Percent = 100
diff --git a/daemons/lvmdbusd/cmdhandler.py b/daemons/lvmdbusd/cmdhandler.py
index 8fbcd2e3a..0c4d5cb61 100644
--- a/daemons/lvmdbusd/cmdhandler.py
+++ b/daemons/lvmdbusd/cmdhandler.py
@@ -38,7 +38,7 @@ cmd_lock = threading.RLock()
class LvmExecutionMeta(object):
- def __init__(self, start, ended, cmd, ec, stdout_txt, stderr_txt):
+ def __init__(self, start, ended, cmd, ec=-1000, stdout_txt=None, stderr_txt=None):
self.lock = threading.RLock()
self.start = start
self.ended = ended
@@ -49,26 +49,42 @@ class LvmExecutionMeta(object):
def __str__(self):
with self.lock:
- return "EC= %d for %s\n" \
- "STARTED: %f, ENDED: %f\n" \
+ if self.ended == 0:
+ ended_txt = "still running"
+ self.ended = time.time()
+ else:
+ ended_txt = str(time.ctime(self.ended))
+
+ return 'EC= %d for "%s"\n' \
+ "STARTED: %s, ENDED: %s, DURATION: %f\n" \
"STDOUT=%s\n" \
"STDERR=%s\n" % \
- (self.ec, str(self.cmd), self.start, self.ended, self.stdout_txt,
- self.stderr_txt)
+ (self.ec, " ".join(self.cmd), time.ctime(self.start), ended_txt, float(self.ended) - self.start,
+ self.stdout_txt,
+ self.stderr_txt)
+
+ def completed(self, end_time, ec, stdout_txt, stderr_txt):
+ with self.lock:
+ self.ended = end_time
+ self.ec = ec
+ self.stdout_txt = stdout_txt
+ self.stderr_txt = stderr_txt
class LvmFlightRecorder(object):
def __init__(self, size=16):
self.queue = collections.deque(maxlen=size)
+ self.lock = threading.RLock()
def add(self, lvm_exec_meta):
- self.queue.append(lvm_exec_meta)
+ with self.lock:
+ self.queue.append(lvm_exec_meta)
def dump(self):
- with cmd_lock:
+ with self.lock:
if len(self.queue):
- log_error("LVM dbus flight recorder START")
+ log_error("LVM dbus flight recorder START (in order of newest to oldest)")
for c in reversed(self.queue):
log_error(str(c))
log_error("LVM dbus flight recorder END")
@@ -200,11 +216,15 @@ def time_wrapper(command, debug=False):
with cmd_lock:
start = time.time()
+ meta = LvmExecutionMeta(start, 0, command)
+ # Add the partial metadata to black box, so if the command hangs
+ # we will see what it was in the block box dump.
+ cfg.blackbox.add(meta)
results = _t_call(command, debug)
ended = time.time()
total_time += (ended - start)
total_count += 1
- cfg.blackbox.add(LvmExecutionMeta(start, ended, command, *results))
+ meta.completed(ended, *results)
return results
8 months, 1 week
main - lvmdbustest: Remove force exception in _wait_for_job
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ea45ba753eaa168429b...
Commit: ea45ba753eaa168429b9747500e6f31f2856890f
Parent: 3fdf4493481ff8baae2ac5416dce6d05b69e6b28
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Tue Aug 9 17:36:54 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Fri Sep 16 10:49:36 2022 -0500
lvmdbustest: Remove force exception in _wait_for_job
We put this in to test one of the paths in the damon, but unfortunately
if we hit the race condition where the job actually is done we will try
to call j.Wait(1) after the remove. This fails with:
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownMethod:
Method "Wait" with signature "i" on interface "com.redhat.lvmdbus1.Job"
doesn't exist
Which is caused by the dbus object no longer existing. We could handle
this, but the issue is we no longer have the ability to get the result to
return, they have been lost.
A better solution would be to write a specific unit test to force this code
path and handle all the possible outcomes.
---
test/dbus/lvmdbustest.py | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/test/dbus/lvmdbustest.py b/test/dbus/lvmdbustest.py
index 02d4d35d7..e7df238ce 100755
--- a/test/dbus/lvmdbustest.py
+++ b/test/dbus/lvmdbustest.py
@@ -900,16 +900,6 @@ class TestDbusService(unittest.TestCase):
j.Remove()
break
- else:
- # Most of the time we will get this exception as expected, but there is
- # a race condition between checking if it's complete and removing it (we want to try to remove while
- # it's not complete to raise the exception)
- # Thus, we can't reliably use self.assertRaises.
- # We have included it here to test this path in the daemon.
- try:
- j.Remove()
- except dbus.exceptions.DBusException:
- pass
if j.Wait(1):
self.assertTrue(j.Wait(0))
8 months, 1 week
main - lvmdbusd: Add lockfile
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=3fdf4493481ff8baae2...
Commit: 3fdf4493481ff8baae2ac5416dce6d05b69e6b28
Parent: 1a4384979cdf889bd63a932d83933079c53490ae
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Mon Aug 8 20:48:10 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Fri Sep 16 10:49:36 2022 -0500
lvmdbusd: Add lockfile
The daemon cannot handle multiple copies of itself running at the
same time, ensure this cannot happen.
---
daemons/lvmdbusd/cfg.py | 2 +
daemons/lvmdbusd/main.py | 111 +++++++++++++++++++++++-----------------------
daemons/lvmdbusd/utils.py | 37 ++++++++++++++--
3 files changed, 92 insertions(+), 58 deletions(-)
diff --git a/daemons/lvmdbusd/cfg.py b/daemons/lvmdbusd/cfg.py
index 684c2b208..ee4e41b30 100644
--- a/daemons/lvmdbusd/cfg.py
+++ b/daemons/lvmdbusd/cfg.py
@@ -16,6 +16,8 @@ from lvmdbusd import path
LVM_CMD = os.getenv('LVM_BINARY', path.LVM_BINARY)
+LOCK_FILE = os.getenv("LVM_DBUSD_LOCKFILE", "/var/lock/lvm/lvmdbusd")
+
# This is the global object manager
om = None
diff --git a/daemons/lvmdbusd/main.py b/daemons/lvmdbusd/main.py
index 1e883c901..7b455052e 100644
--- a/daemons/lvmdbusd/main.py
+++ b/daemons/lvmdbusd/main.py
@@ -154,61 +154,62 @@ def main():
install_signal_handlers()
- dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
- dbus.mainloop.glib.threads_init()
+ with utils.LockFile(cfg.LOCK_FILE):
+ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+ dbus.mainloop.glib.threads_init()
- cmdhandler.set_execution(cfg.args.use_lvm_shell)
+ cmdhandler.set_execution(cfg.args.use_lvm_shell)
- if use_session:
- cfg.bus = dbus.SessionBus()
- else:
- cfg.bus = dbus.SystemBus()
- # The base name variable needs to exist for things to work.
- # noinspection PyUnusedLocal
- base_name = dbus.service.BusName(BUS_NAME, cfg.bus)
- cfg.om = Lvm(BASE_OBJ_PATH)
- cfg.om.register_object(Manager(MANAGER_OBJ_PATH))
-
- cfg.db = lvmdb.DataStore(vdo_support=cfg.vdo_support)
-
- # Using a thread to process requests, we cannot hang the dbus library
- # thread that is handling the dbus interface
- thread_list.append(
- threading.Thread(target=process_request, name='process_request'))
-
- # Have a single thread handling updating lvm and the dbus model so we
- # don't have multiple threads doing this as the same time
- updater = StateUpdate()
- thread_list.append(updater.thread)
-
- cfg.load = updater.load
-
- cfg.loop = GLib.MainLoop()
-
- for thread in thread_list:
- thread.damon = True
- thread.start()
-
- # 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')
-
- try:
- if cfg.run.value != 0:
- cfg.loop.run()
- udevwatch.remove()
-
- for thread in thread_list:
- thread.join()
- except KeyboardInterrupt:
- # If we are unable to register signal handler, we will end up here when
- # the service gets a ^C or a kill -2 <parent pid>
- utils.handler(signal.SIGINT)
+ if use_session:
+ cfg.bus = dbus.SessionBus()
+ else:
+ cfg.bus = dbus.SystemBus()
+ # The base name variable needs to exist for things to work.
+ # noinspection PyUnusedLocal
+ base_name = dbus.service.BusName(BUS_NAME, cfg.bus)
+ cfg.om = Lvm(BASE_OBJ_PATH)
+ cfg.om.register_object(Manager(MANAGER_OBJ_PATH))
+
+ cfg.db = lvmdb.DataStore(vdo_support=cfg.vdo_support)
+
+ # Using a thread to process requests, we cannot hang the dbus library
+ # thread that is handling the dbus interface
+ thread_list.append(
+ threading.Thread(target=process_request, name='process_request'))
+
+ # Have a single thread handling updating lvm and the dbus model so we
+ # don't have multiple threads doing this as the same time
+ updater = StateUpdate()
+ thread_list.append(updater.thread)
+
+ cfg.load = updater.load
+
+ cfg.loop = GLib.MainLoop()
+
+ for thread in thread_list:
+ thread.damon = True
+ thread.start()
+
+ # 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')
+
+ try:
+ if cfg.run.value != 0:
+ cfg.loop.run()
+ udevwatch.remove()
+
+ for thread in thread_list:
+ thread.join()
+ except KeyboardInterrupt:
+ # If we are unable to register signal handler, we will end up here when
+ # the service gets a ^C or a kill -2 <parent pid>
+ utils.handler(signal.SIGINT)
return 0
diff --git a/daemons/lvmdbusd/utils.py b/daemons/lvmdbusd/utils.py
index f5bca1b46..d24a34935 100644
--- a/daemons/lvmdbusd/utils.py
+++ b/daemons/lvmdbusd/utils.py
@@ -11,10 +11,12 @@ import xml.etree.ElementTree as Et
import sys
import inspect
import ctypes
+import errno
+import fcntl
import os
+import stat
import string
import datetime
-from fcntl import fcntl, F_GETFL, F_SETFL
import dbus
from lvmdbusd import cfg
@@ -690,8 +692,8 @@ def mt_remove_dbus_objects(objs):
# Make stream non-blocking
def make_non_block(stream):
- flags = fcntl(stream, F_GETFL)
- fcntl(stream, F_SETFL, flags | os.O_NONBLOCK)
+ flags = fcntl.fcntl(stream, fcntl.F_GETFL)
+ fcntl.fcntl(stream, fcntl.F_SETFL, flags | os.O_NONBLOCK)
def read_decoded(stream):
@@ -699,3 +701,32 @@ def read_decoded(stream):
if tmp:
return tmp.decode("utf-8")
return ''
+
+
+class LockFile(object):
+ """
+ Simple lock file class
+ Based on Pg.1144 "The Linux Programming Interface" by Michael Kerrisk
+ """
+ def __init__(self, lock_file):
+ self.fd = 0
+ self.lock_file = lock_file
+
+ def __enter__(self):
+ try:
+ self.fd = os.open(self.lock_file, os.O_CREAT | os.O_RDWR, stat.S_IRUSR | stat.S_IWUSR)
+
+ # Get and set the close on exec and lock the file
+ flags = fcntl.fcntl(self.fd, fcntl.F_GETFD)
+ flags |= fcntl.FD_CLOEXEC
+ fcntl.fcntl(self.fd, fcntl.F_SETFL, flags)
+ fcntl.lockf(self.fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
+ except OSError as e:
+ if e.errno == errno.EAGAIN:
+ log_error("Daemon already running, exiting!")
+ else:
+ log_error("Error during creation of lock file(%s): errno(%d), exiting!" % (self.lock_file, e.errno))
+ sys.exit(114)
+
+ def __exit__(self, _type, _value, _traceback):
+ os.close(self.fd)
8 months, 1 week
main - lvmdbusd: Move arg. setup/checking to function
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=1a4384979cdf889bd63...
Commit: 1a4384979cdf889bd63a932d83933079c53490ae
Parent: 3eb19c4b7ae0b0b862a9cf92760922e4a524600a
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Mon Aug 8 20:44:32 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Fri Sep 16 10:49:36 2022 -0500
lvmdbusd: Move arg. setup/checking to function
---
daemons/lvmdbusd/main.py | 37 ++++++++++++++++++++++---------------
daemons/lvmdbusd/utils.py | 4 ++++
2 files changed, 26 insertions(+), 15 deletions(-)
diff --git a/daemons/lvmdbusd/main.py b/daemons/lvmdbusd/main.py
index 50b8e568f..1e883c901 100644
--- a/daemons/lvmdbusd/main.py
+++ b/daemons/lvmdbusd/main.py
@@ -25,7 +25,7 @@ from .manager import Manager
import traceback
import queue
from . import udevwatch
-from .utils import log_debug, log_error
+from .utils import log_debug, log_error, log_msg
import argparse
import os
import sys
@@ -81,9 +81,7 @@ def install_signal_handlers():
log_error("GLib.unix_signal_[add|add_full] are NOT available!")
-def main():
- start = time.time()
- # Add simple command line handling
+def process_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--udev", action='store_true',
@@ -110,14 +108,9 @@ def main():
type=check_bb_size,
dest='bb_size')
- use_session = os.getenv('LVMDBUSD_USE_SESSION', False)
-
- # Ensure that we get consistent output for parsing stdout/stderr
- os.environ["LC_ALL"] = "C"
-
- cfg.args = parser.parse_args()
+ args = parser.parse_args()
- if not cfg.args.use_json:
+ if not args.use_json:
log_error("Daemon no longer supports lvm without JSON support, exiting!")
sys.exit(1)
else:
@@ -125,6 +118,24 @@ def main():
log_error("Un-supported version of LVM, daemon requires JSON output, exiting!")
sys.exit(1)
+ # Add udev watching
+ if args.use_udev:
+ # Make sure this msg ends up in the journal, so we know
+ log_msg('Utilizing udev to trigger updates')
+
+ return args
+
+
+def main():
+ start = time.time()
+ use_session = os.getenv('LVMDBUSD_USE_SESSION', False)
+
+ # Ensure that we get consistent output for parsing stdout/stderr
+ os.environ["LC_ALL"] = "C"
+
+ # Add simple command line handling
+ cfg.args = process_args()
+
cfg.create_request_entry = RequestEntry
# We create a flight recorder in cmdhandler too, but we replace it here
@@ -178,10 +189,6 @@ def main():
thread.damon = True
thread.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
diff --git a/daemons/lvmdbusd/utils.py b/daemons/lvmdbusd/utils.py
index cc221fc2d..f5bca1b46 100644
--- a/daemons/lvmdbusd/utils.py
+++ b/daemons/lvmdbusd/utils.py
@@ -313,6 +313,10 @@ def log_error(msg, *attributes):
_common_log(msg, *attributes)
+def log_msg(msg, *attributes):
+ _common_log(msg, *attributes)
+
+
def dump_threads_stackframe():
ident_to_name = {}
8 months, 1 week
main - lvmdbusd: Remove addl. checks on --nojson
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=3eb19c4b7ae0b0b862a...
Commit: 3eb19c4b7ae0b0b862a9cf92760922e4a524600a
Parent: 4b4d431631ec8df90d6d5793fbfc26c6999e154c
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Mon Aug 8 16:08:23 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Fri Sep 16 10:49:36 2022 -0500
lvmdbusd: Remove addl. checks on --nojson
We check earlier that if you specify --nojson we will exit.
---
daemons/lvmdbusd/main.py | 8 --------
1 file changed, 8 deletions(-)
diff --git a/daemons/lvmdbusd/main.py b/daemons/lvmdbusd/main.py
index 597441a9e..50b8e568f 100644
--- a/daemons/lvmdbusd/main.py
+++ b/daemons/lvmdbusd/main.py
@@ -132,20 +132,12 @@ def main():
# cmdhandler is for when we are running other code with a different main.
cfg.blackbox = LvmFlightRecorder(cfg.args.bb_size)
- if cfg.args.use_lvm_shell and not cfg.args.use_json:
- log_error("You cannot specify --lvmshell and --nojson")
- sys.exit(1)
-
log_debug("Using lvm binary: %s" % cfg.LVM_CMD)
# We will dynamically add interfaces which support vdo if it
# exists.
cfg.vdo_support = supports_vdo()
- if cfg.vdo_support and not cfg.args.use_json:
- log_error("You cannot specify --nojson when lvm has VDO support")
- sys.exit(1)
-
# List of threads that we start up
thread_list = []
8 months, 1 week
main - lvmdbustest: Include major number 259
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=4b4d431631ec8df90d6...
Commit: 4b4d431631ec8df90d6d5793fbfc26c6999e154c
Parent: 9ffa1ef884f51d08fc6f2b39287a8d566eeed7df
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Mon Aug 8 10:03:52 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Fri Sep 16 10:49:36 2022 -0500
lvmdbustest: Include major number 259
When you have > 16 partitions for a block device the major number
changes, include them for testing.
---
test/dbus/lvmdbustest.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/test/dbus/lvmdbustest.py b/test/dbus/lvmdbustest.py
index aadd036b0..02d4d35d7 100755
--- a/test/dbus/lvmdbustest.py
+++ b/test/dbus/lvmdbustest.py
@@ -1414,7 +1414,10 @@ class TestDbusService(unittest.TestCase):
@staticmethod
def _get_devices():
context = pyudev.Context()
- return context.list_devices(subsystem='block', MAJOR='8')
+ bd = context.list_devices(subsystem='block')
+ # Handle block extended major too (259)
+ return [b for b in bd if b.properties.get('MAJOR') == '8' or
+ b.properties.get('MAJOR') == '259']
def _pv_scan(self, activate, cache, device_paths, major_minors):
mgr = self._manager().Manager
8 months, 1 week
main - lvmdbustest: Use updated pyudev syntax
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=9ffa1ef884f51d08fc6...
Commit: 9ffa1ef884f51d08fc6f2b39287a8d566eeed7df
Parent: 0887896847807e159a70edc5ac92a4030c13923a
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Mon Aug 8 10:02:37 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Fri Sep 16 10:49:36 2022 -0500
lvmdbustest: Use updated pyudev syntax
Previous syntax has been deprecated.
---
test/dbus/lvmdbustest.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/test/dbus/lvmdbustest.py b/test/dbus/lvmdbustest.py
index e6f6d4891..aadd036b0 100755
--- a/test/dbus/lvmdbustest.py
+++ b/test/dbus/lvmdbustest.py
@@ -1430,7 +1430,7 @@ class TestDbusService(unittest.TestCase):
def test_pv_scan(self):
def major_minor(d):
- return (int(d.properties['MAJOR']), int(d.properties['MINOR']))
+ return (int(d.properties.get('MAJOR')), int(d.properties.get('MINOR')))
devices = TestDbusService._get_devices()
@@ -1439,7 +1439,7 @@ class TestDbusService(unittest.TestCase):
self.assertEqual(self._pv_scan(False, False, [], []), '/')
self._check_consistency()
- block_path = [d.properties['DEVNAME'] for d in devices]
+ block_path = [d.properties.get('DEVNAME') for d in devices]
self.assertEqual(self._pv_scan(False, True, block_path, []), '/')
self._check_consistency()
8 months, 1 week