Blame SOURCES/0084-libmultipath-split-set_int-to-enable-reuse.patch

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