diff mbox series

[v2,30/49] libmultipath: implement dm_is_mpath() with new API

Message ID 20240712171458.77611-31-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 | 59 ++++++++++------------------------------
 1 file changed, 15 insertions(+), 44 deletions(-)

Comments

Benjamin Marzinski July 15, 2024, 10:43 p.m. UTC | #1
On Fri, Jul 12, 2024 at 07:14:38PM +0200, Martin Wilck wrote:
> Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
> ---
>  libmultipath/devmapper.c | 59 ++++++++++------------------------------
>  1 file changed, 15 insertions(+), 44 deletions(-)
> 
> diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
> index 47ff827..11bccb1 100644
> --- a/libmultipath/devmapper.c
> +++ b/libmultipath/devmapper.c
> @@ -975,52 +975,23 @@ static int dm_type_match(const char *name, char *type)
>  
>  int dm_is_mpath(const char *name)
>  {
> -	int r = DM_IS_MPATH_ERR;
> -	struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL;
> -	struct dm_info info;
> -	uint64_t start, length;
> -	char *target_type = NULL;
> -	char *params;
> -	const char *uuid;
> +	char uuid[DM_UUID_LEN];
> +	int rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY,
> +			       (mapid_t) { .str = name },
> +			       (mapinfo_t) { .uuid = uuid });
>  
> -	if (!(dmt = libmp_dm_task_create(DM_DEVICE_TABLE)))
> -		goto out;
> -
> -	if (!dm_task_set_name(dmt, name))
> -		goto out;
> -
> -	if (!libmp_dm_task_run(dmt)) {
> -		dm_log_error(3, DM_DEVICE_TABLE, dmt);
> -		goto out;
> +	switch (rc) {
> +	case DMP_OK:
> +		if (!strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN))
> +			return DM_IS_MPATH_YES;
> +		/* fallthrough */
> +	case DMP_NOT_FOUND:
> +	case DMP_NO_MATCH:
> +		return DM_IS_MPATH_NO;
> +	case DMP_ERR:
> +	default:
> +		return DM_IS_MPATH_ERR;
>  	}
> -
> -	if (!dm_task_get_info(dmt, &info))
> -		goto out;
> -
> -	r = DM_IS_MPATH_NO;
> -
> -	if (!info.exists)
> -		goto out;
> -
> -	uuid = dm_task_get_uuid(dmt);
> -
> -	if (!uuid || strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN) != 0)
> -		goto out;
> -
> -	/* Fetch 1st target */
> -	if (dm_get_next_target(dmt, NULL, &start, &length, &target_type,
> -			       &params) != NULL)
> -		/* multiple targets */
> -		goto out;
> -
> -	if (!target_type || strcmp(target_type, TGT_MPATH) != 0)
> -		goto out;
> -
> -	r = DM_IS_MPATH_YES;
> -out:
> -	if (r == DM_IS_MPATH_ERR)
> -		condlog(3, "%s: dm command failed in %s: %s", name, __func__, strerror(errno));
> -	return r;
>  }
>  
>  int dm_map_present_by_wwid(const char *wwid)
> -- 
> 2.45.2
diff mbox series

Patch

diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
index 47ff827..11bccb1 100644
--- a/libmultipath/devmapper.c
+++ b/libmultipath/devmapper.c
@@ -975,52 +975,23 @@  static int dm_type_match(const char *name, char *type)
 
 int dm_is_mpath(const char *name)
 {
-	int r = DM_IS_MPATH_ERR;
-	struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL;
-	struct dm_info info;
-	uint64_t start, length;
-	char *target_type = NULL;
-	char *params;
-	const char *uuid;
+	char uuid[DM_UUID_LEN];
+	int rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY,
+			       (mapid_t) { .str = name },
+			       (mapinfo_t) { .uuid = uuid });
 
-	if (!(dmt = libmp_dm_task_create(DM_DEVICE_TABLE)))
-		goto out;
-
-	if (!dm_task_set_name(dmt, name))
-		goto out;
-
-	if (!libmp_dm_task_run(dmt)) {
-		dm_log_error(3, DM_DEVICE_TABLE, dmt);
-		goto out;
+	switch (rc) {
+	case DMP_OK:
+		if (!strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN))
+			return DM_IS_MPATH_YES;
+		/* fallthrough */
+	case DMP_NOT_FOUND:
+	case DMP_NO_MATCH:
+		return DM_IS_MPATH_NO;
+	case DMP_ERR:
+	default:
+		return DM_IS_MPATH_ERR;
 	}
-
-	if (!dm_task_get_info(dmt, &info))
-		goto out;
-
-	r = DM_IS_MPATH_NO;
-
-	if (!info.exists)
-		goto out;
-
-	uuid = dm_task_get_uuid(dmt);
-
-	if (!uuid || strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN) != 0)
-		goto out;
-
-	/* Fetch 1st target */
-	if (dm_get_next_target(dmt, NULL, &start, &length, &target_type,
-			       &params) != NULL)
-		/* multiple targets */
-		goto out;
-
-	if (!target_type || strcmp(target_type, TGT_MPATH) != 0)
-		goto out;
-
-	r = DM_IS_MPATH_YES;
-out:
-	if (r == DM_IS_MPATH_ERR)
-		condlog(3, "%s: dm command failed in %s: %s", name, __func__, strerror(errno));
-	return r;
 }
 
 int dm_map_present_by_wwid(const char *wwid)