Blame SOURCES/0082-libmultipath-keep-renames-from-stopping-other-multip.patch

86e138
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
86e138
From: Benjamin Marzinski <bmarzins@redhat.com>
86e138
Date: Tue, 31 Jan 2023 12:00:31 -0600
86e138
Subject: [PATCH] libmultipath: keep renames from stopping other multipath
86e138
 actions
86e138
86e138
If select_action() is called and a multipath device needs to be renamed,
86e138
the code currently checks if force_reload is set, and if so, does the
86e138
reload after the rename.  But if force_reload isn't set, only the rename
86e138
happens, regardless of what other actions are needed. This can happen if
86e138
multipathd starts up and a device needs both a reload and a rename.
86e138
86e138
Make multipath check for resize, reload, and switch pathgroup along with
86e138
rename, and do both if necessary.
86e138
86e138
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
86e138
---
86e138
 libmultipath/configure.c | 62 +++++++++++++++++-----------------------
86e138
 libmultipath/configure.h |  4 ++-
86e138
 2 files changed, 30 insertions(+), 36 deletions(-)
86e138
86e138
diff --git a/libmultipath/configure.c b/libmultipath/configure.c
86e138
index 24d051dd..bbdbb8ca 100644
86e138
--- a/libmultipath/configure.c
86e138
+++ b/libmultipath/configure.c
86e138
@@ -714,7 +714,8 @@ static bool is_udev_ready(struct multipath *cmpp)
86e138
 static void
86e138
 select_reload_action(struct multipath *mpp, const char *reason)
86e138
 {
86e138
-	mpp->action = ACT_RELOAD;
86e138
+	mpp->action = mpp->action == ACT_RENAME ? ACT_RELOAD_RENAME :
86e138
+		      ACT_RELOAD;
86e138
 	condlog(3, "%s: set ACT_RELOAD (%s)", mpp->alias, reason);
86e138
 }
86e138
 
86e138
@@ -725,6 +726,7 @@ void select_action (struct multipath *mpp, const struct _vector *curmp,
86e138
 	struct multipath * cmpp_by_name;
86e138
 	char * mpp_feat, * cmpp_feat;
86e138
 
86e138
+	mpp->action = ACT_NOTHING;
86e138
 	cmpp = find_mp_by_wwid(curmp, mpp->wwid);
86e138
 	cmpp_by_name = find_mp_by_alias(curmp, mpp->alias);
86e138
 
86e138
@@ -747,14 +749,8 @@ void select_action (struct multipath *mpp, const struct _vector *curmp,
86e138
 			mpp->alias);
86e138
 		strlcpy(mpp->alias_old, cmpp->alias, WWID_SIZE);
86e138
 		mpp->action = ACT_RENAME;
86e138
-		if (force_reload) {
86e138
-			mpp->force_udev_reload = 1;
86e138
-			mpp->action = ACT_FORCERENAME;
86e138
-		}
86e138
-		return;
86e138
-	}
86e138
-
86e138
-	if (cmpp != cmpp_by_name) {
86e138
+		/* don't return here. Check for other needed actions */
86e138
+	} else if (cmpp != cmpp_by_name) {
86e138
 		condlog(2, "%s: unable to rename %s to %s (%s is used by %s)",
86e138
 			mpp->wwid, cmpp->alias, mpp->alias,
86e138
 			mpp->alias, cmpp_by_name->wwid);
86e138
@@ -762,12 +758,13 @@ void select_action (struct multipath *mpp, const struct _vector *curmp,
86e138
 		FREE(mpp->alias);
86e138
 		mpp->alias = STRDUP(cmpp->alias);
86e138
 		mpp->action = ACT_IMPOSSIBLE;
86e138
-		return;
86e138
+		/* don't return here. Check for other needed actions */
86e138
 	}
86e138
 
86e138
 	if (cmpp->size != mpp->size) {
86e138
 		mpp->force_udev_reload = 1;
86e138
-		mpp->action = ACT_RESIZE;
86e138
+		mpp->action = mpp->action == ACT_RENAME ? ACT_RESIZE_RENAME :
86e138
+			      ACT_RESIZE;
86e138
 		condlog(3, "%s: set ACT_RESIZE (size change)",
86e138
 			mpp->alias);
86e138
 		return;
86e138
@@ -843,14 +840,14 @@ void select_action (struct multipath *mpp, const struct _vector *curmp,
86e138
 		return;
86e138
 	}
86e138
 	if (cmpp->nextpg != mpp->bestpg) {
86e138
-		mpp->action = ACT_SWITCHPG;
86e138
+		mpp->action = mpp->action == ACT_RENAME ? ACT_SWITCHPG_RENAME :
86e138
+			      ACT_SWITCHPG;
86e138
 		condlog(3, "%s: set ACT_SWITCHPG (next path group change)",
86e138
 			mpp->alias);
86e138
 		return;
86e138
 	}
86e138
-	mpp->action = ACT_NOTHING;
86e138
-	condlog(3, "%s: set ACT_NOTHING (map unchanged)",
86e138
-		mpp->alias);
86e138
+	if (mpp->action == ACT_NOTHING)
86e138
+		condlog(3, "%s: set ACT_NOTHING (map unchanged)", mpp->alias);
86e138
 	return;
86e138
 }
86e138
 
86e138
@@ -951,6 +948,17 @@ int domap(struct multipath *mpp, char *params, int is_daemon)
86e138
 		}
86e138
 	}
86e138
 
86e138
+	if (mpp->action == ACT_RENAME || mpp->action == ACT_SWITCHPG_RENAME ||
86e138
+	    mpp->action == ACT_RELOAD_RENAME ||
86e138
+	    mpp->action == ACT_RESIZE_RENAME) {
86e138
+		conf = get_multipath_config();
86e138
+		pthread_cleanup_push(put_multipath_config, conf);
86e138
+		r = dm_rename(mpp->alias_old, mpp->alias,
86e138
+			      conf->partition_delim, mpp->skip_kpartx);
86e138
+		pthread_cleanup_pop(1);
86e138
+		if (r == DOMAP_FAIL)
86e138
+			return r;
86e138
+	}
86e138
 	switch (mpp->action) {
86e138
 	case ACT_REJECT:
86e138
 	case ACT_NOTHING:
86e138
@@ -958,6 +966,7 @@ int domap(struct multipath *mpp, char *params, int is_daemon)
86e138
 		return DOMAP_EXIST;
86e138
 
86e138
 	case ACT_SWITCHPG:
86e138
+	case ACT_SWITCHPG_RENAME:
86e138
 		dm_switchgroup(mpp->alias, mpp->bestpg);
86e138
 		/*
86e138
 		 * we may have avoided reinstating paths because there where in
86e138
@@ -984,6 +993,7 @@ int domap(struct multipath *mpp, char *params, int is_daemon)
86e138
 		break;
86e138
 
86e138
 	case ACT_RELOAD:
86e138
+	case ACT_RELOAD_RENAME:
86e138
 		sysfs_set_max_sectors_kb(mpp, 1);
86e138
 		if (mpp->ghost_delay_tick > 0 && pathcount(mpp, PATH_UP))
86e138
 			mpp->ghost_delay_tick = 0;
86e138
@@ -991,6 +1001,7 @@ int domap(struct multipath *mpp, char *params, int is_daemon)
86e138
 		break;
86e138
 
86e138
 	case ACT_RESIZE:
86e138
+	case ACT_RESIZE_RENAME:
86e138
 		sysfs_set_max_sectors_kb(mpp, 1);
86e138
 		if (mpp->ghost_delay_tick > 0 && pathcount(mpp, PATH_UP))
86e138
 			mpp->ghost_delay_tick = 0;
86e138
@@ -998,29 +1009,10 @@ int domap(struct multipath *mpp, char *params, int is_daemon)
86e138
 		break;
86e138
 
86e138
 	case ACT_RENAME:
86e138
-		conf = get_multipath_config();
86e138
-		pthread_cleanup_push(put_multipath_config, conf);
86e138
-		r = dm_rename(mpp->alias_old, mpp->alias,
86e138
-			      conf->partition_delim, mpp->skip_kpartx);
86e138
-		pthread_cleanup_pop(1);
86e138
-		break;
86e138
-
86e138
-	case ACT_FORCERENAME:
86e138
-		conf = get_multipath_config();
86e138
-		pthread_cleanup_push(put_multipath_config, conf);
86e138
-		r = dm_rename(mpp->alias_old, mpp->alias,
86e138
-			      conf->partition_delim, mpp->skip_kpartx);
86e138
-		pthread_cleanup_pop(1);
86e138
-		if (r) {
86e138
-			sysfs_set_max_sectors_kb(mpp, 1);
86e138
-			if (mpp->ghost_delay_tick > 0 &&
86e138
-			    pathcount(mpp, PATH_UP))
86e138
-				mpp->ghost_delay_tick = 0;
86e138
-			r = dm_addmap_reload(mpp, params, 0);
86e138
-		}
86e138
 		break;
86e138
 
86e138
 	default:
86e138
+		r = DOMAP_FAIL;
86e138
 		break;
86e138
 	}
86e138
 
86e138
diff --git a/libmultipath/configure.h b/libmultipath/configure.h
86e138
index 2bf73e65..9d935db3 100644
86e138
--- a/libmultipath/configure.h
86e138
+++ b/libmultipath/configure.h
86e138
@@ -18,9 +18,11 @@ enum actions {
86e138
 	ACT_RENAME,
86e138
 	ACT_CREATE,
86e138
 	ACT_RESIZE,
86e138
-	ACT_FORCERENAME,
86e138
+	ACT_RELOAD_RENAME,
86e138
 	ACT_DRY_RUN,
86e138
 	ACT_IMPOSSIBLE,
86e138
+	ACT_RESIZE_RENAME,
86e138
+	ACT_SWITCHPG_RENAME,
86e138
 };
86e138
 
86e138
 /*