On Mon, Sep 11, 2023 at 06:38:11PM +0200, mwilck@xxxxxxxx wrote: > From: Martin Wilck <mwilck@xxxxxxxx> > > Factor out a trivial helper function. > Reviewed-by: Benjamin Marzinski <bmarzins@xxxxxxxxxx> > Signed-off-by: Martin Wilck <mwilck@xxxxxxxx> > --- > libmultipath/alias.c | 32 +++++++++++++++++++------------- > 1 file changed, 19 insertions(+), 13 deletions(-) > > diff --git a/libmultipath/alias.c b/libmultipath/alias.c > index c0139a2..83ded88 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 > -- > 2.42.0 -- dm-devel mailing list dm-devel@xxxxxxxxxx https://listman.redhat.com/mailman/listinfo/dm-devel