[PATCH 02/21] libmultipath: add alias_already_taken()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Martin Wilck <mwilck@xxxxxxxx>

Factor out a trivial helper function.

Signed-off-by: Martin Wilck <mwilck@xxxxxxxx>
Cc: David Bond <dbond@xxxxxxxx>
---
 libmultipath/alias.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/libmultipath/alias.c b/libmultipath/alias.c
index c0139a2..abde08c 100644
--- a/libmultipath/alias.c
+++ b/libmultipath/alias.c
@@ -8,6 +8,7 @@
 #include <string.h>
 #include <limits.h>
 #include <stdio.h>
+#include <stdbool.h>
 
 #include "debug.h"
 #include "util.h"
@@ -109,8 +110,24 @@ scan_devname(const char *alias, const char *prefix)
 	return n;
 }
 
-static int
-id_already_taken(int id, const char *prefix, const char *map_wwid)
+static bool alias_already_taken(const char *alias, const char *map_wwid)
+{
+
+	if (dm_map_present(alias)) {
+		char wwid[WWID_SIZE];
+
+		/* If both the name and the wwid match, then it's fine.*/
+		if (dm_get_uuid(alias, wwid, sizeof(wwid)) == 0 &&
+		    strncmp(map_wwid, wwid, sizeof(wwid)) == 0)
+			return false;
+		condlog(3, "%s: alias '%s' already taken, but not in bindings file. reselecting alias",
+			map_wwid, alias);
+		return true;
+	}
+	return false;
+}
+
+static bool id_already_taken(int id, const char *prefix, const char *map_wwid)
 {
 	STRBUF_ON_STACK(buf);
 	const char *alias;
@@ -120,20 +137,9 @@ id_already_taken(int id, const char *prefix, const char *map_wwid)
 		return 0;
 
 	alias = get_strbuf_str(&buf);
-	if (dm_map_present(alias)) {
-		char wwid[WWID_SIZE];
-
-		/* If both the name and the wwid match, then it's fine.*/
-		if (dm_get_uuid(alias, wwid, sizeof(wwid)) == 0 &&
-		    strncmp(map_wwid, wwid, sizeof(wwid)) == 0)
-			return 0;
-		condlog(3, "%s: alias '%s' already taken, but not in bindings file. reselecting alias", map_wwid, alias);
-		return 1;
-	}
-	return 0;
+	return alias_already_taken(alias, map_wwid);
 }
 
-
 /*
  * Returns: 0   if matching entry in WWIDs file found
  *         -1   if an error occurs
-- 
2.41.0

--
dm-devel mailing list
dm-devel@xxxxxxxxxx
https://listman.redhat.com/mailman/listinfo/dm-devel




[Index of Archives]     [DM Crypt]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite Discussion]     [KDE Users]     [Fedora Docs]

  Powered by Linux