Blame SOURCES/0037-libmultipath-count-pending-paths-as-active-on-loads.patch

96a22b
From 7159242be31dbb3f25aa67920462107bc2bc5fe0 Mon Sep 17 00:00:00 2001
96a22b
From: Benjamin Marzinski <bmarzins@redhat.com>
96a22b
Date: Thu, 9 Jul 2020 18:20:18 -0500
96a22b
Subject: [PATCH] libmultipath: count pending paths as active on loads
96a22b
96a22b
When multipath loads a table, it signals to udev if there are no active
96a22b
paths.  Multipath wasn't counting pending paths as active.  This meant
96a22b
that if all the paths were pending, udev would treat the device as not
96a22b
ready, and not run kpartx on it.  Even if the pending paths later
96a22b
because active and were reinstated, the kernel would not send a new
96a22b
uevent, because from its point of view, they were always up.
96a22b
96a22b
The alternative would be to continue to treat them as failed in the udev
96a22b
rules, but then also tell the kernel that they were down, so that it
96a22b
would trigger a uevent when they were reinstated. However, this could
96a22b
lead to newly created multipath devices failing IO, simply because the
96a22b
path checkers hadn't returned yet. Having udev assume that the the
96a22b
device is up, like the kernel does, seems like the safer option.
96a22b
96a22b
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
96a22b
---
96a22b
 libmultipath/devmapper.c |  3 ++-
96a22b
 libmultipath/structs.c   | 20 ++++++++++++++++++++
96a22b
 libmultipath/structs.h   |  1 +
96a22b
 3 files changed, 23 insertions(+), 1 deletion(-)
96a22b
96a22b
diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
96a22b
index 7f98bf9d..91ff0b3d 100644
96a22b
--- a/libmultipath/devmapper.c
96a22b
+++ b/libmultipath/devmapper.c
96a22b
@@ -408,7 +408,8 @@ static uint16_t build_udev_flags(const struct multipath *mpp, int reload)
96a22b
 	/* DM_UDEV_DISABLE_LIBRARY_FALLBACK is added in dm_addmap */
96a22b
 	return	(mpp->skip_kpartx == SKIP_KPARTX_ON ?
96a22b
 		 MPATH_UDEV_NO_KPARTX_FLAG : 0) |
96a22b
-		((count_active_paths(mpp) == 0 || mpp->ghost_delay_tick > 0) ?
96a22b
+		((count_active_pending_paths(mpp) == 0 ||
96a22b
+		  mpp->ghost_delay_tick > 0) ?
96a22b
 		 MPATH_UDEV_NO_PATHS_FLAG : 0) |
96a22b
 		(reload && !mpp->force_udev_reload ?
96a22b
 		 MPATH_UDEV_RELOAD_FLAG : 0);
96a22b
diff --git a/libmultipath/structs.c b/libmultipath/structs.c
96a22b
index 2dd378c4..dda9884c 100644
96a22b
--- a/libmultipath/structs.c
96a22b
+++ b/libmultipath/structs.c
96a22b
@@ -500,6 +500,26 @@ int count_active_paths(const struct multipath *mpp)
96a22b
 	return count;
96a22b
 }
96a22b
 
96a22b
+int count_active_pending_paths(const struct multipath *mpp)
96a22b
+{
96a22b
+	struct pathgroup *pgp;
96a22b
+	struct path *pp;
96a22b
+	int count = 0;
96a22b
+	int i, j;
96a22b
+
96a22b
+	if (!mpp->pg)
96a22b
+		return 0;
96a22b
+
96a22b
+	vector_foreach_slot (mpp->pg, pgp, i) {
96a22b
+		vector_foreach_slot (pgp->paths, pp, j) {
96a22b
+			if (pp->state == PATH_UP || pp->state == PATH_GHOST ||
96a22b
+			    pp->state == PATH_PENDING)
96a22b
+				count++;
96a22b
+		}
96a22b
+	}
96a22b
+	return count;
96a22b
+}
96a22b
+
96a22b
 int pathcmp(const struct pathgroup *pgp, const struct pathgroup *cpgp)
96a22b
 {
96a22b
 	int i, j;
96a22b
diff --git a/libmultipath/structs.h b/libmultipath/structs.h
96a22b
index 9bd39eb1..8e78b8c0 100644
96a22b
--- a/libmultipath/structs.h
96a22b
+++ b/libmultipath/structs.h
96a22b
@@ -465,6 +465,7 @@ struct path * first_path (const struct multipath *mpp);
96a22b
 int pathcountgr (const struct pathgroup *, int);
96a22b
 int pathcount (const struct multipath *, int);
96a22b
 int count_active_paths(const struct multipath *);
96a22b
+int count_active_pending_paths(const struct multipath *);
96a22b
 int pathcmp (const struct pathgroup *, const struct pathgroup *);
96a22b
 int add_feature (char **, const char *);
96a22b
 int remove_feature (char **, const char *);
96a22b
-- 
96a22b
2.17.2
96a22b