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

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