From 48dfb805f0027698484c576e5d833de52f728791 Mon Sep 17 00:00:00 2001 From: eabdullin Date: Tue, 11 Mar 2025 08:31:57 +0000 Subject: [PATCH] import UBI lvm2-2.03.14-15.el8_10 --- ...ventd-move-var-set-to-locked-section.patch | 31 +++ SOURCES/0132-dmeventd-use-return.patch | 50 +++++ ...td-unregister-all-devices-on-restart.patch | 117 +++++++++++ .../0134-dmeventd-info-status-report.patch | 149 +++++++++++++ ...re.ac-add-with-dmeventd-exit-on-path.patch | 68 ++++++ SOURCES/0136-configure-autoreconf.patch | 111 ++++++++++ ...meventd-implement-exit_on-file-check.patch | 196 ++++++++++++++++++ SOURCES/0138-debug-correct-level.patch | 118 +++++++++++ SOURCES/0139-tests-check-exit_on-works.patch | 54 +++++ SPECS/lvm2.spec | 16 +- 10 files changed, 909 insertions(+), 1 deletion(-) create mode 100644 SOURCES/0131-dmeventd-move-var-set-to-locked-section.patch create mode 100644 SOURCES/0132-dmeventd-use-return.patch create mode 100644 SOURCES/0133-dmeventd-unregister-all-devices-on-restart.patch create mode 100644 SOURCES/0134-dmeventd-info-status-report.patch create mode 100644 SOURCES/0135-configure.ac-add-with-dmeventd-exit-on-path.patch create mode 100644 SOURCES/0136-configure-autoreconf.patch create mode 100644 SOURCES/0137-dmeventd-implement-exit_on-file-check.patch create mode 100644 SOURCES/0138-debug-correct-level.patch create mode 100644 SOURCES/0139-tests-check-exit_on-works.patch diff --git a/SOURCES/0131-dmeventd-move-var-set-to-locked-section.patch b/SOURCES/0131-dmeventd-move-var-set-to-locked-section.patch new file mode 100644 index 0000000..a52bb41 --- /dev/null +++ b/SOURCES/0131-dmeventd-move-var-set-to-locked-section.patch @@ -0,0 +1,31 @@ +From 068897bbd15e16b666079952f465239d933d2228 Mon Sep 17 00:00:00 2001 +From: Zdenek Kabelac +Date: Thu, 31 Aug 2023 18:45:30 +0200 +Subject: [PATCH 131/139] dmeventd: move var set to locked section + +It should not change the actual code flow, however make the +set of the current_event variable inside locked section. + +(cherry picked from commit 29630b2d7fcb28827f0c928edd6cd638f6ea2591) +--- + daemons/dmeventd/dmeventd.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c +index d89ab4af8..fa60b6f31 100644 +--- a/daemons/dmeventd/dmeventd.c ++++ b/daemons/dmeventd/dmeventd.c +@@ -1043,9 +1043,9 @@ static void *_monitor_thread(void *arg) + _unlock_mutex(); + + _do_process_event(thread); +- thread->current_events = 0; /* Current events processed */ + + _lock_mutex(); ++ thread->current_events = 0; /* Current events processed */ + thread->processing = 0; + + /* +-- +2.48.1 + diff --git a/SOURCES/0132-dmeventd-use-return.patch b/SOURCES/0132-dmeventd-use-return.patch new file mode 100644 index 0000000..80fa1f3 --- /dev/null +++ b/SOURCES/0132-dmeventd-use-return.patch @@ -0,0 +1,50 @@ +From d7f61ce3933f75f3ebcd74c2a815cdcea28ea8d5 Mon Sep 17 00:00:00 2001 +From: Zdenek Kabelac +Date: Mon, 25 Sep 2023 11:51:25 +0200 +Subject: [PATCH 132/139] dmeventd: use return + +Use 'return' instead of calling exit() when possible. + +(cherry picked from commit c31dcf3632988ef4e8d1c62a685f4c436b5f115e) +--- + daemons/dmeventd/dmeventd.c | 10 +++++----- + 1 file changed, 5 insertions(+), 5 deletions(-) + +diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c +index fa60b6f31..9d7118ced 100644 +--- a/daemons/dmeventd/dmeventd.c ++++ b/daemons/dmeventd/dmeventd.c +@@ -2169,17 +2169,17 @@ int main(int argc, char *argv[]) + .server_path = DM_EVENT_FIFO_SERVER + }; + time_t now, idle_exit_timeout = DMEVENTD_IDLE_EXIT_TIMEOUT; +- opterr = 0; +- optind = 0; + ++ optopt = optind = opterr = 0; ++ optarg = (char*) ""; + while ((opt = getopt(argc, argv, "?fhVdlR")) != EOF) { + switch (opt) { + case 'h': + _usage(argv[0], stdout); +- exit(EXIT_SUCCESS); ++ return EXIT_SUCCESS; + case '?': + _usage(argv[0], stderr); +- exit(EXIT_SUCCESS); ++ return EXIT_SUCCESS; + case 'R': + _restart++; + break; +@@ -2194,7 +2194,7 @@ int main(int argc, char *argv[]) + break; + case 'V': + printf("dmeventd version: %s\n", DM_LIB_VERSION); +- exit(EXIT_SUCCESS); ++ return EXIT_SUCCESS; + } + } + +-- +2.48.1 + diff --git a/SOURCES/0133-dmeventd-unregister-all-devices-on-restart.patch b/SOURCES/0133-dmeventd-unregister-all-devices-on-restart.patch new file mode 100644 index 0000000..ff3f9db --- /dev/null +++ b/SOURCES/0133-dmeventd-unregister-all-devices-on-restart.patch @@ -0,0 +1,117 @@ +From bc94a75dc4705023d7e074363867129563b0d469 Mon Sep 17 00:00:00 2001 +From: Zdenek Kabelac +Date: Mon, 25 Sep 2023 11:42:53 +0200 +Subject: [PATCH 133/139] dmeventd: unregister all devices on restart + +Instead of just exiting in the middle of monitoring, +unregisted all monitored devices first and then exit. + +To speedup this path, all send internal SIGINT when thread +unregiters itself, to wakup-up main sleeping loop. + +(cherry picked from commit 637d812df56440d792ab403f63e50583d78cdfef) +--- + daemons/dmeventd/dmeventd.c | 55 ++++++++++++++++++++++++++++--------- + 1 file changed, 42 insertions(+), 13 deletions(-) + +diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c +index 9d7118ced..e05545403 100644 +--- a/daemons/dmeventd/dmeventd.c ++++ b/daemons/dmeventd/dmeventd.c +@@ -997,6 +997,8 @@ static void _monitor_unregister(void *arg) + _lock_mutex(); + thread->status = DM_THREAD_DONE; /* Last access to thread memory! */ + _unlock_mutex(); ++ if (_exit_now) /* Exit is already in-progress, wake-up sleeping select() */ ++ kill(getpid(), SIGINT); + } + + /* Device monitoring thread. */ +@@ -1161,6 +1163,36 @@ static int _unregister_for_event(struct message_data *message_data) + return ret; + } + ++static void _unregister_all_threads(void) ++{ ++ struct thread_status *thread, *tmp; ++ ++ _lock_mutex(); ++ ++ dm_list_iterate_items_safe(thread, tmp, &_thread_registry) ++ _update_events(thread, 0); ++ ++ _unlock_mutex(); ++} ++ ++static void _wait_for_new_pid(void) ++{ ++ unsigned long st_ino = 0; ++ struct stat st; ++ int i; ++ ++ for (i = 0; i < 400000; ++i) { ++ if (lstat(DMEVENTD_PIDFILE, &st) == 0) { ++ if (!st_ino) ++ st_ino = st.st_ino; ++ else if (st_ino != st.st_ino) ++ break; /* different pidfile */ ++ } else if (errno == ENOENT) ++ break; /* pidfile is removed */ ++ usleep(100); ++ } ++} ++ + /* + * Register for an event. + * +@@ -1677,9 +1709,9 @@ static void _process_request(struct dm_event_fifos *fifos) + free(msg.data); + + if (cmd == DM_EVENT_CMD_DIE) { +- if (unlink(DMEVENTD_PIDFILE)) +- log_sys_error("unlink", DMEVENTD_PIDFILE); +- _exit(0); ++ _unregister_all_threads(); ++ _exit_now = DM_SCHEDULED_EXIT; ++ log_info("dmeventd exiting for restart."); + } + } + +@@ -1769,7 +1801,8 @@ static void _init_thread_signals(void) + */ + static void _exit_handler(int sig __attribute__((unused))) + { +- _exit_now = DM_SIGNALED_EXIT; ++ if (!_exit_now) ++ _exit_now = DM_SIGNALED_EXIT; + } + + #ifdef __linux__ +@@ -2116,19 +2149,15 @@ static void _restart_dmeventd(void) + ((e = getenv(SD_ACTIVATION_ENV_VAR_NAME)) && strcmp(e, "1"))) + _systemd_activation = 1; + +- for (i = 0; i < 10; ++i) { +- if ((access(DMEVENTD_PIDFILE, F_OK) == -1) && (errno == ENOENT)) +- break; +- usleep(10); +- } ++ fini_fifos(&fifos); + +- if (!_systemd_activation) { +- fini_fifos(&fifos); ++ /* Give a few seconds dmeventd to finish */ ++ _wait_for_new_pid(); ++ ++ if (!_systemd_activation) + return; +- } + + /* Reopen fifos. */ +- fini_fifos(&fifos); + if (!init_fifos(&fifos)) { + fprintf(stderr, "Could not initiate communication with new instance of dmeventd.\n"); + exit(EXIT_FAILURE); +-- +2.48.1 + diff --git a/SOURCES/0134-dmeventd-info-status-report.patch b/SOURCES/0134-dmeventd-info-status-report.patch new file mode 100644 index 0000000..5f9695b --- /dev/null +++ b/SOURCES/0134-dmeventd-info-status-report.patch @@ -0,0 +1,149 @@ +From 7dfa1f3d0d03cc682bb3bb503d2ad44ff4e836a6 Mon Sep 17 00:00:00 2001 +From: Zdenek Kabelac +Date: Mon, 25 Sep 2023 11:49:14 +0200 +Subject: [PATCH 134/139] dmeventd: info status report + +To quickly get info about some internal dmeventd status, +implment 'dmeventd -i' support. + +Reported messages are some 'raw' internal informations mainly +useful to developers. + +(cherry picked from commit 80d34abf4974e45471f947fb2b85146a30feb87d) +--- + daemons/dmeventd/dmeventd.c | 69 +++++++++++++++++++++++++++++++++++-- + man/dmeventd.8_main | 7 ++++ + 2 files changed, 74 insertions(+), 2 deletions(-) + +diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c +index e05545403..46c34ada2 100644 +--- a/daemons/dmeventd/dmeventd.c ++++ b/daemons/dmeventd/dmeventd.c +@@ -2063,6 +2063,68 @@ static int _reinstate_registrations(struct dm_event_fifos *fifos) + return 1; + } + ++static int _info_dmeventd(const char *name, struct dm_event_fifos *fifos) ++{ ++ struct dm_event_daemon_message msg = { 0 }; ++ int i, count = 0; ++ char *line; ++ int version; ++ int ret = 0; ++ ++ /* Get the list of registrations from the running daemon. */ ++ if (!init_fifos(fifos)) { ++ fprintf(stderr, "Could not initiate communication with existing dmeventd.\n"); ++ return 0; ++ } ++ ++ if (!dm_event_get_version(fifos, &version)) { ++ fprintf(stderr, "Could not communicate with existing dmeventd.\n"); ++ goto out; ++ } ++ ++ if (version < 1) { ++ fprintf(stderr, "The running dmeventd instance is too old.\n" ++ "Protocol version %d (required: 1). Action cancelled.\n", version); ++ goto out; ++ } ++ ++ if (daemon_talk(fifos, &msg, DM_EVENT_CMD_GET_STATUS, "-", "-", 0, 0)) { ++ fprintf(stderr, "Failed to acquire status from existing dmeventd.\n"); ++ goto out; ++ } ++ ++ line = strchr(msg.data, ' ') + 1; ++ for (i = 0; msg.data[i]; ++i) ++ if (msg.data[i] == ';') { ++ msg.data[i] = 0; ++ if (!count) ++ printf("%s is monitoring:\n", name); ++ printf("%s\n", line); ++ line = msg.data + i + 1; ++ ++count; ++ } ++ ++ free(msg.data); ++ ++ if (!count) ++ printf("%s does not monitor any device.\n", name); ++ ++ if (version >= 2) { ++ if (daemon_talk(fifos, &msg, DM_EVENT_CMD_GET_PARAMETERS, "-", "-", 0, 0)) { ++ fprintf(stderr, "Failed to acquire parameters from existing dmeventd.\n"); ++ goto out; ++ } ++ printf("%s internal status: %s\n", name, msg.data); ++ free(msg.data); ++ } ++ ++ ret = 1; ++out: ++ fini_fifos(fifos); ++ ++ return ret; ++} ++ + static void _restart_dmeventd(void) + { + struct dm_event_fifos fifos = { +@@ -2178,10 +2240,11 @@ bad: + static void _usage(char *prog, FILE *file) + { + fprintf(file, "Usage:\n" +- "%s [-d [-d [-d]]] [-f] [-h] [-l] [-R] [-V] [-?]\n\n" ++ "%s [-d [-d [-d]]] [-f] [-h] [i] [-l] [-R] [-V] [-?]\n\n" + " -d Log debug messages to syslog (-d, -dd, -ddd)\n" + " -f Don't fork, run in the foreground\n" + " -h Show this help information\n" ++ " -i Query running instance of dmeventd for info\n" + " -l Log to stdout,stderr instead of syslog\n" + " -? Show this help information on stderr\n" + " -R Restart dmeventd\n" +@@ -2201,7 +2264,7 @@ int main(int argc, char *argv[]) + + optopt = optind = opterr = 0; + optarg = (char*) ""; +- while ((opt = getopt(argc, argv, "?fhVdlR")) != EOF) { ++ while ((opt = getopt(argc, argv, "?fhiVdlR")) != EOF) { + switch (opt) { + case 'h': + _usage(argv[0], stdout); +@@ -2209,6 +2272,8 @@ int main(int argc, char *argv[]) + case '?': + _usage(argv[0], stderr); + return EXIT_SUCCESS; ++ case 'i': ++ return _info_dmeventd(argv[0], &fifos) ? EXIT_SUCCESS : EXIT_FAILURE; + case 'R': + _restart++; + break; +diff --git a/man/dmeventd.8_main b/man/dmeventd.8_main +index 77b07e4d8..75926bae5 100644 +--- a/man/dmeventd.8_main ++++ b/man/dmeventd.8_main +@@ -12,6 +12,7 @@ dmeventd \(em Device-mapper event daemon + .RB [ -d ]]] + .RB [ -f ] + .RB [ -h ] ++.RB [ -i ] + .RB [ -l ] + .RB [ -R ] + .RB [ -V ] +@@ -44,6 +45,12 @@ Don't fork, run in the foreground. + Show help information. + . + .TP ++.B -i ++Query the running daemon instance for the status informations. The format is ++internal and unstable and it is targeted for developers. ++Format may change between versions. ++. ++.TP + .B -l + Log through stdout and stderr instead of syslog. + This option works only with option -f, otherwise it is ignored. +-- +2.48.1 + diff --git a/SOURCES/0135-configure.ac-add-with-dmeventd-exit-on-path.patch b/SOURCES/0135-configure.ac-add-with-dmeventd-exit-on-path.patch new file mode 100644 index 0000000..58647bc --- /dev/null +++ b/SOURCES/0135-configure.ac-add-with-dmeventd-exit-on-path.patch @@ -0,0 +1,68 @@ +From ebe966020d2378bcc1a7f61551d4278bde6b8f6c Mon Sep 17 00:00:00 2001 +From: Zdenek Kabelac +Date: Mon, 25 Sep 2023 15:48:06 +0200 +Subject: [PATCH 135/139] configure.ac: add --with-dmeventd-exit-on-path + +(cherry picked from commit 744cdc3ba885f9dc8e1444cb77a190d5ea0007ed) +--- + configure.ac | 32 +++++++++++++++++++------------- + 1 file changed, 19 insertions(+), 13 deletions(-) + +diff --git a/configure.ac b/configure.ac +index 6cdf1a7e6..01e0b4d51 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -1715,24 +1715,29 @@ AC_DEFINE_UNQUOTED(LVMIMPORTVDO_PATH, ["$LVMIMPORTVDO_PATH"], [Path to lvm_impor + + ################################################################################ + dnl -- dmeventd pidfile and executable path ++AC_ARG_WITH(dmeventd-pidfile, ++ AS_HELP_STRING([--with-dmeventd-pidfile=PATH], ++ [dmeventd pidfile [PID_DIR/dmeventd.pid]]), ++ DMEVENTD_PIDFILE=$withval, ++ DMEVENTD_PIDFILE="$DEFAULT_PID_DIR/dmeventd.pid") ++AC_ARG_WITH(dmeventd-path, ++ AS_HELP_STRING([--with-dmeventd-path=PATH], ++ [dmeventd path [EPREFIX/sbin/dmeventd]]), ++ DMEVENTD_PATH=$withval, ++ DMEVENTD_PATH="$SBINDIR/dmeventd") ++AC_ARG_WITH(dmeventd-exit-on-path, ++ AS_HELP_STRING([--with-dmeventd-exit-on-path=PATH], ++ [Default path to exit-on file in dmeventd [/run/nologin]]), ++ DEFAULT_DMEVENTD_EXIT_ON_PATH=$withval, ++ DEFAULT_DMEVENTD_EXIT_ON_PATH="/run/nologin") ++ + if test "$BUILD_DMEVENTD" = yes; then +- AC_ARG_WITH(dmeventd-pidfile, +- AS_HELP_STRING([--with-dmeventd-pidfile=PATH], +- [dmeventd pidfile [PID_DIR/dmeventd.pid]]), +- DMEVENTD_PIDFILE=$withval, +- DMEVENTD_PIDFILE="$DEFAULT_PID_DIR/dmeventd.pid") + AC_DEFINE_UNQUOTED(DMEVENTD_PIDFILE, ["$DMEVENTD_PIDFILE"], + [Path to dmeventd pidfile.]) +-fi +- +-if test "$BUILD_DMEVENTD" = yes; then +- AC_ARG_WITH(dmeventd-path, +- AS_HELP_STRING([--with-dmeventd-path=PATH], +- [dmeventd path [EPREFIX/sbin/dmeventd]]), +- DMEVENTD_PATH=$withval, +- DMEVENTD_PATH="$SBINDIR/dmeventd") + AC_DEFINE_UNQUOTED(DMEVENTD_PATH, ["$DMEVENTD_PATH"], + [Path to dmeventd binary.]) ++ AC_DEFINE_UNQUOTED(DEFAULT_DMEVENTD_EXIT_ON_PATH, ["$DEFAULT_DMEVENTD_EXIT_ON_PATH"], ++ [Path to exit-on dmeventd file.]) + fi + + ################################################################################ +@@ -1861,6 +1866,7 @@ AC_SUBST(DEFAULT_ARCHIVE_SUBDIR) + AC_SUBST(DEFAULT_BACKUP_SUBDIR) + AC_SUBST(DEFAULT_CACHE_SUBDIR) + AC_SUBST(DEFAULT_DM_RUN_DIR) ++AC_SUBST(DEFAULT_DMEVENTD_EXIT_ON_PATH) + AC_SUBST(DEFAULT_LOCK_DIR) + AC_SUBST(DEFAULT_MIRROR_SEGTYPE) + AC_SUBST(DEFAULT_PID_DIR) +-- +2.48.1 + diff --git a/SOURCES/0136-configure-autoreconf.patch b/SOURCES/0136-configure-autoreconf.patch new file mode 100644 index 0000000..87da0cb --- /dev/null +++ b/SOURCES/0136-configure-autoreconf.patch @@ -0,0 +1,111 @@ +From c499428897b8ea51eefd7a90f4141e532ec9fbb9 Mon Sep 17 00:00:00 2001 +From: Zdenek Kabelac +Date: Mon, 25 Sep 2023 15:49:52 +0200 +Subject: [PATCH 136/139] configure: autoreconf + +(cherry picked from commit 3da18a06d8e0671374f9bf8b841017cfd5d1e5ea) +--- + configure | 33 +++++++++++++++++++++++---------- + include/configure.h.in | 3 +++ + 2 files changed, 26 insertions(+), 10 deletions(-) + +diff --git a/configure b/configure +index cfad36e51..17083e7ff 100755 +--- a/configure ++++ b/configure +@@ -730,6 +730,7 @@ DEFAULT_PROFILE_SUBDIR + DEFAULT_PID_DIR + DEFAULT_MIRROR_SEGTYPE + DEFAULT_LOCK_DIR ++DEFAULT_DMEVENTD_EXIT_ON_PATH + DEFAULT_DM_RUN_DIR + DEFAULT_CACHE_SUBDIR + DEFAULT_BACKUP_SUBDIR +@@ -989,6 +990,7 @@ with_systemdsystemunitdir + with_tmpfilesdir + with_dmeventd_pidfile + with_dmeventd_path ++with_dmeventd_exit_on_path + with_default_system_dir + with_default_profile_subdir + with_default_archive_subdir +@@ -1793,6 +1795,9 @@ Optional Packages: + dmeventd pidfile [PID_DIR/dmeventd.pid] + --with-dmeventd-path=PATH + dmeventd path [EPREFIX/sbin/dmeventd] ++ --with-dmeventd-exit-on-path=PATH ++ Default path to exit-on file in dmeventd ++ [/run/nologin] + --with-default-system-dir=DIR + default LVM system directory [/etc/lvm] + --with-default-profile-subdir=SUBDIR +@@ -14081,8 +14086,6 @@ _ACEOF + + + ################################################################################ +-if test "$BUILD_DMEVENTD" = yes; then +- + # Check whether --with-dmeventd-pidfile was given. + if test "${with_dmeventd_pidfile+set}" = set; then : + withval=$with_dmeventd_pidfile; DMEVENTD_PIDFILE=$withval +@@ -14091,14 +14094,6 @@ else + fi + + +-cat >>confdefs.h <<_ACEOF +-#define DMEVENTD_PIDFILE "$DMEVENTD_PIDFILE" +-_ACEOF +- +-fi +- +-if test "$BUILD_DMEVENTD" = yes; then +- + # Check whether --with-dmeventd-path was given. + if test "${with_dmeventd_path+set}" = set; then : + withval=$with_dmeventd_path; DMEVENTD_PATH=$withval +@@ -14107,10 +14102,28 @@ else + fi + + ++# Check whether --with-dmeventd-exit-on-path was given. ++if test "${with_dmeventd_exit_on_path+set}" = set; then : ++ withval=$with_dmeventd_exit_on_path; DEFAULT_DMEVENTD_EXIT_ON_PATH=$withval ++else ++ DEFAULT_DMEVENTD_EXIT_ON_PATH="/run/nologin" ++fi ++ ++ ++if test "$BUILD_DMEVENTD" = yes; then ++ ++cat >>confdefs.h <<_ACEOF ++#define DMEVENTD_PIDFILE "$DMEVENTD_PIDFILE" ++_ACEOF ++ + cat >>confdefs.h <<_ACEOF + #define DMEVENTD_PATH "$DMEVENTD_PATH" + _ACEOF + ++cat >>confdefs.h <<_ACEOF ++#define DEFAULT_DMEVENTD_EXIT_ON_PATH "$DEFAULT_DMEVENTD_EXIT_ON_PATH" ++_ACEOF ++ + fi + + ################################################################################ +diff --git a/include/configure.h.in b/include/configure.h.in +index e0d971bbf..b8b728b73 100644 +--- a/include/configure.h.in ++++ b/include/configure.h.in +@@ -48,6 +48,9 @@ + /* Name of default metadata cache subdirectory. */ + #undef DEFAULT_CACHE_SUBDIR + ++/* Path to exit-on dmeventd file. */ ++#undef DEFAULT_DMEVENTD_EXIT_ON_PATH ++ + /* Define default node creation behavior with dmsetup create */ + #undef DEFAULT_DM_ADD_NODE + +-- +2.48.1 + diff --git a/SOURCES/0137-dmeventd-implement-exit_on-file-check.patch b/SOURCES/0137-dmeventd-implement-exit_on-file-check.patch new file mode 100644 index 0000000..4466f83 --- /dev/null +++ b/SOURCES/0137-dmeventd-implement-exit_on-file-check.patch @@ -0,0 +1,196 @@ +From b7dd2a9e5973544f248aeeb7bc0b5e7afbd27d9b Mon Sep 17 00:00:00 2001 +From: Zdenek Kabelac +Date: Mon, 25 Sep 2023 13:07:00 +0200 +Subject: [PATCH 137/139] dmeventd: implement exit_on file check + +When exit on file is present in a system and term/break signal is +catched, them dmeventd is no longger refusing to exit. + +For the correct shutdown, there should be ideally unmonitoring call, +however in some case it's very hard to implement this correct procedure. + +With this 'exit on' file dmeventd at least avoid 'blocking' shutdown, +before systemd kills use with -9 anyway possibly even in some unwanted +stated of internal dmeventd processing (i.e. in the middle of some lvm +command processing). + +(cherry picked from commit a9d7a9d1289d7cafa1db5fd1e41417bf4f7709d1) +--- + daemons/dmeventd/dmeventd.c | 57 ++++++++++++++++++++++++++++--------- + make.tmpl.in | 1 + + man/Makefile.in | 1 + + man/dmeventd.8_main | 12 ++++++++ + 4 files changed, 58 insertions(+), 13 deletions(-) + +diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c +index 46c34ada2..828bc0c7a 100644 +--- a/daemons/dmeventd/dmeventd.c ++++ b/daemons/dmeventd/dmeventd.c +@@ -98,6 +98,7 @@ static int _systemd_activation = 0; + static int _foreground = 0; + static int _restart = 0; + static time_t _idle_since = 0; ++static const char *_exit_on = DEFAULT_DMEVENTD_EXIT_ON_PATH; + static char **_initial_registrations = 0; + + /* FIXME Make configurable at runtime */ +@@ -723,12 +724,18 @@ static int _get_status(struct message_data *message_data) + static int _get_parameters(struct message_data *message_data) { + struct dm_event_daemon_message *msg = message_data->msg; + int size; ++ char idle_buf[32] = ""; ++ ++ if (_idle_since) ++ (void)dm_snprintf(idle_buf, sizeof(idle_buf), " idle=%lu", (long unsigned) (time(NULL) - _idle_since)); + + free(msg->data); +- if ((size = dm_asprintf(&msg->data, "%s pid=%d daemon=%s exec_method=%s", ++ if ((size = dm_asprintf(&msg->data, "%s pid=%d daemon=%s exec_method=%s exit_on=\"%s\"%s", + message_data->id, getpid(), + _foreground ? "no" : "yes", +- _systemd_activation ? "systemd" : "direct")) < 0) { ++ _systemd_activation ? "systemd" : "direct", ++ _exit_on, ++ idle_buf)) < 0) { + stack; + return -ENOMEM; + } +@@ -2240,8 +2247,9 @@ bad: + static void _usage(char *prog, FILE *file) + { + fprintf(file, "Usage:\n" +- "%s [-d [-d [-d]]] [-f] [-h] [i] [-l] [-R] [-V] [-?]\n\n" ++ "%s [-d [-d [-d]]] [-e path] [-f] [-h] [i] [-l] [-R] [-V] [-?]\n\n" + " -d Log debug messages to syslog (-d, -dd, -ddd)\n" ++ " -e Select a file path checked on exit\n" + " -f Don't fork, run in the foreground\n" + " -h Show this help information\n" + " -i Query running instance of dmeventd for info\n" +@@ -2264,7 +2272,7 @@ int main(int argc, char *argv[]) + + optopt = optind = opterr = 0; + optarg = (char*) ""; +- while ((opt = getopt(argc, argv, "?fhiVdlR")) != EOF) { ++ while ((opt = getopt(argc, argv, ":?e:fhiVdlR")) != EOF) { + switch (opt) { + case 'h': + _usage(argv[0], stdout); +@@ -2277,6 +2285,13 @@ int main(int argc, char *argv[]) + case 'R': + _restart++; + break; ++ case 'e': ++ if (strchr(optarg, '"')) { ++ fprintf(stderr, "dmeventd: option -e does not accept path \"%s\" with '\"' character.\n", optarg); ++ return EXIT_FAILURE; ++ } ++ _exit_on=optarg; ++ break; + case 'f': + _foreground++; + break; +@@ -2289,6 +2304,9 @@ int main(int argc, char *argv[]) + case 'V': + printf("dmeventd version: %s\n", DM_LIB_VERSION); + return EXIT_SUCCESS; ++ case ':': ++ fprintf(stderr, "dmeventd: option -%c requires an argument.\n", optopt); ++ return EXIT_FAILURE; + } + } + +@@ -2379,15 +2397,28 @@ int main(int argc, char *argv[]) + break; + } + } +- } else if (_exit_now == DM_SIGNALED_EXIT) { +- _exit_now = DM_SCHEDULED_EXIT; +- /* +- * When '_exit_now' is set, signal has been received, +- * but can not simply exit unless all +- * threads are done processing. +- */ +- log_info("dmeventd received break, scheduling exit."); +- } ++ } else ++ switch (_exit_now) { ++ case DM_SIGNALED_EXIT: ++ _exit_now = DM_SCHEDULED_EXIT; ++ /* ++ * When '_exit_now' is set, signal has been received, ++ * but can not simply exit unless all ++ * threads are done processing. ++ */ ++ log_info("dmeventd received break, scheduling exit."); ++ /* fall through */ ++ case DM_SCHEDULED_EXIT: ++ /* While exit is scheduled, check for exit_on file */ ++ DEBUGLOG("Checking exit on file \"%s\".", _exit_on); ++ if (_exit_on[0] && (access(_exit_on, F_OK) == 0)) { ++ log_info("dmeventd detected exit on file %s, unregistering all monitored devices.", ++ _exit_on); ++ _unregister_all_threads(); ++ } ++ break; ++ } ++ + _process_request(&fifos); + _cleanup_unused_threads(); + } +diff --git a/make.tmpl.in b/make.tmpl.in +index 7799a8adb..99170ca7f 100644 +--- a/make.tmpl.in ++++ b/make.tmpl.in +@@ -147,6 +147,7 @@ DEFAULT_LOCK_DIR = @DEFAULT_LOCK_DIR@ + DEFAULT_RUN_DIR = @DEFAULT_RUN_DIR@ + DEFAULT_PID_DIR = @DEFAULT_PID_DIR@ + DEFAULT_MANGLING = @MANGLING@ ++DEFAULT_DMEVENTD_EXIT_ON_PATH = @DEFAULT_DMEVENTD_EXIT_ON_PATH@ + + # Setup vpath search paths for some suffixes + vpath %.c $(srcdir) +diff --git a/man/Makefile.in b/man/Makefile.in +index ba6f2046f..f324150de 100644 +--- a/man/Makefile.in ++++ b/man/Makefile.in +@@ -181,6 +181,7 @@ $(SED) -e "s+#VERSION#+$(LVM_VERSION)+" \ + -e "s+#DEFAULT_PID_DIR#+$(DEFAULT_PID_DIR)+" \ + -e "s+#SYSTEMD_GENERATOR_DIR#+$(SYSTEMD_GENERATOR_DIR)+" \ + -e "s+#DEFAULT_LIBLINE#+$(DEFAULT_LIBLINE)+" \ ++ -e "s+#DEFAULT_DMEVENTD_EXIT_ON_PATH#+$(DEFAULT_DMEVENTD_EXIT_ON_PATH)+" \ + -e "s+#DEFAULT_MANGLING#+$(DEFAULT_MANGLING)+" $< > $@ + endef + +diff --git a/man/dmeventd.8_main b/man/dmeventd.8_main +index 75926bae5..7a780da7c 100644 +--- a/man/dmeventd.8_main ++++ b/man/dmeventd.8_main +@@ -10,6 +10,8 @@ dmeventd \(em Device-mapper event daemon + .RB [ -d + .RB [ -d + .RB [ -d ]]] ++.RB [ -e ++.BR exit_on_path ] + .RB [ -f ] + .RB [ -h ] + .RB [ -i ] +@@ -37,6 +39,16 @@ debug messages sent to syslog. + Each extra d adds more debugging information. + . + .TP ++.B -e exit_on_path ++Specifies the file path whose presence is checked by the daemon when it ++receives a signal (SIGINT, SIGTERM) and allows to exit even if there are still ++monitored devices. ++This can help with system shutdown where devices ++have not been unmonitored properly. ++To disable this behavior set this to the empty string "". ++Default value is "\fI#DEFAULT_DMEVENTD_EXIT_ON_PATH#\fP". ++. ++.TP + .B -f + Don't fork, run in the foreground. + . +-- +2.48.1 + diff --git a/SOURCES/0138-debug-correct-level.patch b/SOURCES/0138-debug-correct-level.patch new file mode 100644 index 0000000..d42871f --- /dev/null +++ b/SOURCES/0138-debug-correct-level.patch @@ -0,0 +1,118 @@ +From 490631e2cd0947116f21192837703b2e563b863c Mon Sep 17 00:00:00 2001 +From: Zdenek Kabelac +Date: Wed, 20 Sep 2023 15:36:54 +0200 +Subject: [PATCH 138/139] debug: correct level + +No error for just tracing message. + +(cherry picked from commit e930ee93f7361a7b0b7a357acc4187bf630b7f14) +--- + daemons/dmeventd/dmeventd.c | 20 ++++++++++---------- + device_mapper/ioctl/libdm-iface.c | 2 +- + libdm/ioctl/libdm-iface.c | 2 +- + 3 files changed, 12 insertions(+), 12 deletions(-) + +diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c +index 828bc0c7a..f529f8ac5 100644 +--- a/daemons/dmeventd/dmeventd.c ++++ b/daemons/dmeventd/dmeventd.c +@@ -1765,7 +1765,7 @@ static void _cleanup_unused_threads(void) + DEBUGLOG("Destroying Thr %x.", (int)thread->thread); + + if (pthread_join(thread->thread, NULL)) +- log_sys_error("pthread_join", ""); ++ log_sys_debug("pthread_join", ""); + + _free_thread_status(thread); + _lock_mutex(); +@@ -1796,7 +1796,7 @@ static void _init_thread_signals(void) + sigdelset(&my_sigset, SIGQUIT); + + if (pthread_sigmask(SIG_BLOCK, &my_sigset, NULL)) +- log_sys_error("pthread_sigmask", "SIG_BLOCK"); ++ log_sys_debug("pthread_sigmask", "SIG_BLOCK"); + } + + /* +@@ -1825,7 +1825,7 @@ static int _set_oom_adj(const char *oom_adj_path, int val) + fprintf(fp, "%i", val); + + if (dm_fclose(fp)) +- log_sys_error("fclose", oom_adj_path); ++ log_sys_debug("fclose", oom_adj_path); + + return 1; + } +@@ -1839,11 +1839,11 @@ static int _protect_against_oom_killer(void) + + if (stat(OOM_ADJ_FILE, &st) == -1) { + if (errno != ENOENT) +- log_sys_error("stat", OOM_ADJ_FILE); ++ log_sys_debug("stat", OOM_ADJ_FILE); + + /* Try old oom_adj interface as a fallback */ + if (stat(OOM_ADJ_FILE_OLD, &st) == -1) { +- log_sys_error("stat", OOM_ADJ_FILE_OLD); ++ log_sys_debug("stat", OOM_ADJ_FILE_OLD); + return 1; + } + +@@ -1932,14 +1932,14 @@ out: + static void _remove_files_on_exit(void) + { + if (unlink(DMEVENTD_PIDFILE)) +- log_sys_error("unlink", DMEVENTD_PIDFILE); ++ log_sys_debug("unlink", DMEVENTD_PIDFILE); + + if (!_systemd_activation) { + if (unlink(DM_EVENT_FIFO_CLIENT)) +- log_sys_error("unlink", DM_EVENT_FIFO_CLIENT); ++ log_sys_debug("unlink", DM_EVENT_FIFO_CLIENT); + + if (unlink(DM_EVENT_FIFO_SERVER)) +- log_sys_error("unlink", DM_EVENT_FIFO_SERVER); ++ log_sys_debug("unlink", DM_EVENT_FIFO_SERVER); + } + } + +@@ -2428,9 +2428,9 @@ int main(int argc, char *argv[]) + log_notice("dmeventd shutting down."); + + if (fifos.client >= 0 && close(fifos.client)) +- log_sys_error("client close", fifos.client_path); ++ log_sys_debug("client close", fifos.client_path); + if (fifos.server >= 0 && close(fifos.server)) +- log_sys_error("server close", fifos.server_path); ++ log_sys_debug("server close", fifos.server_path); + + if (_use_syslog) + closelog(); +diff --git a/device_mapper/ioctl/libdm-iface.c b/device_mapper/ioctl/libdm-iface.c +index 533bb9eea..b09284118 100644 +--- a/device_mapper/ioctl/libdm-iface.c ++++ b/device_mapper/ioctl/libdm-iface.c +@@ -397,7 +397,7 @@ static void _close_control_fd(void) + { + if (_control_fd != -1) { + if (close(_control_fd) < 0) +- log_sys_error("close", "_control_fd"); ++ log_sys_debug("close", "_control_fd"); + _control_fd = -1; + } + } +diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c +index 28589a15c..7c7259874 100644 +--- a/libdm/ioctl/libdm-iface.c ++++ b/libdm/ioctl/libdm-iface.c +@@ -396,7 +396,7 @@ static void _close_control_fd(void) + { + if (_control_fd != -1) { + if (close(_control_fd) < 0) +- log_sys_error("close", "_control_fd"); ++ log_sys_debug("close", "_control_fd"); + _control_fd = -1; + } + } +-- +2.48.1 + diff --git a/SOURCES/0139-tests-check-exit_on-works.patch b/SOURCES/0139-tests-check-exit_on-works.patch new file mode 100644 index 0000000..7420b92 --- /dev/null +++ b/SOURCES/0139-tests-check-exit_on-works.patch @@ -0,0 +1,54 @@ +From 4f4a5c39ae768714925809970598b15268cd4ddb Mon Sep 17 00:00:00 2001 +From: Zdenek Kabelac +Date: Tue, 26 Sep 2023 01:21:41 +0200 +Subject: [PATCH 139/139] tests: check exit_on works + +(cherry picked from commit cb8486a9b2d6f3c73749f98287cad6adbc4f857f) +--- + test/shell/dmeventd-restart.sh | 26 +++++++++++++++++++++++--- + 1 file changed, 23 insertions(+), 3 deletions(-) + +diff --git a/test/shell/dmeventd-restart.sh b/test/shell/dmeventd-restart.sh +index 0def8c1fa..96e4c7cff 100644 +--- a/test/shell/dmeventd-restart.sh ++++ b/test/shell/dmeventd-restart.sh +@@ -46,8 +46,8 @@ rm LOCAL_DMEVENTD debug.log* + dmeventd -R -f & + echo $! >LOCAL_DMEVENTD + +-# wait longer as tries to communicate with killed daemon +-sleep 9 ++# wait longer as tries 5s to communicate with killed daemon ++sleep 7 + # now dmeventd should not be running + not pgrep dmeventd + rm LOCAL_DMEVENTD +@@ -63,4 +63,24 @@ test -e LOCAL_CLVMD || not grep 'already monitored' lvchange.out + lvchange --monitor y --verbose $vg/$lv2 2>&1 | tee lvchange.out + test -e LOCAL_CLVMD || not grep 'already monitored' lvchange.out + +-vgremove -ff $vg ++rm -f debug.log* ++dmeventd -R -f -e "$PWD/test_nologin" -ldddd > debug.log_DMEVENTD_$RANDOM 2>&1 & ++echo $! >LOCAL_DMEVENTD ++ ++pgrep -o dmeventd ++kill -INT "$(< LOCAL_DMEVENTD)" ++sleep 1 ++ ++# dmeventd should be still present (although in 'exit-mode') ++pgrep -o dmeventd ++ ++# Create a file simulating 'shutdown in progress' ++touch test_nologin ++sleep 1.1 ++ ++# Should be now dead (within 1 second) ++not pgrep -o dmeventd ++rm -f LOCAL_DMEVENTD ++ ++# Do not run dmeventd here again ++vgremove -ff --config 'activation/monitoring = 0' $vg +-- +2.48.1 + diff --git a/SPECS/lvm2.spec b/SPECS/lvm2.spec index 429e073..1225863 100644 --- a/SPECS/lvm2.spec +++ b/SPECS/lvm2.spec @@ -68,7 +68,7 @@ Version: 2.03.14 %if 0%{?from_snapshot} Release: 0.1.20210426git%{shortcommit}%{?dist}%{?rel_suffix} %else -Release: 14%{?dist}%{?rel_suffix} +Release: 15%{?dist}%{?rel_suffix} %endif License: GPLv2 URL: http://sourceware.org/lvm2 @@ -227,6 +227,16 @@ Patch126: 0125-raid-add-messages-to-lvs-command-output-in-case-Raid.patch #Patch130: 0129-remove-unused-variable.patch # Patch131: 0130-spec-Install-and-package-etc-lvm-devices.patch +# RHEL-8288: +Patch132: 0131-dmeventd-move-var-set-to-locked-section.patch +Patch133: 0132-dmeventd-use-return.patch +Patch134: 0133-dmeventd-unregister-all-devices-on-restart.patch +Patch135: 0134-dmeventd-info-status-report.patch +Patch136: 0135-configure.ac-add-with-dmeventd-exit-on-path.patch +Patch137: 0136-configure-autoreconf.patch +Patch138: 0137-dmeventd-implement-exit_on-file-check.patch +Patch139: 0138-debug-correct-level.patch +Patch140: 0139-tests-check-exit_on-works.patch BuildRequires: gcc %if %{enable_testsuite} @@ -905,6 +915,10 @@ An extensive functional testsuite for LVM2. %endif %changelog +* Wed Jan 22 2025 Marian Csontos - 2.03.14-15 +- Fix dmeventd blocking on shutdown. +- Force exit dmeventd when /run/nologin is present. + * Fri Feb 02 2024 Marian Csontos - 2.03.14-14 - Fix multisegment RAID1 allocator using one disk for both legs. - Fix lvconvert -m 0 taking rimage_0 even if it is out of sync.