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