diff mbox series

[v2,05/18] libmultipath: make _dm_flush_map() return an enum

Message ID 20240103175643.18438-6-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
A future patch will add an additional return code, so make this an enum
instead of just using numbers.

Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
 libmultipath/devmapper.c | 18 +++++++++---------
 libmultipath/devmapper.h |  7 +++++++
 multipath/main.c         |  2 +-
 multipathd/main.c        | 12 ++++++------
 4 files changed, 23 insertions(+), 16 deletions(-)
diff mbox series

Patch

diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
index 1646110b..f5b4f4c0 100644
--- a/libmultipath/devmapper.c
+++ b/libmultipath/devmapper.c
@@ -1071,7 +1071,7 @@  int _dm_flush_map (const char * mapname, int need_sync, int deferred_remove,
 	char *params = NULL;
 
 	if (dm_is_mpath(mapname) != 1)
-		return 0; /* nothing to do */
+		return DM_FLUSH_OK; /* nothing to do */
 
 	/* if the device currently has no partitions, do not
 	   run kpartx on it if you fail to delete it */
@@ -1081,7 +1081,7 @@  int _dm_flush_map (const char * mapname, int need_sync, int deferred_remove,
 	/* If you aren't doing a deferred remove, make sure that no
 	 * devices are in use */
 	if (!do_deferred(deferred_remove) && partmap_in_use(mapname, NULL))
-			return 1;
+			return DM_FLUSH_FAIL;
 
 	if (need_suspend &&
 	    dm_get_map(mapname, &mapsize, &params) == DMP_OK &&
@@ -1096,11 +1096,11 @@  int _dm_flush_map (const char * mapname, int need_sync, int deferred_remove,
 	params = NULL;
 
 	if (dm_remove_partmaps(mapname, need_sync, deferred_remove))
-		return 1;
+		return DM_FLUSH_FAIL;
 
 	if (!do_deferred(deferred_remove) && dm_get_opencount(mapname)) {
 		condlog(2, "%s: map in use", mapname);
-		return 1;
+		return DM_FLUSH_FAIL;
 	}
 
 	do {
@@ -1114,14 +1114,14 @@  int _dm_flush_map (const char * mapname, int need_sync, int deferred_remove,
 			    && dm_map_present(mapname)) {
 				condlog(4, "multipath map %s remove deferred",
 					mapname);
-				return 2;
+				return DM_FLUSH_DEFERRED;
 			}
 			condlog(4, "multipath map %s removed", mapname);
-			return 0;
+			return DM_FLUSH_OK;
 		} else if (dm_is_mpath(mapname) != 1) {
 			condlog(4, "multipath map %s removed externally",
 				mapname);
-			return 0; /*we raced with someone else removing it */
+			return DM_FLUSH_OK; /* raced. someone else removed it */
 		} else {
 			condlog(2, "failed to remove multipath map %s",
 				mapname);
@@ -1137,7 +1137,7 @@  int _dm_flush_map (const char * mapname, int need_sync, int deferred_remove,
 	if (queue_if_no_path == 1)
 		_dm_queue_if_no_path(mapname, 1);
 
-	return 1;
+	return DM_FLUSH_FAIL;
 }
 
 #ifdef LIBDM_API_DEFERRED
@@ -1184,7 +1184,7 @@  int dm_flush_maps (int retries)
 		goto out;
 
 	do {
-		r |= dm_suspend_and_flush_map(names->name, retries);
+		r |= dm_suspend_and_flush_map(names->name, retries) != DM_FLUSH_OK;
 		next = names->next;
 		names = (void *) names + next;
 	} while (next);
diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h
index 1eacd966..9d484dab 100644
--- a/libmultipath/devmapper.h
+++ b/libmultipath/devmapper.h
@@ -48,6 +48,13 @@  int dm_get_map(const char *, unsigned long long *, char **);
 int dm_get_status(const char *, char **);
 int dm_type(const char *, char *);
 int dm_is_mpath(const char *);
+
+enum {
+	DM_FLUSH_OK = 0,
+	DM_FLUSH_FAIL,
+	DM_FLUSH_DEFERRED,
+};
+
 int _dm_flush_map (const char *, int, int, int, int);
 int dm_flush_map_nopaths(const char * mapname, int deferred_remove);
 #define dm_flush_map(mapname) _dm_flush_map(mapname, 1, 0, 0, 0)
diff --git a/multipath/main.c b/multipath/main.c
index c51884f2..00302087 100644
--- a/multipath/main.c
+++ b/multipath/main.c
@@ -1070,7 +1070,7 @@  main (int argc, char *argv[])
 			r = RTVL_FAIL;
 			goto out;
 		}
-		r = dm_suspend_and_flush_map(dev, retries) ?
+		r = (dm_suspend_and_flush_map(dev, retries) != DM_FLUSH_OK) ?
 		    RTVL_FAIL : RTVL_OK;
 		goto out;
 	}
diff --git a/multipathd/main.c b/multipathd/main.c
index 17468985..ed543caa 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -598,13 +598,13 @@  flush_map_nopaths(struct multipath *mpp, struct vectors *vecs) {
 		dm_queue_if_no_path(mpp, 0);
 	}
 	r = dm_flush_map_nopaths(mpp->alias, mpp->deferred_remove);
-	if (r) {
-		if (r == 1)
-			condlog(0, "%s: can't flush", mpp->alias);
-		else {
+	if (r != DM_FLUSH_OK) {
+		if (r == DM_FLUSH_DEFERRED) {
 			condlog(2, "%s: devmap deferred remove", mpp->alias);
 			mpp->deferred_remove = DEFERRED_REMOVE_IN_PROGRESS;
 		}
+		else
+			condlog(0, "%s: can't flush", mpp->alias);
 		return false;
 	}
 
@@ -746,7 +746,7 @@  coalesce_maps(struct vectors *vecs, vector nmpv)
 			 * remove all current maps not allowed by the
 			 * current configuration
 			 */
-			if (dm_flush_map(ompp->alias)) {
+			if (dm_flush_map(ompp->alias) != DM_FLUSH_OK) {
 				condlog(0, "%s: unable to flush devmap",
 					ompp->alias);
 				/*
@@ -789,7 +789,7 @@  int
 flush_map(struct multipath * mpp, struct vectors * vecs)
 {
 	int r = dm_suspend_and_flush_map(mpp->alias, 0);
-	if (r) {
+	if (r != DM_FLUSH_OK) {
 		condlog(0, "%s: can't flush", mpp->alias);
 		return r;
 	}