diff mbox series

[v2,09/18] multipathd: handle busy devices in cli_del_maps()

Message ID 20240103175643.18438-10-bmarzins@redhat.com (mailing list archive)
State Not Applicable, archived
Delegated to: christophe varoqui
Headers show
Series change how multipathd deletes maps plus cleanups | expand

Commit Message

Benjamin Marzinski Jan. 3, 2024, 5:56 p.m. UTC
Make cli_del_maps() return -EBUSY like cli_del_map() if it fails because
a device is in use and it doesn't run into any other type of failures.

Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
 libmultipath/devmapper.c  | 10 +++++++---
 multipath/main.c          |  3 ++-
 multipathd/cli_handlers.c | 19 +++++++++++++------
 3 files changed, 22 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
index 6bbe784d..e970e71b 100644
--- a/libmultipath/devmapper.c
+++ b/libmultipath/devmapper.c
@@ -1163,7 +1163,7 @@  dm_flush_map_nopaths(const char * mapname,
 
 int dm_flush_maps (int retries)
 {
-	int r = 1;
+	int r = DM_FLUSH_FAIL;
 	struct dm_task *dmt;
 	struct dm_names *names;
 	unsigned next = 0;
@@ -1181,12 +1181,16 @@  int dm_flush_maps (int retries)
 	if (!(names = dm_task_get_names (dmt)))
 		goto out;
 
-	r = 0;
+	r = DM_FLUSH_OK;
 	if (!names->dev)
 		goto out;
 
 	do {
-		r |= dm_suspend_and_flush_map(names->name, retries) != DM_FLUSH_OK;
+		int ret;
+		ret = dm_suspend_and_flush_map(names->name, retries);
+		if (ret == DM_FLUSH_FAIL ||
+		    (r != DM_FLUSH_FAIL && ret == DM_FLUSH_BUSY))
+			r = ret;
 		next = names->next;
 		names = (void *) names + next;
 	} while (next);
diff --git a/multipath/main.c b/multipath/main.c
index 48d684e3..664f7b97 100644
--- a/multipath/main.c
+++ b/multipath/main.c
@@ -1082,7 +1082,8 @@  main (int argc, char *argv[])
 		goto out;
 	}
 	else if (cmd == CMD_FLUSH_ALL) {
-		r = dm_flush_maps(retries) ? RTVL_FAIL : RTVL_OK;
+		r = (dm_flush_maps(retries) != DM_FLUSH_OK) ?
+		    RTVL_FAIL : RTVL_OK;
 		goto out;
 	}
 	while ((r = configure(conf, cmd, dev_type, dev)) == RTVL_RETRY)
diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c
index b49bc73a..af211a6b 100644
--- a/multipathd/cli_handlers.c
+++ b/multipathd/cli_handlers.c
@@ -767,18 +767,25 @@  cli_del_maps (void *v, struct strbuf *reply, void *data)
 {
 	struct vectors * vecs = (struct vectors *)data;
 	struct multipath *mpp;
-	int i, ret = 0;
+	int i, ret, r = 0;
 
 	condlog(2, "remove maps (operator)");
 	vector_foreach_slot(vecs->mpvec, mpp, i) {
-		if (flush_map(mpp, vecs))
-			ret++;
-		else
+		ret = flush_map(mpp, vecs);
+		if (ret == DM_FLUSH_OK)
 			i--;
+		else if (ret == DM_FLUSH_BUSY && r != 1)
+			r = -EBUSY;
+		else
+			r = 1;
 	}
 	/* flush any multipath maps that aren't currently known by multipathd */
-	ret |= dm_flush_maps(0);
-	return ret;
+	ret = dm_flush_maps(0);
+	if (ret == DM_FLUSH_BUSY && r != 1)
+		r = -EBUSY;
+	else if (ret != DM_FLUSH_OK)
+		r = 1;
+	return r;
 }
 
 static int