diff mbox series

[v2,12/18] multipathd: make cli_handlers check for paths by dev and devt

Message ID 20240103175643.18438-13-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
Some of the client handlers checked for paths by both dev and devt, but
not all. Also, many of the client handlers don't print anything if they
failed to find a path. Make all the client handlers which work on path
devices use a new function, find_path_by_str(), which will try both
methods to find a path, and can print out an error message if none is
found.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
 multipathd/cli_handlers.c | 40 ++++++++++++++++++++-------------------
 1 file changed, 21 insertions(+), 19 deletions(-)
diff mbox series

Patch

diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c
index 21fb9dd3..6d5d53bc 100644
--- a/multipathd/cli_handlers.c
+++ b/multipathd/cli_handlers.c
@@ -33,6 +33,20 @@ 
 #include "cli_handlers.h"
 #include "devmapper.h"
 
+static struct path *
+find_path_by_str(const struct _vector *pathvec, const char *str,
+		  const char *action_str)
+{
+	struct path *pp;
+
+	if (!(pp = find_path_by_devt(pathvec, str)))
+		pp = find_path_by_dev(pathvec, str);
+
+	if (!pp && action_str)
+		condlog(2, "%s: invalid path name. cannot %s", str, action_str);
+	return pp;
+}
+
 static int
 show_paths (struct strbuf *reply, struct vectors *vecs, char *style, int pretty)
 {
@@ -241,7 +255,7 @@  cli_list_path (void *v, struct strbuf *reply, void *data)
 	param = convert_dev(param, 1);
 	condlog(3, "%s: list path (operator)", param);
 
-	pp = find_path_by_dev(vecs->pathvec, param);
+	pp = find_path_by_str(vecs->pathvec, param, "list path");
 	if (!pp)
 		return 1;
 
@@ -556,7 +570,7 @@  cli_add_path (void *v, struct strbuf *reply, void *data)
 	if (invalid)
 		goto blacklisted;
 
-	pp = find_path_by_dev(vecs->pathvec, param);
+	pp = find_path_by_str(vecs->pathvec, param, NULL);
 	if (pp && pp->initialized != INIT_REMOVED) {
 		condlog(2, "%s: path already in pathvec", param);
 
@@ -665,7 +679,7 @@  cli_del_path (void * v, struct strbuf *reply, void * data)
 
 	param = convert_dev(param, 1);
 	condlog(2, "%s: remove path (operator)", param);
-	pp = find_path_by_dev(vecs->pathvec, param);
+	pp = find_path_by_str(vecs->pathvec, param, NULL);
 	if (!pp) {
 		condlog(0, "%s: path already removed", param);
 		return 1;
@@ -1092,10 +1106,7 @@  cli_reinstate(void * v, struct strbuf *reply, void * data)
 	struct path * pp;
 
 	param = convert_dev(param, 1);
-	pp = find_path_by_dev(vecs->pathvec, param);
-
-	if (!pp)
-		 pp = find_path_by_devt(vecs->pathvec, param);
+	pp = find_path_by_str(vecs->pathvec, param, "reinstate path");
 
 	if (!pp || !pp->mpp || !pp->mpp->alias)
 		return 1;
@@ -1140,10 +1151,7 @@  cli_fail(void * v, struct strbuf *reply, void * data)
 	int r;
 
 	param = convert_dev(param, 1);
-	pp = find_path_by_dev(vecs->pathvec, param);
-
-	if (!pp)
-		 pp = find_path_by_devt(vecs->pathvec, param);
+	pp = find_path_by_str(vecs->pathvec, param, "fail path");
 
 	if (!pp || !pp->mpp || !pp->mpp->alias)
 		return 1;
@@ -1384,10 +1392,7 @@  static int cli_set_marginal(void * v, struct strbuf *reply, void * data)
 	struct path * pp;
 
 	param = convert_dev(param, 1);
-	pp = find_path_by_dev(vecs->pathvec, param);
-
-	if (!pp)
-		pp = find_path_by_devt(vecs->pathvec, param);
+	pp = find_path_by_str(vecs->pathvec, param, "set marginal path");
 
 	if (!pp || !pp->mpp || !pp->mpp->alias)
 		return 1;
@@ -1411,10 +1416,7 @@  static int cli_unset_marginal(void * v, struct strbuf *reply, void * data)
 	struct path * pp;
 
 	param = convert_dev(param, 1);
-	pp = find_path_by_dev(vecs->pathvec, param);
-
-	if (!pp)
-		pp = find_path_by_devt(vecs->pathvec, param);
+	pp = find_path_by_str(vecs->pathvec, param, "unset marginal path");
 
 	if (!pp || !pp->mpp || !pp->mpp->alias)
 		return 1;