From ee8fb0310c53ed003a43b324c99cdfd891dd1a7c Mon Sep 17 00:00:00 2001 From: David Teigland Date: Tue, 25 Jan 2022 16:05:32 -0600 Subject: remove static autoactivation event based autoactivation is now the only method that lvm provides for autoactivation. Setting lvm.conf event_activation=0 can still be used to disable event based autoactivation commands, but doing so will no longer enable static autoactivation. --- scripts/Makefile.in | 14 -- .../blk_availability_systemd_red_hat.service.in | 2 +- scripts/generator-internals.c | 221 ------------------- .../lvm2_activation_generator_systemd_red_hat.c | 233 --------------------- scripts/lvm2_monitoring_systemd_red_hat.service.in | 2 +- 5 files changed, 2 insertions(+), 470 deletions(-) delete mode 100644 scripts/generator-internals.c delete mode 100644 scripts/lvm2_activation_generator_systemd_red_hat.c (limited to 'scripts') diff --git a/scripts/Makefile.in b/scripts/Makefile.in index 0d7f45680..ebcea92f9 100644 --- a/scripts/Makefile.in +++ b/scripts/Makefile.in @@ -15,9 +15,6 @@ srcdir = @srcdir@ top_srcdir = @top_srcdir@ top_builddir = @top_builddir@ -SOURCES = lvm2_activation_generator_systemd_red_hat.c -TARGETS = lvm2_activation_generator_systemd_red_hat - include $(top_builddir)/make.tmpl ifeq ("@BUILD_DMEVENTD@", "yes") @@ -78,17 +75,6 @@ ifeq ("@BLKDEACTIVATE@", "yes") $(Q) $(INSTALL_SCRIPT) blk_availability_init_red_hat $(initdir)/blk-availability endif -CFLAGS_lvm2_activation_generator_systemd_red_hat.o += $(EXTRA_EXEC_CFLAGS) - -lvm2_activation_generator_systemd_red_hat: $(OBJECTS) $(LVMINTERNAL_LIBS) - @echo " [CC] $@" - $(Q) $(CC) -o $@ $(OBJECTS) $(CFLAGS) $(LDFLAGS) $(EXTRA_EXEC_LDFLAGS) $(ELDFLAGS) $(LVMINTERNAL_LIBS) $(LIBS) - -install_systemd_generators: - @echo " [INSTALL] systemd_generators" - $(Q) $(INSTALL_DIR) $(systemd_generator_dir) - $(Q) $(INSTALL_PROGRAM) lvm2_activation_generator_systemd_red_hat $(systemd_generator_dir)/lvm2-activation-generator - install_systemd_units: install_dbus_service @echo " [INSTALL] systemd_units" $(Q) $(INSTALL_DIR) $(systemd_unit_dir) diff --git a/scripts/blk_availability_systemd_red_hat.service.in b/scripts/blk_availability_systemd_red_hat.service.in index 82d3b82d0..4102566be 100644 --- a/scripts/blk_availability_systemd_red_hat.service.in +++ b/scripts/blk_availability_systemd_red_hat.service.in @@ -1,7 +1,7 @@ [Unit] Description=Availability of block devices Before=shutdown.target -After=lvm2-activation.service iscsi-shutdown.service iscsi.service iscsid.service fcoe.service rbdmap.service +After=iscsi-shutdown.service iscsi.service iscsid.service fcoe.service rbdmap.service DefaultDependencies=no Conflicts=shutdown.target diff --git a/scripts/generator-internals.c b/scripts/generator-internals.c deleted file mode 100644 index 733e8189c..000000000 --- a/scripts/generator-internals.c +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright (C) 2018 Red Hat, Inc. All rights reserved. - * - * This file is part of the device-mapper userspace tools. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -// This file contains the unit testable parts of -// lvm2_activation_generator_systemd_red_hat - -#include "device_mapper/all.h" - -#include -#include -#include -#include /* For PATH_MAX for musl libc */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//---------------------------------------------------------------- - -static void _error(const char *format, ...) __attribute__ ((format(printf, 1, 2))); - -//---------------------------------------------------------------- - -// I'm rolling my own version of popen() here because I do not want to -// go through the shell. - -struct child_process { - pid_t pid; - FILE *fp; -}; - -static bool _open_child(struct child_process *child, const char *cmd, const char *argv[]) -{ - int r, pipe_fd[2]; - - r = pipe(pipe_fd); - if (r < 0) { - _error("call to pipe() failed: %d\n", r); - return false; - } - - child->pid = fork(); - if (child->pid < 0) { - (void) close(pipe_fd[0]); - (void) close(pipe_fd[1]); - _error("call to fork() failed: %d\n", r); - return false; - } - - if (child->pid == 0) { - // child - (void) close(pipe_fd[0]); - if (pipe_fd[1] != STDOUT_FILENO) { - (void) dup2(pipe_fd[1], STDOUT_FILENO); - (void) close(pipe_fd[1]); - } - - /* Suppressing any use of syslog */ - (void) setenv("LVM_SUPPRESS_SYSLOG", "1", 1); - - if (execv(cmd, (char *const *) argv) < 0) - _error("execv failed: %s\n", strerror(errno)); - // Shouldn't get here unless exec failed. - exit(1); - } else { - // parent - (void) close(pipe_fd[1]); - child->fp = fdopen(pipe_fd[0], "r"); - if (!child->fp) { - _error("call to fdopen() failed\n"); - return false; - } - } - - return true; -} - -// Returns the child's exit status -static bool _close_child(struct child_process *child) -{ - int status; - - (void) fclose(child->fp); - - while (waitpid(child->pid, &status, 0) < 0) - if (errno != EINTR) - return -1; - - if (WIFEXITED(status) && !WEXITSTATUS(status)) - return true; - - return false; -} - -//---------------------------------------------------------------- -// Aquiring config from the lvmconfig process - -#define LVM_CONF_EVENT_ACTIVATION "global/event_activation" -#define LVM_CONF_USE_LVMPOLLD "global/use_lvmpolld" - -struct config { - bool event_activation; - bool sysinit_needed; -}; - -static bool _begins_with(const char *line, const char *prefix, const char **rest) -{ - size_t len = strlen(prefix); - - if (strlen(line) < len) - return false; - - if (strncmp(line, prefix, len)) - return false; - - *rest = line + len; - - return true; -} - -static bool _parse_bool(const char *val, bool * result) -{ - const char *b = val, *e; - - while (*b && isspace(*b)) - b++; - - if (!*b) - goto parse_error; - - e = b; - while (*e && !isspace(*e)) - e++; - - if ((e - b) != 1) - goto parse_error; - - // We only handle '1', or '0' - if (*b == '1') { - *result = true; - return true; - - } else if (*b == '0') { - *result = false; - return true; - } - // Fallthrough - - parse_error: - _error("couldn't parse bool value '%s'\n", val); - return false; -} - -static bool _parse_line(const char *line, struct config *cfg) -{ - const char *val; - - if (_begins_with(line, "event_activation=", &val)) { - return _parse_bool(val, &cfg->event_activation); - - } else if (_begins_with(line, "use_lvmpolld=", &val)) { - bool r; - if (!_parse_bool(val, &r)) - return false; - cfg->sysinit_needed = !r; - return true; - } - - return false; -} - -static bool _get_config(struct config *cfg, const char *lvmconfig_path) -{ - static const char *_argv[] = { - "lvmconfig", "--type", "full", - LVM_CONF_EVENT_ACTIVATION, LVM_CONF_USE_LVMPOLLD, NULL - }; - - bool r = true; - char buffer[256]; - struct child_process child; - - cfg->event_activation = false; - cfg->sysinit_needed = true; - - if (!_open_child(&child, lvmconfig_path, _argv)) { - _error("couldn't open lvmconfig process\n"); - return false; - } - - while (fgets(buffer, sizeof(buffer), child.fp)) { - if (!_parse_line(buffer, cfg)) { - _error("_parse_line() failed\n"); - r = false; - } - } - - if (!_close_child(&child)) { - _error("lvmconfig failed\n"); - r = false; - } - - return r; -} diff --git a/scripts/lvm2_activation_generator_systemd_red_hat.c b/scripts/lvm2_activation_generator_systemd_red_hat.c deleted file mode 100644 index 0f4ac8da2..000000000 --- a/scripts/lvm2_activation_generator_systemd_red_hat.c +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Copyright (C) 2012 Red Hat, Inc. All rights reserved. - * - * This file is part of the device-mapper userspace tools. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -// Code in this file gets included in the unit tests. -#include "generator-internals.c" - -// Logging - -#define KMSG_DEV_PATH "/dev/kmsg" -static int _kmsg_fd; - -static void _log_init(void) -{ - // failing is harmless - _kmsg_fd = open(KMSG_DEV_PATH, O_WRONLY | O_NOCTTY); -} - -static void _log_exit(void) -{ - if (_kmsg_fd != -1) - (void) close(_kmsg_fd); -} - -__attribute__ ((format(printf, 1, 2))) -static void _error(const char *format, ...) -{ - int n; - va_list ap; - char message[PATH_MAX + 30]; /* +3 for '' where n is the log level and +27 for lvm2-activation-generator: " prefix */ - - snprintf(message, 31, "<%d>lvm2-activation-generator: ", LOG_ERR); - - va_start(ap, format); - n = vsnprintf(message + 30, PATH_MAX, format, ap); - va_end(ap); - - if (_kmsg_fd < 0 || (n < 0 || ((unsigned) n + 1 > PATH_MAX))) - return; - - /* The n+31: +30 for "lvm2-activation-generator: " prefix and +1 for '\0' suffix */ - if (write(_kmsg_fd, message, n + 31) < 0) - _error("Failed to write activation message %s: %m.\n", message); -} - -//---------------------------------------------------------------- - -#define UNIT_TARGET_LOCAL_FS "local-fs-pre.target" -#define UNIT_TARGET_REMOTE_FS "remote-fs-pre.target" - -struct generator { - const char *dir; - struct config cfg; - - int kmsg_fd; - char unit_path[PATH_MAX]; - char target_path[PATH_MAX]; -}; - -enum { - UNIT_EARLY, - UNIT_MAIN, - UNIT_NET -}; - -static const char *_unit_names[] = { - [UNIT_EARLY] = "lvm2-activation-early.service", - [UNIT_MAIN] = "lvm2-activation.service", - [UNIT_NET] = "lvm2-activation-net.service" -}; - -//---------------------------------------------------------------- - -static int register_unit_with_target(struct generator *gen, const char *unit, - const char *target) -{ - int r = 1; - - if (dm_snprintf(gen->target_path, PATH_MAX, "%s/%s.wants", gen->dir, target) < 0) { - r = 0; - goto out; - } - - (void) dm_prepare_selinux_context(gen->target_path, S_IFDIR); - if (mkdir(gen->target_path, 0755) < 0 && errno != EEXIST) { - _error("Failed to create target directory %s: %m.\n", gen->target_path); - r = 0; - goto out; - } - - if (dm_snprintf - (gen->target_path, PATH_MAX, "%s/%s.wants/%s", gen->dir, target, unit) < 0) { - r = 0; - goto out; - } - (void) dm_prepare_selinux_context(gen->target_path, S_IFLNK); - if (symlink(gen->unit_path, gen->target_path) < 0) { - _error("Failed to create symlink for unit %s: %m.\n", unit); - r = 0; - } - out: - dm_prepare_selinux_context(NULL, 0); - return r; -} - -static int generate_unit(struct generator *gen, int unit) -{ - FILE *f; - const char *unit_name = _unit_names[unit]; - const char *target_name = - unit == UNIT_NET ? UNIT_TARGET_REMOTE_FS : UNIT_TARGET_LOCAL_FS; - - if (dm_snprintf(gen->unit_path, PATH_MAX, "%s/%s", gen->dir, unit_name) - < 0) - return 0; - - if (!(f = fopen(gen->unit_path, "wxe"))) { - _error("Failed to create unit file %s: %m.\n", unit_name); - return 0; - } - - fputs("# Automatically generated by lvm2-activation-generator.\n" - "#\n" - "# This unit is responsible for direct activation of LVM logical volumes\n" - "# if event-based activation not used (global/event_activation=0 in\n" - "# lvm.conf). Direct LVM activation requires udev to be settled!\n\n" - "[Unit]\n" - "Description=LVM direct activation of logical volumes\n" - "Documentation=man:lvm2-activation-generator(8)\n" - "SourcePath=/etc/lvm/lvm.conf\n" "DefaultDependencies=no\n", f); - - fputs("Conflicts=shutdown.target\n", f); - - if (unit == UNIT_NET) { - fprintf(f, "After=%s iscsi.service fcoe.service rbdmap.service\n" - "Before=remote-fs-pre.target shutdown.target\n\n" - "[Service]\n" - "ExecStartPre=/usr/bin/udevadm settle\n", _unit_names[UNIT_MAIN]); - } else { - if (unit == UNIT_EARLY) - fputs("After=systemd-udev-settle.service\n" - "Before=cryptsetup.target\n", f); - else - fprintf(f, "After=%s cryptsetup.target\n", _unit_names[UNIT_EARLY]); - - fputs("Before=local-fs-pre.target shutdown.target\n" - "Wants=systemd-udev-settle.service\n\n" "[Service]\n", f); - } - - fputs("ExecStart=" LVM_PATH " vgchange -aay", f); - if (gen->cfg.sysinit_needed) - fputs(" --sysinit", f); - fputs("\nType=oneshot\n", f); - - if (fclose(f) < 0) { - _error("Failed to write unit file %s: %m.\n", unit_name); - return 0; - } - - if (!register_unit_with_target(gen, unit_name, target_name)) { - _error("Failed to register unit %s with target %s.\n", - unit_name, target_name); - return 0; - } - - return 1; -} - -static bool _parse_command_line(struct generator *gen, int argc, const char **argv) -{ - if (argc != 4) { - _error("Incorrect number of arguments for activation generator.\n"); - return false; - } - - gen->dir = argv[1]; - return true; -} - -static bool _run(int argc, const char **argv) -{ - bool r; - mode_t old_mask; - struct generator gen; - - if (!_parse_command_line(&gen, argc, argv)) - return false; - - if (_get_config(&gen.cfg, LVMCONFIG_PATH)) { - if (gen.cfg.event_activation) - // If event_activation=1, pvscan --cache -aay does activation. - return true; - } - - /* - * Create the activation units if: - * - _get_config succeeded and event_activation=0 - * - _get_config failed, then this is a failsafe fallback - */ - - /* mark lvm2-activation.*.service as world-accessible */ - old_mask = umask(0022); - - r = generate_unit(&gen, UNIT_EARLY) && - generate_unit(&gen, UNIT_MAIN) && generate_unit(&gen, UNIT_NET); - - umask(old_mask); - - return r; -} - -int main(int argc, const char **argv) -{ - bool r; - - _log_init(); - r = _run(argc, argv); - if (!r) - _error("Activation generator failed.\n"); - _log_exit(); - - return r ? EXIT_SUCCESS : EXIT_FAILURE; -} diff --git a/scripts/lvm2_monitoring_systemd_red_hat.service.in b/scripts/lvm2_monitoring_systemd_red_hat.service.in index 4bf744a7f..c0c96e316 100644 --- a/scripts/lvm2_monitoring_systemd_red_hat.service.in +++ b/scripts/lvm2_monitoring_systemd_red_hat.service.in @@ -2,7 +2,7 @@ Description=Monitoring of LVM2 mirrors, snapshots etc. using dmeventd or progress polling Documentation=man:dmeventd(8) man:lvcreate(8) man:lvchange(8) man:vgchange(8) Requires=dm-event.socket -After=dm-event.socket dm-event.service lvm2-activation.service +After=dm-event.socket dm-event.service Before=local-fs-pre.target shutdown.target DefaultDependencies=no Conflicts=shutdown.target -- cgit v1.2.1