From: mwilck@suse.com
To: Christophe Varoqui <christophe.varoqui@opensvc.com>,
Benjamin Marzinski <bmarzins@redhat.com>
Cc: dm-devel@redhat.com, Martin Wilck <mwilck@suse.com>
Subject: [dm-devel] [PATCH v2 21/37] libmultipath: adapt to new semantics of dm_get_uuid()
Date: Mon, 11 Sep 2023 18:38:30 +0200 [thread overview]
Message-ID: <20230911163846.27197-22-mwilck@suse.com> (raw)
In-Reply-To: <20230911163846.27197-1-mwilck@suse.com>
From: Martin Wilck <mwilck@suse.com>
dm_get_uuid() will return 1 for non-existing maps. Thus we don't need
to call dm_map_present() any more in alias_already_taken(). This changes
our semantics: previously we'd avoid using an alias for which dm_get_uuid()
had failed. Now we treat failure in dm_get_uuid() as indication that the
map doesn't exist. This is not dangerous because dm_task_get_uuid() cannot
fail, and thus the modified dm_get_uuid() will fail if and only if
dm_map_present() would return false.
This makes the "failed alias" test mostly obsolete, as "failed" is now
treated as "unused".
Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
---
libmultipath/alias.c | 23 ++++++++++++-----------
tests/alias.c | 32 +++++++-------------------------
2 files changed, 19 insertions(+), 36 deletions(-)
diff --git a/libmultipath/alias.c b/libmultipath/alias.c
index d656374..58436ec 100644
--- a/libmultipath/alias.c
+++ b/libmultipath/alias.c
@@ -295,18 +295,19 @@ scan_devname(const char *alias, const char *prefix)
static bool alias_already_taken(const char *alias, const char *map_wwid)
{
- if (dm_map_present(alias)) {
- char wwid[WWID_SIZE];
+ 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 false;
- condlog(3, "%s: alias '%s' already taken, reselecting alias",
- map_wwid, alias);
- return true;
- }
- return false;
+ /* If the map doesn't exist, it's fine */
+ if (dm_get_uuid(alias, wwid, sizeof(wwid)) != 0)
+ return false;
+
+ /* If both the name and the wwid match, it's fine.*/
+ if (strncmp(map_wwid, wwid, sizeof(wwid)) == 0)
+ return false;
+
+ condlog(3, "%s: alias '%s' already taken, reselecting alias",
+ map_wwid, alias);
+ return true;
}
static bool id_already_taken(int id, const char *prefix, const char *map_wwid)
diff --git a/tests/alias.c b/tests/alias.c
index 50a21ec..d1cc487 100644
--- a/tests/alias.c
+++ b/tests/alias.c
@@ -73,12 +73,6 @@ int __wrap_mkstemp(char *template)
return 10;
}
-int __wrap_dm_map_present(const char * str)
-{
- check_expected(str);
- return mock_type(int);
-}
-
int __wrap_dm_get_uuid(const char *name, char *uuid, int uuid_len)
{
int ret;
@@ -398,14 +392,13 @@ static int test_scan_devname(void)
static void mock_unused_alias(const char *alias)
{
- expect_string(__wrap_dm_map_present, str, alias);
- will_return(__wrap_dm_map_present, 0);
+ expect_string(__wrap_dm_get_uuid, name, alias);
+ expect_value(__wrap_dm_get_uuid, uuid_len, WWID_SIZE);
+ will_return(__wrap_dm_get_uuid, 1);
}
static void mock_self_alias(const char *alias, const char *wwid)
{
- expect_string(__wrap_dm_map_present, str, alias);
- will_return(__wrap_dm_map_present, 1);
expect_string(__wrap_dm_get_uuid, name, alias);
expect_value(__wrap_dm_get_uuid, uuid_len, WWID_SIZE);
will_return(__wrap_dm_get_uuid, 0);
@@ -432,18 +425,13 @@ static void mock_self_alias(const char *alias, const char *wwid)
#define mock_failed_alias(alias, wwid) \
do { \
- expect_string(__wrap_dm_map_present, str, alias); \
- will_return(__wrap_dm_map_present, 1); \
expect_string(__wrap_dm_get_uuid, name, alias); \
expect_value(__wrap_dm_get_uuid, uuid_len, WWID_SIZE); \
will_return(__wrap_dm_get_uuid, 1); \
- expect_condlog(3, USED_STR(alias, wwid)); \
} while (0)
#define mock_used_alias(alias, wwid) \
do { \
- expect_string(__wrap_dm_map_present, str, alias); \
- will_return(__wrap_dm_map_present, 1); \
expect_string(__wrap_dm_get_uuid, name, alias); \
expect_value(__wrap_dm_get_uuid, uuid_len, WWID_SIZE); \
will_return(__wrap_dm_get_uuid, 0); \
@@ -566,9 +554,8 @@ static void lb_empty_failed(void **state)
mock_bindings_file("");
expect_condlog(3, NOMATCH_WWID_STR("WWID0"));
mock_failed_alias("MPATHa", "WWID0");
- mock_unused_alias("MPATHb");
rc = lookup_binding(NULL, "WWID0", &alias, "MPATH", 1);
- assert_int_equal(rc, 2);
+ assert_int_equal(rc, 1);
assert_ptr_equal(alias, NULL);
free(alias);
}
@@ -666,9 +653,8 @@ static void lb_nomatch_a_3_used_failed_self(void **state)
mock_used_alias("MPATHc", "WWID1");
mock_used_alias("MPATHd", "WWID1");
mock_failed_alias("MPATHe", "WWID1");
- mock_self_alias("MPATHf", "WWID1");
rc = lookup_binding(NULL, "WWID1", &alias, "MPATH", 1);
- assert_int_equal(rc, 6);
+ assert_int_equal(rc, 5);
assert_ptr_equal(alias, NULL);
}
@@ -940,7 +926,7 @@ static void lb_nomatch_b_a_aa(void **state)
static void lb_nomatch_b_a_aa_zz(void **state)
{
- int rc, i;
+ int rc;
char *alias;
STRBUF_ON_STACK(buf);
@@ -949,11 +935,7 @@ static void lb_nomatch_b_a_aa_zz(void **state)
* lookup_binding finds MPATHaaa as next free entry, because MPATHaa is
* found before MPATHb, and MPATHzz was in the bindings, too.
*/
- for (i = 0; i <= 26; i++) {
- print_strbuf(&buf, "MPATH");
- format_devname(&buf, i + 1);
- print_strbuf(&buf, " WWID%d\n", i);
- }
+ fill_bindings(&buf, 0, 26);
print_strbuf(&buf, "MPATHzz WWID676\n");
mock_bindings_file(get_strbuf_str(&buf));
expect_condlog(3, NOMATCH_WWID_STR("WWID703"));
--
2.42.0
--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel
next prev parent reply other threads:[~2023-09-11 16:39 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-11 16:38 [dm-devel] [PATCH v2 00/37] multipath-tools: user-friendly names rework mwilck
2023-09-11 16:38 ` [dm-devel] [PATCH v2 01/37] libmultipath: sysfs_set_scsi_tmo: do nothing for ACT_DRY_RUN mwilck
2023-09-11 16:38 ` [dm-devel] [PATCH v2 02/37] libmultipath: add alias_already_taken() mwilck
2023-09-12 22:59 ` Benjamin Marzinski
2023-09-11 16:38 ` [dm-devel] [PATCH v2 03/37] libmultipath: unify use_existing_alias() and get_user_friendly_alias() mwilck
2023-09-11 16:38 ` [dm-devel] [PATCH v2 04/37] libmultipath: never allocate an alias that's already taken mwilck
2023-09-12 23:00 ` Benjamin Marzinski
2023-09-11 16:38 ` [dm-devel] [PATCH v2 05/37] libmultipath: lookup_binding: add comment about the algorithm mwilck
2023-09-11 16:38 ` [dm-devel] [PATCH v2 06/37] multipath-tools test: simplify debugging for condlog mismatch mwilck
2023-09-11 16:38 ` [dm-devel] [PATCH v2 07/37] multipath-tools tests: add tests for get_user_friendly_alias() mwilck
2023-09-12 23:00 ` Benjamin Marzinski
2023-09-11 16:38 ` [dm-devel] [PATCH v2 08/37] multipath-tools test: consistent use of macros in alias test mwilck
2023-09-11 16:38 ` [dm-devel] [PATCH v2 09/37] multipath-tools tests: convert mock_{failed, used}_alias to macros mwilck
2023-09-11 16:38 ` [dm-devel] [PATCH v2 10/37] multipath-tools test: use mock_bindings_file() consistently mwilck
2023-09-11 16:38 ` [dm-devel] [PATCH v2 11/37] libmultipath: add global variable for current bindings mwilck
2023-09-11 16:38 ` [dm-devel] [PATCH v2 12/37] libmultipath: rename fix_bindings_file() to update_bindings_file() mwilck
2023-09-11 16:38 ` [dm-devel] [PATCH v2 13/37] libmultipath: alias.c: move bindings related code up mwilck
2023-09-11 16:38 ` [dm-devel] [PATCH v2 14/37] libmultipath: update_bindings_file: take filename argument mwilck
2023-09-11 16:38 ` [dm-devel] [PATCH v2 15/37] libmultipath: update_bindings_file: use a single write() mwilck
2023-09-11 16:38 ` [dm-devel] [PATCH v2 16/37] libmultipath: update_bindings_file: don't log temp file name mwilck
2023-09-11 16:38 ` [dm-devel] [PATCH v2 17/37] libmultipath: alias.c: factor out read_binding() mwilck
2023-09-11 16:38 ` [dm-devel] [PATCH v2 18/37] libmultipath: keep bindings in memory mwilck
2023-09-12 23:00 ` Benjamin Marzinski
2023-09-11 16:38 ` [dm-devel] [PATCH v2 19/37] multipath-tools tests: fix alias tests mwilck
2023-09-12 22:02 ` Benjamin Marzinski
2023-09-11 16:38 ` [dm-devel] [PATCH v2 20/37] libmultipath: dm_get_uuid(): return emtpy UUID for non-existing maps mwilck
2023-09-11 16:38 ` mwilck [this message]
2023-09-11 16:38 ` [dm-devel] [PATCH v2 22/37] libmultipath: sort aliases by length and strcmp mwilck
2023-09-12 23:00 ` Benjamin Marzinski
2023-09-13 13:53 ` Martin Wilck
2023-09-13 14:38 ` Benjamin Marzinski
2023-09-13 19:07 ` Martin Wilck
2023-09-13 23:15 ` Benjamin Marzinski
2023-09-11 16:38 ` [dm-devel] [PATCH v2 23/37] multipath-tools tests: fix alias test after sort order change mwilck
2023-09-12 23:01 ` Benjamin Marzinski
2023-09-11 16:38 ` [dm-devel] [PATCH v2 24/37] libmultipath: simplify get_free_id() assuming total ordering mwilck
2023-09-12 22:59 ` Benjamin Marzinski
2023-09-11 16:38 ` [dm-devel] [PATCH v2 25/37] multipath-tools tests: adapt alias tests for " mwilck
2023-09-12 23:01 ` Benjamin Marzinski
2023-09-11 16:38 ` [dm-devel] [PATCH v2 26/37] multipath-tools tests: add test for ordering of bindings mwilck
2023-09-12 23:05 ` Benjamin Marzinski
2023-09-12 23:20 ` Benjamin Marzinski
2023-09-13 14:05 ` Martin Wilck
2023-09-11 16:38 ` [dm-devel] [PATCH v2 27/37] multipathd: watch bindings file with inotify + timestamp mwilck
2023-09-13 22:07 ` Benjamin Marzinski
2023-09-14 13:25 ` Martin Wilck
2023-09-14 14:28 ` Martin Wilck
2023-09-14 15:00 ` Benjamin Marzinski
2023-09-11 16:38 ` [dm-devel] [PATCH v2 28/37] multipath-tools tests: mock pthread_mutex_{lock, unlock} mwilck
2023-09-13 22:18 ` Benjamin Marzinski
2023-09-11 16:38 ` [dm-devel] [PATCH v2 29/37] multipath-tools Makefile: sanitize paths for configuration files mwilck
2023-09-13 22:30 ` Benjamin Marzinski
2023-09-11 16:38 ` [dm-devel] [PATCH v2 30/37] multipath-tools: add compile time configuration for "/etc/multipath" mwilck
2023-09-13 22:32 ` Benjamin Marzinski
2023-09-11 16:38 ` [dm-devel] [PATCH v2 31/37] multipath-tools man pages: generate with correct paths mwilck
2023-09-13 22:44 ` Benjamin Marzinski
2023-09-11 16:38 ` [dm-devel] [PATCH v2 32/37] libdmmp/Makefile: fix bug in install section mwilck
2023-09-13 22:46 ` Benjamin Marzinski
2023-09-11 16:38 ` [dm-devel] [PATCH v2 33/37] multipath-tools: README.md: improve documentation for compile-time options mwilck
2023-09-13 22:58 ` Benjamin Marzinski
2023-09-11 16:38 ` [dm-devel] [PATCH v2 34/37] libmultipath: print built-in values for deprecated options mwilck
2023-09-13 23:05 ` Benjamin Marzinski
2023-09-11 16:38 ` [dm-devel] [PATCH v2 35/37] multipath: add a missing newline mwilck
2023-09-13 23:05 ` Benjamin Marzinski
2023-09-11 16:38 ` [dm-devel] [PATCH v2 36/37] multipath-tools: allow prefixes with and w/o trailing slash mwilck
2023-09-13 23:09 ` Benjamin Marzinski
2023-09-11 16:38 ` [dm-devel] [PATCH v2 37/37] libmultipath: deprecate bindings_file, wwids_file, prkeys_file mwilck
2023-09-13 23:13 ` 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=20230911163846.27197-22-mwilck@suse.com \
--to=mwilck@suse.com \
--cc=bmarzins@redhat.com \
--cc=christophe.varoqui@opensvc.com \
--cc=dm-devel@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox