From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Sat, 26 Sep 2020 23:25:46 -0500 Subject: [PATCH] libmpathvalid: use default *_multipath_config, udev, and logsink Signed-off-by: Benjamin Marzinski --- libmpathvalid/libmpathvalid.version | 2 +- libmpathvalid/mpath_valid.c | 73 ++++++++++++++++++++--------- libmpathvalid/mpath_valid.h | 12 +++-- 3 files changed, 61 insertions(+), 26 deletions(-) diff --git a/libmpathvalid/libmpathvalid.version b/libmpathvalid/libmpathvalid.version index 4d8a8ba4..3bd0d3c5 100644 --- a/libmpathvalid/libmpathvalid.version +++ b/libmpathvalid/libmpathvalid.version @@ -1,7 +1,7 @@ MPATH_1.0 { global: - mpathvalid_conf; mpathvalid_init; + mpathvalid_reload_config; mpathvalid_exit; mpathvalid_is_path; mpathvalid_get_mode; diff --git a/libmpathvalid/mpath_valid.c b/libmpathvalid/mpath_valid.c index 6153e8b7..d839dbac 100644 --- a/libmpathvalid/mpath_valid.c +++ b/libmpathvalid/mpath_valid.c @@ -15,9 +15,7 @@ #include "mpath_cmd.h" #include "valid.h" #include "mpath_valid.h" - -static struct config default_config = { .verbosity = -1 }; -struct config *mpathvalid_conf = &default_config; +#include "debug.h" static unsigned int get_conf_mode(struct config *conf) { @@ -68,38 +66,70 @@ static int convert_result(int result) { } int -mpathvalid_init(int verbosity) +mpathvalid_init(int verbosity, int log_style) { unsigned int version[3]; struct config *conf; - default_config.verbosity = verbosity; - skip_libmp_dm_init(); - conf = load_config(DEFAULT_CONFIGFILE); - if (!conf) + logsink = log_style; + if (libmultipath_init()) return -1; + conf = get_multipath_config(); conf->verbosity = verbosity; - if (dm_prereq(version)) + put_multipath_config(conf); + + skip_libmp_dm_init(); + if (init_config(DEFAULT_CONFIGFILE)) goto fail; - memcpy(conf->version, version, sizeof(version)); + if (dm_prereq(version)) + goto fail_config; - mpathvalid_conf = conf; + conf = get_multipath_config(); + conf->verbosity = verbosity; + memcpy(conf->version, version, sizeof(version)); + put_multipath_config(conf); return 0; + +fail_config: + uninit_config(); fail: - free_config(conf); + libmultipath_exit(); return -1; } int -mpathvalid_exit(void) +mpathvalid_reload_config(void) { - struct config *conf = mpathvalid_conf; + int verbosity; + unsigned int version[3]; + struct config *conf; + + conf = get_multipath_config(); + memcpy(version, conf->version, sizeof(version)); + verbosity = conf->verbosity; + put_multipath_config(conf); - default_config.verbosity = -1; - if (mpathvalid_conf == &default_config) - return 0; - mpathvalid_conf = &default_config; - free_config(conf); + uninit_config(); + + conf = get_multipath_config(); + conf->verbosity = verbosity; + put_multipath_config(conf); + + if (init_config(DEFAULT_CONFIGFILE)) + return -1; + + conf = get_multipath_config(); + conf->verbosity = verbosity; + memcpy(conf->version, version, sizeof(version)); + put_multipath_config(conf); + return 0; +} + +int +mpathvalid_exit(void) +{ + uninit_config(); + libmultipath_exit(); return 0; } @@ -121,9 +151,10 @@ mpathvalid_is_path(const char *name, unsigned int mode, char **wwid, if (!name || mode >= MPATH_MAX_MODE) return r; - if (nr_paths > 0 && !path_wwids) return r; + if (!udev) + return r; pp = alloc_path(); if (!pp) @@ -136,7 +167,7 @@ mpathvalid_is_path(const char *name, unsigned int mode, char **wwid, } conf = get_multipath_config(); - if (!conf || conf == &default_config) + if (!conf) goto out_wwid; if (mode != MPATH_DEFAULT) set_conf_mode(conf, mode); diff --git a/libmpathvalid/mpath_valid.h b/libmpathvalid/mpath_valid.h index 7fd8aa47..c83b8da5 100644 --- a/libmpathvalid/mpath_valid.h +++ b/libmpathvalid/mpath_valid.h @@ -42,15 +42,19 @@ enum mpath_valid_result { MPATH_IS_MAYBE_VALID, }; -struct config; -extern struct config *mpathvalid_conf; -int mpathvalid_init(int verbosity); +enum mpath_valid_log_style { + MPATH_LOG_STDIO = -1, + MPATH_LOG_STDIO_TIMESTAMP, + MPATH_LOG_SYSLOG, +}; + +int mpathvalid_init(int verbosity, int log_style); +int mpathvalid_reload_config(void); int mpathvalid_exit(void); unsigned int mpathvalid_get_mode(void); int mpathvalid_is_path(const char *name, unsigned int mode, char **wwid, const char **path_wwids, unsigned int nr_paths); - #ifdef __cplusplus } #endif -- 2.17.2