Blame SOURCES/0042-libmultipath-move-fast_io_fail-defines-to-structs.h.patch

60b218
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
60b218
From: Benjamin Marzinski <bmarzins@redhat.com>
60b218
Date: Mon, 12 Oct 2020 16:06:11 -0500
60b218
Subject: [PATCH] libmultipath: move fast_io_fail defines to structs.h
60b218
60b218
Since fast_io_fail is part of the multipath struct, its symbolic values
60b218
belong in structs.h. Also, make it an instance of a general enum, which
60b218
will be used again in future patches, and change the set/print functions
60b218
which use it to use the general enum instead.
60b218
60b218
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
60b218
---
60b218
 libmultipath/config.h  |  8 --------
60b218
 libmultipath/dict.c    | 30 +++++++++++++++---------------
60b218
 libmultipath/dict.h    |  2 +-
60b218
 libmultipath/propsel.c |  2 +-
60b218
 libmultipath/structs.h | 17 +++++++++++++++++
60b218
 5 files changed, 34 insertions(+), 25 deletions(-)
60b218
60b218
diff --git a/libmultipath/config.h b/libmultipath/config.h
60b218
index 160867cd..f38c7639 100644
60b218
--- a/libmultipath/config.h
60b218
+++ b/libmultipath/config.h
60b218
@@ -11,14 +11,6 @@
60b218
 #define ORIGIN_CONFIG  1
60b218
 #define ORIGIN_NO_CONFIG 2
60b218
 
60b218
-/*
60b218
- * In kernel, fast_io_fail == 0 means immediate failure on rport delete.
60b218
- * OTOH '0' means not-configured in various places in multipath-tools.
60b218
- */
60b218
-#define MP_FAST_IO_FAIL_UNSET (0)
60b218
-#define MP_FAST_IO_FAIL_OFF (-1)
60b218
-#define MP_FAST_IO_FAIL_ZERO (-2)
60b218
-
60b218
 enum devtypes {
60b218
 	DEV_NONE,
60b218
 	DEV_DEVT,
60b218
diff --git a/libmultipath/dict.c b/libmultipath/dict.c
60b218
index 184d4b22..ce8e1cda 100644
60b218
--- a/libmultipath/dict.c
60b218
+++ b/libmultipath/dict.c
60b218
@@ -834,7 +834,7 @@ declare_mp_attr_handler(gid, set_gid)
60b218
 declare_mp_attr_snprint(gid, print_gid)
60b218
 
60b218
 static int
60b218
-set_fast_io_fail(vector strvec, void *ptr)
60b218
+set_undef_off_zero(vector strvec, void *ptr)
60b218
 {
60b218
 	char * buff;
60b218
 	int *int_ptr = (int *)ptr;
60b218
@@ -844,36 +844,36 @@ set_fast_io_fail(vector strvec, void *ptr)
60b218
 		return 1;
60b218
 
60b218
 	if (strcmp(buff, "off") == 0)
60b218
-		*int_ptr = MP_FAST_IO_FAIL_OFF;
60b218
+		*int_ptr = UOZ_OFF;
60b218
 	else if (sscanf(buff, "%d", int_ptr) != 1 ||
60b218
-		 *int_ptr < MP_FAST_IO_FAIL_ZERO)
60b218
-		*int_ptr = MP_FAST_IO_FAIL_UNSET;
60b218
+		 *int_ptr < UOZ_ZERO)
60b218
+		*int_ptr = UOZ_UNDEF;
60b218
 	else if (*int_ptr == 0)
60b218
-		*int_ptr = MP_FAST_IO_FAIL_ZERO;
60b218
+		*int_ptr = UOZ_ZERO;
60b218
 
60b218
 	FREE(buff);
60b218
 	return 0;
60b218
 }
60b218
 
60b218
 int
60b218
-print_fast_io_fail(char * buff, int len, long v)
60b218
+print_undef_off_zero(char * buff, int len, long v)
60b218
 {
60b218
-	if (v == MP_FAST_IO_FAIL_UNSET)
60b218
+	if (v == UOZ_UNDEF)
60b218
 		return 0;
60b218
-	if (v == MP_FAST_IO_FAIL_OFF)
60b218
+	if (v == UOZ_OFF)
60b218
 		return snprintf(buff, len, "\"off\"");
60b218
-	if (v == MP_FAST_IO_FAIL_ZERO)
60b218
+	if (v == UOZ_ZERO)
60b218
 		return snprintf(buff, len, "0");
60b218
 	return snprintf(buff, len, "%ld", v);
60b218
 }
60b218
 
60b218
-declare_def_handler(fast_io_fail, set_fast_io_fail)
60b218
-declare_def_snprint_defint(fast_io_fail, print_fast_io_fail,
60b218
+declare_def_handler(fast_io_fail, set_undef_off_zero)
60b218
+declare_def_snprint_defint(fast_io_fail, print_undef_off_zero,
60b218
 			   DEFAULT_FAST_IO_FAIL)
60b218
-declare_ovr_handler(fast_io_fail, set_fast_io_fail)
60b218
-declare_ovr_snprint(fast_io_fail, print_fast_io_fail)
60b218
-declare_hw_handler(fast_io_fail, set_fast_io_fail)
60b218
-declare_hw_snprint(fast_io_fail, print_fast_io_fail)
60b218
+declare_ovr_handler(fast_io_fail, set_undef_off_zero)
60b218
+declare_ovr_snprint(fast_io_fail, print_undef_off_zero)
60b218
+declare_hw_handler(fast_io_fail, set_undef_off_zero)
60b218
+declare_hw_snprint(fast_io_fail, print_undef_off_zero)
60b218
 
60b218
 static int
60b218
 set_dev_loss(vector strvec, void *ptr)
60b218
diff --git a/libmultipath/dict.h b/libmultipath/dict.h
60b218
index a40ac66f..a917e1ca 100644
60b218
--- a/libmultipath/dict.h
60b218
+++ b/libmultipath/dict.h
60b218
@@ -13,7 +13,7 @@ int print_rr_weight(char *buff, int len, long v);
60b218
 int print_pgfailback(char *buff, int len, long v);
60b218
 int print_pgpolicy(char *buff, int len, long v);
60b218
 int print_no_path_retry(char *buff, int len, long v);
60b218
-int print_fast_io_fail(char *buff, int len, long v);
60b218
+int print_undef_off_zero(char *buff, int len, long v);
60b218
 int print_dev_loss(char *buff, int len, unsigned long v);
60b218
 int print_reservation_key(char * buff, int len, struct be64 key, uint8_t
60b218
 			  flags, int source);
60b218
diff --git a/libmultipath/propsel.c b/libmultipath/propsel.c
60b218
index d7febec6..725db2b1 100644
60b218
--- a/libmultipath/propsel.c
60b218
+++ b/libmultipath/propsel.c
60b218
@@ -755,7 +755,7 @@ int select_fast_io_fail(struct config *conf, struct multipath *mp)
60b218
 	mp_set_conf(fast_io_fail);
60b218
 	mp_set_default(fast_io_fail, DEFAULT_FAST_IO_FAIL);
60b218
 out:
60b218
-	print_fast_io_fail(buff, 12, mp->fast_io_fail);
60b218
+	print_undef_off_zero(buff, 12, mp->fast_io_fail);
60b218
 	condlog(3, "%s: fast_io_fail_tmo = %s %s", mp->alias, buff, origin);
60b218
 	return 0;
60b218
 }
60b218
diff --git a/libmultipath/structs.h b/libmultipath/structs.h
60b218
index 8e78b8c0..29209984 100644
60b218
--- a/libmultipath/structs.h
60b218
+++ b/libmultipath/structs.h
60b218
@@ -229,6 +229,23 @@ enum vpd_vendor_ids {
60b218
 	VPD_VP_ARRAY_SIZE, /* This must remain the last entry */
60b218
 };
60b218
 
60b218
+/*
60b218
+ * Multipath treats 0 as undefined for optional config parameters.
60b218
+ * Use this for cases where 0 is a valid option for systems multipath
60b218
+ * is communicating with
60b218
+ */
60b218
+enum undefined_off_zero {
60b218
+	UOZ_UNDEF = 0,
60b218
+	UOZ_OFF = -1,
60b218
+	UOZ_ZERO = -2,
60b218
+};
60b218
+
60b218
+enum fast_io_fail_states {
60b218
+	MP_FAST_IO_FAIL_UNSET = UOZ_UNDEF,
60b218
+	MP_FAST_IO_FAIL_OFF = UOZ_OFF,
60b218
+	MP_FAST_IO_FAIL_ZERO = UOZ_ZERO,
60b218
+};
60b218
+
60b218
 struct vpd_vendor_page {
60b218
 	int pg;
60b218
 	const char *name;
60b218
-- 
60b218
2.17.2
60b218