1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00
Commit Graph

1763 Commits

Author SHA1 Message Date
Tony Asleson
36a8fb20bf lvmdbusd: Correct lvm shell signal & child process handling
Previously when the __del__ method ran on LVMShellProxy we would blindly
call terminate().  This was a race condition as the underlying process
may/maynot be present.  When the process is still present the SIGTERM will
end up being seen by lvmdbusd too.  Re-work the code so that we
first try to wait for the child process to exit and only then if it hasn't
exited will we send it a SIGTERM.  We also ensure that when this is
executed we will briefly ignore a SIGTERM that arrives for the daemon.
2022-09-22 08:33:06 -05:00
Tony Asleson
9c2ed74221 lvmdbusd: Register for SIGTERM
Ensure we log that we are exiting on this signal too.
2022-09-20 16:37:01 -05:00
Tony Asleson
d88998f516 lvmdbusd: Correct get_object_path_by_uuid_lvm_id
When checking to see if the PV is missing we incorrectly checked that the
path_create was equal to PV creation.  However, there are cases where we
are doing a lookup where the path_create == None.  In this case, we would
fail to set lvm_id == None which caused a problem as we had more than 1
PV that was missing.  When this occurred, the second lookup matched the
first missing PV that was added to the object manager.  This resulted in
the following:

Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/lvmdbusd/utils.py", line 667, in _run
    self.rc = self.f(*self.args)
  File "/usr/lib/python3.9/site-packages/lvmdbusd/fetch.py", line 25, in _main_thread_load
    (changes, remove) = load_pvs(
  File "/usr/lib/python3.9/site-packages/lvmdbusd/pv.py", line 46, in load_pvs
    return common(
  File "/usr/lib/python3.9/site-packages/lvmdbusd/loader.py", line 55, in common
    del existing_paths[dbus_object.dbus_object_path()]

Because we expect to find the object in existing_paths if we found it in
the lookup.

resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2085078
2022-09-20 16:36:53 -05:00
Tony Asleson
8686657664 lvmdbusd: Remove --reportformat
Latest upstream build of lvm results in the following error when
trying to use lvmshell.

"Argument --reportformat cannot be used in interactive mode.,
Error during parsing of command line."
2022-09-16 10:49:37 -05:00
Tony Asleson
11c033c222 lvmdbusd: Include lvm debug output for lvmshell
Move the option to add the debug file into lvm_full_report_json so that
we collect the debug data when we fork & exec lvm and when we use lvm
shell.
2022-09-16 10:49:37 -05:00
Tony Asleson
a4b7f988d8 lvmdbusd: Call readlines instead of readline
Better to drain everything we have now that our IO is line orientated
when using a ptty.
2022-09-16 10:49:37 -05:00
Tony Asleson
8e1e40c499 lvmdbusd: Raise IOError instead of ignoring
We end up in a bad state if we simply eat IOErrors here.  Exit the lvmshell
process and raise the IOError.
2022-09-16 10:49:37 -05:00
Tony Asleson
2c5762038a lvmdbusd: Correct log_error for shell proxy 2022-09-16 10:49:37 -05:00
Tony Asleson
d51fb57f1a lvmdbusd: Check for KeyError in refresh
Bubble up a LvmBug if we get a KeyError on a lvm column name.
2022-09-16 10:49:37 -05:00
Tony Asleson
feaf46863b lvmdbusd: Use common func. for checking missing LV keys 2022-09-16 10:49:37 -05:00
Tony Asleson
ed9072dad8 lvmdbusd: Correct undefined var 2022-09-16 10:49:37 -05:00
Tony Asleson
9fc24b1d3b lvmdbusd: Handle 'exit' for lvm_shell_proxy
Useful for testing `exit_shell` when running interactively.
2022-09-16 10:49:37 -05:00
Tony Asleson
b3d13c50d7 lvmdbusd: Use pseudo tty to get "lvm>" prompt again
When lvm is compiled with editline, if the file descriptors don't look like
a tty, then no "lvm> " prompt is done.  Having lvm output the shell prompt
when consuming JSON on a report file descriptor is very useful in
determining if lvm command is complete.
2022-09-16 10:49:37 -05:00
Tony Asleson
664a06650d lvmdbusd: Remove PID from log messages
Previously the daemon would output PID:TID.  If it's running under systemd
it skips outputting PID as systemd already does this.
2022-09-16 10:49:37 -05:00
Tony Asleson
e977b70bfb lvmdbusd: Remove duplicate code
The logic for _cache_lv and _writecache_lv was identical except for which
underlying lvm command to run.  Factor out common.
2022-09-16 10:49:37 -05:00
Tony Asleson
f4c03faa65 lvmdbusd: Raise LvmBug exception for invalid JSON
This will cause lvm debug data to get logged if it's available.
2022-09-16 10:49:37 -05:00
Tony Asleson
85fcbfd9d7 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
2022-09-16 10:49:37 -05:00
Tony Asleson
d42bdb07de lvmdbusd: Re-work error handling
Introduce an exception which is used for known existing issues with lvm.
This is used to distinguish between errors between lvm itself and lvmdbusd.
In the case of lvm bugs, when we simply retry the operation we will log
very little.  Otherwise, we will dump a full traceback for investigation
when we do the retry.
2022-09-16 10:49:37 -05:00
Tony Asleson
cb32b0a87f lvmdbusd: Use common function for traceback
We were using a number of different ways to achieve the same result.  Use
a common function to make this consistent.
2022-09-16 10:49:37 -05:00
Tony Asleson
22942f4916 lvmdbusd: Don't output debug for fullreport exit code 5
This is expected with an exported vg
2022-09-16 10:49:37 -05:00
Tony Asleson
e5c41b94b8 lvmdbusd: refactor and correct fetch thread logic
Simplify the fetch thread and correct the logic used for selecting the
options which are used when we batch update a state refresh.
2022-09-16 10:49:37 -05:00
Tony Asleson
25abe41b00 lvmdbusd: Re-work error handling for run_cmd
Instead of lumping all the exceptions, break them out to handle the dbus
exceptions separately, to reduce the amount of debug information that ends
up in the journal that has questionable value.
2022-09-16 10:49:37 -05:00
Tony Asleson
e6e874922e lvmdbusd: Handle SIGINT quietly
Change how we exit on SIGINT so that we don't output needless debug.
2022-09-16 10:49:37 -05:00
Tony Asleson
0296e56073 lvmdbusd: Don't report recoverable error
Lvm occasionally fails to return all the request JSON keys in the output of
"fullreport".  This happens very rarely.  When it does the daemon was reporting
the resulting informational exception:

MThreadRunner: exception
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/lvmdbusd/utils.py", line 667, in _run
    self.rc = self.f(*self.args)
  File "/usr/lib/python3.9/site-packages/lvmdbusd/fetch.py", line 40, in _main_thread_load
    (lv_changes, remove) = load_lvs(
  File "/usr/lib/python3.9/site-packages/lvmdbusd/lv.py", line 143, in load_lvs
    return common(
  File "/usr/lib/python3.9/site-packages/lvmdbusd/loader.py", line 37, in common
    objects = retrieve(search_keys, cache_refresh=False)
  File "/usr/lib/python3.9/site-packages/lvmdbusd/lv.py", line 95, in lvs_state_retrieve
    l['vdo_operating_mode'],
KeyError: 'vdo_operating_mode'

The daemon retries the operation, which usually works and the daemon continues.
However, simply reporting this informational stack trace is causing CI and other
automated tests to fail as they expect no tracebacks in the log output.

Remove the reporting of this code path unless it persists and causes the daemon
to give up and exit.

Ref: https://bugzilla.redhat.com/show_bug.cgi?id=2120267
2022-09-16 10:49:37 -05:00
Tony Asleson
2918994873 lvmdbusd: WS, imports, grammar 2022-09-16 10:49:37 -05:00
Tony Asleson
b0c7220dbb lvmdbusd: Add debug circular buffer
When the daemon isn't started with --debug we will keep a circular
buffer of the past N number of debug messages which we will output
when we encounter an issue.
2022-09-16 10:49:37 -05:00
Tony Asleson
a5e6947d74 lvmdbusd: Set LVM_COMMAND_PROFILE=lvmdbusd
We need this to prevent lvm from interleaving the JSON output with errors
written to stderr.
2022-09-16 10:49:37 -05:00
Tony Asleson
ec50979b03 lvmdbusd: Correct typos 2022-09-16 10:49:37 -05:00
Tony Asleson
3d8882db83 lvmdbusd: fix hangs on SIGINT
Rather than trying to bubble up return codes that get us to exit cleanly
it's better to just raise an exception to bail.  In some cases functions
don't have return codes, so they cannot be checked.
2022-09-16 10:49:37 -05:00
Tony Asleson
60e4ba36e0 lvmdbusd: Remove unused locking functionality
I don't think we have ever utilized this, remove.
2022-09-16 10:49:37 -05:00
Tony Asleson
cfc87157a4 lvmdbusd: Make sure to set cfg.got_external_event
We were incorrectly only setting this if --udev wasn't present on the
command line.  In all cases when we see a manager.ExternalEvent we want
to set this.
2022-09-16 10:49:37 -05:00
Tony Asleson
068073e924 lvmdbusd: Correct typos 2022-09-16 10:49:36 -05:00
Tony Asleson
abf22df46c lvmdbusd: Handle no lastlog
Depending on when an occurs, it maynot have any information available for
lastlog.  In this case try to grab an error message from the original
response.
2022-09-16 10:49:36 -05:00
Tony Asleson
6b9cc7432e lvmdbusd: Remove exclusionary language 2022-09-16 10:49:36 -05:00
Tony Asleson
c13efb2ffc lvmdbusd: Remove unneeded command line args 2022-09-16 10:49:36 -05:00
Tony Asleson
b3d8366ff2 lvmdbusd: Add SIGUSR2 to dump flight recorder 2022-09-16 10:49:36 -05:00
Tony Asleson
05f7fa5a85 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.
2022-09-16 10:49:36 -05:00
Tony Asleson
3fdf449348 lvmdbusd: Add lockfile
The daemon cannot handle multiple copies of itself running at the
same time, ensure this cannot happen.
2022-09-16 10:49:36 -05:00
Tony Asleson
1a4384979c lvmdbusd: Move arg. setup/checking to function 2022-09-16 10:49:36 -05:00
Tony Asleson
3eb19c4b7a lvmdbusd: Remove addl. checks on --nojson
We check earlier that if you specify --nojson we will exit.
2022-09-16 10:49:36 -05:00
Tony Asleson
01ef2f2525 lvmdbusd: Remove try/except for mkfifo
We should never run into this error condition when using tempfile.mkdtemp.
2022-06-30 10:55:16 -05:00
Tony Asleson
0d957dcacc lvmdusd: Remove non lvm JSON output support 2022-06-30 10:55:16 -05:00
Tony Asleson
d393436727 lvmdbusd: Correct grammar in lvm shell proxy comments 2022-06-30 10:55:16 -05:00
Tony Asleson
6914942685 lvmdbusd: Don't require "lvm> " prompt for shell
Depending on how lvm is compiled, it may not present the "lvm> " prompt
when using the lvm shell.  Don't require it to be present.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2090391
2022-06-30 10:55:16 -05:00
Tony Asleson
eee89a941e lvmdbusd: Job prop. Get/GetAll exec. immediately
This allows API user the ability to check on the status of a long running
job without blocking in the request queue.
2022-06-30 10:55:16 -05:00
Tony Asleson
7a2090655d lvmdbusd: Remove the use of sub shell for lvm shell
This reduces the number of processes and improves security.
2022-06-30 10:55:16 -05:00
Tony Asleson
51d9b686c0 lvmdbusd: Add debug output for which lvm binary is used 2022-06-30 10:55:16 -05:00
Tony Asleson
b3407b16c1 lvmdbusd: re-work lvm shell main
Add an optional single argument "bisect" to use with git bisect for
automation.  Normal case is no arguments when running stand-alone.
2022-06-30 10:55:16 -05:00
Tony Asleson
58c6c9e9aa lvmdbusd: Simplify child process env
We don't need to duplicate the entire env from the parent, supply only what
is needed.
2022-06-30 10:55:16 -05:00
Tony Asleson
37733cd4eb lvmdbusd: Correct conditional for lvm child process running
Poll returns None when process is running, else exit value.  If poll returns
0 we will fail to exit the select loop.
2022-06-30 10:55:16 -05:00