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