All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benjamin Marzinski <bmarzins@redhat.com>
To: Martin Wilck <martin.wilck@suse.com>
Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>,
	dm-devel@lists.linux.dev, Martin Wilck <mwilck@suse.com>
Subject: Re: [PATCH v2 25/49] libmultipath: improve dm_get_wwid() return value logic
Date: Mon, 15 Jul 2024 18:42:30 -0400	[thread overview]
Message-ID: <ZpWl1qrpqZ-TQulk@redhat.com> (raw)
In-Reply-To: <20240712171458.77611-26-mwilck@suse.com>

On Fri, Jul 12, 2024 at 07:14:33PM +0200, Martin Wilck wrote:
> Make dm_get_wwid() return different status codes for non-existing maps,
> maps that exists but are not multipath maps, and generic error case,
> and handle these return codes appropriately in callers.
> 
> The error handling is als changed; dm_get_wwid() doesn't take
> care of making the ouput 0-terminated if anything fails. The
> caller is responsible for that. Change callers accordingly.
> 
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
> Signed-off-by: Martin Wilck <mwilck@suse.com>
> ---
>  libmultipath/alias.c     | 11 ++++++++---
>  libmultipath/configure.c | 27 +++++++++++++++------------
>  libmultipath/devmapper.c | 22 +++++++++++++++++-----
>  libmultipath/wwids.c     |  2 +-
>  multipathd/main.c        |  7 +++++--
>  tests/alias.c            | 10 +++++-----
>  6 files changed, 51 insertions(+), 28 deletions(-)
> 
> diff --git a/libmultipath/alias.c b/libmultipath/alias.c
> index 10e58a7..c4eb5d8 100644
> --- a/libmultipath/alias.c
> +++ b/libmultipath/alias.c
> @@ -408,13 +408,18 @@ static bool alias_already_taken(const char *alias, const char *map_wwid)
>  {
>  
>  	char wwid[WWID_SIZE];
> +	int rc = dm_get_wwid(alias, wwid, sizeof(wwid));
>  
> -	/* If the map doesn't exist, it's fine */
> -	if (dm_get_wwid(alias, wwid, sizeof(wwid)) != 0)
> +	/*
> +	 * If the map doesn't exist, it's fine.
> +	 * In the generic error case, assume that the device is not
> +	 * taken, and try to proceed.
> +	 */
> +	if (rc == DMP_NOT_FOUND || rc == DMP_ERR)
>  		return false;
>  
>  	/* If both the name and the wwid match, it's fine.*/
> -	if (strncmp(map_wwid, wwid, sizeof(wwid)) == 0)
> +	if (rc == DMP_OK && strncmp(map_wwid, wwid, sizeof(wwid)) == 0)
>  		return false;
>  
>  	condlog(3, "%s: alias '%s' already taken, reselecting alias",
> diff --git a/libmultipath/configure.c b/libmultipath/configure.c
> index 666d4e8..2fdaca8 100644
> --- a/libmultipath/configure.c
> +++ b/libmultipath/configure.c
> @@ -845,18 +845,21 @@ int domap(struct multipath *mpp, char *params, int is_daemon)
>  
>  	if (mpp->action == ACT_CREATE && dm_map_present(mpp->alias)) {
>  		char wwid[WWID_SIZE];
> +		int rc = dm_get_wwid(mpp->alias, wwid, sizeof(wwid));
>  
> -		if (dm_get_wwid(mpp->alias, wwid, sizeof(wwid)) == 0) {
> -			if (!strncmp(mpp->wwid, wwid, sizeof(wwid))) {
> -				condlog(3, "%s: map already present",
> -					mpp->alias);
> -				mpp->action = ACT_RELOAD;
> -			} else {
> -				condlog(0, "%s: map \"%s\" already present with WWID %s, skipping",
> -					mpp->wwid, mpp->alias, wwid);
> -				condlog(0, "please check alias settings in config and bindings file");
> -				mpp->action = ACT_REJECT;
> -			}
> +		if (rc == DMP_OK && !strncmp(mpp->wwid, wwid, sizeof(wwid))) {
> +			condlog(3, "%s: map already present",
> +				mpp->alias);
> +			mpp->action = ACT_RELOAD;
> +		} else if (rc == DMP_OK) {
> +			condlog(1, "%s: map \"%s\" already present with WWID \"%s\", skipping\n"
> +				   "please check alias settings in config and bindings file",
> +				mpp->wwid, mpp->alias, wwid);
> +			mpp->action = ACT_REJECT;
> +		} else if (rc == DMP_NO_MATCH) {
> +			condlog(1, "%s: alias \"%s\" already taken by a non-multipath map",
> +				mpp->wwid, mpp->alias);
> +			mpp->action = ACT_REJECT;
>  		}
>  	}
>  
> @@ -1320,7 +1323,7 @@ static int _get_refwwid(enum mpath_cmds cmd, const char *dev,
>  		break;
>  
>  	case DEV_DEVMAP:
> -		if (((dm_get_wwid(dev, tmpwwid, WWID_SIZE)) == 0)
> +		if (((dm_get_wwid(dev, tmpwwid, WWID_SIZE)) == DMP_OK)
>  		    && (strlen(tmpwwid)))
>  			refwwid = tmpwwid;
>  
> diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
> index 3fca08c..003d834 100644
> --- a/libmultipath/devmapper.c
> +++ b/libmultipath/devmapper.c
> @@ -840,19 +840,29 @@ int dm_get_map(const char *name, unsigned long long *size, char **outparams)
>  	}
>  }
>  
> +/**
> + * dm_get_wwid(): return WWID for a multipath map
> + * @returns:
> + *    DMP_OK if successful
> + *    DMP_NOT_FOUND if the map doesn't exist
> + *    DMP_NO_MATCH if the map exists but is not a multipath map
> + *    DMP_ERR for other errors
> + * Caller may access uuid if and only if DMP_OK is returned.
> + */
>  int dm_get_wwid(const char *name, char *uuid, int uuid_len)
>  {
>  	char tmp[DM_UUID_LEN];
> +	int rc = dm_get_dm_uuid(name, tmp);
>  
> -	if (dm_get_dm_uuid(name, tmp) != DMP_OK)
> -		return 1;
> +	if (rc != DMP_OK)
> +		return rc;
>  
>  	if (!strncmp(tmp, UUID_PREFIX, UUID_PREFIX_LEN))
>  		strlcpy(uuid, tmp + UUID_PREFIX_LEN, uuid_len);
>  	else
> -		uuid[0] = '\0';
> +		return DMP_NO_MATCH;
>  
> -	return 0;
> +	return DMP_OK;
>  }
>  
>  static int is_mpath_part(const char *part_name, const char *map_name)
> @@ -1388,8 +1398,10 @@ struct multipath *dm_get_multipath(const char *name)
>  	if (dm_get_map(name, &mpp->size, NULL) != DMP_OK)
>  		goto out;
>  
> -	if (dm_get_wwid(name, mpp->wwid, WWID_SIZE) != 0)
> +	if (dm_get_wwid(name, mpp->wwid, WWID_SIZE) != DMP_OK) {
>  		condlog(2, "%s: failed to get uuid for %s", __func__, name);
> +		mpp->wwid[0] = '\0';
> +	}
>  	if (dm_get_info(name, &mpp->dmi) != 0)
>  		condlog(2, "%s: failed to get info for %s", __func__, name);
>  
> diff --git a/libmultipath/wwids.c b/libmultipath/wwids.c
> index 7a4cb74..aac18c0 100644
> --- a/libmultipath/wwids.c
> +++ b/libmultipath/wwids.c
> @@ -295,7 +295,7 @@ should_multipath(struct path *pp1, vector pathvec, vector mpvec)
>  		struct multipath *mp = find_mp_by_wwid(mpvec, pp1->wwid);
>  
>  		if (mp != NULL &&
> -		    dm_get_wwid(mp->alias, tmp_wwid, WWID_SIZE) == 0 &&
> +		    dm_get_wwid(mp->alias, tmp_wwid, WWID_SIZE) == DMP_OK &&
>  		    !strncmp(tmp_wwid, pp1->wwid, WWID_SIZE)) {
>  			condlog(3, "wwid %s is already multipathed, keeping it",
>  				pp1->wwid);
> diff --git a/multipathd/main.c b/multipathd/main.c
> index 442a154..1e7a6ac 100644
> --- a/multipathd/main.c
> +++ b/multipathd/main.c
> @@ -726,8 +726,11 @@ add_map_without_path (struct vectors *vecs, const char *alias)
>  		condlog(3, "%s: cannot access table", mpp->alias);
>  		goto out;
>  	}
> -	if (!strlen(mpp->wwid))
> -		dm_get_wwid(mpp->alias, mpp->wwid, WWID_SIZE);
> +	if (!strlen(mpp->wwid) &&
> +	    dm_get_wwid(mpp->alias, mpp->wwid, WWID_SIZE) != DMP_OK) {
> +		condlog(3, "%s: cannot obtain WWID", mpp->alias);
> +		goto out;
> +	}
>  	if (!strlen(mpp->wwid))
>  		condlog(1, "%s: adding map with empty WWID", mpp->alias);
>  	conf = get_multipath_config();
> diff --git a/tests/alias.c b/tests/alias.c
> index 1f78656..a95b308 100644
> --- a/tests/alias.c
> +++ b/tests/alias.c
> @@ -84,7 +84,7 @@ int __wrap_dm_get_wwid(const char *name, char *uuid, int uuid_len)
>  	check_expected(uuid_len);
>  	assert_non_null(uuid);
>  	ret = mock_type(int);
> -	if (ret == 0)
> +	if (ret == DMP_OK)
>  		strcpy(uuid, mock_ptr_type(char *));
>  	return ret;
>  }
> @@ -438,14 +438,14 @@ static void mock_unused_alias(const char *alias)
>  {
>  	expect_string(__wrap_dm_get_wwid, name, alias);
>  	expect_value(__wrap_dm_get_wwid, uuid_len, WWID_SIZE);
> -	will_return(__wrap_dm_get_wwid, 1);
> +	will_return(__wrap_dm_get_wwid, DMP_NOT_FOUND);
>  }
>  
>  static void mock_self_alias(const char *alias, const char *wwid)
>  {
>  	expect_string(__wrap_dm_get_wwid, name, alias);
>  	expect_value(__wrap_dm_get_wwid, uuid_len, WWID_SIZE);
> -	will_return(__wrap_dm_get_wwid, 0);
> +	will_return(__wrap_dm_get_wwid, DMP_OK);
>  	will_return(__wrap_dm_get_wwid, wwid);
>  }
>  
> @@ -471,14 +471,14 @@ static void mock_self_alias(const char *alias, const char *wwid)
>  	do {								\
>  		expect_string(__wrap_dm_get_wwid, name, alias);		\
>  		expect_value(__wrap_dm_get_wwid, uuid_len, WWID_SIZE);	\
> -		will_return(__wrap_dm_get_wwid, 1);			\
> +		will_return(__wrap_dm_get_wwid, DMP_NOT_FOUND);		\
>  	} while (0)
>  
>  #define mock_used_alias(alias, wwid)					\
>  	do {								\
>  		expect_string(__wrap_dm_get_wwid, name, alias);		\
>  		expect_value(__wrap_dm_get_wwid, uuid_len, WWID_SIZE);	\
> -		will_return(__wrap_dm_get_wwid, 0);			\
> +		will_return(__wrap_dm_get_wwid, DMP_OK);		\
>  		will_return(__wrap_dm_get_wwid, "WWID_USED");		\
>  		expect_condlog(3, USED_STR(alias, wwid));		\
>  	} while(0)
> -- 
> 2.45.2


  reply	other threads:[~2024-07-15 22:42 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-12 17:14 [PATCH v2 00/49] multipath-tools: devmapper API refactored Martin Wilck
2024-07-12 17:14 ` [PATCH v2 01/49] multipath-tools CI: more fixes for arm/v7 Martin Wilck
2024-07-12 17:14 ` [PATCH v2 02/49] multipath-tools CI: fix dmevents test for Debian Sid, arm/v7 Martin Wilck
2024-07-12 17:14 ` [PATCH v2 03/49] create-config.mk: use printf instead of /bin/echo Martin Wilck
2024-07-12 17:14 ` [PATCH v2 04/49] multipathd.service.in: use @BINDIR@ instead of /sbin Martin Wilck
2024-07-12 17:14 ` [PATCH v2 05/49] Makefile.inc: replace @BINDIR@ with $(TGTDIR)/$(bindir) Martin Wilck
2024-07-12 17:14 ` [PATCH v2 06/49] kpartx.rules: use @BINDIR@ to locate kpartx Martin Wilck
2024-07-15 22:08   ` Benjamin Marzinski
2024-07-12 17:14 ` [PATCH v2 07/49] multipath-tools: Remove hard-coded paths to executables Martin Wilck
2024-07-12 17:14 ` [PATCH v2 08/49] multipath-tools: compile_commands.json fixes Martin Wilck
2024-07-12 17:14 ` [PATCH v2 09/49] multipath-tools: .gitignore: ignore o.wrap files for CI helpers Martin Wilck
2024-07-12 17:14 ` [PATCH v2 10/49] libmultipath: remove unused includes in devmapper.h Martin Wilck
2024-07-12 17:14 ` [PATCH v2 11/49] libmultipath: use DM_DEVICE_INFO in dm_mapname() Martin Wilck
2024-07-12 17:14 ` [PATCH v2 12/49] multipath-tools: don't call dm_task_no_open_count() Martin Wilck
2024-07-12 17:14 ` [PATCH v2 13/49] libmpathutil: export cleanup_udev_device() Martin Wilck
2024-07-12 17:14 ` [PATCH v2 14/49] libmpathutil: add cleanup_vector() Martin Wilck
2024-07-12 17:14 ` [PATCH v2 15/49] libmultipath: add cleanup helpers for struct multipath Martin Wilck
2024-07-12 17:14 ` [PATCH v2 16/49] libmultipath: add cleanup_dm_task(), and use it in devmapper.c Martin Wilck
2024-07-15 22:13   ` Benjamin Marzinski
2024-07-12 17:14 ` [PATCH v2 17/49] libmultipath: rename dm_type()->dm_type_match() and use symbolic values Martin Wilck
2024-07-15 22:14   ` Benjamin Marzinski
2024-07-12 17:14 ` [PATCH v2 18/49] libmultipath: Use symbolic return values for dm_is_mpath() Martin Wilck
2024-07-15 22:14   ` Benjamin Marzinski
2024-07-12 17:14 ` [PATCH v2 19/49] libmultipath: add libmp_mapinfo() Martin Wilck
2024-07-15 22:41   ` Benjamin Marzinski
2024-07-16 15:51     ` Martin Wilck
2024-07-16 20:19       ` Benjamin Marzinski
2024-07-12 17:14 ` [PATCH v2 20/49] libmultipath tests: add tests for libmp_mapinfo() Martin Wilck
2024-07-12 17:14 ` [PATCH v2 21/49] libmultipath: implement dm_get_info() and dm_map_present() with new API Martin Wilck
2024-07-12 17:14 ` [PATCH v2 22/49] libmultipath: remove dm_get_prefixed_uuid() Martin Wilck
2024-07-12 17:14 ` [PATCH v2 23/49] libmultipath: is_mpath_part(): improve parsing Martin Wilck
2024-07-12 17:14 ` [PATCH v2 24/49] libmultipath: rename dm_get_uuid() -> dm_get_wwid() Martin Wilck
2024-07-12 17:14 ` [PATCH v2 25/49] libmultipath: improve dm_get_wwid() return value logic Martin Wilck
2024-07-15 22:42   ` Benjamin Marzinski [this message]
2024-07-12 17:14 ` [PATCH v2 26/49] libmultipath: reimplement dm_map_name() with new API Martin Wilck
2024-07-15 22:42   ` Benjamin Marzinski
2024-07-12 17:14 ` [PATCH v2 27/49] libmultipath: reimplement dm_map_present_by_uuid() Martin Wilck
2024-07-12 17:14 ` [PATCH v2 28/49] libmultipath: reimplement dm_get_opencount() with new API Martin Wilck
2024-07-12 17:14 ` [PATCH v2 29/49] libmpathpersist: skip redundant dm_map_present() call Martin Wilck
2024-07-12 17:14 ` [PATCH v2 30/49] libmultipath: implement dm_is_mpath() with new API Martin Wilck
2024-07-15 22:43   ` Benjamin Marzinski
2024-07-12 17:14 ` [PATCH v2 31/49] libmultipath: implement dm_get_multipath() " Martin Wilck
2024-07-12 17:14 ` [PATCH v2 32/49] libmultipath: use libmp_mapinfo() in _dm_flush_map() Martin Wilck
2024-07-12 17:14 ` [PATCH v2 33/49] libmultipath: add is_mpath_uuid() helper Martin Wilck
2024-07-15 22:43   ` Benjamin Marzinski
2024-07-12 17:14 ` [PATCH v2 34/49] libmultipath: add is_mpath_part_uuid() helper Martin Wilck
2024-07-12 17:14 ` [PATCH v2 35/49] libmultipath: add dmp_errstr() helper Martin Wilck
2024-07-12 17:14 ` [PATCH v2 36/49] libmultipath: use libmp_mapinfo() in do_foreach_partmaps() Martin Wilck
2024-07-12 17:14 ` [PATCH v2 37/49] libmultipath: use libmp_pathinfo() in update_multipath_table() Martin Wilck
2024-07-15 22:44   ` Benjamin Marzinski
2024-07-12 17:14 ` [PATCH v2 38/49] libmultipath: update mpp->dmi " Martin Wilck
2024-07-12 17:14 ` [PATCH v2 39/49] libmultipath: drop extra call to dm_map_present() in domap() Martin Wilck
2024-07-12 17:14 ` [PATCH v2 40/49] libmultipath: split off update_multipath_table__() Martin Wilck
2024-07-12 17:14 ` [PATCH v2 41/49] multipath: implement check_usable_paths() with libmp_pathinfo() Martin Wilck
2024-07-15 22:45   ` Benjamin Marzinski
2024-07-12 17:14 ` [PATCH v2 42/49] multipathd: implement add_map_without_path() with libmp_mapinfo() Martin Wilck
2024-07-15 22:47   ` Benjamin Marzinski
2024-07-12 17:14 ` [PATCH v2 43/49] libmultipath: simplify dm_get_maps() Martin Wilck
2024-07-12 17:14 ` [PATCH v2 44/49] libmpathpersist: use libmp_mapinfo() in mpath_get_map() Martin Wilck
2024-07-15 22:48   ` Benjamin Marzinski
2024-07-12 17:14 ` [PATCH v2 45/49] libmpathpersist: use mpp->alias in do_mpath_persistent_reserve_out() Martin Wilck
2024-07-12 17:14 ` [PATCH v2 46/49] libmultipath: fix deferred_remove logic in remove_partmap() Martin Wilck
2024-07-15 22:49   ` Benjamin Marzinski
2024-07-12 17:14 ` [PATCH v2 47/49] libmultipath: don't call do_foreach_partmaps() recursively Martin Wilck
2024-07-15 22:51   ` Benjamin Marzinski
2024-07-12 17:14 ` [PATCH v2 48/49] libmultipath: Move UUID check into libmp_pathinfo__() Martin Wilck
2024-07-15 23:24   ` Benjamin Marzinski
2024-07-12 17:14 ` [PATCH v2 49/49] multipath-tools tests: fix directio test with real device Martin Wilck
2024-07-15 23:25   ` Benjamin Marzinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZpWl1qrpqZ-TQulk@redhat.com \
    --to=bmarzins@redhat.com \
    --cc=christophe.varoqui@opensvc.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=martin.wilck@suse.com \
    --cc=mwilck@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.