diff mbox series

[v2,26/49] libmultipath: reimplement dm_map_name() with new API

Message ID 20240712171458.77611-27-mwilck@suse.com (mailing list archive)
State Not Applicable, archived
Delegated to: christophe varoqui
Headers show
Series multipath-tools: devmapper API refactored | expand

Commit Message

Martin Wilck July 12, 2024, 5:14 p.m. UTC
Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/devmapper.c | 34 ++++++----------------------------
 1 file changed, 6 insertions(+), 28 deletions(-)

Comments

Benjamin Marzinski July 15, 2024, 10:42 p.m. UTC | #1
On Fri, Jul 12, 2024 at 07:14:34PM +0200, Martin Wilck wrote:
> Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
> ---
>  libmultipath/devmapper.c | 34 ++++++----------------------------
>  1 file changed, 6 insertions(+), 28 deletions(-)
> 
> diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
> index 003d834..8af4167 100644
> --- a/libmultipath/devmapper.c
> +++ b/libmultipath/devmapper.c
> @@ -1481,37 +1481,15 @@ dm_is_suspended(const char *name)
>  	return info.suspended;
>  }
>  
> -char *
> -dm_mapname(int major, int minor)
> +char *dm_mapname(int major, int minor)
>  {
> -	char * response = NULL;
> -	const char *map;
> -	struct dm_task *dmt;
> -	int r;
> +	char name[WWID_SIZE];
>  
> -	if (!(dmt = libmp_dm_task_create(DM_DEVICE_INFO)))
> +	if (libmp_mapinfo(DM_MAP_BY_DEV,
> +			  (mapid_t) { ._u = { major, minor } },
> +			  (mapinfo_t) { .name = name }) != DMP_OK)
>  		return NULL;
> -
> -	if (!dm_task_set_major(dmt, major) ||
> -	    !dm_task_set_minor(dmt, minor))
> -		goto bad;
> -
> -	r = libmp_dm_task_run(dmt);
> -	if (!r) {
> -		dm_log_error(2, DM_DEVICE_INFO, dmt);
> -		goto bad;
> -	}
> -
> -	map = dm_task_get_name(dmt);
> -	if (map && strlen(map))
> -		response = strdup((const char *)map);
> -
> -	dm_task_destroy(dmt);
> -	return response;
> -bad:
> -	dm_task_destroy(dmt);
> -	condlog(0, "%i:%i: error fetching map name", major, minor);
> -	return NULL;
> +	return strdup(name);
>  }
>  
>  static int
> -- 
> 2.45.2
diff mbox series

Patch

diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
index 003d834..8af4167 100644
--- a/libmultipath/devmapper.c
+++ b/libmultipath/devmapper.c
@@ -1481,37 +1481,15 @@  dm_is_suspended(const char *name)
 	return info.suspended;
 }
 
-char *
-dm_mapname(int major, int minor)
+char *dm_mapname(int major, int minor)
 {
-	char * response = NULL;
-	const char *map;
-	struct dm_task *dmt;
-	int r;
+	char name[WWID_SIZE];
 
-	if (!(dmt = libmp_dm_task_create(DM_DEVICE_INFO)))
+	if (libmp_mapinfo(DM_MAP_BY_DEV,
+			  (mapid_t) { ._u = { major, minor } },
+			  (mapinfo_t) { .name = name }) != DMP_OK)
 		return NULL;
-
-	if (!dm_task_set_major(dmt, major) ||
-	    !dm_task_set_minor(dmt, minor))
-		goto bad;
-
-	r = libmp_dm_task_run(dmt);
-	if (!r) {
-		dm_log_error(2, DM_DEVICE_INFO, dmt);
-		goto bad;
-	}
-
-	map = dm_task_get_name(dmt);
-	if (map && strlen(map))
-		response = strdup((const char *)map);
-
-	dm_task_destroy(dmt);
-	return response;
-bad:
-	dm_task_destroy(dmt);
-	condlog(0, "%i:%i: error fetching map name", major, minor);
-	return NULL;
+	return strdup(name);
 }
 
 static int