Blame SOURCES/0105-multipathd-handle-fpin-events.patch

7805a0
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
7805a0
From: Muneendra Kumar <muneendra.kumar@broadcom.com>
7805a0
Date: Wed, 9 Feb 2022 19:28:10 -0800
7805a0
Subject: [PATCH] multipathd: handle fpin events
7805a0
7805a0
This patch incorporates the functionality to handle
7805a0
FPIN ELS events present as part of FCTransport daemon
7805a0
(available in EPEL8) into the multipathd. This helps us to
7805a0
reduce the response time to react and take the necessary actions
7805a0
on receiving the FPIN events.
7805a0
7805a0
This patch currently support FPIN-Li Events.
7805a0
7805a0
It adds a new thread to listen for ELS frames from driver and on
7805a0
receiving the frame payload, push the payload to a list and notify the
7805a0
fpin_els_li_consumer thread to process it.Once consumer thread is
7805a0
notified, it returns to listen for more ELS frames from driver.
7805a0
7805a0
The consumer thread process the ELS frames and moves the devices paths
7805a0
which are affected due to link integrity to marginal path groups.
7805a0
This also sets the associated portstate to marginal.
7805a0
The paths which are set to marginal path group will be unset
7805a0
on receiving the RSCN events
7805a0
7805a0
[ MW: minor fixup for 32bit compilation ]
7805a0
7805a0
Signed-off-by: Muneendra Kumar <muneendra.kumar@broadcom.com>
7805a0
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
7805a0
Signed-off-by: Martin Wilck <mwilck@suse.com>
7805a0
Reviewed-by: Martin Wilck <mwilck@suse.com>
7805a0
---
7805a0
 Makefile.inc               |  13 +
7805a0
 libmultipath/Makefile      |   5 +
7805a0
 libmultipath/dict.c        |  56 +++-
7805a0
 libmultipath/propsel.c     |  47 +++-
7805a0
 libmultipath/structs.h     |   7 +
7805a0
 multipath/multipath.conf.5 |  19 +-
7805a0
 multipathd/Makefile        |  10 +
7805a0
 multipathd/fpin.h          |  20 ++
7805a0
 multipathd/fpin_handlers.c | 541 +++++++++++++++++++++++++++++++++++++
7805a0
 multipathd/main.c          |  35 ++-
7805a0
 10 files changed, 738 insertions(+), 15 deletions(-)
7805a0
 create mode 100644 multipathd/fpin.h
7805a0
 create mode 100644 multipathd/fpin_handlers.c
7805a0
7805a0
diff --git a/Makefile.inc b/Makefile.inc
7805a0
index 220009e0..25c16f4e 100644
7805a0
--- a/Makefile.inc
7805a0
+++ b/Makefile.inc
7805a0
@@ -146,6 +146,19 @@ check_file = $(shell \
7805a0
 	echo "$$found" \
7805a0
 	)
7805a0
 
7805a0
+# Check whether a file contains a variable with name $1 in header file $2
7805a0
+check_var = $(shell \
7805a0
+	if grep -Eq "(^|[[:blank:]])$1([[:blank:]]|=|$$)" "$2"; then \
7805a0
+                found=1; \
7805a0
+                status="yes"; \
7805a0
+        else \
7805a0
+                found=0; \
7805a0
+                status="no"; \
7805a0
+        fi; \
7805a0
+        echo 1>&2 "Checking for ..  $1 in $2 ... $$status"; \
7805a0
+        echo "$$found" \
7805a0
+        )
7805a0
+
7805a0
 %.o:	%.c
7805a0
 	@echo building $@ because of $?
7805a0
 	$(CC) $(CFLAGS) -c -o $@ $<
7805a0
diff --git a/libmultipath/Makefile b/libmultipath/Makefile
7805a0
index ad690a49..49f71dfa 100644
7805a0
--- a/libmultipath/Makefile
7805a0
+++ b/libmultipath/Makefile
7805a0
@@ -40,6 +40,11 @@ ifneq ($(call check_func,dm_hold_control_dev,/usr/include/libdevmapper.h),0)
7805a0
 	CFLAGS += -DLIBDM_API_HOLD_CONTROL
7805a0
 endif
7805a0
 
7805a0
+ifneq ($(call check_var,ELS_DTAG_LNK_INTEGRITY,/usr/include/scsi/fc/fc_els.h),0)
7805a0
+	CFLAGS += -DFPIN_EVENT_HANDLER
7805a0
+endif
7805a0
+
7805a0
+
7805a0
 OBJS = memory.o parser.o vector.o devmapper.o callout.o \
7805a0
 	hwtable.o blacklist.o util.o dmparser.o config.o \
7805a0
 	structs.o discovery.o propsel.o dict.o \
7805a0
diff --git a/libmultipath/dict.c b/libmultipath/dict.c
7805a0
index 8321ec1e..d7cd94a5 100644
7805a0
--- a/libmultipath/dict.c
7805a0
+++ b/libmultipath/dict.c
7805a0
@@ -579,6 +579,59 @@ snprint_def_find_multipaths(struct config *conf, char *buff, int len,
7805a0
 			 find_multipaths_optvals[conf->find_multipaths]);
7805a0
 }
7805a0
 
7805a0
+static const char * const marginal_pathgroups_optvals[] = {
7805a0
+	[MARGINAL_PATHGROUP_OFF] = "off",
7805a0
+	[MARGINAL_PATHGROUP_ON] = "on",
7805a0
+#ifdef FPIN_EVENT_HANDLER
7805a0
+	[MARGINAL_PATHGROUP_FPIN] = "fpin",
7805a0
+#endif
7805a0
+};
7805a0
+
7805a0
+static int
7805a0
+def_marginal_pathgroups_handler(struct config *conf, vector strvec,
7805a0
+			    const char *file, int line_nr)
7805a0
+{
7805a0
+	char *buff;
7805a0
+	unsigned int i;
7805a0
+
7805a0
+	buff = set_value(strvec);
7805a0
+	if (!buff)
7805a0
+		return 1;
7805a0
+	for (i = MARGINAL_PATHGROUP_OFF;
7805a0
+	     i < ARRAY_SIZE(marginal_pathgroups_optvals); i++) {
7805a0
+		if (marginal_pathgroups_optvals[i] != NULL &&
7805a0
+		    !strcmp(buff, marginal_pathgroups_optvals[i])) {
7805a0
+			conf->marginal_pathgroups = i;
7805a0
+			break;
7805a0
+		}
7805a0
+	}
7805a0
+
7805a0
+	if (i >= ARRAY_SIZE(marginal_pathgroups_optvals)) {
7805a0
+		if (strcmp(buff, "no") == 0 || strcmp(buff, "0") == 0)
7805a0
+			conf->marginal_pathgroups = MARGINAL_PATHGROUP_OFF;
7805a0
+		else if (strcmp(buff, "yes") == 0 || strcmp(buff, "1") == 0)
7805a0
+			conf->marginal_pathgroups = MARGINAL_PATHGROUP_ON;
7805a0
+		/* This can only be true if FPIN_EVENT_HANDLER isn't defined,
7805a0
+		 * otherwise this check will have already happened above */
7805a0
+		else if (strcmp(buff, "fpin") == 0)
7805a0
+			condlog(1, "%s line %d, support for \"fpin\" is not compiled in for marginal_pathgroups", file, line_nr);
7805a0
+		else
7805a0
+			condlog(1, "%s line %d, invalid value for marginal_pathgroups: \"%s\"",
7805a0
+				file, line_nr, buff);
7805a0
+	}
7805a0
+	free(buff);
7805a0
+	return 0;
7805a0
+}
7805a0
+
7805a0
+static int
7805a0
+snprint_def_marginal_pathgroups(struct config *conf, char *buff, int len,
7805a0
+			    const void *data)
7805a0
+{
7805a0
+	return snprintf(buff, len, "\"%s\"",
7805a0
+			marginal_pathgroups_optvals[conf->marginal_pathgroups]);
7805a0
+}
7805a0
+
7805a0
+
7805a0
 declare_def_handler(selector, set_str)
7805a0
 declare_def_snprint_defstr(selector, print_str, DEFAULT_SELECTOR)
7805a0
 declare_hw_handler(selector, set_str)
7805a0
@@ -1596,9 +1649,6 @@ declare_ovr_snprint(all_tg_pt, print_yes_no_undef)
7805a0
 declare_hw_handler(all_tg_pt, set_yes_no_undef)
7805a0
 declare_hw_snprint(all_tg_pt, print_yes_no_undef)
7805a0
 
7805a0
-declare_def_handler(marginal_pathgroups, set_yes_no)
7805a0
-declare_def_snprint(marginal_pathgroups, print_yes_no)
7805a0
-
7805a0
 declare_def_handler(recheck_wwid, set_yes_no_undef)
7805a0
 declare_def_snprint_defint(recheck_wwid, print_yes_no_undef, DEFAULT_RECHECK_WWID)
7805a0
 declare_ovr_handler(recheck_wwid, set_yes_no_undef)
7805a0
diff --git a/libmultipath/propsel.c b/libmultipath/propsel.c
7805a0
index 209c1d67..be79902f 100644
7805a0
--- a/libmultipath/propsel.c
7805a0
+++ b/libmultipath/propsel.c
7805a0
@@ -85,6 +85,8 @@ static const char cmdline_origin[] =
7805a0
 	"(setting: multipath command line [-p] flag)";
7805a0
 static const char autodetect_origin[] =
7805a0
 	"(setting: storage device autodetected)";
7805a0
+static const char fpin_marginal_path_origin[] =
7805a0
+	"(setting: overridden by marginal_path_fpin)";
7805a0
 static const char marginal_path_origin[] =
7805a0
 	"(setting: implied by marginal_path check)";
7805a0
 static const char delay_watch_origin[] =
7805a0
@@ -1052,9 +1054,12 @@ int select_san_path_err_threshold(struct config *conf, struct multipath *mp)
7805a0
 	const char *origin;
7805a0
 	char buff[12];
7805a0
 
7805a0
-	if (marginal_path_check_enabled(mp)) {
7805a0
+	if (marginal_path_check_enabled(mp) || (conf->marginal_pathgroups == MARGINAL_PATHGROUP_FPIN)) {
7805a0
 		mp->san_path_err_threshold = NU_NO;
7805a0
-		origin = marginal_path_origin;
7805a0
+		if (conf->marginal_pathgroups == MARGINAL_PATHGROUP_FPIN)
7805a0
+			origin = fpin_marginal_path_origin;
7805a0
+		else
7805a0
+			origin = marginal_path_origin;
7805a0
 		goto out;
7805a0
 	}
7805a0
 	mp_set_mpe(san_path_err_threshold);
7805a0
@@ -1075,9 +1080,12 @@ int select_san_path_err_forget_rate(struct config *conf, struct multipath *mp)
7805a0
 	const char *origin;
7805a0
 	char buff[12];
7805a0
 
7805a0
-	if (marginal_path_check_enabled(mp)) {
7805a0
+	if (marginal_path_check_enabled(mp) || (conf->marginal_pathgroups == MARGINAL_PATHGROUP_FPIN)) {
7805a0
 		mp->san_path_err_forget_rate = NU_NO;
7805a0
-		origin = marginal_path_origin;
7805a0
+		if (conf->marginal_pathgroups == MARGINAL_PATHGROUP_FPIN)
7805a0
+			origin = fpin_marginal_path_origin;
7805a0
+		else
7805a0
+			origin = marginal_path_origin;
7805a0
 		goto out;
7805a0
 	}
7805a0
 	mp_set_mpe(san_path_err_forget_rate);
7805a0
@@ -1099,9 +1107,12 @@ int select_san_path_err_recovery_time(struct config *conf, struct multipath *mp)
7805a0
 	const char *origin;
7805a0
 	char buff[12];
7805a0
 
7805a0
-	if (marginal_path_check_enabled(mp)) {
7805a0
+	if (marginal_path_check_enabled(mp) || (conf->marginal_pathgroups == MARGINAL_PATHGROUP_FPIN)) {
7805a0
 		mp->san_path_err_recovery_time = NU_NO;
7805a0
-		origin = marginal_path_origin;
7805a0
+		if (conf->marginal_pathgroups == MARGINAL_PATHGROUP_FPIN)
7805a0
+			origin = fpin_marginal_path_origin;
7805a0
+		else
7805a0
+			origin = marginal_path_origin;
7805a0
 		goto out;
7805a0
 	}
7805a0
 	mp_set_mpe(san_path_err_recovery_time);
7805a0
@@ -1123,6 +1134,12 @@ int select_marginal_path_err_sample_time(struct config *conf, struct multipath *
7805a0
 	const char *origin;
7805a0
 	char buff[12];
7805a0
 
7805a0
+	if (conf->marginal_pathgroups == MARGINAL_PATHGROUP_FPIN) {
7805a0
+		mp->marginal_path_err_sample_time = NU_NO;
7805a0
+		origin = fpin_marginal_path_origin;
7805a0
+		goto out;
7805a0
+	}
7805a0
+
7805a0
 	mp_set_mpe(marginal_path_err_sample_time);
7805a0
 	mp_set_ovr(marginal_path_err_sample_time);
7805a0
 	mp_set_hwe(marginal_path_err_sample_time);
7805a0
@@ -1141,6 +1158,12 @@ int select_marginal_path_err_rate_threshold(struct config *conf, struct multipat
7805a0
 	const char *origin;
7805a0
 	char buff[12];
7805a0
 
7805a0
+	if (conf->marginal_pathgroups == MARGINAL_PATHGROUP_FPIN) {
7805a0
+		mp->marginal_path_err_rate_threshold = NU_NO;
7805a0
+		origin = fpin_marginal_path_origin;
7805a0
+		goto out;
7805a0
+	}
7805a0
+
7805a0
 	mp_set_mpe(marginal_path_err_rate_threshold);
7805a0
 	mp_set_ovr(marginal_path_err_rate_threshold);
7805a0
 	mp_set_hwe(marginal_path_err_rate_threshold);
7805a0
@@ -1159,6 +1182,12 @@ int select_marginal_path_err_recheck_gap_time(struct config *conf, struct multip
7805a0
 	const char *origin;
7805a0
 	char buff[12];
7805a0
 
7805a0
+	if (conf->marginal_pathgroups == MARGINAL_PATHGROUP_FPIN) {
7805a0
+		mp->marginal_path_err_recheck_gap_time = NU_NO;
7805a0
+		origin = fpin_marginal_path_origin;
7805a0
+		goto out;
7805a0
+	}
7805a0
+
7805a0
 	mp_set_mpe(marginal_path_err_recheck_gap_time);
7805a0
 	mp_set_ovr(marginal_path_err_recheck_gap_time);
7805a0
 	mp_set_hwe(marginal_path_err_recheck_gap_time);
7805a0
@@ -1177,6 +1206,12 @@ int select_marginal_path_double_failed_time(struct config *conf, struct multipat
7805a0
 	const char *origin;
7805a0
 	char buff[12];
7805a0
 
7805a0
+	if (conf->marginal_pathgroups == MARGINAL_PATHGROUP_FPIN) {
7805a0
+		mp->marginal_path_double_failed_time = NU_NO;
7805a0
+		origin = fpin_marginal_path_origin;
7805a0
+		goto out;
7805a0
+	}
7805a0
+
7805a0
 	mp_set_mpe(marginal_path_double_failed_time);
7805a0
 	mp_set_ovr(marginal_path_double_failed_time);
7805a0
 	mp_set_hwe(marginal_path_double_failed_time);
7805a0
diff --git a/libmultipath/structs.h b/libmultipath/structs.h
7805a0
index 875e726e..3ed5cfc1 100644
7805a0
--- a/libmultipath/structs.h
7805a0
+++ b/libmultipath/structs.h
7805a0
@@ -128,6 +128,12 @@ enum find_multipaths_states {
7805a0
 	__FIND_MULTIPATHS_LAST,
7805a0
 };
7805a0
 
7805a0
+enum marginal_pathgroups_mode {
7805a0
+	MARGINAL_PATHGROUP_OFF = YN_NO,
7805a0
+	MARGINAL_PATHGROUP_ON = YN_YES,
7805a0
+	MARGINAL_PATHGROUP_FPIN,
7805a0
+};
7805a0
+
7805a0
 enum flush_states {
7805a0
 	FLUSH_UNDEF = YNU_UNDEF,
7805a0
 	FLUSH_DISABLED = YNU_NO,
7805a0
@@ -429,6 +435,7 @@ struct multipath {
7805a0
 	unsigned char prflag;
7805a0
 	int all_tg_pt;
7805a0
 	struct gen_multipath generic_mp;
7805a0
+	bool fpin_must_reload;
7805a0
 };
7805a0
 
7805a0
 static inline int marginal_path_check_enabled(const struct multipath *mpp)
7805a0
diff --git a/multipath/multipath.conf.5 b/multipath/multipath.conf.5
7805a0
index abbc89af..805b7a5e 100644
7805a0
--- a/multipath/multipath.conf.5
7805a0
+++ b/multipath/multipath.conf.5
7805a0
@@ -1063,20 +1063,26 @@ The default is: \fBno\fR
7805a0
 .
7805a0
 .TP
7805a0
 .B marginal_pathgroups
7805a0
-If set to \fIno\fR, the \fIdelay_*_checks\fR, \fImarginal_path_*\fR, and
7805a0
+If set to \fIoff\fR, the \fIdelay_*_checks\fR, \fImarginal_path_*\fR, and
7805a0
 \fIsan_path_err_*\fR options will keep marginal, or \(dqshaky\(dq, paths from
7805a0
 being reinstated until they have been monitored for some time. This can cause
7805a0
 situations where all non-marginal paths are down, and no paths are usable
7805a0
 until multipathd detects this and reinstates a marginal path. If the multipath
7805a0
 device is not configured to queue IO in this case, it can cause IO errors to
7805a0
 occur, even though there are marginal paths available.  However, if this
7805a0
-option is set to \fIyes\fR, when one of the marginal path detecting methods
7805a0
+option is set to \fIon\fR, when one of the marginal path detecting methods
7805a0
 determines that a path is marginal, it will be reinstated and placed in a
7805a0
 seperate pathgroup that will only be used after all the non-marginal pathgroups
7805a0
 have been tried first. This prevents the possibility of IO errors occuring
7805a0
 while marginal paths are still usable. After the path has been monitored
7805a0
 for the configured time, and is declared healthy, it will be returned to its
7805a0
-normal pathgroup. See "Shaky paths detection" below for more information.
7805a0
+normal pathgroup.
7805a0
+However if this option is set to \fIfpin\fR multipathd will receive fpin
7805a0
+notifications, set path states to "marginal" accordingly, and regroup paths
7805a0
+as described for "marginal_pathgroups yes". This option can't be used in combination
7805a0
+with other options for "Shaky path detection" (see below).If it is set to fpin,
7805a0
+marginal_path_xyz and san_path_err_xyz parameters are implicitly set to 0.
7805a0
+See "Shaky paths detection" below for more information.
7805a0
 .RS
7805a0
 .TP
7805a0
 The default  is: \fBno\fR
7805a0
@@ -1852,6 +1858,13 @@ increase and the threshold is never reached. Ticks are the time between
7805a0
 path checks by multipathd, which is variable and controlled by the
7805a0
 \fIpolling_interval\fR and \fImax_polling_interval\fR parameters.
7805a0
 .
7805a0
+.TP
7805a0
+.B \(dqFPIN \(dq failure tracking
7805a0
+Fibre channel fabrics can notify hosts about fabric-level issues such
7805a0
+as integrity failures or congestion with so-called Fabric Performance
7805a0
+Impact Notifications (FPINs).On receiving the fpin notifications through ELS
7805a0
+multipathd will move the affected path and port states to marginal.
7805a0
+.
7805a0
 .RS 8
7805a0
 .LP
7805a0
 This method is \fBdeprecated\fR in favor of the \(dqmarginal_path\(dq failure
7805a0
diff --git a/multipathd/Makefile b/multipathd/Makefile
7805a0
index 8d901178..835edd93 100644
7805a0
--- a/multipathd/Makefile
7805a0
+++ b/multipathd/Makefile
7805a0
@@ -1,5 +1,9 @@
7805a0
 include ../Makefile.inc
7805a0
 
7805a0
+ifneq ($(call check_var,ELS_DTAG_LNK_INTEGRITY,/usr/include/scsi/fc/fc_els.h),0)
7805a0
+	CFLAGS += -DFPIN_EVENT_HANDLER
7805a0
+	FPIN_SUPPORT = 1
7805a0
+endif
7805a0
 #
7805a0
 # debugging stuff
7805a0
 #
7805a0
@@ -28,6 +32,12 @@ endif
7805a0
 OBJS = main.o pidfile.o uxlsnr.o uxclnt.o cli.o cli_handlers.o waiter.o \
7805a0
        dmevents.o
7805a0
 
7805a0
+ifeq ($(FPIN_SUPPORT),1)
7805a0
+OBJS += fpin_handlers.o
7805a0
+endif
7805a0
+
7805a0
+
7805a0
+
7805a0
 EXEC = multipathd
7805a0
 
7805a0
 all : $(EXEC)
7805a0
diff --git a/multipathd/fpin.h b/multipathd/fpin.h
7805a0
new file mode 100644
7805a0
index 00000000..bfcc1ce2
7805a0
--- /dev/null
7805a0
+++ b/multipathd/fpin.h
7805a0
@@ -0,0 +1,20 @@
7805a0
+#ifndef __FPIN_H__
7805a0
+#define __FPIN_H__
7805a0
+
7805a0
+#ifdef FPIN_EVENT_HANDLER
7805a0
+void *fpin_fabric_notification_receiver(void *unused);
7805a0
+void *fpin_els_li_consumer(void *data);
7805a0
+void fpin_clean_marginal_dev_list(__attribute__((unused)) void *arg);
7805a0
+#else
7805a0
+static void *fpin_fabric_notification_receiver(__attribute__((unused))void *unused)
7805a0
+{
7805a0
+	return NULL;
7805a0
+}
7805a0
+static void *fpin_els_li_consumer(__attribute__((unused))void *data)
7805a0
+{
7805a0
+	return NULL;
7805a0
+}
7805a0
+/* fpin_clean_marginal_dev_list() is never called */
7805a0
+#endif
7805a0
+
7805a0
+#endif
7805a0
diff --git a/multipathd/fpin_handlers.c b/multipathd/fpin_handlers.c
7805a0
new file mode 100644
7805a0
index 00000000..b14366d7
7805a0
--- /dev/null
7805a0
+++ b/multipathd/fpin_handlers.c
7805a0
@@ -0,0 +1,541 @@
7805a0
+#include <errno.h>
7805a0
+#include <unistd.h>
7805a0
+#include <sys/types.h>
7805a0
+#include <sys/socket.h>
7805a0
+#include <libudev.h>
7805a0
+#include <stdint.h>
7805a0
+#include <scsi/scsi_netlink_fc.h>
7805a0
+#include <scsi/fc/fc_els.h>
7805a0
+
7805a0
+#include "parser.h"
7805a0
+#include "vector.h"
7805a0
+#include "structs.h"
7805a0
+#include "structs_vec.h"
7805a0
+#include "main.h"
7805a0
+#include "debug.h"
7805a0
+#include "util.h"
7805a0
+#include "sysfs.h"
7805a0
+
7805a0
+#include "fpin.h"
7805a0
+#include "devmapper.h"
7805a0
+
7805a0
+static pthread_cond_t fpin_li_cond = PTHREAD_COND_INITIALIZER;
7805a0
+static pthread_mutex_t fpin_li_mutex = PTHREAD_MUTEX_INITIALIZER;
7805a0
+static pthread_mutex_t fpin_li_marginal_dev_mutex = PTHREAD_MUTEX_INITIALIZER;
7805a0
+
7805a0
+static LIST_HEAD(els_marginal_list_head);
7805a0
+static LIST_HEAD(fpin_li_marginal_dev_list_head);
7805a0
+
7805a0
+
7805a0
+#define DEF_RX_BUF_SIZE	4096
7805a0
+#define DEV_NAME_LEN	128
7805a0
+#define FCH_EVT_LINKUP 0x2
7805a0
+#define FCH_EVT_LINK_FPIN 0x501
7805a0
+#define FCH_EVT_RSCN 0x5
7805a0
+
7805a0
+#define list_first_entry(ptr, type, member) \
7805a0
+	list_entry((ptr)->next, type, member)
7805a0
+
7805a0
+/* max ELS frame Size */
7805a0
+#define FC_PAYLOAD_MAXLEN   2048
7805a0
+
7805a0
+struct els_marginal_list {
7805a0
+	uint32_t event_code;
7805a0
+	uint16_t host_num;
7805a0
+	uint16_t length;
7805a0
+	char payload[FC_PAYLOAD_MAXLEN];
7805a0
+	struct list_head node;
7805a0
+};
7805a0
+/* Structure to store the marginal devices info */
7805a0
+struct marginal_dev_list {
7805a0
+	char dev_t[BLK_DEV_SIZE];
7805a0
+	uint32_t host_num;
7805a0
+	struct list_head node;
7805a0
+};
7805a0
+
7805a0
+static void _udev_device_unref(void *p)
7805a0
+{
7805a0
+	udev_device_unref(p);
7805a0
+}
7805a0
+
7805a0
+
7805a0
+/*set/unset the path state to marginal*/
7805a0
+static int fpin_set_pathstate(struct path *pp, bool set)
7805a0
+{
7805a0
+	const char *action = set ? "set" : "unset";
7805a0
+
7805a0
+	if (!pp || !pp->mpp || !pp->mpp->alias)
7805a0
+		return -1;
7805a0
+
7805a0
+	condlog(3, "\n%s: %s  marginal path %s (fpin)",
7805a0
+		action, pp->mpp->alias, pp->dev_t);
7805a0
+	pp->marginal = set;
7805a0
+	pp->mpp->fpin_must_reload = true;
7805a0
+	return 0;
7805a0
+}
7805a0
+
7805a0
+/* This will unset marginal state of a device*/
7805a0
+static void fpin_path_unsetmarginal(char *devname, struct vectors *vecs)
7805a0
+{
7805a0
+	struct path *pp;
7805a0
+
7805a0
+	pp = find_path_by_dev(vecs->pathvec, devname);
7805a0
+	if (!pp)
7805a0
+		pp = find_path_by_devt(vecs->pathvec, devname);
7805a0
+
7805a0
+	fpin_set_pathstate(pp, false);
7805a0
+}
7805a0
+
7805a0
+/*This will set the marginal state of a device*/
7805a0
+static int fpin_path_setmarginal(struct path *pp)
7805a0
+{
7805a0
+	return fpin_set_pathstate(pp, true);
7805a0
+}
7805a0
+
7805a0
+/* Unsets all the devices in the list from marginal state */
7805a0
+static void
7805a0
+fpin_unset_marginal_dev(uint32_t host_num, struct vectors *vecs)
7805a0
+{
7805a0
+	struct marginal_dev_list *tmp_marg = NULL;
7805a0
+	struct marginal_dev_list *marg = NULL;
7805a0
+	struct multipath *mpp;
7805a0
+	int ret = 0;
7805a0
+	int i;
7805a0
+
7805a0
+	pthread_cleanup_push(cleanup_lock, &vecs->lock);
7805a0
+	lock(&vecs->lock);
7805a0
+	pthread_testcancel();
7805a0
+
7805a0
+	pthread_mutex_lock(&fpin_li_marginal_dev_mutex);
7805a0
+	pthread_cleanup_push(cleanup_mutex, &fpin_li_marginal_dev_mutex);
7805a0
+	pthread_testcancel();
7805a0
+	if (list_empty(&fpin_li_marginal_dev_list_head)) {
7805a0
+		condlog(4, "Marginal List is empty\n");
7805a0
+		goto empty;
7805a0
+	}
7805a0
+	list_for_each_entry_safe(marg, tmp_marg, &fpin_li_marginal_dev_list_head, node) {
7805a0
+		if (marg->host_num != host_num)
7805a0
+			continue;
7805a0
+		condlog(4, " unsetting marginal dev: is %s %d\n",
7805a0
+				tmp_marg->dev_t, tmp_marg->host_num);
7805a0
+		fpin_path_unsetmarginal(marg->dev_t, vecs);
7805a0
+		list_del(&marg->node);
7805a0
+		free(marg);
7805a0
+	}
7805a0
+empty:
7805a0
+	pthread_cleanup_pop(1);
7805a0
+	/* walk backwards because update_path_groups() can remove mpp */
7805a0
+	vector_foreach_slot_backwards(vecs->mpvec, mpp, i) {
7805a0
+		if (mpp->fpin_must_reload) {
7805a0
+			ret = update_path_groups(mpp, vecs, 0);
7805a0
+			if (ret == 2)
7805a0
+				condlog(2, "map removed during reload");
7805a0
+			else
7805a0
+				mpp->fpin_must_reload = false;
7805a0
+		}
7805a0
+	}
7805a0
+	pthread_cleanup_pop(1);
7805a0
+}
7805a0
+
7805a0
+/*
7805a0
+ * On Receiving the frame from HBA driver, insert the frame into link
7805a0
+ * integrity frame list which will be picked up later by consumer thread for
7805a0
+ * processing.
7805a0
+ */
7805a0
+static int
7805a0
+fpin_els_add_li_frame(struct fc_nl_event *fc_event)
7805a0
+{
7805a0
+	struct els_marginal_list *els_mrg = NULL;
7805a0
+	int ret = 0;
7805a0
+
7805a0
+	if (fc_event->event_datalen > FC_PAYLOAD_MAXLEN)
7805a0
+		return -EINVAL;
7805a0
+
7805a0
+	pthread_mutex_lock(&fpin_li_mutex);
7805a0
+	pthread_cleanup_push(cleanup_mutex, &fpin_li_mutex);
7805a0
+	pthread_testcancel();
7805a0
+	els_mrg = calloc(1, sizeof(struct els_marginal_list));
7805a0
+	if (els_mrg != NULL) {
7805a0
+		els_mrg->host_num = fc_event->host_no;
7805a0
+		els_mrg->event_code = fc_event->event_code;
7805a0
+		els_mrg->length = fc_event->event_datalen;
7805a0
+		memcpy(els_mrg->payload, &(fc_event->event_data), fc_event->event_datalen);
7805a0
+		list_add_tail(&els_mrg->node, &els_marginal_list_head);
7805a0
+		pthread_cond_signal(&fpin_li_cond);
7805a0
+	} else
7805a0
+		ret = -ENOMEM;
7805a0
+	pthread_cleanup_pop(1);
7805a0
+	return ret;
7805a0
+
7805a0
+}
7805a0
+
7805a0
+/*Sets the rport port_state to marginal*/
7805a0
+static void fpin_set_rport_marginal(struct udev_device *rport_dev)
7805a0
+{
7805a0
+	sysfs_attr_set_value(rport_dev, "port_state",
7805a0
+				"Marginal", strlen("Marginal"));
7805a0
+}
7805a0
+
7805a0
+/*Add the marginal devices info into the list*/
7805a0
+static void
7805a0
+fpin_add_marginal_dev_info(uint32_t host_num, char *devname)
7805a0
+{
7805a0
+	struct marginal_dev_list *newdev = NULL;
7805a0
+
7805a0
+	newdev = calloc(1, sizeof(struct marginal_dev_list));
7805a0
+	if (newdev != NULL) {
7805a0
+		newdev->host_num = host_num;
7805a0
+		strlcpy(newdev->dev_t, devname, BLK_DEV_SIZE);
7805a0
+		condlog(4, "\n%s hostno %d devname %s\n", __func__,
7805a0
+				host_num, newdev->dev_t);
7805a0
+		pthread_mutex_lock(&fpin_li_marginal_dev_mutex);
7805a0
+		list_add_tail(&(newdev->node),
7805a0
+				&fpin_li_marginal_dev_list_head);
7805a0
+		pthread_mutex_unlock(&fpin_li_marginal_dev_mutex);
7805a0
+	}
7805a0
+}
7805a0
+
7805a0
+/*
7805a0
+ * This function goes through the vecs->pathvec, and for
7805a0
+ * each path, check that the host  number,
7805a0
+ * the target WWPN associated with the path matches
7805a0
+ * with the els wwpn and sets the path and port state to
7805a0
+ * Marginal
7805a0
+ */
7805a0
+static int  fpin_chk_wwn_setpath_marginal(uint16_t host_num,  struct vectors *vecs,
7805a0
+		uint64_t els_wwpn)
7805a0
+{
7805a0
+	struct path *pp;
7805a0
+	struct multipath *mpp;
7805a0
+	int i, k;
7805a0
+	char rport_id[42];
7805a0
+	const char *value = NULL;
7805a0
+	struct udev_device *rport_dev = NULL;
7805a0
+	uint64_t wwpn;
7805a0
+	int ret = 0;
7805a0
+
7805a0
+	pthread_cleanup_push(cleanup_lock, &vecs->lock);
7805a0
+	lock(&vecs->lock);
7805a0
+	pthread_testcancel();
7805a0
+
7805a0
+	vector_foreach_slot(vecs->pathvec, pp, k) {
7805a0
+		/* Checks the host number and also for the SCSI FCP */
7805a0
+		if (pp->sg_id.proto_id != SCSI_PROTOCOL_FCP || host_num !=  pp->sg_id.host_no)
7805a0
+			continue;
7805a0
+		sprintf(rport_id, "rport-%d:%d-%d",
7805a0
+				pp->sg_id.host_no, pp->sg_id.channel, pp->sg_id.transport_id);
7805a0
+		rport_dev = udev_device_new_from_subsystem_sysname(udev,
7805a0
+				"fc_remote_ports", rport_id);
7805a0
+		if (!rport_dev) {
7805a0
+			condlog(2, "%s: No fc_remote_port device for '%s'", pp->dev,
7805a0
+					rport_id);
7805a0
+			continue;
7805a0
+		}
7805a0
+		pthread_cleanup_push(_udev_device_unref, rport_dev);
7805a0
+		value = udev_device_get_sysattr_value(rport_dev, "port_name");
7805a0
+		if (!value)
7805a0
+			goto unref;
7805a0
+
7805a0
+		if (value)
7805a0
+			wwpn =  strtol(value, NULL, 16);
7805a0
+		/*
7805a0
+		 * If the port wwpn matches sets the path and port state
7805a0
+		 * to marginal
7805a0
+		 */
7805a0
+		if (wwpn == els_wwpn) {
7805a0
+			ret = fpin_path_setmarginal(pp);
7805a0
+			if (ret < 0)
7805a0
+				goto unref;
7805a0
+			fpin_set_rport_marginal(rport_dev);
7805a0
+			fpin_add_marginal_dev_info(host_num, pp->dev);
7805a0
+		}
7805a0
+unref:
7805a0
+		pthread_cleanup_pop(1);
7805a0
+	}
7805a0
+	/* walk backwards because update_path_groups() can remove mpp */
7805a0
+	vector_foreach_slot_backwards(vecs->mpvec, mpp, i) {
7805a0
+		if (mpp->fpin_must_reload) {
7805a0
+			ret = update_path_groups(mpp, vecs, 0);
7805a0
+			if (ret == 2)
7805a0
+				condlog(2, "map removed during reload");
7805a0
+			else
7805a0
+				mpp->fpin_must_reload = false;
7805a0
+		}
7805a0
+	}
7805a0
+	pthread_cleanup_pop(1);
7805a0
+	return ret;
7805a0
+}
7805a0
+
7805a0
+/*
7805a0
+ * This function loops around all the impacted wwns received as part of els
7805a0
+ * frame and sets the associated path and port states to marginal.
7805a0
+ */
7805a0
+static int
7805a0
+fpin_parse_li_els_setpath_marginal(uint16_t host_num, struct fc_tlv_desc *tlv,
7805a0
+		struct vectors *vecs)
7805a0
+{
7805a0
+	uint32_t wwn_count = 0, iter = 0;
7805a0
+	uint64_t wwpn;
7805a0
+	struct fc_fn_li_desc *li_desc = (struct fc_fn_li_desc *)tlv;
7805a0
+	int count = 0;
7805a0
+	int ret = 0;
7805a0
+
7805a0
+	/* Update the wwn to list */
7805a0
+	wwn_count = be32_to_cpu(li_desc->pname_count);
7805a0
+	condlog(4, "Got wwn count as %d\n", wwn_count);
7805a0
+
7805a0
+	for (iter = 0; iter < wwn_count; iter++) {
7805a0
+		wwpn = be64_to_cpu(li_desc->pname_list[iter]);
7805a0
+		ret = fpin_chk_wwn_setpath_marginal(host_num, vecs, wwpn);
7805a0
+		if (ret < 0)
7805a0
+			condlog(2, "failed to set the path marginal associated with wwpn: 0x%" PRIx64 "\n", wwpn);
7805a0
+
7805a0
+		count++;
7805a0
+	}
7805a0
+	return count;
7805a0
+}
7805a0
+
7805a0
+/*
7805a0
+ * This function process the ELS frame received from HBA driver,
7805a0
+ * and sets the path associated with the port wwn to marginal
7805a0
+ * and also set the port state to marginal.
7805a0
+ */
7805a0
+static int
7805a0
+fpin_process_els_frame(uint16_t host_num, char *fc_payload, struct vectors *vecs)
7805a0
+{
7805a0
+
7805a0
+	int count = -1;
7805a0
+	struct fc_els_fpin *fpin = (struct fc_els_fpin *)fc_payload;
7805a0
+	struct fc_tlv_desc *tlv;
7805a0
+
7805a0
+	tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0];
7805a0
+
7805a0
+	/*
7805a0
+	 * Parse the els frame and set the affected paths and port
7805a0
+	 * state to marginal
7805a0
+	 */
7805a0
+	count = fpin_parse_li_els_setpath_marginal(host_num, tlv, vecs);
7805a0
+	if (count <= 0)
7805a0
+		condlog(4, "Could not find any WWNs, ret = %d\n",
7805a0
+					count);
7805a0
+	return count;
7805a0
+}
7805a0
+
7805a0
+/*
7805a0
+ * This function process the FPIN ELS frame received from HBA driver,
7805a0
+ * and push the frame to appropriate frame list. Currently we have only FPIN
7805a0
+ * LI frame list.
7805a0
+ */
7805a0
+static int
7805a0
+fpin_handle_els_frame(struct fc_nl_event *fc_event)
7805a0
+{
7805a0
+	int ret = -1;
7805a0
+	uint32_t els_cmd;
7805a0
+	struct fc_els_fpin *fpin = (struct fc_els_fpin *)&fc_event->event_data;
7805a0
+	struct fc_tlv_desc *tlv;
7805a0
+	uint32_t dtag;
7805a0
+
7805a0
+	els_cmd = (uint32_t)fc_event->event_data;
7805a0
+	tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0];
7805a0
+	dtag = be32_to_cpu(tlv->desc_tag);
7805a0
+	condlog(4, "Got CMD in add as 0x%x fpin_cmd 0x%x dtag 0x%x\n",
7805a0
+			els_cmd, fpin->fpin_cmd, dtag);
7805a0
+
7805a0
+	if ((fc_event->event_code == FCH_EVT_LINK_FPIN) ||
7805a0
+			(fc_event->event_code == FCH_EVT_LINKUP) ||
7805a0
+			(fc_event->event_code == FCH_EVT_RSCN)) {
7805a0
+
7805a0
+		if (els_cmd == ELS_FPIN) {
7805a0
+			/*
7805a0
+			 * Check the type of fpin by checking the tag info
7805a0
+			 * At present we are supporting only LI events
7805a0
+			 */
7805a0
+			if (dtag == ELS_DTAG_LNK_INTEGRITY) {
7805a0
+				/*Push the Payload to FPIN frame queue. */
7805a0
+				ret = fpin_els_add_li_frame(fc_event);
7805a0
+				if (ret != 0)
7805a0
+					condlog(0, "Failed to process LI frame with error %d\n",
7805a0
+							ret);
7805a0
+			} else {
7805a0
+				condlog(4, "Unsupported FPIN received 0x%x\n", dtag);
7805a0
+				return ret;
7805a0
+			}
7805a0
+		} else {
7805a0
+			/*Push the Payload to FPIN frame queue. */
7805a0
+			ret = fpin_els_add_li_frame(fc_event);
7805a0
+			if (ret != 0)
7805a0
+				condlog(0, "Failed to process Linkup/RSCN event with error %d evnt %d\n",
7805a0
+						ret, fc_event->event_code);
7805a0
+		}
7805a0
+	} else
7805a0
+		condlog(4, "Invalid command received: 0x%x\n", els_cmd);
7805a0
+	return ret;
7805a0
+}
7805a0
+
7805a0
+/*cleans the global marginal dev list*/
7805a0
+void fpin_clean_marginal_dev_list(__attribute__((unused)) void *arg)
7805a0
+{
7805a0
+	struct marginal_dev_list *tmp_marg = NULL;
7805a0
+
7805a0
+	pthread_mutex_lock(&fpin_li_marginal_dev_mutex);
7805a0
+	while (!list_empty(&fpin_li_marginal_dev_list_head)) {
7805a0
+		tmp_marg  = list_first_entry(&fpin_li_marginal_dev_list_head,
7805a0
+				struct marginal_dev_list, node);
7805a0
+		list_del(&tmp_marg->node);
7805a0
+		free(tmp_marg);
7805a0
+	}
7805a0
+	pthread_mutex_unlock(&fpin_li_marginal_dev_mutex);
7805a0
+}
7805a0
+
7805a0
+/* Cleans the global els  marginal list */
7805a0
+static void fpin_clean_els_marginal_list(void *arg)
7805a0
+{
7805a0
+	struct list_head *head = (struct list_head *)arg;
7805a0
+	struct els_marginal_list *els_marg;
7805a0
+
7805a0
+	while (!list_empty(head)) {
7805a0
+		els_marg  = list_first_entry(head, struct els_marginal_list,
7805a0
+					     node);
7805a0
+		list_del(&els_marg->node);
7805a0
+		free(els_marg);
7805a0
+	}
7805a0
+}
7805a0
+
7805a0
+static void rcu_unregister(__attribute__((unused)) void *param)
7805a0
+{
7805a0
+	rcu_unregister_thread();
7805a0
+}
7805a0
+/*
7805a0
+ * This is the FPIN ELS consumer thread. The thread sleeps on pthread cond
7805a0
+ * variable unless notified by fpin_fabric_notification_receiver thread.
7805a0
+ * This thread is only to process FPIN-LI ELS frames. A new thread and frame
7805a0
+ * list will be added if any more ELS frames types are to be supported.
7805a0
+ */
7805a0
+void *fpin_els_li_consumer(void *data)
7805a0
+{
7805a0
+	struct list_head marginal_list_head;
7805a0
+	int ret = 0;
7805a0
+	uint16_t host_num;
7805a0
+	struct els_marginal_list *els_marg;
7805a0
+	uint32_t event_code;
7805a0
+	struct vectors *vecs = (struct vectors *)data;
7805a0
+
7805a0
+	pthread_cleanup_push(rcu_unregister, NULL);
7805a0
+	rcu_register_thread();
7805a0
+	pthread_cleanup_push(fpin_clean_marginal_dev_list, NULL);
7805a0
+	INIT_LIST_HEAD(&marginal_list_head);
7805a0
+	pthread_cleanup_push(fpin_clean_els_marginal_list,
7805a0
+				(void *)&marginal_list_head);
7805a0
+	for ( ; ; ) {
7805a0
+		pthread_mutex_lock(&fpin_li_mutex);
7805a0
+		pthread_cleanup_push(cleanup_mutex, &fpin_li_mutex);
7805a0
+		pthread_testcancel();
7805a0
+		while (list_empty(&els_marginal_list_head))
7805a0
+			pthread_cond_wait(&fpin_li_cond, &fpin_li_mutex);
7805a0
+
7805a0
+		if (!list_empty(&els_marginal_list_head)) {
7805a0
+			condlog(4, "Invoke List splice tail\n");
7805a0
+			list_splice_tail_init(&els_marginal_list_head, &marginal_list_head);
7805a0
+		}
7805a0
+		pthread_cleanup_pop(1);
7805a0
+
7805a0
+		while (!list_empty(&marginal_list_head)) {
7805a0
+			els_marg  = list_first_entry(&marginal_list_head,
7805a0
+							struct els_marginal_list, node);
7805a0
+			host_num = els_marg->host_num;
7805a0
+			event_code = els_marg->event_code;
7805a0
+			/* Now finally process FPIN LI ELS Frame */
7805a0
+			condlog(4, "Got a new Payload buffer, processing it\n");
7805a0
+			if ((event_code ==  FCH_EVT_LINKUP) || (event_code == FCH_EVT_RSCN))
7805a0
+				 fpin_unset_marginal_dev(host_num, vecs);
7805a0
+			else {
7805a0
+				ret = fpin_process_els_frame(host_num, els_marg->payload, vecs);
7805a0
+				if (ret <= 0)
7805a0
+					condlog(0, "ELS frame processing failed with ret %d\n", ret);
7805a0
+			}
7805a0
+			list_del(&els_marg->node);
7805a0
+			free(els_marg);
7805a0
+
7805a0
+		}
7805a0
+	}
7805a0
+
7805a0
+	pthread_cleanup_pop(1);
7805a0
+	pthread_cleanup_pop(1);
7805a0
+	pthread_cleanup_pop(1);
7805a0
+	return NULL;
7805a0
+}
7805a0
+
7805a0
+static void receiver_cleanup_list(__attribute__((unused)) void *arg)
7805a0
+{
7805a0
+	pthread_mutex_lock(&fpin_li_mutex);
7805a0
+	fpin_clean_els_marginal_list(&els_marginal_list_head);
7805a0
+	pthread_mutex_unlock(&fpin_li_mutex);
7805a0
+}
7805a0
+
7805a0
+/*
7805a0
+ * Listen for ELS frames from driver. on receiving the frame payload,
7805a0
+ * push the payload to a list, and notify the fpin_els_li_consumer thread to
7805a0
+ * process it. Once consumer thread is notified, return to listen for more ELS
7805a0
+ * frames from driver.
7805a0
+ */
7805a0
+void *fpin_fabric_notification_receiver(__attribute__((unused))void *unused)
7805a0
+{
7805a0
+	int ret;
7805a0
+	long fd;
7805a0
+	uint32_t els_cmd;
7805a0
+	struct fc_nl_event *fc_event = NULL;
7805a0
+	struct sockaddr_nl fc_local;
7805a0
+	unsigned char buf[DEF_RX_BUF_SIZE] __attribute__((aligned(sizeof(uint64_t))));
7805a0
+	size_t plen = 0;
7805a0
+
7805a0
+	pthread_cleanup_push(rcu_unregister, NULL);
7805a0
+	rcu_register_thread();
7805a0
+
7805a0
+	pthread_cleanup_push(receiver_cleanup_list, NULL);
7805a0
+	fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_SCSITRANSPORT);
7805a0
+	if (fd < 0) {
7805a0
+		condlog(0, "fc socket error %ld", fd);
7805a0
+		return NULL;
7805a0
+	}
7805a0
+
7805a0
+	pthread_cleanup_push(close_fd, (void *)fd);
7805a0
+	memset(&fc_local, 0, sizeof(fc_local));
7805a0
+	fc_local.nl_family = AF_NETLINK;
7805a0
+	fc_local.nl_groups = ~0;
7805a0
+	fc_local.nl_pid = getpid();
7805a0
+	ret = bind(fd, (struct sockaddr *)&fc_local, sizeof(fc_local));
7805a0
+	if (ret == -1) {
7805a0
+		condlog(0, "fc socket bind error %d\n", ret);
7805a0
+		goto out;
7805a0
+	}
7805a0
+	for ( ; ; ) {
7805a0
+		condlog(4, "Waiting for ELS...\n");
7805a0
+		ret = read(fd, buf, DEF_RX_BUF_SIZE);
7805a0
+		if (ret < 0) {
7805a0
+			condlog(0, "failed to read the els frame (%d)", ret);
7805a0
+			continue;
7805a0
+		}
7805a0
+		condlog(4, "Got a new request %d\n", ret);
7805a0
+		if (!NLMSG_OK((struct nlmsghdr *)buf, (unsigned int)ret)) {
7805a0
+			condlog(0, "bad els frame read (%d)", ret);
7805a0
+			continue;
7805a0
+		}
7805a0
+		/* Push the frame to appropriate frame list */
7805a0
+		plen = NLMSG_PAYLOAD((struct nlmsghdr *)buf, 0);
7805a0
+		fc_event = (struct fc_nl_event *)NLMSG_DATA(buf);
7805a0
+		if (plen < sizeof(*fc_event)) {
7805a0
+			condlog(0, "too short (%d) to be an FC event", ret);
7805a0
+			continue;
7805a0
+		}
7805a0
+		els_cmd = (uint32_t)fc_event->event_data;
7805a0
+		condlog(4, "Got host no as %d, event 0x%x, len %d evntnum %d evntcode %d\n",
7805a0
+				fc_event->host_no, els_cmd, fc_event->event_datalen,
7805a0
+				fc_event->event_num, fc_event->event_code);
7805a0
+		fpin_handle_els_frame(fc_event);
7805a0
+	}
7805a0
+out:
7805a0
+	pthread_cleanup_pop(1);
7805a0
+	pthread_cleanup_pop(1);
7805a0
+	pthread_cleanup_pop(1);
7805a0
+	return NULL;
7805a0
+}
7805a0
diff --git a/multipathd/main.c b/multipathd/main.c
7805a0
index eeded52b..4cf5bc41 100644
7805a0
--- a/multipathd/main.c
7805a0
+++ b/multipathd/main.c
7805a0
@@ -16,6 +16,7 @@
7805a0
 #include <linux/oom.h>
7805a0
 #include <libudev.h>
7805a0
 #include <urcu.h>
7805a0
+#include "fpin.h"
7805a0
 #ifdef USE_SYSTEMD
7805a0
 #include <systemd/sd-daemon.h>
7805a0
 #endif
7805a0
@@ -2704,7 +2705,9 @@ reconfigure (struct vectors * vecs)
7805a0
 	conf->sequence_nr = old->sequence_nr + 1;
7805a0
 	rcu_assign_pointer(multipath_conf, conf);
7805a0
 	call_rcu(&old->rcu, rcu_free_config);
7805a0
-
7805a0
+#ifdef FPIN_EVENT_HANDLER
7805a0
+	fpin_clean_marginal_dev_list(NULL);
7805a0
+#endif
7805a0
 	configure(vecs);
7805a0
 
7805a0
 
7805a0
@@ -2878,7 +2881,8 @@ set_oom_adj (void)
7805a0
 static int
7805a0
 child (__attribute__((unused)) void *param)
7805a0
 {
7805a0
-	pthread_t check_thr, uevent_thr, uxlsnr_thr, uevq_thr, dmevent_thr;
7805a0
+	pthread_t check_thr, uevent_thr, uxlsnr_thr, uevq_thr, dmevent_thr,
7805a0
+		  fpin_thr, fpin_consumer_thr;
7805a0
 	pthread_attr_t log_attr, misc_attr, uevent_attr;
7805a0
 	struct vectors * vecs;
7805a0
 	struct multipath * mpp;
7805a0
@@ -2892,6 +2896,7 @@ child (__attribute__((unused)) void *param)
7805a0
 	char *envp;
7805a0
 	int queue_without_daemon;
7805a0
 	enum daemon_status state;
7805a0
+	int fpin_marginal_paths = 0;
7805a0
 
7805a0
 	mlockall(MCL_CURRENT | MCL_FUTURE);
7805a0
 	signal_init();
7805a0
@@ -2959,7 +2964,10 @@ child (__attribute__((unused)) void *param)
7805a0
 
7805a0
 	setscheduler();
7805a0
 	set_oom_adj();
7805a0
-
7805a0
+#ifdef FPIN_EVENT_HANDLER
7805a0
+	if (conf->marginal_pathgroups == MARGINAL_PATHGROUP_FPIN)
7805a0
+		fpin_marginal_paths = 1;
7805a0
+#endif
7805a0
 	/*
7805a0
 	 * Startup done, invalidate configuration
7805a0
 	 */
7805a0
@@ -3020,6 +3028,19 @@ child (__attribute__((unused)) void *param)
7805a0
 		condlog(0, "failed to create uevent dispatcher: %d", rc);
7805a0
 		goto failed;
7805a0
 	}
7805a0
+	if (fpin_marginal_paths) {
7805a0
+		if ((rc = pthread_create(&fpin_thr, &misc_attr,
7805a0
+			fpin_fabric_notification_receiver, NULL))) {
7805a0
+			condlog(0, "failed to create the fpin receiver thread: %d", rc);
7805a0
+			goto failed;
7805a0
+		}
7805a0
+
7805a0
+		if ((rc = pthread_create(&fpin_consumer_thr,
7805a0
+			&misc_attr, fpin_els_li_consumer, vecs))) {
7805a0
+			condlog(0, "failed to create the fpin consumer thread thread: %d", rc);
7805a0
+			goto failed;
7805a0
+		}
7805a0
+	}
7805a0
 	pthread_attr_destroy(&misc_attr);
7805a0
 
7805a0
 	while (1) {
7805a0
@@ -3070,6 +3091,10 @@ child (__attribute__((unused)) void *param)
7805a0
 	pthread_cancel(uevq_thr);
7805a0
 	if (poll_dmevents)
7805a0
 		pthread_cancel(dmevent_thr);
7805a0
+	if (fpin_marginal_paths) {
7805a0
+		pthread_cancel(fpin_thr);
7805a0
+		pthread_cancel(fpin_consumer_thr);
7805a0
+	}
7805a0
 
7805a0
 	pthread_join(check_thr, NULL);
7805a0
 	pthread_join(uevent_thr, NULL);
7805a0
@@ -3077,6 +3102,10 @@ child (__attribute__((unused)) void *param)
7805a0
 	pthread_join(uevq_thr, NULL);
7805a0
 	if (poll_dmevents)
7805a0
 		pthread_join(dmevent_thr, NULL);
7805a0
+	if (fpin_marginal_paths) {
7805a0
+		pthread_join(fpin_thr, NULL);
7805a0
+		pthread_join(fpin_consumer_thr, NULL);
7805a0
+	}
7805a0
 
7805a0
 	stop_io_err_stat_thread();
7805a0