|
|
e65fa3 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
e65fa3 |
From: Benjamin Marzinski <bmarzins@redhat.com>
|
|
|
e65fa3 |
Date: Mon, 4 Oct 2021 16:52:55 -0500
|
|
|
e65fa3 |
Subject: [PATCH] libmultipath: cleanup invalid config handling
|
|
|
e65fa3 |
|
|
|
e65fa3 |
Add error reporting to the remaining config handlers. If the value is
|
|
|
e65fa3 |
invalid, do not change the existing config option's value. Also print
|
|
|
e65fa3 |
an error whenever 0 is returned for an invalid value. When the handler
|
|
|
e65fa3 |
returns 1, config processing already fails with an error message.
|
|
|
e65fa3 |
|
|
|
e65fa3 |
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
|
|
|
e65fa3 |
---
|
|
|
e65fa3 |
libmultipath/dict.c | 73 +++++++++++++++++++++++++++++++--------------
|
|
|
e65fa3 |
1 file changed, 51 insertions(+), 22 deletions(-)
|
|
|
e65fa3 |
|
|
|
e65fa3 |
diff --git a/libmultipath/dict.c b/libmultipath/dict.c
|
|
|
e65fa3 |
index 68647061..c534d703 100644
|
|
|
e65fa3 |
--- a/libmultipath/dict.c
|
|
|
e65fa3 |
+++ b/libmultipath/dict.c
|
|
|
e65fa3 |
@@ -199,8 +199,11 @@ set_yes_no(vector strvec, void *ptr, const char *file, int line_nr)
|
|
|
e65fa3 |
|
|
|
e65fa3 |
if (strcmp(buff, "yes") == 0 || strcmp(buff, "1") == 0)
|
|
|
e65fa3 |
*int_ptr = YN_YES;
|
|
|
e65fa3 |
- else
|
|
|
e65fa3 |
+ else if (strcmp(buff, "no") == 0 || strcmp(buff, "0") == 0)
|
|
|
e65fa3 |
*int_ptr = YN_NO;
|
|
|
e65fa3 |
+ else
|
|
|
e65fa3 |
+ condlog(1, "%s line %d, invalid value for %s: \"%s\"",
|
|
|
e65fa3 |
+ file, line_nr, (char*)VECTOR_SLOT(strvec, 0), buff);
|
|
|
e65fa3 |
|
|
|
e65fa3 |
FREE(buff);
|
|
|
e65fa3 |
return 0;
|
|
|
e65fa3 |
@@ -221,7 +224,8 @@ set_yes_no_undef(vector strvec, void *ptr, const char *file, int line_nr)
|
|
|
e65fa3 |
else if (strcmp(buff, "yes") == 0 || strcmp(buff, "1") == 0)
|
|
|
e65fa3 |
*int_ptr = YNU_YES;
|
|
|
e65fa3 |
else
|
|
|
e65fa3 |
- *int_ptr = YNU_UNDEF;
|
|
|
e65fa3 |
+ condlog(1, "%s line %d, invalid value for %s: \"%s\"",
|
|
|
e65fa3 |
+ file, line_nr, (char*)VECTOR_SLOT(strvec, 0), buff);
|
|
|
e65fa3 |
|
|
|
e65fa3 |
FREE(buff);
|
|
|
e65fa3 |
return 0;
|
|
|
e65fa3 |
@@ -480,9 +484,6 @@ def_find_multipaths_handler(struct config *conf, vector strvec,
|
|
|
e65fa3 |
char *buff;
|
|
|
e65fa3 |
int i;
|
|
|
e65fa3 |
|
|
|
e65fa3 |
- if (set_yes_no_undef(strvec, &conf->find_multipaths, file, line_nr) == 0 && conf->find_multipaths != FIND_MULTIPATHS_UNDEF)
|
|
|
e65fa3 |
- return 0;
|
|
|
e65fa3 |
-
|
|
|
e65fa3 |
buff = set_value(strvec);
|
|
|
e65fa3 |
if (!buff)
|
|
|
e65fa3 |
return 1;
|
|
|
e65fa3 |
@@ -495,9 +496,14 @@ def_find_multipaths_handler(struct config *conf, vector strvec,
|
|
|
e65fa3 |
}
|
|
|
e65fa3 |
}
|
|
|
e65fa3 |
|
|
|
e65fa3 |
- if (conf->find_multipaths == YNU_UNDEF) {
|
|
|
e65fa3 |
- condlog(0, "illegal value for find_multipaths: %s", buff);
|
|
|
e65fa3 |
- conf->find_multipaths = DEFAULT_FIND_MULTIPATHS;
|
|
|
e65fa3 |
+ if (i >= __FIND_MULTIPATHS_LAST) {
|
|
|
e65fa3 |
+ if (strcmp(buff, "no") == 0 || strcmp(buff, "0") == 0)
|
|
|
e65fa3 |
+ conf->find_multipaths = FIND_MULTIPATHS_OFF;
|
|
|
e65fa3 |
+ else if (strcmp(buff, "yes") == 0 || strcmp(buff, "1") == 0)
|
|
|
e65fa3 |
+ conf->find_multipaths = FIND_MULTIPATHS_ON;
|
|
|
e65fa3 |
+ else
|
|
|
e65fa3 |
+ condlog(1, "%s line %d, invalid value for find_multipaths: \"%s\"",
|
|
|
e65fa3 |
+ file, line_nr, buff);
|
|
|
e65fa3 |
}
|
|
|
e65fa3 |
|
|
|
e65fa3 |
FREE(buff);
|
|
|
e65fa3 |
@@ -546,8 +552,10 @@ static int uid_attrs_handler(struct config *conf, vector strvec,
|
|
|
e65fa3 |
if (!val)
|
|
|
e65fa3 |
return 1;
|
|
|
e65fa3 |
if (parse_uid_attrs(val, conf))
|
|
|
e65fa3 |
- condlog(1, "error parsing uid_attrs: \"%s\"", val);
|
|
|
e65fa3 |
- condlog(3, "parsed %d uid_attrs", VECTOR_SIZE(&conf->uid_attrs));
|
|
|
e65fa3 |
+ condlog(1, "%s line %d,error parsing uid_attrs: \"%s\"", file,
|
|
|
e65fa3 |
+ line_nr, val);
|
|
|
e65fa3 |
+ else
|
|
|
e65fa3 |
+ condlog(4, "parsed %d uid_attrs", VECTOR_SIZE(&conf->uid_attrs));
|
|
|
e65fa3 |
FREE(val);
|
|
|
e65fa3 |
return 0;
|
|
|
e65fa3 |
}
|
|
|
e65fa3 |
@@ -775,8 +783,11 @@ def_config_dir_handler(struct config *conf, vector strvec, const char *file,
|
|
|
e65fa3 |
int line_nr)
|
|
|
e65fa3 |
{
|
|
|
e65fa3 |
/* this is only valid in the main config file */
|
|
|
e65fa3 |
- if (conf->processed_main_config)
|
|
|
e65fa3 |
+ if (conf->processed_main_config) {
|
|
|
e65fa3 |
+ condlog(1, "%s line %d, config_dir option only valid in /etc/multipath.conf",
|
|
|
e65fa3 |
+ file, line_nr);
|
|
|
e65fa3 |
return 0;
|
|
|
e65fa3 |
+ }
|
|
|
e65fa3 |
condlog(2, "%s line %d, \"config_dir\" is deprecated and will be disabled in a future release",
|
|
|
e65fa3 |
file, line_nr);
|
|
|
e65fa3 |
return set_path(strvec, &conf->config_dir, file, line_nr);
|
|
|
e65fa3 |
@@ -836,7 +847,9 @@ set_mode(vector strvec, void *ptr, int *flags, const char *file, int line_nr)
|
|
|
e65fa3 |
if (sscanf(buff, "%o", &mode) == 1 && mode <= 0777) {
|
|
|
e65fa3 |
*flags |= (1 << ATTR_MODE);
|
|
|
e65fa3 |
*mode_ptr = mode;
|
|
|
e65fa3 |
- }
|
|
|
e65fa3 |
+ } else
|
|
|
e65fa3 |
+ condlog(1, "%s line %d, invalid value for mode: \"%s\"",
|
|
|
e65fa3 |
+ file, line_nr, buff);
|
|
|
e65fa3 |
|
|
|
e65fa3 |
FREE(buff);
|
|
|
e65fa3 |
return 0;
|
|
|
e65fa3 |
@@ -861,7 +874,9 @@ set_uid(vector strvec, void *ptr, int *flags, const char *file, int line_nr)
|
|
|
e65fa3 |
else if (sscanf(buff, "%u", &uid) == 1){
|
|
|
e65fa3 |
*flags |= (1 << ATTR_UID);
|
|
|
e65fa3 |
*uid_ptr = uid;
|
|
|
e65fa3 |
- }
|
|
|
e65fa3 |
+ } else
|
|
|
e65fa3 |
+ condlog(1, "%s line %d, invalid value for uid: \"%s\"",
|
|
|
e65fa3 |
+ file, line_nr, buff);
|
|
|
e65fa3 |
|
|
|
e65fa3 |
FREE(buff);
|
|
|
e65fa3 |
return 0;
|
|
|
e65fa3 |
@@ -887,7 +902,9 @@ set_gid(vector strvec, void *ptr, int *flags, const char *file, int line_nr)
|
|
|
e65fa3 |
else if (sscanf(buff, "%u", &gid) == 1){
|
|
|
e65fa3 |
*flags |= (1 << ATTR_GID);
|
|
|
e65fa3 |
*gid_ptr = gid;
|
|
|
e65fa3 |
- }
|
|
|
e65fa3 |
+ } else
|
|
|
e65fa3 |
+ condlog(1, "%s line %d, invalid value for gid: \"%s\"",
|
|
|
e65fa3 |
+ file, line_nr, buff);
|
|
|
e65fa3 |
FREE(buff);
|
|
|
e65fa3 |
return 0;
|
|
|
e65fa3 |
}
|
|
|
e65fa3 |
@@ -989,7 +1006,8 @@ set_dev_loss(vector strvec, void *ptr, const char *file, int line_nr)
|
|
|
e65fa3 |
if (!strcmp(buff, "infinity"))
|
|
|
e65fa3 |
*uint_ptr = MAX_DEV_LOSS_TMO;
|
|
|
e65fa3 |
else if (sscanf(buff, "%u", uint_ptr) != 1)
|
|
|
e65fa3 |
- *uint_ptr = DEV_LOSS_TMO_UNSET;
|
|
|
e65fa3 |
+ condlog(1, "%s line %d, invalid value for dev_loss_tmo: \"%s\"",
|
|
|
e65fa3 |
+ file, line_nr, buff);
|
|
|
e65fa3 |
|
|
|
e65fa3 |
FREE(buff);
|
|
|
e65fa3 |
return 0;
|
|
|
e65fa3 |
@@ -1023,13 +1041,19 @@ static int
|
|
|
e65fa3 |
set_pgpolicy(vector strvec, void *ptr, const char *file, int line_nr)
|
|
|
e65fa3 |
{
|
|
|
e65fa3 |
char * buff;
|
|
|
e65fa3 |
+ int policy;
|
|
|
e65fa3 |
int *int_ptr = (int *)ptr;
|
|
|
e65fa3 |
|
|
|
e65fa3 |
buff = set_value(strvec);
|
|
|
e65fa3 |
if (!buff)
|
|
|
e65fa3 |
return 1;
|
|
|
e65fa3 |
|
|
|
e65fa3 |
- *int_ptr = get_pgpolicy_id(buff);
|
|
|
e65fa3 |
+ policy = get_pgpolicy_id(buff);
|
|
|
e65fa3 |
+ if (policy != IOPOLICY_UNDEF)
|
|
|
e65fa3 |
+ *int_ptr = policy;
|
|
|
e65fa3 |
+ else
|
|
|
e65fa3 |
+ condlog(1, "%s line %d, invalid value for path_grouping_policy: \"%s\"",
|
|
|
e65fa3 |
+ file, line_nr, buff);
|
|
|
e65fa3 |
FREE(buff);
|
|
|
e65fa3 |
|
|
|
e65fa3 |
return 0;
|
|
|
e65fa3 |
@@ -1142,10 +1166,11 @@ set_rr_weight(vector strvec, void *ptr, const char *file, int line_nr)
|
|
|
e65fa3 |
|
|
|
e65fa3 |
if (!strcmp(buff, "priorities"))
|
|
|
e65fa3 |
*int_ptr = RR_WEIGHT_PRIO;
|
|
|
e65fa3 |
-
|
|
|
e65fa3 |
- if (!strcmp(buff, "uniform"))
|
|
|
e65fa3 |
+ else if (!strcmp(buff, "uniform"))
|
|
|
e65fa3 |
*int_ptr = RR_WEIGHT_NONE;
|
|
|
e65fa3 |
-
|
|
|
e65fa3 |
+ else
|
|
|
e65fa3 |
+ condlog(1, "%s line %d, invalid value for rr_weight: \"%s\"",
|
|
|
e65fa3 |
+ file, line_nr, buff);
|
|
|
e65fa3 |
FREE(buff);
|
|
|
e65fa3 |
|
|
|
e65fa3 |
return 0;
|
|
|
e65fa3 |
@@ -1281,10 +1306,13 @@ def_log_checker_err_handler(struct config *conf, vector strvec,
|
|
|
e65fa3 |
if (!buff)
|
|
|
e65fa3 |
return 1;
|
|
|
e65fa3 |
|
|
|
e65fa3 |
- if (strlen(buff) == 4 && !strcmp(buff, "once"))
|
|
|
e65fa3 |
+ if (!strcmp(buff, "once"))
|
|
|
e65fa3 |
conf->log_checker_err = LOG_CHKR_ERR_ONCE;
|
|
|
e65fa3 |
- else if (strlen(buff) == 6 && !strcmp(buff, "always"))
|
|
|
e65fa3 |
+ else if (!strcmp(buff, "always"))
|
|
|
e65fa3 |
conf->log_checker_err = LOG_CHKR_ERR_ALWAYS;
|
|
|
e65fa3 |
+ else
|
|
|
e65fa3 |
+ condlog(1, "%s line %d, invalid value for log_checker_err: \"%s\"",
|
|
|
e65fa3 |
+ file, line_nr, buff);
|
|
|
e65fa3 |
|
|
|
e65fa3 |
free(buff);
|
|
|
e65fa3 |
return 0;
|
|
|
e65fa3 |
@@ -1545,7 +1573,8 @@ hw_vpd_vendor_handler(struct config *conf, vector strvec, const char *file,
|
|
|
e65fa3 |
goto out;
|
|
|
e65fa3 |
}
|
|
|
e65fa3 |
}
|
|
|
e65fa3 |
- hwe->vpd_vendor_id = 0;
|
|
|
e65fa3 |
+ condlog(1, "%s line %d, invalid value for vpd_vendor: \"%s\"",
|
|
|
e65fa3 |
+ file, line_nr, buff);
|
|
|
e65fa3 |
out:
|
|
|
e65fa3 |
FREE(buff);
|
|
|
e65fa3 |
return 0;
|