Blame SOURCES/0027-multipathd-add-del-maps-multipathd-command.patch

785c99
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
785c99
From: Benjamin Marzinski <bmarzins@redhat.com>
785c99
Date: Mon, 15 Jun 2020 17:00:54 -0500
785c99
Subject: [PATCH] multipathd: add "del maps" multipathd command
785c99
785c99
This will flush all multipath devices.
785c99
785c99
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
785c99
---
785c99
 libmultipath/devmapper.c  |  7 +++++--
785c99
 libmultipath/devmapper.h  |  2 +-
785c99
 multipath/main.c          |  2 +-
785c99
 multipathd/cli.c          |  1 +
785c99
 multipathd/cli_handlers.c | 19 +++++++++++++++++++
785c99
 multipathd/cli_handlers.h |  1 +
785c99
 multipathd/main.c         |  3 ++-
785c99
 multipathd/main.h         |  1 +
785c99
 8 files changed, 31 insertions(+), 5 deletions(-)
785c99
785c99
diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
785c99
index cda83ce4..7f98bf9d 100644
785c99
--- a/libmultipath/devmapper.c
785c99
+++ b/libmultipath/devmapper.c
785c99
@@ -951,7 +951,7 @@ dm_flush_map_nopaths(const char * mapname, int deferred_remove)
785c99
 
785c99
 #endif
785c99
 
785c99
-int dm_flush_maps (int retries)
785c99
+int dm_flush_maps (int need_suspend, int retries)
785c99
 {
785c99
 	int r = 1;
785c99
 	struct dm_task *dmt;
785c99
@@ -974,7 +974,10 @@ int dm_flush_maps (int retries)
785c99
 
785c99
 	r = 0;
785c99
 	do {
785c99
-		r |= dm_suspend_and_flush_map(names->name, retries);
785c99
+		if (need_suspend)
785c99
+			r |= dm_suspend_and_flush_map(names->name, retries);
785c99
+		else
785c99
+			r |= dm_flush_map(names->name);
785c99
 		next = names->next;
785c99
 		names = (void *) names + next;
785c99
 	} while (next);
785c99
diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h
785c99
index adb55000..7e8812ad 100644
785c99
--- a/libmultipath/devmapper.h
785c99
+++ b/libmultipath/devmapper.h
785c99
@@ -55,7 +55,7 @@ int dm_flush_map_nopaths(const char * mapname, int deferred_remove);
785c99
 #define dm_suspend_and_flush_map(mapname, retries) \
785c99
 	_dm_flush_map(mapname, 1, 0, 1, retries)
785c99
 int dm_cancel_deferred_remove(struct multipath *mpp);
785c99
-int dm_flush_maps (int retries);
785c99
+int dm_flush_maps (int need_suspend, int retries);
785c99
 int dm_fail_path(const char * mapname, char * path);
785c99
 int dm_reinstate_path(const char * mapname, char * path);
785c99
 int dm_queue_if_no_path(const char *mapname, int enable);
785c99
diff --git a/multipath/main.c b/multipath/main.c
785c99
index 78822ee1..7ab3102f 100644
785c99
--- a/multipath/main.c
785c99
+++ b/multipath/main.c
785c99
@@ -1127,7 +1127,7 @@ main (int argc, char *argv[])
785c99
 		goto out;
785c99
 	}
785c99
 	else if (conf->remove == FLUSH_ALL) {
785c99
-		r = dm_flush_maps(retries) ? RTVL_FAIL : RTVL_OK;
785c99
+		r = dm_flush_maps(1, retries) ? RTVL_FAIL : RTVL_OK;
785c99
 		goto out;
785c99
 	}
785c99
 	while ((r = configure(conf, cmd, dev_type, dev)) == RTVL_RETRY)
785c99
diff --git a/multipathd/cli.c b/multipathd/cli.c
785c99
index 800c0fbe..bdc9fb10 100644
785c99
--- a/multipathd/cli.c
785c99
+++ b/multipathd/cli.c
785c99
@@ -568,6 +568,7 @@ cli_init (void) {
785c99
 	add_handler(DEL+PATH, NULL);
785c99
 	add_handler(ADD+MAP, NULL);
785c99
 	add_handler(DEL+MAP, NULL);
785c99
+	add_handler(DEL+MAPS, NULL);
785c99
 	add_handler(SWITCH+MAP+GROUP, NULL);
785c99
 	add_handler(RECONFIGURE, NULL);
785c99
 	add_handler(SUSPEND+MAP, NULL);
785c99
diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c
785c99
index 31c3d9fd..782bb003 100644
785c99
--- a/multipathd/cli_handlers.c
785c99
+++ b/multipathd/cli_handlers.c
785c99
@@ -852,6 +852,25 @@ cli_del_map (void * v, char ** reply, int * len, void * data)
785c99
 	return rc;
785c99
 }
785c99
 
785c99
+int
785c99
+cli_del_maps (void *v, char **reply, int *len, void *data)
785c99
+{
785c99
+	struct vectors * vecs = (struct vectors *)data;
785c99
+	struct multipath *mpp;
785c99
+	int i, ret = 0;
785c99
+
785c99
+	condlog(2, "remove maps (operator)");
785c99
+	vector_foreach_slot(vecs->mpvec, mpp, i) {
785c99
+		if (flush_map(mpp, vecs, 0))
785c99
+			ret++;
785c99
+		else
785c99
+			i--;
785c99
+	}
785c99
+	/* flush any multipath maps that aren't currently known by multipathd */
785c99
+	ret |= dm_flush_maps(0, 0);
785c99
+	return ret;
785c99
+}
785c99
+
785c99
 int
785c99
 cli_reload(void *v, char **reply, int *len, void *data)
785c99
 {
785c99
diff --git a/multipathd/cli_handlers.h b/multipathd/cli_handlers.h
785c99
index 0f451064..6f57b429 100644
785c99
--- a/multipathd/cli_handlers.h
785c99
+++ b/multipathd/cli_handlers.h
785c99
@@ -26,6 +26,7 @@ int cli_add_path (void * v, char ** reply, int * len, void * data);
785c99
 int cli_del_path (void * v, char ** reply, int * len, void * data);
785c99
 int cli_add_map (void * v, char ** reply, int * len, void * data);
785c99
 int cli_del_map (void * v, char ** reply, int * len, void * data);
785c99
+int cli_del_maps (void * v, char ** reply, int * len, void * data);
785c99
 int cli_switch_group(void * v, char ** reply, int * len, void * data);
785c99
 int cli_reconfigure(void * v, char ** reply, int * len, void * data);
785c99
 int cli_resize(void * v, char ** reply, int * len, void * data);
785c99
diff --git a/multipathd/main.c b/multipathd/main.c
785c99
index 1d9ce7f7..1d0579e9 100644
785c99
--- a/multipathd/main.c
785c99
+++ b/multipathd/main.c
785c99
@@ -631,7 +631,7 @@ sync_maps_state(vector mpvec)
785c99
 		sync_map_state(mpp);
785c99
 }
785c99
 
785c99
-static int
785c99
+int
785c99
 flush_map(struct multipath * mpp, struct vectors * vecs, int nopaths)
785c99
 {
785c99
 	int r;
785c99
@@ -1551,6 +1551,7 @@ uxlsnrloop (void * ap)
785c99
 	set_handler_callback(DEL+PATH, cli_del_path);
785c99
 	set_handler_callback(ADD+MAP, cli_add_map);
785c99
 	set_handler_callback(DEL+MAP, cli_del_map);
785c99
+	set_handler_callback(DEL+MAPS, cli_del_maps);
785c99
 	set_handler_callback(SWITCH+MAP+GROUP, cli_switch_group);
785c99
 	set_unlocked_handler_callback(RECONFIGURE, cli_reconfigure);
785c99
 	set_handler_callback(SUSPEND+MAP, cli_suspend);
785c99
diff --git a/multipathd/main.h b/multipathd/main.h
785c99
index 7bb8463f..5dff17e5 100644
785c99
--- a/multipathd/main.h
785c99
+++ b/multipathd/main.h
785c99
@@ -28,6 +28,7 @@ int ev_add_path (struct path *, struct vectors *, int);
785c99
 int ev_remove_path (struct path *, struct vectors *, int);
785c99
 int ev_add_map (char *, const char *, struct vectors *);
785c99
 int ev_remove_map (char *, char *, int, struct vectors *);
785c99
+int flush_map(struct multipath *, struct vectors *, int);
785c99
 int set_config_state(enum daemon_status);
785c99
 void * mpath_alloc_prin_response(int prin_sa);
785c99
 int prin_do_scsi_ioctl(char *, int rq_servact, struct prin_resp * resp,
785c99
-- 
785c99
2.17.2
785c99