Message ID | 20230901180235.23980-3-mwilck@suse.com (mailing list archive) |
---|---|
State | Not Applicable, archived |
Delegated to: | christophe varoqui |
Headers | show |
Series | multipath-tools: user-friendly names rework | expand |
On Fri, Sep 01, 2023 at 08:02:15PM +0200, mwilck@suse.com wrote: > From: Martin Wilck <mwilck@suse.com> > > Factor out a trivial helper function. > > Signed-off-by: Martin Wilck <mwilck@suse.com> > Cc: David Bond <dbond@suse.com> > --- > libmultipath/alias.c | 34 ++++++++++++++++++++-------------- > 1 file changed, 20 insertions(+), 14 deletions(-) > @@ -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) Possibly this should return "false" to match the bool return type. Otherwise, it looks fine. -Ben > - 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@redhat.com https://listman.redhat.com/mailman/listinfo/dm-devel
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