[dm-devel] [PATCH 7/9] libmultipath: add procotol subsection to overrides

Benjamin Marzinski bmarzins at redhat.com
Tue Apr 12 01:59:57 UTC 2022


Add a procotol subsection to the overrides section, just like the one in
the device subsection. This allows users to a protocol specific
parameters to all device configurations.

Signed-off-by: Benjamin Marzinski <bmarzins at redhat.com>
---
 libmultipath/dict.c    | 76 ++++++++++++++++++++++++++++++++----------
 libmultipath/print.c   |  5 +++
 libmultipath/propsel.c | 29 ++++++++++++++--
 3 files changed, 90 insertions(+), 20 deletions(-)

diff --git a/libmultipath/dict.c b/libmultipath/dict.c
index 04d86ee3..4923b8d2 100644
--- a/libmultipath/dict.c
+++ b/libmultipath/dict.c
@@ -386,6 +386,20 @@ snprint_ovr_ ## option (struct config *conf, struct strbuf *buff,	\
 	return function (buff, conf->overrides->option);		\
 }
 
+#define declare_ovr_pc_handler(option, function)			\
+static int								\
+ovr_pc_ ## option ## _handler (struct config *conf, vector strvec,	\
+			       const char *file, int line_nr)		\
+{									\
+	struct pcentry *pce;						\
+	if (!conf->overrides || !conf->overrides->pctable)		\
+		return 1;						\
+	pce = VECTOR_LAST_SLOT(conf->overrides->pctable);		\
+	if (!pce)							\
+		return 1;						\
+	return function (strvec, &pce->option, file, line_nr);		\
+}
+
 #define declare_mp_handler(option, function)				\
 static int								\
 mp_ ## option ## _handler (struct config *conf, vector strvec,		\
@@ -417,10 +431,10 @@ snprint_mp_ ## option (struct config *conf, struct strbuf *buff,	\
 	return function(buff, mpe->option);				\
 }
 
-#define declare_pc_handler(option, function)				\
+#define declare_hw_pc_handler(option, function)				\
 static int								\
-pc_ ## option ## _handler (struct config *conf, vector strvec,		\
-			   const char *file, int line_nr)		\
+hw_pc_ ## option ## _handler (struct config *conf, vector strvec,	\
+			       const char *file, int line_nr)		\
 {									\
 	struct pcentry *pce;						\
 	struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);		\
@@ -1070,7 +1084,8 @@ declare_ovr_handler(fast_io_fail, set_undef_off_zero)
 declare_ovr_snprint(fast_io_fail, print_undef_off_zero)
 declare_hw_handler(fast_io_fail, set_undef_off_zero)
 declare_hw_snprint(fast_io_fail, print_undef_off_zero)
-declare_pc_handler(fast_io_fail, set_undef_off_zero)
+declare_hw_pc_handler(fast_io_fail, set_undef_off_zero)
+declare_ovr_pc_handler(fast_io_fail, set_undef_off_zero)
 declare_pc_snprint(fast_io_fail, print_undef_off_zero)
 
 static int
@@ -1109,7 +1124,8 @@ declare_ovr_handler(dev_loss, set_dev_loss)
 declare_ovr_snprint(dev_loss, print_dev_loss)
 declare_hw_handler(dev_loss, set_dev_loss)
 declare_hw_snprint(dev_loss, print_dev_loss)
-declare_pc_handler(dev_loss, set_dev_loss)
+declare_hw_pc_handler(dev_loss, set_dev_loss)
+declare_ovr_pc_handler(dev_loss, set_dev_loss)
 declare_pc_snprint(dev_loss, print_dev_loss)
 
 declare_def_handler(eh_deadline, set_undef_off_zero)
@@ -1118,7 +1134,8 @@ declare_ovr_handler(eh_deadline, set_undef_off_zero)
 declare_ovr_snprint(eh_deadline, print_undef_off_zero)
 declare_hw_handler(eh_deadline, set_undef_off_zero)
 declare_hw_snprint(eh_deadline, print_undef_off_zero)
-declare_pc_handler(eh_deadline, set_undef_off_zero)
+declare_hw_pc_handler(eh_deadline, set_undef_off_zero)
+declare_ovr_pc_handler(eh_deadline, set_undef_off_zero)
 declare_pc_snprint(eh_deadline, print_undef_off_zero)
 
 static int
@@ -1929,13 +1946,9 @@ declare_mp_snprint(alias, print_str)
 
 
 static int
-protocol_handler(struct config *conf, vector strvec, const char *file,
-               int line_nr)
+_protocol_handler(struct hwentry *hwe)
 {
 	struct pcentry *pce;
-	struct hwentry *hwe = VECTOR_LAST_SLOT(conf->hwtable);
-	if (!hwe)
-		return 1;
 
 	if (!hwe->pctable && !(hwe->pctable = vector_alloc()))
 		return 1;
@@ -1952,6 +1965,27 @@ protocol_handler(struct config *conf, vector strvec, const char *file,
 	return 0;
 }
 
+static int
+hw_protocol_handler(struct config *conf, vector strvec, const char *file,
+		    int line_nr)
+{
+	struct hwentry *hwe = VECTOR_LAST_SLOT(conf->hwtable);
+	if (!hwe)
+		return 1;
+
+	return _protocol_handler(hwe);
+}
+
+static int
+ovr_protocol_handler(struct config *conf, vector strvec, const char *file,
+		     int line_nr)
+{
+	if (!conf->overrides)
+		return 1;
+
+	return _protocol_handler(conf->overrides);
+}
+
 static int
 set_protocol_type(vector strvec, void *ptr, const char *file, int line_nr)
 {
@@ -1986,7 +2020,8 @@ print_protocol_type(struct strbuf *buff, int type)
 	return append_strbuf_quoted(buff, protocol_name[type]);
 }
 
-declare_pc_handler(type, set_protocol_type)
+declare_hw_pc_handler(type, set_protocol_type)
+declare_ovr_pc_handler(type, set_protocol_type)
 declare_pc_snprint(type, print_protocol_type)
 
 /*
@@ -2188,12 +2223,12 @@ init_keywords(vector keywords)
 	install_keyword("all_tg_pt", &hw_all_tg_pt_handler, &snprint_hw_all_tg_pt);
 	install_keyword("vpd_vendor", &hw_vpd_vendor_handler, &snprint_hw_vpd_vendor);
 	install_keyword("recheck_wwid", &hw_recheck_wwid_handler, &snprint_hw_recheck_wwid);
-	install_keyword_multi("protocol", &protocol_handler, NULL);
+	install_keyword_multi("protocol", &hw_protocol_handler, NULL);
 	install_sublevel();
-	install_keyword("type", &pc_type_handler, &snprint_pc_type);
-	install_keyword("fast_io_fail_tmo", &pc_fast_io_fail_handler, &snprint_pc_fast_io_fail);
-	install_keyword("dev_loss_tmo", &pc_dev_loss_handler, &snprint_pc_dev_loss);
-	install_keyword("eh_deadline", &pc_eh_deadline_handler, &snprint_pc_eh_deadline);
+	install_keyword("type", &hw_pc_type_handler, &snprint_pc_type);
+	install_keyword("fast_io_fail_tmo", &hw_pc_fast_io_fail_handler, &snprint_pc_fast_io_fail);
+	install_keyword("dev_loss_tmo", &hw_pc_dev_loss_handler, &snprint_pc_dev_loss);
+	install_keyword("eh_deadline", &hw_pc_eh_deadline_handler, &snprint_pc_eh_deadline);
 	install_sublevel_end();
 	install_sublevel_end();
 
@@ -2237,6 +2272,13 @@ init_keywords(vector keywords)
 	install_keyword("ghost_delay", &ovr_ghost_delay_handler, &snprint_ovr_ghost_delay);
 	install_keyword("all_tg_pt", &ovr_all_tg_pt_handler, &snprint_ovr_all_tg_pt);
 	install_keyword("recheck_wwid", &ovr_recheck_wwid_handler, &snprint_ovr_recheck_wwid);
+	install_keyword_multi("protocol", &ovr_protocol_handler, NULL);
+	install_sublevel();
+	install_keyword("type", &ovr_pc_type_handler, &snprint_pc_type);
+	install_keyword("fast_io_fail_tmo", &ovr_pc_fast_io_fail_handler, &snprint_pc_fast_io_fail);
+	install_keyword("dev_loss_tmo", &ovr_pc_dev_loss_handler, &snprint_pc_dev_loss);
+	install_keyword("eh_deadline", &ovr_pc_eh_deadline_handler, &snprint_pc_eh_deadline);
+	install_sublevel_end();
 
 	install_keyword_root("multipaths", &multipaths_handler);
 	install_keyword_multi("multipath", &multipath_handler, NULL);
diff --git a/libmultipath/print.c b/libmultipath/print.c
index 093e43aa..93df0b0c 100644
--- a/libmultipath/print.c
+++ b/libmultipath/print.c
@@ -1618,6 +1618,11 @@ static int snprint_overrides(const struct config *conf, struct strbuf *buff,
 		if ((rc = snprint_keyword(buff, "\t%k %v\n", kw, NULL)) < 0)
 			return rc;
 	}
+
+	if (overrides->pctable &&
+	    (rc = snprint_pctable(conf, buff, 1, overrides->pctable,
+				   rootkw)) < 0)
+		return rc;
 out:
 	if ((rc = append_strbuf_str(buff, "}\n")) < 0)
 		return rc;
diff --git a/libmultipath/propsel.c b/libmultipath/propsel.c
index 762b7fcb..90a160f1 100644
--- a/libmultipath/propsel.c
+++ b/libmultipath/propsel.c
@@ -81,6 +81,8 @@ static const char conf_origin[] =
 	"(setting: multipath.conf defaults/devices section)";
 static const char overrides_origin[] =
 	"(setting: multipath.conf overrides section)";
+static const char overrides_pce_origin[] =
+	"(setting: multipath.conf overrides protocol section)";
 static const char cmdline_origin[] =
 	"(setting: multipath command line [-p] flag)";
 static const char autodetect_origin[] =
@@ -170,6 +172,27 @@ do {									\
 	}								\
 } while (0)
 
+#define pp_set_ovr_pce(var)						\
+do {									\
+	struct pcentry *_pce;						\
+	int _i;								\
+									\
+	if (conf->overrides) {						\
+		vector_foreach_slot(conf->overrides->pctable, _pce, _i) {	\
+			if (_pce->type == (int)bus_protocol_id(pp) && _pce->var) {	\
+				pp->var = _pce->var;			\
+				origin = overrides_pce_origin;		\
+				goto out;				\
+			}						\
+		}							\
+		if (conf->overrides->var) {				\
+			pp->var = conf->overrides->var;			\
+			origin = overrides_origin;			\
+			goto out;					\
+		}							\
+	}								\
+} while (0)
+
 int select_mode(struct config *conf, struct multipath *mp)
 {
 	const char *origin;
@@ -798,7 +821,7 @@ int select_fast_io_fail(struct config *conf, struct path *pp)
 	const char *origin;
 	STRBUF_ON_STACK(buff);
 
-	pp_set_ovr(fast_io_fail);
+	pp_set_ovr_pce(fast_io_fail);
 	pp_set_hwe_pce(fast_io_fail);
 	pp_set_conf(fast_io_fail);
 	pp_set_default(fast_io_fail, DEFAULT_FAST_IO_FAIL);
@@ -814,7 +837,7 @@ int select_dev_loss(struct config *conf, struct path *pp)
 	const char *origin;
 	STRBUF_ON_STACK(buff);
 
-	pp_set_ovr(dev_loss);
+	pp_set_ovr_pce(dev_loss);
 	pp_set_hwe_pce(dev_loss);
 	pp_set_conf(dev_loss);
 	pp->dev_loss = DEV_LOSS_TMO_UNSET;
@@ -831,7 +854,7 @@ int select_eh_deadline(struct config *conf, struct path *pp)
 	const char *origin;
 	STRBUF_ON_STACK(buff);
 
-	pp_set_ovr(eh_deadline);
+	pp_set_ovr_pce(eh_deadline);
 	pp_set_hwe_pce(eh_deadline);
 	pp_set_conf(eh_deadline);
 	pp->eh_deadline = EH_DEADLINE_UNSET;
-- 
2.17.2



More information about the dm-devel mailing list