import device-mapper-multipath-0.8.4-22.el8

This commit is contained in:
CentOS Sources 2022-03-29 15:03:23 -04:00 committed by Stepan Oksanichenko
parent d460ba2758
commit 57905a784e
15 changed files with 2296 additions and 1 deletions

View File

@ -0,0 +1,43 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Luca BRUNO <luca.bruno@coreos.com>
Date: Fri, 24 Sep 2021 09:34:01 +0000
Subject: [PATCH] multipathd.socket: add missing conditions from service unit
Upstream Status: https://github.com/openSUSE/multipath-tools.git
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2008101
Conflicts: Match the conditions with RHEL-8 multipathd.service unit
commit 345ccf564ce7d904641bd32baf4fc53c2283d95c
Author: Luca BRUNO <luca.bruno@coreos.com>
Date: Fri Sep 24 09:34:01 2021 +0000
multipathd.socket: add missing conditions from service unit
This aligns 'multipathd' socket and service units, by adding the
start conditions that are set on the service but not on the socket.
It should help avoiding situations where the socket unit ends up
marked as failed after hitting its retry-limit.
Fixes: https://github.com/opensvc/multipath-tools/issues/15
Signed-off-by: Luca BRUNO <luca.bruno@coreos.com>
Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
multipathd/multipathd.socket | 3 +++
1 file changed, 3 insertions(+)
diff --git a/multipathd/multipathd.socket b/multipathd/multipathd.socket
index 0ed4a1f7..c62c0fc8 100644
--- a/multipathd/multipathd.socket
+++ b/multipathd/multipathd.socket
@@ -1,6 +1,9 @@
[Unit]
Description=multipathd control socket
DefaultDependencies=no
+ConditionPathExists=/etc/multipath.conf
+ConditionKernelCommandLine=!nompath
+ConditionKernelCommandLine=!multipath=off
Before=sockets.target
[Socket]

View File

@ -0,0 +1,70 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Benjamin Marzinski <bmarzins@redhat.com>
Date: Thu, 23 Sep 2021 14:16:51 -0500
Subject: [PATCH] libmulitpath: add section name to invalid keyword output
If users forget the closing brace for a section in multipath.conf,
multipath has no way to detect that. When it sees the keyword at the
start of the next section, it will complain that there is an invalid
keyword, because that keyword doesn't belong in previous section (which
was never ended with a closing brace). This can confuse users. To make
this easier to understand, when multipath prints and invalid keyword
message, it now also prints the current section name, which can give
users a hint that they didn't end the previous section.
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
libmultipath/parser.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/libmultipath/parser.c b/libmultipath/parser.c
index 48b54e87..96b95936 100644
--- a/libmultipath/parser.c
+++ b/libmultipath/parser.c
@@ -507,7 +507,8 @@ validate_config_strvec(vector strvec, char *file)
}
static int
-process_stream(struct config *conf, FILE *stream, vector keywords, char *file)
+process_stream(struct config *conf, FILE *stream, vector keywords,
+ const char *section, char *file)
{
int i;
int r = 0, t;
@@ -571,16 +572,22 @@ process_stream(struct config *conf, FILE *stream, vector keywords, char *file)
if (keyword->sub) {
kw_level++;
r += process_stream(conf, stream,
- keyword->sub, file);
+ keyword->sub,
+ keyword->string,
+ file);
kw_level--;
}
break;
}
}
- if (i >= VECTOR_SIZE(keywords))
- condlog(1, "%s line %d, invalid keyword: %s",
- file, line_nr, str);
-
+ if (i >= VECTOR_SIZE(keywords)) {
+ if (section)
+ condlog(1, "%s line %d, invalid keyword in the %s section: %s",
+ file, line_nr, section, str);
+ else
+ condlog(1, "%s line %d, invalid keyword: %s",
+ file, line_nr, str);
+ }
free_strvec(strvec);
}
if (kw_level == 1)
@@ -611,7 +618,7 @@ process_file(struct config *conf, char *file)
/* Stream handling */
line_nr = 0;
- r = process_stream(conf, stream, conf->keywords, file);
+ r = process_stream(conf, stream, conf->keywords, NULL, file);
fclose(stream);
//free_keywords(keywords);

View File

@ -0,0 +1,97 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Benjamin Marzinski <bmarzins@redhat.com>
Date: Thu, 23 Sep 2021 21:39:36 -0500
Subject: [PATCH] libmultipath: use typedef for keyword handler and print
functions
Don't keep writing out the function type.
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
libmultipath/parser.c | 10 +++++-----
libmultipath/parser.h | 25 ++++++++++++-------------
2 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/libmultipath/parser.c b/libmultipath/parser.c
index 96b95936..e511acf9 100644
--- a/libmultipath/parser.c
+++ b/libmultipath/parser.c
@@ -32,8 +32,8 @@ static int line_nr;
int
keyword_alloc(vector keywords, char *string,
- int (*handler) (struct config *, vector),
- int (*print) (struct config *, char *, int, const void*),
+ handler_fn *handler,
+ print_fn *print,
int unique)
{
struct keyword *keyword;
@@ -71,8 +71,8 @@ install_sublevel_end(void)
int
_install_keyword(vector keywords, char *string,
- int (*handler) (struct config *, vector),
- int (*print) (struct config *, char *, int, const void*),
+ handler_fn *handler,
+ print_fn *print,
int unique)
{
int i = 0;
@@ -562,7 +562,7 @@ process_stream(struct config *conf, FILE *stream, vector keywords,
goto out;
}
if (keyword->handler) {
- t = (*keyword->handler) (conf, strvec);
+ t = keyword->handler(conf, strvec);
r += t;
if (t)
condlog(1, "multipath.conf +%d, parsing failed: %s",
diff --git a/libmultipath/parser.h b/libmultipath/parser.h
index b7917052..e8d89607 100644
--- a/libmultipath/parser.h
+++ b/libmultipath/parser.h
@@ -39,11 +39,15 @@
#define EOB "}"
#define MAXBUF 1024
-/* ketword definition */
+
+/* keyword definition */
+typedef int print_fn(struct config *, char *, int, const void *);
+typedef int handler_fn(struct config *, vector);
+
struct keyword {
char *string;
- int (*handler) (struct config *, vector);
- int (*print) (struct config *, char *, int, const void *);
+ handler_fn *handler;
+ print_fn *print;
vector sub;
int unique;
};
@@ -58,19 +62,14 @@ struct keyword {
for (i = 0; i < (k)->sub->allocated && ((p) = (k)->sub->slot[i]); i++)
/* Prototypes */
-extern int keyword_alloc(vector keywords, char *string,
- int (*handler) (struct config *, vector),
- int (*print) (struct config *, char *, int,
- const void *),
- int unique);
+extern int keyword_alloc(vector keywords, char *string, handler_fn *handler,
+ print_fn *print, int unique);
#define install_keyword_root(str, h) keyword_alloc(keywords, str, h, NULL, 1)
extern void install_sublevel(void);
extern void install_sublevel_end(void);
-extern int _install_keyword(vector keywords, char *string,
- int (*handler) (struct config *, vector),
- int (*print) (struct config *, char *, int,
- const void *),
- int unique);
+
+extern int _install_keyword(vector keywords, char *string, handler_fn *handler,
+ print_fn *print, int unique);
#define install_keyword(str, vec, pri) _install_keyword(keywords, str, vec, pri, 1)
#define install_keyword_multi(str, vec, pri) _install_keyword(keywords, str, vec, pri, 0)
extern void dump_keywords(vector keydump, int level);

View File

@ -0,0 +1,27 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Benjamin Marzinski <bmarzins@redhat.com>
Date: Fri, 24 Sep 2021 13:13:31 -0500
Subject: [PATCH] libmultipath: print the correct file when parsing fails
Don't assume that parsing failed on multipath.conf
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
libmultipath/parser.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libmultipath/parser.c b/libmultipath/parser.c
index e511acf9..341f2b80 100644
--- a/libmultipath/parser.c
+++ b/libmultipath/parser.c
@@ -565,8 +565,8 @@ process_stream(struct config *conf, FILE *stream, vector keywords,
t = keyword->handler(conf, strvec);
r += t;
if (t)
- condlog(1, "multipath.conf +%d, parsing failed: %s",
- line_nr, buf);
+ condlog(1, "%s line %d, parsing failed: %s",
+ file, line_nr, buf);
}
if (keyword->sub) {

View File

@ -0,0 +1,536 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Benjamin Marzinski <bmarzins@redhat.com>
Date: Fri, 24 Sep 2021 17:59:12 -0500
Subject: [PATCH] libmultipath: pass file and line number to keyword handlers
This will make it possible for the keyword handlers to print more useful
warning messages. It will be used by future patches.
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
libmultipath/dict.c | 145 +++++++++++++++++++++++++-----------------
libmultipath/parser.c | 3 +-
libmultipath/parser.h | 2 +-
3 files changed, 91 insertions(+), 59 deletions(-)
diff --git a/libmultipath/dict.c b/libmultipath/dict.c
index 13698b76..a8872da7 100644
--- a/libmultipath/dict.c
+++ b/libmultipath/dict.c
@@ -28,7 +28,7 @@
#include "dict.h"
static int
-set_int(vector strvec, void *ptr)
+set_int(vector strvec, void *ptr, const char *file, int line_nr)
{
int *int_ptr = (int *)ptr;
char *buff, *eptr;
@@ -57,7 +57,7 @@ set_int(vector strvec, void *ptr)
}
static int
-set_uint(vector strvec, void *ptr)
+set_uint(vector strvec, void *ptr, const char *file, int line_nr)
{
unsigned int *uint_ptr = (unsigned int *)ptr;
char *buff, *eptr, *p;
@@ -89,7 +89,7 @@ set_uint(vector strvec, void *ptr)
}
static int
-set_str(vector strvec, void *ptr)
+set_str(vector strvec, void *ptr, const char *file, int line_nr)
{
char **str_ptr = (char **)ptr;
@@ -104,7 +104,7 @@ set_str(vector strvec, void *ptr)
}
static int
-set_regex(vector strvec, void *ptr)
+set_regex(vector strvec, void *ptr, const char *file, int line_nr)
{
char **str_ptr = (char **)ptr;
@@ -119,7 +119,7 @@ set_regex(vector strvec, void *ptr)
}
static int
-set_yes_no(vector strvec, void *ptr)
+set_yes_no(vector strvec, void *ptr, const char *file, int line_nr)
{
char * buff;
int *int_ptr = (int *)ptr;
@@ -138,7 +138,7 @@ set_yes_no(vector strvec, void *ptr)
}
static int
-set_yes_no_undef(vector strvec, void *ptr)
+set_yes_no_undef(vector strvec, void *ptr, const char *file, int line_nr)
{
char * buff;
int *int_ptr = (int *)ptr;
@@ -240,9 +240,10 @@ print_yes_no_undef (char *buff, int len, long v)
#define declare_def_handler(option, function) \
static int \
-def_ ## option ## _handler (struct config *conf, vector strvec) \
+def_ ## option ## _handler (struct config *conf, vector strvec, \
+ const char *file, int line_nr) \
{ \
- return function (strvec, &conf->option); \
+ return function (strvec, &conf->option, file, line_nr); \
}
#define declare_def_snprint(option, function) \
@@ -277,12 +278,13 @@ snprint_def_ ## option (struct config *conf, char * buff, int len, \
#define declare_hw_handler(option, function) \
static int \
-hw_ ## option ## _handler (struct config *conf, vector strvec) \
+hw_ ## option ## _handler (struct config *conf, vector strvec, \
+ const char *file, int line_nr) \
{ \
struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable); \
if (!hwe) \
return 1; \
- return function (strvec, &hwe->option); \
+ return function (strvec, &hwe->option, file, line_nr); \
}
#define declare_hw_snprint(option, function) \
@@ -296,11 +298,12 @@ snprint_hw_ ## option (struct config *conf, char * buff, int len, \
#define declare_ovr_handler(option, function) \
static int \
-ovr_ ## option ## _handler (struct config *conf, vector strvec) \
+ovr_ ## option ## _handler (struct config *conf, vector strvec, \
+ const char *file, int line_nr) \
{ \
if (!conf->overrides) \
return 1; \
- return function (strvec, &conf->overrides->option); \
+ return function (strvec, &conf->overrides->option, file, line_nr); \
}
#define declare_ovr_snprint(option, function) \
@@ -313,12 +316,13 @@ snprint_ovr_ ## option (struct config *conf, char * buff, int len, \
#define declare_mp_handler(option, function) \
static int \
-mp_ ## option ## _handler (struct config *conf, vector strvec) \
+mp_ ## option ## _handler (struct config *conf, vector strvec, \
+ const char *file, int line_nr) \
{ \
struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable); \
if (!mpe) \
return 1; \
- return function (strvec, &mpe->option); \
+ return function (strvec, &mpe->option, file, line_nr); \
}
#define declare_mp_snprint(option, function) \
@@ -330,9 +334,10 @@ snprint_mp_ ## option (struct config *conf, char * buff, int len, \
return function (buff, len, mpe->option); \
}
-static int checkint_handler(struct config *conf, vector strvec)
+static int checkint_handler(struct config *conf, vector strvec,
+ const char *file, int line_nr)
{
- int rc = set_uint(strvec, &conf->checkint);
+ int rc = set_uint(strvec, &conf->checkint, file, line_nr);
if (rc)
return rc;
@@ -355,9 +360,10 @@ declare_def_snprint(reassign_maps, print_yes_no)
declare_def_handler(multipath_dir, set_str)
declare_def_snprint(multipath_dir, print_str)
-static int def_partition_delim_handler(struct config *conf, vector strvec)
+static int def_partition_delim_handler(struct config *conf, vector strvec,
+ const char *file, int line_nr)
{
- int rc = set_str(strvec, &conf->partition_delim);
+ int rc = set_str(strvec, &conf->partition_delim, file, line_nr);
if (rc != 0)
return rc;
@@ -387,13 +393,13 @@ static const char * const find_multipaths_optvals[] = {
};
static int
-def_find_multipaths_handler(struct config *conf, vector strvec)
+def_find_multipaths_handler(struct config *conf, vector strvec,
+ const char *file, int line_nr)
{
char *buff;
int i;
- if (set_yes_no_undef(strvec, &conf->find_multipaths) == 0 &&
- conf->find_multipaths != FIND_MULTIPATHS_UNDEF)
+ if (set_yes_no_undef(strvec, &conf->find_multipaths, file, line_nr) == 0 && conf->find_multipaths != FIND_MULTIPATHS_UNDEF)
return 0;
buff = set_value(strvec);
@@ -451,7 +457,8 @@ static int snprint_uid_attrs(struct config *conf, char *buff, int len,
return p - buff;
}
-static int uid_attrs_handler(struct config *conf, vector strvec)
+static int uid_attrs_handler(struct config *conf, vector strvec,
+ const char *file, int line_nr)
{
char *val;
@@ -644,7 +651,8 @@ declare_hw_handler(skip_kpartx, set_yes_no_undef)
declare_hw_snprint(skip_kpartx, print_yes_no_undef)
declare_mp_handler(skip_kpartx, set_yes_no_undef)
declare_mp_snprint(skip_kpartx, print_yes_no_undef)
-static int def_disable_changed_wwids_handler(struct config *conf, vector strvec)
+static int def_disable_changed_wwids_handler(struct config *conf, vector strvec,
+ const char *file, int line_nr)
{
return 0;
}
@@ -675,20 +683,23 @@ declare_def_snprint_defstr(enable_foreign, print_str,
DEFAULT_ENABLE_FOREIGN)
static int
-def_config_dir_handler(struct config *conf, vector strvec)
+def_config_dir_handler(struct config *conf, vector strvec, const char *file,
+ int line_nr)
{
/* this is only valid in the main config file */
if (conf->processed_main_config)
return 0;
- return set_str(strvec, &conf->config_dir);
+ return set_str(strvec, &conf->config_dir, file, line_nr);
}
declare_def_snprint(config_dir, print_str)
#define declare_def_attr_handler(option, function) \
static int \
-def_ ## option ## _handler (struct config *conf, vector strvec) \
+def_ ## option ## _handler (struct config *conf, vector strvec, \
+ const char *file, int line_nr) \
{ \
- return function (strvec, &conf->option, &conf->attribute_flags);\
+ return function (strvec, &conf->option, &conf->attribute_flags, \
+ file, line_nr); \
}
#define declare_def_attr_snprint(option, function) \
@@ -702,12 +713,14 @@ snprint_def_ ## option (struct config *conf, char * buff, int len, \
#define declare_mp_attr_handler(option, function) \
static int \
-mp_ ## option ## _handler (struct config *conf, vector strvec) \
+mp_ ## option ## _handler (struct config *conf, vector strvec, \
+ const char *file, int line_nr) \
{ \
struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable); \
if (!mpe) \
return 1; \
- return function (strvec, &mpe->option, &mpe->attribute_flags); \
+ return function (strvec, &mpe->option, &mpe->attribute_flags, \
+ file, line_nr); \
}
#define declare_mp_attr_snprint(option, function) \
@@ -721,7 +734,7 @@ snprint_mp_ ## option (struct config *conf, char * buff, int len, \
}
static int
-set_mode(vector strvec, void *ptr, int *flags)
+set_mode(vector strvec, void *ptr, int *flags, const char *file, int line_nr)
{
mode_t mode;
mode_t *mode_ptr = (mode_t *)ptr;
@@ -742,7 +755,7 @@ set_mode(vector strvec, void *ptr, int *flags)
}
static int
-set_uid(vector strvec, void *ptr, int *flags)
+set_uid(vector strvec, void *ptr, int *flags, const char *file, int line_nr)
{
uid_t uid;
uid_t *uid_ptr = (uid_t *)ptr;
@@ -767,7 +780,7 @@ set_uid(vector strvec, void *ptr, int *flags)
}
static int
-set_gid(vector strvec, void *ptr, int *flags)
+set_gid(vector strvec, void *ptr, int *flags, const char *file, int line_nr)
{
gid_t gid;
gid_t *gid_ptr = (gid_t *)ptr;
@@ -834,7 +847,7 @@ declare_mp_attr_handler(gid, set_gid)
declare_mp_attr_snprint(gid, print_gid)
static int
-set_undef_off_zero(vector strvec, void *ptr)
+set_undef_off_zero(vector strvec, void *ptr, const char *file, int line_nr)
{
char * buff;
int *int_ptr = (int *)ptr;
@@ -876,7 +889,7 @@ declare_hw_handler(fast_io_fail, set_undef_off_zero)
declare_hw_snprint(fast_io_fail, print_undef_off_zero)
static int
-set_dev_loss(vector strvec, void *ptr)
+set_dev_loss(vector strvec, void *ptr, const char *file, int line_nr)
{
char * buff;
unsigned int *uint_ptr = (unsigned int *)ptr;
@@ -919,7 +932,7 @@ declare_hw_handler(eh_deadline, set_undef_off_zero)
declare_hw_snprint(eh_deadline, print_undef_off_zero)
static int
-set_pgpolicy(vector strvec, void *ptr)
+set_pgpolicy(vector strvec, void *ptr, const char *file, int line_nr)
{
char * buff;
int *int_ptr = (int *)ptr;
@@ -985,7 +998,8 @@ get_sys_max_fds(int *max_fds)
static int
-max_fds_handler(struct config *conf, vector strvec)
+max_fds_handler(struct config *conf, vector strvec, const char *file,
+ int line_nr)
{
char * buff;
int r = 0, max_fds;
@@ -1030,7 +1044,7 @@ snprint_max_fds (struct config *conf, char * buff, int len, const void * data)
}
static int
-set_rr_weight(vector strvec, void *ptr)
+set_rr_weight(vector strvec, void *ptr, const char *file, int line_nr)
{
int *int_ptr = (int *)ptr;
char * buff;
@@ -1074,7 +1088,7 @@ declare_mp_handler(rr_weight, set_rr_weight)
declare_mp_snprint(rr_weight, print_rr_weight)
static int
-set_pgfailback(vector strvec, void *ptr)
+set_pgfailback(vector strvec, void *ptr, const char *file, int line_nr)
{
int *int_ptr = (int *)ptr;
char * buff;
@@ -1124,7 +1138,7 @@ declare_mp_handler(pgfailback, set_pgfailback)
declare_mp_snprint(pgfailback, print_pgfailback)
static int
-no_path_retry_helper(vector strvec, void *ptr)
+no_path_retry_helper(vector strvec, void *ptr, const char *file, int line_nr)
{
int *int_ptr = (int *)ptr;
char * buff;
@@ -1169,7 +1183,8 @@ declare_mp_handler(no_path_retry, no_path_retry_helper)
declare_mp_snprint(no_path_retry, print_no_path_retry)
static int
-def_log_checker_err_handler(struct config *conf, vector strvec)
+def_log_checker_err_handler(struct config *conf, vector strvec,
+ const char *file, int line_nr)
{
char * buff;
@@ -1243,7 +1258,8 @@ print_reservation_key(char * buff, int len, struct be64 key, uint8_t flags,
}
static int
-def_reservation_key_handler(struct config *conf, vector strvec)
+def_reservation_key_handler(struct config *conf, vector strvec,
+ const char *file, int line_nr)
{
return set_reservation_key(strvec, &conf->reservation_key,
&conf->sa_flags,
@@ -1260,7 +1276,8 @@ snprint_def_reservation_key (struct config *conf, char * buff, int len,
}
static int
-mp_reservation_key_handler(struct config *conf, vector strvec)
+mp_reservation_key_handler(struct config *conf, vector strvec, const char *file,
+ int line_nr)
{
struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);
if (!mpe)
@@ -1281,7 +1298,7 @@ snprint_mp_reservation_key (struct config *conf, char * buff, int len,
}
static int
-set_off_int_undef(vector strvec, void *ptr)
+set_off_int_undef(vector strvec, void *ptr, const char *file, int line_nr)
{
int *int_ptr = (int *)ptr;
char * buff;
@@ -1422,7 +1439,8 @@ declare_hw_snprint(recheck_wwid, print_yes_no_undef)
static int
-def_uxsock_timeout_handler(struct config *conf, vector strvec)
+def_uxsock_timeout_handler(struct config *conf, vector strvec, const char *file,
+ int line_nr)
{
unsigned int uxsock_timeout;
char *buff;
@@ -1442,7 +1460,8 @@ def_uxsock_timeout_handler(struct config *conf, vector strvec)
}
static int
-hw_vpd_vendor_handler(struct config *conf, vector strvec)
+hw_vpd_vendor_handler(struct config *conf, vector strvec, const char *file,
+ int line_nr)
{
int i;
char *buff;
@@ -1482,7 +1501,8 @@ snprint_hw_vpd_vendor(struct config *conf, char * buff, int len,
* blacklist block handlers
*/
static int
-blacklist_handler(struct config *conf, vector strvec)
+blacklist_handler(struct config *conf, vector strvec, const char*file,
+ int line_nr)
{
if (!conf->blist_devnode)
conf->blist_devnode = vector_alloc();
@@ -1504,7 +1524,8 @@ blacklist_handler(struct config *conf, vector strvec)
}
static int
-blacklist_exceptions_handler(struct config *conf, vector strvec)
+blacklist_exceptions_handler(struct config *conf, vector strvec,
+ const char *file, int line_nr)
{
if (!conf->elist_devnode)
conf->elist_devnode = vector_alloc();
@@ -1527,7 +1548,8 @@ blacklist_exceptions_handler(struct config *conf, vector strvec)
#define declare_ble_handler(option) \
static int \
-ble_ ## option ## _handler (struct config *conf, vector strvec) \
+ble_ ## option ## _handler (struct config *conf, vector strvec, \
+ const char *file, int line_nr) \
{ \
char * buff; \
\
@@ -1543,7 +1565,8 @@ ble_ ## option ## _handler (struct config *conf, vector strvec) \
#define declare_ble_device_handler(name, option, vend, prod) \
static int \
-ble_ ## option ## _ ## name ## _handler (struct config *conf, vector strvec) \
+ble_ ## option ## _ ## name ## _handler (struct config *conf, vector strvec, \
+ const char *file, int line_nr) \
{ \
char * buff; \
\
@@ -1583,13 +1606,15 @@ snprint_ble_simple (struct config *conf, char * buff, int len,
}
static int
-ble_device_handler(struct config *conf, vector strvec)
+ble_device_handler(struct config *conf, vector strvec, const char *file,
+ int line_nr)
{
return alloc_ble_device(conf->blist_device);
}
static int
-ble_except_device_handler(struct config *conf, vector strvec)
+ble_except_device_handler(struct config *conf, vector strvec, const char *file,
+ int line_nr)
{
return alloc_ble_device(conf->elist_device);
}
@@ -1623,7 +1648,8 @@ snprint_bled_product (struct config *conf, char * buff, int len,
* devices block handlers
*/
static int
-devices_handler(struct config *conf, vector strvec)
+devices_handler(struct config *conf, vector strvec, const char *file,
+ int line_nr)
{
if (!conf->hwtable)
conf->hwtable = vector_alloc();
@@ -1635,7 +1661,8 @@ devices_handler(struct config *conf, vector strvec)
}
static int
-device_handler(struct config *conf, vector strvec)
+device_handler(struct config *conf, vector strvec, const char *file,
+ int line_nr)
{
struct hwentry * hwe;
@@ -1672,7 +1699,8 @@ declare_hw_snprint(hwhandler, print_str)
* overrides handlers
*/
static int
-overrides_handler(struct config *conf, vector strvec)
+overrides_handler(struct config *conf, vector strvec, const char *file,
+ int line_nr)
{
if (!conf->overrides)
conf->overrides = alloc_hwe();
@@ -1689,7 +1717,8 @@ overrides_handler(struct config *conf, vector strvec)
* multipaths block handlers
*/
static int
-multipaths_handler(struct config *conf, vector strvec)
+multipaths_handler(struct config *conf, vector strvec, const char *file,
+ int line_nr)
{
if (!conf->mptable)
conf->mptable = vector_alloc();
@@ -1701,7 +1730,8 @@ multipaths_handler(struct config *conf, vector strvec)
}
static int
-multipath_handler(struct config *conf, vector strvec)
+multipath_handler(struct config *conf, vector strvec, const char *file,
+ int line_nr)
{
struct mpentry * mpe;
@@ -1730,7 +1760,8 @@ declare_mp_snprint(alias, print_str)
*/
static int
-deprecated_handler(struct config *conf, vector strvec)
+deprecated_handler(struct config *conf, vector strvec, const char *file,
+ int line_nr)
{
char * buff;
diff --git a/libmultipath/parser.c b/libmultipath/parser.c
index 341f2b80..29e8cee0 100644
--- a/libmultipath/parser.c
+++ b/libmultipath/parser.c
@@ -562,7 +562,8 @@ process_stream(struct config *conf, FILE *stream, vector keywords,
goto out;
}
if (keyword->handler) {
- t = keyword->handler(conf, strvec);
+ t = keyword->handler(conf, strvec, file,
+ line_nr);
r += t;
if (t)
condlog(1, "%s line %d, parsing failed: %s",
diff --git a/libmultipath/parser.h b/libmultipath/parser.h
index e8d89607..8b424b7a 100644
--- a/libmultipath/parser.h
+++ b/libmultipath/parser.h
@@ -42,7 +42,7 @@
/* keyword definition */
typedef int print_fn(struct config *, char *, int, const void *);
-typedef int handler_fn(struct config *, vector);
+typedef int handler_fn(struct config *, vector, const char *file, int line_nr);
struct keyword {
char *string;

View File

@ -0,0 +1,250 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Benjamin Marzinski <bmarzins@redhat.com>
Date: Tue, 28 Sep 2021 15:59:19 -0500
Subject: [PATCH] libmultipath: make set_int take a range for valid values
If a value outside of the valid range is passed to set_int, it caps the
value at appropriate limit, and issues a warning.
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
libmultipath/dict.c | 121 +++++++++++++++++++++++++++-----------------
1 file changed, 75 insertions(+), 46 deletions(-)
diff --git a/libmultipath/dict.c b/libmultipath/dict.c
index a8872da7..686f4d5c 100644
--- a/libmultipath/dict.c
+++ b/libmultipath/dict.c
@@ -28,7 +28,8 @@
#include "dict.h"
static int
-set_int(vector strvec, void *ptr, const char *file, int line_nr)
+set_int(vector strvec, void *ptr, int min, int max, const char *file,
+ int line_nr)
{
int *int_ptr = (int *)ptr;
char *buff, *eptr;
@@ -43,11 +44,17 @@ set_int(vector strvec, void *ptr, const char *file, int line_nr)
if (eptr > buff)
while (isspace(*eptr))
eptr++;
- if (*buff == '\0' || *eptr != '\0' || res > INT_MAX || res < INT_MIN) {
- condlog(1, "%s: invalid value for %s: \"%s\"",
- __func__, (char*)VECTOR_SLOT(strvec, 0), buff);
+ if (*buff == '\0' || *eptr != '\0') {
+ condlog(1, "%s line %d, invalid value for %s: \"%s\"",
+ file, line_nr, (char*)VECTOR_SLOT(strvec, 0), buff);
rc = 1;
} else {
+ if (res > max || res < min) {
+ res = (res > max) ? max : min;
+ condlog(1, "%s line %d, value for %s too %s, capping at %ld",
+ file, line_nr, (char*)VECTOR_SLOT(strvec, 0),
+ (res == max)? "large" : "small", res);
+ }
rc = 0;
*int_ptr = res;
}
@@ -76,8 +83,8 @@ set_uint(vector strvec, void *ptr, const char *file, int line_nr)
while (isspace(*eptr))
eptr++;
if (*buff == '\0' || *eptr != '\0' || !isdigit(*p) || res > UINT_MAX) {
- condlog(1, "%s: invalid value for %s: \"%s\"",
- __func__, (char*)VECTOR_SLOT(strvec, 0), buff);
+ condlog(1, "%s line %d, invalid value for %s: \"%s\"",
+ file, line_nr, (char*)VECTOR_SLOT(strvec, 0), buff);
rc = 1;
} else {
rc = 0;
@@ -246,6 +253,14 @@ def_ ## option ## _handler (struct config *conf, vector strvec, \
return function (strvec, &conf->option, file, line_nr); \
}
+#define declare_def_range_handler(option, minval, maxval) \
+static int \
+def_ ## option ## _handler (struct config *conf, vector strvec, \
+ const char *file, int line_nr) \
+{ \
+ return set_int(strvec, &conf->option, minval, maxval, file, line_nr); \
+}
+
#define declare_def_snprint(option, function) \
static int \
snprint_def_ ## option (struct config *conf, char * buff, int len, \
@@ -287,6 +302,18 @@ hw_ ## option ## _handler (struct config *conf, vector strvec, \
return function (strvec, &hwe->option, file, line_nr); \
}
+#define declare_hw_range_handler(option, minval, maxval) \
+static int \
+hw_ ## option ## _handler (struct config *conf, vector strvec, \
+ const char *file, int line_nr) \
+{ \
+ struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable); \
+ if (!hwe) \
+ return 1; \
+ return set_int(strvec, &hwe->option, minval, maxval, file, line_nr); \
+}
+
+
#define declare_hw_snprint(option, function) \
static int \
snprint_hw_ ## option (struct config *conf, char * buff, int len, \
@@ -306,6 +333,17 @@ ovr_ ## option ## _handler (struct config *conf, vector strvec, \
return function (strvec, &conf->overrides->option, file, line_nr); \
}
+#define declare_ovr_range_handler(option, minval, maxval) \
+static int \
+ovr_ ## option ## _handler (struct config *conf, vector strvec, \
+ const char *file, int line_nr) \
+{ \
+ if (!conf->overrides) \
+ return 1; \
+ return set_int(strvec, &conf->overrides->option, minval, maxval, \
+ file, line_nr); \
+}
+
#define declare_ovr_snprint(option, function) \
static int \
snprint_ovr_ ## option (struct config *conf, char * buff, int len, \
@@ -325,6 +363,17 @@ mp_ ## option ## _handler (struct config *conf, vector strvec, \
return function (strvec, &mpe->option, file, line_nr); \
}
+#define declare_mp_range_handler(option, minval, maxval) \
+static int \
+mp_ ## option ## _handler (struct config *conf, vector strvec, \
+ const char *file, int line_nr) \
+{ \
+ struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable); \
+ if (!mpe) \
+ return 1; \
+ return set_int(strvec, &mpe->option, minval, maxval, file, line_nr); \
+}
+
#define declare_mp_snprint(option, function) \
static int \
snprint_mp_ ## option (struct config *conf, char * buff, int len, \
@@ -351,7 +400,7 @@ declare_def_snprint(checkint, print_int)
declare_def_handler(max_checkint, set_uint)
declare_def_snprint(max_checkint, print_int)
-declare_def_handler(verbosity, set_int)
+declare_def_range_handler(verbosity, 0, MAX_VERBOSITY)
declare_def_snprint(verbosity, print_int)
declare_def_handler(reassign_maps, set_yes_no)
@@ -528,22 +577,22 @@ declare_ovr_snprint(checker_name, print_str)
declare_hw_handler(checker_name, set_str)
declare_hw_snprint(checker_name, print_str)
-declare_def_handler(minio, set_int)
+declare_def_range_handler(minio, 0, INT_MAX)
declare_def_snprint_defint(minio, print_int, DEFAULT_MINIO)
-declare_ovr_handler(minio, set_int)
+declare_ovr_range_handler(minio, 0, INT_MAX)
declare_ovr_snprint(minio, print_nonzero)
-declare_hw_handler(minio, set_int)
+declare_hw_range_handler(minio, 0, INT_MAX)
declare_hw_snprint(minio, print_nonzero)
-declare_mp_handler(minio, set_int)
+declare_mp_range_handler(minio, 0, INT_MAX)
declare_mp_snprint(minio, print_nonzero)
-declare_def_handler(minio_rq, set_int)
+declare_def_range_handler(minio_rq, 0, INT_MAX)
declare_def_snprint_defint(minio_rq, print_int, DEFAULT_MINIO_RQ)
-declare_ovr_handler(minio_rq, set_int)
+declare_ovr_range_handler(minio_rq, 0, INT_MAX)
declare_ovr_snprint(minio_rq, print_nonzero)
-declare_hw_handler(minio_rq, set_int)
+declare_hw_range_handler(minio_rq, 0, INT_MAX)
declare_hw_snprint(minio_rq, print_nonzero)
-declare_mp_handler(minio_rq, set_int)
+declare_mp_range_handler(minio_rq, 0, INT_MAX)
declare_mp_snprint(minio_rq, print_nonzero)
declare_def_handler(queue_without_daemon, set_yes_no)
@@ -562,7 +611,7 @@ snprint_def_queue_without_daemon (struct config *conf,
return 0;
}
-declare_def_handler(checker_timeout, set_int)
+declare_def_range_handler(checker_timeout, 0, INT_MAX)
declare_def_snprint(checker_timeout, print_nonzero)
declare_def_handler(flush_on_last_del, set_yes_no_undef)
@@ -630,13 +679,13 @@ declare_hw_snprint(deferred_remove, print_yes_no_undef)
declare_mp_handler(deferred_remove, set_yes_no_undef)
declare_mp_snprint(deferred_remove, print_yes_no_undef)
-declare_def_handler(retrigger_tries, set_int)
+declare_def_range_handler(retrigger_tries, 0, INT_MAX)
declare_def_snprint(retrigger_tries, print_int)
-declare_def_handler(retrigger_delay, set_int)
+declare_def_range_handler(retrigger_delay, 0, INT_MAX)
declare_def_snprint(retrigger_delay, print_int)
-declare_def_handler(uev_wait_timeout, set_int)
+declare_def_range_handler(uev_wait_timeout, 0, INT_MAX)
declare_def_snprint(uev_wait_timeout, print_int)
declare_def_handler(strict_timing, set_yes_no)
@@ -662,19 +711,19 @@ static int snprint_def_disable_changed_wwids(struct config *conf, char *buff,
return print_ignored(buff, len);
}
-declare_def_handler(remove_retries, set_int)
+declare_def_range_handler(remove_retries, 0, INT_MAX)
declare_def_snprint(remove_retries, print_int)
-declare_def_handler(max_sectors_kb, set_int)
+declare_def_range_handler(max_sectors_kb, 0, INT_MAX)
declare_def_snprint(max_sectors_kb, print_nonzero)
-declare_ovr_handler(max_sectors_kb, set_int)
+declare_ovr_range_handler(max_sectors_kb, 0, INT_MAX)
declare_ovr_snprint(max_sectors_kb, print_nonzero)
-declare_hw_handler(max_sectors_kb, set_int)
+declare_hw_range_handler(max_sectors_kb, 0, INT_MAX)
declare_hw_snprint(max_sectors_kb, print_nonzero)
-declare_mp_handler(max_sectors_kb, set_int)
+declare_mp_range_handler(max_sectors_kb, 0, INT_MAX)
declare_mp_snprint(max_sectors_kb, print_nonzero)
-declare_def_handler(find_multipaths_timeout, set_int)
+declare_def_range_handler(find_multipaths_timeout, INT_MIN, INT_MAX)
declare_def_snprint_defint(find_multipaths_timeout, print_int,
DEFAULT_FIND_MULTIPATHS_TIMEOUT)
@@ -1437,27 +1486,7 @@ declare_ovr_snprint(recheck_wwid, print_yes_no_undef)
declare_hw_handler(recheck_wwid, set_yes_no_undef)
declare_hw_snprint(recheck_wwid, print_yes_no_undef)
-
-static int
-def_uxsock_timeout_handler(struct config *conf, vector strvec, const char *file,
- int line_nr)
-{
- unsigned int uxsock_timeout;
- char *buff;
-
- buff = set_value(strvec);
- if (!buff)
- return 1;
-
- if (sscanf(buff, "%u", &uxsock_timeout) == 1 &&
- uxsock_timeout > DEFAULT_REPLY_TIMEOUT)
- conf->uxsock_timeout = uxsock_timeout;
- else
- conf->uxsock_timeout = DEFAULT_REPLY_TIMEOUT;
-
- free(buff);
- return 0;
-}
+declare_def_range_handler(uxsock_timeout, DEFAULT_REPLY_TIMEOUT, INT_MAX)
static int
hw_vpd_vendor_handler(struct config *conf, vector strvec, const char *file,

View File

@ -0,0 +1,177 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Benjamin Marzinski <bmarzins@redhat.com>
Date: Wed, 29 Sep 2021 12:56:04 -0500
Subject: [PATCH] libmultipath: improve checks for set_str
multipath always requires absolute pathnames, so make sure all file and
directory names start with a slash. Also check that the directories
exist. Finally, some strings, like the alias, will be used in paths.
These must not contain the slash character '/', since it is a forbidden
character in file/directory names. This patch adds seperate handlers for
these three cases. If a config line is invalid, these handlers retain
the existing config string, if any.
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
libmultipath/dict.c | 89 +++++++++++++++++++++++++++++++++++++++------
1 file changed, 78 insertions(+), 11 deletions(-)
diff --git a/libmultipath/dict.c b/libmultipath/dict.c
index 686f4d5c..d547d898 100644
--- a/libmultipath/dict.c
+++ b/libmultipath/dict.c
@@ -5,6 +5,8 @@
* Copyright (c) 2005 Kiyoshi Ueda, NEC
*/
#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include <pwd.h>
#include <string.h>
#include "checkers.h"
@@ -121,7 +123,72 @@ set_regex(vector strvec, void *ptr, const char *file, int line_nr)
if (!*str_ptr)
return 1;
+ return 0;
+}
+static int
+set_dir(vector strvec, void *ptr, const char *file, int line_nr)
+{
+ char **str_ptr = (char **)ptr;
+ char *old_str = *str_ptr;
+ struct stat sb;
+
+ *str_ptr = set_value(strvec);
+ if (!*str_ptr) {
+ free(old_str);
+ return 1;
+ }
+ if ((*str_ptr)[0] != '/'){
+ condlog(1, "%s line %d, %s is not an absolute directory path. Ignoring", file, line_nr, *str_ptr);
+ *str_ptr = old_str;
+ } else {
+ if (stat(*str_ptr, &sb) == 0 && S_ISDIR(sb.st_mode))
+ free(old_str);
+ else {
+ condlog(1, "%s line %d, %s is not an existing directory. Ignoring", file, line_nr, *str_ptr);
+ *str_ptr = old_str;
+ }
+ }
+ return 0;
+}
+
+static int
+set_path(vector strvec, void *ptr, const char *file, int line_nr)
+{
+ char **str_ptr = (char **)ptr;
+ char *old_str = *str_ptr;
+
+ *str_ptr = set_value(strvec);
+ if (!*str_ptr) {
+ free(old_str);
+ return 1;
+ }
+ if ((*str_ptr)[0] != '/'){
+ condlog(1, "%s line %d, %s is not an absolute path. Ignoring",
+ file, line_nr, *str_ptr);
+ *str_ptr = old_str;
+ } else
+ free(old_str);
+ return 0;
+}
+
+static int
+set_str_noslash(vector strvec, void *ptr, const char *file, int line_nr)
+{
+ char **str_ptr = (char **)ptr;
+ char *old_str = *str_ptr;
+
+ *str_ptr = set_value(strvec);
+ if (!*str_ptr) {
+ free(old_str);
+ return 1;
+ }
+ if (strchr(*str_ptr, '/')) {
+ condlog(1, "%s line %d, %s cannot contain a slash. Ignoring",
+ file, line_nr, *str_ptr);
+ *str_ptr = old_str;
+ } else
+ free(old_str);
return 0;
}
@@ -400,19 +467,19 @@ declare_def_snprint(checkint, print_int)
declare_def_handler(max_checkint, set_uint)
declare_def_snprint(max_checkint, print_int)
-declare_def_range_handler(verbosity, 0, MAX_VERBOSITY)
+declare_def_range_handler(verbosity, 0, 4)
declare_def_snprint(verbosity, print_int)
declare_def_handler(reassign_maps, set_yes_no)
declare_def_snprint(reassign_maps, print_yes_no)
-declare_def_handler(multipath_dir, set_str)
+declare_def_handler(multipath_dir, set_dir)
declare_def_snprint(multipath_dir, print_str)
static int def_partition_delim_handler(struct config *conf, vector strvec,
const char *file, int line_nr)
{
- int rc = set_str(strvec, &conf->partition_delim, file, line_nr);
+ int rc = set_str_noslash(strvec, &conf->partition_delim, file, line_nr);
if (rc != 0)
return rc;
@@ -545,11 +612,11 @@ declare_hw_snprint(prio_name, print_str)
declare_mp_handler(prio_name, set_str)
declare_mp_snprint(prio_name, print_str)
-declare_def_handler(alias_prefix, set_str)
+declare_def_handler(alias_prefix, set_str_noslash)
declare_def_snprint_defstr(alias_prefix, print_str, DEFAULT_ALIAS_PREFIX)
-declare_ovr_handler(alias_prefix, set_str)
+declare_ovr_handler(alias_prefix, set_str_noslash)
declare_ovr_snprint(alias_prefix, print_str)
-declare_hw_handler(alias_prefix, set_str)
+declare_hw_handler(alias_prefix, set_str_noslash)
declare_hw_snprint(alias_prefix, print_str)
declare_def_handler(prio_args, set_str)
@@ -633,13 +700,13 @@ declare_hw_snprint(user_friendly_names, print_yes_no_undef)
declare_mp_handler(user_friendly_names, set_yes_no_undef)
declare_mp_snprint(user_friendly_names, print_yes_no_undef)
-declare_def_handler(bindings_file, set_str)
+declare_def_handler(bindings_file, set_path)
declare_def_snprint(bindings_file, print_str)
-declare_def_handler(wwids_file, set_str)
+declare_def_handler(wwids_file, set_path)
declare_def_snprint(wwids_file, print_str)
-declare_def_handler(prkeys_file, set_str)
+declare_def_handler(prkeys_file, set_path)
declare_def_snprint(prkeys_file, print_str)
declare_def_handler(retain_hwhandler, set_yes_no_undef)
@@ -738,7 +805,7 @@ def_config_dir_handler(struct config *conf, vector strvec, const char *file,
/* this is only valid in the main config file */
if (conf->processed_main_config)
return 0;
- return set_str(strvec, &conf->config_dir, file, line_nr);
+ return set_path(strvec, &conf->config_dir, file, line_nr);
}
declare_def_snprint(config_dir, print_str)
@@ -1781,7 +1848,7 @@ multipath_handler(struct config *conf, vector strvec, const char *file,
declare_mp_handler(wwid, set_str)
declare_mp_snprint(wwid, print_str)
-declare_mp_handler(alias, set_str)
+declare_mp_handler(alias, set_str_noslash)
declare_mp_snprint(alias, print_str)
/*

View File

@ -0,0 +1,191 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Benjamin Marzinski <bmarzins@redhat.com>
Date: Mon, 4 Oct 2021 15:27:36 -0500
Subject: [PATCH] libmultipath: split set_int to enable reuse
Split the code that does the actual value parsing out of set_int(), into
a helper function, do_set_int(), so that it can be used by other
handlers. These functions no longer set the config value at all, when
they have invalid input.
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
libmultipath/dict.c | 82 +++++++++++++++++++++++++--------------------
1 file changed, 46 insertions(+), 36 deletions(-)
diff --git a/libmultipath/dict.c b/libmultipath/dict.c
index d547d898..6330836a 100644
--- a/libmultipath/dict.c
+++ b/libmultipath/dict.c
@@ -30,17 +30,12 @@
#include "dict.h"
static int
-set_int(vector strvec, void *ptr, int min, int max, const char *file,
- int line_nr)
+do_set_int(vector strvec, void *ptr, int min, int max, const char *file,
+ int line_nr, char *buff)
{
int *int_ptr = (int *)ptr;
- char *buff, *eptr;
+ char *eptr;
long res;
- int rc;
-
- buff = set_value(strvec);
- if (!buff)
- return 1;
res = strtol(buff, &eptr, 10);
if (eptr > buff)
@@ -49,17 +44,30 @@ set_int(vector strvec, void *ptr, int min, int max, const char *file,
if (*buff == '\0' || *eptr != '\0') {
condlog(1, "%s line %d, invalid value for %s: \"%s\"",
file, line_nr, (char*)VECTOR_SLOT(strvec, 0), buff);
- rc = 1;
- } else {
- if (res > max || res < min) {
- res = (res > max) ? max : min;
- condlog(1, "%s line %d, value for %s too %s, capping at %ld",
+ return 1;
+ }
+ if (res > max || res < min) {
+ res = (res > max) ? max : min;
+ condlog(1, "%s line %d, value for %s too %s, capping at %ld",
file, line_nr, (char*)VECTOR_SLOT(strvec, 0),
- (res == max)? "large" : "small", res);
- }
- rc = 0;
- *int_ptr = res;
+ (res == max)? "large" : "small", res);
}
+ *int_ptr = res;
+ return 0;
+}
+
+static int
+set_int(vector strvec, void *ptr, int min, int max, const char *file,
+ int line_nr)
+{
+ char *buff;
+ int rc;
+
+ buff = set_value(strvec);
+ if (!buff)
+ return 1;
+
+ rc = do_set_int(strvec, ptr, min, max, file, line_nr, buff);
FREE(buff);
return rc;
@@ -965,6 +973,7 @@ declare_mp_attr_snprint(gid, print_gid)
static int
set_undef_off_zero(vector strvec, void *ptr, const char *file, int line_nr)
{
+ int rc = 0;
char * buff;
int *int_ptr = (int *)ptr;
@@ -974,10 +983,10 @@ set_undef_off_zero(vector strvec, void *ptr, const char *file, int line_nr)
if (strcmp(buff, "off") == 0)
*int_ptr = UOZ_OFF;
- else if (sscanf(buff, "%d", int_ptr) != 1 ||
- *int_ptr < UOZ_ZERO)
- *int_ptr = UOZ_UNDEF;
- else if (*int_ptr == 0)
+ else
+ rc = do_set_int(strvec, int_ptr, 0, INT_MAX, file, line_nr,
+ buff);
+ if (rc == 0 && *int_ptr == 0)
*int_ptr = UOZ_ZERO;
FREE(buff);
@@ -1130,14 +1139,12 @@ max_fds_handler(struct config *conf, vector strvec, const char *file,
/* Assume safe limit */
max_fds = 4096;
}
- if (strlen(buff) == 3 &&
- !strcmp(buff, "max"))
- conf->max_fds = max_fds;
- else
- conf->max_fds = atoi(buff);
-
- if (conf->max_fds > max_fds)
+ if (!strcmp(buff, "max")) {
conf->max_fds = max_fds;
+ r = 0;
+ } else
+ r = do_set_int(strvec, &conf->max_fds, 0, max_fds, file,
+ line_nr, buff);
FREE(buff);
@@ -1206,6 +1213,7 @@ declare_mp_snprint(rr_weight, print_rr_weight)
static int
set_pgfailback(vector strvec, void *ptr, const char *file, int line_nr)
{
+ int rc = 0;
int *int_ptr = (int *)ptr;
char * buff;
@@ -1220,11 +1228,11 @@ set_pgfailback(vector strvec, void *ptr, const char *file, int line_nr)
else if (strlen(buff) == 10 && !strcmp(buff, "followover"))
*int_ptr = -FAILBACK_FOLLOWOVER;
else
- *int_ptr = atoi(buff);
+ rc = do_set_int(strvec, ptr, 0, INT_MAX, file, line_nr, buff);
FREE(buff);
- return 0;
+ return rc;
}
int
@@ -1256,6 +1264,7 @@ declare_mp_snprint(pgfailback, print_pgfailback)
static int
no_path_retry_helper(vector strvec, void *ptr, const char *file, int line_nr)
{
+ int rc = 0;
int *int_ptr = (int *)ptr;
char * buff;
@@ -1267,11 +1276,11 @@ no_path_retry_helper(vector strvec, void *ptr, const char *file, int line_nr)
*int_ptr = NO_PATH_RETRY_FAIL;
else if (!strcmp(buff, "queue"))
*int_ptr = NO_PATH_RETRY_QUEUE;
- else if ((*int_ptr = atoi(buff)) < 1)
- *int_ptr = NO_PATH_RETRY_UNDEF;
+ else
+ rc = do_set_int(strvec, ptr, 1, INT_MAX, file, line_nr, buff);
FREE(buff);
- return 0;
+ return rc;
}
int
@@ -1416,6 +1425,7 @@ snprint_mp_reservation_key (struct config *conf, char * buff, int len,
static int
set_off_int_undef(vector strvec, void *ptr, const char *file, int line_nr)
{
+ int rc =0;
int *int_ptr = (int *)ptr;
char * buff;
@@ -1425,11 +1435,11 @@ set_off_int_undef(vector strvec, void *ptr, const char *file, int line_nr)
if (!strcmp(buff, "no") || !strcmp(buff, "0"))
*int_ptr = NU_NO;
- else if ((*int_ptr = atoi(buff)) < 1)
- *int_ptr = NU_UNDEF;
+ else
+ rc = do_set_int(strvec, ptr, 1, INT_MAX, file, line_nr, buff);
FREE(buff);
- return 0;
+ return rc;
}
int

View File

@ -0,0 +1,201 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Benjamin Marzinski <bmarzins@redhat.com>
Date: Mon, 4 Oct 2021 16:52:55 -0500
Subject: [PATCH] libmultipath: cleanup invalid config handling
Add error reporting to the remaining config handlers. If the value is
invalid, do not change the existing config option's value. Also print
an error whenever 0 is returned for an invalid value. When the handler
returns 1, config processing already fails with an error message.
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
libmultipath/dict.c | 73 +++++++++++++++++++++++++++++++--------------
1 file changed, 51 insertions(+), 22 deletions(-)
diff --git a/libmultipath/dict.c b/libmultipath/dict.c
index 6330836a..b255322e 100644
--- a/libmultipath/dict.c
+++ b/libmultipath/dict.c
@@ -212,8 +212,11 @@ set_yes_no(vector strvec, void *ptr, const char *file, int line_nr)
if (strcmp(buff, "yes") == 0 || strcmp(buff, "1") == 0)
*int_ptr = YN_YES;
- else
+ else if (strcmp(buff, "no") == 0 || strcmp(buff, "0") == 0)
*int_ptr = YN_NO;
+ else
+ condlog(1, "%s line %d, invalid value for %s: \"%s\"",
+ file, line_nr, (char*)VECTOR_SLOT(strvec, 0), buff);
FREE(buff);
return 0;
@@ -234,7 +237,8 @@ set_yes_no_undef(vector strvec, void *ptr, const char *file, int line_nr)
else if (strcmp(buff, "yes") == 0 || strcmp(buff, "1") == 0)
*int_ptr = YNU_YES;
else
- *int_ptr = YNU_UNDEF;
+ condlog(1, "%s line %d, invalid value for %s: \"%s\"",
+ file, line_nr, (char*)VECTOR_SLOT(strvec, 0), buff);
FREE(buff);
return 0;
@@ -523,9 +527,6 @@ def_find_multipaths_handler(struct config *conf, vector strvec,
char *buff;
int i;
- if (set_yes_no_undef(strvec, &conf->find_multipaths, file, line_nr) == 0 && conf->find_multipaths != FIND_MULTIPATHS_UNDEF)
- return 0;
-
buff = set_value(strvec);
if (!buff)
return 1;
@@ -538,9 +539,14 @@ def_find_multipaths_handler(struct config *conf, vector strvec,
}
}
- if (conf->find_multipaths == YNU_UNDEF) {
- condlog(0, "illegal value for find_multipaths: %s", buff);
- conf->find_multipaths = DEFAULT_FIND_MULTIPATHS;
+ if (i >= __FIND_MULTIPATHS_LAST) {
+ if (strcmp(buff, "no") == 0 || strcmp(buff, "0") == 0)
+ conf->find_multipaths = FIND_MULTIPATHS_OFF;
+ else if (strcmp(buff, "yes") == 0 || strcmp(buff, "1") == 0)
+ conf->find_multipaths = FIND_MULTIPATHS_ON;
+ else
+ condlog(1, "%s line %d, invalid value for find_multipaths: \"%s\"",
+ file, line_nr, buff);
}
FREE(buff);
@@ -591,8 +597,10 @@ static int uid_attrs_handler(struct config *conf, vector strvec,
if (!val)
return 1;
if (parse_uid_attrs(val, conf))
- condlog(1, "error parsing uid_attrs: \"%s\"", val);
- condlog(3, "parsed %d uid_attrs", VECTOR_SIZE(&conf->uid_attrs));
+ condlog(1, "%s line %d,error parsing uid_attrs: \"%s\"", file,
+ line_nr, val);
+ else
+ condlog(4, "parsed %d uid_attrs", VECTOR_SIZE(&conf->uid_attrs));
FREE(val);
return 0;
}
@@ -811,8 +819,11 @@ def_config_dir_handler(struct config *conf, vector strvec, const char *file,
int line_nr)
{
/* this is only valid in the main config file */
- if (conf->processed_main_config)
+ if (conf->processed_main_config) {
+ condlog(1, "%s line %d, config_dir option only valid in /etc/multipath.conf",
+ file, line_nr);
return 0;
+ }
return set_path(strvec, &conf->config_dir, file, line_nr);
}
declare_def_snprint(config_dir, print_str)
@@ -872,7 +883,9 @@ set_mode(vector strvec, void *ptr, int *flags, const char *file, int line_nr)
if (sscanf(buff, "%o", &mode) == 1 && mode <= 0777) {
*flags |= (1 << ATTR_MODE);
*mode_ptr = mode;
- }
+ } else
+ condlog(1, "%s line %d, invalid value for mode: \"%s\"",
+ file, line_nr, buff);
FREE(buff);
return 0;
@@ -897,7 +910,9 @@ set_uid(vector strvec, void *ptr, int *flags, const char *file, int line_nr)
else if (sscanf(buff, "%u", &uid) == 1){
*flags |= (1 << ATTR_UID);
*uid_ptr = uid;
- }
+ } else
+ condlog(1, "%s line %d, invalid value for uid: \"%s\"",
+ file, line_nr, buff);
FREE(buff);
return 0;
@@ -923,7 +938,9 @@ set_gid(vector strvec, void *ptr, int *flags, const char *file, int line_nr)
else if (sscanf(buff, "%u", &gid) == 1){
*flags |= (1 << ATTR_GID);
*gid_ptr = gid;
- }
+ } else
+ condlog(1, "%s line %d, invalid value for gid: \"%s\"",
+ file, line_nr, buff);
FREE(buff);
return 0;
}
@@ -1026,7 +1043,8 @@ set_dev_loss(vector strvec, void *ptr, const char *file, int line_nr)
if (!strcmp(buff, "infinity"))
*uint_ptr = MAX_DEV_LOSS_TMO;
else if (sscanf(buff, "%u", uint_ptr) != 1)
- *uint_ptr = 0;
+ condlog(1, "%s line %d, invalid value for dev_loss_tmo: \"%s\"",
+ file, line_nr, buff);
FREE(buff);
return 0;
@@ -1060,13 +1078,19 @@ static int
set_pgpolicy(vector strvec, void *ptr, const char *file, int line_nr)
{
char * buff;
+ int policy;
int *int_ptr = (int *)ptr;
buff = set_value(strvec);
if (!buff)
return 1;
- *int_ptr = get_pgpolicy_id(buff);
+ policy = get_pgpolicy_id(buff);
+ if (policy != IOPOLICY_UNDEF)
+ *int_ptr = policy;
+ else
+ condlog(1, "%s line %d, invalid value for path_grouping_policy: \"%s\"",
+ file, line_nr, buff);
FREE(buff);
return 0;
@@ -1179,10 +1203,11 @@ set_rr_weight(vector strvec, void *ptr, const char *file, int line_nr)
if (!strcmp(buff, "priorities"))
*int_ptr = RR_WEIGHT_PRIO;
-
- if (!strcmp(buff, "uniform"))
+ else if (!strcmp(buff, "uniform"))
*int_ptr = RR_WEIGHT_NONE;
-
+ else
+ condlog(1, "%s line %d, invalid value for rr_weight: \"%s\"",
+ file, line_nr, buff);
FREE(buff);
return 0;
@@ -1318,10 +1343,13 @@ def_log_checker_err_handler(struct config *conf, vector strvec,
if (!buff)
return 1;
- if (strlen(buff) == 4 && !strcmp(buff, "once"))
+ if (!strcmp(buff, "once"))
conf->log_checker_err = LOG_CHKR_ERR_ONCE;
- else if (strlen(buff) == 6 && !strcmp(buff, "always"))
+ else if (!strcmp(buff, "always"))
conf->log_checker_err = LOG_CHKR_ERR_ALWAYS;
+ else
+ condlog(1, "%s line %d, invalid value for log_checker_err: \"%s\"",
+ file, line_nr, buff);
free(buff);
return 0;
@@ -1585,7 +1613,8 @@ hw_vpd_vendor_handler(struct config *conf, vector strvec, const char *file,
goto out;
}
}
- hwe->vpd_vendor_id = 0;
+ condlog(1, "%s line %d, invalid value for vpd_vendor: \"%s\"",
+ file, line_nr, buff);
out:
FREE(buff);
return 0;

View File

@ -0,0 +1,218 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Benjamin Marzinski <bmarzins@redhat.com>
Date: Thu, 11 Nov 2021 17:37:05 -0600
Subject: [PATCH] libmultipath: don't return error on invalid values
do_set_int and set_uint return 1 for invalid values. This can cause
multipath to fail completely, while reading the config. The config
handlers should only return a non-zero value if there is an internal
error, not if there is just an invalid value.
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
libmultipath/dict.c | 64 ++++++++++++++++++---------------------------
1 file changed, 25 insertions(+), 39 deletions(-)
diff --git a/libmultipath/dict.c b/libmultipath/dict.c
index b255322e..5a0255b0 100644
--- a/libmultipath/dict.c
+++ b/libmultipath/dict.c
@@ -29,7 +29,7 @@
#include "mpath_cmd.h"
#include "dict.h"
-static int
+static void
do_set_int(vector strvec, void *ptr, int min, int max, const char *file,
int line_nr, char *buff)
{
@@ -44,7 +44,7 @@ do_set_int(vector strvec, void *ptr, int min, int max, const char *file,
if (*buff == '\0' || *eptr != '\0') {
condlog(1, "%s line %d, invalid value for %s: \"%s\"",
file, line_nr, (char*)VECTOR_SLOT(strvec, 0), buff);
- return 1;
+ return;
}
if (res > max || res < min) {
res = (res > max) ? max : min;
@@ -53,7 +53,7 @@ do_set_int(vector strvec, void *ptr, int min, int max, const char *file,
(res == max)? "large" : "small", res);
}
*int_ptr = res;
- return 0;
+ return;
}
static int
@@ -61,16 +61,15 @@ set_int(vector strvec, void *ptr, int min, int max, const char *file,
int line_nr)
{
char *buff;
- int rc;
buff = set_value(strvec);
if (!buff)
return 1;
- rc = do_set_int(strvec, ptr, min, max, file, line_nr, buff);
+ do_set_int(strvec, ptr, min, max, file, line_nr, buff);
FREE(buff);
- return rc;
+ return 0;
}
static int
@@ -79,7 +78,6 @@ set_uint(vector strvec, void *ptr, const char *file, int line_nr)
unsigned int *uint_ptr = (unsigned int *)ptr;
char *buff, *eptr, *p;
unsigned long res;
- int rc;
buff = set_value(strvec);
if (!buff)
@@ -92,17 +90,14 @@ set_uint(vector strvec, void *ptr, const char *file, int line_nr)
if (eptr > buff)
while (isspace(*eptr))
eptr++;
- if (*buff == '\0' || *eptr != '\0' || !isdigit(*p) || res > UINT_MAX) {
+ if (*buff == '\0' || *eptr != '\0' || !isdigit(*p) || res > UINT_MAX)
condlog(1, "%s line %d, invalid value for %s: \"%s\"",
file, line_nr, (char*)VECTOR_SLOT(strvec, 0), buff);
- rc = 1;
- } else {
- rc = 0;
+ else
*uint_ptr = res;
- }
FREE(buff);
- return rc;
+ return 0;
}
static int
@@ -990,7 +985,6 @@ declare_mp_attr_snprint(gid, print_gid)
static int
set_undef_off_zero(vector strvec, void *ptr, const char *file, int line_nr)
{
- int rc = 0;
char * buff;
int *int_ptr = (int *)ptr;
@@ -1000,11 +994,10 @@ set_undef_off_zero(vector strvec, void *ptr, const char *file, int line_nr)
if (strcmp(buff, "off") == 0)
*int_ptr = UOZ_OFF;
- else
- rc = do_set_int(strvec, int_ptr, 0, INT_MAX, file, line_nr,
- buff);
- if (rc == 0 && *int_ptr == 0)
+ else if (strcmp(buff, "0") == 0)
*int_ptr = UOZ_ZERO;
+ else
+ do_set_int(strvec, int_ptr, 1, INT_MAX, file, line_nr, buff);
FREE(buff);
return 0;
@@ -1151,28 +1144,24 @@ max_fds_handler(struct config *conf, vector strvec, const char *file,
int line_nr)
{
char * buff;
- int r = 0, max_fds;
+ int max_fds;
buff = set_value(strvec);
if (!buff)
return 1;
- r = get_sys_max_fds(&max_fds);
- if (r) {
- /* Assume safe limit */
- max_fds = 4096;
- }
- if (!strcmp(buff, "max")) {
+ if (get_sys_max_fds(&max_fds) != 0)
+ max_fds = 4096; /* Assume safe limit */
+ if (!strcmp(buff, "max"))
conf->max_fds = max_fds;
- r = 0;
- } else
- r = do_set_int(strvec, &conf->max_fds, 0, max_fds, file,
- line_nr, buff);
+ else
+ do_set_int(strvec, &conf->max_fds, 0, max_fds, file, line_nr,
+ buff);
FREE(buff);
- return r;
+ return 0;
}
static int
@@ -1238,7 +1227,6 @@ declare_mp_snprint(rr_weight, print_rr_weight)
static int
set_pgfailback(vector strvec, void *ptr, const char *file, int line_nr)
{
- int rc = 0;
int *int_ptr = (int *)ptr;
char * buff;
@@ -1253,11 +1241,11 @@ set_pgfailback(vector strvec, void *ptr, const char *file, int line_nr)
else if (strlen(buff) == 10 && !strcmp(buff, "followover"))
*int_ptr = -FAILBACK_FOLLOWOVER;
else
- rc = do_set_int(strvec, ptr, 0, INT_MAX, file, line_nr, buff);
+ do_set_int(strvec, ptr, 0, INT_MAX, file, line_nr, buff);
FREE(buff);
- return rc;
+ return 0;
}
int
@@ -1289,7 +1277,6 @@ declare_mp_snprint(pgfailback, print_pgfailback)
static int
no_path_retry_helper(vector strvec, void *ptr, const char *file, int line_nr)
{
- int rc = 0;
int *int_ptr = (int *)ptr;
char * buff;
@@ -1302,10 +1289,10 @@ no_path_retry_helper(vector strvec, void *ptr, const char *file, int line_nr)
else if (!strcmp(buff, "queue"))
*int_ptr = NO_PATH_RETRY_QUEUE;
else
- rc = do_set_int(strvec, ptr, 1, INT_MAX, file, line_nr, buff);
+ do_set_int(strvec, ptr, 1, INT_MAX, file, line_nr, buff);
FREE(buff);
- return rc;
+ return 0;
}
int
@@ -1453,7 +1440,6 @@ snprint_mp_reservation_key (struct config *conf, char * buff, int len,
static int
set_off_int_undef(vector strvec, void *ptr, const char *file, int line_nr)
{
- int rc =0;
int *int_ptr = (int *)ptr;
char * buff;
@@ -1464,10 +1450,10 @@ set_off_int_undef(vector strvec, void *ptr, const char *file, int line_nr)
if (!strcmp(buff, "no") || !strcmp(buff, "0"))
*int_ptr = NU_NO;
else
- rc = do_set_int(strvec, ptr, 1, INT_MAX, file, line_nr, buff);
+ do_set_int(strvec, ptr, 1, INT_MAX, file, line_nr, buff);
FREE(buff);
- return rc;
+ return 0;
}
int

View File

@ -0,0 +1,115 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Benjamin Marzinski <bmarzins@redhat.com>
Date: Mon, 15 Nov 2021 10:54:35 -0600
Subject: [PATCH] multipathd: avoid unnecessary path read-only reloads
A mulitpath device can only be reloaded read/write when all paths are
read/write. Also, whenever a read-only device is rescanned, the scsi
subsystem will first unconditionally issue a uevent with DISK_RO=0
before checking the read-only status, and if it the device is still
read-only, issuing another uevent with DISK_RO=1. These uevents cause
pointless reloads when read-only paths are rescanned. To avoid this,
check to see if all paths are read/write before changing a multipath
device from read-only to read/write.
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
libmultipath/sysfs.c | 22 ++++++++++++++++++++++
libmultipath/sysfs.h | 1 +
multipathd/main.c | 31 ++++++++++++++++++++++++++++++-
3 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/libmultipath/sysfs.c b/libmultipath/sysfs.c
index 62ec2ed7..a57bd60e 100644
--- a/libmultipath/sysfs.c
+++ b/libmultipath/sysfs.c
@@ -236,6 +236,28 @@ sysfs_get_size (struct path *pp, unsigned long long * size)
return 0;
}
+int
+sysfs_get_ro (struct path *pp)
+{
+ int ro;
+ char buff[3]; /* Either "0\n\0" or "1\n\0" */
+
+ if (!pp->udev)
+ return -1;
+
+ if (sysfs_attr_get_value(pp->udev, "ro", buff, sizeof(buff)) <= 0) {
+ condlog(3, "%s: Cannot read ro attribute in sysfs", pp->dev);
+ return -1;
+ }
+
+ if (sscanf(buff, "%d\n", &ro) != 1 || ro < 0 || ro > 1) {
+ condlog(3, "%s: Cannot parse ro attribute", pp->dev);
+ return -1;
+ }
+
+ return ro;
+}
+
int sysfs_check_holders(char * check_devt, char * new_devt)
{
unsigned int major, new_minor, table_minor;
diff --git a/libmultipath/sysfs.h b/libmultipath/sysfs.h
index 9ae30b39..91092e44 100644
--- a/libmultipath/sysfs.h
+++ b/libmultipath/sysfs.h
@@ -13,6 +13,7 @@ ssize_t sysfs_attr_get_value(struct udev_device *dev, const char *attr_name,
ssize_t sysfs_bin_attr_get_value(struct udev_device *dev, const char *attr_name,
unsigned char * value, size_t value_len);
int sysfs_get_size (struct path *pp, unsigned long long * size);
+int sysfs_get_ro(struct path *pp);
int sysfs_check_holders(char * check_devt, char * new_devt);
bool sysfs_is_multipathed(const struct path *pp);
#endif
diff --git a/multipathd/main.c b/multipathd/main.c
index 823b53a2..e2b9d546 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -1256,6 +1256,35 @@ fail:
return PATH_REMOVE_FAILED;
}
+static bool
+needs_ro_update(struct multipath *mpp, int ro)
+{
+ struct pathgroup * pgp;
+ struct path * pp;
+ unsigned int i, j;
+ struct dm_info *dmi = NULL;
+
+ if (!mpp || ro < 0)
+ return false;
+ dm_get_info(mpp->alias, &dmi);
+ if (!dmi) /* assume we do need to reload the device */
+ return true;
+ if (dmi->read_only == ro) {
+ free(dmi);
+ return false;
+ }
+ free(dmi);
+ if (ro == 1)
+ return true;
+ vector_foreach_slot (mpp->pg, pgp, i) {
+ vector_foreach_slot (pgp->paths, pp, j) {
+ if (sysfs_get_ro(pp) == 1)
+ return false;
+ }
+ }
+ return true;
+}
+
static int
uev_update_path (struct uevent *uev, struct vectors * vecs)
{
@@ -1321,7 +1350,7 @@ uev_update_path (struct uevent *uev, struct vectors * vecs)
}
ro = uevent_get_disk_ro(uev);
- if (mpp && ro >= 0) {
+ if (needs_ro_update(mpp, ro)) {
condlog(2, "%s: update path write_protect to '%d' (uevent)", uev->kernel, ro);
if (mpp->wait_for_udev)

View File

@ -0,0 +1,133 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Benjamin Marzinski <bmarzins@redhat.com>
Date: Mon, 17 Jan 2022 14:45:38 -0600
Subject: [PATCH] libmultipath: make helper function to trigger path uevents
Pull the code that checks if a path needs to trigger a uevent, and
triggers, out of trigger_paths_udev_change() and into a new function,
trigger_path_udev_change(). This function will be used separately by
a future patch. No functional changes.
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
libmultipath/configure.c | 79 +++++++++++++++++++++-------------------
libmultipath/configure.h | 1 +
2 files changed, 43 insertions(+), 37 deletions(-)
diff --git a/libmultipath/configure.c b/libmultipath/configure.c
index 9c8d3e34..9a9890f5 100644
--- a/libmultipath/configure.c
+++ b/libmultipath/configure.c
@@ -545,11 +545,8 @@ unref:
}
void
-trigger_paths_udev_change(struct multipath *mpp, bool is_mpath)
+trigger_path_udev_change(struct path *pp, bool is_mpath)
{
- struct pathgroup *pgp;
- struct path *pp;
- int i, j;
/*
* If a path changes from multipath to non-multipath, we must
* synthesize an artificial "add" event, otherwise the LVM2 rules
@@ -557,6 +554,45 @@ trigger_paths_udev_change(struct multipath *mpp, bool is_mpath)
* irritate ourselves with an "add", so use "change".
*/
const char *action = is_mpath ? "change" : "add";
+ const char *env;
+
+ if (!pp->udev)
+ return;
+ /*
+ * Paths that are already classified as multipath
+ * members don't need another uevent.
+ */
+ env = udev_device_get_property_value(
+ pp->udev, "DM_MULTIPATH_DEVICE_PATH");
+
+ if (is_mpath && env != NULL && !strcmp(env, "1")) {
+ /*
+ * If FIND_MULTIPATHS_WAIT_UNTIL is not "0",
+ * path is in "maybe" state and timer is running
+ * Send uevent now (see multipath.rules).
+ */
+ env = udev_device_get_property_value(
+ pp->udev, "FIND_MULTIPATHS_WAIT_UNTIL");
+ if (env == NULL || !strcmp(env, "0"))
+ return;
+ } else if (!is_mpath &&
+ (env == NULL || !strcmp(env, "0")))
+ return;
+
+ condlog(3, "triggering %s uevent for %s (is %smultipath member)",
+ action, pp->dev, is_mpath ? "" : "no ");
+ sysfs_attr_set_value(pp->udev, "uevent",
+ action, strlen(action));
+ trigger_partitions_udev_change(pp->udev, action,
+ strlen(action));
+}
+
+void
+trigger_paths_udev_change(struct multipath *mpp, bool is_mpath)
+{
+ struct pathgroup *pgp;
+ struct path *pp;
+ int i, j;
if (!mpp || !mpp->pg)
return;
@@ -564,39 +600,8 @@ trigger_paths_udev_change(struct multipath *mpp, bool is_mpath)
vector_foreach_slot (mpp->pg, pgp, i) {
if (!pgp->paths)
continue;
- vector_foreach_slot(pgp->paths, pp, j) {
- const char *env;
-
- if (!pp->udev)
- continue;
- /*
- * Paths that are already classified as multipath
- * members don't need another uevent.
- */
- env = udev_device_get_property_value(
- pp->udev, "DM_MULTIPATH_DEVICE_PATH");
-
- if (is_mpath && env != NULL && !strcmp(env, "1")) {
- /*
- * If FIND_MULTIPATHS_WAIT_UNTIL is not "0",
- * path is in "maybe" state and timer is running
- * Send uevent now (see multipath.rules).
- */
- env = udev_device_get_property_value(
- pp->udev, "FIND_MULTIPATHS_WAIT_UNTIL");
- if (env == NULL || !strcmp(env, "0"))
- continue;
- } else if (!is_mpath &&
- (env == NULL || !strcmp(env, "0")))
- continue;
-
- condlog(3, "triggering %s uevent for %s (is %smultipath member)",
- action, pp->dev, is_mpath ? "" : "no ");
- sysfs_attr_set_value(pp->udev, "uevent",
- action, strlen(action));
- trigger_partitions_udev_change(pp->udev, action,
- strlen(action));
- }
+ vector_foreach_slot(pgp->paths, pp, j)
+ trigger_path_udev_change(pp, is_mpath);
}
mpp->needs_paths_uevent = 0;
diff --git a/libmultipath/configure.h b/libmultipath/configure.h
index 8a266d31..5cf08d45 100644
--- a/libmultipath/configure.h
+++ b/libmultipath/configure.h
@@ -56,6 +56,7 @@ int get_refwwid (enum mpath_cmds cmd, char * dev, enum devtypes dev_type,
vector pathvec, char **wwid);
int reload_map(struct vectors *vecs, struct multipath *mpp, int refresh, int is_daemon);
struct udev_device *get_udev_device(const char *dev, enum devtypes dev_type);
+void trigger_path_udev_change(struct path *pp, bool is_mpath);
void trigger_paths_udev_change(struct multipath *mpp, bool is_mpath);
void trigger_partitions_udev_change(struct udev_device *dev, const char *action,
int len);

View File

@ -0,0 +1,40 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Benjamin Marzinski <bmarzins@redhat.com>
Date: Mon, 17 Jan 2022 16:46:18 -0600
Subject: [PATCH] multipathd: trigger udev change on path addition
When a multipath device is created for the first time, there is a window
where some path devices way be added to the multipath device, but never
claimed in udev. This can allow other device owners, like lvm, to think
they can use the device.
When a multipath device is first created, all the existing paths that
are not claimed by multipath have a uevent triggered so that they can
get claimed. After that, multipath assumes all future paths added to the
multipath device will have been claimed by multipath, since the device's
WWID is now in the wwids file. This doesn't work for any paths that
have already been processed by the multipath.rules udev rules before
the multipath device was created.
To close this window, when path device is added, and a matching
multipath device already exists, multipathd now checks if the device is
claimed by multipath, and if not, triggers a uevent to claim it.
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
multipathd/main.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/multipathd/main.c b/multipathd/main.c
index e2b9d546..f4b79882 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -1005,6 +1005,8 @@ ev_add_path (struct path * pp, struct vectors * vecs, int need_do_map)
free_path(pp);
return 1;
}
+ if (mpp)
+ trigger_path_udev_change(pp, true);
if (mpp && mpp->wait_for_udev &&
(pathcount(mpp, PATH_UP) > 0 ||
(pathcount(mpp, PATH_GHOST) > 0 &&

View File

@ -0,0 +1,149 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Benjamin Marzinski <bmarzins@redhat.com>
Date: Wed, 2 Feb 2022 17:00:21 -0600
Subject: [PATCH] RH: add support to mpathconf for setting arbitrary default
options
mpathconf now supports --option <name>:[<value>] for setting, changing,
or removing options from the defaults section of multipath.conf.
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
multipath/mpathconf | 58 ++++++++++++++++++++++++++++++++++++++++---
multipath/mpathconf.8 | 7 ++++++
2 files changed, 62 insertions(+), 3 deletions(-)
diff --git a/multipath/mpathconf b/multipath/mpathconf
index 5f2285ab..870512c0 100644
--- a/multipath/mpathconf
+++ b/multipath/mpathconf
@@ -17,7 +17,7 @@
# This program was largely ripped off from lvmconf
#
-unset ENABLE FIND FRIENDLY PROPERTY FOREIGN MODULE MULTIPATHD HAVE_DISABLE HAVE_WWID_DISABLE HAVE_FIND HAVE_BLACKLIST HAVE_EXCEPTIONS HAVE_DEFAULTS HAVE_FRIENDLY HAVE_PROPERTY HAVE_FOREIGN HAVE_MULTIPATHD HAVE_MODULE HAVE_OUTFILE SHOW_STATUS CHANGED_CONFIG WWID_LIST
+unset ENABLE FIND FRIENDLY PROPERTY FOREIGN MODULE MULTIPATHD HAVE_DISABLE HAVE_WWID_DISABLE HAVE_FIND HAVE_BLACKLIST HAVE_EXCEPTIONS HAVE_DEFAULTS HAVE_FRIENDLY HAVE_PROPERTY HAVE_FOREIGN HAVE_MULTIPATHD HAVE_MODULE HAVE_OUTFILE SHOW_STATUS CHANGED_CONFIG WWID_LIST HAVE_OPTION OPTION_NAME OPTION_VALUE
DEFAULT_CONFIG="# device-mapper-multipath configuration file
@@ -57,6 +57,7 @@ function usage
echo "Set find_multipaths (Default y): --find_multipaths <yes|no|strict|greedy|smart>"
echo "Set default property blacklist (Default y): --property_blacklist <y|n>"
echo "Set enable_foreign to show foreign devices (Default n): --enable_foreign <y|n>"
+ echo "Add/Change/Remove option in defaults section: --option <option_name>:<value>"
echo "Load the dm-multipath modules on enable (Default y): --with_module <y|n>"
echo "start/stop/reload multipathd (Default n): --with_multipathd <y|n>"
echo "select output file (Default /etc/multipath.conf): --outfile <FILE>"
@@ -167,6 +168,20 @@ function parse_args
exit 1
fi
;;
+ --option)
+ if [ -n "$2" ]; then
+ OPTION_NAME=$(echo $2 | cut -s -f1 -d:)
+ OPTION_VALUE=$(echo $2 | cut -s -f2 -d:)
+ if [ -z "$OPTION_NAME" ]; then
+ usage
+ exit 1
+ fi
+ shift 2
+ else
+ usage
+ exit 1
+ fi
+ ;;
--enable_foreign)
if [ -n "$2" ]; then
FOREIGN=$2
@@ -213,12 +228,15 @@ function parse_args
function validate_args
{
- if [ "$ENABLE" = "0" ] && [ -n "$FRIENDLY" -o -n "$FIND" -o -n "$PROPERTY" -o -n "$MODULE" ]; then
+ if [ "$ENABLE" = "0" ] && [ -n "$FRIENDLY" -o -n "$FIND" -o -n "$PROPERTY" -o -n "$MODULE" -o -n "$FOREIGN" -o -n "$OPTION_NAME" ]; then
echo "ignoring extra parameters on disable"
FRIENDLY=""
FIND=""
PROPERTY=""
MODULE=""
+ FOREIGN=""
+ OPTION_NAME=""
+ OPTION_VALUE=""
fi
if [ -n "$FRIENDLY" ] && [ "$FRIENDLY" != "y" -a "$FRIENDLY" != "n" ]; then
echo "--user_friendly_names must be either 'y' or 'n'"
@@ -240,7 +258,19 @@ function validate_args
echo "--enable_foreign must be either 'y' or 'n'"
exit 1
fi
- if [ -z "$ENABLE" -a -z "$FIND" -a -z "$FRIENDLY" -a -z "$PROPERTY" -a -z "$FOREIGN" ]; then
+ if [ -n "$OPTION_NAME" ]; then
+ if [[ $OPTION_NAME =~ [[:space:]]|#|\"|!|\{|\} ]]; then
+ echo "--option name \"$OPTION_NAME\" is invalid"
+ exit 1
+ elif [[ $OPTION_VALUE =~ \"|#|!|\{|\} ]]; then
+ echo "--option value \"$OPTION_VALUE\" is invalid"
+ exit 1
+ fi
+ if [[ $OPTION_VALUE =~ [[:space:]] ]]; then
+ OPTION_VALUE=\"$OPTION_VALUE\"
+ fi
+ fi
+ if [ -z "$ENABLE" -a -z "$FIND" -a -z "$FRIENDLY" -a -z "$PROPERTY" -a -z "$FOREIGN" -a -z "$OPTION_NAME" ]; then
SHOW_STATUS=1
fi
if [ -n "$MODULE" ] && [ "$MODULE" != "y" -a "$MODULE" != "n" ]; then
@@ -349,6 +379,13 @@ if [ "$HAVE_DEFAULTS" = "1" ]; then
elif sed -n '/^defaults[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*enable_foreign" ; then
HAVE_FOREIGN=2
fi
+ if [ -n "$OPTION_NAME" ]; then
+ if sed -n '/^defaults[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q '^[[:space:]]*'"$OPTION_NAME"'[[:space:]][[:space:]]*'"$OPTION_VALUE" ; then
+ HAVE_OPTION=1
+ elif sed -n '/^defaults[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q '^[[:space:]]*'"$OPTION_NAME"'\([[:space:]].*\)\?$' ; then
+ HAVE_OPTION=0
+ fi
+ fi
fi
if [ "$HAVE_EXCEPTIONS" = "1" ]; then
@@ -523,6 +560,21 @@ elif [ "$FOREIGN" = "n" ]; then
fi
fi
+if [ -n "$OPTION_NAME" -a -n "$OPTION_VALUE" ]; then
+ if [ -z "$HAVE_OPTION" ]; then
+ sed -i '/^defaults[[:space:]]*{/ a\
+ '"$OPTION_NAME"' '"$OPTION_VALUE"'
+' $TMPFILE
+ CHANGED_CONFIG=1
+ elif [ "$HAVE_OPTION" = 0 ]; then
+ sed -i '/^defaults[[:space:]]*{/,/^}/ s/^[[:space:]]*'"$OPTION_NAME"'\([[:space:]].*\)\?$/ '"$OPTION_NAME"' '"$OPTION_VALUE"'/' $TMPFILE
+ CHANGED_CONFIG=1
+ fi
+elif [ -n "$OPTION_NAME" -a -n "$HAVE_OPTION" ]; then
+ sed -i '/^defaults[[:space:]]*{/,/^}/{/^[[:space:]]*'"$OPTION_NAME"'\([[:space:]].*\)\?$/d}' $TMPFILE
+ CHANGED_CONFIG=1
+fi
+
if [ -f "$OUTPUTFILE" ]; then
cp $OUTPUTFILE $OUTPUTFILE.old
if [ $? != 0 ]; then
diff --git a/multipath/mpathconf.8 b/multipath/mpathconf.8
index 83515eb4..63fe633e 100644
--- a/multipath/mpathconf.8
+++ b/multipath/mpathconf.8
@@ -101,6 +101,13 @@ to the
defaults section. if set to \fBy\fP, this removes the line, if present. This
command can be used along with any other command.
.TP
+.B --option \fB<option_name>:[<value>]\fP
+Sets the defaults section option \fB<option_name>\fP to \fB<value>\fP. If the
+option was not previously set in the defaults section, it is added. If it was
+set, its value is changed to \fB<value>\fP. If \fB<value>\fP is left blank,
+then the option is removed from the defaults section, if was set there. This
+command can be used along with any other command.
+.TP
.B --outfile \fB<filename>\fP
Write the resulting multipath configuration to \fB<filename>\fP instead of
\fB/etc/multipath.conf\fP.

View File

@ -1,7 +1,7 @@
Summary: Tools to manage multipath devices using device-mapper Summary: Tools to manage multipath devices using device-mapper
Name: device-mapper-multipath Name: device-mapper-multipath
Version: 0.8.4 Version: 0.8.4
Release: 17%{?dist} Release: 22%{?dist}
License: GPLv2 License: GPLv2
Group: System Environment/Base Group: System Environment/Base
URL: http://christophe.varoqui.free.fr/ URL: http://christophe.varoqui.free.fr/
@ -87,6 +87,20 @@ Patch00073: 0073-multipath.conf-fix-typo-in-checker_timeout-descripti.patch
Patch00074: 0074-mpathpersist-fail-commands-when-no-usable-paths-exis.patch Patch00074: 0074-mpathpersist-fail-commands-when-no-usable-paths-exis.patch
Patch00075: 0075-multipath-print-warning-if-multipathd-is-not-running.patch Patch00075: 0075-multipath-print-warning-if-multipathd-is-not-running.patch
Patch00076: 0076-multipathd-don-t-access-path-if-it-was-deleted.patch Patch00076: 0076-multipathd-don-t-access-path-if-it-was-deleted.patch
Patch00077: 0077-multipathd.socket-add-missing-conditions-from-servic.patch
Patch00078: 0078-libmulitpath-add-section-name-to-invalid-keyword-out.patch
Patch00079: 0079-libmultipath-use-typedef-for-keyword-handler-and-pri.patch
Patch00080: 0080-libmultipath-print-the-correct-file-when-parsing-fai.patch
Patch00081: 0081-libmultipath-pass-file-and-line-number-to-keyword-ha.patch
Patch00082: 0082-libmultipath-make-set_int-take-a-range-for-valid-val.patch
Patch00083: 0083-libmultipath-improve-checks-for-set_str.patch
Patch00084: 0084-libmultipath-split-set_int-to-enable-reuse.patch
Patch00085: 0085-libmultipath-cleanup-invalid-config-handling.patch
Patch00086: 0086-libmultipath-don-t-return-error-on-invalid-values.patch
Patch00087: 0087-multipathd-avoid-unnecessary-path-read-only-reloads.patch
Patch00088: 0088-libmultipath-make-helper-function-to-trigger-path-ue.patch
Patch00089: 0089-multipathd-trigger-udev-change-on-path-addition.patch
Patch00090: 0090-RH-add-support-to-mpathconf-for-setting-arbitrary-de.patch
# runtime # runtime
Requires: %{name}-libs = %{version}-%{release} Requires: %{name}-libs = %{version}-%{release}
@ -288,6 +302,40 @@ fi
%{_pkgconfdir}/libdmmp.pc %{_pkgconfdir}/libdmmp.pc
%changelog %changelog
* Mon Feb 7 2022 Benjamin Marzinski <bmarzins@redhat.com> 0.8.4-22
- Add 0090-RH-add-support-to-mpathconf-for-setting-arbitrary-de.patch
- Resolves: bz #1981240
* Tue Jan 18 2022 Benjamin Marzinski <bmarzins@redhat.com> 0.8.4-21
- Add 0088-libmultipath-make-helper-function-to-trigger-path-ue.patch
- Add 0089-multipathd-trigger-udev-change-on-path-addition.patch
- Resolves: bz #1862032
* Thu Nov 18 2021 Benjamin Marzinski <bmarzins@redhat.com> 0.8.4-20
- Add 0079-libmultipath-use-typedef-for-keyword-handler-and-pri.patch
- Add 0080-libmultipath-print-the-correct-file-when-parsing-fai.patch
- Add 0081-libmultipath-pass-file-and-line-number-to-keyword-ha.patch
- Add 0082-libmultipath-make-set_int-take-a-range-for-valid-val.patch
- Add 0083-libmultipath-improve-checks-for-set_str.patch
- Add 0084-libmultipath-split-set_int-to-enable-reuse.patch
- Add 0085-libmultipath-cleanup-invalid-config-handling.patch
- Add 0086-libmultipath-don-t-return-error-on-invalid-values.patch
* Above 8 patches fix bz #1900595
- Add 0087-multipathd-avoid-unnecessary-path-read-only-reloads.patch
* Fixes bz #2009624
- Resolves: bz #1900595, #2009624, #2021823
* Thu Oct 28 2021 Benjamin Marzinski <bmarzins@redhat.com> 0.8.4-19
- Fix multipath_conf_syntax test to work with bz #1918150
- Resolves: bz #1918150
* Thu Oct 7 2021 Benjamin Marzinski <bmarzins@redhat.com> 0.8.4-18
- Add 0077-multipathd.socket-add-missing-conditions-from-servic.patch
* Fixes bz #2008101
- Add 0078-libmulitpath-add-section-name-to-invalid-keyword-out.patch
* Fixes bz #1918150
- Resolves: bz #1918150, #2008101
* Fri Jul 23 2021 Benjamin Marzinski <bmarzins@redhat.com> 0.8.4-17 * Fri Jul 23 2021 Benjamin Marzinski <bmarzins@redhat.com> 0.8.4-17
- Add 0074-mpathpersist-fail-commands-when-no-usable-paths-exis.patch - Add 0074-mpathpersist-fail-commands-when-no-usable-paths-exis.patch
* Fixes bz #1984723 * Fixes bz #1984723