device-mapper-multipath/0002-libmultipath-add-alias_already_taken.patch

76 lines
2.1 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martin Wilck <mwilck@suse.com>
Date: Tue, 22 Aug 2023 21:36:11 +0200
Subject: [PATCH] libmultipath: add alias_already_taken()
Factor out a trivial helper function.
Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
libmultipath/alias.c | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)
diff --git a/libmultipath/alias.c b/libmultipath/alias.c
index c0139a2e..83ded886 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,30 +110,35 @@ 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)
{
- STRBUF_ON_STACK(buf);
- const char *alias;
-
- if (append_strbuf_str(&buf, prefix) < 0 ||
- format_devname(&buf, id) < 0)
- 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 false;
+ condlog(3, "%s: alias '%s' already taken, but not in bindings file. reselecting alias",
+ map_wwid, alias);
+ return true;
}
- return 0;
+ return false;
}
+static bool id_already_taken(int id, const char *prefix, const char *map_wwid)
+{
+ STRBUF_ON_STACK(buf);
+ const char *alias;
+
+ if (append_strbuf_str(&buf, prefix) < 0 ||
+ format_devname(&buf, id) < 0)
+ return false;
+
+ alias = get_strbuf_str(&buf);
+ return alias_already_taken(alias, map_wwid);
+}
/*
* Returns: 0 if matching entry in WWIDs file found