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

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