Skip to contentSkip to conversation

main - lvmdbusd: Instruct lvm to output debug to file for fullreport

PATCH Tony Asleson 1 participant 1 message Sep 19, 2022

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=85fcbfd9d7697d3954c4f13a791f127205e260ee
Commit:        85fcbfd9d7697d3954c4f13a791f127205e260ee
Parent:        d42bdb07def72d68c05241823979b28952978c05
Author:        Tony Asleson <[email protected]>
AuthorDate:    Wed Aug 31 15:04:59 2022 -0500
Committer:     Tony Asleson <[email protected]>
CommitterDate: Fri Sep 16 10:49:37 2022 -0500

lvmdbusd: Instruct lvm to output debug to file for fullreport

Historically we have seen a few different errors which occur when we call fullreport. Failing exit code and JSON which is missing one or more keys. Instruct lvm to dump the debug to a file during fullreport calls when we fork & exec lvm. If we encounter an error, ouput the debug data. The reason this isn't being done when lvmshell is used is because we don't have an easy way to test the error paths.

This change is complicated by the following:

1. We don't know if fullreport was good until we evaluate all the JSON. This is done a bit after we have called into lvm and returned.
2. We don't want to orphan the debug file used by lvm if the daemon is killed. Thus we try to minimize the window where the debug file hasn't already been unlinked. A RFE to pass an open FD to lvm for this purpose is outstanding.

The temp. file is:
-rw------. 1 root root /tmp/lvmdbusd.lvm.debug.XXXXXXXX.log

---
 daemons/lvmdbusd/cfg.py        |  4 +++
 daemons/lvmdbusd/cmdhandler.py |  9 ++++-
 daemons/lvmdbusd/fetch.py      |  6 ++++
 daemons/lvmdbusd/main.py       |  4 +++
 daemons/lvmdbusd/utils.py      | 78 +++++++++++++++++++++++++++++++++++-------
 5 files changed, 87 insertions(+), 14 deletions(-)
daemons/lvmdbusd/cfg.py +4 -0
index a758b8a77..5b342bc20 100644
@@ -109,3 +109,7 @@ def exit_daemon():
     if run and loop:
         run.value = 0
         loop.quit()
+
+
+# Debug data for lvm
+lvmdebug = None
daemons/lvmdbusd/cmdhandler.py +8 -1
index 7a349e87e..102844739 100644
@@ -17,7 +17,7 @@ import os
 
 from lvmdbusd import cfg
 from lvmdbusd.utils import pv_dest_ranges, log_debug, log_error, add_no_notify,\
-			make_non_block, read_decoded, extract_stack_trace, LvmBug
+			make_non_block, read_decoded, extract_stack_trace, LvmBug, add_config_option
 from lvmdbusd.lvm_shell_proxy import LVMShellProxy
 
 try:
@@ -121,6 +121,12 @@ def call_lvm(command, debug=False, line_cb=None,
 	command.insert(0, cfg.LVM_CMD)
 	command = add_no_notify(command)
 
+	# If we are running the fullreport command, we will ask lvm to output the debug
+	# data, so we can have the required information for lvm to debug the fullreport failures.
+	if "fullreport" in command:
+		fn = cfg.lvmdebug.setup()
+		add_config_option(command, "--config", "log {level=7 file=%s syslog=0}" % fn)
+
 	process = Popen(command, stdout=PIPE, stderr=PIPE, close_fds=True,
 					env=os.environ)
 
@@ -163,6 +169,7 @@ def call_lvm(command, debug=False, line_cb=None,
 			break
 
 	if process.returncode is not None:
+		cfg.lvmdebug.lvm_complete()
 		if debug or (process.returncode != 0 and (process.returncode != 5 and "fullreport" in command)):
 			_debug_c(command, process.returncode, (stdout_text, stderr_text))
 
daemons/lvmdbusd/fetch.py +6 -0
index dc527be36..199b86073 100644
@@ -171,6 +171,7 @@ class StateUpdate(object):
 				cfg.exit_daemon()
 			else:
 				# Slow things down when encountering errors
+				cfg.lvmdebug.complete()
 				time.sleep(1)
 
 		while cfg.run.value != 0:
@@ -205,11 +206,16 @@ class StateUpdate(object):
 			except SystemExit:
 				break
 			except LvmBug as bug:
+				# If a lvm bug occurred, we will dump the lvm debug data if
+				# we have it.
+				cfg.lvmdebug.dump()
 				log_error(str(bug))
 				_handle_error()
 			except Exception as e:
 				log_error("update_thread: \n%s" % extract_stack_trace(e))
 				_handle_error()
+			finally:
+				cfg.lvmdebug.complete()
 
 		# Make sure to unblock any that may be waiting before we exit this thread
 		# otherwise they hang forever ...
daemons/lvmdbusd/main.py +4 -0
index a426a535d..ab66efcc9 100644
@@ -138,6 +138,10 @@ def main():
 	os.environ["LC_ALL"] = "C"
 	os.environ["LVM_COMMAND_PROFILE"] = "lvmdbusd"
 
+	# Save off the debug data needed for lvm team to debug issues
+	# only used for 'fullreport' at this time.
+	cfg.lvmdebug = utils.LvmDebugData()
+
 	# Add simple command line handling
 	cfg.args = process_args()
 
daemons/lvmdbusd/utils.py +65 -13

100 lines not on this page · raw message