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