diff mbox series

[20/21] libmultipath: dm_get_uuid(): return emtpy UUID for non-existing maps

Message ID 20230901180235.23980-21-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. 1, 2023, 6:02 p.m. UTC
From: Martin Wilck <mwilck@suse.com>

libdevmapper will most probably not return a UUID for non-existing
maps anyway. But it's cheap to double-check here.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/devmapper.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Benjamin Marzinski Sept. 6, 2023, 10:47 p.m. UTC | #1
On Fri, Sep 01, 2023 at 08:02:33PM +0200, mwilck@suse.com wrote:
> From: Martin Wilck <mwilck@suse.com>
> 
> libdevmapper will most probably not return a UUID for non-existing
> maps anyway. But it's cheap to double-check here.
> 
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
> Signed-off-by: Martin Wilck <mwilck@suse.com>
> ---
>  libmultipath/devmapper.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
> index 248c373..9be82f4 100644
> --- a/libmultipath/devmapper.c
> +++ b/libmultipath/devmapper.c
> @@ -706,12 +706,16 @@ dm_get_prefixed_uuid(const char *name, char *uuid, int uuid_len)
>  {
>  	struct dm_task *dmt;
>  	const char *uuidtmp;
> +	struct dm_info info;
>  	int r = 1;
>  
>  	dmt = libmp_dm_task_create(DM_DEVICE_INFO);
>  	if (!dmt)
>  		return 1;
>  
> +	if (uuid_len > 0)
> +		uuid[0] = '\0';
> +
>  	if (!dm_task_set_name (dmt, name))
>  		goto uuidout;
>  
> @@ -720,11 +724,13 @@ dm_get_prefixed_uuid(const char *name, char *uuid, int uuid_len)
>  		goto uuidout;
>  	}
>  
> +	if (!dm_task_get_info(dmt, &info) ||
> +	    !info.exists)
> +		goto uuidout;
> +
>  	uuidtmp = dm_task_get_uuid(dmt);
>  	if (uuidtmp)
>  		strlcpy(uuid, uuidtmp, uuid_len);
> -	else
> -		uuid[0] = '\0';
>  
>  	r = 0;
>  uuidout:
> -- 
> 2.41.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/devmapper.c b/libmultipath/devmapper.c
index 248c373..9be82f4 100644
--- a/libmultipath/devmapper.c
+++ b/libmultipath/devmapper.c
@@ -706,12 +706,16 @@  dm_get_prefixed_uuid(const char *name, char *uuid, int uuid_len)
 {
 	struct dm_task *dmt;
 	const char *uuidtmp;
+	struct dm_info info;
 	int r = 1;
 
 	dmt = libmp_dm_task_create(DM_DEVICE_INFO);
 	if (!dmt)
 		return 1;
 
+	if (uuid_len > 0)
+		uuid[0] = '\0';
+
 	if (!dm_task_set_name (dmt, name))
 		goto uuidout;
 
@@ -720,11 +724,13 @@  dm_get_prefixed_uuid(const char *name, char *uuid, int uuid_len)
 		goto uuidout;
 	}
 
+	if (!dm_task_get_info(dmt, &info) ||
+	    !info.exists)
+		goto uuidout;
+
 	uuidtmp = dm_task_get_uuid(dmt);
 	if (uuidtmp)
 		strlcpy(uuid, uuidtmp, uuid_len);
-	else
-		uuid[0] = '\0';
 
 	r = 0;
 uuidout: