diff mbox series

[v2,02/37] libmultipath: add alias_already_taken()

Message ID 20230911163846.27197-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

Commit Message

Martin Wilck Sept. 11, 2023, 4:38 p.m. UTC
From: Martin Wilck <mwilck@suse.com>

Factor out a trivial helper function.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/alias.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

Comments

Benjamin Marzinski Sept. 12, 2023, 10:59 p.m. UTC | #1
On Mon, Sep 11, 2023 at 06:38:11PM +0200, mwilck@suse.com wrote:
> From: Martin Wilck <mwilck@suse.com>
> 
> Factor out a trivial helper function.
> 
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
> Signed-off-by: Martin Wilck <mwilck@suse.com>
> ---
>  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@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel
diff mbox series

Patch

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