From 16c6ce9b94c20410971a551321fc1b772cdff0b5 Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 5 Jun 2024 19:22:48 -0400 Subject: [PATCH 001/145] multipathd: fix flush check in flush_map() Forgot the comparison in the "if" statement. Fixes 8a3898339 ("multipathd: sync features on flush_map failure corner case") Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipathd/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multipathd/main.c b/multipathd/main.c index 09286dd00..58afe14a7 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -813,7 +813,7 @@ flush_map(struct multipath * mpp, struct vectors * vecs) { int r = dm_suspend_and_flush_map(mpp->alias, 0); if (r != DM_FLUSH_OK) { - if (DM_FLUSH_FAIL_CANT_RESTORE) + if (r == DM_FLUSH_FAIL_CANT_RESTORE) remove_feature(&mpp->features, "queue_if_no_path"); condlog(0, "%s: can't flush", mpp->alias); return r; From d092638c065939c29ea14e9cbf872a72e95ebed4 Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 5 Jun 2024 19:22:49 -0400 Subject: [PATCH 002/145] libmultipath: check for not PATH_UP in detect_alua Previously detect_alua was setting pp->tpgs if the path state was either PATH_UP or PATH_REMOVED. Setting pp->tpgs for PATH_REMOVED makes no sense. PATH_UP is the only state that path_offline() returns where we should set pp->tpgs, so just check for that, instead of checking for all the states where we shouldn't set pp->tpgs. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- libmultipath/discovery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index e20524221..380e0e959 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -1087,7 +1087,7 @@ detect_alua(struct path * pp) return; state = path_offline(pp); - if (state == PATH_DOWN || state == PATH_PENDING) + if (state != PATH_UP) return; pp->tpgs = TPGS_NONE; From ca957f2ac27e453cb4719629f734556790ac3cfe Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 5 Jun 2024 19:22:52 -0400 Subject: [PATCH 003/145] multipath-tools: Makefile.inc: compile with -fexceptions multipath is not currently running the cleanup_functions from __attribute__((cleanup(cleanup_function))) when threads are cancelled. To do this, it needs to be compiled with -fexceptions https://gcc.gnu.org/onlinedocs/gcc-14.1.0/gcc/Common-Variable-Attributes.html#index-cleanup-variable-attribute Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- Makefile.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile.inc b/Makefile.inc index 81b86cd8f..ed4a42347 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -105,7 +105,8 @@ CPPFLAGS := $(FORTIFY_OPT) $(CPPFLAGS) $(D_URCU_VERSION) \ -DRUNTIME_DIR=\"$(runtimedir)\" -DCONFIG_DIR=\"$(TGTDIR)$(configdir)\" \ -DDEFAULT_CONFIGFILE=\"$(TGTDIR)$(configfile)\" -DSTATE_DIR=\"$(TGTDIR)$(statedir)\" \ -DEXTRAVERSION=\"$(EXTRAVERSION)\" -MMD -MP -CFLAGS := -std=gnu99 $(CFLAGS) $(OPTFLAGS) $(WARNFLAGS) -pipe +CFLAGS := -std=gnu99 $(CFLAGS) $(OPTFLAGS) $(WARNFLAGS) -pipe \ + -fexceptions BIN_CFLAGS := -fPIE -DPIE LIB_CFLAGS := -fPIC SHARED_FLAGS := -shared From 7f45a024bceecc0f227089b92c049a2e1ae40e7d Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 5 Jun 2024 19:22:53 -0400 Subject: [PATCH 004/145] multipathd: free alias if cli_add_map() is cancelled Use the cleanup attribute to make sure that alias is freed if cli_add_map() is cancelled. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipathd/cli_handlers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c index 117570e15..0106213ee 100644 --- a/multipathd/cli_handlers.c +++ b/multipathd/cli_handlers.c @@ -699,7 +699,8 @@ cli_add_map (void * v, struct strbuf *reply, void * data) char * param = get_keyparam(v, KEY_MAP); int major = -1, minor = -1; char dev_path[FILE_NAME_SIZE]; - char *refwwid, *alias = NULL; + char *refwwid; + char *alias __attribute__((cleanup(cleanup_charp))) = NULL; int rc, count = 0; struct config *conf; int invalid = 0; @@ -748,7 +749,6 @@ cli_add_map (void * v, struct strbuf *reply, void * data) return 1; } rc = ev_add_map(dev_path, alias, vecs); - free(alias); return rc; } From 282ea9f91e6161e6c9ed33d57e57f3a797254daf Mon Sep 17 00:00:00 2001 From: Kou Wenqi Date: Wed, 12 Jun 2024 14:18:37 +0800 Subject: [PATCH 005/145] multipath.conf.5: fix the description of prio_args for path_latency prio This aligns the description of prio_args for path_latency prio and the actual code. Signed-off-by: Kou Wenqi Reviewed-by: Martin Wilck Signed-off-by: Martin Wilck --- multipath/multipath.conf.5.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/multipath/multipath.conf.5.in b/multipath/multipath.conf.5.in index dacb9b0e2..e0794bacb 100644 --- a/multipath/multipath.conf.5.in +++ b/multipath/multipath.conf.5.in @@ -437,11 +437,11 @@ Needs a value of the form "io_num=\fI<20>\fR base_num=\fI<10>\fR" .TP 8 .I io_num The number of read IOs sent to the current path continuously, used to calculate the average path latency. -Valid Values: Integer, [2, 200]. +Valid Values: Integer, [20, 200]. .TP .I base_num -The base number value of logarithmic scale, used to partition different priority ranks. Valid Values: Integer, -[2, 10]. And Max average latency value is 100s, min average latency value is 1us. +The base number value of logarithmic scale, used to partition different priority ranks. Valid Values: +Double-precision floating-point, [1.1, 10]. And Max average latency value is 100s, min average latency value is 1us. For example: If base_num=10, the paths will be grouped in priority groups with path latency <=1us, (1us, 10us], (10us, 100us], (100us, 1ms], (1ms, 10ms], (10ms, 100ms], (100ms, 1s], (1s, 10s], (10s, 100s], >100s. .RE From b70feeb2dca8139bff050b976f6f96b14018a0ea Mon Sep 17 00:00:00 2001 From: Xose Vazquez Perez Date: Sat, 13 Jul 2024 13:10:20 +0200 Subject: [PATCH 006/145] multipath-tools: add older HUAWEI models Taken from Huawei UltraPath multipathing doc: https://support.huawei.com/enterprise/en/doc/EDOC1100362072/4a563777/showing-array-models-supported-by-the-ultrapath ===================== HUASY Dorado2100 HUAWEI Dorado2100 HUAWEI Dorado2100 G2 HUASY Dorado5100 HUAWEI Dorado5100 HUAWEI HVS85T HUAWEI HVS88T HS S2100 HUAWEI S2100 HUASY S2200T HUAWEI S2200T HS S2300 HUAWEI S2300 HS S2300E HUAWEI S2300E HS S2600 HUAWEI S2600 HS S2600T HUASY S2600T HUAWEI S2600T HUAWEI S2900 HUASY S3900 HUAWEI S3900 HUASY S3900-M200 HUAWEI S3900-M200 HUASY S3900-M300 HUAWEI S3900-M300 HS S5100 HUAWEI S5100 HS S5300 HUASY S5300 HUAWEI S5300 HS S5500 HUAWEI S5500 HUASY S5500T HUAWEI S5500T HS S5600 HUAWEI S5600 HUASY S5600T HUAWEI S5600T HUASY S5800T HUAWEI S5800T HUASY S5900-M100 HUAWEI S5900-M100 HUASY S5900-M200 HUAWEI S5900-M200 HS S6800E HUAWEI S6800E HUASY S6800T HUAWEI S6800T HUASY S6900 HUAWEI S6900 HUASY S6900-M100 HUAWEI S6900-M100 HS S8000 HUAWEI S8000 HS S8000-I HUASY S8000-I HUAWEI S8000-I HS V1500 HUAWEI V1500 HS V1500N HUAWEI V1500N HS V1600N HUAWEI V1600N HS V1800 HUAWEI V1800 HS VIS6000 HUAWEI VIS6000 HS VIS6000T HUAWEI VIS6000T ===================== Cc: Martin Wilck Cc: Benjamin Marzinski Cc: Christophe Varoqui Cc: DM-DEVEL ML Signed-off-by: Xose Vazquez Perez Reviewed-by: Martin Wilck --- libmultipath/hwtable.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libmultipath/hwtable.c b/libmultipath/hwtable.c index 9e008df61..095a91603 100644 --- a/libmultipath/hwtable.c +++ b/libmultipath/hwtable.c @@ -1119,6 +1119,14 @@ static struct hwentry default_hw[] = { /* * Huawei */ + { + /* All, except OceanStor V3-V6 */ + .vendor = "^(HUAWEI|HUASY|HS)", + .product = "^(Dorado|HVS8|S[23568]|V1[568]|VIS6000)", + .pgpolicy = GROUP_BY_PRIO, + .pgfailback = -FAILBACK_IMMEDIATE, + .no_path_retry = 15, + }, { /* OceanStor V3-V6 */ .vendor = "HUAWEI", From 014e31460c8a89ef739e75c884b9e9fc382ab3f7 Mon Sep 17 00:00:00 2001 From: Xose Vazquez Perez Date: Sat, 13 Jul 2024 13:10:21 +0200 Subject: [PATCH 007/145] multipath-tools: add more tags XSG1 vendors Taken from Huawei UltraPath multipathing doc: https://support.huawei.com/enterprise/en/doc/EDOC1100362072/4a563777/showing-array-models-supported-by-the-ultrapath ============ AnyStor XSG1 HUAWEI XSG1 Marstor XSG1 NETPOSA XSG1 SanM XSG1 SUGON XSG1 UDsafe XSG1 ============ Cc: Martin Wilck Cc: Benjamin Marzinski Cc: Christophe Varoqui Cc: DM-DEVEL ML Signed-off-by: Xose Vazquez Perez Reviewed-by: Martin Wilck --- libmultipath/hwtable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmultipath/hwtable.c b/libmultipath/hwtable.c index 095a91603..c539a9b5f 100644 --- a/libmultipath/hwtable.c +++ b/libmultipath/hwtable.c @@ -1129,7 +1129,7 @@ static struct hwentry default_hw[] = { }, { /* OceanStor V3-V6 */ - .vendor = "HUAWEI", + .vendor = "^(HUAWEI|AnyStor|Marstor|NETPOSA|SanM|SUGON|UDsafe)", .product = "XSG1", .pgpolicy = GROUP_BY_PRIO, .pgfailback = -FAILBACK_IMMEDIATE, From 7e4145af06d985a43a234dd361c4945c952dd205 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Tue, 25 Jun 2024 09:43:41 +0200 Subject: [PATCH 008/145] GitHub workflows: multiarch: add openSUSE Tumbleweed Include openSUSE Tumbleweed as another rolling release with support for armv7 and i386 architectures. Signed-off-by: Martin Wilck --- .github/workflows/multiarch.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/multiarch.yaml b/.github/workflows/multiarch.yaml index 7b762e5cb..df95a02fb 100644 --- a/.github/workflows/multiarch.yaml +++ b/.github/workflows/multiarch.yaml @@ -36,6 +36,7 @@ jobs: - alpine - debian-sid - fedora-rawhide + - opensuse-tumbleweed arch: [amd64, ppc64le, aarch64, s390x, 386, arm/v7] exclude: - os: fedora-rawhide From 606dc52f3681e88fc4447bcea2208e104a9bc18f Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Tue, 25 Jun 2024 12:06:15 +0200 Subject: [PATCH 009/145] multipath-tools CI: more fixes for arm/v7 The previous fix for the CI under arm/v7 was incomplete, and actually broke the tests under openSUSE Tumbleweed. Closer examination showed that the issues were caused by Debian's move to 64bit time_t on some 32 bit architectures [1][2]. This effort causes _TIME_BITS=64 to be set by gcc internally, and introduces symbol redirections for libaio [3], on Debian with gcc 13 and newer only. Fix the conditions for symbol remappings in wrap64.h. [1] https://wiki.debian.org/ReleaseGoals/64bit-time [2] https://salsa.debian.org/toolchain-team/gcc/-/commit/d82fb8a8ab7b84f61fb8290a2c3aa2e3f54e7b8a [3] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1062218 Fixes: 6a7524a ("multipath-tools tests: fix CI failures on arm/v7 with glibc 2.37") Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- tests/wrap64.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/wrap64.h b/tests/wrap64.h index 7e4342069..af6cc2ba5 100644 --- a/tests/wrap64.h +++ b/tests/wrap64.h @@ -2,6 +2,8 @@ #define _WRAP64_H 1 #include #include +/* The following include is required for LIBAIO_REDIRECT */ +#include #include "util.h" /* @@ -47,7 +49,8 @@ * fcntl() needs special treatment; fcntl64() has been introduced in 2.28. * https://savannah.gnu.org/forum/forum.php?forum_id=9205 */ -#if defined(__GLIBC__) && __GLIBC_PREREQ(2, 37) && defined(__arm__) && __ARM_ARCH == 7 +#if defined(__GLIBC__) && __GLIBC_PREREQ(2, 34) && __BITS_PER_LONG == 32 \ + && defined(_TIME_BITS) && _TIME_BITS == 64 #define WRAP_FCNTL_NAME __fcntl_time64 #elif defined(__GLIBC__) && __GLIBC_PREREQ(2, 28) #define WRAP_FCNTL_NAME WRAP_NAME(fcntl) @@ -60,7 +63,8 @@ /* * glibc 2.37 uses __ioctl_time64 for ioctl */ -#if defined(__GLIBC__) && __GLIBC_PREREQ(2, 37) && defined(__arm__) && __ARM_ARCH == 7 +#if defined(__GLIBC__) && __GLIBC_PREREQ(2, 34) && __BITS_PER_LONG == 32 \ + && defined(_TIME_BITS) && _TIME_BITS == 64 #define WRAP_IOCTL_NAME __ioctl_time64 #else #define WRAP_IOCTL_NAME ioctl @@ -68,7 +72,8 @@ #define WRAP_IOCTL CONCAT2(__wrap_, WRAP_IOCTL_NAME) #define REAL_IOCTL CONCAT2(__real_, WRAP_IOCTL_NAME) -#if defined(__NR_io_pgetevents) && __BITS_PER_LONG == 32 && defined(_TIME_BITS) && _TIME_BITS == 64 +#if defined(__GLIBC__) && defined(LIBAIO_REDIRECT) && __BITS_PER_LONG == 32 \ + && defined(_TIME_BITS) && _TIME_BITS == 64 #define WRAP_IO_GETEVENTS_NAME io_getevents_time64 #else #define WRAP_IO_GETEVENTS_NAME io_getevents From 2c7867a5596f896c1757f7e70b719b459732627f Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Mon, 8 Jul 2024 22:09:30 +0200 Subject: [PATCH 010/145] multipath-tools CI: fix dmevents test for Debian Sid, arm/v7 Same fix as in 6a7524a ("multipath-tools tests: fix CI failures on arm/v7 with glibc 2.37"). Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- tests/dmevents.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/tests/dmevents.c b/tests/dmevents.c index 395b16d77..668e6d270 100644 --- a/tests/dmevents.c +++ b/tests/dmevents.c @@ -253,8 +253,9 @@ int __wrap_dm_geteventnr(const char *name) return -1; } -int __wrap_ioctl(int fd, unsigned long request, void *argp) +int WRAP_IOCTL(int fd, unsigned long request, void *argp) { + condlog(1, "%s %ld", __func__, request); assert_int_equal(fd, waiter->fd); assert_int_equal(request, DM_DEV_ARM_POLL); return mock_type(int); @@ -675,7 +676,7 @@ static void test_dmevent_loop_bad1(void **state) skip(); will_return(__wrap_poll, 1); - will_return(__wrap_ioctl, -1); + wrap_will_return(WRAP_IOCTL, -1); assert_int_equal(dmevent_loop(), 1); dev_evt = find_dmevents("foo"); assert_ptr_not_equal(dev_evt, NULL); @@ -697,7 +698,7 @@ static void test_dmevent_loop_bad2(void **state) skip(); will_return(__wrap_poll, 1); - will_return(__wrap_ioctl, 0); + wrap_will_return(WRAP_IOCTL, 0); will_return(__wrap_libmp_dm_task_create, NULL); assert_int_equal(dmevent_loop(), 1); dev_evt = find_dmevents("foo"); @@ -721,9 +722,8 @@ static void test_dmevent_loop_good0(void **state) remove_all_dm_device_events(); unwatch_all_dmevents(); will_return(__wrap_poll, 1); - will_return(__wrap_ioctl, 0); + wrap_will_return(WRAP_IOCTL, 0); will_return(__wrap_libmp_dm_task_create, &data); - will_return(__wrap_dm_task_no_open_count, 1); will_return(__wrap_dm_task_run, 1); will_return(__wrap_dm_task_get_names, 1); assert_int_equal(dmevent_loop(), 1); @@ -757,9 +757,8 @@ static void test_dmevent_loop_good1(void **state) assert_int_equal(add_dm_device_event("foo", 1, 6), 0); assert_int_equal(remove_dm_device_event("xyzzy"), 0); will_return(__wrap_poll, 1); - will_return(__wrap_ioctl, 0); + wrap_will_return(WRAP_IOCTL, 0); will_return(__wrap_libmp_dm_task_create, &data); - will_return(__wrap_dm_task_no_open_count, 1); will_return(__wrap_dm_task_run, 1); will_return(__wrap_dm_task_get_names, 1); expect_string(__wrap_update_multipath, mapname, "foo"); @@ -805,9 +804,8 @@ static void test_dmevent_loop_good2(void **state) assert_int_equal(watch_dmevents("baz"), 0); assert_int_equal(add_dm_device_event("baz", 1, 14), 0); will_return(__wrap_poll, 1); - will_return(__wrap_ioctl, 0); + wrap_will_return(WRAP_IOCTL, 0); will_return(__wrap_libmp_dm_task_create, &data); - will_return(__wrap_dm_task_no_open_count, 1); will_return(__wrap_dm_task_run, 1); will_return(__wrap_dm_task_get_names, 1); expect_string(__wrap_update_multipath, mapname, "bar"); @@ -849,9 +847,8 @@ static void test_dmevent_loop_good3(void **state) assert_int_equal(remove_dm_device_event("foo"), 0); unwatch_dmevents("bar"); will_return(__wrap_poll, 1); - will_return(__wrap_ioctl, 0); + wrap_will_return(WRAP_IOCTL, 0); will_return(__wrap_libmp_dm_task_create, &data); - will_return(__wrap_dm_task_no_open_count, 1); will_return(__wrap_dm_task_run, 1); will_return(__wrap_dm_task_get_names, 1); expect_string(__wrap_remove_map_by_alias, alias, "foo"); @@ -874,7 +871,7 @@ static void test_arm_poll(void **state) struct test_data *datap = (struct test_data *)(*state); if (datap == NULL) skip(); - will_return(__wrap_ioctl, 0); + wrap_will_return(WRAP_IOCTL, 0); assert_int_equal(arm_dm_event_poll(waiter->fd), 0); } From 8cf033b26fb1dbd6281bad4d1e989a835fe7d580 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 6 Jun 2024 22:14:08 +0200 Subject: [PATCH 011/145] create-config.mk: use printf instead of /bin/echo The behavior of "echo -e" is not part of the POSIY standard and different shells handle it differently. OTOH, /bin/echo isn't necessarily available, either. Use printf instead, which is part of POSIX. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- create-config.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/create-config.mk b/create-config.mk index 4d318b964..0abbb3af4 100644 --- a/create-config.mk +++ b/create-config.mk @@ -147,11 +147,11 @@ TEST_CC_OPTION = $(shell \ # On some distros (e.g. Debian Buster) it will be falsely reported as supported # but it doesn't seem to make a difference wrt the compilation result. FORTIFY_OPT := $(shell \ - if /bin/echo -e '$(__HASH__)include \nint main(void) { return 0; }' | \ + if printf '$(__HASH__)include \nint main(void) { return 0; }\n' | \ $(CC) -o /dev/null $(OPTFLAGS) -c -Werror -D_FORTIFY_SOURCE=3 -xc - 2>/dev/null; \ then \ echo "-D_FORTIFY_SOURCE=3"; \ - elif /bin/echo -e '$(__HASH__)include \nint main(void) { return 0; }' | \ + elif printf '$(__HASH__)include \nint main(void) { return 0; }\n' | \ $(CC) -o /dev/null $(OPTFLAGS) -c -Werror -D_FORTIFY_SOURCE=2 -xc - 2>/dev/null; \ then \ echo "-D_FORTIFY_SOURCE=2"; \ From 8ec2bc1d28593c6a8774e7c9a16303a0b3b74066 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 6 Jun 2024 22:07:20 +0200 Subject: [PATCH 012/145] multipathd.service.in: use @BINDIR@ instead of /sbin The path in the unit file should match the actual installation path. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- multipathd/multipathd.service.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/multipathd/multipathd.service.in b/multipathd/multipathd.service.in index a63ddd9a4..646001e69 100644 --- a/multipathd/multipathd.service.in +++ b/multipathd/multipathd.service.in @@ -16,8 +16,8 @@ ConditionVirtualization=!container [Service] Type=notify NotifyAccess=main -ExecStart=/sbin/multipathd -d -s -ExecReload=/sbin/multipathd reconfigure +ExecStart=@BINDIR@/multipathd -d -s +ExecReload=@BINDIR@/multipathd reconfigure TasksMax=infinity LimitRTPRIO=10 CPUWeight=1000 From d3a4478eaea53c45747c3b36361a251473e1285e Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 6 Jun 2024 22:11:59 +0200 Subject: [PATCH 013/145] Makefile.inc: replace @BINDIR@ with $(TGTDIR)/$(bindir) The unit files and udev rules that use @BINDIR@ for substitutions have the installation target's point of view, they must include $(TGTDIR) (which is empty by default). Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- Makefile.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.inc b/Makefile.inc index ed4a42347..28b603212 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -150,4 +150,4 @@ NV_VERSION_SCRIPT = $(DEVLIB:%.so=%-nv.version) %: %.in @echo creating $@ - $(Q)sed 's:@CONFIGFILE@:'$(TGTDIR)$(configfile)':g;s:@CONFIGDIR@:'$(TGTDIR)$(configdir)':g;s:@STATE_DIR@:'$(TGTDIR)$(statedir)':g;s:@RUNTIME_DIR@:'$(runtimedir)':g;s/@MODPROBE_UNIT@/'$(MODPROBE_UNIT)'/g;s:@BINDIR@:'$(bindir)':g' $< >$@ + $(Q)sed 's:@CONFIGFILE@:'$(TGTDIR)$(configfile)':g;s:@CONFIGDIR@:'$(TGTDIR)$(configdir)':g;s:@STATE_DIR@:'$(TGTDIR)$(statedir)':g;s:@RUNTIME_DIR@:'$(runtimedir)':g;s/@MODPROBE_UNIT@/'$(MODPROBE_UNIT)'/g;s:@BINDIR@:'$(TGTDIR)$(bindir)':g' $< >$@ From 8c384754179e15f32747bfc0557fca4660e31e2b Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 6 Jun 2024 22:25:50 +0200 Subject: [PATCH 014/145] kpartx.rules: use @BINDIR@ to locate kpartx The path for kpartx should match the installed binary. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- .gitignore | 1 + kpartx/Makefile | 6 +++--- kpartx/{kpartx.rules => kpartx.rules.in} | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) rename kpartx/{kpartx.rules => kpartx.rules.in} (96%) diff --git a/.gitignore b/.gitignore index 049ffe88e..355ddbb69 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ config.mk cscope.files cscope.out kpartx/kpartx +kpartx/kpartx.rules multipath/multipath multipath/multipath.8 multipath/multipath.conf.5 diff --git a/kpartx/Makefile b/kpartx/Makefile index 7720a7404..849fd36d0 100644 --- a/kpartx/Makefile +++ b/kpartx/Makefile @@ -13,13 +13,13 @@ LIBDEPS += -ldevmapper OBJS := bsd.o dos.o kpartx.o solaris.o unixware.o dasd.o sun.o \ gpt.o mac.o ps3.o crc32.o lopart.o xstrncpy.o devmapper.o -all: $(EXEC) +all: $(EXEC) kpartx.rules $(EXEC): $(OBJS) @echo building $@ because of $? $(Q)$(CC) $(CFLAGS) $(OBJS) -o $(EXEC) $(LDFLAGS) $(LIBDEPS) -install: $(EXEC) $(EXEC).8 +install: $(EXEC) $(EXEC).8 kpartx.rules $(Q)$(INSTALL_PROGRAM) -d $(DESTDIR)$(bindir) $(Q)$(INSTALL_PROGRAM) -m 755 $(EXEC) $(DESTDIR)$(bindir) $(Q)$(INSTALL_PROGRAM) -d $(DESTDIR)$(libudevdir) @@ -41,7 +41,7 @@ uninstall: $(Q)$(RM) $(DESTDIR)$(libudevdir)/rules.d/68-del-part-nodes.rules clean: dep_clean - $(Q)$(RM) core *.o $(EXEC) + $(Q)$(RM) core *.o $(EXEC) kpartx.rules include $(wildcard $(OBJS:.o=.d)) diff --git a/kpartx/kpartx.rules b/kpartx/kpartx.rules.in similarity index 96% rename from kpartx/kpartx.rules rename to kpartx/kpartx.rules.in index 8dd3369c3..9d879609c 100644 --- a/kpartx/kpartx.rules +++ b/kpartx/kpartx.rules.in @@ -39,6 +39,6 @@ LABEL="mpath_kpartx_end" GOTO="kpartx_end" LABEL="run_kpartx" -RUN+="/sbin/kpartx -un -p -part /dev/$name" +RUN+="@BINDIR@/kpartx -un -p -part /dev/$name" LABEL="kpartx_end" From 4e276a49ee5c68095d1816583bc2522fd5329358 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Tue, 11 Jun 2024 17:29:45 +0200 Subject: [PATCH 015/145] multipath-tools: Remove hard-coded paths to executables Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- Makefile.inc | 17 ++++++++++++++--- kpartx/kpartx_id | 8 ++++---- multipath/11-dm-mpath.rules.in | 4 ++-- multipath/multipath.rules.in | 6 +++--- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Makefile.inc b/Makefile.inc index 28b603212..fe9f1bf3d 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -42,9 +42,11 @@ etc_prefix := $(prefix) # Where to install systemd-related files. systemd is usually installed under /usr # Note: systemd installations with "split-usr=true" use separate "prefixdir" and # "rootprefixdir". Our systemd_prefix corresponds to "prefixdir". -# In this case, override only unitdir and libudevdir below to use -# systemd's "rootprefixdir" instead of $(systemd_prefix) +# In this case, override only unitdir, libudevdir and sys_execprefix below +# to use systemd's "rootprefixdir" instead of $(systemd_prefix) systemd_prefix := /usr +# Prefix for binaries that are owned by other packages (including systemd) +sys_execprefix := /usr # Make sure all prefix variables end in "/" append-slash = $(1)$(if $(filter %/,$(1)),,/) @@ -53,6 +55,7 @@ override exec_prefix := $(call append-slash,$(exec_prefix)) override usr_prefix := $(call append-slash,$(usr_prefix)) override etc_prefix := $(call append-slash,$(etc_prefix)) override systemd_prefix := $(call append-slash,$(systemd_prefix)) +override sys_execprefix := $(call append-slash,$(sys_execprefix)) unitdir := $(systemd_prefix)lib/systemd/system tmpfilesdir := $(systemd_prefix)lib/tmpfiles.d @@ -74,6 +77,7 @@ runtimedir := $(if $(shell test -L /var/run -o ! -d /var/run && echo 1),/ru devmapper_incdir := $(or $(shell $(PKG_CONFIG) --variable=includedir devmapper),/usr/include) libudev_incdir := $(or $(shell $(PKG_CONFIG) --variable=includedir libudev),/usr/include) kernel_incdir := /usr/include +sysdir_bin := $(sys_execprefix)bin ifeq ($(V),) Q := @ @@ -150,4 +154,11 @@ NV_VERSION_SCRIPT = $(DEVLIB:%.so=%-nv.version) %: %.in @echo creating $@ - $(Q)sed 's:@CONFIGFILE@:'$(TGTDIR)$(configfile)':g;s:@CONFIGDIR@:'$(TGTDIR)$(configdir)':g;s:@STATE_DIR@:'$(TGTDIR)$(statedir)':g;s:@RUNTIME_DIR@:'$(runtimedir)':g;s/@MODPROBE_UNIT@/'$(MODPROBE_UNIT)'/g;s:@BINDIR@:'$(TGTDIR)$(bindir)':g' $< >$@ + $(Q)sed -e 's:@CONFIGFILE@:'$(TGTDIR)$(configfile)':g' \ + -e 's:@CONFIGDIR@:'$(TGTDIR)$(configdir)':g' \ + -e 's:@STATE_DIR@:'$(TGTDIR)$(statedir)':g' \ + -e 's:@BINDIR@:'$(TGTDIR)$(bindir)':g' \ + -e 's:@SYSDIR_BIN@:'$(sysdir_bin)': g' \ + -e 's:@RUNTIME_DIR@:'$(runtimedir)':g' \ + -e 's/@MODPROBE_UNIT@/'$(MODPROBE_UNIT)'/g' \ + $< >$@ diff --git a/kpartx/kpartx_id b/kpartx/kpartx_id index 4672927e9..f9211d26d 100755 --- a/kpartx/kpartx_id +++ b/kpartx/kpartx_id @@ -21,8 +21,6 @@ # sent upstream but has not been accepted yet. # -DMSETUP=/sbin/dmsetup - MAJOR=$1 MINOR=$2 UUID=$3 @@ -32,12 +30,14 @@ if [ -z "$MAJOR" -o -z "$MINOR" ]; then exit 1; fi +DMSETUP=$(command -v dmsetup) || DMSETUP=/sbin/dmsetup + # Device-mapper not installed; not an error -if [ ! -x $DMSETUP ] ; then +if [ ! -x "$DMSETUP" ] ; then + echo "$0: dmsetup not found" >&2 exit 0 fi - # Table UUIDs are always '-'. dmuuid=${UUID#*-} dmtbl=${UUID%%-*} diff --git a/multipath/11-dm-mpath.rules.in b/multipath/11-dm-mpath.rules.in index 0562eddfb..30647b99a 100644 --- a/multipath/11-dm-mpath.rules.in +++ b/multipath/11-dm-mpath.rules.in @@ -9,7 +9,7 @@ ENV{.DM_SUSPENDED}!="?*", ENV{.DM_SUSPENDED}="$env{DM_SUSPENDED}" # Coldplug event while device is suspended (e.g. during a reload) ACTION=="add", ENV{DM_ACTIVATION}=="1", ENV{.DM_SUSPENDED}=="1", \ - PROGRAM="/bin/logger -t 11-dm-mpath.rules -p daemon.warning \"Coldplug event for suspended device\"", \ + PROGRAM="@SYSDIR_BIN@/logger -t 11-dm-mpath.rules -p daemon.warning \"Coldplug event for suspended device\"", \ ENV{DM_COLDPLUG_SUSPENDED}="1", GOTO="scan_import" # Coldplug event. Import previously set properties. @@ -70,7 +70,7 @@ LABEL="check_mpath_unchanged" IMPORT{db}="DM_COLDPLUG_SUSPENDED" ENV{DM_COLDPLUG_SUSPENDED}=="1", ENV{.DM_SUSPENDED}!="1", \ ENV{DM_ACTIVATION}="1", ENV{MPATH_UNCHANGED}="0", \ - PROGRAM="/bin/logger -t 11-dm-mpath.rules -p daemon.notice \"Forcing activation of previously suspended device\"", \ + PROGRAM="@SYSDIR_BIN@/logger -t 11-dm-mpath.rules -p daemon.notice \"Forcing activation of previously suspended device\"", \ GOTO="check_mpath_ready" # DM_SUBSYSTEM_UDEV_FLAG0 is the "RELOAD" flag for multipath subsystem. diff --git a/multipath/multipath.rules.in b/multipath/multipath.rules.in index 780bf8521..2ac1972fe 100644 --- a/multipath/multipath.rules.in +++ b/multipath/multipath.rules.in @@ -2,7 +2,7 @@ SUBSYSTEM!="block", GOTO="end_mpath" KERNEL!="sd*|dasd*|nvme*", GOTO="end_mpath" ACTION=="remove", TEST=="@RUNTIME_DIR@/multipath/find_multipaths/$major:$minor", \ - RUN+="/usr/bin/rm -f @RUNTIME_DIR@/multipath/find_multipaths/$major:$minor" + RUN+="@SYSDIR_BIN@/rm -f @RUNTIME_DIR@/multipath/find_multipaths/$major:$minor" ACTION!="add|change", GOTO="end_mpath" IMPORT{cmdline}="nompath" @@ -69,7 +69,7 @@ ENV{.SAVED_FM_WAIT_UNTIL}=="?*", GOTO="pretend_mpath" # # We must trigger an "add" event because LVM2 will only act on those. -RUN+="/usr/bin/systemd-run --unit=cancel-multipath-wait-$kernel --description 'cancel waiting for multipath siblings of $kernel' --no-block --timer-property DefaultDependencies=no --timer-property Conflicts=shutdown.target --timer-property Before=shutdown.target --timer-property Conflicts=initrd-cleanup.service --timer-property Before=initrd-cleanup.service --timer-property AccuracySec=500ms --property DefaultDependencies=no --property Conflicts=shutdown.target --property Before=shutdown.target --property Conflicts=initrd-cleanup.service --property Before=initrd-cleanup.service --on-active=$env{FIND_MULTIPATHS_WAIT_UNTIL} /usr/bin/udevadm trigger --action=add $sys$devpath" +RUN+="@SYSDIR_BIN@/systemd-run --unit=cancel-multipath-wait-$kernel --description 'cancel waiting for multipath siblings of $kernel' --no-block --timer-property DefaultDependencies=no --timer-property Conflicts=shutdown.target --timer-property Before=shutdown.target --timer-property Conflicts=initrd-cleanup.service --timer-property Before=initrd-cleanup.service --timer-property AccuracySec=500ms --property DefaultDependencies=no --property Conflicts=shutdown.target --property Before=shutdown.target --property Conflicts=initrd-cleanup.service --property Before=initrd-cleanup.service --on-active=$env{FIND_MULTIPATHS_WAIT_UNTIL} @SYSDIR_BIN@/udevadm trigger --action=add $sys$devpath" LABEL="pretend_mpath" ENV{DM_MULTIPATH_DEVICE_PATH}="1" @@ -85,7 +85,7 @@ ENV{FIND_MULTIPATHS_WAIT_UNTIL}!="?*", GOTO="end_mpath" ENV{FIND_MULTIPATHS_WAIT_UNTIL}=="0", GOTO="end_mpath" ENV{FIND_MULTIPATHS_WAIT_CANCELLED}="1" -RUN+="/usr/bin/systemctl stop cancel-multipath-wait-$kernel.timer" +RUN+="@SYSDIR_BIN@/systemctl stop cancel-multipath-wait-$kernel.timer" # If "multipath -u" failed, no values are imported from the program, # and we are still using the values for DM_MULTIPATH_DEVICE_PATH and From 01fc1dfc3fe6f18b0969eea13a315bd72195eb10 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 27 Jun 2024 17:10:49 +0200 Subject: [PATCH 016/145] multipath-tools: compile_commands.json fixes compile_commands.json serves as input for clangd, while working with lsp under emacs. It's normal for functions and parameters to be unused while writing code. Therefore suppress -Werror for this use case. clangd will display the warnings. Use "make testprogs" to generate compile_commands.json, in order to be able to use clangd for the CI code, too. Finally, don't remove compile_commands.json with "make clean". Normally the compile commands remain the same, even if a clean rebuild of the binaries is necessary. Put the file into .gitignore instead. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- .gitignore | 1 + Makefile | 4 ++-- Makefile.inc | 12 +++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 355ddbb69..efdbd8a20 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ *.gz *.d \#* +compile_commands.json config.mk cscope.files cscope.out diff --git a/Makefile b/Makefile index 4df5f1612..14bbac246 100644 --- a/Makefile +++ b/Makefile @@ -83,7 +83,7 @@ abi-test: abi reference-abi $(wildcard abi/*.abi) # Requires bear (https://github.com/rizsotto/Bear) compile_commands.json: Makefile Makefile.inc $(BUILDDIRS:=/Makefile) $(Q)$(MAKE) clean - $(Q)bear -- $(MAKE) + $(Q)bear -- $(MAKE) WARN_ONLY=1 test-progs || rm $@ libmpathutil libdmmp: libmpathcmd libmultipath: libmpathutil @@ -109,7 +109,7 @@ $(BUILDDIRS:=.uninstall): clean: @touch config.mk $(Q)$(MAKE) $(BUILDDIRS:=.clean) tests.clean || true - $(Q)$(RM) -r abi abi.tar.gz abi-test compile_commands.json config.mk + $(Q)$(RM) -r abi abi.tar.gz abi-test config.mk install: $(BUILDDIRS:=.install) uninstall: $(BUILDDIRS:=.uninstall) diff --git a/Makefile.inc b/Makefile.inc index fe9f1bf3d..729618bdb 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -100,9 +100,15 @@ MODPROBE_UNIT := $(shell test "0$(SYSTEMD)" -lt 245 2>/dev/null || \ echo "modprobe@dm_multipath.service") OPTFLAGS := -O2 -g $(STACKPROT) --param=ssp-buffer-size=4 -WARNFLAGS := -Werror -Wall -Wextra -Wformat=2 $(WFORMATOVERFLOW) -Werror=implicit-int \ - -Werror=implicit-function-declaration -Werror=format-security \ - $(WNOCLOBBERED) -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS) $(W_URCU_TYPE_LIMITS) + +# Set WARN_ONLY=1 to avoid compilation erroring out due to warnings. Useful during development. +WARN_ONLY := +ERROR := $(if $(WARN_ONLY),,error=) +WERROR := $(if $(WARN_ONLY),,-Werror) +WARNFLAGS := $(WERROR) -Wall -Wextra -Wformat=2 $(WFORMATOVERFLOW) -W$(ERROR)implicit-int \ + -W$(ERROR)implicit-function-declaration -W$(ERROR)format-security \ + $(WNOCLOBBERED) -W$(ERROR)cast-qual $(ERROR_DISCARDED_QUALIFIERS) $(W_URCU_TYPE_LIMITS) + CPPFLAGS := $(FORTIFY_OPT) $(CPPFLAGS) $(D_URCU_VERSION) \ -D_FILE_OFFSET_BITS=64 \ -DBIN_DIR=\"$(bindir)\" -DMULTIPATH_DIR=\"$(TGTDIR)$(plugindir)\" \ From 8021c4429baa0d5149f25a746bcd3c65116e05b7 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Tue, 2 Jul 2024 19:07:56 +0200 Subject: [PATCH 017/145] multipath-tools: .gitignore: ignore o.wrap files for CI helpers Unlike the .o.wrap files for the CI tests themselves, these are not automatically deleted by "make" as intermediate files. Ignore them. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index efdbd8a20..4548cfbec 100644 --- a/.gitignore +++ b/.gitignore @@ -42,6 +42,8 @@ libdmmp/test/libdmmp_speed_test tests/*-test tests/*.out tests/*.vgr +tests/test-lib.o.wrap +tests/test-log.o.wrap libmultipath/nvme-ioctl.c libmultipath/nvme-ioctl.h libmultipath/autoconfig.h From 3099a3b93d67e6713ab51e4e0957748174898666 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 27 Jun 2024 17:13:52 +0200 Subject: [PATCH 018/145] libmultipath: remove unused includes in devmapper.h Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 08bb3c51c..3ee855538 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -17,13 +17,11 @@ #include #include "util.h" -#include "checkers.h" #include "vector.h" #include "structs.h" #include "debug.h" #include "devmapper.h" #include "sysfs.h" -#include "config.h" #include "wwids.h" #include "version.h" #include "time-util.h" From 9350966eb73ac5c9ecbb3272a8651dbfe615648c Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 27 Jun 2024 13:02:56 +0200 Subject: [PATCH 019/145] libmultipath: use DM_DEVICE_INFO in dm_mapname() DM_DEVICE_INFO aka the kernel's DM_DEV_STATUS ioctl, is sufficient to fetch the map name, and more lightweight than DM_DEVICE_STATUS, which maps to the kernel's DM_TABLE_STATUS ioctl. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 3ee855538..baa1eadc9 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1412,7 +1412,7 @@ dm_mapname(int major, int minor) struct dm_task *dmt; int r; - if (!(dmt = libmp_dm_task_create(DM_DEVICE_STATUS))) + if (!(dmt = libmp_dm_task_create(DM_DEVICE_INFO))) return NULL; if (!dm_task_set_major(dmt, major) || @@ -1422,7 +1422,7 @@ dm_mapname(int major, int minor) dm_task_no_open_count(dmt); r = libmp_dm_task_run(dmt); if (!r) { - dm_log_error(2, DM_DEVICE_STATUS, dmt); + dm_log_error(2, DM_DEVICE_INFO, dmt); goto bad; } From d00281fb47ba3061c84bf4de06621465d0b31df7 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 27 Jun 2024 17:18:44 +0200 Subject: [PATCH 020/145] multipath-tools: don't call dm_task_no_open_count() dm_task_no_open_count() only sets DM_SKIP_BDGET_FLAG in the dm task, which has been ignored by the kernel since 5c6bd75d06db ("[PATCH] dm: prevent removal if open") (v2.6.18 / 2006). Even for older kernels, not setting this flag has only a minor, performance-related effect (skipping one call to bdget_disk()). Don't use this dead API any more. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- kpartx/devmapper.c | 15 --------------- libmultipath/devmapper.c | 36 ------------------------------------ multipathd/dmevents.c | 2 -- multipathd/waiter.c | 2 -- tests/dmevents.c | 13 ------------- 5 files changed, 68 deletions(-) diff --git a/kpartx/devmapper.c b/kpartx/devmapper.c index f12762c5c..bf078388a 100644 --- a/kpartx/devmapper.c +++ b/kpartx/devmapper.c @@ -35,8 +35,6 @@ int dm_prereq(char * str, uint32_t x, uint32_t y, uint32_t z) if (!(dmt = dm_task_create(DM_DEVICE_LIST_VERSIONS))) return 1; - dm_task_no_open_count(dmt); - if (!dm_task_run(dmt)) goto out; @@ -78,7 +76,6 @@ int dm_simplecmd(int task, const char *name, int no_flush, __DM_API_COOKIE_UNUSE if (!dm_task_set_name(dmt, name)) goto out; - dm_task_no_open_count(dmt); dm_task_skip_lockfs(dmt); if (no_flush) @@ -175,8 +172,6 @@ int dm_addmap(int task, const char *name, const char *target, if (!dm_task_set_gid(dmt, gid)) goto addout; - dm_task_no_open_count(dmt); - #ifdef LIBDM_API_COOKIE if (!udev_sync) udev_flags = DM_UDEV_DISABLE_LIBRARY_FALLBACK; @@ -212,8 +207,6 @@ static int dm_map_present(char *str, char **uuid) if (!dm_task_set_name(dmt, str)) goto out; - dm_task_no_open_count(dmt); - if (!dm_task_run(dmt)) goto out; @@ -247,7 +240,6 @@ static int dm_rename (const char *old, const char *new) if (!dm_task_set_name(dmt, old) || !dm_task_set_newname(dmt, new) || - !dm_task_no_open_count(dmt) || !dm_task_set_cookie(dmt, &cookie, udev_flags)) goto out; @@ -291,7 +283,6 @@ dm_mapname(int major, int minor) if (!(dmt = dm_task_create(DM_DEVICE_INFO))) return NULL; - dm_task_no_open_count(dmt); dm_task_set_major(dmt, major); dm_task_set_minor(dmt, minor); @@ -352,7 +343,6 @@ dm_mapuuid(const char *mapname) if (!dm_task_set_name(dmt, mapname)) goto out; - dm_task_no_open_count(dmt); if (!dm_task_run(dmt)) goto out; @@ -407,7 +397,6 @@ dm_get_map(const char *mapname, char * outparams) if (!dm_task_set_name(dmt, mapname)) goto out; - dm_task_no_open_count(dmt); if (!dm_task_run(dmt)) goto out; @@ -474,8 +463,6 @@ dm_type(const char * name, char * type) if (!dm_task_set_name(dmt, name)) goto out; - dm_task_no_open_count(dmt); - if (!dm_task_run(dmt)) goto out; @@ -545,8 +532,6 @@ do_foreach_partmaps (const char * mapname, const char *uuid, if (!(dmt = dm_task_create(DM_DEVICE_LIST))) return 1; - dm_task_no_open_count(dmt); - if (!dm_task_run(dmt)) goto out; diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index baa1eadc9..8996c1d6e 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -217,8 +217,6 @@ static int dm_tgt_version (unsigned int *version, char *str) if (!(dmt = dm_task_create(DM_DEVICE_LIST_VERSIONS))) return 1; - dm_task_no_open_count(dmt); - if (!libmp_dm_task_run(dmt)) { dm_log_error(2, DM_DEVICE_LIST_VERSIONS, dmt); condlog(0, "Cannot communicate with kernel DM"); @@ -398,7 +396,6 @@ dm_simplecmd (int task, const char *name, int flags, uint16_t udev_flags) { if (!dm_task_set_name (dmt, name)) goto out; - dm_task_no_open_count(dmt); dm_task_skip_lockfs(dmt); /* for DM_DEVICE_RESUME */ #ifdef LIBDM_API_FLUSH if (flags & DMFL_NO_FLUSH) @@ -495,8 +492,6 @@ dm_addmap (int task, const char *target, struct multipath *mpp, task == DM_DEVICE_RELOAD ? "reload" : "addmap", mpp->size, target, params); - dm_task_no_open_count(dmt); - if (task == DM_DEVICE_CREATE && !dm_task_set_cookie(dmt, &cookie, udev_flags)) goto freeout; @@ -627,8 +622,6 @@ dm_get_info(const char *name, struct dm_info *info) if (!dm_task_set_name(dmt, name)) goto out; - dm_task_no_open_count(dmt); - if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_INFO, dmt); goto out; @@ -667,8 +660,6 @@ int dm_get_map(const char *name, unsigned long long *size, char **outparams) if (!dm_task_set_name(dmt, name)) goto out; - dm_task_no_open_count(dmt); - errno = 0; if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_TABLE, dmt); @@ -787,8 +778,6 @@ int dm_get_status(const char *name, char **outstatus) if (!dm_task_set_name(dmt, name)) goto out; - dm_task_no_open_count(dmt); - errno = 0; if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_STATUS, dmt); @@ -845,8 +834,6 @@ int dm_type(const char *name, char *type) if (!dm_task_set_name(dmt, name)) goto out; - dm_task_no_open_count(dmt); - if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_TABLE, dmt); goto out; @@ -889,8 +876,6 @@ int dm_is_mpath(const char *name) if (!dm_task_set_name(dmt, name)) goto out_task; - dm_task_no_open_count(dmt); - if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_TABLE, dmt); goto out_task; @@ -950,8 +935,6 @@ dm_map_present_by_uuid(const char *uuid) if (!(dmt = libmp_dm_task_create(DM_DEVICE_INFO))) goto out; - dm_task_no_open_count(dmt); - if (!dm_task_set_uuid(dmt, prefixed_uuid)) goto out_task; @@ -1158,8 +1141,6 @@ int dm_flush_maps (int retries) if (!(dmt = libmp_dm_task_create (DM_DEVICE_LIST))) return r; - dm_task_no_open_count(dmt); - if (!libmp_dm_task_run (dmt)) { dm_log_error(3, DM_DEVICE_LIST, dmt); goto out; @@ -1205,8 +1186,6 @@ dm_message(const char * mapname, char * message) if (!dm_task_set_message(dmt, message)) goto out; - dm_task_no_open_count(dmt); - if (!libmp_dm_task_run(dmt)) { dm_log_error(2, DM_DEVICE_TARGET_MSG, dmt); goto out; @@ -1341,8 +1320,6 @@ dm_get_maps (vector mp) if (!(dmt = libmp_dm_task_create(DM_DEVICE_LIST))) return 1; - dm_task_no_open_count(dmt); - if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_LIST, dmt); goto out; @@ -1419,7 +1396,6 @@ dm_mapname(int major, int minor) !dm_task_set_minor(dmt, minor)) goto bad; - dm_task_no_open_count(dmt); r = libmp_dm_task_run(dmt); if (!r) { dm_log_error(2, DM_DEVICE_INFO, dmt); @@ -1455,8 +1431,6 @@ do_foreach_partmaps (const char * mapname, if (!(dmt = libmp_dm_task_create(DM_DEVICE_LIST))) return 1; - dm_task_no_open_count(dmt); - if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_LIST, dmt); goto out; @@ -1665,8 +1639,6 @@ dm_rename (const char * old, char * new, char *delim, int skip_kpartx) if (!dm_task_set_newname(dmt, new)) goto out; - dm_task_no_open_count(dmt); - if (!dm_task_set_cookie(dmt, &cookie, udev_flags)) goto out; r = libmp_dm_task_run(dmt); @@ -1713,8 +1685,6 @@ int dm_reassign_table(const char *name, char *old, char *new) if (!dm_task_set_name(dmt, name)) goto out; - dm_task_no_open_count(dmt); - if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_TABLE, dmt); goto out; @@ -1756,8 +1726,6 @@ int dm_reassign_table(const char *name, char *old, char *new) } while (next); if (modified) { - dm_task_no_open_count(reload_dmt); - if (!libmp_dm_task_run(reload_dmt)) { dm_log_error(3, DM_DEVICE_RELOAD, reload_dmt); condlog(3, "%s: failed to reassign targets", name); @@ -1803,8 +1771,6 @@ int dm_reassign(const char *mapname) if (!dm_task_set_name(dmt, mapname)) goto out; - dm_task_no_open_count(dmt); - if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_DEPS, dmt); goto out; @@ -1861,8 +1827,6 @@ int dm_setgeometry(struct multipath *mpp) if (!dm_task_set_name(dmt, mpp->alias)) goto out; - dm_task_no_open_count(dmt); - /* What a sick interface ... */ snprintf(heads, 4, "%u", pp->geom.heads); snprintf(sectors, 4, "%u", pp->geom.sectors); diff --git a/multipathd/dmevents.c b/multipathd/dmevents.c index 5657000cd..3fbdc5530 100644 --- a/multipathd/dmevents.c +++ b/multipathd/dmevents.c @@ -154,8 +154,6 @@ static int dm_get_events(void) if (!(dmt = libmp_dm_task_create(DM_DEVICE_LIST))) return -1; - dm_task_no_open_count(dmt); - if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_LIST, dmt); goto fail; diff --git a/multipathd/waiter.c b/multipathd/waiter.c index d1f344b6c..1dd93c5b2 100644 --- a/multipathd/waiter.c +++ b/multipathd/waiter.c @@ -108,8 +108,6 @@ static int waiteventloop (struct event_thread *waiter) return 1; } - dm_task_no_open_count(waiter->dmt); - /* wait */ sigemptyset(&set); sigaddset(&set, SIGUSR2); diff --git a/tests/dmevents.c b/tests/dmevents.c index 668e6d270..2f98173c4 100644 --- a/tests/dmevents.c +++ b/tests/dmevents.c @@ -267,15 +267,6 @@ struct dm_task *__wrap_libmp_dm_task_create(int task) return mock_type(struct dm_task *); } -int __real_dm_task_no_open_count(struct dm_task *dmt); -int __wrap_dm_task_no_open_count(struct dm_task *dmt) -{ - if (!setup_done) - return __real_dm_task_no_open_count(dmt); - assert_ptr_equal((struct test_data *)dmt, &data); - return mock_type(int); -} - int __real_dm_task_run(struct dm_task *dmt); int __wrap_dm_task_run(struct dm_task *dmt) { @@ -554,7 +545,6 @@ static void test_get_events_bad1(void **state) skip(); will_return(__wrap_libmp_dm_task_create, &data); - will_return(__wrap_dm_task_no_open_count, 1); will_return(__wrap_dm_task_run, 0); assert_int_equal(dm_get_events(), -1); } @@ -567,7 +557,6 @@ static void test_get_events_bad2(void **state) skip(); will_return(__wrap_libmp_dm_task_create, &data); - will_return(__wrap_dm_task_no_open_count, 1); will_return(__wrap_dm_task_run, 1); will_return(__wrap_dm_task_get_names, 0); assert_int_equal(dm_get_events(), -1); @@ -582,7 +571,6 @@ static void test_get_events_good0(void **state) assert_int_equal(add_dm_device_event("foo", 1, 5), 0); will_return(__wrap_libmp_dm_task_create, &data); - will_return(__wrap_dm_task_no_open_count, 1); will_return(__wrap_dm_task_run, 1); will_return(__wrap_dm_task_get_names, 1); assert_int_equal(dm_get_events(), 0); @@ -617,7 +605,6 @@ static void test_get_events_good1(void **state) assert_int_equal(add_dm_device_event("foo", 1, 6), 0); assert_int_equal(remove_dm_device_event("xyzzy"), 0); will_return(__wrap_libmp_dm_task_create, &data); - will_return(__wrap_dm_task_no_open_count, 1); will_return(__wrap_dm_task_run, 1); will_return(__wrap_dm_task_get_names, 1); assert_int_equal(dm_get_events(), 0); From 1d00f4a989bd7821d2ed3eec85ae5f2a5732ddeb Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 5 Jul 2024 22:13:13 +0200 Subject: [PATCH 021/145] libmpathutil: export cleanup_udev_device() This function is useful in multiple callers. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathutil/libmpathutil.version | 4 ++++ libmpathutil/util.c | 6 ++++++ libmpathutil/util.h | 3 +++ libmultipath/print.c | 6 ------ tests/Makefile | 2 +- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/libmpathutil/libmpathutil.version b/libmpathutil/libmpathutil.version index fee74a32d..86450f497 100644 --- a/libmpathutil/libmpathutil.version +++ b/libmpathutil/libmpathutil.version @@ -133,3 +133,7 @@ LIBMPATHUTIL_2.0 { LIBMPATHUTIL_2.1 { libmp_basename; }; + +LIBMPATHUTIL_2.2 { + cleanup_udev_device; +}; diff --git a/libmpathutil/util.c b/libmpathutil/util.c index 23d303f91..67db3c8a1 100644 --- a/libmpathutil/util.c +++ b/libmpathutil/util.c @@ -373,3 +373,9 @@ void cleanup_ucharp(unsigned char **p) { free(*p); } + +void cleanup_udev_device(struct udev_device **udd) +{ + if (*udd) + udev_device_unref(*udd); +} diff --git a/libmpathutil/util.h b/libmpathutil/util.h index 4997fed6b..c19f74974 100644 --- a/libmpathutil/util.h +++ b/libmpathutil/util.h @@ -10,6 +10,7 @@ #include #include #include +#include size_t strchop(char *); @@ -139,4 +140,6 @@ static inline void clear_bit_in_bitfield(unsigned int bit, struct bitfield *bf) void cleanup_charp(char **p); void cleanup_ucharp(unsigned char **p); +void cleanup_udev_device(struct udev_device **udd); + #endif /* _UTIL_H */ diff --git a/libmultipath/print.c b/libmultipath/print.c index d592001dc..b7af91379 100644 --- a/libmultipath/print.c +++ b/libmultipath/print.c @@ -436,12 +436,6 @@ snprint_multipath_vpd_data(struct strbuf *buff, return append_strbuf_str(buff, "[undef]"); } -static void cleanup_udev_device(struct udev_device **udd) -{ - if (*udd) - udev_device_unref(*udd); -} - static int snprint_multipath_max_sectors_kb(struct strbuf *buff, const struct multipath *mpp) { diff --git a/tests/Makefile b/tests/Makefile index 4005204a4..8afa8c67e 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -53,7 +53,7 @@ vpd-test_OBJDEPS := $(multipathdir)/discovery.o vpd-test_LIBDEPS := -ludev -lpthread -ldl alias-test_TESTDEPS := test-log.o alias-test_OBJDEPS := $(mpathutildir)/util.o -alias-test_LIBDEPS := -lpthread -ldl +alias-test_LIBDEPS := -ludev -lpthread -ldl valid-test_OBJDEPS := $(multipathdir)/valid.o $(multipathdir)/discovery.o valid-test_LIBDEPS := -lmount -ludev -lpthread -ldl devt-test_LIBDEPS := -ludev From 344855e6c75c5918561147f7f083227c673cbb0c Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 5 Jul 2024 22:13:48 +0200 Subject: [PATCH 022/145] libmpathutil: add cleanup_vector() Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathutil/libmpathutil.version | 1 + libmpathutil/vector.c | 6 ++++++ libmpathutil/vector.h | 1 + 3 files changed, 8 insertions(+) diff --git a/libmpathutil/libmpathutil.version b/libmpathutil/libmpathutil.version index 86450f497..cb0523167 100644 --- a/libmpathutil/libmpathutil.version +++ b/libmpathutil/libmpathutil.version @@ -136,4 +136,5 @@ LIBMPATHUTIL_2.1 { LIBMPATHUTIL_2.2 { cleanup_udev_device; + cleanup_vector; }; diff --git a/libmpathutil/vector.c b/libmpathutil/vector.c index df59db5dd..7c3ce43d4 100644 --- a/libmpathutil/vector.c +++ b/libmpathutil/vector.c @@ -169,6 +169,12 @@ vector_free(vector v) free(v); } +void cleanup_vector(vector *pv) +{ + if (*pv) + vector_free(*pv); +} + void free_strvec(vector strvec) { diff --git a/libmpathutil/vector.h b/libmpathutil/vector.h index c0b09cb43..a41f15740 100644 --- a/libmpathutil/vector.h +++ b/libmpathutil/vector.h @@ -78,6 +78,7 @@ extern vector vector_alloc(void); extern bool vector_alloc_slot(vector v); vector vector_reset(vector v); extern void vector_free(vector v); +void cleanup_vector(vector *pv); #define vector_free_const(x) vector_free((vector)(long)(x)) extern void free_strvec(vector strvec); extern void vector_set_slot(vector v, void *value); From ff31fdd91cb1b49f10ec9fdee7ae2fe1f911b8e1 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 5 Jul 2024 22:15:28 +0200 Subject: [PATCH 023/145] libmultipath: add cleanup helpers for struct multipath Export cleanup_multipath_and_paths(), which will be used by multipath. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/libmultipath.version | 1 + libmultipath/structs.c | 12 ++++++++++++ libmultipath/structs.h | 2 ++ 3 files changed, 15 insertions(+) diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index eb5117499..f58cb1de7 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -66,6 +66,7 @@ global: check_foreign; cleanup_bindings; cleanup_lock; + cleanup_multipath_and_paths; coalesce_paths; count_active_paths; delete_all_foreign; diff --git a/libmultipath/structs.c b/libmultipath/structs.c index be3125ed1..1583e0012 100644 --- a/libmultipath/structs.c +++ b/libmultipath/structs.c @@ -329,6 +329,18 @@ free_multipath (struct multipath * mpp, enum free_path_mode free_paths) free(mpp); } +void cleanup_multipath(struct multipath **pmpp) +{ + if (*pmpp) + free_multipath(*pmpp, KEEP_PATHS); +} + +void cleanup_multipath_and_paths(struct multipath **pmpp) +{ + if (*pmpp) + free_multipath(*pmpp, FREE_PATHS); +} + void drop_multipath (vector mpvec, char * wwid, enum free_path_mode free_paths) { diff --git a/libmultipath/structs.h b/libmultipath/structs.h index dbaf4d439..3b91e39ca 100644 --- a/libmultipath/structs.h +++ b/libmultipath/structs.h @@ -544,6 +544,8 @@ void free_pathvec (vector vec, enum free_path_mode free_paths); void free_pathgroup (struct pathgroup * pgp, enum free_path_mode free_paths); void free_pgvec (vector pgvec, enum free_path_mode free_paths); void free_multipath (struct multipath *, enum free_path_mode free_paths); +void cleanup_multipath(struct multipath **pmpp); +void cleanup_multipath_and_paths(struct multipath **pmpp); void free_multipath_attributes (struct multipath *); void drop_multipath (vector mpvec, char * wwid, enum free_path_mode free_paths); void free_multipathvec (vector mpvec, enum free_path_mode free_paths); From ad5c3cbc433530bb01cf4519e9be97c457f93c56 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Sat, 29 Jun 2024 09:58:26 +0200 Subject: [PATCH 024/145] libmultipath: add cleanup_dm_task(), and use it in devmapper.c This allows us to get rid of a lot of goto statements, and generally obtain cleaner code. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 261 ++++++++++++++++----------------------- 1 file changed, 108 insertions(+), 153 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 8996c1d6e..7dac9fa23 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -91,6 +91,12 @@ int libmp_dm_task_run(struct dm_task *dmt) return r; } +static void cleanup_dm_task(struct dm_task **pdmt) +{ + if (*pdmt) + dm_task_destroy(*pdmt); +} + __attribute__((format(printf, 4, 5))) static void dm_write_log (int level, const char *file, int line, const char *f, ...) { @@ -203,8 +209,8 @@ static void init_dm_drv_version(void) static int dm_tgt_version (unsigned int *version, char *str) { - int r = 2; - struct dm_task *dmt; + bool found = false; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; struct dm_versions *target; struct dm_versions *last_target; unsigned int *v; @@ -220,31 +226,28 @@ static int dm_tgt_version (unsigned int *version, char *str) if (!libmp_dm_task_run(dmt)) { dm_log_error(2, DM_DEVICE_LIST_VERSIONS, dmt); condlog(0, "Cannot communicate with kernel DM"); - goto out; + return 1; } target = dm_task_get_versions(dmt); do { last_target = target; if (!strncmp(str, target->name, strlen(str))) { - r = 1; + found = true; break; } target = (void *) target + target->next; } while (last_target != target); - if (r == 2) { + if (!found) { condlog(0, "DM %s kernel driver not loaded", str); - goto out; + return 1; } v = target->version; version[0] = v[0]; version[1] = v[1]; version[2] = v[2]; - r = 0; -out: - dm_task_destroy(dmt); - return r; + return 0; } static void init_dm_mpath_version(void) @@ -383,18 +386,18 @@ libmp_dm_task_create(int task) static int dm_simplecmd (int task, const char *name, int flags, uint16_t udev_flags) { - int r = 0; + int r; int udev_wait_flag = (((flags & DMFL_NEED_SYNC) || udev_flags) && (task == DM_DEVICE_RESUME || task == DM_DEVICE_REMOVE)); uint32_t cookie = 0; - struct dm_task *dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; if (!(dmt = libmp_dm_task_create (task))) return 0; if (!dm_task_set_name (dmt, name)) - goto out; + return 0; dm_task_skip_lockfs(dmt); /* for DM_DEVICE_RESUME */ #ifdef LIBDM_API_FLUSH @@ -408,7 +411,7 @@ dm_simplecmd (int task, const char *name, int flags, uint16_t udev_flags) { if (udev_wait_flag && !dm_task_set_cookie(dmt, &cookie, DM_UDEV_DISABLE_LIBRARY_FALLBACK | udev_flags)) - goto out; + return 0; r = libmp_dm_task_run (dmt); if (!r) @@ -416,8 +419,6 @@ dm_simplecmd (int task, const char *name, int flags, uint16_t udev_flags) { if (udev_wait_flag) libmp_udev_wait(cookie); -out: - dm_task_destroy (dmt); return r; } @@ -440,8 +441,9 @@ static int dm_addmap (int task, const char *target, struct multipath *mpp, char * params, int ro, uint16_t udev_flags) { int r = 0; - struct dm_task *dmt; - char *prefixed_uuid = NULL; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; + char __attribute__((cleanup(cleanup_charp))) *prefixed_uuid = NULL; + uint32_t cookie = 0; if (task == DM_DEVICE_CREATE && strlen(mpp->wwid) == 0) { @@ -457,10 +459,10 @@ dm_addmap (int task, const char *target, struct multipath *mpp, return 0; if (!dm_task_set_name (dmt, mpp->alias)) - goto addout; + return 0; if (!dm_task_add_target (dmt, 0, mpp->size, target, params)) - goto addout; + return 0; if (ro) dm_task_set_ro(dmt); @@ -469,10 +471,10 @@ dm_addmap (int task, const char *target, struct multipath *mpp, if (asprintf(&prefixed_uuid, UUID_PREFIX "%s", mpp->wwid) < 0) { condlog(0, "cannot create prefixed uuid : %s", strerror(errno)); - goto addout; + return 0; } if (!dm_task_set_uuid(dmt, prefixed_uuid)) - goto freeout; + return 0; dm_task_skip_lockfs(dmt); #ifdef LIBDM_API_FLUSH dm_task_no_flush(dmt); @@ -481,33 +483,28 @@ dm_addmap (int task, const char *target, struct multipath *mpp, if (mpp->attribute_flags & (1 << ATTR_MODE) && !dm_task_set_mode(dmt, mpp->mode)) - goto freeout; + return 0; if (mpp->attribute_flags & (1 << ATTR_UID) && !dm_task_set_uid(dmt, mpp->uid)) - goto freeout; + return 0; if (mpp->attribute_flags & (1 << ATTR_GID) && !dm_task_set_gid(dmt, mpp->gid)) - goto freeout; + return 0; + condlog(2, "%s: %s [0 %llu %s %s]", mpp->alias, task == DM_DEVICE_RELOAD ? "reload" : "addmap", mpp->size, target, params); if (task == DM_DEVICE_CREATE && !dm_task_set_cookie(dmt, &cookie, udev_flags)) - goto freeout; + return 0; r = libmp_dm_task_run (dmt); if (!r) dm_log_error(2, task, dmt); if (task == DM_DEVICE_CREATE) - libmp_udev_wait(cookie); -freeout: - if (prefixed_uuid) - free(prefixed_uuid); - -addout: - dm_task_destroy (dmt); + libmp_udev_wait(cookie); if (r) mpp->need_reload = false; @@ -648,46 +645,41 @@ int dm_map_present(const char * str) int dm_get_map(const char *name, unsigned long long *size, char **outparams) { - int r = DMP_ERR; - struct dm_task *dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; uint64_t start, length; char *target_type = NULL; char *params = NULL; if (!(dmt = libmp_dm_task_create(DM_DEVICE_TABLE))) - return r; + return DMP_ERR; if (!dm_task_set_name(dmt, name)) - goto out; + return DMP_ERR; errno = 0; if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_TABLE, dmt); if (dm_task_get_errno(dmt) == ENXIO) - r = DMP_NOT_FOUND; - goto out; + return DMP_NOT_FOUND; + else + return DMP_ERR; } - r = DMP_NOT_FOUND; /* Fetch 1st target */ if (dm_get_next_target(dmt, NULL, &start, &length, &target_type, ¶ms) != NULL || !params) /* more than one target or not found target */ - goto out; + return DMP_NOT_FOUND; if (size) *size = length; if (!outparams) - r = DMP_OK; + return DMP_OK; else { *outparams = strdup(params); - r = *outparams ? DMP_OK : DMP_ERR; + return *outparams ? DMP_OK : DMP_ERR; } - -out: - dm_task_destroy(dmt); - return r; } static int @@ -767,7 +759,7 @@ is_mpath_part(const char *part_name, const char *map_name) int dm_get_status(const char *name, char **outstatus) { int r = DMP_ERR; - struct dm_task *dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; uint64_t start, length; char *target_type = NULL; char *status = NULL; @@ -796,7 +788,7 @@ int dm_get_status(const char *name, char **outstatus) goto out; if (!status) { - condlog(2, "get null status."); + condlog(2, "got null status."); goto out; } @@ -808,9 +800,9 @@ int dm_get_status(const char *name, char **outstatus) } out: if (r != DMP_OK) - condlog(0, "%s: error getting map status string", name); + condlog(0, "%s: %s: error getting map status string: %d", + __func__, name, r); - dm_task_destroy(dmt); return r; } @@ -823,7 +815,7 @@ int dm_get_status(const char *name, char **outstatus) int dm_type(const char *name, char *type) { int r = 0; - struct dm_task *dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; uint64_t start, length; char *target_type = NULL; char *params; @@ -850,7 +842,6 @@ int dm_type(const char *name, char *type) r = 1; out: - dm_task_destroy(dmt); return r; } @@ -863,7 +854,7 @@ int dm_type(const char *name, char *type) int dm_is_mpath(const char *name) { int r = -1; - struct dm_task *dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; struct dm_info info; uint64_t start, length; char *target_type = NULL; @@ -874,38 +865,36 @@ int dm_is_mpath(const char *name) goto out; if (!dm_task_set_name(dmt, name)) - goto out_task; + goto out; if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_TABLE, dmt); - goto out_task; + goto out; } if (!dm_task_get_info(dmt, &info)) - goto out_task; + goto out; r = 0; if (!info.exists) - goto out_task; + goto out; uuid = dm_task_get_uuid(dmt); if (!uuid || strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN) != 0) - goto out_task; + goto out; /* Fetch 1st target */ if (dm_get_next_target(dmt, NULL, &start, &length, &target_type, ¶ms) != NULL) /* multiple targets */ - goto out_task; + goto out; if (!target_type || strcmp(target_type, TGT_MPATH) != 0) - goto out_task; + goto out; r = 1; -out_task: - dm_task_destroy(dmt); out: if (r < 0) condlog(3, "%s: dm command failed in %s: %s", name, __FUNCTION__, strerror(errno)); @@ -1131,10 +1120,10 @@ dm_flush_map_nopaths(const char *mapname, int deferred_remove __DR_UNUSED__) return _dm_flush_map(mapname, flags, 0); } -int dm_flush_maps (int retries) +int dm_flush_maps(int retries) { int r = DM_FLUSH_FAIL; - struct dm_task *dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; struct dm_names *names; unsigned next = 0; @@ -1143,15 +1132,15 @@ int dm_flush_maps (int retries) if (!libmp_dm_task_run (dmt)) { dm_log_error(3, DM_DEVICE_LIST, dmt); - goto out; + return r; } if (!(names = dm_task_get_names (dmt))) - goto out; + return r; r = DM_FLUSH_OK; if (!names->dev) - goto out; + return r; do { int ret; @@ -1163,16 +1152,13 @@ int dm_flush_maps (int retries) names = (void *) names + next; } while (next); -out: - dm_task_destroy (dmt); return r; } int dm_message(const char * mapname, char * message) { - int r = 1; - struct dm_task *dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; if (!(dmt = libmp_dm_task_create(DM_DEVICE_TARGET_MSG))) return 1; @@ -1191,13 +1177,10 @@ dm_message(const char * mapname, char * message) goto out; } - r = 0; + return 0; out: - if (r) - condlog(0, "DM message failed [%s]", message); - - dm_task_destroy(dmt); - return r; + condlog(0, "DM message failed [%s]", message); + return 1; } int @@ -1305,12 +1288,10 @@ struct multipath *dm_get_multipath(const char *name) return NULL; } -int -dm_get_maps (vector mp) +int dm_get_maps(vector mp) { struct multipath * mpp; - int r = 1; - struct dm_task *dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; struct dm_names *names; unsigned next = 0; @@ -1322,15 +1303,15 @@ dm_get_maps (vector mp) if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_LIST, dmt); - goto out; + return 1; } if (!(names = dm_task_get_names(dmt))) - goto out; + return 1; if (!names->dev) { - r = 0; /* this is perfectly valid */ - goto out; + /* this is perfectly valid */ + return 0; } do { @@ -1339,11 +1320,11 @@ dm_get_maps (vector mp) mpp = dm_get_multipath(names->name); if (!mpp) - goto out; + return 1; if (!vector_alloc_slot(mp)) { free_multipath(mpp, KEEP_PATHS); - goto out; + return 1; } vector_set_slot(mp, mpp); @@ -1352,11 +1333,7 @@ dm_get_maps (vector mp) names = (void *) names + next; } while (next); - r = 0; - goto out; -out: - dm_task_destroy (dmt); - return r; + return 0; } int @@ -1419,33 +1396,29 @@ do_foreach_partmaps (const char * mapname, int (*partmap_func)(const char *, void *), void *data) { - struct dm_task *dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; + char __attribute__((cleanup(cleanup_charp))) *params = NULL; struct dm_names *names; unsigned next = 0; - char *params = NULL; unsigned long long size; char dev_t[32]; - int r = 1; char *p; if (!(dmt = libmp_dm_task_create(DM_DEVICE_LIST))) return 1; - if (!libmp_dm_task_run(dmt)) { - dm_log_error(3, DM_DEVICE_LIST, dmt); - goto out; - } + if (!libmp_dm_task_run(dmt)) + return 1; if (!(names = dm_task_get_names(dmt))) - goto out; + return 1; - if (!names->dev) { - r = 0; /* this is perfectly valid */ - goto out; - } + if (!names->dev) + /* this is perfectly valid */ + return 0; if (dm_dev_t(mapname, &dev_t[0], 32)) - goto out; + return 1; do { if ( @@ -1471,8 +1444,8 @@ do_foreach_partmaps (const char * mapname, (p = strstr(params, dev_t)) && !isdigit(*(p + strlen(dev_t))) ) { - if ((r = partmap_func(names->name, data)) != 0) - goto out; + if (partmap_func(names->name, data) != 0) + return 1; } free(params); @@ -1481,11 +1454,7 @@ do_foreach_partmaps (const char * mapname, names = (void *) names + next; } while (next); - r = 0; -out: - free(params); - dm_task_destroy (dmt); - return r; + return 0; } struct remove_data { @@ -1623,7 +1592,7 @@ int dm_rename (const char * old, char * new, char *delim, int skip_kpartx) { int r = 0; - struct dm_task *dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; uint32_t cookie = 0; uint16_t udev_flags = DM_UDEV_DISABLE_LIBRARY_FALLBACK | ((skip_kpartx == SKIP_KPARTX_ON)? MPATH_UDEV_NO_KPARTX_FLAG : 0); @@ -1634,22 +1603,19 @@ dm_rename (const char * old, char * new, char *delim, int skip_kpartx) return r; if (!dm_task_set_name(dmt, old)) - goto out; + return r; if (!dm_task_set_newname(dmt, new)) - goto out; + return r; if (!dm_task_set_cookie(dmt, &cookie, udev_flags)) - goto out; + return r; + r = libmp_dm_task_run(dmt); if (!r) dm_log_error(2, DM_DEVICE_RENAME, dmt); libmp_udev_wait(cookie); - -out: - dm_task_destroy(dmt); - return r; } @@ -1672,9 +1638,10 @@ void dm_reassign_deps(char *table, const char *dep, const char *newdep) int dm_reassign_table(const char *name, char *old, char *new) { - int r = 0, modified = 0; + int modified = 0; uint64_t start, length; - struct dm_task *dmt, *reload_dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *reload_dmt = NULL; char *target, *params = NULL; char *buff; void *next = NULL; @@ -1683,16 +1650,16 @@ int dm_reassign_table(const char *name, char *old, char *new) return 0; if (!dm_task_set_name(dmt, name)) - goto out; + return 0; if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_TABLE, dmt); - goto out; + return 0; } if (!(reload_dmt = libmp_dm_task_create(DM_DEVICE_RELOAD))) - goto out; + return 0; if (!dm_task_set_name(reload_dmt, name)) - goto out_reload; + return 0; do { next = dm_get_next_target(dmt, next, &start, &length, @@ -1705,13 +1672,13 @@ int dm_reassign_table(const char *name, char *old, char *new) */ condlog(1, "%s: invalid target found in map %s", __func__, name); - goto out_reload; + return 0; } buff = strdup(params); if (!buff) { condlog(3, "%s: failed to replace target %s, " "out of memory", name, target); - goto out_reload; + return 0; } if (strcmp(target, TGT_MPATH) && strstr(params, old)) { condlog(3, "%s: replace target %s %s", @@ -1729,18 +1696,12 @@ int dm_reassign_table(const char *name, char *old, char *new) if (!libmp_dm_task_run(reload_dmt)) { dm_log_error(3, DM_DEVICE_RELOAD, reload_dmt); condlog(3, "%s: failed to reassign targets", name); - goto out_reload; + return 0; } dm_simplecmd_noflush(DM_DEVICE_RESUME, name, MPATH_UDEV_RELOAD_FLAG); } - r = 1; - -out_reload: - dm_task_destroy(reload_dmt); -out: - dm_task_destroy(dmt); - return r; + return 1; } @@ -1752,10 +1713,9 @@ int dm_reassign_table(const char *name, char *old, char *new) int dm_reassign(const char *mapname) { struct dm_deps *deps; - struct dm_task *dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; struct dm_info info; char dev_t[32], dm_dep[32]; - int r = 0; unsigned int i; if (dm_dev_t(mapname, &dev_t[0], 32)) { @@ -1769,21 +1729,21 @@ int dm_reassign(const char *mapname) } if (!dm_task_set_name(dmt, mapname)) - goto out; + return 0; if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_DEPS, dmt); - goto out; + return 0; } if (!dm_task_get_info(dmt, &info)) - goto out; + return 0; if (!(deps = dm_task_get_deps(dmt))) - goto out; + return 0; if (!info.exists) - goto out; + return 0; for (i = 0; i < deps->count; i++) { sprintf(dm_dep, "%d:%d", @@ -1792,15 +1752,12 @@ int dm_reassign(const char *mapname) sysfs_check_holders(dm_dep, dev_t); } - r = 1; -out: - dm_task_destroy (dmt); - return r; + return 1; } int dm_setgeometry(struct multipath *mpp) { - struct dm_task *dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; struct path *pp; char heads[4], sectors[4]; char cylinders[10], start[32]; @@ -1825,7 +1782,7 @@ int dm_setgeometry(struct multipath *mpp) return 0; if (!dm_task_set_name(dmt, mpp->alias)) - goto out; + return 0; /* What a sick interface ... */ snprintf(heads, 4, "%u", pp->geom.heads); @@ -1834,14 +1791,12 @@ int dm_setgeometry(struct multipath *mpp) snprintf(start, 32, "%lu", pp->geom.start); if (!dm_task_set_geometry(dmt, cylinders, heads, sectors, start)) { condlog(3, "%s: Failed to set geometry", mpp->alias); - goto out; + return 0; } r = libmp_dm_task_run(dmt); if (!r) dm_log_error(3, DM_DEVICE_SET_GEOMETRY, dmt); -out: - dm_task_destroy(dmt); return r; } From 55a57a27718b09861a8ab6b5486cf4039f439d8f Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 11 Jul 2024 22:52:41 +0200 Subject: [PATCH 025/145] libmultipath: rename dm_type()->dm_type_match() and use symbolic values Also, make the function static. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 37 +++++++++++++++++++------------------ libmultipath/devmapper.h | 1 - 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 7dac9fa23..7ba84e0d9 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -806,43 +806,44 @@ int dm_get_status(const char *name, char **outstatus) return r; } -/* - * returns: - * 1 : match - * 0 : no match - * -1 : empty map, or more than 1 target - */ -int dm_type(const char *name, char *type) +enum { + DM_TYPE_NOMATCH = 0, + DM_TYPE_MATCH, + /* more than 1 target */ + DM_TYPE_MULTI, + /* empty map */ + DM_TYPE_EMPTY, + DM_TYPE_ERR, +}; +static int dm_type_match(const char *name, char *type) { - int r = 0; struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; uint64_t start, length; char *target_type = NULL; char *params; if (!(dmt = libmp_dm_task_create(DM_DEVICE_TABLE))) - return 0; + return DM_TYPE_ERR; if (!dm_task_set_name(dmt, name)) - goto out; + return DM_TYPE_ERR; if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_TABLE, dmt); - goto out; + return DM_TYPE_ERR; } /* Fetch 1st target */ if (dm_get_next_target(dmt, NULL, &start, &length, &target_type, ¶ms) != NULL) /* multiple targets */ - r = -1; + return DM_TYPE_MULTI; else if (!target_type) - r = -1; + return DM_TYPE_EMPTY; else if (!strcmp(target_type, type)) - r = 1; - -out: - return r; + return DM_TYPE_MATCH; + else + return DM_TYPE_NOMATCH; } /* @@ -1425,7 +1426,7 @@ do_foreach_partmaps (const char * mapname, /* * if there is only a single "linear" target */ - (dm_type(names->name, TGT_PART) == 1) && + (dm_type_match(names->name, TGT_PART) == DM_TYPE_MATCH) && /* * and the uuid of the target is a partition of the diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 19b79c5bf..ff2857578 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -46,7 +46,6 @@ int dm_map_present (const char *name); int dm_map_present_by_uuid(const char *uuid); int dm_get_map(const char *name, unsigned long long *size, char **outparams); int dm_get_status(const char *name, char **outstatus); -int dm_type(const char *name, char *type); int dm_is_mpath(const char *name); enum { From 6dacf3031f50c6472e8df2cfa0831679d86df953 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 11 Jul 2024 22:57:37 +0200 Subject: [PATCH 026/145] libmultipath: Use symbolic return values for dm_is_mpath() Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathpersist/mpath_persist_int.c | 2 +- libmultipath/devmapper.c | 22 ++++++++-------------- libmultipath/devmapper.h | 6 ++++++ multipath/main.c | 4 ++-- multipathd/dmevents.c | 19 +++++++++++++------ multipathd/main.c | 2 +- 6 files changed, 31 insertions(+), 24 deletions(-) diff --git a/libmpathpersist/mpath_persist_int.c b/libmpathpersist/mpath_persist_int.c index 178c2f540..6da0401f6 100644 --- a/libmpathpersist/mpath_persist_int.c +++ b/libmpathpersist/mpath_persist_int.c @@ -185,7 +185,7 @@ static int mpath_get_map(vector curmp, vector pathvec, int fd, char **palias, condlog(3, "alias = %s", alias); - if (dm_map_present(alias) && dm_is_mpath(alias) != 1){ + if (dm_map_present(alias) && dm_is_mpath(alias) != DM_IS_MPATH_YES) { condlog(3, "%s: not a multipath device.", alias); goto out; } diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 7ba84e0d9..5492a8681 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -846,15 +846,9 @@ static int dm_type_match(const char *name, char *type) return DM_TYPE_NOMATCH; } -/* - * returns: - * 1 : is multipath device - * 0 : is not multipath device - * -1 : error - */ int dm_is_mpath(const char *name) { - int r = -1; + int r = DM_IS_MPATH_ERR; struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; struct dm_info info; uint64_t start, length; @@ -876,7 +870,7 @@ int dm_is_mpath(const char *name) if (!dm_task_get_info(dmt, &info)) goto out; - r = 0; + r = DM_IS_MPATH_NO; if (!info.exists) goto out; @@ -895,10 +889,10 @@ int dm_is_mpath(const char *name) if (!target_type || strcmp(target_type, TGT_MPATH) != 0) goto out; - r = 1; + r = DM_IS_MPATH_YES; out: - if (r < 0) - condlog(3, "%s: dm command failed in %s: %s", name, __FUNCTION__, strerror(errno)); + if (r == DM_IS_MPATH_ERR) + condlog(3, "%s: dm command failed in %s: %s", name, __func__, strerror(errno)); return r; } @@ -1039,7 +1033,7 @@ int _dm_flush_map (const char *mapname, int flags, int retries) unsigned long long mapsize; char *params = NULL; - if (dm_is_mpath(mapname) != 1) + if (dm_is_mpath(mapname) != DM_IS_MPATH_YES) return DM_FLUSH_OK; /* nothing to do */ /* if the device currently has no partitions, do not @@ -1086,7 +1080,7 @@ int _dm_flush_map (const char *mapname, int flags, int retries) } condlog(4, "multipath map %s removed", mapname); return DM_FLUSH_OK; - } else if (dm_is_mpath(mapname) != 1) { + } else if (dm_is_mpath(mapname) != DM_IS_MPATH_YES) { condlog(4, "multipath map %s removed externally", mapname); return DM_FLUSH_OK; /* raced. someone else removed it */ @@ -1316,7 +1310,7 @@ int dm_get_maps(vector mp) } do { - if (dm_is_mpath(names->name) != 1) + if (dm_is_mpath(names->name) != DM_IS_MPATH_YES) goto next; mpp = dm_get_multipath(names->name); diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index ff2857578..9438c2d3d 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -46,6 +46,12 @@ int dm_map_present (const char *name); int dm_map_present_by_uuid(const char *uuid); int dm_get_map(const char *name, unsigned long long *size, char **outparams); int dm_get_status(const char *name, char **outstatus); + +enum { + DM_IS_MPATH_NO, + DM_IS_MPATH_YES, + DM_IS_MPATH_ERR, +}; int dm_is_mpath(const char *name); enum { diff --git a/multipath/main.c b/multipath/main.c index ce702e7f9..c82bc868b 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -247,7 +247,7 @@ static int check_usable_paths(struct config *conf, goto out; } - if (dm_is_mpath(mapname) != 1) { + if (dm_is_mpath(mapname) != DM_IS_MPATH_YES) { condlog(1, "%s is not a multipath map", devpath); goto free; } @@ -1080,7 +1080,7 @@ main (int argc, char *argv[]) goto out; } if (cmd == CMD_FLUSH_ONE) { - if (dm_is_mpath(dev) != 1) { + if (dm_is_mpath(dev) != DM_IS_MPATH_YES) { condlog(0, "%s is not a multipath device", dev); r = RTVL_FAIL; goto out; diff --git a/multipathd/dmevents.c b/multipathd/dmevents.c index 3fbdc5530..af1e12e71 100644 --- a/multipathd/dmevents.c +++ b/multipathd/dmevents.c @@ -168,9 +168,13 @@ static int dm_get_events(void) while (names->dev) { uint32_t event_nr; - /* Don't delete device if dm_is_mpath() fails without - * checking the device type */ - if (dm_is_mpath(names->name) == 0) + /* + * Don't delete device if dm_is_mpath() fails without + * checking the device type. + * IOW, only delete devices from the event list for which + * we positively know that they aren't multipath devices. + */ + if (dm_is_mpath(names->name) == DM_IS_MPATH_NO) goto next; event_nr = dm_event_nr(names); @@ -206,9 +210,12 @@ int watch_dmevents(char *name) struct dev_event *dev_evt, *old_dev_evt; int i; - /* We know that this is a multipath device, so only fail if - * device-mapper tells us that we're wrong */ - if (dm_is_mpath(name) == 0) { + /* + * We know that this is a multipath device, so only fail if + * device-mapper tells us that we're wrong + * IOW, don't fail for DM generic errors. + */ + if (dm_is_mpath(name) == DM_IS_MPATH_NO) { condlog(0, "%s: not a multipath device. can't watch events", name); return -1; diff --git a/multipathd/main.c b/multipathd/main.c index 58afe14a7..132bb2e97 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -865,7 +865,7 @@ ev_add_map (char * dev, const char * alias, struct vectors * vecs) int reassign_maps; struct config *conf; - if (dm_is_mpath(alias) != 1) { + if (dm_is_mpath(alias) != DM_IS_MPATH_YES) { condlog(4, "%s: not a multipath map", alias); return 0; } From fd2a873b11c3050831fe654335d4a9afad0ab5ff Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 28 Jun 2024 12:26:03 +0200 Subject: [PATCH 027/145] libmultipath: add libmp_mapinfo() libmp_mapinfo() is intended as a generic abstraction for retrieving information from the kernel device-mapper driver. It retrieves the information that the caller needs, with a minimal set of DM ioctls, and never more then 2 ioctl calls. libdm's DM_DEVICE_TABLE and DM_DEVICE_STATUS calls map to the kernel's DM_TABLE_STATUS ioctl, with or without the DM_STATUS_TABLE_FLAG set, respectively. DM_TABLE_STATUS always retrieves the basic map status (struct dm_info) and the map UUID and name, too. Note: I'd prefer to use an unnamed struct instead of _u in union libmp_map_identifer. But doing using an unnamed struct and and initializing the union like this in a function argument: func((mapid_t) { .major = major, .minor = minor }) is not part of C99, and not supported in gcc 4.8, which we still support. Likewise, the following syntax for initializing an empty struct: (mapinfo_t) { 0 } is not supported on all architectures we support (notably clang 3.5 under Debian Jessie). Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 194 +++++++++++++++++++++++++++++- libmultipath/devmapper.h | 70 +++++++++++ libmultipath/libmultipath.version | 3 +- 3 files changed, 265 insertions(+), 2 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 5492a8681..f90a8df62 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -14,7 +14,6 @@ #include #include #include -#include #include "util.h" #include "vector.h" @@ -604,6 +603,199 @@ has_dm_info(const struct multipath *mpp) return (mpp && mpp->dmi.exists != 0); } +static int libmp_set_map_identifier(int flags, mapid_t id, struct dm_task *dmt) +{ + switch (flags & __DM_MAP_BY_MASK) { + case DM_MAP_BY_UUID: + if (!id.str || !(*id.str)) + return 0; + return dm_task_set_uuid(dmt, id.str); + case DM_MAP_BY_NAME: + if (!id.str || !(*id.str)) + return 0; + return dm_task_set_name(dmt, id.str); + case DM_MAP_BY_DEV: + if (!dm_task_set_major(dmt, id._u.major)) + return 0; + return dm_task_set_minor(dmt, id._u.minor); + case DM_MAP_BY_DEVT: + if (!dm_task_set_major(dmt, major(id.devt))) + return 0; + return dm_task_set_minor(dmt, minor(id.devt)); + default: + condlog(0, "%s: invalid by_id", __func__); + return 0; + } +} + +static int libmp_mapinfo__(int flags, mapid_t id, mapinfo_t info, const char *map_id) +{ + /* avoid libmp_mapinfo__ in log messages */ + static const char fname__[] = "libmp_mapinfo"; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; + struct dm_info dmi; + int rc, ioctl_nr; + uint64_t start, length = 0; + char *target_type = NULL, *params = NULL; + const char *name = NULL, *uuid = NULL; + char __attribute__((cleanup(cleanup_charp))) *tmp_target = NULL; + char __attribute__((cleanup(cleanup_charp))) *tmp_status = NULL; + bool tgt_set = false; + + /* + * If both info.target and info.status are set, we need two + * ioctls. Call this function recursively. + * If successful, tmp_target will be non-NULL. + */ + if (info.target && info.status) { + rc = libmp_mapinfo__(flags, id, + (mapinfo_t) { .target = &tmp_target }, + map_id); + if (rc != DMP_OK) + return rc; + tgt_set = true; + } + + /* + * The DM_DEVICE_TABLE and DM_DEVICE_STATUS ioctls both fetch the basic + * information from DM_DEVICE_INFO, too. + * Choose the most lightweight ioctl to fetch all requested info. + */ + if (info.target && !info.status) + ioctl_nr = DM_DEVICE_TABLE; + else if (info.status || info.size || flags & __MAPINFO_TGT_TYPE) + ioctl_nr = DM_DEVICE_STATUS; + else + ioctl_nr = DM_DEVICE_INFO; + + if (!(dmt = libmp_dm_task_create(ioctl_nr))) + return DMP_ERR; + + if (!libmp_set_map_identifier(flags, id, dmt)) { + condlog(2, "%s: failed to set map identifier to %s", fname__, map_id); + return DMP_ERR; + } + + if (!libmp_dm_task_run(dmt)) { + dm_log_error(3, ioctl_nr, dmt); + if (dm_task_get_errno(dmt) == ENXIO) { + condlog(2, "%s: map %s not found", fname__, map_id); + return DMP_NOT_FOUND; + } else + return DMP_ERR; + } + + condlog(4, "%s: DM ioctl %d succeeded for %s", + fname__, ioctl_nr, map_id); + + if (!dm_task_get_info(dmt, &dmi)) { + condlog(2, "%s: dm_task_get_info() failed for %s ", fname__, map_id); + return DMP_ERR; + } else if(!dmi.exists) { + condlog(2, "%s: map %s doesn't exist", fname__, map_id); + return DMP_NOT_FOUND; + } + + if (info.target || info.status || info.size || flags & __MAPINFO_TGT_TYPE) { + if (dm_get_next_target(dmt, NULL, &start, &length, + &target_type, ¶ms) != NULL) { + condlog(2, "%s: map %s has multiple targets", fname__, map_id); + return DMP_NOT_FOUND; + } + if (!params) { + condlog(2, "%s: map %s has no targets", fname__, map_id); + return DMP_NOT_FOUND; + } + if (flags & __MAPINFO_TGT_TYPE) { + const char *tgt_type = flags & MAPINFO_MPATH_ONLY ? TGT_MPATH : TGT_PART; + + if (strcmp(target_type, tgt_type)) { + condlog(3, "%s: target type mismatch: \"%s\" != \"%s\"", + fname__, tgt_type, target_type); + return DMP_NO_MATCH; + } + } + } + + /* + * Check possible error conditions. + * If error is returned, don't touch any output parameters. + */ + if ((info.name && !(name = dm_task_get_name(dmt))) + || (info.uuid && !(uuid = dm_task_get_uuid(dmt))) + || (info.status && !(tmp_status = strdup(params))) + || (info.target && !tmp_target && !(tmp_target = strdup(params)))) + return DMP_ERR; + + if (info.name) { + strlcpy(info.name, name, WWID_SIZE); + condlog(4, "%s: %s: name: \"%s\"", fname__, map_id, info.name); + } + if (info.uuid) { + strlcpy(info.uuid, uuid, DM_UUID_LEN); + condlog(4, "%s: %s: uuid: \"%s\"", fname__, map_id, info.uuid); + } + + if (info.size) { + *info.size = length; + condlog(4, "%s: %s: size: %lld", fname__, map_id, *info.size); + } + + if (info.dmi) { + memcpy(info.dmi, &dmi, sizeof(*info.dmi)); + condlog(4, "%s: %s %d:%d, %d targets, %s table, %s, %s, %d opened, %u events", + fname__, map_id, + info.dmi->major, info.dmi->minor, + info.dmi->target_count, + info.dmi->live_table ? "live" : + info.dmi->inactive_table ? "inactive" : "no", + info.dmi->suspended ? "suspended" : "active", + info.dmi->read_only ? "ro" : "rw", + info.dmi->open_count, + info.dmi->event_nr); + } + + if (info.target) { + *info.target = steal_ptr(tmp_target); + if (!tgt_set) + condlog(4, "%s: %s: target: \"%s\"", fname__, map_id, *info.target); + } + + if (info.status) { + *info.status = steal_ptr(tmp_status); + condlog(4, "%s: %s: status: \"%s\"", fname__, map_id, *info.status); + } + + return DMP_OK; +} + +/* Helper: format a string describing the map for log messages */ +static const char* libmp_map_identifier(int flags, mapid_t id, char buf[BLK_DEV_SIZE]) +{ + switch (flags & __DM_MAP_BY_MASK) { + case DM_MAP_BY_NAME: + case DM_MAP_BY_UUID: + return id.str; + case DM_MAP_BY_DEV: + safe_snprintf(buf, BLK_DEV_SIZE, "%d:%d", id._u.major, id._u.minor); + return buf; + case DM_MAP_BY_DEVT: + safe_snprintf(buf, BLK_DEV_SIZE, "%d:%d", major(id.devt), minor(id.devt)); + return buf; + default: + safe_snprintf(buf, BLK_DEV_SIZE, "*invalid*"); + return buf; + } +} + +int libmp_mapinfo(int flags, mapid_t id, mapinfo_t info) +{ + char idbuf[BLK_DEV_SIZE]; + + return libmp_mapinfo__(flags, id, info, + libmp_map_identifier(flags, id, idbuf)); +} + int dm_get_info(const char *name, struct dm_info *info) { diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 9438c2d3d..4ccaaa713 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -1,5 +1,6 @@ #ifndef _DEVMAPPER_H #define _DEVMAPPER_H +#include #include "autoconfig.h" #include "structs.h" @@ -31,8 +32,77 @@ enum { DMP_ERR, DMP_OK, DMP_NOT_FOUND, + DMP_NO_MATCH, }; +/** + * enum mapinfo_flags: input flags for libmp_mapinfo() + */ +enum __mapinfo_flags { + /** DM_MAP_BY_NAME: identify map by device-mapper name from @name */ + DM_MAP_BY_NAME = 0, + /** DM_MAP_BY_UUID: identify map by device-mapper UUID from @uuid */ + DM_MAP_BY_UUID, + /** DM_MAP_BY_DEV: identify map by major/minor number from @dmi */ + DM_MAP_BY_DEV, + /** DM_MAP_BY_DEVT: identify map by a dev_t */ + DM_MAP_BY_DEVT, + __DM_MAP_BY_MASK = (1 << 8) - 1, + /* Fail if target type is not multipath */ + MAPINFO_MPATH_ONLY = (1 << 8), + /* Fail if target type is not "partition" (linear) */ + MAPINFO_PART_ONLY = (1 << 9), + __MAPINFO_TGT_TYPE = (MAPINFO_MPATH_ONLY | MAPINFO_PART_ONLY), +}; + +typedef union libmp_map_identifier { + const char *str; + struct { + int major; + int minor; + } _u; + dev_t devt; +} mapid_t; + +typedef struct libmp_map_info { + /** @name: name of the map. + * If non-NULL, it must point to an array of WWID_SIZE bytes + */ + char *name; + /** @uuid: UUID of the map. + * If non-NULL it must point to an array of DM_UUID_LEN bytes + */ + char *uuid; + /** @dmi: Basic info, must point to a valid dm_info buffer if non-NULL */ + struct dm_info *dmi; + /** @target: target params, *@target will be allocated if @target is non-NULL*/ + char **target; + /** @size: target size. */ + unsigned long long *size; + /** @status: target status, *@status will be allocated if @status is non-NULL */ + char **status; +} mapinfo_t; + +/** + * libmp_mapinfo(): obtain information about a map from the kernel + * @param flags: see __mapinfo_flags above. + * Exactly one of DM_MAP_BY_NAME, DM_MAP_BY_UUID, and DM_MAP_BY_DEV must be set. + * @param id: string or major/minor to identify the map to query + * @param info: output parameters, see above. Non-NULL elements will be filled in. + * @returns: + * DMP_OK if successful. + * DMP_NOT_FOUND if the map wasn't found, or has no or multiple targets. + * DMP_NO_MATCH if the map didn't match @tgt_type (see above). + * DMP_ERR if some other error occurred. + * + * This function obtains the requested information for the device-mapper map + * identified by the input parameters. + * Output parameters are only filled in if the return value is DMP_OK. + * For target / status / size information, the map's table should contain + * only one target (usually multipath or linear). + */ +int libmp_mapinfo(int flags, mapid_t id, mapinfo_t info); + int dm_prereq(unsigned int *v); void skip_libmp_dm_init(void); void libmp_dm_exit(void); diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index f58cb1de7..48c2b673e 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -43,7 +43,7 @@ LIBMPATHCOMMON_1.0.0 { put_multipath_config; }; -LIBMULTIPATH_24.0.0 { +LIBMULTIPATH_25.0.0 { global: /* symbols referenced by multipath and multipathd */ add_foreign; @@ -134,6 +134,7 @@ global: libmp_get_version; libmp_get_multipath_config; libmp_dm_task_run; + libmp_mapinfo; libmp_put_multipath_config; libmp_udev_set_sync_support; libmultipath_exit; From 28d9f8ce6a60d228ee205afde4314bac9fb0c82c Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Mon, 8 Jul 2024 23:23:26 +0200 Subject: [PATCH 028/145] libmultipath tests: add tests for libmp_mapinfo() Unfortunately, we need several ugly compatibility macros again in order to make these tests work with the entire set of compilers and libraries supported by multipath-tools. Details are found in comments in the code. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.h | 1 + tests/Makefile | 3 +- tests/mapinfo.c | 1175 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 1178 insertions(+), 1 deletion(-) create mode 100644 tests/mapinfo.c diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 4ccaaa713..974e2ac99 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -1,5 +1,6 @@ #ifndef _DEVMAPPER_H #define _DEVMAPPER_H +#include #include #include "autoconfig.h" #include "structs.h" diff --git a/tests/Makefile b/tests/Makefile index 8afa8c67e..55fbf0fe2 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -9,7 +9,7 @@ CFLAGS += $(BIN_CFLAGS) -Wno-unused-parameter $(W_MISSING_INITIALIZERS) LIBDEPS += -L. -L $(mpathutildir) -L$(mpathcmddir) -lmultipath -lmpathutil -lmpathcmd -lcmocka TESTS := uevent parser util dmevents hwtable blacklist unaligned vpd pgpolicy \ - alias directio valid devt mpathvalid strbuf sysfs features cli + alias directio valid devt mpathvalid strbuf sysfs features cli mapinfo HELPERS := test-lib.o test-log.o .PRECIOUS: $(TESTS:%=%-test) @@ -68,6 +68,7 @@ sysfs-test_OBJDEPS := $(multipathdir)/sysfs.o $(mpathutildir)/util.o sysfs-test_LIBDEPS := -ludev -lpthread -ldl features-test_LIBDEPS := -ludev -lpthread cli-test_OBJDEPS := $(daemondir)/cli.o +mapinfo-test_LIBDEPS = -lpthread -ldevmapper %.o: %.c @echo building $@ because of $? diff --git a/tests/mapinfo.c b/tests/mapinfo.c new file mode 100644 index 000000000..f3a8440c0 --- /dev/null +++ b/tests/mapinfo.c @@ -0,0 +1,1175 @@ +/* + * Copyright (c) 2024 Martin Wilck, SUSE + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +/* + * glibc <= 2.19 (Ubuntu Trusty, Debian Jessie) uses macros to inline strdup(), + * which makes our strdup wrapper fail. + */ +#define _GNU_SOURCE 1 +#include +#include +#ifndef __GLIBC_PREREQ +#define __GLIBC_PREREQ(x, y) 0 +#endif +#if defined(__GLIBC__) && !(__GLIBC_PREREQ(2, 20)) +#define __NO_STRING_INLINES 1 +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "util.h" +#include "devmapper.h" +#include "globals.c" +/* + * We can't just use mapinfo-test_OBJDEPS because + */ +#include "../libmultipath/devmapper.c" + +static const struct dm_info __attribute__((unused)) MPATH_DMI_01 = { + .exists = 1, + .live_table = 1, + .open_count = 1, + .target_count = 1, + .major = 254, + .minor = 123, +}; + +static const char MPATH_NAME_01[] = "mpathx"; +static const char MPATH_UUID_01[] = "mpath-3600a098038302d414b2b4d4453474f62"; +static const char MPATH_TARGET_01[] = + "2 pg_init_retries 50 1 alua 2 1 " + "service-time 0 3 2 65:32 1 1 67:64 1 1 69:96 1 1 " + "service-time 0 3 2 8:16 1 1 66:48 1 1 68:80 1 1 "; +static const char MPATH_STATUS_01[] = + "2 0 1 0 2 1 " + "A 0 3 2 65:32 A 0 0 1 67:64 A 0 0 1 69:96 A 0 0 1 " + "E 0 3 2 8:16 A 0 0 1 66:48 A 0 0 1 68:80 A 0 0 1 "; + +char *__real_strdup(const char *str); +char *__wrap_strdup(const char *str) +{ + if (mock_type(int)) + return __real_strdup(str); + return NULL; +} + +void __wrap_dm_task_destroy(struct dm_task *t) +{ +} + +struct dm_task *__wrap_dm_task_create(int task) +{ + check_expected(task); + return mock_ptr_type(void *); +} + +int __wrap_dm_task_run(struct dm_task *t) +{ + return mock_type(int); +} + +/* + * Hack for older versions of libdevmapper, where dm_task_get_errno() + * is not available. + */ +#ifndef LIBDM_API_GET_ERRNO +#define WILL_RETURN_GET_ERRNO(y) do { errno = y; } while (0) +#else +int __wrap_dm_task_get_errno(struct dm_task *t) +{ + return mock_type(int); +} +#define WILL_RETURN_GET_ERRNO(y) will_return(__wrap_dm_task_get_errno, y) +#endif + +int __wrap_dm_task_set_name(struct dm_task *t, const char *name) +{ + check_expected(name); + return mock_type(int); +} + +int __wrap_dm_task_set_uuid(struct dm_task *t, const char *uuid) +{ + check_expected(uuid); + return mock_type(int); +} + +int __wrap_dm_task_set_major(struct dm_task *t, int val) +{ + check_expected(val); + return mock_type(int); +} + +int __wrap_dm_task_set_minor(struct dm_task *t, int val) +{ + check_expected(val); + return mock_type(int); +} + +/* between LVM2 2.02.110 and 2.02.112, dm_task_get_info was a macro */ +#ifdef dm_task_get_info +#define WRAP_DM_TASK_GET_INFO(x) \ + will_return(__wrap_dm_task_get_info_with_deferred_remove, x) +int __wrap_dm_task_get_info_with_deferred_remove(struct dm_task *t, struct dm_info *dmi) +#else +#define WRAP_DM_TASK_GET_INFO(x) \ + will_return(__wrap_dm_task_get_info, x) +int __wrap_dm_task_get_info(struct dm_task *t, struct dm_info *dmi) +#endif +{ + int rc = mock_type(int); + + assert_non_null(dmi); + if (rc) { + struct dm_info *info = mock_ptr_type(struct dm_info *); + + memcpy(dmi, info, sizeof(*dmi)); + } + return rc; +} + +void * __wrap_dm_get_next_target(struct dm_task *dmt, void *next, + uint64_t *start, uint64_t *length, + char **target_type, char **params) +{ + *start = 0; + *length = mock_type(uint64_t); + *target_type = mock_ptr_type(char *); + *params = mock_ptr_type(char *); + return mock_ptr_type(void *); +} + +static void mock_dm_get_next_target(uint64_t len, const char *target_type, + const char *params, void *next) +{ + will_return(__wrap_dm_get_next_target, len); + will_return(__wrap_dm_get_next_target, target_type); + will_return(__wrap_dm_get_next_target, params); + will_return(__wrap_dm_get_next_target, next); +} + +const char *__wrap_dm_task_get_name(struct dm_task *t) +{ + return mock_ptr_type(const char *); +} + +const char *__wrap_dm_task_get_uuid(struct dm_task *t) +{ + return mock_ptr_type(const char *); +} + +static void mock_mapinfo_name_1(int ioctl_nr, int create_rc, const char *name, + int name_rc, int run_rc, int err) +{ + expect_value(__wrap_dm_task_create, task, ioctl_nr); + will_return(__wrap_dm_task_create, create_rc); + if (create_rc == 0) + return; + expect_value(__wrap_dm_task_set_name, name, name); + will_return(__wrap_dm_task_set_name, name_rc); + if (name_rc == 0) + return; + will_return(__wrap_dm_task_run, run_rc); + if (run_rc == 0) { + WILL_RETURN_GET_ERRNO(err); + /* for dm_log_error() */ + WILL_RETURN_GET_ERRNO(err); + } +} + +static void test_mapinfo_bad_task_create_01(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 0, NULL, 0, 0, 0); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_mapid(void **state) +{ + int rc; + + /* can't use mock_mapinfo_name() here because of invalid id type */ + expect_value(__wrap_dm_task_create, task, DM_DEVICE_INFO); + will_return(__wrap_dm_task_create, 1); + rc = libmp_mapinfo(DM_MAP_BY_NAME + 100, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_set_name(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 0, 0, 0); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_task_run_01(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 0, EINVAL); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_task_run_02(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 0, ENXIO); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NOT_FOUND); +} + +/* libmp_mapinfo must choose DM_DEVICE_STATUS */ +static void test_mapinfo_bad_task_run_03(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 0, EINVAL); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_task_run_04(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 0, ENXIO); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NOT_FOUND); +} + +/* If target is set, libmp_mapinfo must choose DM_DEVICE_TABLE */ +static void test_mapinfo_bad_task_run_05(void **state) +{ + int rc; + char *params = NULL; + + mock_mapinfo_name_1(DM_DEVICE_TABLE, 1, "foo", 1, 0, EINVAL); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .target = ¶ms }); + assert_int_equal(rc, DMP_ERR); + assert_ptr_equal(params, NULL); +} + +static void test_mapinfo_bad_task_run_06(void **state) +{ + int rc; + char *params = NULL; + + mock_mapinfo_name_1(DM_DEVICE_TABLE, 1, "foo", 1, 0, ENXIO); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .target = ¶ms }); + assert_int_equal(rc, DMP_NOT_FOUND); + assert_ptr_equal(params, NULL); +} + +/* If status is set, libmp_mapinfo must choose DM_DEVICE_STATUS */ +static void test_mapinfo_bad_task_run_07(void **state) +{ + int rc; + char *params = NULL; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 0, EINVAL); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .status = ¶ms }); + assert_int_equal(rc, DMP_ERR); + assert_ptr_equal(params, NULL); +} + +static void test_mapinfo_bad_task_run_08(void **state) +{ + int rc; + char *params = NULL; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 0, ENXIO); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .status = ¶ms }); + assert_int_equal(rc, DMP_NOT_FOUND); + assert_ptr_equal(params, NULL); +} + +static void test_mapinfo_bad_task_run_09(void **state) +{ + int rc; + char *params = NULL, *status = NULL; + + mock_mapinfo_name_1(DM_DEVICE_TABLE, 1, "foo", 1, 0, EINVAL); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .target = ¶ms, .status = &status }); + assert_int_equal(rc, DMP_ERR); + assert_ptr_equal(params, NULL); + assert_ptr_equal(status, NULL); +} + +static void test_mapinfo_bad_task_run_10(void **state) +{ + int rc; + char *params = NULL, *status = NULL; + + mock_mapinfo_name_1(DM_DEVICE_TABLE, 1, "foo", 1, 0, ENXIO); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .target = ¶ms, .status = &status }); + assert_int_equal(rc, DMP_NOT_FOUND); + assert_ptr_equal(params, NULL); + assert_ptr_equal(status, NULL); +} + +static void test_mapinfo_bad_get_info_01(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(0); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_get_info_02(void **state) +{ + int rc; + struct dm_info dmi = { .suspended = 0 }; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&dmi); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NOT_FOUND); +} + +static void test_mapinfo_bad_get_info_03(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(0); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_PART_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_get_info_04(void **state) +{ + int rc; + struct dm_info dmi = { .suspended = 0 }; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&dmi); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_PART_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NOT_FOUND); +} + +static void test_mapinfo_good_exists(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_OK); +} + +static void test_mapinfo_bad_set_uuid(void **state) +{ + int rc; + + expect_value(__wrap_dm_task_create, task, DM_DEVICE_INFO); + will_return(__wrap_dm_task_create, 1); + expect_value(__wrap_dm_task_set_uuid, uuid, "foo"); + will_return(__wrap_dm_task_set_uuid, 0); + rc = libmp_mapinfo(DM_MAP_BY_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_set_dev_01(void **state) +{ + int rc; + + expect_value(__wrap_dm_task_create, task, DM_DEVICE_INFO); + will_return(__wrap_dm_task_create, 1); + expect_value(__wrap_dm_task_set_major, val, 254); + will_return(__wrap_dm_task_set_major, 0); + rc = libmp_mapinfo(DM_MAP_BY_DEV, + (mapid_t) { ._u = { 254, 123 } }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_set_dev_02(void **state) +{ + int rc; + + expect_value(__wrap_dm_task_create, task, DM_DEVICE_INFO); + will_return(__wrap_dm_task_create, 1); + expect_value(__wrap_dm_task_set_major, val, 254); + will_return(__wrap_dm_task_set_major, 1); + expect_value(__wrap_dm_task_set_minor, val, 123); + will_return(__wrap_dm_task_set_minor, 0); + rc = libmp_mapinfo(DM_MAP_BY_DEV, + (mapid_t) { ._u = { 254, 123 } }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_set_dev_03(void **state) +{ + int rc; + dev_t devt = makedev(254, 123); + + expect_value(__wrap_dm_task_create, task, DM_DEVICE_INFO); + will_return(__wrap_dm_task_create, 1); + expect_value(__wrap_dm_task_set_major, val, 254); + will_return(__wrap_dm_task_set_major, 0); + rc = libmp_mapinfo(DM_MAP_BY_DEVT, + (mapid_t) { .devt = devt }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_set_dev_04(void **state) +{ + int rc; + dev_t devt = makedev(254, 123); + + expect_value(__wrap_dm_task_create, task, DM_DEVICE_INFO); + will_return(__wrap_dm_task_create, 1); + expect_value(__wrap_dm_task_set_major, val, 254); + will_return(__wrap_dm_task_set_major, 1); + expect_value(__wrap_dm_task_set_minor, val, 123); + will_return(__wrap_dm_task_set_minor, 0); + rc = libmp_mapinfo(DM_MAP_BY_DEVT, + (mapid_t) { .devt = devt }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_good_info(void **state) +{ + int rc; + struct dm_info dmi; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .dmi = &dmi }); + assert_int_equal(rc, DMP_OK); + assert_memory_equal(&dmi, &MPATH_DMI_01, sizeof(dmi)); +} + +static void test_mapinfo_good_by_uuid_info(void **state) +{ + int rc; + struct dm_info dmi; + + expect_value(__wrap_dm_task_create, task, DM_DEVICE_INFO); + will_return(__wrap_dm_task_create, 1); + expect_value(__wrap_dm_task_set_uuid, uuid, "foo"); + will_return(__wrap_dm_task_set_uuid, 1); + will_return(__wrap_dm_task_run, 1); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + rc = libmp_mapinfo(DM_MAP_BY_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .dmi = &dmi }); + assert_int_equal(rc, DMP_OK); + assert_memory_equal(&dmi, &MPATH_DMI_01, sizeof(dmi)); +} + +static void test_mapinfo_good_by_dev_info(void **state) +{ + int rc; + struct dm_info dmi; + + expect_value(__wrap_dm_task_create, task, DM_DEVICE_INFO); + will_return(__wrap_dm_task_create, 1); + expect_value(__wrap_dm_task_set_major, val, 254); + will_return(__wrap_dm_task_set_major, 1); + expect_value(__wrap_dm_task_set_minor, val, 123); + will_return(__wrap_dm_task_set_minor, 1); + will_return(__wrap_dm_task_run, 1); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + rc = libmp_mapinfo(DM_MAP_BY_DEV, + (mapid_t) { ._u = { 254, 123 } }, + (mapinfo_t) { .dmi = &dmi }); + assert_int_equal(rc, DMP_OK); + assert_memory_equal(&dmi, &MPATH_DMI_01, sizeof(dmi)); +} + +static void test_mapinfo_good_by_devt_info(void **state) +{ + dev_t devt = makedev(254, 123); + int rc; + struct dm_info dmi; + + expect_value(__wrap_dm_task_create, task, DM_DEVICE_INFO); + will_return(__wrap_dm_task_create, 1); + expect_value(__wrap_dm_task_set_major, val, 254); + will_return(__wrap_dm_task_set_major, 1); + expect_value(__wrap_dm_task_set_minor, val, 123); + will_return(__wrap_dm_task_set_minor, 1); + will_return(__wrap_dm_task_run, 1); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + rc = libmp_mapinfo(DM_MAP_BY_DEVT, + (mapid_t) { .devt = devt }, + (mapinfo_t) { .dmi = &dmi }); + assert_int_equal(rc, DMP_OK); + assert_memory_equal(&dmi, &MPATH_DMI_01, sizeof(dmi)); +} + +static void test_mapinfo_bad_name(void **state) +{ + int rc; + char name[WWID_SIZE] = { 0 }; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + will_return(__wrap_dm_task_get_name, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = name }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_good_name(void **state) +{ + int rc; + char name[WWID_SIZE] = { 0 }; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + will_return(__wrap_dm_task_get_name, MPATH_NAME_01); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = name }); + assert_int_equal(rc, DMP_OK); + assert_true(!strcmp(name, MPATH_NAME_01)); +} + +static void test_mapinfo_bad_uuid(void **state) +{ + int rc; + char uuid[DM_UUID_LEN] = { 0 }; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + will_return(__wrap_dm_task_get_uuid, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .uuid = uuid }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_good_uuid(void **state) +{ + int rc; + char uuid[DM_UUID_LEN] = { 0 }; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .uuid = uuid }); + assert_int_equal(rc, DMP_OK); + assert_true(!strcmp(uuid, MPATH_UUID_01)); +} + +/* If size is set, libmp_mapinfo needs to do a DM_DEVICE_STATUS ioctl */ +static void test_mapinfo_good_size(void **state) +{ + int rc; + unsigned long long size; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, NULL, MPATH_TARGET_01, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .size = &size }); + assert_int_equal(rc, DMP_OK); + assert_int_equal(size, 12345); +} + +static void test_mapinfo_bad_next_target_01(void **state) +{ + int rc; + unsigned long long size; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + /* multiple targets */ + mock_dm_get_next_target(12345, NULL, MPATH_STATUS_01, (void *)1); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .size = &size }); + assert_int_equal(rc, DMP_NOT_FOUND); +} + +static void test_mapinfo_bad_next_target_02(void **state) +{ + int rc; + unsigned long long size; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + /* no targets */ + mock_dm_get_next_target(12345, NULL, NULL, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .size = &size }); + assert_int_equal(rc, DMP_NOT_FOUND); +} + +/* libmp_mapinfo needs to do a DM_DEVICE_STATUS ioctl */ +static void test_mapinfo_bad_target_type_01(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, "linear", MPATH_STATUS_01, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NO_MATCH); +} + +static void test_mapinfo_bad_target_type_02(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_PART_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NO_MATCH); +} + +static void test_mapinfo_bad_target_type_03(void **state) +{ + int rc; + struct dm_info dmi = { .suspended = 0 }; + char name[WWID_SIZE] = { 0 }; + char uuid[DM_UUID_LEN] = { 0 }; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_PART, MPATH_STATUS_01, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .dmi = &dmi, .name = name, .uuid = uuid }); + assert_int_equal(rc, DMP_NO_MATCH); + /* make sure memory content is not changed */ + assert_memory_equal(&dmi, &((struct dm_info) { .exists = 0 }), sizeof(dmi)); + assert_memory_equal(&name, &((char[WWID_SIZE]) { 0 }), WWID_SIZE); + assert_memory_equal(&uuid, &((char[DM_UUID_LEN]) { 0 }), DM_UUID_LEN); +} + +static void test_mapinfo_bad_target_type_04(void **state) +{ + int rc; + char __attribute__((cleanup(cleanup_charp))) *status = NULL; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_PART_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .status = &status }); + assert_int_equal(rc, DMP_NO_MATCH); + assert_null(status); +} + +static void test_mapinfo_bad_target_type_05(void **state) +{ + int rc; + char __attribute__((cleanup(cleanup_charp))) *target = NULL; + + mock_mapinfo_name_1(DM_DEVICE_TABLE, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_PART_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .target = &target }); + assert_int_equal(rc, DMP_NO_MATCH); + assert_null(target); +} + +static void test_mapinfo_good_target_type_01(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_OK); +} + +static void test_mapinfo_good_target_type_02(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_PART, MPATH_STATUS_01, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_PART_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_OK); +} + +static void test_mapinfo_good_target_type_03(void **state) +{ + int rc; + struct dm_info dmi = { .suspended = 0 }; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .dmi = &dmi }); + assert_int_equal(rc, DMP_OK); + assert_memory_equal(&dmi, &MPATH_DMI_01, sizeof(dmi)); +} + +/* test for returning multiple parameters */ +static void test_mapinfo_good_target_type_04(void **state) +{ + int rc; + struct dm_info dmi = { .suspended = 0 }; + char name[WWID_SIZE] = { 0 }; + char uuid[DM_UUID_LEN] = { 0 }; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL); + will_return(__wrap_dm_task_get_name, MPATH_NAME_01); + will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .dmi = &dmi, .name = name, .uuid = uuid }); + assert_int_equal(rc, DMP_OK); + assert_memory_equal(&dmi, &MPATH_DMI_01, sizeof(dmi)); + assert_true(!strcmp(name, MPATH_NAME_01)); + assert_true(!strcmp(uuid, MPATH_UUID_01)); +} + +static void test_mapinfo_good_status_01(void **state) +{ + int rc; + char __attribute__((cleanup(cleanup_charp))) *status = NULL; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL); + will_return(__wrap_strdup, 1); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .status = &status }); + assert_int_equal(rc, DMP_OK); + assert_non_null(status); + assert_true(!strcmp(status, MPATH_STATUS_01)); +} + +static void test_mapinfo_bad_strdup_01(void **state) +{ + int rc; + char __attribute__((cleanup(cleanup_charp))) *status = NULL; + char name[WWID_SIZE] = { 0 }; + char uuid[DM_UUID_LEN] = { 0 }; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL); + will_return(__wrap_dm_task_get_name, MPATH_NAME_01); + will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01); + will_return(__wrap_strdup, 0); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .status = &status, .uuid = uuid, .name = name }); + assert_int_equal(rc, DMP_ERR); + assert_null(status); + assert_memory_equal(&name, &((char[WWID_SIZE]) { 0 }), WWID_SIZE); + assert_memory_equal(&uuid, &((char[DM_UUID_LEN]) { 0 }), DM_UUID_LEN); + +} + +static void test_mapinfo_bad_get_name_01(void **state) +{ + int rc; + char __attribute__((cleanup(cleanup_charp))) *status = NULL; + char name[WWID_SIZE] = { 0 }; + char uuid[DM_UUID_LEN] = { 0 }; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL); + will_return(__wrap_dm_task_get_name, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .status = &status, .uuid = uuid, .name = name }); + assert_int_equal(rc, DMP_ERR); + assert_null(status); + assert_memory_equal(&name, &((char[WWID_SIZE]) { 0 }), WWID_SIZE); + assert_memory_equal(&uuid, &((char[DM_UUID_LEN]) { 0 }), DM_UUID_LEN); + +} + +static void test_mapinfo_bad_get_uuid_01(void **state) +{ + int rc; + char __attribute__((cleanup(cleanup_charp))) *status = NULL; + char name[WWID_SIZE] = { 0 }; + char uuid[DM_UUID_LEN] = { 0 }; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL); + will_return(__wrap_dm_task_get_name, MPATH_NAME_01); + will_return(__wrap_dm_task_get_uuid, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .status = &status, .uuid = uuid, .name = name }); + assert_int_equal(rc, DMP_ERR); + assert_null(status); + assert_memory_equal(&name, &((char[WWID_SIZE]) { 0 }), WWID_SIZE); + assert_memory_equal(&uuid, &((char[DM_UUID_LEN]) { 0 }), DM_UUID_LEN); + +} + +static void test_mapinfo_bad_task_run_11(void **state) +{ + int rc; + char *params = NULL, *status = NULL; + + mock_mapinfo_name_1(DM_DEVICE_TABLE, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, NULL, MPATH_TARGET_01, NULL); + will_return(__wrap_strdup, 1); + /* error in 2nd dm_task_run */ + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 0, EINVAL); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .target = ¶ms, .status = &status }); + assert_int_equal(rc, DMP_ERR); + assert_ptr_equal(params, NULL); + assert_ptr_equal(status, NULL); +} + +static void test_mapinfo_bad_get_name_02(void **state) +{ + int rc; + char *target = NULL, *status = NULL; + char name[WWID_SIZE] = { 0 }; + char uuid[DM_UUID_LEN] = { 0 }; + struct dm_info dmi = { .suspended = 0 }; + + mock_mapinfo_name_1(DM_DEVICE_TABLE, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_TARGET_01, NULL); + will_return(__wrap_strdup, 1); + /* 2nd ioctl */ + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL); + will_return(__wrap_dm_task_get_name, NULL); + + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { + .target = &target, .status = &status, + .uuid = uuid, .name = name, .dmi = &dmi }); + assert_int_equal(rc, DMP_ERR); + assert_null(status); + assert_null(target); + assert_memory_equal(&dmi, &((struct dm_info) { .suspended = 0 }), sizeof(dmi)); + assert_memory_equal(&name, &((char[WWID_SIZE]) { 0 }), WWID_SIZE); + assert_memory_equal(&uuid, &((char[DM_UUID_LEN]) { 0 }), DM_UUID_LEN); +} + +static void test_mapinfo_bad_get_uuid_02(void **state) +{ + int rc; + char *target = NULL, *status = NULL; + char name[WWID_SIZE] = { 0 }; + char uuid[DM_UUID_LEN] = { 0 }; + struct dm_info dmi = { .suspended = 0 }; + + mock_mapinfo_name_1(DM_DEVICE_TABLE, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_TARGET_01, NULL); + will_return(__wrap_strdup, 1); + /* 2nd ioctl */ + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL); + will_return(__wrap_dm_task_get_name, MPATH_NAME_01); + will_return(__wrap_dm_task_get_uuid, NULL); + + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { + .target = &target, .status = &status, + .uuid = uuid, .name = name, .dmi = &dmi }); + assert_int_equal(rc, DMP_ERR); + assert_null(status); + assert_null(target); + assert_memory_equal(&dmi, &((struct dm_info) { .suspended = 0 }), sizeof(dmi)); + assert_memory_equal(&name, &((char[WWID_SIZE]) { 0 }), WWID_SIZE); + assert_memory_equal(&uuid, &((char[DM_UUID_LEN]) { 0 }), DM_UUID_LEN); +} + +static void test_mapinfo_bad_strdup_02(void **state) +{ + int rc; + char *target = NULL, *status = NULL; + char name[WWID_SIZE] = { 0 }; + char uuid[DM_UUID_LEN] = { 0 }; + struct dm_info dmi = { .suspended = 0 }; + + mock_mapinfo_name_1(DM_DEVICE_TABLE, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_TARGET_01, NULL); + will_return(__wrap_strdup, 1); + /* 2nd ioctl */ + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL); + will_return(__wrap_dm_task_get_name, MPATH_NAME_01); + will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01); + will_return(__wrap_strdup, 0); + + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { + .target = &target, .status = &status, + .uuid = uuid, .name = name, .dmi = &dmi }); + assert_int_equal(rc, DMP_ERR); + assert_null(status); + assert_null(target); + assert_memory_equal(&dmi, &((struct dm_info) { .suspended = 0 }), sizeof(dmi)); + assert_memory_equal(&name, &((char[WWID_SIZE]) { 0 }), WWID_SIZE); + assert_memory_equal(&uuid, &((char[DM_UUID_LEN]) { 0 }), DM_UUID_LEN); +} + +static void test_mapinfo_bad_strdup_03(void **state) +{ + int rc; + char *target = NULL, *status = NULL; + char name[WWID_SIZE] = { 0 }; + char uuid[DM_UUID_LEN] = { 0 }; + struct dm_info dmi = { .suspended = 0 }; + + mock_mapinfo_name_1(DM_DEVICE_TABLE, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_TARGET_01, NULL); + will_return(__wrap_strdup, 0); + /* No 2nd ioctl, as there was an error in the 1st */ + + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { + .target = &target, .status = &status, + .uuid = uuid, .name = name, .dmi = &dmi }); + assert_int_equal(rc, DMP_ERR); + assert_null(status); + assert_null(target); + assert_memory_equal(&dmi, &((struct dm_info) { .suspended = 0 }), sizeof(dmi)); + assert_memory_equal(&name, &((char[WWID_SIZE]) { 0 }), WWID_SIZE); + assert_memory_equal(&uuid, &((char[DM_UUID_LEN]) { 0 }), DM_UUID_LEN); +} + +static void test_mapinfo_good_all_01(void **state) +{ + int rc; + char __attribute__((cleanup(cleanup_charp))) *target = NULL; + char __attribute__((cleanup(cleanup_charp))) *status = NULL; + char name[WWID_SIZE] = { 0 }; + char uuid[DM_UUID_LEN] = { 0 }; + struct dm_info dmi = { .suspended = 0 }; + unsigned long long size; + + mock_mapinfo_name_1(DM_DEVICE_TABLE, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_TARGET_01, NULL); + will_return(__wrap_strdup, 1); + /* 2nd ioctl */ + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL); + will_return(__wrap_dm_task_get_name, MPATH_NAME_01); + will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01); + will_return(__wrap_strdup, 1); + + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { + .target = &target, .status = &status, + .uuid = uuid, .name = name, + .dmi = &dmi, .size = &size }); + assert_int_equal(rc, DMP_OK); + assert_non_null(status); + assert_non_null(target); + assert_int_equal(size, 12345); + assert_memory_equal(&dmi, &MPATH_DMI_01, sizeof(dmi)); + assert_true(!strcmp(target, MPATH_TARGET_01)); + assert_true(!strcmp(status, MPATH_STATUS_01)); + assert_true(!strcmp(name, MPATH_NAME_01)); + assert_true(!strcmp(uuid, MPATH_UUID_01)); +} + +static int test_mapinfo(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_mapinfo_bad_task_create_01), + cmocka_unit_test(test_mapinfo_bad_mapid), + cmocka_unit_test(test_mapinfo_bad_set_name), + cmocka_unit_test(test_mapinfo_bad_task_run_01), + cmocka_unit_test(test_mapinfo_bad_task_run_02), + cmocka_unit_test(test_mapinfo_bad_task_run_03), + cmocka_unit_test(test_mapinfo_bad_task_run_04), + cmocka_unit_test(test_mapinfo_bad_task_run_05), + cmocka_unit_test(test_mapinfo_bad_task_run_06), + cmocka_unit_test(test_mapinfo_bad_task_run_07), + cmocka_unit_test(test_mapinfo_bad_task_run_08), + cmocka_unit_test(test_mapinfo_bad_task_run_09), + cmocka_unit_test(test_mapinfo_bad_task_run_10), + cmocka_unit_test(test_mapinfo_bad_task_run_11), + cmocka_unit_test(test_mapinfo_bad_get_info_01), + cmocka_unit_test(test_mapinfo_bad_get_info_02), + cmocka_unit_test(test_mapinfo_bad_get_info_03), + cmocka_unit_test(test_mapinfo_bad_get_info_04), + cmocka_unit_test(test_mapinfo_good_exists), + cmocka_unit_test(test_mapinfo_bad_set_uuid), + cmocka_unit_test(test_mapinfo_bad_set_dev_01), + cmocka_unit_test(test_mapinfo_bad_set_dev_02), + cmocka_unit_test(test_mapinfo_bad_set_dev_03), + cmocka_unit_test(test_mapinfo_bad_set_dev_04), + cmocka_unit_test(test_mapinfo_good_info), + cmocka_unit_test(test_mapinfo_good_by_uuid_info), + cmocka_unit_test(test_mapinfo_good_by_dev_info), + cmocka_unit_test(test_mapinfo_good_by_devt_info), + cmocka_unit_test(test_mapinfo_bad_name), + cmocka_unit_test(test_mapinfo_good_name), + cmocka_unit_test(test_mapinfo_bad_uuid), + cmocka_unit_test(test_mapinfo_good_uuid), + cmocka_unit_test(test_mapinfo_good_size), + cmocka_unit_test(test_mapinfo_bad_next_target_01), + cmocka_unit_test(test_mapinfo_bad_next_target_02), + cmocka_unit_test(test_mapinfo_bad_target_type_01), + cmocka_unit_test(test_mapinfo_bad_target_type_02), + cmocka_unit_test(test_mapinfo_bad_target_type_03), + cmocka_unit_test(test_mapinfo_bad_target_type_04), + cmocka_unit_test(test_mapinfo_bad_target_type_05), + cmocka_unit_test(test_mapinfo_good_target_type_01), + cmocka_unit_test(test_mapinfo_good_target_type_02), + cmocka_unit_test(test_mapinfo_good_target_type_03), + cmocka_unit_test(test_mapinfo_good_target_type_04), + cmocka_unit_test(test_mapinfo_good_status_01), + cmocka_unit_test(test_mapinfo_bad_get_name_01), + cmocka_unit_test(test_mapinfo_bad_get_uuid_01), + cmocka_unit_test(test_mapinfo_bad_strdup_01), + cmocka_unit_test(test_mapinfo_bad_get_name_02), + cmocka_unit_test(test_mapinfo_bad_get_uuid_02), + cmocka_unit_test(test_mapinfo_bad_strdup_02), + cmocka_unit_test(test_mapinfo_bad_strdup_03), + cmocka_unit_test(test_mapinfo_good_all_01), + }; + return cmocka_run_group_tests(tests, NULL, NULL); +} + +int main(void) +{ + int ret = 0; + + init_test_verbosity(4); + skip_libmp_dm_init(); + ret += test_mapinfo(); + return ret; +} From 5578f6ba69d8182fdb3f31e8daf71b216f2b58ee Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Sat, 29 Jun 2024 13:30:14 +0200 Subject: [PATCH 029/145] libmultipath: implement dm_get_info() and dm_map_present() with new API Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 54 ++++--------------------------- libmultipath/devmapper.h | 16 +++++++-- libmultipath/libmultipath.version | 2 -- multipathd/main.c | 4 +-- 4 files changed, 23 insertions(+), 53 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index f90a8df62..f38fdaf13 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -796,45 +796,6 @@ int libmp_mapinfo(int flags, mapid_t id, mapinfo_t info) libmp_map_identifier(flags, id, idbuf)); } -int -dm_get_info(const char *name, struct dm_info *info) -{ - int r = -1; - struct dm_task *dmt; - - if (!name || !info) - return r; - - if (!(dmt = libmp_dm_task_create(DM_DEVICE_INFO))) - return r; - - if (!dm_task_set_name(dmt, name)) - goto out; - - if (!libmp_dm_task_run(dmt)) { - dm_log_error(3, DM_DEVICE_INFO, dmt); - goto out; - } - - if (!dm_task_get_info(dmt, info)) - goto out; - - if (!info->exists) - goto out; - - r = 0; -out: - dm_task_destroy(dmt); - return r; -} - -int dm_map_present(const char * str) -{ - struct dm_info info; - - return (dm_get_info(str, &info) == 0); -} - int dm_get_map(const char *name, unsigned long long *size, char **outparams) { struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; @@ -1133,15 +1094,14 @@ dm_map_present_by_uuid(const char *uuid) return r; } -static int -dm_dev_t (const char * mapname, char * dev_t, int len) +static int dm_dev_t (const char *mapname, char *dev_t, int len) { struct dm_info info; - if (dm_get_info(mapname, &info) != 0) + if (dm_get_info(mapname, &info) != DMP_OK) return 1; - if (snprintf(dev_t, len, "%i:%i", info.major, info.minor) > len) + if (safe_snprintf(dev_t, len, "%i:%i", info.major, info.minor)) return 1; return 0; @@ -1182,7 +1142,7 @@ dm_get_major_minor(const char *name, int *major, int *minor) { struct dm_info info; - if (dm_get_info(name, &info) != 0) + if (dm_get_info(name, &info) != DMP_OK) return -1; *major = info.major; @@ -1528,7 +1488,7 @@ dm_geteventnr (const char *name) { struct dm_info info; - if (dm_get_info(name, &info) != 0) + if (dm_get_info(name, &info) != DMP_OK) return -1; return info.event_nr; @@ -1539,7 +1499,7 @@ dm_is_suspended(const char *name) { struct dm_info info; - if (dm_get_info(name, &info) != 0) + if (dm_get_info(name, &info) != DMP_OK) return -1; return info.suspended; @@ -1690,7 +1650,7 @@ dm_get_deferred_remove (const char * mapname) { struct dm_info info; - if (dm_get_info(mapname, &info) != 0) + if (dm_get_info(mapname, &info) != DMP_OK) return -1; return info.deferred_remove; diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 974e2ac99..d0a5abd50 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -104,6 +104,20 @@ typedef struct libmp_map_info { */ int libmp_mapinfo(int flags, mapid_t id, mapinfo_t info); +static inline int dm_get_info(const char *mapname, struct dm_info *info) +{ + return libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = mapname }, + (mapinfo_t) { .dmi = info }); +} + +static inline int dm_map_present(const char *mapname) +{ + return libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = mapname }, + (mapinfo_t) { .name = NULL }) == DMP_OK; +} + int dm_prereq(unsigned int *v); void skip_libmp_dm_init(void); void libmp_dm_exit(void); @@ -113,7 +127,6 @@ int dm_simplecmd_flush (int task, const char *name, uint16_t udev_flags); int dm_simplecmd_noflush (int task, const char *name, uint16_t udev_flags); int dm_addmap_create (struct multipath *mpp, char *params); int dm_addmap_reload (struct multipath *mpp, char *params, int flush); -int dm_map_present (const char *name); int dm_map_present_by_uuid(const char *uuid); int dm_get_map(const char *name, unsigned long long *size, char **outparams); int dm_get_status(const char *name, char **outstatus); @@ -164,7 +177,6 @@ int dm_get_major_minor (const char *name, int *major, int *minor); char * dm_mapname(int major, int minor); int dm_get_uuid(const char *name, char *uuid, int uuid_len); bool has_dm_info(const struct multipath *mpp); -int dm_get_info (const char * mapname, struct dm_info *dmi); int dm_rename (const char * old, char * new, char * delim, int skip_kpartx); int dm_reassign(const char * mapname); int dm_reassign_table(const char *name, char *old, char *new); diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index 48c2b673e..7a5034910 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -78,14 +78,12 @@ global: dm_flush_map_nopaths; dm_flush_maps; dm_geteventnr; - dm_get_info; dm_get_major_minor; dm_get_maps; dm_get_multipath; dm_get_uuid; dm_is_mpath; dm_mapname; - dm_map_present; dm_prereq; dm_queue_if_no_path; dm_reassign; diff --git a/multipathd/main.c b/multipathd/main.c index 132bb2e97..394ca7dd5 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -502,7 +502,7 @@ remove_maps_and_stop_waiters(struct vectors *vecs) int refresh_multipath(struct vectors *vecs, struct multipath *mpp) { - if (dm_get_info(mpp->alias, &mpp->dmi)) { + if (dm_get_info(mpp->alias, &mpp->dmi) != DMP_OK) { /* Error accessing table */ condlog(2, "%s: cannot access table", mpp->alias); goto out; @@ -722,7 +722,7 @@ add_map_without_path (struct vectors *vecs, const char *alias) mpp->alias = strdup(alias); - if (dm_get_info(mpp->alias, &mpp->dmi)) { + if (dm_get_info(mpp->alias, &mpp->dmi) != DMP_OK) { condlog(3, "%s: cannot access table", mpp->alias); goto out; } From 38f0e10764a615923d2a6fbb36c67644795b3525 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 28 Jun 2024 12:29:29 +0200 Subject: [PATCH 030/145] libmultipath: remove dm_get_prefixed_uuid() ... and replace it by calls to the new API. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 53 +++++++++------------------------------- 1 file changed, 11 insertions(+), 42 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index f38fdaf13..1b7ea49ef 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -796,6 +796,13 @@ int libmp_mapinfo(int flags, mapid_t id, mapinfo_t info) libmp_map_identifier(flags, id, idbuf)); } +static int dm_get_dm_uuid(const char *mapname, char uuid[DM_UUID_LEN]) +{ + return libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = mapname }, + (mapinfo_t) { .uuid = uuid }); +} + int dm_get_map(const char *name, unsigned long long *size, char **outparams) { struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; @@ -835,48 +842,11 @@ int dm_get_map(const char *name, unsigned long long *size, char **outparams) } } -static int -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; - - if (!libmp_dm_task_run(dmt)) { - dm_log_error(3, DM_DEVICE_INFO, dmt); - 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); - - r = 0; -uuidout: - dm_task_destroy(dmt); - return r; -} - int dm_get_uuid(const char *name, char *uuid, int uuid_len) { char tmp[DM_UUID_LEN]; - if (dm_get_prefixed_uuid(name, tmp, sizeof(tmp))) + if (dm_get_dm_uuid(name, tmp) != DMP_OK) return 1; if (!strncmp(tmp, UUID_PREFIX, UUID_PREFIX_LEN)) @@ -887,16 +857,15 @@ int dm_get_uuid(const char *name, char *uuid, int uuid_len) return 0; } -static int -is_mpath_part(const char *part_name, const char *map_name) +static int is_mpath_part(const char *part_name, const char *map_name) { char *p; char part_uuid[DM_UUID_LEN], map_uuid[DM_UUID_LEN]; - if (dm_get_prefixed_uuid(part_name, part_uuid, sizeof(part_uuid))) + if (dm_get_dm_uuid(part_name, part_uuid) != DMP_OK) return 0; - if (dm_get_prefixed_uuid(map_name, map_uuid, sizeof(map_uuid))) + if (dm_get_dm_uuid(map_name, map_uuid) != DMP_OK) return 0; if (strncmp(part_uuid, "part", 4) != 0) From cd8cf078c10746b4004033ba48b30c4b68af2fec Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Mon, 1 Jul 2024 17:24:23 +0200 Subject: [PATCH 031/145] libmultipath: is_mpath_part(): improve parsing Use sscanf to make the parsing of the UUID more robust. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 1b7ea49ef..289b4bd29 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -859,23 +859,20 @@ int dm_get_uuid(const char *name, char *uuid, int uuid_len) static int is_mpath_part(const char *part_name, const char *map_name) { - char *p; - char part_uuid[DM_UUID_LEN], map_uuid[DM_UUID_LEN]; + char part_uuid[DM_UUID_LEN], map_uuid[DM_UUID_LEN], c; + int np, nc; if (dm_get_dm_uuid(part_name, part_uuid) != DMP_OK) return 0; - if (dm_get_dm_uuid(map_name, map_uuid) != DMP_OK) + if (2 != sscanf(part_uuid, "part%d-%n" UUID_PREFIX "%c", &np, &nc, &c) + || np <= 0) return 0; - if (strncmp(part_uuid, "part", 4) != 0) + if (dm_get_dm_uuid(map_name, map_uuid) != DMP_OK) return 0; - p = strstr(part_uuid, UUID_PREFIX); - if (p && !strcmp(p, map_uuid)) - return 1; - - return 0; + return !strcmp(part_uuid + nc, map_uuid); } int dm_get_status(const char *name, char **outstatus) From b5dae695714cbc40371dfe220d6a124e8cd6cadb Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Mon, 1 Jul 2024 17:36:56 +0200 Subject: [PATCH 032/145] libmultipath: rename dm_get_uuid() -> dm_get_wwid() ... to make the distinction between WWID (multipath) and UUID (device mapper) a little more obvious. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/alias.c | 2 +- libmultipath/configure.c | 4 ++-- libmultipath/devmapper.c | 4 ++-- libmultipath/devmapper.h | 2 +- libmultipath/libmultipath.version | 2 +- libmultipath/wwids.c | 2 +- multipathd/main.c | 2 +- tests/alias.c | 30 +++++++++++++++--------------- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index a54616c70..10e58a768 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -410,7 +410,7 @@ static bool alias_already_taken(const char *alias, const char *map_wwid) char wwid[WWID_SIZE]; /* If the map doesn't exist, it's fine */ - if (dm_get_uuid(alias, wwid, sizeof(wwid)) != 0) + if (dm_get_wwid(alias, wwid, sizeof(wwid)) != 0) return false; /* If both the name and the wwid match, it's fine.*/ diff --git a/libmultipath/configure.c b/libmultipath/configure.c index b5c701fad..666d4e804 100644 --- a/libmultipath/configure.c +++ b/libmultipath/configure.c @@ -846,7 +846,7 @@ int domap(struct multipath *mpp, char *params, int is_daemon) if (mpp->action == ACT_CREATE && dm_map_present(mpp->alias)) { char wwid[WWID_SIZE]; - if (dm_get_uuid(mpp->alias, wwid, sizeof(wwid)) == 0) { + 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); @@ -1320,7 +1320,7 @@ static int _get_refwwid(enum mpath_cmds cmd, const char *dev, break; case DEV_DEVMAP: - if (((dm_get_uuid(dev, tmpwwid, WWID_SIZE)) == 0) + if (((dm_get_wwid(dev, tmpwwid, WWID_SIZE)) == 0) && (strlen(tmpwwid))) refwwid = tmpwwid; diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 289b4bd29..de59ee6ac 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -842,7 +842,7 @@ int dm_get_map(const char *name, unsigned long long *size, char **outparams) } } -int dm_get_uuid(const char *name, char *uuid, int uuid_len) +int dm_get_wwid(const char *name, char *uuid, int uuid_len) { char tmp[DM_UUID_LEN]; @@ -1390,7 +1390,7 @@ struct multipath *dm_get_multipath(const char *name) if (dm_get_map(name, &mpp->size, NULL) != DMP_OK) goto out; - if (dm_get_uuid(name, mpp->wwid, WWID_SIZE) != 0) + if (dm_get_wwid(name, mpp->wwid, WWID_SIZE) != 0) condlog(2, "%s: failed to get uuid for %s", __func__, name); if (dm_get_info(name, &mpp->dmi) != 0) condlog(2, "%s: failed to get info for %s", __func__, name); diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index d0a5abd50..6e4ee2ab0 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -175,7 +175,7 @@ int dm_geteventnr (const char *name); int dm_is_suspended(const char *name); int dm_get_major_minor (const char *name, int *major, int *minor); char * dm_mapname(int major, int minor); -int dm_get_uuid(const char *name, char *uuid, int uuid_len); +int dm_get_wwid(const char *name, char *uuid, int uuid_len); bool has_dm_info(const struct multipath *mpp); int dm_rename (const char * old, char * new, char * delim, int skip_kpartx); int dm_reassign(const char * mapname); diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index 7a5034910..7d3ff638a 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -81,7 +81,7 @@ global: dm_get_major_minor; dm_get_maps; dm_get_multipath; - dm_get_uuid; + dm_get_wwid; dm_is_mpath; dm_mapname; dm_prereq; diff --git a/libmultipath/wwids.c b/libmultipath/wwids.c index 591cd09b5..7a4cb7476 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_uuid(mp->alias, tmp_wwid, WWID_SIZE) == 0 && + dm_get_wwid(mp->alias, tmp_wwid, WWID_SIZE) == 0 && !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 394ca7dd5..442a154d2 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -727,7 +727,7 @@ add_map_without_path (struct vectors *vecs, const char *alias) goto out; } if (!strlen(mpp->wwid)) - dm_get_uuid(mpp->alias, mpp->wwid, WWID_SIZE); + dm_get_wwid(mpp->alias, mpp->wwid, WWID_SIZE); 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 95ce994c5..1f786561f 100644 --- a/tests/alias.c +++ b/tests/alias.c @@ -76,7 +76,7 @@ int WRAP_FUNC(mkstemp)(char *template) return 10; } -int __wrap_dm_get_uuid(const char *name, char *uuid, int uuid_len) +int __wrap_dm_get_wwid(const char *name, char *uuid, int uuid_len) { int ret; @@ -436,17 +436,17 @@ static int test_scan_devname(void) static void mock_unused_alias(const char *alias) { - 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_string(__wrap_dm_get_wwid, name, alias); + expect_value(__wrap_dm_get_wwid, uuid_len, WWID_SIZE); + will_return(__wrap_dm_get_wwid, 1); } static void mock_self_alias(const char *alias, const char *wwid) { - 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); - will_return(__wrap_dm_get_uuid, 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, wwid); } #define USED_STR(alias_str, wwid_str) wwid_str ": alias '" alias_str "' already taken, reselecting alias\n" @@ -469,17 +469,17 @@ static void mock_self_alias(const char *alias, const char *wwid) #define mock_failed_alias(alias, wwid) \ do { \ - 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_string(__wrap_dm_get_wwid, name, alias); \ + expect_value(__wrap_dm_get_wwid, uuid_len, WWID_SIZE); \ + will_return(__wrap_dm_get_wwid, 1); \ } while (0) #define mock_used_alias(alias, wwid) \ do { \ - 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); \ - will_return(__wrap_dm_get_uuid, "WWID_USED"); \ + 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, "WWID_USED"); \ expect_condlog(3, USED_STR(alias, wwid)); \ } while(0) From a46ef2cf0e0d2214ebc7bebf7595b07704a0aef8 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Mon, 1 Jul 2024 17:57:58 +0200 Subject: [PATCH 033/145] libmultipath: improve dm_get_wwid() return value logic 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. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- 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 10e58a768..c4eb5d8d3 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 666d4e804..2fdaca85a 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 de59ee6ac..06ec902d4 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -842,19 +842,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) @@ -1390,8 +1400,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 7a4cb7476..aac18c047 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 442a154d2..1e7a6aca4 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 1f786561f..a95b30817 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) From 56898358394f4bd4593018a709b62cfa8fe15688 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 28 Jun 2024 12:30:27 +0200 Subject: [PATCH 034/145] libmultipath: reimplement dm_map_name() with new API Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 06ec902d4..5f09a25af 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1483,37 +1483,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 From 39a12eb2d966923cd29749b70df2b90d0d7da104 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 27 Jun 2024 19:31:44 +0200 Subject: [PATCH 035/145] libmultipath: reimplement dm_map_present_by_uuid() ... and rename it to dm_map_present_by_wwid(). Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 47 ++++++---------------------------------- libmultipath/devmapper.h | 2 +- libmultipath/valid.c | 2 +- tests/valid.c | 10 ++++----- 4 files changed, 14 insertions(+), 47 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 5f09a25af..3b0840c4a 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1025,49 +1025,16 @@ int dm_is_mpath(const char *name) return r; } -/* - * Return - * 1 : map with uuid exists - * 0 : map with uuid doesn't exist - * -1 : error - */ -int -dm_map_present_by_uuid(const char *uuid) +int dm_map_present_by_wwid(const char *wwid) { - struct dm_task *dmt; - struct dm_info info; - char prefixed_uuid[WWID_SIZE + UUID_PREFIX_LEN]; - int r = -1; - - if (!uuid || uuid[0] == '\0') - return 0; - - if (safe_sprintf(prefixed_uuid, UUID_PREFIX "%s", uuid)) - goto out; - - if (!(dmt = libmp_dm_task_create(DM_DEVICE_INFO))) - goto out; - - if (!dm_task_set_uuid(dmt, prefixed_uuid)) - goto out_task; - - if (!libmp_dm_task_run(dmt)) { - dm_log_error(3, DM_DEVICE_INFO, dmt); - goto out_task; - } - - if (!dm_task_get_info(dmt, &info)) - goto out_task; + char tmp[DM_UUID_LEN]; - r = !!info.exists; + if (safe_sprintf(tmp, UUID_PREFIX "%s", wwid)) + return DMP_ERR; -out_task: - dm_task_destroy(dmt); -out: - if (r < 0) - condlog(3, "%s: dm command failed in %s: %s", uuid, - __FUNCTION__, strerror(errno)); - return r; + return libmp_mapinfo(DM_MAP_BY_UUID, + (mapid_t) { .str = tmp }, + (mapinfo_t) { .name = NULL }); } static int dm_dev_t (const char *mapname, char *dev_t, int len) diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 6e4ee2ab0..c6ee8180c 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -127,7 +127,7 @@ int dm_simplecmd_flush (int task, const char *name, uint16_t udev_flags); int dm_simplecmd_noflush (int task, const char *name, uint16_t udev_flags); int dm_addmap_create (struct multipath *mpp, char *params); int dm_addmap_reload (struct multipath *mpp, char *params, int flush); -int dm_map_present_by_uuid(const char *uuid); +int dm_map_present_by_wwid(const char *uuid); int dm_get_map(const char *name, unsigned long long *size, char **outparams); int dm_get_status(const char *name, char **outstatus); diff --git a/libmultipath/valid.c b/libmultipath/valid.c index f2237787d..9267cef9a 100644 --- a/libmultipath/valid.c +++ b/libmultipath/valid.c @@ -360,7 +360,7 @@ is_path_valid(const char *name, struct config *conf, struct path *pp, if (check_wwids_file(pp->wwid, 0) == 0) return PATH_IS_VALID_NO_CHECK; - if (dm_map_present_by_uuid(pp->wwid) == 1) + if (dm_map_present_by_wwid(pp->wwid) == DMP_OK) return PATH_IS_VALID; /* all these act like FIND_MULTIPATHS_STRICT for finding if a diff --git a/tests/valid.c b/tests/valid.c index 18a5a7bf8..a93bbe508 100644 --- a/tests/valid.c +++ b/tests/valid.c @@ -189,7 +189,7 @@ int __wrap_check_wwids_file(char *wwid, int write_wwid) return -1; } -int __wrap_dm_map_present_by_uuid(const char *uuid) +int __wrap_dm_map_present_by_wwid(const char *uuid) { int ret = mock_type(int); assert_string_equal(uuid, mock_ptr_type(char *)); @@ -271,8 +271,8 @@ static void setup_passing(char *name, char *wwid, unsigned int check_multipathd, will_return(__wrap_check_wwids_file, wwid); if (stage == STAGE_CHECK_WWIDS) return; - will_return(__wrap_dm_map_present_by_uuid, 0); - will_return(__wrap_dm_map_present_by_uuid, wwid); + will_return(__wrap_dm_map_present_by_wwid, 0); + will_return(__wrap_dm_map_present_by_wwid, wwid); } static void test_bad_arguments(void **state) @@ -516,8 +516,8 @@ static void test_check_uuid_present(void **state) memset(&pp, 0, sizeof(pp)); conf.find_multipaths = FIND_MULTIPATHS_STRICT; setup_passing(name, wwid, CHECK_MPATHD_RUNNING, STAGE_CHECK_WWIDS); - will_return(__wrap_dm_map_present_by_uuid, 1); - will_return(__wrap_dm_map_present_by_uuid, wwid); + will_return(__wrap_dm_map_present_by_wwid, 1); + will_return(__wrap_dm_map_present_by_wwid, wwid); assert_int_equal(is_path_valid(name, &conf, &pp, true), PATH_IS_VALID); assert_string_equal(pp.dev, name); From 1fd6cd9bbd4d6da2fb7364db34b025dfc620a466 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 27 Jun 2024 20:35:05 +0200 Subject: [PATCH 036/145] libmultipath: reimplement dm_get_opencount() with new API Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 3b0840c4a..21ae9511d 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1050,34 +1050,14 @@ static int dm_dev_t (const char *mapname, char *dev_t, int len) return 0; } -int -dm_get_opencount (const char * mapname) +int dm_get_opencount (const char *mapname) { - int r = -1; - struct dm_task *dmt; struct dm_info info; - if (!(dmt = libmp_dm_task_create(DM_DEVICE_INFO))) - return 0; - - if (!dm_task_set_name(dmt, mapname)) - goto out; - - if (!libmp_dm_task_run(dmt)) { - dm_log_error(3, DM_DEVICE_INFO, dmt); - goto out; - } - - if (!dm_task_get_info(dmt, &info)) - goto out; - - if (!info.exists) - goto out; + if (dm_get_info(mapname, &info) != DMP_OK) + return -1; - r = info.open_count; -out: - dm_task_destroy(dmt); - return r; + return info.open_count; } int From d24d7189ab5ecf4156e7881c66330e6c52b7691a Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 27 Jun 2024 20:56:29 +0200 Subject: [PATCH 037/145] libmpathpersist: skip redundant dm_map_present() call dm_is_mpath() returns 0 if the map does not exist, the additional dm_map_present() call is not necessary. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathpersist/mpath_persist_int.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmpathpersist/mpath_persist_int.c b/libmpathpersist/mpath_persist_int.c index 6da0401f6..5a5ac3b84 100644 --- a/libmpathpersist/mpath_persist_int.c +++ b/libmpathpersist/mpath_persist_int.c @@ -185,7 +185,7 @@ static int mpath_get_map(vector curmp, vector pathvec, int fd, char **palias, condlog(3, "alias = %s", alias); - if (dm_map_present(alias) && dm_is_mpath(alias) != DM_IS_MPATH_YES) { + if (dm_is_mpath(alias) != DM_IS_MPATH_YES) { condlog(3, "%s: not a multipath device.", alias); goto out; } From 8f7f69dae76f44caa70c08d84f1b027a83c529d2 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Tue, 2 Jul 2024 19:15:20 +0200 Subject: [PATCH 038/145] libmultipath: implement dm_is_mpath() with new API Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 61 +++++++++++----------------------------- 1 file changed, 16 insertions(+), 45 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 21ae9511d..9ed601452 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -977,52 +977,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; - - 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; + char uuid[DM_UUID_LEN]; + int rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = name }, + (mapinfo_t) { .uuid = uuid }); + + 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, - ¶ms) != 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) From e708b67e58f509d6018622d0e0baf01b76ee3964 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Tue, 2 Jul 2024 21:21:11 +0200 Subject: [PATCH 039/145] libmultipath: implement dm_get_multipath() with new API Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 9ed601452..bcc06705d 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1304,7 +1304,8 @@ dm_disablegroup(const char * mapname, int index) struct multipath *dm_get_multipath(const char *name) { - struct multipath *mpp = NULL; + struct multipath __attribute((cleanup(cleanup_multipath))) *mpp = NULL; + char uuid[DM_UUID_LEN]; mpp = alloc_multipath(); if (!mpp) @@ -1313,22 +1314,22 @@ struct multipath *dm_get_multipath(const char *name) mpp->alias = strdup(name); if (!mpp->alias) - goto out; + return NULL; - if (dm_get_map(name, &mpp->size, NULL) != DMP_OK) - goto out; + if (libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = name }, + (mapinfo_t) { + .size = &mpp->size, + .uuid = uuid, + .dmi = &mpp->dmi, + }) != DMP_OK) + return NULL; - 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); + if (strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN)) + return NULL; - return mpp; -out: - free_multipath(mpp, KEEP_PATHS); - return NULL; + strlcpy(mpp->wwid, uuid + UUID_PREFIX_LEN, sizeof(mpp->wwid)); + return steal_ptr(mpp); } int dm_get_maps(vector mp) From 5ab6b2e0e8d1a92ce8d98a5acc8bd9098b531996 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 5 Jul 2024 16:43:21 +0200 Subject: [PATCH 040/145] libmultipath: use libmp_mapinfo() in _dm_flush_map() We can spare one dm ioctl here. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index bcc06705d..44ad031ac 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1076,10 +1076,15 @@ int _dm_flush_map (const char *mapname, int flags, int retries) int r; int queue_if_no_path = 0; int udev_flags = 0; - unsigned long long mapsize; - char *params = NULL; + char *params __attribute__((cleanup(cleanup_charp))) = NULL; + char uuid[DM_UUID_LEN]; - if (dm_is_mpath(mapname) != DM_IS_MPATH_YES) + if (libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = mapname }, + (mapinfo_t) { + .uuid = uuid, + .target = ¶ms }) != DMP_OK + || strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN)) return DM_FLUSH_OK; /* nothing to do */ /* if the device currently has no partitions, do not @@ -1093,7 +1098,6 @@ int _dm_flush_map (const char *mapname, int flags, int retries) return DM_FLUSH_BUSY; if ((flags & DMFL_SUSPEND) && - dm_get_map(mapname, &mapsize, ¶ms) == DMP_OK && strstr(params, "queue_if_no_path")) { if (!_dm_queue_if_no_path(mapname, 0)) queue_if_no_path = 1; @@ -1101,8 +1105,6 @@ int _dm_flush_map (const char *mapname, int flags, int retries) /* Leave queue_if_no_path alone if unset failed */ queue_if_no_path = -1; } - free(params); - params = NULL; if ((r = dm_remove_partmaps(mapname, flags))) return r; From d30092bb90dfb171b50c9b45ce2b1d3f61b29e48 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 5 Jul 2024 17:06:01 +0200 Subject: [PATCH 041/145] libmultipath: add is_mpath_uuid() helper Export it, as it will be used by multipathd and libmpathpersist. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 13 +++++++++---- libmultipath/devmapper.h | 2 ++ libmultipath/libmultipath.version | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 44ad031ac..2d9db3180 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -842,6 +842,11 @@ int dm_get_map(const char *name, unsigned long long *size, char **outparams) } } +bool is_mpath_uuid(const char uuid[DM_UUID_LEN]) +{ + return !strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN); +} + /** * dm_get_wwid(): return WWID for a multipath map * @returns: @@ -859,7 +864,7 @@ int dm_get_wwid(const char *name, char *uuid, int uuid_len) if (rc != DMP_OK) return rc; - if (!strncmp(tmp, UUID_PREFIX, UUID_PREFIX_LEN)) + if (is_mpath_uuid(tmp)) strlcpy(uuid, tmp + UUID_PREFIX_LEN, uuid_len); else return DMP_NO_MATCH; @@ -984,7 +989,7 @@ int dm_is_mpath(const char *name) switch (rc) { case DMP_OK: - if (!strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN)) + if (is_mpath_uuid(uuid)) return DM_IS_MPATH_YES; /* fallthrough */ case DMP_NOT_FOUND: @@ -1084,7 +1089,7 @@ int _dm_flush_map (const char *mapname, int flags, int retries) (mapinfo_t) { .uuid = uuid, .target = ¶ms }) != DMP_OK - || strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN)) + || !is_mpath_uuid(uuid)) return DM_FLUSH_OK; /* nothing to do */ /* if the device currently has no partitions, do not @@ -1327,7 +1332,7 @@ struct multipath *dm_get_multipath(const char *name) }) != DMP_OK) return NULL; - if (strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN)) + if (!is_mpath_uuid(uuid)) return NULL; strlcpy(mpp->wwid, uuid + UUID_PREFIX_LEN, sizeof(mpp->wwid)); diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index c6ee8180c..f550ff2e0 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -136,6 +136,8 @@ enum { DM_IS_MPATH_YES, DM_IS_MPATH_ERR, }; + +bool is_mpath_uuid(const char uuid[DM_UUID_LEN]); int dm_is_mpath(const char *name); enum { diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index 7d3ff638a..5b8f9e024 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -127,6 +127,7 @@ global: init_foreign; init_prio; io_err_stat_handle_pathfail; + is_mpath_uuid; is_path_valid; libmp_dm_task_create; libmp_get_version; From 69e99b4a75c1dd8ed487f4d1167e12b37fe3a2d7 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 5 Jul 2024 17:07:45 +0200 Subject: [PATCH 042/145] libmultipath: add is_mpath_part_uuid() helper Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 2d9db3180..beb63d7a1 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -872,21 +872,15 @@ int dm_get_wwid(const char *name, char *uuid, int uuid_len) return DMP_OK; } -static int is_mpath_part(const char *part_name, const char *map_name) +static bool is_mpath_part_uuid(const char part_uuid[DM_UUID_LEN], + const char map_uuid[DM_UUID_LEN]) { - char part_uuid[DM_UUID_LEN], map_uuid[DM_UUID_LEN], c; + char c; int np, nc; - if (dm_get_dm_uuid(part_name, part_uuid) != DMP_OK) - return 0; - if (2 != sscanf(part_uuid, "part%d-%n" UUID_PREFIX "%c", &np, &nc, &c) || np <= 0) - return 0; - - if (dm_get_dm_uuid(map_name, map_uuid) != DMP_OK) - return 0; - + return false; return !strcmp(part_uuid + nc, map_uuid); } @@ -980,6 +974,20 @@ static int dm_type_match(const char *name, char *type) return DM_TYPE_NOMATCH; } +static bool is_mpath_part(const char *part_name, const char *map_name) +{ + char part_uuid[DM_UUID_LEN], map_uuid[DM_UUID_LEN]; + + if (dm_get_dm_uuid(map_name, map_uuid) != DMP_OK + || !is_mpath_uuid(map_uuid)) + return false; + + if (dm_get_dm_uuid(part_name, part_uuid) != DMP_OK) + return false; + + return is_mpath_part_uuid(part_uuid, map_uuid); +} + int dm_is_mpath(const char *name) { char uuid[DM_UUID_LEN]; From 47158f907be76df846497e84a677bb26897440db Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 5 Jul 2024 17:35:24 +0200 Subject: [PATCH 043/145] libmultipath: add dmp_errstr() helper Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 14 ++++++++++++++ libmultipath/devmapper.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index beb63d7a1..1d412072e 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -79,6 +79,20 @@ static void libmp_udev_wait(unsigned int c) } #endif +const char *dmp_errstr(int rc) +{ + static const char *str[] = { + [DMP_ERR] = "generic error", + [DMP_OK] = "success", + [DMP_NOT_FOUND] = "not found", + [DMP_NO_MATCH] = "target type mismatch", + [__DMP_LAST__] = "**invalid**", + }; + if (rc < 0 || rc > __DMP_LAST__) + rc = __DMP_LAST__; + return str[rc]; +} + int libmp_dm_task_run(struct dm_task *dmt) { int r; diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index f550ff2e0..6854c6b4a 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -34,8 +34,11 @@ enum { DMP_OK, DMP_NOT_FOUND, DMP_NO_MATCH, + __DMP_LAST__, }; +const char* dmp_errstr(int rc); + /** * enum mapinfo_flags: input flags for libmp_mapinfo() */ From a50fd29a76350ee6976e890505f8696e94845151 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 5 Jul 2024 17:21:24 +0200 Subject: [PATCH 044/145] libmultipath: use libmp_mapinfo() in do_foreach_partmaps() Also, simplify the if statement a bit. drop is_mpath_part() and dm_type_match, because do_foreach_partmaps() was the last user of these functions. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 100 ++++++++++----------------------------- 1 file changed, 26 insertions(+), 74 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 1d412072e..37d257881 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -948,60 +948,6 @@ int dm_get_status(const char *name, char **outstatus) return r; } -enum { - DM_TYPE_NOMATCH = 0, - DM_TYPE_MATCH, - /* more than 1 target */ - DM_TYPE_MULTI, - /* empty map */ - DM_TYPE_EMPTY, - DM_TYPE_ERR, -}; -static int dm_type_match(const char *name, char *type) -{ - struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; - uint64_t start, length; - char *target_type = NULL; - char *params; - - if (!(dmt = libmp_dm_task_create(DM_DEVICE_TABLE))) - return DM_TYPE_ERR; - - if (!dm_task_set_name(dmt, name)) - return DM_TYPE_ERR; - - if (!libmp_dm_task_run(dmt)) { - dm_log_error(3, DM_DEVICE_TABLE, dmt); - return DM_TYPE_ERR; - } - - /* Fetch 1st target */ - if (dm_get_next_target(dmt, NULL, &start, &length, - &target_type, ¶ms) != NULL) - /* multiple targets */ - return DM_TYPE_MULTI; - else if (!target_type) - return DM_TYPE_EMPTY; - else if (!strcmp(target_type, type)) - return DM_TYPE_MATCH; - else - return DM_TYPE_NOMATCH; -} - -static bool is_mpath_part(const char *part_name, const char *map_name) -{ - char part_uuid[DM_UUID_LEN], map_uuid[DM_UUID_LEN]; - - if (dm_get_dm_uuid(map_name, map_uuid) != DMP_OK - || !is_mpath_uuid(map_uuid)) - return false; - - if (dm_get_dm_uuid(part_name, part_uuid) != DMP_OK) - return false; - - return is_mpath_part_uuid(part_uuid, map_uuid); -} - int dm_is_mpath(const char *name) { char uuid[DM_UUID_LEN]; @@ -1443,7 +1389,7 @@ char *dm_mapname(int major, int minor) } static int -do_foreach_partmaps (const char * mapname, +do_foreach_partmaps (const char *mapname, int (*partmap_func)(const char *, void *), void *data) { @@ -1451,9 +1397,18 @@ do_foreach_partmaps (const char * mapname, char __attribute__((cleanup(cleanup_charp))) *params = NULL; struct dm_names *names; unsigned next = 0; - unsigned long long size; - char dev_t[32]; + char dev_t[BLK_DEV_SIZE]; char *p; + char map_uuid[DM_UUID_LEN]; + struct dm_info info; + + if (libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = mapname }, + (mapinfo_t) { .uuid = map_uuid, .dmi = &info }) != DMP_OK) + return 1; + + if (safe_sprintf(dev_t, "%i:%i", info.major, info.minor)) + return 1; if (!(dmt = libmp_dm_task_create(DM_DEVICE_LIST))) return 1; @@ -1468,41 +1423,38 @@ do_foreach_partmaps (const char * mapname, /* this is perfectly valid */ return 0; - if (dm_dev_t(mapname, &dev_t[0], 32)) - return 1; - do { + char part_uuid[DM_UUID_LEN]; + if ( /* * if there is only a single "linear" target */ - (dm_type_match(names->name, TGT_PART) == DM_TYPE_MATCH) && - + libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_PART_ONLY, + (mapid_t) { .str = names->name }, + (mapinfo_t) { + .uuid = part_uuid, + .target = ¶ms, + }) == DMP_OK && /* * and the uuid of the target is a partition of the * uuid of the multipath device */ - is_mpath_part(names->name, mapname) && - - /* - * and we can fetch the map table from the kernel - */ - dm_get_map(names->name, &size, ¶ms) == DMP_OK && + is_mpath_part_uuid(part_uuid, map_uuid) && /* * and the table maps over the multipath map */ (p = strstr(params, dev_t)) && - !isdigit(*(p + strlen(dev_t))) - ) { - if (partmap_func(names->name, data) != 0) - return 1; - } + !isdigit(*(p + strlen(dev_t))) && + + (partmap_func(names->name, data) != 0)) + return 1; free(params); params = NULL; next = names->next; - names = (void *) names + next; + names = (void*) names + next; } while (next); return 0; From 10794d19a023e08a091daf1b1d1415acd07d30e8 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 5 Jul 2024 17:37:54 +0200 Subject: [PATCH 045/145] libmultipath: use libmp_pathinfo() in update_multipath_table() This allows us to remove dm_get_status(), and dm_get_map(), of which update_multipath_table() was the last caller. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 89 -------------------------------------- libmultipath/devmapper.h | 2 - libmultipath/structs_vec.c | 26 ++++++----- 3 files changed, 15 insertions(+), 102 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 37d257881..5ad2e3c9c 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -817,45 +817,6 @@ static int dm_get_dm_uuid(const char *mapname, char uuid[DM_UUID_LEN]) (mapinfo_t) { .uuid = uuid }); } -int dm_get_map(const char *name, unsigned long long *size, char **outparams) -{ - struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; - uint64_t start, length; - char *target_type = NULL; - char *params = NULL; - - if (!(dmt = libmp_dm_task_create(DM_DEVICE_TABLE))) - return DMP_ERR; - - if (!dm_task_set_name(dmt, name)) - return DMP_ERR; - - errno = 0; - if (!libmp_dm_task_run(dmt)) { - dm_log_error(3, DM_DEVICE_TABLE, dmt); - if (dm_task_get_errno(dmt) == ENXIO) - return DMP_NOT_FOUND; - else - return DMP_ERR; - } - - /* Fetch 1st target */ - if (dm_get_next_target(dmt, NULL, &start, &length, - &target_type, ¶ms) != NULL || !params) - /* more than one target or not found target */ - return DMP_NOT_FOUND; - - if (size) - *size = length; - - if (!outparams) - return DMP_OK; - else { - *outparams = strdup(params); - return *outparams ? DMP_OK : DMP_ERR; - } -} - bool is_mpath_uuid(const char uuid[DM_UUID_LEN]) { return !strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN); @@ -898,56 +859,6 @@ static bool is_mpath_part_uuid(const char part_uuid[DM_UUID_LEN], return !strcmp(part_uuid + nc, map_uuid); } -int dm_get_status(const char *name, char **outstatus) -{ - int r = DMP_ERR; - struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; - uint64_t start, length; - char *target_type = NULL; - char *status = NULL; - - if (!(dmt = libmp_dm_task_create(DM_DEVICE_STATUS))) - return r; - - if (!dm_task_set_name(dmt, name)) - goto out; - - errno = 0; - if (!libmp_dm_task_run(dmt)) { - dm_log_error(3, DM_DEVICE_STATUS, dmt); - if (dm_task_get_errno(dmt) == ENXIO) - r = DMP_NOT_FOUND; - goto out; - } - - r = DMP_NOT_FOUND; - /* Fetch 1st target */ - if (dm_get_next_target(dmt, NULL, &start, &length, - &target_type, &status) != NULL) - goto out; - - if (!target_type || strcmp(target_type, TGT_MPATH) != 0) - goto out; - - if (!status) { - condlog(2, "got null status."); - goto out; - } - - if (!outstatus) - r = DMP_OK; - else { - *outstatus = strdup(status); - r = *outstatus ? DMP_OK : DMP_ERR; - } -out: - if (r != DMP_OK) - condlog(0, "%s: %s: error getting map status string: %d", - __func__, name, r); - - return r; -} - int dm_is_mpath(const char *name) { char uuid[DM_UUID_LEN]; diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 6854c6b4a..563f77f92 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -131,8 +131,6 @@ int dm_simplecmd_noflush (int task, const char *name, uint16_t udev_flags); int dm_addmap_create (struct multipath *mpp, char *params); int dm_addmap_reload (struct multipath *mpp, char *params, int flush); int dm_map_present_by_wwid(const char *uuid); -int dm_get_map(const char *name, unsigned long long *size, char **outparams); -int dm_get_status(const char *name, char **outstatus); enum { DM_IS_MPATH_NO, diff --git a/libmultipath/structs_vec.c b/libmultipath/structs_vec.c index ccc4efc77..f2cfe31e8 100644 --- a/libmultipath/structs_vec.c +++ b/libmultipath/structs_vec.c @@ -484,30 +484,34 @@ int update_multipath_table (struct multipath *mpp, vector pathvec, int flags) { int r = DMP_ERR; - char *params = NULL; + char __attribute__((cleanup(cleanup_charp))) *params = NULL; + char __attribute__((cleanup(cleanup_charp))) *status = NULL; + unsigned long long size = mpp->size; if (!mpp) return r; - r = dm_get_map(mpp->alias, &mpp->size, ¶ms); + r = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = mpp->alias }, + (mapinfo_t) { + .target = ¶ms, + .status = &status, + .size = &mpp->size, + }); + if (r != DMP_OK) { - condlog(2, "%s: %s", mpp->alias, (r == DMP_ERR)? "error getting table" : "map not present"); + condlog(2, "%s: %s", mpp->alias, dmp_errstr(r)); return r; - } + } else if (size != mpp->size) + condlog(0, "%s: size changed from %llu to %llu", mpp->alias, size, mpp->size); if (disassemble_map(pathvec, params, mpp)) { condlog(2, "%s: cannot disassemble map", mpp->alias); - free(params); return DMP_ERR; } - free(params); - params = NULL; - if (dm_get_status(mpp->alias, ¶ms) != DMP_OK) - condlog(2, "%s: %s", mpp->alias, (r == DMP_ERR)? "error getting status" : "map not present"); - else if (disassemble_status(params, mpp)) + if (disassemble_status(status, mpp)) condlog(2, "%s: cannot disassemble status", mpp->alias); - free(params); /* FIXME: we should deal with the return value here */ update_pathvec_from_dm(pathvec, mpp, flags); From cff3e3ecac6059711e917935d50f8a59c42999df Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 5 Jul 2024 17:40:03 +0200 Subject: [PATCH 046/145] libmultipath: update mpp->dmi in update_multipath_table() This comes almost for free now. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/structs_vec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libmultipath/structs_vec.c b/libmultipath/structs_vec.c index f2cfe31e8..295dac8ae 100644 --- a/libmultipath/structs_vec.c +++ b/libmultipath/structs_vec.c @@ -497,6 +497,7 @@ update_multipath_table (struct multipath *mpp, vector pathvec, int flags) .target = ¶ms, .status = &status, .size = &mpp->size, + .dmi = &mpp->dmi, }); if (r != DMP_OK) { From 4dabf7489372b829dda8f395e0ad5e2ebddfbc77 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 5 Jul 2024 17:48:54 +0200 Subject: [PATCH 047/145] libmultipath: drop extra call to dm_map_present() in domap() dm_get_wwid() will return DMP_NOT_FOUND if the map doesn't exist. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/configure.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libmultipath/configure.c b/libmultipath/configure.c index 2fdaca85a..b4de863c6 100644 --- a/libmultipath/configure.c +++ b/libmultipath/configure.c @@ -834,6 +834,7 @@ int domap(struct multipath *mpp, char *params, int is_daemon) { int r = DOMAP_FAIL; struct config *conf; + char wwid[WWID_SIZE]; /* * last chance to quit before touching the devmaps @@ -843,8 +844,7 @@ int domap(struct multipath *mpp, char *params, int is_daemon) return DOMAP_DRY; } - if (mpp->action == ACT_CREATE && dm_map_present(mpp->alias)) { - char wwid[WWID_SIZE]; + if (mpp->action == ACT_CREATE) { int rc = dm_get_wwid(mpp->alias, wwid, sizeof(wwid)); if (rc == DMP_OK && !strncmp(mpp->wwid, wwid, sizeof(wwid))) { From 407f09e29395eed286e63302c522f9cd2eff6ac4 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 5 Jul 2024 23:18:14 +0200 Subject: [PATCH 048/145] libmultipath: split off update_multipath_table__() Split off the part of the function that does the disassembly from the part calling libmp_mapinfo(). This makes it possible to call the function from a context where the map info is already available. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/libmultipath.version | 1 + libmultipath/structs_vec.c | 31 +++++++++++++++++++------------ libmultipath/structs_vec.h | 2 ++ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index 5b8f9e024..54b5a23e2 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -206,6 +206,7 @@ global: uninit_config; update_mpp_paths; update_multipath_strings; + update_multipath_table__; update_multipath_table; update_queue_mode_add_path; update_queue_mode_del_path; diff --git a/libmultipath/structs_vec.c b/libmultipath/structs_vec.c index 295dac8ae..731b1bce6 100644 --- a/libmultipath/structs_vec.c +++ b/libmultipath/structs_vec.c @@ -480,6 +480,24 @@ extract_hwe_from_path(struct multipath * mpp) condlog(2, "%s: no hwe found", mpp->alias); } +int +update_multipath_table__ (struct multipath *mpp, vector pathvec, int flags, + const char *params, const char *status) +{ + if (disassemble_map(pathvec, params, mpp)) { + condlog(2, "%s: cannot disassemble map", mpp->alias); + return DMP_ERR; + } + + if (disassemble_status(status, mpp)) + condlog(2, "%s: cannot disassemble status", mpp->alias); + + /* FIXME: we should deal with the return value here */ + update_pathvec_from_dm(pathvec, mpp, flags); + + return DMP_OK; +} + int update_multipath_table (struct multipath *mpp, vector pathvec, int flags) { @@ -506,18 +524,7 @@ update_multipath_table (struct multipath *mpp, vector pathvec, int flags) } else if (size != mpp->size) condlog(0, "%s: size changed from %llu to %llu", mpp->alias, size, mpp->size); - if (disassemble_map(pathvec, params, mpp)) { - condlog(2, "%s: cannot disassemble map", mpp->alias); - return DMP_ERR; - } - - if (disassemble_status(status, mpp)) - condlog(2, "%s: cannot disassemble status", mpp->alias); - - /* FIXME: we should deal with the return value here */ - update_pathvec_from_dm(pathvec, mpp, flags); - - return DMP_OK; + return update_multipath_table__(mpp, pathvec, flags, params, status); } static struct path *find_devt_in_pathgroups(const struct multipath *mpp, diff --git a/libmultipath/structs_vec.h b/libmultipath/structs_vec.h index dbc43058e..01f5dc421 100644 --- a/libmultipath/structs_vec.h +++ b/libmultipath/structs_vec.h @@ -33,6 +33,8 @@ struct multipath * add_map_with_path (struct vectors * vecs, const struct multipath *current_mpp); void update_queue_mode_del_path(struct multipath *mpp); void update_queue_mode_add_path(struct multipath *mpp); +int update_multipath_table__ (struct multipath *mpp, vector pathvec, int flags, + const char *params, const char *status); int update_multipath_table (struct multipath *mpp, vector pathvec, int flags); int update_multipath_status (struct multipath *mpp); vector get_used_hwes(const struct _vector *pathvec); From 8bed80d6a89ea1be8fc48f3619b1ecf912b5268d Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 5 Jul 2024 22:24:20 +0200 Subject: [PATCH 049/145] multipath: implement check_usable_paths() with libmp_pathinfo() ... and use cleanup attributes. We need to call the disassemble...() functions from multipath directly now, but we fetch exactly the data we need from the kernel. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- multipath/main.c | 58 ++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/multipath/main.c b/multipath/main.c index c82bc868b..0d989dc70 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -222,12 +222,14 @@ get_dm_mpvec (enum mpath_cmds cmd, vector curmp, vector pathvec, char * refwwid) static int check_usable_paths(struct config *conf, const char *devpath, enum devtypes dev_type) { - struct udev_device *ud = NULL; - struct multipath *mpp = NULL; + struct udev_device __attribute__((cleanup(cleanup_udev_device))) *ud = NULL; + struct multipath __attribute__((cleanup(cleanup_multipath_and_paths))) *mpp = NULL; struct pathgroup *pg; struct path *pp; - char *mapname; - vector pathvec = NULL; + char __attribute__((cleanup(cleanup_charp))) *params = NULL; + char __attribute__((cleanup(cleanup_charp))) *status = NULL; + vector __attribute((cleanup(cleanup_vector))) pathvec = NULL; + char uuid[DM_UUID_LEN]; dev_t devt; int r = 1, i, j; @@ -238,31 +240,39 @@ static int check_usable_paths(struct config *conf, devt = udev_device_get_devnum(ud); if (!dm_is_dm_major(major(devt))) { condlog(1, "%s is not a dm device", devpath); - goto out; - } - - mapname = dm_mapname(major(devt), minor(devt)); - if (mapname == NULL) { - condlog(1, "dm device not found: %s", devpath); - goto out; + return r; } - if (dm_is_mpath(mapname) != DM_IS_MPATH_YES) { - condlog(1, "%s is not a multipath map", devpath); - goto free; - } + mpp = alloc_multipath(); + if (!mpp) + return r; + if (!(mpp->alias = malloc(WWID_SIZE))) + return r; /* pathvec is needed for disassemble_map */ pathvec = vector_alloc(); if (pathvec == NULL) - goto free; + return r; + + if (libmp_mapinfo(DM_MAP_BY_DEVT | MAPINFO_MPATH_ONLY, + (mapid_t) { .devt = devt }, + (mapinfo_t) { + .name = mpp->alias, + .uuid = uuid, + .dmi = &mpp->dmi, + .size = &mpp->size, + .target = ¶ms, + .status = &status, + }) != DMP_OK) + return r; - mpp = dm_get_multipath(mapname); - if (mpp == NULL) - goto free; + if (!is_mpath_uuid(uuid)) + return r; + + strlcpy(mpp->wwid, uuid + UUID_PREFIX_LEN, sizeof(mpp->wwid)); - if (update_multipath_table(mpp, pathvec, 0) != DMP_OK) - goto free; + if (update_multipath_table__(mpp, pathvec, 0, params, status) != DMP_OK) + return r; vector_foreach_slot (mpp->pg, pg, i) { vector_foreach_slot (pg->paths, pp, j) { @@ -284,12 +294,6 @@ static int check_usable_paths(struct config *conf, found: condlog(r == 0 ? 3 : 2, "%s:%s usable paths found", devpath, r == 0 ? "" : " no"); -free: - free(mapname); - free_multipath(mpp, FREE_PATHS); - vector_free(pathvec); -out: - udev_device_unref(ud); return r; } From 0e2fd754356e7272cade7e406161d2e5eec3cde8 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 5 Jul 2024 23:19:28 +0200 Subject: [PATCH 050/145] multipathd: implement add_map_without_path() with libmp_mapinfo() Also, change the return value to int, as this is more expressive and the returned struct multipath isn't used by the caller. Also remove the call to sync_map_state() in ev_add_map(), which is redundant because add_map_without_path() would have called update_map() and thus sync_map_state() already. Note: this removes the call to remove_map() at the end of the function, which doesn't make sense anyway, because update_multipath_table() would not return error unless the table disassembly failed, in which case nothing would have been added the the mpvec or pathvec yet. It should be sufficient to just cleanup the local data structures when add_map_without_path() fails. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- multipathd/main.c | 83 ++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 1e7a6aca4..32011c95f 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -707,51 +707,57 @@ update_map (struct multipath *mpp, struct vectors *vecs, int new_map) return 0; } -static struct multipath * -add_map_without_path (struct vectors *vecs, const char *alias) +static int add_map_without_path (struct vectors *vecs, const char *alias) { - struct multipath * mpp = alloc_multipath(); + struct multipath __attribute__((cleanup(cleanup_multipath_and_paths))) + *mpp = alloc_multipath(); + char __attribute__((cleanup(cleanup_charp))) *params = NULL; + char __attribute__((cleanup(cleanup_charp))) *status = NULL; struct config *conf; + char uuid[DM_UUID_LEN]; + int rc = DMP_ERR; + + if (!mpp || !(mpp->alias = strdup(alias))) + return DMP_ERR; + + if ((rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = mpp->alias }, + (mapinfo_t) { + .uuid = uuid, + .dmi = &mpp->dmi, + .size = &mpp->size, + .target = ¶ms, + .status = &status, + })) != DMP_OK) + return rc; + + if (!is_mpath_uuid(uuid)) + return DMP_NO_MATCH; + else + strlcpy(mpp->wwid, uuid + UUID_PREFIX_LEN, sizeof(mpp->wwid)); - if (!mpp) - return NULL; - if (!alias) { - free(mpp); - return NULL; - } - - mpp->alias = strdup(alias); - - if (dm_get_info(mpp->alias, &mpp->dmi) != DMP_OK) { - condlog(3, "%s: cannot access table", mpp->alias); - goto out; - } - 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(); mpp->mpe = find_mpe(conf->mptable, mpp->wwid); put_multipath_config(conf); - if (update_multipath_table(mpp, vecs->pathvec, 0) != DMP_OK) - goto out; + if ((rc = update_multipath_table__(mpp, vecs->pathvec, 0, params, status)) != DMP_OK) + return DMP_ERR; if (!vector_alloc_slot(vecs->mpvec)) - goto out; - - vector_set_slot(vecs->mpvec, mpp); + return DMP_ERR; + vector_set_slot(vecs->mpvec, steal_ptr(mpp)); - if (update_map(mpp, vecs, 1) != 0) /* map removed */ - return NULL; + /* + * We can't pass mpp here, steal_ptr() has just nullified it. + * vector_set_slot() just set the last slot, use that. + */ + if (update_map(VECTOR_LAST_SLOT(vecs->mpvec), vecs, 1) != 0) /* map removed */ + return DMP_ERR; - return mpp; -out: - remove_map(mpp, vecs->pathvec, vecs->mpvec); - return NULL; + return DMP_OK; } static int @@ -865,14 +871,9 @@ int ev_add_map (char * dev, const char * alias, struct vectors * vecs) { struct multipath * mpp; - int reassign_maps; + int reassign_maps, rc; struct config *conf; - if (dm_is_mpath(alias) != DM_IS_MPATH_YES) { - condlog(4, "%s: not a multipath map", alias); - return 0; - } - mpp = find_mp_by_alias(vecs->mpvec, alias); if (mpp) { @@ -910,10 +911,12 @@ ev_add_map (char * dev, const char * alias, struct vectors * vecs) /* * now we can register the map */ - if ((mpp = add_map_without_path(vecs, alias))) { - sync_map_state(mpp); + if ((rc = add_map_without_path(vecs, alias)) == DMP_OK) { condlog(2, "%s: devmap %s registered", alias, dev); return 0; + } else if (rc == DMP_NO_MATCH) { + condlog(4, "%s: not a multipath map", alias); + return 0; } else { condlog(2, "%s: ev_add_map failed", dev); return 1; From bf3a4ada0f86a5d8f7a10ba35249b5a6b410cff3 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Mon, 8 Jul 2024 19:23:52 +0200 Subject: [PATCH 051/145] libmultipath: simplify dm_get_maps() Make dm_get_multipath() return a distinct error code for non-multipath targets. This way the extra call to dm_is_mpath() is not necessary any more. As dm_get_maps() is the only caller of dm_get_multipath(), transform it into a static function. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 44 +++++++++++++++++++++------------------- libmultipath/devmapper.h | 1 - 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 5ad2e3c9c..588900171 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1188,39 +1188,42 @@ dm_disablegroup(const char * mapname, int index) return dm_groupmsg("disable", mapname, index); } -struct multipath *dm_get_multipath(const char *name) +static int dm_get_multipath(const char *name, struct multipath **pmpp) { struct multipath __attribute((cleanup(cleanup_multipath))) *mpp = NULL; char uuid[DM_UUID_LEN]; + int rc; mpp = alloc_multipath(); if (!mpp) - return NULL; + return DMP_ERR; mpp->alias = strdup(name); if (!mpp->alias) - return NULL; + return DMP_ERR; - if (libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + if ((rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, (mapid_t) { .str = name }, (mapinfo_t) { .size = &mpp->size, .uuid = uuid, .dmi = &mpp->dmi, - }) != DMP_OK) - return NULL; + })) != DMP_OK) + return rc; if (!is_mpath_uuid(uuid)) - return NULL; + return DMP_NO_MATCH; strlcpy(mpp->wwid, uuid + UUID_PREFIX_LEN, sizeof(mpp->wwid)); - return steal_ptr(mpp); + *pmpp = steal_ptr(mpp); + + return DMP_OK; } int dm_get_maps(vector mp) { - struct multipath * mpp; + struct multipath *mpp = NULL; struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; struct dm_names *names; unsigned next = 0; @@ -1245,20 +1248,19 @@ int dm_get_maps(vector mp) } do { - if (dm_is_mpath(names->name) != DM_IS_MPATH_YES) - goto next; - - mpp = dm_get_multipath(names->name); - if (!mpp) - return 1; - - if (!vector_alloc_slot(mp)) { - free_multipath(mpp, KEEP_PATHS); + switch (dm_get_multipath(names->name, &mpp)) { + case DMP_OK: + if (!vector_alloc_slot(mp)) { + free_multipath(mpp, KEEP_PATHS); + return 1; + } + vector_set_slot(mp, mpp); + break; + case DMP_NO_MATCH: + break; + default: return 1; } - - vector_set_slot(mp, mpp); -next: next = names->next; names = (void *) names + next; } while (next); diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 563f77f92..d0e20bfe7 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -184,7 +184,6 @@ int dm_rename (const char * old, char * new, char * delim, int skip_kpartx); int dm_reassign(const char * mapname); int dm_reassign_table(const char *name, char *old, char *new); int dm_setgeometry(struct multipath *mpp); -struct multipath *dm_get_multipath(const char *name); #define VERSION_GE(v, minv) ( \ (v[0] > minv[0]) || \ From 8e771868e6f4fda1a195da86fb9a1007a183ab05 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Mon, 8 Jul 2024 20:11:53 +0200 Subject: [PATCH 052/145] libmpathpersist: use libmp_mapinfo() in mpath_get_map() When obtaining the map name, make sure right away that the map is a multipath device. This saves an ioctl and slightly simplifies the function. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathpersist/mpath_persist_int.c | 50 +++++++++++++---------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/libmpathpersist/mpath_persist_int.c b/libmpathpersist/mpath_persist_int.c index 5a5ac3b84..a3eb80acf 100644 --- a/libmpathpersist/mpath_persist_int.c +++ b/libmpathpersist/mpath_persist_int.c @@ -157,10 +157,9 @@ static int get_mpvec(vector curmp, vector pathvec, char *refwwid) static int mpath_get_map(vector curmp, vector pathvec, int fd, char **palias, struct multipath **pmpp) { - int ret = MPATH_PR_DMMP_ERROR; + int rc; struct stat info; - int major, minor; - char *alias; + char alias[WWID_SIZE], uuid[DM_UUID_LEN]; struct multipath *mpp; if (fstat(fd, &info) != 0){ @@ -172,47 +171,44 @@ static int mpath_get_map(vector curmp, vector pathvec, int fd, char **palias, return MPATH_PR_FILE_ERROR; } - major = major(info.st_rdev); - minor = minor(info.st_rdev); - condlog(4, "Device %d:%d", major, minor); - /* get alias from major:minor*/ - alias = dm_mapname(major, minor); - if (!alias){ - condlog(0, "%d:%d failed to get device alias.", major, minor); + rc = libmp_mapinfo(DM_MAP_BY_DEVT | MAPINFO_MPATH_ONLY, + (mapid_t) { .devt = info.st_rdev }, + (mapinfo_t) { + .name = alias, + .uuid = uuid, + }); + + if (rc == DMP_NO_MATCH || !is_mpath_uuid(uuid)) { + condlog(3, "%s: not a multipath device.", alias); + return MPATH_PR_DMMP_ERROR; + } else if (rc != DMP_OK) { + condlog(1, "%d:%d failed to get device alias.", + major(info.st_rdev), minor(info.st_rdev)); return MPATH_PR_DMMP_ERROR; } - condlog(3, "alias = %s", alias); - - if (dm_is_mpath(alias) != DM_IS_MPATH_YES) { - condlog(3, "%s: not a multipath device.", alias); - goto out; - } + condlog(4, "alias = %s", alias); /* get info of all paths from the dm device */ - if (get_mpvec(curmp, pathvec, alias)){ + if (get_mpvec(curmp, pathvec, alias)) { condlog(0, "%s: failed to get device info.", alias); - goto out; + return MPATH_PR_DMMP_ERROR; } mpp = find_mp_by_alias(curmp, alias); if (!mpp) { condlog(0, "%s: devmap not registered.", alias); - goto out; + return MPATH_PR_DMMP_ERROR; } - ret = MPATH_PR_SUCCESS; if (pmpp) *pmpp = mpp; - if (palias) { - *palias = alias; - alias = NULL; - } -out: - free(alias); - return ret; + if (palias && (*palias = strdup(alias)) == NULL) + return MPATH_PR_DMMP_ERROR; + + return MPATH_PR_SUCCESS; } int do_mpath_persistent_reserve_in(vector curmp, vector pathvec, From 3a26e27cdc99cbd1070273cc70c965afea0d8247 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Mon, 8 Jul 2024 20:29:27 +0200 Subject: [PATCH 053/145] libmpathpersist: use mpp->alias in do_mpath_persistent_reserve_out() The extra pointer "alias" isn't necessary. The mp vector is initialized by dm_get_maps(), which will allocate mpp->alias for every map, thus we can use it in do_mpath_persistent_reserve_out(). This allows us to simplify both this function itself and mpath_get_map(). Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathpersist/mpath_persist_int.c | 38 ++++++++++++----------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/libmpathpersist/mpath_persist_int.c b/libmpathpersist/mpath_persist_int.c index a3eb80acf..807415fef 100644 --- a/libmpathpersist/mpath_persist_int.c +++ b/libmpathpersist/mpath_persist_int.c @@ -154,8 +154,7 @@ static int get_mpvec(vector curmp, vector pathvec, char *refwwid) return MPATH_PR_SUCCESS ; } -static int mpath_get_map(vector curmp, vector pathvec, int fd, char **palias, - struct multipath **pmpp) +static int mpath_get_map(vector curmp, vector pathvec, int fd, struct multipath **pmpp) { int rc; struct stat info; @@ -205,8 +204,6 @@ static int mpath_get_map(vector curmp, vector pathvec, int fd, char **palias, if (pmpp) *pmpp = mpp; - if (palias && (*palias = strdup(alias)) == NULL) - return MPATH_PR_DMMP_ERROR; return MPATH_PR_SUCCESS; } @@ -218,7 +215,7 @@ int do_mpath_persistent_reserve_in(vector curmp, vector pathvec, struct multipath *mpp; int ret; - ret = mpath_get_map(curmp, pathvec, fd, NULL, &mpp); + ret = mpath_get_map(curmp, pathvec, fd, &mpp); if (ret != MPATH_PR_SUCCESS) return ret; @@ -649,12 +646,11 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd, struct prout_param_descriptor *paramp, int noisy) { struct multipath *mpp; - char *alias; int ret; uint64_t prkey; struct config *conf; - ret = mpath_get_map(curmp, pathvec, fd, &alias, &mpp); + ret = mpath_get_map(curmp, pathvec, fd, &mpp); if (ret != MPATH_PR_SUCCESS) return ret; @@ -670,21 +666,20 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd, (!get_be64(mpp->reservation_key) || memcmp(paramp->key, &mpp->reservation_key, 8) == 0)))) { memcpy(&mpp->reservation_key, paramp->sa_key, 8); - if (update_prkey_flags(alias, get_be64(mpp->reservation_key), + if (update_prkey_flags(mpp->alias, get_be64(mpp->reservation_key), paramp->sa_flags)) { condlog(0, "%s: failed to set prkey for multipathd.", - alias); - ret = MPATH_PR_DMMP_ERROR; - goto out1; + mpp->alias); + return MPATH_PR_DMMP_ERROR; } } if (memcmp(paramp->key, &mpp->reservation_key, 8) && memcmp(paramp->sa_key, &mpp->reservation_key, 8) && (prkey || rq_servact != MPATH_PROUT_REG_IGN_SA)) { - condlog(0, "%s: configured reservation key doesn't match: 0x%" PRIx64, alias, get_be64(mpp->reservation_key)); - ret = MPATH_PR_SYNTAX_ERROR; - goto out1; + condlog(0, "%s: configured reservation key doesn't match: 0x%" PRIx64, + mpp->alias, get_be64(mpp->reservation_key)); + return MPATH_PR_SYNTAX_ERROR; } switch(rq_servact) @@ -703,24 +698,21 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd, ret = mpath_prout_rel(mpp, rq_servact, rq_scope, rq_type, paramp, noisy); break; default: - ret = MPATH_PR_OTHER; - goto out1; + return MPATH_PR_OTHER; } if ((ret == MPATH_PR_SUCCESS) && ((rq_servact == MPATH_PROUT_REG_SA) || (rq_servact == MPATH_PROUT_REG_IGN_SA))) { if (prkey == 0) { - update_prflag(alias, 0); - update_prkey(alias, 0); + update_prflag(mpp->alias, 0); + update_prkey(mpp->alias, 0); } else - update_prflag(alias, 1); + update_prflag(mpp->alias, 1); } else if ((ret == MPATH_PR_SUCCESS) && (rq_servact == MPATH_PROUT_CLEAR_SA)) { - update_prflag(alias, 0); - update_prkey(alias, 0); + update_prflag(mpp->alias, 0); + update_prkey(mpp->alias, 0); } -out1: - free(alias); return ret; } From f1e1c22206e7660b27fde9442a64a5eb5de2c6af Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 12 Jul 2024 14:34:25 +0200 Subject: [PATCH 054/145] libmultipath: fix deferred_remove logic in remove_partmap() The logic for returning DM_FLUSH_BUSY in remove_partmap() got accidentally reverted in commit 20aeeb6. Fix it. Fixes: 20aeeb6 ("libmultipath: fix deferred_remove function arguments") Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 588900171..e96b83ef0 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1384,7 +1384,7 @@ remove_partmap(const char *name, void *data) if (dm_get_opencount(name)) { dm_remove_partmaps(name, rd->flags); - if ((rd->flags & DMFL_DEFERRED) && dm_get_opencount(name)) { + if (!(rd->flags & DMFL_DEFERRED) && dm_get_opencount(name)) { condlog(2, "%s: map in use", name); return DM_FLUSH_BUSY; } From 59425ee7076728a7b79e12b72ef0ec881acf1602 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 12 Jul 2024 17:25:20 +0200 Subject: [PATCH 055/145] libmultipath: Move UUID check into libmp_pathinfo__() We have a couple of callers that check whether the map UUID conforms to the multipath convention ("mpath-xyz"). Move this check into libmp_mapinfo__(). Add another flag MAPINFO_CHECK_UUID for this purpose. This allows to simplify some callers, which only fetched the UUID in order to check it. Note that the UUID check is orthogonal to MAPINFO_MPATH_ONLY, which tests the target type. We shold make sure that both tests are in agreement, but this is postponed to a later patch set. is_mpath_uuid() can now be converted to a static function. Also add some unit tests for the WWID check. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathpersist/mpath_persist_int.c | 11 +- libmultipath/devmapper.c | 52 +++---- libmultipath/devmapper.h | 3 +- libmultipath/libmultipath.version | 1 - multipath/main.c | 5 +- multipathd/main.c | 7 +- tests/mapinfo.c | 226 ++++++++++++++++++++++++++++ 7 files changed, 256 insertions(+), 49 deletions(-) diff --git a/libmpathpersist/mpath_persist_int.c b/libmpathpersist/mpath_persist_int.c index 807415fef..f4d9e7c85 100644 --- a/libmpathpersist/mpath_persist_int.c +++ b/libmpathpersist/mpath_persist_int.c @@ -158,7 +158,7 @@ static int mpath_get_map(vector curmp, vector pathvec, int fd, struct multipath { int rc; struct stat info; - char alias[WWID_SIZE], uuid[DM_UUID_LEN]; + char alias[WWID_SIZE]; struct multipath *mpp; if (fstat(fd, &info) != 0){ @@ -171,14 +171,11 @@ static int mpath_get_map(vector curmp, vector pathvec, int fd, struct multipath } /* get alias from major:minor*/ - rc = libmp_mapinfo(DM_MAP_BY_DEVT | MAPINFO_MPATH_ONLY, + rc = libmp_mapinfo(DM_MAP_BY_DEVT | MAPINFO_MPATH_ONLY | MAPINFO_CHECK_UUID, (mapid_t) { .devt = info.st_rdev }, - (mapinfo_t) { - .name = alias, - .uuid = uuid, - }); + (mapinfo_t) { .name = alias }); - if (rc == DMP_NO_MATCH || !is_mpath_uuid(uuid)) { + if (rc == DMP_NO_MATCH) { condlog(3, "%s: not a multipath device.", alias); return MPATH_PR_DMMP_ERROR; } else if (rc != DMP_OK) { diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index e96b83ef0..455905a26 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -611,6 +611,11 @@ int dm_addmap_reload(struct multipath *mpp, char *params, int flush) return 0; } +static bool is_mpath_uuid(const char uuid[DM_UUID_LEN]) +{ + return !strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN); +} + bool has_dm_info(const struct multipath *mpp) { @@ -736,11 +741,17 @@ static int libmp_mapinfo__(int flags, mapid_t id, mapinfo_t info, const char *ma * If error is returned, don't touch any output parameters. */ if ((info.name && !(name = dm_task_get_name(dmt))) - || (info.uuid && !(uuid = dm_task_get_uuid(dmt))) + || ((info.uuid || flags & MAPINFO_CHECK_UUID) + && !(uuid = dm_task_get_uuid(dmt))) || (info.status && !(tmp_status = strdup(params))) || (info.target && !tmp_target && !(tmp_target = strdup(params)))) return DMP_ERR; + if (flags & MAPINFO_CHECK_UUID && !is_mpath_uuid(uuid)) { + condlog(3, "%s: UUID mismatch: %s", fname__, uuid); + return DMP_NO_MATCH; + } + if (info.name) { strlcpy(info.name, name, WWID_SIZE); condlog(4, "%s: %s: name: \"%s\"", fname__, map_id, info.name); @@ -810,18 +821,6 @@ int libmp_mapinfo(int flags, mapid_t id, mapinfo_t info) libmp_map_identifier(flags, id, idbuf)); } -static int dm_get_dm_uuid(const char *mapname, char uuid[DM_UUID_LEN]) -{ - return libmp_mapinfo(DM_MAP_BY_NAME, - (mapid_t) { .str = mapname }, - (mapinfo_t) { .uuid = uuid }); -} - -bool is_mpath_uuid(const char uuid[DM_UUID_LEN]) -{ - return !strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN); -} - /** * dm_get_wwid(): return WWID for a multipath map * @returns: @@ -834,16 +833,14 @@ bool is_mpath_uuid(const char uuid[DM_UUID_LEN]) 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); + int rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = name }, + (mapinfo_t) { .uuid = tmp }); if (rc != DMP_OK) return rc; - if (is_mpath_uuid(tmp)) - strlcpy(uuid, tmp + UUID_PREFIX_LEN, uuid_len); - else - return DMP_NO_MATCH; - + strlcpy(uuid, tmp + UUID_PREFIX_LEN, uuid_len); return DMP_OK; } @@ -861,16 +858,13 @@ static bool is_mpath_part_uuid(const char part_uuid[DM_UUID_LEN], int dm_is_mpath(const char *name) { - char uuid[DM_UUID_LEN]; - int rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + int rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY | MAPINFO_CHECK_UUID, (mapid_t) { .str = name }, - (mapinfo_t) { .uuid = uuid }); + (mapinfo_t) { .uuid = NULL }); switch (rc) { case DMP_OK: - if (is_mpath_uuid(uuid)) - return DM_IS_MPATH_YES; - /* fallthrough */ + return DM_IS_MPATH_YES; case DMP_NOT_FOUND: case DMP_NO_MATCH: return DM_IS_MPATH_NO; @@ -961,14 +955,10 @@ int _dm_flush_map (const char *mapname, int flags, int retries) int queue_if_no_path = 0; int udev_flags = 0; char *params __attribute__((cleanup(cleanup_charp))) = NULL; - char uuid[DM_UUID_LEN]; - if (libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + if (libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY | MAPINFO_CHECK_UUID, (mapid_t) { .str = mapname }, - (mapinfo_t) { - .uuid = uuid, - .target = ¶ms }) != DMP_OK - || !is_mpath_uuid(uuid)) + (mapinfo_t) { .target = ¶ms }) != DMP_OK) return DM_FLUSH_OK; /* nothing to do */ /* if the device currently has no partitions, do not diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index d0e20bfe7..7a551d903 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -57,6 +57,8 @@ enum __mapinfo_flags { /* Fail if target type is not "partition" (linear) */ MAPINFO_PART_ONLY = (1 << 9), __MAPINFO_TGT_TYPE = (MAPINFO_MPATH_ONLY | MAPINFO_PART_ONLY), + /* Fail if the UUID doesn't match the multipath UUID format */ + MAPINFO_CHECK_UUID = (1 << 10), }; typedef union libmp_map_identifier { @@ -138,7 +140,6 @@ enum { DM_IS_MPATH_ERR, }; -bool is_mpath_uuid(const char uuid[DM_UUID_LEN]); int dm_is_mpath(const char *name); enum { diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index 54b5a23e2..292a33083 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -127,7 +127,6 @@ global: init_foreign; init_prio; io_err_stat_handle_pathfail; - is_mpath_uuid; is_path_valid; libmp_dm_task_create; libmp_get_version; diff --git a/multipath/main.c b/multipath/main.c index 0d989dc70..4b19d2ea8 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -254,7 +254,7 @@ static int check_usable_paths(struct config *conf, if (pathvec == NULL) return r; - if (libmp_mapinfo(DM_MAP_BY_DEVT | MAPINFO_MPATH_ONLY, + if (libmp_mapinfo(DM_MAP_BY_DEVT | MAPINFO_MPATH_ONLY | MAPINFO_CHECK_UUID, (mapid_t) { .devt = devt }, (mapinfo_t) { .name = mpp->alias, @@ -266,9 +266,6 @@ static int check_usable_paths(struct config *conf, }) != DMP_OK) return r; - if (!is_mpath_uuid(uuid)) - return r; - strlcpy(mpp->wwid, uuid + UUID_PREFIX_LEN, sizeof(mpp->wwid)); if (update_multipath_table__(mpp, pathvec, 0, params, status) != DMP_OK) diff --git a/multipathd/main.c b/multipathd/main.c index 32011c95f..833c1e237 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -720,7 +720,7 @@ static int add_map_without_path (struct vectors *vecs, const char *alias) if (!mpp || !(mpp->alias = strdup(alias))) return DMP_ERR; - if ((rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + if ((rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY | MAPINFO_CHECK_UUID, (mapid_t) { .str = mpp->alias }, (mapinfo_t) { .uuid = uuid, @@ -731,10 +731,7 @@ static int add_map_without_path (struct vectors *vecs, const char *alias) })) != DMP_OK) return rc; - if (!is_mpath_uuid(uuid)) - return DMP_NO_MATCH; - else - strlcpy(mpp->wwid, uuid + UUID_PREFIX_LEN, sizeof(mpp->wwid)); + strlcpy(mpp->wwid, uuid + UUID_PREFIX_LEN, sizeof(mpp->wwid)); if (!strlen(mpp->wwid)) condlog(1, "%s: adding map with empty WWID", mpp->alias); diff --git a/tests/mapinfo.c b/tests/mapinfo.c index f3a8440c0..f7ad86822 100644 --- a/tests/mapinfo.c +++ b/tests/mapinfo.c @@ -54,6 +54,16 @@ static const char MPATH_STATUS_01[] = "A 0 3 2 65:32 A 0 0 1 67:64 A 0 0 1 69:96 A 0 0 1 " "E 0 3 2 8:16 A 0 0 1 66:48 A 0 0 1 68:80 A 0 0 1 "; +static const char BAD_UUID_01[] = ""; +static const char BAD_UUID_02[] = "mpath3600a098038302d414b2b4d4453474f62"; +static const char BAD_UUID_03[] = " mpath-3600a098038302d414b2b4d4453474f62"; +static const char BAD_UUID_04[] = "-mpath-3600a098038302d414b2b4d4453474f62"; +static const char BAD_UUID_05[] = "mpth-3600a098038302d414b2b4d4453474f62"; +static const char BAD_UUID_06[] = "part1-mpath-3600a098038302d414b2b4d4453474f62"; +static const char BAD_UUID_07[] = "mpath 3600a098038302d414b2b4d4453474f62"; +static const char BAD_UUID_08[] = "mpath"; +static const char BAD_UUID_09[] = "mpath-"; + char *__real_strdup(const char *str); char *__wrap_strdup(const char *str) { @@ -413,6 +423,208 @@ static void test_mapinfo_good_exists(void **state) assert_int_equal(rc, DMP_OK); } +static void test_mapinfo_bad_check_uuid_00(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + will_return(__wrap_dm_task_get_uuid, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_check_uuid_01(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + will_return(__wrap_dm_task_get_uuid, BAD_UUID_01); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NO_MATCH); +} + +static void test_mapinfo_bad_check_uuid_02(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + will_return(__wrap_dm_task_get_uuid, BAD_UUID_02); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NO_MATCH); +} + +static void test_mapinfo_bad_check_uuid_03(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + will_return(__wrap_dm_task_get_uuid, BAD_UUID_03); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NO_MATCH); +} + +static void test_mapinfo_bad_check_uuid_04(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + will_return(__wrap_dm_task_get_uuid, BAD_UUID_04); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NO_MATCH); +} + +static void test_mapinfo_bad_check_uuid_05(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + will_return(__wrap_dm_task_get_uuid, BAD_UUID_05); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NO_MATCH); +} + +static void test_mapinfo_bad_check_uuid_06(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + will_return(__wrap_dm_task_get_uuid, BAD_UUID_06); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NO_MATCH); +} + +static void test_mapinfo_bad_check_uuid_07(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + will_return(__wrap_dm_task_get_uuid, BAD_UUID_07); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NO_MATCH); +} + +static void test_mapinfo_bad_check_uuid_08(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + will_return(__wrap_dm_task_get_uuid, BAD_UUID_08); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NO_MATCH); +} + +static void test_mapinfo_bad_check_uuid_09(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + will_return(__wrap_dm_task_get_uuid, BAD_UUID_09); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_OK); +} + +static void test_mapinfo_good_check_uuid_01(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_OK); +} + +static void test_mapinfo_good_check_uuid_02(void **state) +{ + int rc; + char uuid[DM_UUID_LEN]; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .uuid = uuid }); + assert_int_equal(rc, DMP_OK); +} + +static void test_mapinfo_good_check_uuid_03(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL); + will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_OK); +} + +static void test_mapinfo_good_check_uuid_04(void **state) +{ + char __attribute__((cleanup(cleanup_charp))) *target = NULL; + int rc; + + mock_mapinfo_name_1(DM_DEVICE_TABLE, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL); + will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01); + will_return(__wrap_strdup, 1); + + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .target = &target }); + assert_int_equal(rc, DMP_OK); +} + static void test_mapinfo_bad_set_uuid(void **state) { int rc; @@ -1126,6 +1338,20 @@ static int test_mapinfo(void) cmocka_unit_test(test_mapinfo_bad_get_info_03), cmocka_unit_test(test_mapinfo_bad_get_info_04), cmocka_unit_test(test_mapinfo_good_exists), + cmocka_unit_test(test_mapinfo_bad_check_uuid_00), + cmocka_unit_test(test_mapinfo_bad_check_uuid_01), + cmocka_unit_test(test_mapinfo_bad_check_uuid_02), + cmocka_unit_test(test_mapinfo_bad_check_uuid_03), + cmocka_unit_test(test_mapinfo_bad_check_uuid_04), + cmocka_unit_test(test_mapinfo_bad_check_uuid_05), + cmocka_unit_test(test_mapinfo_bad_check_uuid_06), + cmocka_unit_test(test_mapinfo_bad_check_uuid_07), + cmocka_unit_test(test_mapinfo_bad_check_uuid_08), + cmocka_unit_test(test_mapinfo_bad_check_uuid_09), + cmocka_unit_test(test_mapinfo_good_check_uuid_01), + cmocka_unit_test(test_mapinfo_good_check_uuid_02), + cmocka_unit_test(test_mapinfo_good_check_uuid_03), + cmocka_unit_test(test_mapinfo_good_check_uuid_04), cmocka_unit_test(test_mapinfo_bad_set_uuid), cmocka_unit_test(test_mapinfo_bad_set_dev_01), cmocka_unit_test(test_mapinfo_bad_set_dev_02), From 3940e1a005ebc73f4806d868f767c528365cf7cf Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 12 Jul 2024 15:58:29 +0200 Subject: [PATCH 056/145] libmultipath: don't call do_foreach_partmaps() recursively We've removed partition mappings recursively since 83fb936 ("Correctly remove logical partition maps"). This was wrong, because kpartx doesn't create logical partitions as mappings onto the extended partition. Rather, logical partitions are created by kpartx as mappings to the multipath device, and afaics, this has always been the case. Therefore, the loop in do_foreach_partmaps() will detect all partition mappings (primary, extended, and logical) without recursion. At least since 4059e42 ("libmultipath: fix partition detection"), the recursion has actually been pointless, because is_mpath_part() would never have returned "true" for a pair of two partition mappings (one representing an extended partition and one a logical partition). Avoiding the recursion has the additional benefit that the complexity of removing maps scales with N, where N is the number of dm devices, rather than with N^2. Also, it simplifies the code. Split partmap_in_use() into two separate functions, mpath_in_use() (to be called for multipath maps) and count_partitions(), which is called from do_foreach_partmaps(). Because do_foreach_partmaps() is now only legitimately called for multipath maps, quit early if called for another map type. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 48 +++++++++++++++++++------------ libmultipath/devmapper.h | 2 +- libmultipath/libmultipath.version | 2 +- multipathd/main.c | 2 +- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 455905a26..3b2e8ac27 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -929,22 +929,37 @@ has_partmap(const char *name __attribute__((unused)), return 1; } -int -partmap_in_use(const char *name, void *data) +/* + * This will be called from mpath_in_use, for each partition. + * If the partition itself in use, returns 1 immediately, causing + * do_foreach_partmaps() to stop iterating and return 1. + * Otherwise, increases the partition count. + */ +static int count_partitions(const char *name, void *data) +{ + int *ret_count = (int *)data; + int open_count = dm_get_opencount(name); + + if (open_count) + return 1; + (*ret_count)++; + return 0; +} + +int mpath_in_use(const char *name) { - int part_count, *ret_count = (int *)data; int open_count = dm_get_opencount(name); - if (ret_count) - (*ret_count)++; - part_count = 0; if (open_count) { - if (do_foreach_partmaps(name, partmap_in_use, &part_count)) - return 1; - if (open_count != part_count) { - condlog(2, "%s: map in use", name); + int part_count = 0; + + if (do_foreach_partmaps(name, count_partitions, &part_count)) { + condlog(4, "%s: %s has open partitions", __func__, name); return 1; } + condlog(4, "%s: %s: %d openers, %d partitions", __func__, name, + open_count, part_count); + return open_count > part_count; } return 0; } @@ -968,7 +983,7 @@ int _dm_flush_map (const char *mapname, int flags, int retries) /* If you aren't doing a deferred remove, make sure that no * devices are in use */ - if (!(flags & DMFL_DEFERRED) && partmap_in_use(mapname, NULL)) + if (!(flags & DMFL_DEFERRED) && mpath_in_use(mapname)) return DM_FLUSH_BUSY; if ((flags & DMFL_SUSPEND) && @@ -1305,7 +1320,7 @@ do_foreach_partmaps (const char *mapname, char map_uuid[DM_UUID_LEN]; struct dm_info info; - if (libmp_mapinfo(DM_MAP_BY_NAME, + if (libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, (mapid_t) { .str = mapname }, (mapinfo_t) { .uuid = map_uuid, .dmi = &info }) != DMP_OK) return 1; @@ -1372,12 +1387,9 @@ remove_partmap(const char *name, void *data) { struct remove_data *rd = (struct remove_data *)data; - if (dm_get_opencount(name)) { - dm_remove_partmaps(name, rd->flags); - if (!(rd->flags & DMFL_DEFERRED) && dm_get_opencount(name)) { - condlog(2, "%s: map in use", name); - return DM_FLUSH_BUSY; - } + if (!(rd->flags & DMFL_DEFERRED) && dm_get_opencount(name)) { + condlog(2, "%s: map in use", name); + return DM_FLUSH_BUSY; } condlog(4, "partition map %s removed", name); dm_device_remove(name, rd->flags); diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 7a551d903..f6d0017ee 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -150,7 +150,7 @@ enum { DM_FLUSH_BUSY, }; -int partmap_in_use(const char *name, void *data); +int mpath_in_use(const char *name); enum { DMFL_NONE = 0, diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index 292a33083..959f675e2 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -138,10 +138,10 @@ global: libmultipath_exit; libmultipath_init; load_config; + mpath_in_use; need_io_err_check; orphan_path; parse_prkey_flags; - partmap_in_use; pathcount; path_discovery; path_get_tpgs; diff --git a/multipathd/main.c b/multipathd/main.c index 833c1e237..13ed6d058 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -597,7 +597,7 @@ flush_map_nopaths(struct multipath *mpp, struct vectors *vecs) { return false; } if (mpp->flush_on_last_del == FLUSH_UNUSED && - partmap_in_use(mpp->alias, NULL) && is_queueing) { + mpath_in_use(mpp->alias) && is_queueing) { condlog(2, "%s: map in use and queueing, can't remove", mpp->alias); return false; From 01c27597fa4a4792827a3a94fc1b838bfe7dd4b4 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 11 Jul 2024 17:56:22 +0200 Subject: [PATCH 057/145] multipath-tools tests: fix directio test with real device Allow setting DIO_TEST_DEV during runtime, by reading the environment variable. The test was fragile despite the delay, because the real io_getevents() call isn't guaranteed to return the number of events requested. Fix that. Moreover, allow reading DIO_TEST_DELAY (in us) from the environment. With the io_getevents fix, for me the test succeeded even with 0 us delay. Change the README accordingly. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- tests/Makefile | 8 --- tests/README.md | 29 ++++++-- tests/directio.c | 182 ++++++++++++++++++++++++++--------------------- 3 files changed, 122 insertions(+), 97 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index 55fbf0fe2..02580e738 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -21,12 +21,6 @@ valgrind: $(TESTS:%=%.vgr) # test-specific compiler flags # XYZ-test_FLAGS: Additional compiler flags for this test -ifneq ($(wildcard directio_test_dev),) -DIO_TEST_DEV = $(shell sed -n -e 's/^[[:space:]]*DIO_TEST_DEV[[:space:]]*=[[:space:]]*\([^[:space:]\#]\+\).*/\1/p' < directio_test_dev) -endif -ifneq ($(DIO_TEST_DEV),) -directio-test_FLAGS := -DDIO_TEST_DEV=\"$(DIO_TEST_DEV)\" -endif mpathvalid-test_FLAGS := -I$(mpathvaliddir) features-test_FLAGS := -I$(multipathdir)/nvme @@ -59,9 +53,7 @@ valid-test_LIBDEPS := -lmount -ludev -lpthread -ldl devt-test_LIBDEPS := -ludev mpathvalid-test_LIBDEPS := -ludev -lpthread -ldl mpathvalid-test_OBJDEPS := $(mpathvaliddir)/mpath_valid.o -ifneq ($(DIO_TEST_DEV),) directio-test_LIBDEPS := -laio -endif strbuf-test_OBJDEPS := $(mpathutildir)/strbuf.o sysfs-test_TESTDEPS := test-log.o sysfs-test_OBJDEPS := $(multipathdir)/sysfs.o $(mpathutildir)/util.o diff --git a/tests/README.md b/tests/README.md index fd36fc1e8..0cae0579a 100644 --- a/tests/README.md +++ b/tests/README.md @@ -13,6 +13,17 @@ If valgrind detects a bad memory access or leak, the test will fail. The output of the test run, including valgrind output, is stored as `.vgr`. +## Running tests manually + +`make test` or `make -C test "$TEST.out"` will only run the test program if +the output files `$TEST.out` don't exist yet. To re-run the test, delete the +output file first. In order to run a test outside `make`, set the library +search path: + + cd tests + export LD_LIBRARY_PATH=.:../libmpathutil:../libmpathcmd + ./dmevents-test # or whatever other test you want to run + ## Controlling verbosity for unit tests Some test programs use the environment variable `MPATHTEST_VERBOSITY` to @@ -37,15 +48,21 @@ This test includes test items that require a access to a block device. The device will be opened in read-only mode; you don't need to worry about data loss. However, the user needs to specify a device to be used. Set the environment variable `DIO_TEST_DEV` to the path of the device. -Alternatively, create a file `directio_test_dev` under -the `tests` directory containing a single line that sets this environment -variable in Bourne Shell syntax, like this: - - DIO_TEST_DEV=/dev/sdc3 - After that, run `make directio.out` as root in the `tests` directory to perform the test. +With a real test device, the test results may note be 100% reproducible, +and sporadic test failures may occur under certain circumstances. +It may be necessary to introduce a certain delay between test +operations. To do so, set the environment variable `DIO_TEST_DELAY` to a +positive integer that determines the delay (in microseconds) after each +`io_submit()` operation. The default delay is 10 microseconds. + +*Note:* `DIO_TEST_DEV` doesn't have to be set during compilation of +`directio-test`. This used to be the case in previous versions of +multipath-tools. Previously, it was possible to set `DIO_TEST_DEV` in a file +`tests/directio_test_dev`. This is not supported any more. + ## Adding tests The unit tests are based on the [cmocka test framework](https://cmocka.org/), diff --git a/tests/directio.c b/tests/directio.c index d5f84f10b..763929e53 100644 --- a/tests/directio.c +++ b/tests/directio.c @@ -34,6 +34,8 @@ struct io_event mock_events[AIO_GROUP_SIZE]; /* same as the checker max */ int ev_off = 0; struct timespec zero_timeout = { .tv_sec = 0 }; struct timespec full_timeout = { .tv_sec = -1 }; +const char *test_dev = NULL; +unsigned int test_delay = 10000; #ifdef __GLIBC__ #define ioctl_request_t unsigned long @@ -45,12 +47,13 @@ int REAL_IOCTL(int fd, ioctl_request_t request, void *argp); int WRAP_IOCTL(int fd, ioctl_request_t request, void *argp) { -#ifdef DIO_TEST_DEV - mock_type(int); - return REAL_IOCTL(fd, request, argp); -#else int *blocksize = (int *)argp; + if (test_dev) { + mock_type(int); + return REAL_IOCTL(fd, request, argp); + } + assert_int_equal(fd, test_fd); /* * On MUSL libc, the "request" arg is an int (glibc: unsigned long). @@ -64,88 +67,80 @@ int WRAP_IOCTL(int fd, ioctl_request_t request, void *argp) assert_non_null(blocksize); *blocksize = mock_type(int); return 0; -#endif } int REAL_FCNTL (int fd, int cmd, long arg); int WRAP_FCNTL (int fd, int cmd, long arg) { -#ifdef DIO_TEST_DEV - return REAL_FCNTL(fd, cmd, arg); -#else + if (test_dev) + return REAL_FCNTL(fd, cmd, arg); assert_int_equal(fd, test_fd); assert_int_equal(cmd, F_GETFL); return O_DIRECT; -#endif } int __real___fxstat(int ver, int fd, struct stat *statbuf); int __wrap___fxstat(int ver, int fd, struct stat *statbuf) { -#ifdef DIO_TEST_DEV - return __real___fxstat(ver, fd, statbuf); -#else + if (test_dev) + return __real___fxstat(ver, fd, statbuf); + assert_int_equal(fd, test_fd); assert_non_null(statbuf); memset(statbuf, 0, sizeof(struct stat)); return 0; -#endif + } int __real_io_setup(int maxevents, io_context_t *ctxp); int __wrap_io_setup(int maxevents, io_context_t *ctxp) { - ioctx_count++; -#ifdef DIO_TEST_DEV int ret = mock_type(int); - assert_int_equal(ret, __real_io_setup(maxevents, ctxp)); + + if (test_dev) + assert_int_equal(ret, __real_io_setup(maxevents, ctxp)); + ioctx_count++; return ret; -#else - return mock_type(int); -#endif } int __real_io_destroy(io_context_t ctx); int __wrap_io_destroy(io_context_t ctx) { - ioctx_count--; -#ifdef DIO_TEST_DEV int ret = mock_type(int); - assert_int_equal(ret, __real_io_destroy(ctx)); + + ioctx_count--; + if (test_dev) + assert_int_equal(ret, __real_io_destroy(ctx)); + return ret; -#else - return mock_type(int); -#endif } int __real_io_submit(io_context_t ctx, long nr, struct iocb *ios[]); int __wrap_io_submit(io_context_t ctx, long nr, struct iocb *ios[]) { -#ifdef DIO_TEST_DEV - struct timespec dev_delay = { .tv_nsec = 100000 }; int ret = mock_type(int); - assert_int_equal(ret, __real_io_submit(ctx, nr, ios)); - nanosleep(&dev_delay, NULL); + + if (test_dev) { + struct timespec dev_delay = { .tv_nsec = test_delay }; + assert_int_equal(ret, __real_io_submit(ctx, nr, ios)); + nanosleep(&dev_delay, NULL); + } return ret; -#else - return mock_type(int); -#endif } int __real_io_cancel(io_context_t ctx, struct iocb *iocb, struct io_event *evt); int __wrap_io_cancel(io_context_t ctx, struct iocb *iocb, struct io_event *evt) { -#ifdef DIO_TEST_DEV - return __real_io_cancel(ctx, iocb, evt); -#else - return 0; -#endif + if (test_dev) + return __real_io_cancel(ctx, iocb, evt); + else + return 0; } int REAL_IO_GETEVENTS(io_context_t ctx, long min_nr, long nr, @@ -155,38 +150,43 @@ int WRAP_IO_GETEVENTS(io_context_t ctx, long min_nr, long nr, struct io_event *events, struct timespec *timeout) { int nr_evs; -#ifndef DIO_TEST_DEV struct timespec *sleep_tmo; int i; struct io_event *evs; -#endif assert_non_null(timeout); nr_evs = mock_type(int); assert_true(nr_evs <= nr); if (!nr_evs) return 0; -#ifdef DIO_TEST_DEV - mock_ptr_type(struct timespec *); - mock_ptr_type(struct io_event *); - assert_int_equal(nr_evs, REAL_IO_GETEVENTS(ctx, min_nr, nr_evs, - events, timeout)); -#else - sleep_tmo = mock_ptr_type(struct timespec *); - if (sleep_tmo) { - if (sleep_tmo->tv_sec < 0) - nanosleep(timeout, NULL); - else - nanosleep(sleep_tmo, NULL); - } - if (nr_evs < 0) { - errno = -nr_evs; - return -1; + if (test_dev) { + int n = 0; + mock_ptr_type(struct timespec *); + mock_ptr_type(struct io_event *); + + condlog(2, "min_nr = %ld nr_evs = %d", min_nr, nr_evs); + while (n < nr_evs) { + min_nr = min_nr <= nr_evs - n ? min_nr : nr_evs - n; + n += REAL_IO_GETEVENTS(ctx, min_nr, nr_evs - n, + events + n, timeout); + } + assert_int_equal(nr_evs, n); + } else { + sleep_tmo = mock_ptr_type(struct timespec *); + if (sleep_tmo) { + if (sleep_tmo->tv_sec < 0) + nanosleep(timeout, NULL); + else + nanosleep(sleep_tmo, NULL); + } + if (nr_evs < 0) { + errno = -nr_evs; + return -1; + } + evs = mock_ptr_type(struct io_event *); + for (i = 0; i < nr_evs; i++) + events[i] = evs[i]; } - evs = mock_ptr_type(struct io_event *); - for (i = 0; i < nr_evs; i++) - events[i] = evs[i]; -#endif ev_off -= nr_evs; return nr_evs; } @@ -259,10 +259,9 @@ static void do_libcheck_init(struct checker *c, int blocksize, assert_non_null(ct->req); if (req) *req = ct->req; -#ifndef DIO_TEST_DEV - /* don't check fake blocksize on real devices */ - assert_int_equal(ct->req->blksize, blocksize); -#endif + if (!test_dev) + /* don't check fake blocksize on real devices */ + assert_int_equal(ct->req->blksize, blocksize); } static int is_checker_running(struct checker *c) @@ -583,11 +582,11 @@ static void test_async_timeout_cancel_failed(void **state) do_check_state(&c[1], 0, 2, PATH_PENDING); return_io_getevents_none(); do_check_state(&c[0], 0, 2, PATH_DOWN); -#ifndef DIO_TEST_DEV - /* can't pick which even gets returned on real devices */ - return_io_getevents_nr(NULL, 1, &reqs[1], &res[1]); - do_check_state(&c[1], 0, 2, PATH_UP); -#endif + if (!test_dev) { + /* can't pick which even gets returned on real devices */ + return_io_getevents_nr(NULL, 1, &reqs[1], &res[1]); + do_check_state(&c[1], 0, 2, PATH_UP); + } return_io_getevents_none(); do_check_state(&c[0], 0, 2, PATH_DOWN); assert_true(is_checker_running(&c[0])); @@ -663,12 +662,11 @@ static void test_check_state_blksize(void **state) int blksize[] = {4096, 1024, 512}; struct async_req *reqs[3]; int res[] = {0,1,0}; -#ifdef DIO_TEST_DEV - /* can't pick event return state on real devices */ int chk_state[] = {PATH_UP, PATH_UP, PATH_UP}; -#else - int chk_state[] = {PATH_UP, PATH_DOWN, PATH_UP}; -#endif + + /* can't pick event return state on real devices */ + if (!test_dev) + chk_state[1] = PATH_DOWN; assert_true(list_empty(&aio_grp_list)); will_return(__wrap_io_setup, 0); @@ -718,20 +716,38 @@ static void test_check_state_async(void **state) static int setup(void **state) { -#ifdef DIO_TEST_DEV - test_fd = open(DIO_TEST_DEV, O_RDONLY); - if (test_fd < 0) - fail_msg("cannot open %s: %m", DIO_TEST_DEV); -#endif + char *dl = getenv("DIO_TEST_DELAY"); + test_dev = getenv("DIO_TEST_DEV"); + + if (test_dev) { + condlog(2, "%s: opening %s", __func__, test_dev); + test_fd = open(test_dev, O_RDONLY); + if (dl) { + char *e; + long int d = strtol(dl, &e, 10); + + if (*e == '\0' && d >= 0 && (d * 1000) < (long)UINT_MAX) + test_delay = d * 1000; + else { + condlog(1, "DIO_TEST_DELAY=%s is invalid", dl); + return 1; + } + } + condlog(2, "%s: delay = %u us", __func__, test_delay / 1000); + } + if (test_fd < 0) { + fail_msg("cannot open %s: %m", test_dev); + return 1; + } return 0; } static int teardown(void **state) { -#ifdef DIO_TEST_DEV - assert_true(test_fd > 0); - assert_int_equal(close(test_fd), 0); -#endif + if (test_dev) { + assert_true(test_fd > 0); + assert_int_equal(close(test_fd), 0); + } return 0; } @@ -762,7 +778,7 @@ int main(void) { int ret = 0; - init_test_verbosity(5); + init_test_verbosity(2); ret += test_directio(); return ret; } From fd4ccb6ec536b2e14d3e3f72b68078a7607b88bf Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 10 Jul 2024 15:46:35 +0200 Subject: [PATCH 058/145] Makefile: add targets for test-progs.cpio and test-progs.tar Signed-off-by: Martin Wilck --- Makefile | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 14bbac246..f06f7faa9 100644 --- a/Makefile +++ b/Makefile @@ -16,10 +16,13 @@ LIB_BUILDDIRS += \ libdmmp endif -BUILDDIRS := $(LIB_BUILDDIRS) \ +PLUGIN_BUILDDIRS := \ libmultipath/prioritizers \ libmultipath/checkers \ libmultipath/foreign \ + +BUILDDIRS := $(LIB_BUILDDIRS) \ + $(PLUGIN_BUILDDIRS) \ multipath \ multipathd \ mpathpersist \ @@ -123,6 +126,16 @@ test: all valgrind-test: all @$(MAKE) -C tests valgrind +TEST-ARTIFACTS := config.mk Makefile.inc \ + $(LIB_BUILDDIRS:%=%/*.so*) $(PLUGIN_BUILDDIRS:%=%/*.so) \ + tests/Makefile tests/*.so* tests/lib/* tests/*-test + +test-progs.cpio: test-progs + @printf "%s\\n" $(TEST-ARTIFACTS) | cpio -o -H crc >$@ + +test-progs.tar: test-progs + @tar cf $@ $(TEST-ARTIFACTS) + .PHONY: TAGS TAGS: @etags -a libmultipath/*.c From d1af020a089a5a13f8f82ea9b2cac7b3c7ab8938 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 10 Jul 2024 21:41:57 +0200 Subject: [PATCH 059/145] multipath-tools tests: Fix .SECONDARY in Makefile for GNU make 4.4 In some GitHub CI workflows, we create archives of test binaries to be restored and installed in a different environment. These can by run with "make -C tests". But make 4.4 changed the way how missing explicit dependencies are treated in pattern rules. Thus make 4.4 and newer would attempt to rebuild some of the test programs in the new environment, which would fail because of missing devel files and tools. Fix this by adding all additional dependencies to .SECONDARY. See https://savannah.gnu.org/bugs/index.php?65972 for further details. Signed-off-by: Martin Wilck --- tests/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Makefile b/tests/Makefile index 02580e738..28c00ad2d 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -91,7 +91,7 @@ clean: test_clean valgrind_clean dep_clean $(Q)$(RM) $(TESTS:%=%-test) $(OBJS) *.o.wrap $(Q)$(RM) -rf lib conf.d -.SECONDARY: $(OBJS) +.SECONDARY: $(OBJS) $(foreach T,$(TESTS),$($T-test_OBJDEPS)) $(HELPERS:%=%.wrap) include $(wildcard $(OBJS:.o=.d)) From ca083e01c42ecd7c203bafe868ee826baac4ede6 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 18 Jul 2024 12:30:41 +0200 Subject: [PATCH 060/145] GitHub workflows: native.yaml: fix os name for Debian Jessie matrix.os is "debian-jessie", not just "jessie". Signed-off-by: Martin Wilck --- .github/workflows/native.yaml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/native.yaml b/.github/workflows/native.yaml index a062845e4..f07b414ae 100644 --- a/.github/workflows/native.yaml +++ b/.github/workflows/native.yaml @@ -40,21 +40,22 @@ jobs: - name: checkout uses: actions/checkout@v1 - name: build and test - if: ${{ matrix.os != 'jessie' }} - run: make test + if: ${{ matrix.os != 'debian-jessie' }} + run: make -j -Orecurse test - name: build and test (jessie) # On jessie, we use libreadline 5 (no licensing issue) - if: ${{ matrix.os == 'jessie' }} - run: make -j -Orecurse READLINE=libreadline test + if: ${{ matrix.os == 'debian-jessie' }} + run: make -j -Orecurse READLINE=libreadline test + - name: clean run: make clean - name: clang - if: ${{ matrix.os != 'jessie' }} + if: ${{ matrix.os != 'debian-jessie' }} env: CC: clang run: make -j -Orecurse test - name: clang (jessie) - if: ${{ matrix.os == 'jessie' }} + if: ${{ matrix.os == 'debian-jessie' }} env: CC: clang run: make READLINE=libreadline test From 1be2f9ae0c33b567b05c674b7377b341eff1dffd Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 10 Jul 2024 21:58:43 +0200 Subject: [PATCH 061/145] GitHub workflows: native.yml: run root tests Signed-off-by: Martin Wilck --- .github/workflows/native.yaml | 66 +++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/.github/workflows/native.yaml b/.github/workflows/native.yaml index f07b414ae..80ff6df56 100644 --- a/.github/workflows/native.yaml +++ b/.github/workflows/native.yaml @@ -47,6 +47,21 @@ jobs: if: ${{ matrix.os == 'debian-jessie' }} run: make -j -Orecurse READLINE=libreadline test + - name: set archive name + # Leap containers have cpio but not tar + run: echo ARCHIVE_TGT=test-progs.cpio >> $GITHUB_ENV + if: ${{ matrix.os == 'opensuse-leap' }} + - name: set archive name + run: echo ARCHIVE_TGT=test-progs.tar >> $GITHUB_ENV + if: ${{ matrix.os != 'opensuse-leap' }} + - name: create binary archive + run: make ${{ env.ARCHIVE_TGT }} + - name: upload binary archive + uses: actions/upload-artifact@v1 + with: + name: native-${{ matrix.os }} + path: ${{ env.ARCHIVE_TGT }} + - name: clean run: make clean - name: clang @@ -59,3 +74,54 @@ jobs: env: CC: clang run: make READLINE=libreadline test + + root-test: + runs-on: ubuntu-22.04 + needs: stable + strategy: + fail-fast: false + matrix: + os: + - debian-jessie + - debian-buster + - debian-bullseye + - debian-bookworm + - fedora-40 + - opensuse-leap + steps: + - name: mpath + run: sudo modprobe dm_multipath + - name: brd + run: sudo modprobe brd rd_nr=1 rd_size=65536 + + - name: checkout + uses: actions/checkout@v1 + + - name: download binary archive + uses: actions/download-artifact@v1 + with: + name: native-${{ matrix.os }} + - name: unpack binary archive + run: cpio -idv < native-${{ matrix.os }}/test-progs.cpio + if: ${{ matrix.os == 'opensuse-leap' }} + - name: unpack binary archive + run: tar xfmv native-${{ matrix.os }}/test-progs.tar + if: ${{ matrix.os != 'opensuse-leap' }} + + - name: run root tests + uses: mosteo-actions/docker-run@v1 + with: + image: ghcr.io/mwilck/multipath-build-${{ matrix.os }} + guest-dir: /__w/multipath-tools/multipath-tools + host-dir: ${{ github.workspace }} + params: > + --workdir /__w/multipath-tools/multipath-tools --privileged + -v /dev/ram0:/dev/ram0 -e DIO_TEST_DEV=/dev/ram0 + command: -C tests directio.out dmevents.out + id: root-test + continue-on-error: true + - name: show root test output + run: for o in tests/*.out; do echo "===== $o ====="; cat "$o"; done + - name: fail + run: /bin/false + if: ${{ steps.root-test.outcome == 'failure' }} From 5cb497df8f509ffe411bbcaad9921c77a8b3e30b Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Tue, 16 Jul 2024 20:32:08 +0200 Subject: [PATCH 062/145] GitHub workflows: foreign.yaml: run dmevents test as root Running the directio test doesn't work because aio is not supported under qemu-linux-user. So dmevents is the only current test that makes sense to run as root. Signed-off-by: Martin Wilck --- .github/workflows/foreign.yaml | 68 ++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 12 deletions(-) diff --git a/.github/workflows/foreign.yaml b/.github/workflows/foreign.yaml index a62ae0098..9e4d35e0f 100644 --- a/.github/workflows/foreign.yaml +++ b/.github/workflows/foreign.yaml @@ -36,20 +36,14 @@ jobs: - name: checkout uses: actions/checkout@v1 - name: build - run: make -j8 -Orecurse TESTDIR=/build/tests test-progs + run: make -j8 -Orecurse test-progs - name: create binary archive - run: > - tar cfv binaries.tar - Makefile* config.mk - libmpathcmd/*.so* libmultipath/*.so* libmpathutil/*.so* - libmultipath/checkers/*.so libmultipath/prioritizers/*.so - libmultipath/foreign/*.so - tests/lib tests/*-test tests/Makefile tests/*.so* + run: make test-progs.tar - name: upload binary archive uses: actions/upload-artifact@v1 with: name: cross-${{ matrix.os }}-${{ matrix.arch }} - path: binaries.tar + path: test-progs.tar test: runs-on: ubuntu-22.04 @@ -71,15 +65,65 @@ jobs: with: name: cross-${{ matrix.os }}-${{ matrix.arch }} - name: unpack binary archive - run: tar xfv cross-${{ matrix.os }}-${{ matrix.arch }}/binaries.tar + run: tar xfv cross-${{ matrix.os }}-${{ matrix.arch }}/test-progs.tar - name: enable foreign arch uses: dbhi/qus/action@main - name: run tests uses: mosteo-actions/docker-run@v1 with: image: ghcr.io/mwilck/multipath-run-debian-${{ matrix.os }} - guest-dir: /build + guest-dir: /__w/multipath-tools/multipath-tools host-dir: ${{ github.workspace }} command: -C tests - params: "--platform linux/${{ env.CONTAINER_ARCH }}" + params: > + --workdir /__w/multipath-tools/multipath-tools + --platform linux/${{ env.CONTAINER_ARCH }} pull-params: "--platform linux/${{ env.CONTAINER_ARCH }}" + + root-test: + runs-on: ubuntu-22.04 + needs: cross-build + strategy: + fail-fast: false + matrix: + os: [bookworm, sid] + arch: [ppc64le, arm64, s390x] + steps: + - name: mpath + run: sudo modprobe dm_multipath + - name: brd + run: sudo modprobe brd rd_nr=1 rd_size=65536 + - name: set container arch + run: echo CONTAINER_ARCH="${{ matrix.arch }}" >> $GITHUB_ENV + if: ${{ matrix.arch != 'armhf' }} + - name: set container arch + run: echo CONTAINER_ARCH="arm/v7" >> $GITHUB_ENV + if: ${{ matrix.arch == 'armhf' }} + - name: download binary archive + uses: actions/download-artifact@v1 + with: + name: cross-${{ matrix.os }}-${{ matrix.arch }} + - name: unpack binary archive + run: tar xfv cross-${{ matrix.os }}-${{ matrix.arch }}/test-progs.tar + - name: enable foreign arch + uses: dbhi/qus/action@main + - name: run tests + uses: mosteo-actions/docker-run@v1 + with: + image: ghcr.io/mwilck/multipath-run-debian-${{ matrix.os }} + guest-dir: /__w/multipath-tools/multipath-tools + host-dir: ${{ github.workspace }} + command: -C tests dmevents.out + params: > + --workdir /__w/multipath-tools/multipath-tools + --platform linux/${{ env.CONTAINER_ARCH }} + --privileged + -v /dev/ram0:/dev/ram0 -e DIO_TEST_DEV=/dev/ram0 + pull-params: "--platform linux/${{ env.CONTAINER_ARCH }}" + id: root-test + continue-on-error: true + - name: show root test output + run: for o in tests/*.out; do echo "===== $o ====="; cat "$o"; done + - name: fail + run: /bin/false + if: ${{ steps.root-test.outcome == 'failure' }} From 70a2680ecd216e6af904421fbcd440be17da7625 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 18 Jul 2024 12:37:44 +0200 Subject: [PATCH 063/145] GitHub workflows: spelling fixes Signed-off-by: Martin Wilck --- .github/actions/spelling/expect.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index def43a522..78b5fc5e2 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -102,6 +102,7 @@ libdevmapper libdmmp libedit libjson +libmpathcmd libmpathpersist libmpathutil libmpathvalid @@ -205,6 +206,7 @@ sysfs sysinit tcp terabytes +SYSDIR TESTDEPS testname tgill From c5314043f48b71e73fd9065d86f8f62083a5960c Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 18 Jul 2024 17:12:42 +0200 Subject: [PATCH 064/145] fixup "libmultipath tests: add tests for libmp_mapinfo()" The mapinfo test had a workaround for the fact that on glibc < 2.20 strdup() is a macro. It turns out that we need the same workaround for 2.22. Signed-off-by: Martin Wilck --- tests/mapinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/mapinfo.c b/tests/mapinfo.c index f7ad86822..fca6462f6 100644 --- a/tests/mapinfo.c +++ b/tests/mapinfo.c @@ -13,7 +13,7 @@ #ifndef __GLIBC_PREREQ #define __GLIBC_PREREQ(x, y) 0 #endif -#if defined(__GLIBC__) && !(__GLIBC_PREREQ(2, 20)) +#if defined(__GLIBC__) && !(__GLIBC_PREREQ(2, 23)) #define __NO_STRING_INLINES 1 #endif From d07c0fba02ec6f0c89792e0b8a6cec2850e0996b Mon Sep 17 00:00:00 2001 From: Xose Vazquez Perez Date: Wed, 17 Jul 2024 11:51:07 +0200 Subject: [PATCH 065/145] multipath-tools: remove duplicate headers Minimal cleaning done with scripts/checkincludes.pl Cc: Martin Wilck Cc: Benjamin Marzinski Cc: Christophe Varoqui Cc: DM-DEVEL ML Signed-off-by: Xose Vazquez Perez Reviewed-by: Martin Wilck --- libmpathutil/msort.c | 1 - multipathd/cli_handlers.c | 1 - 2 files changed, 2 deletions(-) diff --git a/libmpathutil/msort.c b/libmpathutil/msort.c index 2963486ee..50f799d91 100644 --- a/libmpathutil/msort.c +++ b/libmpathutil/msort.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include "msort.h" diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c index 0106213ee..7eb76337b 100644 --- a/multipathd/cli_handlers.c +++ b/multipathd/cli_handlers.c @@ -31,7 +31,6 @@ #include "foreign.h" #include "strbuf.h" #include "cli_handlers.h" -#include "devmapper.h" static struct path * find_path_by_str(const struct _vector *pathvec, const char *str, From e0d873c70555b3a6ad24082870e12f8ed747b635 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 18 Jul 2024 18:39:04 +0200 Subject: [PATCH 066/145] libmultipath.version: remove dm_get_wwid() Since 0e2fd75 ("multipathd: implement add_map_without_path() with libmp_mapinfo()"), this function doesn't need to be exported any more. Signed-off-by: Martin Wilck --- libmultipath/libmultipath.version | 1 - 1 file changed, 1 deletion(-) diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index 959f675e2..5784e5a38 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -81,7 +81,6 @@ global: dm_get_major_minor; dm_get_maps; dm_get_multipath; - dm_get_wwid; dm_is_mpath; dm_mapname; dm_prereq; From 787e00dbe930ffac8eac85c7314558e8966e9e00 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 18 Jul 2024 18:32:17 +0200 Subject: [PATCH 067/145] Update README.md Signed-off-by: Martin Wilck --- .github/actions/spelling/expect.txt | 2 ++ .github/actions/spelling/patterns.txt | 3 +++ NEWS.md | 30 +++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index 78b5fc5e2..ccb04baad 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -59,6 +59,7 @@ EVPD failback failover fds +fexceptions FFFFFFFF fge followover @@ -90,6 +91,7 @@ igroup img inotify inttypes +ioctls iscsi isw kpartx diff --git a/.github/actions/spelling/patterns.txt b/.github/actions/spelling/patterns.txt index aa361654a..27d42d904 100644 --- a/.github/actions/spelling/patterns.txt +++ b/.github/actions/spelling/patterns.txt @@ -22,6 +22,7 @@ \bdmmp_pgs\b \bdmmp_mpath_kdev_name_get\b \bfast_io_fail_tmo\b +\blibmp_mapinfo\b \bLimitRTPRIO=?\b \bmax_fds\b \bmissing_uev_wait_timeout\b @@ -101,5 +102,7 @@ \bHBAs\b \bSANtricity\b \bVTrak\b +\bXSG1\b + diff --git a/NEWS.md b/NEWS.md index 5b3f131c6..f85938603 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,35 @@ # multipath-tools Release Notes +## multipath-tools 0.9.x (in preparation) + +### User-Visible Changes + +* Add hardware defaults for Huawei storage arrays and XSG1 vendors + +### Other major changes + +* Refactored a significant part of the libmultipath / libdevmapper interface. + All functions that retrieve information about DM maps have been converted + to use just one worker function, libmp_mapinfo(). This reduces code size + while providing more flexibility and efficiency (less device-mapper ioctls). + Also, cleanup attributes are used consistently in the libdevmapper-related code. +* Made map removal more efficient by avoiding unnecessary recursion. + +### Bug fixes + +* Fixed bug that caused queueing to be always disabled if flushing a map failed + (bug introduced in 0.9.8). +* Fixed failure to remove maps even with `deferred_remove` (bug introduced in 0.9.9). + +### Other + +* Use `-fexceptions` during compilation to make sure cleanup code is executed + when threads are cancelled +* Fixed CI for ARM/v7 +* Remove hardcoded paths and make them configurable instead. + This should improve compatibility e.g. with NixOS. +* Fixed directio CI test for real devices, run more "real" tests in CI + ## multipath-tools 0.9.9, 2024/05 ### Important note From 50f4990f6b902c90d0f766832330499209bf1e9b Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 18 Jul 2024 19:31:12 +0200 Subject: [PATCH 068/145] libmpathcmd: check len parameter in mpath_recv_reply_data() Found by coverity. Callers check this parameter already, but the function is exported by libmpathcmd, so make sure we don't write '\0' to reply[-1]. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathcmd/mpath_cmd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libmpathcmd/mpath_cmd.c b/libmpathcmd/mpath_cmd.c index 60b2d965e..d7c3371e7 100644 --- a/libmpathcmd/mpath_cmd.c +++ b/libmpathcmd/mpath_cmd.c @@ -170,6 +170,8 @@ int mpath_recv_reply_data(int fd, char *reply, size_t len, { ssize_t ret; + if (len <= 0) + return 0; ret = read_all(fd, reply, len, timeout); if (ret < 0) return ret; From 77340e7dee6c8aa3ccc8d4720ec291b9f96c326e Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 18 Jul 2024 20:18:39 +0200 Subject: [PATCH 069/145] multipath-tools: use signed loop variable in vector_foreach_slot If we delete entries in the vector_foreach_slot loop, the loop index may underflow. It's not a big issue because we re-increment it in the next iteration and use a cast to int in the loop end condition, but it's cleaner to use an int here. Found by coverity. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- multipathd/main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 13ed6d058..be3503824 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -762,7 +762,7 @@ coalesce_maps(struct vectors *vecs, vector nmpv) { struct multipath * ompp; vector ompv = vecs->mpvec; - unsigned int i, reassign_maps; + int i, reassign_maps; struct config *conf; conf = get_multipath_config(); @@ -1748,7 +1748,7 @@ static int map_discovery (struct vectors * vecs) { struct multipath * mpp; - unsigned int i; + int i; if (dm_get_maps(vecs->mpvec)) return 1; @@ -1970,7 +1970,7 @@ static void mpvec_garbage_collector (struct vectors * vecs) { struct multipath * mpp; - unsigned int i; + int i; if (!vecs->mpvec) return; @@ -2014,7 +2014,7 @@ static void missing_uev_wait_tick(struct vectors *vecs) { struct multipath * mpp; - unsigned int i; + int i; int timed_out = 0; vector_foreach_slot (vecs->mpvec, mpp, i) { @@ -2039,7 +2039,7 @@ static void ghost_delay_tick(struct vectors *vecs) { struct multipath * mpp; - unsigned int i; + int i; vector_foreach_slot (vecs->mpvec, mpp, i) { if (mpp->ghost_delay_tick <= 0) From a2a16ad6446cf0f734a3b72eb007edd182d20260 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 18 Jul 2024 20:41:23 +0200 Subject: [PATCH 070/145] libmpathutil: avoid size_t underflow in strchop() Found by coverity. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathutil/util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libmpathutil/util.c b/libmpathutil/util.c index 67db3c8a1..9c422f1f0 100644 --- a/libmpathutil/util.c +++ b/libmpathutil/util.c @@ -27,8 +27,8 @@ strchop(char *str) { size_t i; - for (i = strlen(str) - 1; i != (size_t) -1 && isspace(str[i]); i--) ; - str[++i] = '\0'; + for (i = strlen(str); i != 0 && isspace(str[i - 1]); i--) ; + str[i] = '\0'; return i; } From 7668f4bdf845f2c98cdcf660a037c3960901b42a Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 18 Jul 2024 20:43:39 +0200 Subject: [PATCH 071/145] fixup "libmultipath: use libmp_pathinfo() in update_multipath_table()" We need to check for NULL before dereferencing mpp. Found by coverity. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/structs_vec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libmultipath/structs_vec.c b/libmultipath/structs_vec.c index 731b1bce6..d58ef5a73 100644 --- a/libmultipath/structs_vec.c +++ b/libmultipath/structs_vec.c @@ -504,11 +504,12 @@ update_multipath_table (struct multipath *mpp, vector pathvec, int flags) int r = DMP_ERR; char __attribute__((cleanup(cleanup_charp))) *params = NULL; char __attribute__((cleanup(cleanup_charp))) *status = NULL; - unsigned long long size = mpp->size; + unsigned long long size; if (!mpp) return r; + size = mpp->size; r = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, (mapid_t) { .str = mpp->alias }, (mapinfo_t) { From db1e72679bf1ba04b75f93936272b5a420918359 Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 24 Jul 2024 14:17:12 -0400 Subject: [PATCH 072/145] libmpathpersist: set mpp->mpe before selecting reservation_key libmpathpersist was not setting mpp->mpe before calling select_reservation_key(). This means that if the reservation key was set in the multipaths sections, it wasn't being selected. This appeared to work for many commands because of an error in checking if the correct reservation key was used. If mpp->reservation key was unset, then it would considered to match if either the RK or SARK was unset in the command. mpathpersist should fail if it doesn't find a configured mpp->resevation key, with one exception. To make it easier to remove old keys, if --register-ignore is called, and the command SARK is 0x0 so the device is being unregistered, allow mpp->reservation_key to be unset. The code already allows mpp->reservation_key to not match the command RK in this case. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- libmpathpersist/mpath_persist_int.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libmpathpersist/mpath_persist_int.c b/libmpathpersist/mpath_persist_int.c index f4d9e7c85..95bbdcd89 100644 --- a/libmpathpersist/mpath_persist_int.c +++ b/libmpathpersist/mpath_persist_int.c @@ -652,6 +652,7 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd, return ret; conf = get_multipath_config(); + mpp->mpe = find_mpe(conf->mptable, mpp->wwid); select_reservation_key(conf, mpp); select_all_tg_pt(conf, mpp); put_multipath_config(conf); @@ -671,6 +672,12 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd, } } + if (!get_be64(mpp->reservation_key) && + (prkey || rq_servact != MPATH_PROUT_REG_IGN_SA)) { + condlog(0, "%s: no configured reservation key", mpp->alias); + return MPATH_PR_SYNTAX_ERROR; + } + if (memcmp(paramp->key, &mpp->reservation_key, 8) && memcmp(paramp->sa_key, &mpp->reservation_key, 8) && (prkey || rq_servact != MPATH_PROUT_REG_IGN_SA)) { From e1ae74f0890a591f255241b7f859a33e4af1172e Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 17 Jul 2024 14:10:47 -0400 Subject: [PATCH 073/145] libmultipath: rename dm_map_present_by_wwid() and add outputs add arguments to dm_map_present_by_wwid() to allow optionally fetching the device name and dm info for the devices found by WWID. These will be used by a later patch. Since it can now also be used to get the name and dm info of a device from its WWID, rename it to dm_find_map_by_wwid() Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- libmultipath/devmapper.c | 5 +++-- libmultipath/devmapper.h | 2 +- libmultipath/valid.c | 2 +- tests/valid.c | 13 +++++++------ 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 3b2e8ac27..0347a17c7 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -874,7 +874,8 @@ int dm_is_mpath(const char *name) } } -int dm_map_present_by_wwid(const char *wwid) +/* if name is non-NULL, it must point to an array of WWID_SIZE bytes */ +int dm_find_map_by_wwid(const char *wwid, char *name, struct dm_info *dmi) { char tmp[DM_UUID_LEN]; @@ -883,7 +884,7 @@ int dm_map_present_by_wwid(const char *wwid) return libmp_mapinfo(DM_MAP_BY_UUID, (mapid_t) { .str = tmp }, - (mapinfo_t) { .name = NULL }); + (mapinfo_t) { .name = name, .dmi = dmi }); } static int dm_dev_t (const char *mapname, char *dev_t, int len) diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index f6d0017ee..a26dc1e5d 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -132,7 +132,7 @@ int dm_simplecmd_flush (int task, const char *name, uint16_t udev_flags); int dm_simplecmd_noflush (int task, const char *name, uint16_t udev_flags); int dm_addmap_create (struct multipath *mpp, char *params); int dm_addmap_reload (struct multipath *mpp, char *params, int flush); -int dm_map_present_by_wwid(const char *uuid); +int dm_find_map_by_wwid(const char *wwid, char *name, struct dm_info *dmi); enum { DM_IS_MPATH_NO, diff --git a/libmultipath/valid.c b/libmultipath/valid.c index 9267cef9a..b7e0cc9b6 100644 --- a/libmultipath/valid.c +++ b/libmultipath/valid.c @@ -360,7 +360,7 @@ is_path_valid(const char *name, struct config *conf, struct path *pp, if (check_wwids_file(pp->wwid, 0) == 0) return PATH_IS_VALID_NO_CHECK; - if (dm_map_present_by_wwid(pp->wwid) == DMP_OK) + if (dm_find_map_by_wwid(pp->wwid, NULL, NULL) == DMP_OK) return PATH_IS_VALID; /* all these act like FIND_MULTIPATHS_STRICT for finding if a diff --git a/tests/valid.c b/tests/valid.c index a93bbe508..ecaeb4677 100644 --- a/tests/valid.c +++ b/tests/valid.c @@ -189,10 +189,11 @@ int __wrap_check_wwids_file(char *wwid, int write_wwid) return -1; } -int __wrap_dm_map_present_by_wwid(const char *uuid) +int __wrap_dm_find_map_by_wwid(const char *wwid, char *name, + struct dm_info *dmi) { int ret = mock_type(int); - assert_string_equal(uuid, mock_ptr_type(char *)); + assert_string_equal(wwid, mock_ptr_type(char *)); return ret; } @@ -271,8 +272,8 @@ static void setup_passing(char *name, char *wwid, unsigned int check_multipathd, will_return(__wrap_check_wwids_file, wwid); if (stage == STAGE_CHECK_WWIDS) return; - will_return(__wrap_dm_map_present_by_wwid, 0); - will_return(__wrap_dm_map_present_by_wwid, wwid); + will_return(__wrap_dm_find_map_by_wwid, 0); + will_return(__wrap_dm_find_map_by_wwid, wwid); } static void test_bad_arguments(void **state) @@ -516,8 +517,8 @@ static void test_check_uuid_present(void **state) memset(&pp, 0, sizeof(pp)); conf.find_multipaths = FIND_MULTIPATHS_STRICT; setup_passing(name, wwid, CHECK_MPATHD_RUNNING, STAGE_CHECK_WWIDS); - will_return(__wrap_dm_map_present_by_wwid, 1); - will_return(__wrap_dm_map_present_by_wwid, wwid); + will_return(__wrap_dm_find_map_by_wwid, 1); + will_return(__wrap_dm_find_map_by_wwid, wwid); assert_int_equal(is_path_valid(name, &conf, &pp, true), PATH_IS_VALID); assert_string_equal(pp.dev, name); From 4c8acd6e5bb432bbe53e3ea52cfb35c71ec8e8a7 Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 17 Jul 2024 14:10:48 -0400 Subject: [PATCH 074/145] multipathd: make cli_add_map() handle adding maps by WWID correctly cli_add_map() runs filter_wwid() on the input param as if it were a WWID, but dm_get_major_minor() will never find the multipath device if the user actually passes in a WWID. To handle this case, call get_refwwid() early in the function, and use dm_find_map_by_wwid() to check if the map exists, and find its alias and minor number. Also, the do/while loop is unnecessarily confusing and only avoids one repeated function call. Remove it to simplify cli_add_map(). Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- libmultipath/libmultipath.version | 5 +++ multipathd/cli_handlers.c | 60 +++++++++++-------------------- 2 files changed, 25 insertions(+), 40 deletions(-) diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index 5784e5a38..0ec45271a 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -241,3 +241,8 @@ global: local: *; }; + +LIBMULTIPATH_25.1.0 { +global: + dm_find_map_by_wwid; +} LIBMULTIPATH_25.0.0; diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c index 7eb76337b..924d06ecf 100644 --- a/multipathd/cli_handlers.c +++ b/multipathd/cli_handlers.c @@ -696,57 +696,37 @@ cli_add_map (void * v, struct strbuf *reply, void * data) { struct vectors * vecs = (struct vectors *)data; char * param = get_keyparam(v, KEY_MAP); - int major = -1, minor = -1; char dev_path[FILE_NAME_SIZE]; - char *refwwid; - char *alias __attribute__((cleanup(cleanup_charp))) = NULL; - int rc, count = 0; - struct config *conf; - int invalid = 0; + char *refwwid __attribute__((cleanup(cleanup_charp))) = NULL; + char alias[WWID_SIZE]; + int rc; + struct dm_info dmi; param = convert_dev(param, 0); condlog(2, "%s: add map (operator)", param); - conf = get_multipath_config(); - pthread_cleanup_push(put_multipath_config, conf); - if (filter_wwid(conf->blist_wwid, conf->elist_wwid, param, NULL) > 0) - invalid = 1; - pthread_cleanup_pop(1); - if (invalid) { + if (get_refwwid(CMD_NONE, param, DEV_DEVMAP, vecs->pathvec, &refwwid) == + PATHINFO_SKIPPED) { append_strbuf_str(reply, "blacklisted\n"); condlog(2, "%s: map blacklisted", param); return 1; + } else if (!refwwid) { + condlog(2, "%s: unknown map.", param); + return -ENODEV; } - do { - if (dm_get_major_minor(param, &major, &minor) < 0) - condlog(count ? 2 : 3, - "%s: not a device mapper table", param); - else { - sprintf(dev_path, "dm-%d", minor); - alias = dm_mapname(major, minor); + if (dm_find_map_by_wwid(refwwid, alias, &dmi) != DMP_OK) { + condlog(3, "%s: map not present. creating", param); + if (coalesce_paths(vecs, NULL, refwwid, FORCE_RELOAD_NONE, + CMD_NONE) != CP_OK) { + condlog(2, "%s: coalesce_paths failed", param); + return 1; + } + if (dm_find_map_by_wwid(refwwid, alias, &dmi) != DMP_OK) { + condlog(2, "%s: failed getting map", param); + return 1; } - /*if there is no mapname found, we first create the device*/ - if (!alias && !count) { - condlog(3, "%s: mapname not found for %d:%d", - param, major, minor); - get_refwwid(CMD_NONE, param, DEV_DEVMAP, - vecs->pathvec, &refwwid); - if (refwwid) { - if (coalesce_paths(vecs, NULL, refwwid, - FORCE_RELOAD_NONE, CMD_NONE) - != CP_OK) - condlog(2, "%s: coalesce_paths failed", - param); - free(refwwid); - } - } /*we attempt to create device only once*/ - count++; - } while (!alias && (count < 2)); - - if (!alias) { - condlog(2, "%s: add map failed", param); - return 1; } + sprintf(dev_path, "dm-%u", dmi.minor); rc = ev_add_map(dev_path, alias, vecs); return rc; } From 4c8310efb8f79e3f492fa92f1a55f2ea98f40118 Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 17 Jul 2024 14:10:49 -0400 Subject: [PATCH 075/145] multipathd: remove checker restart optimization Future commits will make this optimization unusable. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipathd/main.c | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index be3503824..8930ac97b 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -2704,7 +2704,7 @@ checkerloop (void *ap) while (1) { struct timespec diff_time, start_time, end_time; - int num_paths = 0, strict_timing, rc = 0, i = 0; + int num_paths = 0, strict_timing, rc = 0; unsigned int ticks = 0; enum checker_state checker_state = CHECKER_STARTING; @@ -2723,7 +2723,7 @@ checkerloop (void *ap) sd_notify(0, "WATCHDOG=1"); #endif while (checker_state != CHECKER_FINISHED) { - unsigned int paths_checked = 0; + unsigned int paths_checked = 0, i; struct timespec chk_start_time; pthread_cleanup_push(cleanup_lock, &vecs->lock); @@ -2733,28 +2733,11 @@ checkerloop (void *ap) if (checker_state == CHECKER_STARTING) { vector_foreach_slot(vecs->pathvec, pp, i) pp->is_checked = false; - i = 0; checker_state = CHECKER_RUNNING; - } else { - /* - * Paths could have been removed since we - * dropped the lock. Find the path to continue - * checking at. Since paths can be removed from - * anywhere in the vector, but can only be added - * at the end, the last checked path must be - * between its old location, and the start or - * the vector. - */ - if (i >= VECTOR_SIZE(vecs->pathvec)) - i = VECTOR_SIZE(vecs->pathvec) - 1; - while ((pp = VECTOR_SLOT(vecs->pathvec, i))) { - if (pp->is_checked == true) - break; - i--; - } - i++; } - vector_foreach_slot_after (vecs->pathvec, pp, i) { + vector_foreach_slot(vecs->pathvec, pp, i) { + if (pp->is_checked) + continue; pp->is_checked = true; rc = check_path(vecs, pp, ticks); if (rc < 0) { From a89243e2daec2d9b3d90e2e7a6f10286a3bb6797 Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 17 Jul 2024 14:10:50 -0400 Subject: [PATCH 076/145] multipathd: refactor path state getting code into a helper Pull the code that gets the new path state out into a helper function named check_path_state(), in preparation for splittig check_path() into two functions. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipathd/main.c | 64 ++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 8930ac97b..056834f1a 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -2305,6 +2305,43 @@ should_skip_path(struct path *pp){ return 0; } +static int +check_path_state(struct path *pp) +{ + int newstate; + struct config *conf; + + newstate = path_offline(pp); + if (newstate == PATH_UP) { + conf = get_multipath_config(); + pthread_cleanup_push(put_multipath_config, conf); + newstate = get_state(pp, conf, 1, newstate); + pthread_cleanup_pop(1); + } else { + checker_clear_message(&pp->checker); + condlog(3, "%s: state %s, checker not called", + pp->dev, checker_state_name(newstate)); + } + /* + * Wait for uevent for removed paths; + * some LLDDs like zfcp keep paths unavailable + * without sending uevents. + */ + if (newstate == PATH_REMOVED) + newstate = PATH_DOWN; + + if (newstate == PATH_WILD || newstate == PATH_UNCHECKED) { + condlog(2, "%s: unusable path (%s) - checker failed", + pp->dev, checker_state_name(newstate)); + LOG_MSG(2, pp); + conf = get_multipath_config(); + pthread_cleanup_push(put_multipath_config, conf); + pathinfo(pp, conf, 0); + pthread_cleanup_pop(1); + } + return newstate; +} + /* * Returns '1' if the path has been checked, '-1' if it was blacklisted * and '0' otherwise @@ -2384,33 +2421,8 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) */ pp->tick = checkint; - newstate = path_offline(pp); - if (newstate == PATH_UP) { - conf = get_multipath_config(); - pthread_cleanup_push(put_multipath_config, conf); - newstate = get_state(pp, conf, 1, newstate); - pthread_cleanup_pop(1); - } else { - checker_clear_message(&pp->checker); - condlog(3, "%s: state %s, checker not called", - pp->dev, checker_state_name(newstate)); - } - /* - * Wait for uevent for removed paths; - * some LLDDs like zfcp keep paths unavailable - * without sending uevents. - */ - if (newstate == PATH_REMOVED) - newstate = PATH_DOWN; - + newstate = check_path_state(pp); if (newstate == PATH_WILD || newstate == PATH_UNCHECKED) { - condlog(2, "%s: unusable path (%s) - checker failed", - pp->dev, checker_state_name(newstate)); - LOG_MSG(2, pp); - conf = get_multipath_config(); - pthread_cleanup_push(put_multipath_config, conf); - pathinfo(pp, conf, 0); - pthread_cleanup_pop(1); return 1; } else if ((newstate != PATH_UP && newstate != PATH_GHOST && newstate != PATH_PENDING) && (pp->state == PATH_DELAYED)) { From bc4f0b93dceb1bbb24a48d1a166402c0635f5ee2 Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 17 Jul 2024 14:10:51 -0400 Subject: [PATCH 077/145] multipathd: handle uninitialized paths in new function Pull the code to handle uninitialized paths out of check_path() and into a new function called handle_uninitialized_paths(). This should cause no functional changes. Also make check_path() static. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipathd/main.c | 168 ++++++++++++++++++++++++++++------------------ 1 file changed, 101 insertions(+), 67 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 056834f1a..e3f53bf19 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -2343,10 +2343,9 @@ check_path_state(struct path *pp) } /* - * Returns '1' if the path has been checked, '-1' if it was blacklisted - * and '0' otherwise + * Returns '1' if the path has been checked and '0' otherwise */ -int +static int check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) { int newstate; @@ -2354,16 +2353,13 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) int chkr_new_path_up = 0; int disable_reinstate = 0; int oldchkrstate = pp->chkrstate; - int retrigger_tries; unsigned int checkint, max_checkint; struct config *conf; int marginal_pathgroups, marginal_changed = 0; int ret; bool need_reload; - if (((pp->initialized == INIT_OK || pp->initialized == INIT_PARTIAL || - pp->initialized == INIT_REQUESTED_UDEV) && !pp->mpp) || - pp->initialized == INIT_REMOVED) + if (pp->initialized == INIT_REMOVED) return 0; if (pp->tick) @@ -2372,7 +2368,6 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) return 0; /* don't check this path yet */ conf = get_multipath_config(); - retrigger_tries = conf->retrigger_tries; checkint = conf->checkint; max_checkint = conf->max_checkint; marginal_pathgroups = conf->marginal_pathgroups; @@ -2383,38 +2378,6 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) pp->checkint = checkint; }; - if (!pp->mpp && pp->initialized == INIT_MISSING_UDEV) { - if (pp->retriggers < retrigger_tries) { - static const char change[] = "change"; - ssize_t ret; - - condlog(2, "%s: triggering change event to reinitialize", - pp->dev); - pp->initialized = INIT_REQUESTED_UDEV; - pp->retriggers++; - ret = sysfs_attr_set_value(pp->udev, "uevent", change, - sizeof(change) - 1); - if (ret != sizeof(change) - 1) - log_sysfs_attr_set_value(1, ret, - "%s: failed to trigger change event", - pp->dev); - return 0; - } else { - condlog(1, "%s: not initialized after %d udev retriggers", - pp->dev, retrigger_tries); - /* - * Make sure that the "add missing path" code path - * below may reinstate the path later, if it ever - * comes up again. - * The WWID needs not be cleared; if it was set, the - * state hadn't been INIT_MISSING_UDEV in the first - * place. - */ - pp->initialized = INIT_FAILED; - return 0; - } - } - /* * provision a next check soonest, * in case we exit abnormally from here @@ -2435,32 +2398,6 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) pp->checkint = checkint; return 1; } - if (!pp->mpp) { - if (!strlen(pp->wwid) && - (pp->initialized == INIT_FAILED || - pp->initialized == INIT_NEW) && - (newstate == PATH_UP || newstate == PATH_GHOST)) { - condlog(2, "%s: add missing path", pp->dev); - conf = get_multipath_config(); - pthread_cleanup_push(put_multipath_config, conf); - ret = pathinfo(pp, conf, DI_ALL | DI_BLACKLIST); - pthread_cleanup_pop(1); - /* INIT_OK implies ret == PATHINFO_OK */ - if (pp->initialized == INIT_OK) { - ev_add_path(pp, vecs, 1); - pp->tick = 1; - } else { - if (ret == PATHINFO_SKIPPED) - return -1; - /* - * We failed multiple times to initialize this - * path properly. Don't re-check too often. - */ - pp->checkint = max_checkint; - } - } - return 0; - } /* * Async IO in flight. Keep the previous path state * and reschedule as soon as possible @@ -2679,6 +2616,99 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) return 1; } +/* + * Returns -1 if the path was blacklisted, and 0 otherwise + */ +static int +handle_uninitialized_path(struct vectors * vecs, struct path * pp, + unsigned int ticks) +{ + int newstate; + int retrigger_tries; + unsigned int checkint, max_checkint; + struct config *conf; + int ret; + + if (pp->initialized != INIT_NEW && pp->initialized != INIT_FAILED && + pp->initialized != INIT_MISSING_UDEV) + return 0; + + if (pp->tick) + pp->tick -= (pp->tick > ticks) ? ticks : pp->tick; + if (pp->tick) + return 0; /* don't check this path yet */ + + conf = get_multipath_config(); + retrigger_tries = conf->retrigger_tries; + checkint = conf->checkint; + max_checkint = conf->max_checkint; + put_multipath_config(conf); + + if (pp->initialized == INIT_MISSING_UDEV) { + if (pp->retriggers < retrigger_tries) { + static const char change[] = "change"; + ssize_t ret; + + condlog(2, "%s: triggering change event to reinitialize", + pp->dev); + pp->initialized = INIT_REQUESTED_UDEV; + pp->retriggers++; + ret = sysfs_attr_set_value(pp->udev, "uevent", change, + sizeof(change) - 1); + if (ret != sizeof(change) - 1) + log_sysfs_attr_set_value(1, ret, + "%s: failed to trigger change event", + pp->dev); + return 0; + } else { + condlog(1, "%s: not initialized after %d udev retriggers", + pp->dev, retrigger_tries); + /* + * Make sure that the "add missing path" code path + * below may reinstate the path later, if it ever + * comes up again. + * The WWID needs not be cleared; if it was set, the + * state hadn't been INIT_MISSING_UDEV in the first + * place. + */ + pp->initialized = INIT_FAILED; + return 0; + } + } + + /* + * provision a next check soonest, + * in case we exit abnormally from here + */ + pp->tick = checkint; + + newstate = check_path_state(pp); + + if (!strlen(pp->wwid) && + (pp->initialized == INIT_FAILED || pp->initialized == INIT_NEW) && + (newstate == PATH_UP || newstate == PATH_GHOST)) { + condlog(2, "%s: add missing path", pp->dev); + conf = get_multipath_config(); + pthread_cleanup_push(put_multipath_config, conf); + ret = pathinfo(pp, conf, DI_ALL | DI_BLACKLIST); + pthread_cleanup_pop(1); + /* INIT_OK implies ret == PATHINFO_OK */ + if (pp->initialized == INIT_OK) { + ev_add_path(pp, vecs, 1); + pp->tick = 1; + } else { + if (ret == PATHINFO_SKIPPED) + return -1; + /* + * We failed multiple times to initialize this + * path properly. Don't re-check too often. + */ + pp->checkint = max_checkint; + } + } + return 0; +} + enum checker_state { CHECKER_STARTING, CHECKER_RUNNING, @@ -2751,7 +2781,11 @@ checkerloop (void *ap) if (pp->is_checked) continue; pp->is_checked = true; - rc = check_path(vecs, pp, ticks); + if (pp->mpp) + rc = check_path(vecs, pp, ticks); + else + rc = handle_uninitialized_path(vecs, pp, + ticks); if (rc < 0) { condlog(1, "%s: check_path() failed, removing", pp->dev); From cb7ae997789b2833f36a99d3acb575c9dfe03a1d Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 17 Jul 2024 14:10:52 -0400 Subject: [PATCH 078/145] multipathd: check paths immediately after failing udev initialization When handle_uninitialized_path() moves a path from INIT_MISSING_UDEV to INIT_FAILED, it has already waited for conf->retrigger_delay seconds. It might as well check the path state now, instead of waiting for the next iteration. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipathd/main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/multipathd/main.c b/multipathd/main.c index e3f53bf19..ed2542c9b 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -2672,7 +2672,6 @@ handle_uninitialized_path(struct vectors * vecs, struct path * pp, * place. */ pp->initialized = INIT_FAILED; - return 0; } } From 8e4961e6fc0d4247a460a46598e9c82856aa7a7c Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 17 Jul 2024 14:10:53 -0400 Subject: [PATCH 079/145] multipathd: set pp->tick = max_checkint in handle_uninitialized_path When handle_uninitialized_path() checks a path, it will either: 1. trigger a new uevent to initalize the path, in which case it won't check the path again until that uevent is processed and updates pp->tick 2. blacklist the path, in which case the path gets removed 3. intialize the path correctly, in which case it sets pp->tick = 1 4. fail to initialize the path, in which case it was supposed to set pp->tick to max_checkint, but instead it set pp->checkint to max_checkint, which never worked correctly. By setting pp->tick to max_checkint at the start, handle_uninitialized_path() will continue to work as it previously did, except in case 4, where in now works correctly. There's no point in messing with pp->checkint for paths that haven't been initialized yet. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipathd/main.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index ed2542c9b..723999cd6 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -2625,7 +2625,6 @@ handle_uninitialized_path(struct vectors * vecs, struct path * pp, { int newstate; int retrigger_tries; - unsigned int checkint, max_checkint; struct config *conf; int ret; @@ -2640,8 +2639,7 @@ handle_uninitialized_path(struct vectors * vecs, struct path * pp, conf = get_multipath_config(); retrigger_tries = conf->retrigger_tries; - checkint = conf->checkint; - max_checkint = conf->max_checkint; + pp->tick = conf->max_checkint; put_multipath_config(conf); if (pp->initialized == INIT_MISSING_UDEV) { @@ -2675,12 +2673,6 @@ handle_uninitialized_path(struct vectors * vecs, struct path * pp, } } - /* - * provision a next check soonest, - * in case we exit abnormally from here - */ - pp->tick = checkint; - newstate = check_path_state(pp); if (!strlen(pp->wwid) && @@ -2695,14 +2687,8 @@ handle_uninitialized_path(struct vectors * vecs, struct path * pp, if (pp->initialized == INIT_OK) { ev_add_path(pp, vecs, 1); pp->tick = 1; - } else { - if (ret == PATHINFO_SKIPPED) - return -1; - /* - * We failed multiple times to initialize this - * path properly. Don't re-check too often. - */ - pp->checkint = max_checkint; + } else if (ret == PATHINFO_SKIPPED) { + return -1; } } return 0; From 828e74535e8b1e3d763bc6f99350f6a13ae7c39d Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 17 Jul 2024 14:10:54 -0400 Subject: [PATCH 080/145] multipathd: return 0 from check_path() if that path wasn't checked If check_path_state() returns PATH_WILD or PATH_UNCHECKED, then the path wasn't correctly checked, and check_path() should return 0. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipathd/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multipathd/main.c b/multipathd/main.c index 723999cd6..9fbdbfbd5 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -2386,7 +2386,7 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) newstate = check_path_state(pp); if (newstate == PATH_WILD || newstate == PATH_UNCHECKED) { - return 1; + return 0; } else if ((newstate != PATH_UP && newstate != PATH_GHOST && newstate != PATH_PENDING) && (pp->state == PATH_DELAYED)) { /* If path state become failed again cancel path delay state */ From d5813f0261e4a00a20c2fbb06fd82c58b953a323 Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 17 Jul 2024 14:10:55 -0400 Subject: [PATCH 081/145] multipathd: reorder path state checks Reorder the path state checks in check_path(), so that it first does all the checks which can result in returning with the path unchecked or removed from the multipath device. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipathd/main.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 9fbdbfbd5..86f7ab1f5 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -2385,19 +2385,8 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) pp->tick = checkint; newstate = check_path_state(pp); - if (newstate == PATH_WILD || newstate == PATH_UNCHECKED) { + if (newstate == PATH_WILD || newstate == PATH_UNCHECKED) return 0; - } else if ((newstate != PATH_UP && newstate != PATH_GHOST && - newstate != PATH_PENDING) && (pp->state == PATH_DELAYED)) { - /* If path state become failed again cancel path delay state */ - pp->state = newstate; - /* - * path state bad again should change the check interval time - * to the shortest delay - */ - pp->checkint = checkint; - return 1; - } /* * Async IO in flight. Keep the previous path state * and reschedule as soon as possible @@ -2436,6 +2425,17 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) return 0; } + if ((newstate != PATH_UP && newstate != PATH_GHOST && + newstate != PATH_PENDING) && (pp->state == PATH_DELAYED)) { + /* If path state become failed again cancel path delay state */ + pp->state = newstate; + /* + * path state bad again should change the check interval time + * to the shortest delay + */ + pp->checkint = checkint; + return 1; + } if ((newstate == PATH_UP || newstate == PATH_GHOST) && (san_path_check_enabled(pp->mpp) || marginal_path_check_enabled(pp->mpp))) { From d0bf35fc6957bf8f98c2d693ff8e95bc3c31717b Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 17 Jul 2024 14:10:56 -0400 Subject: [PATCH 082/145] multipathd: adjust when mpp is synced with the kernel Move the code to sync the mpp device state into a helper function and add a counter to to make sure that the device is synced at least once every max_checkint secs. This makes sure that multipath devices with no paths will still get synced with the kernel. Also, if multiple paths are checked in the same loop, the multipath device will only be synced with the kernel once, since every time the mpp is synced in any code path, mpp->sync_tick is reset. The code still syncs the mpp before updating the path state for two main reasons. 1. Sometimes multipathd leaves the mpp with a garbage state. Future patches will fix most of these cases, but the code intentially does not remove the mpp is resyncing fails while checking paths. But this does leave the mpp with a garbage state. 2. The kernel chages the multipath state independently of multipathd. If the kernel fails a path, a uevent will arrive shortly. But the kernel doesn't provide any notification when it switches the active path group or if it ends up picking a different one than multipathd selected. Multipathd needs to know the actual current pathgroup to know when it should be switching them. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- libmultipath/configure.c | 1 + libmultipath/structs.h | 2 ++ libmultipath/structs_vec.c | 5 +++ multipathd/main.c | 64 +++++++++++++++++++++++++------------- 4 files changed, 50 insertions(+), 22 deletions(-) diff --git a/libmultipath/configure.c b/libmultipath/configure.c index b4de863c6..34158e31b 100644 --- a/libmultipath/configure.c +++ b/libmultipath/configure.c @@ -358,6 +358,7 @@ int setup_map(struct multipath *mpp, char **params, struct vectors *vecs) sysfs_set_scsi_tmo(conf, mpp); marginal_pathgroups = conf->marginal_pathgroups; + mpp->sync_tick = conf->max_checkint; pthread_cleanup_pop(1); if (!mpp->features || !mpp->hwhandler || !mpp->selector) { diff --git a/libmultipath/structs.h b/libmultipath/structs.h index 3b91e39ca..002eeae14 100644 --- a/libmultipath/structs.h +++ b/libmultipath/structs.h @@ -453,6 +453,8 @@ struct multipath { int ghost_delay; int ghost_delay_tick; int queue_mode; + unsigned int sync_tick; + bool is_checked; uid_t uid; gid_t gid; mode_t mode; diff --git a/libmultipath/structs_vec.c b/libmultipath/structs_vec.c index d58ef5a73..7f267ba06 100644 --- a/libmultipath/structs_vec.c +++ b/libmultipath/structs_vec.c @@ -505,11 +505,16 @@ update_multipath_table (struct multipath *mpp, vector pathvec, int flags) char __attribute__((cleanup(cleanup_charp))) *params = NULL; char __attribute__((cleanup(cleanup_charp))) *status = NULL; unsigned long long size; + struct config *conf; if (!mpp) return r; size = mpp->size; + conf = get_multipath_config(); + mpp->sync_tick = conf->max_checkint; + put_multipath_config(conf); + r = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, (mapid_t) { .str = mpp->alias }, (mapinfo_t) { diff --git a/multipathd/main.c b/multipathd/main.c index 86f7ab1f5..ae40f5990 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -2342,6 +2342,37 @@ check_path_state(struct path *pp) return newstate; } +static void +do_sync_mpp(struct vectors * vecs, struct multipath *mpp) +{ + int i, ret; + struct path *pp; + + mpp->is_checked = true; + ret = update_multipath_strings(mpp, vecs->pathvec); + if (ret != DMP_OK) { + condlog(1, "%s: %s", mpp->alias, ret == DMP_NOT_FOUND ? + "device not found" : + "couldn't synchronize with kernel state"); + vector_foreach_slot (mpp->paths, pp, i) + pp->dmstate = PSTATE_UNDEF; + return; + } + set_no_path_retry(mpp); +} + +static void +sync_mpp(struct vectors * vecs, struct multipath *mpp, unsigned int ticks) +{ + if (mpp->sync_tick) + mpp->sync_tick -= (mpp->sync_tick > ticks) ? ticks : + mpp->sync_tick; + if (mpp->sync_tick) + return; + + do_sync_mpp(vecs, mpp); +} + /* * Returns '1' if the path has been checked and '0' otherwise */ @@ -2356,7 +2387,6 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) unsigned int checkint, max_checkint; struct config *conf; int marginal_pathgroups, marginal_changed = 0; - int ret; bool need_reload; if (pp->initialized == INIT_REMOVED) @@ -2395,26 +2425,6 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) pp->tick = 1; return 0; } - /* - * Synchronize with kernel state - */ - ret = update_multipath_strings(pp->mpp, vecs->pathvec); - if (ret != DMP_OK) { - if (ret == DMP_NOT_FOUND) { - /* multipath device missing. Likely removed */ - condlog(1, "%s: multipath device '%s' not found", - pp->dev, pp->mpp ? pp->mpp->alias : ""); - return 0; - } else - condlog(1, "%s: Couldn't synchronize with kernel state", - pp->dev); - pp->dmstate = PSTATE_UNDEF; - } - /* if update_multipath_strings orphaned the path, quit early */ - if (!pp->mpp) - return 0; - set_no_path_retry(pp->mpp); - if (pp->recheck_wwid == RECHECK_WWID_ON && (newstate == PATH_UP || newstate == PATH_GHOST) && ((pp->state != PATH_UP && pp->state != PATH_GHOST) || @@ -2424,7 +2434,12 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) handle_path_wwid_change(pp, vecs); return 0; } - + if (!pp->mpp->is_checked) { + do_sync_mpp(vecs, pp->mpp); + /* if update_multipath_strings orphaned the path, quit early */ + if (!pp->mpp) + return 0; + } if ((newstate != PATH_UP && newstate != PATH_GHOST && newstate != PATH_PENDING) && (pp->state == PATH_DELAYED)) { /* If path state become failed again cancel path delay state */ @@ -2752,12 +2767,17 @@ checkerloop (void *ap) while (checker_state != CHECKER_FINISHED) { unsigned int paths_checked = 0, i; struct timespec chk_start_time; + struct multipath *mpp; pthread_cleanup_push(cleanup_lock, &vecs->lock); lock(&vecs->lock); pthread_testcancel(); + vector_foreach_slot(vecs->mpvec, mpp, i) + mpp->is_checked = false; get_monotonic_time(&chk_start_time); if (checker_state == CHECKER_STARTING) { + vector_foreach_slot(vecs->mpvec, mpp, i) + sync_mpp(vecs, mpp, ticks); vector_foreach_slot(vecs->pathvec, pp, i) pp->is_checked = false; checker_state = CHECKER_RUNNING; From 6840a419d91eab9f8a07122867d59b3e7a917083 Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 17 Jul 2024 14:10:57 -0400 Subject: [PATCH 083/145] multipathd: resync map after setup_map in ev_remove_path In ev_remove_path() it was possible to exit after calling setup_map() without resyncing the mpp state with the kernel. This meant that the mpp state in multipathd might not match with the kernel state at all. It's safe to exit before calling setup_map() if either wait_for_udev is set or need_do_map is not set. In both cases, setup_map() will later be called, either by a uevent or by the calling function. Once setup_map() has been called, setup_multipath() and sync_map_state() are now always called, to make sure the mpp matches the kernel state. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipathd/main.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index ae40f5990..6a0272135 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -1395,6 +1395,8 @@ ev_remove_path (struct path *pp, struct vectors * vecs, int need_do_map) * avoid referring to the map of an orphaned path */ if ((mpp = pp->mpp)) { + char devt[BLK_DEV_SIZE]; + /* * Mark the path as removed. In case of success, we * will delete it for good. Otherwise, it will be deleted @@ -1428,12 +1430,6 @@ ev_remove_path (struct path *pp, struct vectors * vecs, int need_do_map) flush_map_nopaths(mpp, vecs)) goto out; - if (setup_map(mpp, ¶ms, vecs)) { - condlog(0, "%s: failed to setup map for" - " removal of path %s", mpp->alias, pp->dev); - goto fail; - } - if (mpp->wait_for_udev) { mpp->wait_for_udev = 2; retval = REMOVE_PATH_DELAY; @@ -1444,6 +1440,12 @@ ev_remove_path (struct path *pp, struct vectors * vecs, int need_do_map) retval = REMOVE_PATH_DELAY; goto out; } + + if (setup_map(mpp, ¶ms, vecs)) { + condlog(0, "%s: failed to setup map for" + " removal of path %s", mpp->alias, pp->dev); + goto fail; + } /* * reload the map */ @@ -1453,24 +1455,20 @@ ev_remove_path (struct path *pp, struct vectors * vecs, int need_do_map) "removal of path %s", mpp->alias, pp->dev); retval = REMOVE_PATH_FAILURE; - } else { - /* - * update our state from kernel - */ - char devt[BLK_DEV_SIZE]; - - strlcpy(devt, pp->dev_t, sizeof(devt)); - - /* setup_multipath will free the path - * regardless of whether it succeeds or - * fails */ - if (setup_multipath(vecs, mpp)) - return REMOVE_PATH_MAP_ERROR; - sync_map_state(mpp); + } + /* + * update mpp state from kernel even if domap failed. + * If the path was removed from the mpp, setup_multipath will + * free the path regardless of whether it succeeds or fails + */ + strlcpy(devt, pp->dev_t, sizeof(devt)); + if (setup_multipath(vecs, mpp)) + return REMOVE_PATH_MAP_ERROR; + sync_map_state(mpp); + if (retval == REMOVE_PATH_SUCCESS) condlog(2, "%s: path removed from map %s", devt, mpp->alias); - } } else { /* mpp == NULL */ if ((i = find_slot(vecs->pathvec, (void *)pp)) != -1) From 5fdd2c86e6ff3471ddc9eecee756423d8ffdbe71 Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 17 Jul 2024 14:10:58 -0400 Subject: [PATCH 084/145] multipathd: resync map after setup_map in resize_map In resize_map() it was possible to exit after calling setup_map() without resyncing the mpp state with the kernel. This meant that the mpp state in multipathd might not match with the kernel state at all. Once setup_map() has been called, setup_multipath() and sync_map_state() are now always called, to make sure the mpp matches the kernel state. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipathd/main.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 6a0272135..6951e5ed2 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -1534,6 +1534,7 @@ needs_ro_update(struct multipath *mpp, int ro) int resize_map(struct multipath *mpp, unsigned long long size, struct vectors * vecs) { + int ret = 0; char *params __attribute__((cleanup(cleanup_charp))) = NULL; unsigned long long orig_size = mpp->size; @@ -1543,7 +1544,8 @@ int resize_map(struct multipath *mpp, unsigned long long size, condlog(0, "%s: failed to setup map for resize : %s", mpp->alias, strerror(errno)); mpp->size = orig_size; - return 1; + ret = 1; + goto out; } mpp->action = ACT_RESIZE; mpp->force_udev_reload = 1; @@ -1551,13 +1553,14 @@ int resize_map(struct multipath *mpp, unsigned long long size, condlog(0, "%s: failed to resize map : %s", mpp->alias, strerror(errno)); mpp->size = orig_size; - return 1; + ret = 1; } +out: if (setup_multipath(vecs, mpp) != 0) return 2; sync_map_state(mpp); - return 0; + return ret; } static int From 9ae56baec90eafa93f115fcf9fbcd9f05f735418 Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 17 Jul 2024 14:10:59 -0400 Subject: [PATCH 085/145] multipathd: always resync map in reload_and_sync_map reload_and_sync_map() needs to always resync the map after calling reload_map(), because the mpp state may no longer match the kernel state if reload_map() fails. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipathd/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 6951e5ed2..19ca36685 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -2188,13 +2188,15 @@ static int reload_map(struct vectors *vecs, struct multipath *mpp, int reload_and_sync_map(struct multipath *mpp, struct vectors *vecs) { + int ret = 0; + if (reload_map(vecs, mpp, 1)) - return 1; + ret = 1; if (setup_multipath(vecs, mpp) != 0) return 2; sync_map_state(mpp); - return 0; + return ret; } static int check_path_reinstate_state(struct path * pp) { From c8e3a87d15baa12432945924483ed695d9b01b88 Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 17 Jul 2024 14:11:00 -0400 Subject: [PATCH 086/145] multipathd: correctly handle paths removed for a wwid change If check_path() exitted because the path's wwid changed and it was removed, checkerloop() wasn't decrementing the pathvec loop count. This caused the next path to be skipped by the checker loop. To solve this, switch check_path() and handle_uninitialized_path() to symbolic returns and make check_path() return CHECK_PATH_REMOVED when a path is removed, make handle_uninitialized_path() also remove the path if it was blacklisted, and make checkerloop() just decrement the loop count when a path handling function returns CHECK_PATH_REMOVED. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipathd/main.c | 73 ++++++++++++++++++++++++++--------------------- multipathd/main.h | 2 +- 2 files changed, 41 insertions(+), 34 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 19ca36685..80f0ff9dd 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -974,20 +974,24 @@ rescan_path(struct udev_device *ud) } } -void +/* Returns true if the path was removed */ +bool handle_path_wwid_change(struct path *pp, struct vectors *vecs) { struct udev_device *udd; static const char add[] = "add"; ssize_t ret; char dev[FILE_NAME_SIZE]; + bool removed = false; if (!pp || !pp->udev) - return; + return removed; strlcpy(dev, pp->dev, sizeof(dev)); udd = udev_device_ref(pp->udev); - if (!(ev_remove_path(pp, vecs, 1) & REMOVE_PATH_SUCCESS) && pp->mpp) { + if (ev_remove_path(pp, vecs, 1) & REMOVE_PATH_SUCCESS) { + removed = true; + } else if (pp->mpp) { pp->dmstate = PSTATE_FAILED; dm_fail_path(pp->mpp->alias, pp->dev_t); } @@ -997,6 +1001,7 @@ handle_path_wwid_change(struct path *pp, struct vectors *vecs) if (ret != sizeof(add) - 1) log_sysfs_attr_set_value(1, ret, "%s: failed to trigger add event", dev); + return removed; } bool @@ -2376,9 +2381,12 @@ sync_mpp(struct vectors * vecs, struct multipath *mpp, unsigned int ticks) do_sync_mpp(vecs, mpp); } -/* - * Returns '1' if the path has been checked and '0' otherwise - */ +enum check_path_return { + CHECK_PATH_CHECKED, + CHECK_PATH_SKIPPED, + CHECK_PATH_REMOVED, +}; + static int check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) { @@ -2393,12 +2401,12 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) bool need_reload; if (pp->initialized == INIT_REMOVED) - return 0; + return CHECK_PATH_SKIPPED; if (pp->tick) pp->tick -= (pp->tick > ticks) ? ticks : pp->tick; if (pp->tick) - return 0; /* don't check this path yet */ + return CHECK_PATH_SKIPPED; conf = get_multipath_config(); checkint = conf->checkint; @@ -2419,14 +2427,14 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) newstate = check_path_state(pp); if (newstate == PATH_WILD || newstate == PATH_UNCHECKED) - return 0; + return CHECK_PATH_SKIPPED; /* * Async IO in flight. Keep the previous path state * and reschedule as soon as possible */ if (newstate == PATH_PENDING) { pp->tick = 1; - return 0; + return CHECK_PATH_SKIPPED; } if (pp->recheck_wwid == RECHECK_WWID_ON && (newstate == PATH_UP || newstate == PATH_GHOST) && @@ -2434,14 +2442,14 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) pp->dmstate == PSTATE_FAILED) && check_path_wwid_change(pp)) { condlog(0, "%s: path wwid change detected. Removing", pp->dev); - handle_path_wwid_change(pp, vecs); - return 0; + return handle_path_wwid_change(pp, vecs)? CHECK_PATH_REMOVED : + CHECK_PATH_SKIPPED; } if (!pp->mpp->is_checked) { do_sync_mpp(vecs, pp->mpp); /* if update_multipath_strings orphaned the path, quit early */ if (!pp->mpp) - return 0; + return CHECK_PATH_SKIPPED; } if ((newstate != PATH_UP && newstate != PATH_GHOST && newstate != PATH_PENDING) && (pp->state == PATH_DELAYED)) { @@ -2452,7 +2460,7 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) * to the shortest delay */ pp->checkint = checkint; - return 1; + return CHECK_PATH_CHECKED; } if ((newstate == PATH_UP || newstate == PATH_GHOST) && (san_path_check_enabled(pp->mpp) || @@ -2467,7 +2475,7 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) * in time */ pp->tick = 1; pp->state = PATH_DELAYED; - return 1; + return CHECK_PATH_CHECKED; } if (!pp->marginal) { pp->marginal = 1; @@ -2525,7 +2533,7 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) pp->mpp->failback_tick = 0; pp->mpp->stat_path_failures++; - return 1; + return CHECK_PATH_CHECKED; } if (newstate == PATH_UP || newstate == PATH_GHOST) { @@ -2604,7 +2612,7 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) pp->state = newstate; if (pp->mpp->wait_for_udev) - return 1; + return CHECK_PATH_CHECKED; /* * path prio refreshing */ @@ -2631,12 +2639,9 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) switch_pathgroup(pp->mpp); } } - return 1; + return CHECK_PATH_CHECKED; } -/* - * Returns -1 if the path was blacklisted, and 0 otherwise - */ static int handle_uninitialized_path(struct vectors * vecs, struct path * pp, unsigned int ticks) @@ -2648,12 +2653,12 @@ handle_uninitialized_path(struct vectors * vecs, struct path * pp, if (pp->initialized != INIT_NEW && pp->initialized != INIT_FAILED && pp->initialized != INIT_MISSING_UDEV) - return 0; + return CHECK_PATH_SKIPPED; if (pp->tick) pp->tick -= (pp->tick > ticks) ? ticks : pp->tick; if (pp->tick) - return 0; /* don't check this path yet */ + return CHECK_PATH_SKIPPED; conf = get_multipath_config(); retrigger_tries = conf->retrigger_tries; @@ -2675,7 +2680,7 @@ handle_uninitialized_path(struct vectors * vecs, struct path * pp, log_sysfs_attr_set_value(1, ret, "%s: failed to trigger change event", pp->dev); - return 0; + return CHECK_PATH_SKIPPED; } else { condlog(1, "%s: not initialized after %d udev retriggers", pp->dev, retrigger_tries); @@ -2706,10 +2711,16 @@ handle_uninitialized_path(struct vectors * vecs, struct path * pp, ev_add_path(pp, vecs, 1); pp->tick = 1; } else if (ret == PATHINFO_SKIPPED) { - return -1; + int i; + + condlog(1, "%s: path blacklisted. removing", pp->dev); + if ((i = find_slot(vecs->pathvec, (void *)pp)) != -1) + vector_del_slot(vecs->pathvec, i); + free_path(pp); + return CHECK_PATH_REMOVED; } } - return 0; + return CHECK_PATH_CHECKED; } enum checker_state { @@ -2794,14 +2805,10 @@ checkerloop (void *ap) else rc = handle_uninitialized_path(vecs, pp, ticks); - if (rc < 0) { - condlog(1, "%s: check_path() failed, removing", - pp->dev); - vector_del_slot(vecs->pathvec, i); - free_path(pp); + if (rc == CHECK_PATH_REMOVED) i--; - } else - num_paths += rc; + else if (rc == CHECK_PATH_CHECKED) + num_paths++; if (++paths_checked % 128 == 0 && (lock_has_waiters(&vecs->lock) || waiting_clients())) { diff --git a/multipathd/main.h b/multipathd/main.h index 4fcd64026..7aa93ca3c 100644 --- a/multipathd/main.h +++ b/multipathd/main.h @@ -47,7 +47,7 @@ int setup_multipath(struct vectors * vecs, struct multipath * mpp); int update_multipath(struct vectors *vecs, char *mapname); int reload_and_sync_map(struct multipath *mpp, struct vectors *vecs); -void handle_path_wwid_change(struct path *pp, struct vectors *vecs); +bool handle_path_wwid_change(struct path *pp, struct vectors *vecs); bool check_path_wwid_change(struct path *pp); int finish_path_init(struct path *pp, struct vectors * vecs); int resize_map(struct multipath *mpp, unsigned long long size, From dd265e59796db4fd2837dada4480a8798c26dec5 Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 17 Jul 2024 14:11:01 -0400 Subject: [PATCH 087/145] multipathd: handle changed wwid when adding partial path If multipathd noticed that the WWID didn't match the device when adding a partial path, but removing it failed, multipathd wasn't disabling the path. Instead of calling handle_path_wwid_change(), which doesn't make much sense when multipathd is expecting a uevent, just manually disable the path if ev_remove_path() fails. Since the path hasn't actually been removed, multipathd needs to make sure that it says failed when the path state is resynced with the kernel. Set the state to PATH_UNCHECKED in orphan_path(), and additionally skip all path in INIT_REMOVED in sync_map_state(). Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- libmultipath/structs.c | 1 + libmultipath/structs_vec.c | 3 ++- multipathd/cli_handlers.c | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libmultipath/structs.c b/libmultipath/structs.c index 1583e0012..0a26096a5 100644 --- a/libmultipath/structs.c +++ b/libmultipath/structs.c @@ -146,6 +146,7 @@ uninitialize_path(struct path *pp) return; pp->dmstate = PSTATE_UNDEF; + pp->state = PATH_UNCHECKED; pp->uid_attribute = NULL; pp->checker_timeout = 0; diff --git a/libmultipath/structs_vec.c b/libmultipath/structs_vec.c index 7f267ba06..c44492bdf 100644 --- a/libmultipath/structs_vec.c +++ b/libmultipath/structs_vec.c @@ -724,7 +724,8 @@ sync_map_state(struct multipath *mpp) vector_foreach_slot (mpp->pg, pgp, i){ vector_foreach_slot (pgp->paths, pp, j){ - if (pp->state == PATH_UNCHECKED || + if (pp->initialized == INIT_REMOVED || + pp->state == PATH_UNCHECKED || pp->state == PATH_WILD || pp->state == PATH_DELAYED) continue; diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c index 924d06ecf..4b6cfba2e 100644 --- a/multipathd/cli_handlers.c +++ b/multipathd/cli_handlers.c @@ -539,7 +539,11 @@ add_partial_path(struct path *pp, struct vectors *vecs) if (strlen(wwid) && strncmp(wwid, pp->wwid, WWID_SIZE) != 0) { condlog(0, "%s: path wwid changed from '%s' to '%s'. removing", pp->dev, wwid, pp->wwid); - ev_remove_path(pp, vecs, 1); + if (!(ev_remove_path(pp, vecs, 1) & REMOVE_PATH_SUCCESS) && + pp->mpp) { + pp->dmstate = PSTATE_FAILED; + dm_fail_path(pp->mpp->alias, pp->dev_t); + } udev_device_unref(udd); return -1; } From 26dc96a1689e52ae7eb98e8fb3ce9969f941a02d Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 17 Jul 2024 14:11:02 -0400 Subject: [PATCH 088/145] multipathd: don't read conf->checkint twice in check_path check_path() already has saved the value of conf->checkint in the local variable checkint, so there's no reason to read it again. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipathd/main.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 80f0ff9dd..36e545873 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -2513,9 +2513,7 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) * upon state change, reset the checkint * to the shortest delay */ - conf = get_multipath_config(); - pp->checkint = conf->checkint; - put_multipath_config(conf); + pp->checkint = checkint; if (newstate != PATH_UP && newstate != PATH_GHOST) { /* From c0ba04da2f15609d2c187b2db04c3d173d87ff0c Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Fri, 19 Jul 2024 15:40:57 -0400 Subject: [PATCH 089/145] multipathd: make multipath devices manage their path check times multipathd's path checking can be very bursty, with all the paths running their path checkers at the same time, and then all doing nothing while waiting for the next check time. Alternatively, the paths in a multipath device might all run their path checkers at a different time, which can keep the multipath device from having a coherent view of the state of all of its paths. This patch makes all the paths of a multipath device converge to running their checkers at the same time, and spreads out when this time is for the different multipath devices. To do this, the checking time is divided into adjustment intervals (conf->adjust_int), so that the checkers run at some index within this interval. conf->adjust_int is chosen so that it is a multiple of all possible pp->checkint values. This means that regardless of pp->checkint, the path should always be checked on the same indexes, each adjustement interval. Each multipath device has a goal index. These are evenly spread out between 0 and conf->max_checkint. Every conf->adjust_int seconds, each multipath device should try to check all of its paths on its goal index. If the multipath device's check times are not aligned with the goal index, then pp->tick for the next check will be decremented by one, to align it over time. In order for the path checkers to run every pp->checkint seconds, multipathd needs to track how long a path check has been pending for, and subtract that time from the number of ticks till the checker is run again. If the checker has been pending for more that pp->checkint, the path will be rechecked on the next tick after the checker returns. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- libmultipath/config.c | 12 ++++++ libmultipath/config.h | 1 + libmultipath/structs.c | 1 + libmultipath/structs.h | 1 + multipathd/main.c | 91 ++++++++++++++++++++++++++++++++++-------- 5 files changed, 89 insertions(+), 17 deletions(-) diff --git a/libmultipath/config.c b/libmultipath/config.c index 83fa73695..a59533b55 100644 --- a/libmultipath/config.c +++ b/libmultipath/config.c @@ -982,6 +982,18 @@ int _init_config (const char *file, struct config *conf) conf->checkint = conf->max_checkint; condlog(3, "polling interval: %d, max: %d", conf->checkint, conf->max_checkint); + /* + * make sure that that adjust_int is a multiple of all possible values + * of pp->checkint. + */ + if (conf->max_checkint % conf->checkint == 0) { + conf->adjust_int = conf->max_checkint; + } else { + conf->adjust_int = conf->checkint; + while (2 * conf->adjust_int < conf->max_checkint) + conf->adjust_int *= 2; + conf->adjust_int *= conf->max_checkint; + } if (conf->blist_devnode == NULL) { conf->blist_devnode = vector_alloc(); diff --git a/libmultipath/config.h b/libmultipath/config.h index 384193ab0..800c0ca9c 100644 --- a/libmultipath/config.h +++ b/libmultipath/config.h @@ -147,6 +147,7 @@ struct config { int minio_rq; unsigned int checkint; unsigned int max_checkint; + unsigned int adjust_int; bool use_watchdog; int pgfailback; int rr_weight; diff --git a/libmultipath/structs.c b/libmultipath/structs.c index 0a26096a5..232b42304 100644 --- a/libmultipath/structs.c +++ b/libmultipath/structs.c @@ -149,6 +149,7 @@ uninitialize_path(struct path *pp) pp->state = PATH_UNCHECKED; pp->uid_attribute = NULL; pp->checker_timeout = 0; + pp->pending_ticks = 0; if (checker_selected(&pp->checker)) checker_put(&pp->checker); diff --git a/libmultipath/structs.h b/libmultipath/structs.h index 002eeae14..457d7836c 100644 --- a/libmultipath/structs.h +++ b/libmultipath/structs.h @@ -360,6 +360,7 @@ struct path { unsigned long long size; unsigned int checkint; unsigned int tick; + unsigned int pending_ticks; int bus; int offline; int state; diff --git a/multipathd/main.c b/multipathd/main.c index 36e545873..b075b0579 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -2388,7 +2388,7 @@ enum check_path_return { }; static int -check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) +do_check_path (struct vectors * vecs, struct path * pp) { int newstate; int new_path_up = 0; @@ -2400,14 +2400,6 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) int marginal_pathgroups, marginal_changed = 0; bool need_reload; - if (pp->initialized == INIT_REMOVED) - return CHECK_PATH_SKIPPED; - - if (pp->tick) - pp->tick -= (pp->tick > ticks) ? ticks : pp->tick; - if (pp->tick) - return CHECK_PATH_SKIPPED; - conf = get_multipath_config(); checkint = conf->checkint; max_checkint = conf->max_checkint; @@ -2419,12 +2411,6 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) pp->checkint = checkint; }; - /* - * provision a next check soonest, - * in case we exit abnormally from here - */ - pp->tick = checkint; - newstate = check_path_state(pp); if (newstate == PATH_WILD || newstate == PATH_UNCHECKED) return CHECK_PATH_SKIPPED; @@ -2587,7 +2573,6 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) condlog(4, "%s: delay next check %is", pp->dev_t, pp->checkint); } - pp->tick = pp->checkint; } } else if (newstate != PATH_UP && newstate != PATH_GHOST) { @@ -2640,6 +2625,77 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) return CHECK_PATH_CHECKED; } +static int +check_path (struct vectors * vecs, struct path * pp, unsigned int ticks, + time_t start_secs) +{ + int r; + unsigned int adjust_int, max_checkint; + struct config *conf; + time_t next_idx, goal_idx; + + if (pp->initialized == INIT_REMOVED) + return CHECK_PATH_SKIPPED; + + if (pp->tick) + pp->tick -= (pp->tick > ticks) ? ticks : pp->tick; + if (pp->tick) + return CHECK_PATH_SKIPPED; + + conf = get_multipath_config(); + max_checkint = conf->max_checkint; + adjust_int = conf->adjust_int; + put_multipath_config(conf); + + r = do_check_path(vecs, pp); + + /* + * do_check_path() removed or orphaned the path. + */ + if (r == CHECK_PATH_REMOVED || !pp->mpp) + return r; + + if (pp->tick != 0) { + /* the path checker is pending */ + if (pp->state != PATH_DELAYED) + pp->pending_ticks++; + else + pp->pending_ticks = 0; + return r; + } + + /* schedule the next check */ + pp->tick = pp->checkint; + if (pp->pending_ticks >= pp->tick) + pp->tick = 1; + else + pp->tick -= pp->pending_ticks; + pp->pending_ticks = 0; + + if (pp->tick == 1) + return r; + + /* + * every mpp has a goal_idx in the range of + * 0 <= goal_idx < conf->max_checkint + * + * The next check has an index, next_idx, in the range of + * 0 <= next_idx < conf->adjust_int + * + * If the difference between the goal index and the next check index + * is not a multiple of pp->checkint, then the device is not checking + * the paths at its goal index, and pp->tick will be decremented by + * one, to align it over time. + */ + goal_idx = (find_slot(vecs->mpvec, pp->mpp)) * + max_checkint / VECTOR_SIZE(vecs->mpvec); + next_idx = (start_secs + pp->tick) % adjust_int; + if ((goal_idx - next_idx) % pp->checkint != 0) + pp->tick--; + + return r; +} + static int handle_uninitialized_path(struct vectors * vecs, struct path * pp, unsigned int ticks) @@ -2799,7 +2855,8 @@ checkerloop (void *ap) continue; pp->is_checked = true; if (pp->mpp) - rc = check_path(vecs, pp, ticks); + rc = check_path(vecs, pp, ticks, + chk_start_time.tv_sec); else rc = handle_uninitialized_path(vecs, pp, ticks); From 66acfb61cedd8c17ecd80cbe53f0f7716d32a812 Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 17 Jul 2024 14:11:04 -0400 Subject: [PATCH 090/145] multipathd: factor out actual path checking loop from checkerloop Move the code that actually loops through the paths and checks them into a separate function, to stop it from being so heavily indented. This will be more imporant when a future patch makes paths checked by mpp. No functional changes. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipathd/main.c | 65 +++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index b075b0579..05b84dc94 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -2783,6 +2783,38 @@ enum checker_state { CHECKER_FINISHED, }; +static enum checker_state +check_paths(struct vectors *vecs, unsigned int ticks, int *num_paths_p) +{ + unsigned int paths_checked = 0; + struct timespec diff_time, start_time, end_time; + struct path *pp; + int i, rc; + + get_monotonic_time(&start_time); + vector_foreach_slot(vecs->pathvec, pp, i) { + if (pp->is_checked) + continue; + pp->is_checked = true; + if (pp->mpp) + rc = check_path(vecs, pp, ticks, start_time.tv_sec); + else + rc = handle_uninitialized_path(vecs, pp, ticks); + if (rc == CHECK_PATH_REMOVED) + i--; + else if (rc == CHECK_PATH_CHECKED) + (*num_paths_p)++; + if (++paths_checked % 128 == 0 && + (lock_has_waiters(&vecs->lock) || waiting_clients())) { + get_monotonic_time(&end_time); + timespecsub(&end_time, &start_time, &diff_time); + if (diff_time.tv_sec > 0) + return CHECKER_RUNNING; + } + } + return CHECKER_FINISHED; +} + static void * checkerloop (void *ap) { @@ -2814,7 +2846,7 @@ checkerloop (void *ap) while (1) { struct timespec diff_time, start_time, end_time; - int num_paths = 0, strict_timing, rc = 0; + int num_paths = 0, strict_timing; unsigned int ticks = 0; enum checker_state checker_state = CHECKER_STARTING; @@ -2833,16 +2865,14 @@ checkerloop (void *ap) sd_notify(0, "WATCHDOG=1"); #endif while (checker_state != CHECKER_FINISHED) { - unsigned int paths_checked = 0, i; - struct timespec chk_start_time; struct multipath *mpp; + int i; pthread_cleanup_push(cleanup_lock, &vecs->lock); lock(&vecs->lock); pthread_testcancel(); vector_foreach_slot(vecs->mpvec, mpp, i) mpp->is_checked = false; - get_monotonic_time(&chk_start_time); if (checker_state == CHECKER_STARTING) { vector_foreach_slot(vecs->mpvec, mpp, i) sync_mpp(vecs, mpp, ticks); @@ -2850,32 +2880,7 @@ checkerloop (void *ap) pp->is_checked = false; checker_state = CHECKER_RUNNING; } - vector_foreach_slot(vecs->pathvec, pp, i) { - if (pp->is_checked) - continue; - pp->is_checked = true; - if (pp->mpp) - rc = check_path(vecs, pp, ticks, - chk_start_time.tv_sec); - else - rc = handle_uninitialized_path(vecs, pp, - ticks); - if (rc == CHECK_PATH_REMOVED) - i--; - else if (rc == CHECK_PATH_CHECKED) - num_paths++; - if (++paths_checked % 128 == 0 && - (lock_has_waiters(&vecs->lock) || - waiting_clients())) { - get_monotonic_time(&end_time); - timespecsub(&end_time, &chk_start_time, - &diff_time); - if (diff_time.tv_sec > 0) - goto unlock; - } - } - checker_state = CHECKER_FINISHED; -unlock: + checker_state = check_paths(vecs, ticks, &num_paths); lock_cleanup_pop(vecs->lock); if (checker_state != CHECKER_FINISHED) { /* Yield to waiters */ From 7133ff23c3e0b701b4dc5b22c5b6408310d4df3c Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 17 Jul 2024 14:11:05 -0400 Subject: [PATCH 091/145] multipathd: check paths in order by mpp Instead of checking all of the paths in vecs->pathvec in order, first check all the paths in each multipath device. Then check the uninitialized paths. One issue with checking paths this way is that the multipath device can be resynced or even removed while a path is being checked. The path can also be removed. If there is any change to the multipath device, multipathd needs to loop through its paths again, because the current indexes may not longer be valid. To do this change mpp->is_checked to an int called mpp->synced_count, and increment it whenever the multipath device gets resynced. After each path is checked, make sure that the multipath device still exists, that mpp->synced_count hasn't changed. If either has happened, restart checking at the current index in mpvec (which will either be the same mpp if it was just resynced, or the next mpp if the last one was deleted). Since the multipath device is resynced when its first path is checked, this restart will happen to every multipath device at least once per loop. But the paths themselves aren't rechecked, so it's not much overhead. If resyncing a multipath device fails in do_check_mpp(), there may be path devices that have pp->mpp set, but are no longer in one of the multipath device's pathgroups, and thus will not get checked. This almost definitely means the multipath device was deleted. If do_check_mpp() failed to resync the device, but it wasn't deleted, it will get called again in max_checkint seconds even if it no longer has mpp->pg set, and the paths will get checked again after that. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- libmultipath/structs.h | 2 +- libmultipath/structs_vec.c | 1 + multipathd/main.c | 54 ++++++++++++++++++++++++++++++++------ 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/libmultipath/structs.h b/libmultipath/structs.h index 457d7836c..91509881c 100644 --- a/libmultipath/structs.h +++ b/libmultipath/structs.h @@ -455,7 +455,7 @@ struct multipath { int ghost_delay_tick; int queue_mode; unsigned int sync_tick; - bool is_checked; + int synced_count; uid_t uid; gid_t gid; mode_t mode; diff --git a/libmultipath/structs_vec.c b/libmultipath/structs_vec.c index c44492bdf..50b17e665 100644 --- a/libmultipath/structs_vec.c +++ b/libmultipath/structs_vec.c @@ -514,6 +514,7 @@ update_multipath_table (struct multipath *mpp, vector pathvec, int flags) conf = get_multipath_config(); mpp->sync_tick = conf->max_checkint; put_multipath_config(conf); + mpp->synced_count++; r = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, (mapid_t) { .str = mpp->alias }, diff --git a/multipathd/main.c b/multipathd/main.c index 05b84dc94..d31ba8250 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -2356,7 +2356,6 @@ do_sync_mpp(struct vectors * vecs, struct multipath *mpp) int i, ret; struct path *pp; - mpp->is_checked = true; ret = update_multipath_strings(mpp, vecs->pathvec); if (ret != DMP_OK) { condlog(1, "%s: %s", mpp->alias, ret == DMP_NOT_FOUND ? @@ -2431,7 +2430,7 @@ do_check_path (struct vectors * vecs, struct path * pp) return handle_path_wwid_change(pp, vecs)? CHECK_PATH_REMOVED : CHECK_PATH_SKIPPED; } - if (!pp->mpp->is_checked) { + if (pp->mpp->synced_count == 0) { do_sync_mpp(vecs, pp->mpp); /* if update_multipath_strings orphaned the path, quit early */ if (!pp->mpp) @@ -2788,18 +2787,57 @@ check_paths(struct vectors *vecs, unsigned int ticks, int *num_paths_p) { unsigned int paths_checked = 0; struct timespec diff_time, start_time, end_time; + struct multipath *mpp; struct path *pp; int i, rc; get_monotonic_time(&start_time); + + vector_foreach_slot(vecs->mpvec, mpp, i) { + struct pathgroup *pgp; + struct path *pp; + int j, k; + bool check_for_waiters = false; + /* maps can be rechecked, so this is not always 0 */ + int synced_count = mpp->synced_count; + + vector_foreach_slot (mpp->pg, pgp, j) { + vector_foreach_slot (pgp->paths, pp, k) { + if (!pp->mpp || pp->is_checked) + continue; + pp->is_checked = true; + rc = check_path(vecs, pp, ticks, + start_time.tv_sec); + if (rc == CHECK_PATH_CHECKED) + (*num_paths_p)++; + if (++paths_checked % 128 == 0) + check_for_waiters = true; + /* + * mpp has been removed or resynced. Path may + * have been removed. + */ + if (VECTOR_SLOT(vecs->mpvec, i) != mpp || + synced_count != mpp->synced_count) { + i--; + goto next_mpp; + } + } + } +next_mpp: + if (check_for_waiters && + (lock_has_waiters(&vecs->lock) || waiting_clients())) { + get_monotonic_time(&end_time); + timespecsub(&end_time, &start_time, &diff_time); + if (diff_time.tv_sec > 0) + return CHECKER_RUNNING; + } + } vector_foreach_slot(vecs->pathvec, pp, i) { - if (pp->is_checked) + if (pp->mpp || pp->is_checked) continue; pp->is_checked = true; - if (pp->mpp) - rc = check_path(vecs, pp, ticks, start_time.tv_sec); - else - rc = handle_uninitialized_path(vecs, pp, ticks); + + rc = handle_uninitialized_path(vecs, pp, ticks); if (rc == CHECK_PATH_REMOVED) i--; else if (rc == CHECK_PATH_CHECKED) @@ -2872,7 +2910,7 @@ checkerloop (void *ap) lock(&vecs->lock); pthread_testcancel(); vector_foreach_slot(vecs->mpvec, mpp, i) - mpp->is_checked = false; + mpp->synced_count = 0; if (checker_state == CHECKER_STARTING) { vector_foreach_slot(vecs->mpvec, mpp, i) sync_mpp(vecs, mpp, ticks); From 4a664f817c9a2ddc6d71b6e9f0d113f380a99475 Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 17 Jul 2024 14:11:06 -0400 Subject: [PATCH 092/145] multipathd: clean up the correct wwid in check_path_wwid_change After check_path_wwid_change() grabbed a new copy of the wwid, it was stripping trailing whitespace off of pp->wwid, instead of the copy it just got. Fixes: 4660cff ("multipathd: add recheck_wwid option to verify the path wwid") Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipathd/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index d31ba8250..daec9e934 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -1025,9 +1025,9 @@ check_path_wwid_change(struct path *pp) } /*Strip any trailing blanks */ - for (i = strlen(pp->wwid); i > 0 && pp->wwid[i-1] == ' '; i--); + for (i = strlen(wwid); i > 0 && wwid[i-1] == ' '; i--); /* no-op */ - pp->wwid[i] = '\0'; + wwid[i] = '\0'; condlog(4, "%s: Got wwid %s by sgio", pp->dev, wwid); if (strncmp(wwid, pp->wwid, WWID_SIZE)) { From 41605026dc773c04e7d9912fe6c671a249edac4e Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 18 Jul 2024 18:32:17 +0200 Subject: [PATCH 093/145] multipath-tools: update NEWS.md Signed-off-by: Martin Wilck --- NEWS.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index f85938603..cb0639def 100644 --- a/NEWS.md +++ b/NEWS.md @@ -19,7 +19,11 @@ * Fixed bug that caused queueing to be always disabled if flushing a map failed (bug introduced in 0.9.8). -* Fixed failure to remove maps even with `deferred_remove` (bug introduced in 0.9.9). +* Fixed failure to remove maps even with `deferred_remove` (bug introduced in + 0.9.9). +* Fixed old mpathpersist bug leading to the error message "configured reservation + key doesn't match: 0x0" when `reservation_key` was configured in the + multipaths section of `multipath.conf`. ### Other @@ -29,6 +33,7 @@ * Remove hardcoded paths and make them configurable instead. This should improve compatibility e.g. with NixOS. * Fixed directio CI test for real devices, run more "real" tests in CI +* Fixed minor issues detected by coverity. ## multipath-tools 0.9.9, 2024/05 From de74fbd210b73b264c0b093ed0dbaa1819b3215a Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Tue, 6 Aug 2024 18:54:41 -0400 Subject: [PATCH 094/145] multipathd: show pending reconfigs in 'show daemon' output Since the "multipathd reconfigure" command simply schedules a reconfigure, and doesn't wait until it has occurred, it would be nice to be able to query multipathd to see if the reconfigure has completed. "multipathd show daemon" doesn't work for this. The reconfigure could be delayed, and the output gives no indication that there is a pending reconfigure. Change the ouput to add " (pending reconfigure)" if a reconfigure is pending. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipathd/cli_handlers.c | 11 +++++++++-- multipathd/main.c | 15 ++++++++------- multipathd/main.h | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c index 4b6cfba2e..ef5f53e25 100644 --- a/multipathd/cli_handlers.c +++ b/multipathd/cli_handlers.c @@ -342,8 +342,15 @@ show_status (struct strbuf *reply, struct vectors *vecs) static int show_daemon (struct strbuf *reply) { - if (print_strbuf(reply, "pid %d %s\n", - daemon_pid, daemon_status()) < 0) + const char *status; + bool pending_reconfig; + + status = daemon_status(&pending_reconfig); + if (status == NULL) + return 1; + if (print_strbuf(reply, "pid %d %s%s\n", + daemon_pid, status, + pending_reconfig ? " (pending reconfigure)" : "") < 0) return 1; return 0; diff --git a/multipathd/main.c b/multipathd/main.c index daec9e934..f43ff549a 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -132,6 +132,8 @@ static int poll_dmevents = 1; static enum daemon_status running_state = DAEMON_INIT; /* Don't access this variable without holding config_lock */ static bool __delayed_reconfig; +/* Don't access this variable without holding config_lock */ +static enum force_reload_types reconfigure_pending = FORCE_RELOAD_NONE; pid_t daemon_pid; static pthread_mutex_t config_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t config_cond; @@ -142,19 +144,21 @@ static bool check_thr_started, uevent_thr_started, uxlsnr_thr_started, fpin_consumer_thr_started; static int pid_fd = -1; -static inline enum daemon_status get_running_state(void) +static inline enum daemon_status get_running_state(bool *pending_reconfig) { enum daemon_status st; pthread_mutex_lock(&config_lock); st = running_state; + if (pending_reconfig != NULL) + *pending_reconfig = (reconfigure_pending != FORCE_RELOAD_NONE); pthread_mutex_unlock(&config_lock); return st; } int should_exit(void) { - return get_running_state() == DAEMON_SHUTDOWN; + return get_running_state(NULL) == DAEMON_SHUTDOWN; } /* @@ -179,9 +183,9 @@ static const char *daemon_status_msg[DAEMON_STATUS_SIZE] = { }; const char * -daemon_status(void) +daemon_status(bool *pending_reconfig) { - int status = get_running_state(); + int status = get_running_state(pending_reconfig); if (status < DAEMON_INIT || status >= DAEMON_STATUS_SIZE) return NULL; @@ -277,9 +281,6 @@ enum daemon_status wait_for_state_change_if(enum daemon_status oldstate, return st; } -/* Don't access this variable without holding config_lock */ -static enum force_reload_types reconfigure_pending = FORCE_RELOAD_NONE; - /* must be called with config_lock held */ static void __post_config_state(enum daemon_status state) { diff --git a/multipathd/main.h b/multipathd/main.h index 7aa93ca3c..ef838a022 100644 --- a/multipathd/main.h +++ b/multipathd/main.h @@ -31,7 +31,7 @@ extern pid_t daemon_pid; extern int uxsock_timeout; void exit_daemon(void); -const char * daemon_status(void); +const char *daemon_status(bool *pending_reconfig); enum daemon_status wait_for_state_change_if(enum daemon_status oldstate, unsigned long ms); void schedule_reconfigure(enum force_reload_types requested_type); From a634209205bbba7a897c9b5f0b880c4b321d9815 Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Wed, 7 Aug 2024 18:59:10 -0400 Subject: [PATCH 095/145] libmultipath: fix ontap prioritizer snprintf limits The ontap prioritizer functions dump_cdb() and process_sg_error() both incorrectly set the snprintf() limits larger than the available space. Instead of multiplying the number of elements to print by the size of an element to calculate the limit, they multiplied the number of elements to print by the maximum number of elements that the buffer could hold. Fix this by making these functions use strbufs instead. mwilck: removed log message in print_strbuf() failure case. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck Signed-off-by: Martin Wilck --- libmultipath/prioritizers/ontap.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/libmultipath/prioritizers/ontap.c b/libmultipath/prioritizers/ontap.c index 117886ea7..90eaf2748 100644 --- a/libmultipath/prioritizers/ontap.c +++ b/libmultipath/prioritizers/ontap.c @@ -23,6 +23,7 @@ #include "prio.h" #include "structs.h" #include "unaligned.h" +#include "strbuf.h" #define INQUIRY_CMD 0x12 #define INQUIRY_CMDLEN 6 @@ -35,32 +36,29 @@ static void dump_cdb(unsigned char *cdb, int size) { int i; - char buf[10*5+1]; - char * p = &buf[0]; + STRBUF_ON_STACK(buf); - condlog(0, "- SCSI CDB: "); - for (i=0; imasked_status, io_hdr->host_status, io_hdr->driver_status); if (io_hdr->sb_len_wr > 0) { - condlog(0, "- SCSI sense data: "); - for (i=0; isb_len_wr; i++) { - p += snprintf(p, 128*(io_hdr->sb_len_wr-i), "0x%02x ", - io_hdr->sbp[i]); + for (i = 0; i < io_hdr->sb_len_wr; i++) { + if (print_strbuf(&buf, "0x%02x ", io_hdr->sbp[i]) < 0) + return; } - condlog(0, "%s", buf); + condlog(0, "- SCSI sense data: %s", get_strbuf_str(&buf)); } } From 4cf36e73e20289f8f0c62f014b2d0dcffedbd8a5 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 8 Aug 2024 12:53:48 +0200 Subject: [PATCH 096/145] multipath-tools tests: make alias.test succeed with increased verbosity With MPATHTEST_VERBOSITY > 3, the alias test fails because of an unexpected message at verbosity level 4. Fix it. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- tests/alias.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/alias.c b/tests/alias.c index a95b30817..4f23cf960 100644 --- a/tests/alias.c +++ b/tests/alias.c @@ -1438,6 +1438,7 @@ static void gufa_empty_new_rw(void **state) { mock_bindings_file(""); mock_unused_alias("MPATHa"); + expect_condlog(4, "_read_bindings_file: bindings are unchanged"); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); mock_allocate_binding("MPATHa", "WWID0"); @@ -1451,6 +1452,7 @@ static void gufa_empty_new_ro_1(void **state) { mock_bindings_file(""); mock_unused_alias("MPATHa"); + expect_condlog(4, "_read_bindings_file: bindings are unchanged"); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); mock_allocate_binding_err("MPATHa", "WWID0", -EROFS, "Read-only file system"); @@ -1462,6 +1464,7 @@ static void gufa_empty_new_ro_2(void **state) { char *alias; mock_bindings_file(""); + expect_condlog(4, "_read_bindings_file: bindings are unchanged"); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); mock_unused_alias("MPATHa"); @@ -1473,6 +1476,7 @@ static void gufa_match_a_unused(void **state) { char *alias; mock_bindings_file("MPATHa WWID0"); + expect_condlog(4, "_read_bindings_file: bindings are unchanged"); expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); mock_unused_alias("MPATHa"); expect_condlog(3, EXISTING_STR("MPATHa", "WWID0")); @@ -1486,6 +1490,7 @@ static void gufa_match_a_self(void **state) { char *alias; mock_bindings_file("MPATHa WWID0"); + expect_condlog(4, "_read_bindings_file: bindings are unchanged"); expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); mock_self_alias("MPATHa", "WWID0"); expect_condlog(3, EXISTING_STR("MPATHa", "WWID0")); @@ -1500,6 +1505,7 @@ static void gufa_match_a_used(void **state) { mock_bindings_file("MPATHa WWID0"); + expect_condlog(4, "_read_bindings_file: bindings are unchanged"); expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); mock_used_alias("MPATHa", "WWID0"); @@ -1514,6 +1520,7 @@ static void gufa_nomatch_a_c(void **state) { mock_bindings_file(bindings); mock_unused_alias("MPATHb"); + expect_condlog(4, "_read_bindings_file: bindings are unchanged"); expect_condlog(3, NOMATCH_WWID_STR("WWID1")); mock_allocate_binding_len("MPATHb", "WWID1", strlen(bindings)); @@ -1530,6 +1537,7 @@ static void gufa_nomatch_c_a(void **state) { mock_bindings_file(bindings); mock_unused_alias("MPATHb"); + expect_condlog(4, "_read_bindings_file: bindings are unchanged"); expect_condlog(3, NOMATCH_WWID_STR("WWID1")); mock_allocate_binding_len("MPATHb", "WWID1", sizeof(bindings) - 1); @@ -1545,6 +1553,7 @@ static void gufa_nomatch_c_b(void **state) { "MPATHb WWID1\n"); mock_bindings_file(bindings); + expect_condlog(4, "_read_bindings_file: bindings are unchanged"); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); mock_unused_alias("MPATHa"); @@ -1561,6 +1570,7 @@ static void gufa_nomatch_c_b_used(void **state) { "MPATHb WWID1\n"); mock_bindings_file(bindings); + expect_condlog(4, "_read_bindings_file: bindings are unchanged"); expect_condlog(3, NOMATCH_WWID_STR("WWID4")); mock_used_alias("MPATHa", "WWID4"); mock_unused_alias("MPATHd"); @@ -1579,6 +1589,7 @@ static void gufa_nomatch_b_f_a(void **state) { "MPATHa WWID0\n"); mock_bindings_file(bindings); + expect_condlog(4, "_read_bindings_file: bindings are unchanged"); expect_condlog(3, NOMATCH_WWID_STR("WWID7")); mock_unused_alias("MPATHc"); @@ -1595,6 +1606,7 @@ static void gufa_nomatch_b_aa_a(void **state) { fill_bindings(&buf, 0, 26); mock_bindings_file(get_strbuf_str(&buf)); + expect_condlog(4, "_read_bindings_file: bindings are unchanged"); expect_condlog(3, NOMATCH_WWID_STR("WWID28")); mock_unused_alias("MPATHab"); mock_allocate_binding_len("MPATHab", "WWID28", get_strbuf_len(&buf)); @@ -1611,6 +1623,7 @@ static void gufa_nomatch_b_f_a_sorted(void **state) { "MPATHa WWID0\n"); mock_bindings_file(bindings); + expect_condlog(4, "_read_bindings_file: bindings are unchanged"); expect_condlog(3, NOMATCH_WWID_STR("WWID7")); mock_unused_alias("MPATHc"); @@ -1626,6 +1639,7 @@ static void gufa_old_empty(void **state) { /* rlookup_binding for ALIAS */ mock_bindings_file(""); + expect_condlog(4, "_read_bindings_file: bindings are unchanged"); expect_condlog(3, NOMATCH_STR("MPATHz")); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); @@ -1642,6 +1656,7 @@ static void gufa_old_match(void **state) { mock_bindings_file("MPATHb WWID1\n" "MPATHz WWID0"); + expect_condlog(4, "_read_bindings_file: bindings are unchanged"); expect_condlog(3, FOUND_ALIAS_STR("MPATHz", "WWID0")); alias = get_user_friendly_alias("WWID0", "MPATHz", "MPATH", false); @@ -1654,6 +1669,7 @@ static void gufa_old_match_other(void **state) { static const char bindings[] = "MPATHz WWID9\n"; mock_bindings_file(bindings); + expect_condlog(4, "_read_bindings_file: bindings are unchanged"); expect_condlog(3, FOUND_ALIAS_STR("MPATHz", "WWID9")); expect_condlog(0, REUSE_STR("MPATHz", "WWID9")); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); @@ -1671,6 +1687,7 @@ static void gufa_old_match_other_used(void **state) { static const char bindings[] = "MPATHz WWID9\n"; mock_bindings_file(bindings); + expect_condlog(4, "_read_bindings_file: bindings are unchanged"); expect_condlog(3, FOUND_ALIAS_STR("MPATHz", "WWID9")); expect_condlog(0, REUSE_STR("MPATHz", "WWID9")); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); @@ -1689,6 +1706,7 @@ static void gufa_old_match_other_wwidmatch(void **state) { "MPATHc WWID2"); mock_bindings_file(bindings); + expect_condlog(4, "_read_bindings_file: bindings are unchanged"); expect_condlog(3, FOUND_ALIAS_STR("MPATHz", "WWID9")); expect_condlog(0, REUSE_STR("MPATHz", "WWID9")); expect_condlog(3, FOUND_STR("MPATHc", "WWID2")); @@ -1706,6 +1724,7 @@ static void gufa_old_match_other_wwidmatch_used(void **state) { "MPATHc WWID2"); mock_bindings_file(bindings); + expect_condlog(4, "_read_bindings_file: bindings are unchanged"); expect_condlog(3, FOUND_ALIAS_STR("MPATHz", "WWID9")); expect_condlog(0, REUSE_STR("MPATHz", "WWID9")); expect_condlog(3, FOUND_STR("MPATHc", "WWID2")); @@ -1720,6 +1739,7 @@ static void gufa_old_nomatch_wwidmatch(void **state) { static const char bindings[] = "MPATHa WWID0"; mock_bindings_file(bindings); + expect_condlog(4, "_read_bindings_file: bindings are unchanged"); expect_condlog(3, NOMATCH_STR("MPATHz")); expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); mock_unused_alias("MPATHa"); @@ -1735,6 +1755,7 @@ static void gufa_old_nomatch_wwidmatch_used(void **state) { static const char bindings[] = "MPATHa WWID0"; mock_bindings_file(bindings); + expect_condlog(4, "_read_bindings_file: bindings are unchanged"); expect_condlog(3, NOMATCH_STR("MPATHz")); expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); mock_used_alias("MPATHa", "WWID0"); @@ -1748,6 +1769,7 @@ static void gufa_old_nomatch_nowwidmatch(void **state) { static const char bindings[] = "MPATHb WWID1\n"; mock_bindings_file(bindings); + expect_condlog(4, "_read_bindings_file: bindings are unchanged"); expect_condlog(3, NOMATCH_STR("MPATHz")); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); From 87f48fab454fc46ad72633c089923de8600b8fd7 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 8 Aug 2024 10:45:04 +0200 Subject: [PATCH 097/145] libmpathutil: avoid extra memory allocation in print_strbuf() Instead of allocating a temporary buffer with vasprintf() and copying its contents to the strbuf, try to print directly into the strbuf and use the return value to expand the buffer if necessary. This saves a memory allocation on every invocation of print_strbuf(), and thus reduces the likelihood of failure and at the same time increases efficiency. We need an extra call to vsnprintf() if the buffer must be expanded, but vasprintf() will need to re-process the input internally as well after determining the required buffer size, therefore this probably won't hurt much. Add some more tests for print_strbuf() to make sure this works as intended. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathutil/strbuf.c | 23 +++++++++++---- tests/strbuf.c | 68 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 5 deletions(-) diff --git a/libmpathutil/strbuf.c b/libmpathutil/strbuf.c index e23b65e80..6e53c3f3e 100644 --- a/libmpathutil/strbuf.c +++ b/libmpathutil/strbuf.c @@ -196,17 +196,30 @@ int print_strbuf(struct strbuf *buf, const char *fmt, ...) { va_list ap; int ret; - char *tail; + size_t space = buf->size - buf->offs; va_start(ap, fmt); - ret = vasprintf(&tail, fmt, ap); + ret = vsnprintf(buf->buf + buf->offs, space, fmt, ap); va_end(ap); if (ret < 0) - return -ENOMEM; + return ret; + else if ((size_t)ret < space) { + buf->offs += ret; + return ret; + } + + ret = expand_strbuf(buf, ret); + if (ret < 0) + return ret; + + space = buf->size - buf->offs; + va_start(ap, fmt); + ret = vsnprintf(buf->buf + buf->offs, space, fmt, ap); + va_end(ap); - ret = __append_strbuf_str(buf, tail, ret); + if (ret >= 0) + buf->offs += ret; - free(tail); return ret; } diff --git a/tests/strbuf.c b/tests/strbuf.c index f8554da56..d7d4cd94e 100644 --- a/tests/strbuf.c +++ b/tests/strbuf.c @@ -279,6 +279,71 @@ static void test_print_strbuf(void **state) assert_int_equal(print_strbuf(&buf, "%d%% of %d is %0.2f", 5, 100, 0.05), 17); assert_string_equal(get_strbuf_str(&buf), "5% of 100 is 0.05"); + +} + +/* length of string is not a divisor of chunk size */ +static void test_print_strbuf_2(void **state) +{ + STRBUF_ON_STACK(buf); + const char sentence[] = "This sentence has forty-seven (47) characters. "; + const char *s; + const int repeat = 100; + int i; + + for (i = 0; i < repeat; i++) + assert_int_equal(print_strbuf(&buf, "%s", sentence), + sizeof(sentence) - 1); + + s = get_strbuf_str(&buf); + condlog(3, "%s", s); + assert_int_equal(strlen(s), repeat * (sizeof(sentence) - 1)); + for (i = 0; i < repeat; i++) + assert_int_equal(strncmp(s + i * (sizeof(sentence) - 1), + sentence, sizeof(sentence) - 1), 0); +} + +/* length of string is divisor of chunk size */ +static void test_print_strbuf_3(void **state) +{ + STRBUF_ON_STACK(buf); + const char sentence[] = "This sentence has 32 characters."; + const char *s; + const int repeat = 100; + int i; + + for (i = 0; i < repeat; i++) + assert_int_equal(print_strbuf(&buf, "%s", sentence), + sizeof(sentence) - 1); + + s = get_strbuf_str(&buf); + condlog(3, "%s", s); + assert_int_equal(strlen(s), repeat * (sizeof(sentence) - 1)); + for (i = 0; i < repeat; i++) + assert_int_equal(strncmp(s + i * (sizeof(sentence) - 1), + sentence, sizeof(sentence) - 1), 0); +} + +static void test_print_strbuf_4(void **state) +{ + STRBUF_ON_STACK(buf); + const char sentence[] = "This sentence has a lot of characters, " + "which makes it hopefully longer than the chunk size given by " + "the constant \"BUF_CHUNK\" in libmpathutil/strbuf.c. "; + const char *s; + const int repeat = 100; + int i; + + for (i = 0; i < repeat; i++) + assert_int_equal(print_strbuf(&buf, "%s", sentence), + sizeof(sentence) - 1); + + s = get_strbuf_str(&buf); + condlog(3, "%s", s); + assert_int_equal(strlen(s), repeat * (sizeof(sentence) - 1)); + for (i = 0; i < repeat; i++) + assert_int_equal(strncmp(s + i * (sizeof(sentence) - 1), + sentence, sizeof(sentence) - 1), 0); } static void test_truncate_strbuf(void **state) @@ -394,6 +459,9 @@ static int test_strbuf(void) cmocka_unit_test(test_strbuf_quoted), cmocka_unit_test(test_strbuf_escaped), cmocka_unit_test(test_print_strbuf), + cmocka_unit_test(test_print_strbuf_2), + cmocka_unit_test(test_print_strbuf_3), + cmocka_unit_test(test_print_strbuf_4), cmocka_unit_test(test_truncate_strbuf), cmocka_unit_test(test_fill_strbuf), }; From 2115c3c99bbce2adb26e3b832f5d342e887e4d92 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 16:49:56 +0200 Subject: [PATCH 098/145] libmpathutil: rename strlcat and strlcpy User programs are forbidden to use names of functions provided by the standard library [1]. Since glibc 2.38, strlcpy() and strlcat() are part of the system library. Rename our own functions to libmp_strlcpy() and libmp_strlcat(), respectively, and only use the short names if the C library doesn't have them. It turns out that msul libc has always had strlcat() and strlcpy(), so use the system library function with musl, too. [1] https://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html Reviewed-by: Benjamin Marzinski --- libmpathutil/util.c | 4 ++-- libmpathutil/util.h | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/libmpathutil/util.c b/libmpathutil/util.c index 9c422f1f0..136aa5954 100644 --- a/libmpathutil/util.c +++ b/libmpathutil/util.c @@ -121,7 +121,7 @@ get_word (const char *sentence, char **word) return skip + len; } -size_t strlcpy(char * restrict dst, const char * restrict src, size_t size) +size_t libmp_strlcpy(char * restrict dst, const char * restrict src, size_t size) { size_t bytes = 0; char ch; @@ -138,7 +138,7 @@ size_t strlcpy(char * restrict dst, const char * restrict src, size_t size) return bytes; } -size_t strlcat(char * restrict dst, const char * restrict src, size_t size) +size_t libmp_strlcat(char * restrict dst, const char * restrict src, size_t size) { size_t bytes = 0; char ch; diff --git a/libmpathutil/util.h b/libmpathutil/util.h index c19f74974..7bad85592 100644 --- a/libmpathutil/util.h +++ b/libmpathutil/util.h @@ -12,6 +12,10 @@ #include #include +#ifndef __GLIBC_PREREQ +#define __GLIBC_PREREQ(x, y) 0 +#endif + size_t strchop(char *); const char *libmp_basename(const char *filename); @@ -22,8 +26,12 @@ int basenamecpy (const char *src, char *dst, size_t size); int filepresent (const char *run); char *get_next_string(char **temp, const char *split_char); int get_word (const char * sentence, char ** word); -size_t strlcpy(char * restrict dst, const char * restrict src, size_t size); -size_t strlcat(char * restrict dst, const char * restrict src, size_t size); +size_t libmp_strlcpy(char * restrict dst, const char * restrict src, size_t size); +size_t libmp_strlcat(char * restrict dst, const char * restrict src, size_t size); +#if defined(__GLIBC__) && ! (__GLIBC_PREREQ(2, 38)) +#define strlcpy(dst, src, size) libmp_strlcpy(dst, src, size) +#define strlcat(dst, src, size) libmp_strlcat(dst, src, size) +#endif dev_t parse_devt(const char *dev_t); char *convert_dev(char *dev, int is_path_device); void setup_thread_attr(pthread_attr_t *attr, size_t stacksize, int detached); @@ -62,9 +70,6 @@ struct scandir_result { }; void free_scandir_result(struct scandir_result *); -#ifndef __GLIBC_PREREQ -#define __GLIBC_PREREQ(x, y) 0 -#endif /* * ffsll() is also available on glibc < 2.27 if _GNU_SOURCE is defined. * But relying on that would require that every program using this header file From 6b1f41f0758c7355251f3bb4fc4db4421307ff21 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 16:59:52 +0200 Subject: [PATCH 099/145] libmpathutil.version: remove strlcpy and strlcat, and LIBMULTIPATH section With the removal of strlcpy from the "symbols referenced by multipath and multipathd" section, this part of the ABI (which is actually the part of LIBMULTIPATH_16.0.0 which was moved to libmpathutil and exported to multipath and/or multipathd) has now changed for the first time since the split between libmpathutil and libmultipath. It makes no sense to further track whether or not any symbols exported by libmpathutil are used by multipath or multipathd. It turns out that both executables were already using some symbols from the sections that were supposedly used by libmultipath only. Therefore, move all symbols to the new LIBMPATHUTIL_4.0 ABI. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathutil/libmpathutil.version | 90 ++++++++++++++----------------- 1 file changed, 39 insertions(+), 51 deletions(-) diff --git a/libmpathutil/libmpathutil.version b/libmpathutil/libmpathutil.version index cb0523167..8393b91cf 100644 --- a/libmpathutil/libmpathutil.version +++ b/libmpathutil/libmpathutil.version @@ -43,98 +43,86 @@ LIBMPATHCOMMON_1.0.0 { put_multipath_config; }; -/* symbols referenced by multipath and multipathd */ -LIBMULTIPATH_16.0.0 { +LIBMPATHUTIL_4.0 { global: + alloc_bitfield; alloc_strvec; + __append_strbuf_str; append_strbuf_str; + append_strbuf_quoted; + basenamecpy; cleanup_charp; + cleanup_fclose; + cleanup_fd_ptr; + cleanup_free_ptr; cleanup_mutex; cleanup_ucharp; + cleanup_udev_device; + cleanup_vector; + cleanup_vector_free; convert_dev; dlog; + filepresent; fill_strbuf; + find_keyword; find_slot; + free_keywords; free_scandir_result; free_strvec; + get_linux_version_code; get_monotonic_time; + __get_strbuf_buf; get_next_string; get_strbuf_len; get_strbuf_str; + get_word; + _install_keyword; + install_sublevel; + install_sublevel_end; is_quote; + keyword_alloc; + _log_bitfield_overflow; + libmp_basename; + libmp_strlcat; + libmp_strlcpy; libmp_verbosity; + log_safe; log_thread_reset; log_thread_start; log_thread_stop; logsink; + msort; normalize_timespec; + parse_devt; print_strbuf; + process_file; pthread_cond_init_mono; recv_packet; reset_strbuf; + safe_write; send_packet; set_max_fds; + set_value; setup_thread_attr; strchop; - strlcpy; + should_exit; + snprint_keyword; + steal_strbuf_str; timespeccmp; timespecsub; truncate_strbuf; + validate_config_strvec; ux_socket_listen; vector_alloc; vector_alloc_slot; vector_del_slot; + vector_find_or_add_slot; vector_free; + vector_insert_slot; + vector_move_up; vector_reset; vector_set_slot; - + vector_sort; local: *; }; - -/* symbols referenced internally by libmultipath */ -LIBMPATHUTIL_2.0 { - alloc_bitfield; - __append_strbuf_str; - append_strbuf_quoted; - basenamecpy; - cleanup_fd_ptr; - cleanup_free_ptr; - cleanup_vector_free; - cleanup_fclose; - filepresent; - find_keyword; - free_keywords; - get_linux_version_code; - __get_strbuf_buf; - get_word; - _install_keyword; - install_sublevel; - install_sublevel_end; - keyword_alloc; - _log_bitfield_overflow; - log_safe; - msort; - parse_devt; - process_file; - safe_write; - set_value; - should_exit; - snprint_keyword; - steal_strbuf_str; - strlcat; - validate_config_strvec; - vector_find_or_add_slot; - vector_insert_slot; - vector_move_up; - vector_sort; -}; - -LIBMPATHUTIL_2.1 { - libmp_basename; -}; - -LIBMPATHUTIL_2.2 { - cleanup_udev_device; - cleanup_vector; -}; From 4186b6ca197dad138725ed327bebf81683a6edb3 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 22:57:45 +0200 Subject: [PATCH 100/145] libmpathutil: fix __attribute typo in log_pthread.c Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathutil/log_pthread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmpathutil/log_pthread.c b/libmpathutil/log_pthread.c index 69b441bf6..f30eb7ed1 100644 --- a/libmpathutil/log_pthread.c +++ b/libmpathutil/log_pthread.c @@ -60,7 +60,7 @@ static void flush_logqueue (void) } while (empty == 0); } -static void cleanup_log_thread(__attribute((unused)) void *arg) +static void cleanup_log_thread(__attribute__((unused)) void *arg) { logdbg(stderr, "log thread exiting"); pthread_mutex_lock(&logev_lock); From 2e1997292f8f83a30c5dd324009457b632c470d0 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 23:02:52 +0200 Subject: [PATCH 101/145] libmultipath: devmapper.c: rename __DR_UNUSED__, and fix __attribute typo Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 0347a17c7..fe604f1bb 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -45,9 +45,9 @@ static int dm_conf_verbosity; #ifdef LIBDM_API_DEFERRED static int dm_cancel_remove_partmaps(const char * mapname); -#define __DR_UNUSED__ /* empty */ +#define DR_UNUSED__ /* empty */ #else -#define __DR_UNUSED__ __attribute__((unused)) +#define DR_UNUSED__ __attribute__((unused)) #endif static int dm_remove_partmaps (const char *mapname, int flags); @@ -1041,7 +1041,7 @@ int _dm_flush_map (const char *mapname, int flags, int retries) } int -dm_flush_map_nopaths(const char *mapname, int deferred_remove __DR_UNUSED__) +dm_flush_map_nopaths(const char *mapname, int deferred_remove DR_UNUSED__) { int flags = DMFL_NEED_SYNC; @@ -1196,7 +1196,7 @@ dm_disablegroup(const char * mapname, int index) static int dm_get_multipath(const char *name, struct multipath **pmpp) { - struct multipath __attribute((cleanup(cleanup_multipath))) *mpp = NULL; + struct multipath __attribute__((cleanup(cleanup_multipath))) *mpp = NULL; char uuid[DM_UUID_LEN]; int rc; From e60bf21483be6c2d766bd1bc16a2b64906aa4afa Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 23:05:31 +0200 Subject: [PATCH 102/145] multipathd: fix __attribute typo Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- multipathd/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multipathd/main.c b/multipathd/main.c index f43ff549a..bb19c9792 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -1220,7 +1220,7 @@ int ev_add_path (struct path * pp, struct vectors * vecs, int need_do_map) { struct multipath * mpp; - char *params __attribute((cleanup(cleanup_charp))) = NULL; + char *params __attribute__((cleanup(cleanup_charp))) = NULL; int retries = 3; int start_waiter = 0; int ret; From 216de532a03aebcc83f4476ad3c45684a6488eef Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 17:31:51 +0200 Subject: [PATCH 103/145] multipath-tools: use common convention for "header file included" macros User code shouldn't define any identifiers starting with 2 underscores, or underscore + capital letter [1]. Adopt this convention for all macros indicating that a certain header file is included. Moreover, use a common convention for constructing these macros: the macro is the base name of the header file, in capital letters, non-alphanumeric characters replaced by underscore, with "_INCLUDED" appended. This convention is well readable and was already used in a few files. The only exceptions to this rule are: - the header files under libmultipath/nvme and libmultipath/nvme/linux, where "NVME_" or "LINUX_" is prepended to the base name, respectively; - the files "byteorder.h" and "devmapper.h" under kpartx/, to avoid ambiguity with the files by the same name under libmultipath; - "main.h" for mpathpersist, to avoid ambiguity with multipathd's main.h. This commit also adds "already included" macros where they'd been missing so far. [1] https://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- create-config.mk | 4 ++-- kpartx/byteorder.h | 6 +++--- kpartx/crc32.h | 6 +++--- kpartx/dasd.h | 6 +++--- kpartx/devmapper.h | 6 +++--- kpartx/dos.h | 2 +- kpartx/efi.h | 6 +++--- kpartx/gpt.h | 4 ++-- kpartx/kpartx.h | 6 +++--- kpartx/lopart.h | 3 +++ kpartx/mac.h | 4 ++-- kpartx/xstrncpy.h | 3 +++ libdmmp/libdmmp/libdmmp.h | 6 +++--- libdmmp/libdmmp_private.h | 6 +++--- libmpathcmd/mpath_cmd.h | 6 +++--- libmpathpersist/mpath_persist.h | 6 +++--- libmpathpersist/mpath_persist_int.h | 6 +++--- libmpathpersist/mpath_pr_ioctl.h | 5 +++++ libmpathpersist/mpathpr.h | 4 ++-- libmpathutil/debug.h | 6 +++--- libmpathutil/globals.h | 4 ++-- libmpathutil/log.h | 6 +++--- libmpathutil/log_pthread.h | 6 +++--- libmpathutil/msort.h | 4 ++-- libmpathutil/parser.h | 4 ++-- libmpathutil/strbuf.h | 4 ++-- libmpathutil/time-util.h | 6 +++--- libmpathutil/util.h | 6 +++--- libmpathutil/uxsock.h | 5 ++++- libmpathutil/vector.h | 4 ++-- libmpathvalid/mpath_valid.h | 6 +++--- libmultipath/alias.h | 6 +++--- libmultipath/blacklist.h | 6 +++--- libmultipath/checkers.h | 6 +++--- libmultipath/checkers/cciss.h | 4 ++-- libmultipath/checkers/directio.h | 6 +++--- libmultipath/checkers/emc_clariion.h | 6 +++--- libmultipath/checkers/hp_sw.h | 6 +++--- libmultipath/checkers/rdac.h | 6 +++--- libmultipath/checkers/readsector0.h | 6 +++--- libmultipath/checkers/tur.h | 6 +++--- libmultipath/config.h | 4 ++-- libmultipath/configure.h | 4 ++++ libmultipath/defaults.h | 7 ++++--- libmultipath/devmapper.h | 7 ++++--- libmultipath/dict.h | 9 +++------ libmultipath/discovery.h | 6 +++--- libmultipath/dm-generic.h | 6 +++--- libmultipath/dmparser.h | 5 +++++ libmultipath/file.h | 6 +++--- libmultipath/foreign.h | 7 ++++--- libmultipath/generic.h | 6 +++--- libmultipath/hwtable.h | 6 +++--- libmultipath/io_err_stat.h | 6 +++--- libmultipath/libsg.h | 6 +++--- libmultipath/list.h | 6 +++--- libmultipath/lock.h | 6 +++--- libmultipath/nvme-lib.h | 6 +++--- libmultipath/nvme/argconfig.h | 4 ++-- libmultipath/nvme/json.h | 4 ++-- libmultipath/nvme/linux/nvme.h | 6 +++--- libmultipath/nvme/linux/nvme_ioctl.h | 6 +++--- libmultipath/nvme/nvme-ioctl.h | 6 +++--- libmultipath/nvme/nvme.h | 6 +++--- libmultipath/nvme/plugin.h | 4 ++-- libmultipath/pgpolicies.h | 4 ++-- libmultipath/print.h | 6 +++--- libmultipath/prio.h | 6 +++--- libmultipath/prioritizers/alua.h | 4 ++-- libmultipath/prioritizers/alua_rtpg.h | 6 +++--- libmultipath/prioritizers/alua_spc3.h | 6 +++--- libmultipath/prioritizers/weightedpath.h | 4 ++-- libmultipath/prkey.h | 6 +++--- libmultipath/propsel.h | 3 +++ libmultipath/sg_include.h | 3 +++ libmultipath/structs.h | 6 +++--- libmultipath/structs_vec.h | 6 +++--- libmultipath/switchgroup.h | 5 +++++ libmultipath/sysfs.h | 4 ++-- libmultipath/uevent.h | 6 +++--- libmultipath/unaligned.h | 6 +++--- libmultipath/valid.h | 6 +++--- libmultipath/version.h | 6 +++--- libmultipath/wwids.h | 6 +++--- mpathpersist/main.h | 4 ++++ multipathd/cli.h | 6 +++--- multipathd/cli_handlers.h | 4 ++-- multipathd/dmevents.h | 6 +++--- multipathd/fpin.h | 4 ++-- multipathd/init_unwinder.h | 4 ++-- multipathd/main.h | 6 +++--- multipathd/pidfile.h | 4 ++++ multipathd/uxclnt.h | 5 +++++ multipathd/uxlsnr.h | 4 ++-- multipathd/waiter.h | 6 +++--- tests/test-lib.h | 4 ++-- tests/test-log.h | 4 ++-- tests/wrap64.h | 4 ++-- 98 files changed, 282 insertions(+), 235 deletions(-) diff --git a/create-config.mk b/create-config.mk index 0abbb3af4..8bd2c20ce 100644 --- a/create-config.mk +++ b/create-config.mk @@ -163,8 +163,8 @@ all: $(TOPDIR)/config.mk $(multipathdir)/autoconfig.h: @echo creating $@ - @echo '#ifndef _AUTOCONFIG_H' >$@ - @echo '#define _AUTOCONFIG_H' >>$@ + @echo '#ifndef AUTOCONFIG_H_INCLUDED' >$@ + @echo '#define AUTOCONFIG_H_INCLUDED' >>$@ @for x in $(DEFINES); do echo "#define $$x" >>$@; done @echo '#endif' >>$@ diff --git a/kpartx/byteorder.h b/kpartx/byteorder.h index 199c66bee..75990a859 100644 --- a/kpartx/byteorder.h +++ b/kpartx/byteorder.h @@ -1,5 +1,5 @@ -#ifndef BYTEORDER_H_INCLUDED -#define BYTEORDER_H_INCLUDED +#ifndef KPARTX_BYTEORDER_H_INCLUDED +#define KPARTX_BYTEORDER_H_INCLUDED #ifdef __linux__ # include @@ -26,4 +26,4 @@ # error unsupported #endif -#endif /* BYTEORDER_H_INCLUDED */ +#endif /* KPARTX_BYTEORDER_H_INCLUDED */ diff --git a/kpartx/crc32.h b/kpartx/crc32.h index a4505b842..abbadbbe6 100644 --- a/kpartx/crc32.h +++ b/kpartx/crc32.h @@ -1,8 +1,8 @@ /* * crc32.h */ -#ifndef _CRC32_H -#define _CRC32_H +#ifndef CRC32_H_INCLUDED +#define CRC32_H_INCLUDED #include #include @@ -16,4 +16,4 @@ extern uint32_t crc32_be(uint32_t crc, unsigned char const *p, size_t len); #define ether_crc_le(length, data) crc32_le(~0, data, length) #define ether_crc(length, data) crc32_be(~0, data, length) -#endif /* _CRC32_H */ +#endif /* CRC32_H_INCLUDED */ diff --git a/kpartx/dasd.h b/kpartx/dasd.h index 8ad5d6202..481ad79ee 100644 --- a/kpartx/dasd.h +++ b/kpartx/dasd.h @@ -22,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef _DASD_H -#define _DASD_H +#ifndef DASD_H_INCLUDED +#define DASD_H_INCLUDED typedef struct ttr { @@ -289,4 +289,4 @@ cchhb2blk (cchhb_t *ptr, struct hd_geometry *geo) ptr->b; } -#endif /* _DASD_H */ +#endif /* DASD_H_INCLUDED */ diff --git a/kpartx/devmapper.h b/kpartx/devmapper.h index 701bdf6e6..e4db86213 100644 --- a/kpartx/devmapper.h +++ b/kpartx/devmapper.h @@ -1,5 +1,5 @@ -#ifndef _KPARTX_DEVMAPPER_H -#define _KPARTX_DEVMAPPER_H +#ifndef KPARTX_DEVMAPPER_H_INCLUDED +#define KPARTX_DEVMAPPER_H_INCLUDED #ifdef DM_SUBSYSTEM_UDEV_FLAG0 #define MPATH_UDEV_RELOAD_FLAG DM_SUBSYSTEM_UDEV_FLAG0 @@ -36,4 +36,4 @@ int dm_find_part(const char *parent, const char *delim, int part, char *nondm_create_uuid(dev_t devt); int nondm_parse_uuid(const char *uuid, unsigned int *major, unsigned int *minor); -#endif /* _KPARTX_DEVMAPPER_H */ +#endif /* KPARTX_DEVMAPPER_H_INCLUDED */ diff --git a/kpartx/dos.h b/kpartx/dos.h index f45e7f688..678cddc5c 100644 --- a/kpartx/dos.h +++ b/kpartx/dos.h @@ -10,4 +10,4 @@ struct partition { unsigned int nr_sects; } __attribute__((packed)); -#endif /* DOS_H_INCLUDED */ +#endif /* DOS_H_INCLUDED */ diff --git a/kpartx/efi.h b/kpartx/efi.h index af5660aa1..10af0e719 100644 --- a/kpartx/efi.h +++ b/kpartx/efi.h @@ -17,8 +17,8 @@ along with this program. If not, see . */ -#ifndef EFI_H -#define EFI_H +#ifndef EFI_H_INCLUDED +#define EFI_H_INCLUDED /* * Extensible Firmware Interface @@ -54,4 +54,4 @@ efi_guidcmp(efi_guid_t left, efi_guid_t right) typedef uint16_t efi_char16_t; /* UNICODE character */ -#endif /* EFI_H */ +#endif /* EFI_H_INCLUDED */ diff --git a/kpartx/gpt.h b/kpartx/gpt.h index 4e1b49aa7..b35320ff3 100644 --- a/kpartx/gpt.h +++ b/kpartx/gpt.h @@ -21,8 +21,8 @@ along with this program. If not, see . */ -#ifndef _GPT_H -#define _GPT_H +#ifndef GPT_H_INCLUDED +#define GPT_H_INCLUDED #include diff --git a/kpartx/kpartx.h b/kpartx/kpartx.h index 727632c1e..8a210304d 100644 --- a/kpartx/kpartx.h +++ b/kpartx/kpartx.h @@ -1,5 +1,5 @@ -#ifndef _KPARTX_H -#define _KPARTX_H +#ifndef KPARTX_H_INCLUDED +#define KPARTX_H_INCLUDED #include #include @@ -70,4 +70,4 @@ four2int(unsigned char *p) { return p[0] + (p[1]<<8) + (p[2]<<16) + (p[3]<<24); } -#endif /* _KPARTX_H */ +#endif /* KPARTX_H_INCLUDED */ diff --git a/kpartx/lopart.h b/kpartx/lopart.h index c73ab2367..7cdcfe7d0 100644 --- a/kpartx/lopart.h +++ b/kpartx/lopart.h @@ -1,4 +1,7 @@ +#ifndef LOPART_H_INCLUDED +#define LOPART_H_INCLUDED extern int verbose; extern int set_loop (char **, const char *, int, int *); extern int del_loop (const char *); extern char * find_loop_by_file (const char *); +#endif diff --git a/kpartx/mac.h b/kpartx/mac.h index 55c3ec927..253fd0dd0 100644 --- a/kpartx/mac.h +++ b/kpartx/mac.h @@ -1,5 +1,5 @@ -#ifndef MAC_H -#define MAC_H +#ifndef MAC_H_INCLUDED +#define MAC_H_INCLUDED #include diff --git a/kpartx/xstrncpy.h b/kpartx/xstrncpy.h index 05c8fa26f..cb87aaac8 100644 --- a/kpartx/xstrncpy.h +++ b/kpartx/xstrncpy.h @@ -1 +1,4 @@ +#ifndef XSTRNCPY_H_INCLUDED +#define XSTRNCPY_H_INCLUDED extern void xstrncpy(char *dest, const char *src, size_t n); +#endif diff --git a/libdmmp/libdmmp/libdmmp.h b/libdmmp/libdmmp/libdmmp.h index 6e6610d4a..25cd42ec8 100644 --- a/libdmmp/libdmmp/libdmmp.h +++ b/libdmmp/libdmmp/libdmmp.h @@ -19,8 +19,8 @@ */ -#ifndef _LIB_DMMP_H_ -#define _LIB_DMMP_H_ +#ifndef LIBDMMP_H_INCLUDED +#define LIBDMMP_H_INCLUDED #include #include @@ -732,4 +732,4 @@ DMMP_DLL_EXPORT const char *dmmp_last_error_msg(struct dmmp_context *ctx); } /* End of extern "C" */ #endif -#endif /* End of _LIB_DMMP_H_ */ +#endif /* End of LIBDMMP_H_INCLUDED */ diff --git a/libdmmp/libdmmp_private.h b/libdmmp/libdmmp_private.h index b1a6ddeae..9606fb39b 100644 --- a/libdmmp/libdmmp_private.h +++ b/libdmmp/libdmmp_private.h @@ -18,8 +18,8 @@ * Todd Gill */ -#ifndef _LIB_DMMP_PRIVATE_H_ -#define _LIB_DMMP_PRIVATE_H_ +#ifndef LIBDMMP_PRIVATE_H_INCLUDED +#define LIBDMMP_PRIVATE_H_INCLUDED /* * Notes: @@ -209,4 +209,4 @@ DMMP_DLL_LOCAL void _dmmp_log_stderr(struct dmmp_context *ctx, int priority, } /* End of extern "C" */ #endif -#endif /* End of _LIB_DMMP_PRIVATE_H_ */ +#endif /* End of LIBDMMP_PRIVATE_H_INCLUDED */ diff --git a/libmpathcmd/mpath_cmd.h b/libmpathcmd/mpath_cmd.h index 0c293c718..b58aaac5f 100644 --- a/libmpathcmd/mpath_cmd.h +++ b/libmpathcmd/mpath_cmd.h @@ -17,8 +17,8 @@ * along with this program. If not, see . */ -#ifndef LIB_MPATH_CMD_H -#define LIB_MPATH_CMD_H +#ifndef MPATH_CMD_H_INCLUDED +#define MPATH_CMD_H_INCLUDED /* * This should be sufficient for json output for >10000 maps, @@ -141,4 +141,4 @@ int mpath_recv_reply_data(int fd, char *reply, size_t len, #ifdef __cplusplus } #endif -#endif /* LIB_MPATH_CMD_H */ +#endif /* MPATH_CMD_H_INCLUDED */ diff --git a/libmpathpersist/mpath_persist.h b/libmpathpersist/mpath_persist.h index 0046f1206..9c88e151b 100644 --- a/libmpathpersist/mpath_persist.h +++ b/libmpathpersist/mpath_persist.h @@ -1,7 +1,7 @@ /* version - 1.0 */ -#ifndef MPATH_PERSIST_LIB_H -#define MPATH_PERSIST_LIB_H +#ifndef MPATH_PERSIST_H_INCLUDED +#define MPATH_PERSIST_H_INCLUDED #ifdef __cplusplus @@ -326,4 +326,4 @@ void mpath_persistent_reserve_free_vecs(void); } #endif -#endif /*MPATH_PERSIST_LIB_H*/ +#endif /* MPATH_PERSIST_H_INCLUDED */ diff --git a/libmpathpersist/mpath_persist_int.h b/libmpathpersist/mpath_persist_int.h index 31457535a..7819823c8 100644 --- a/libmpathpersist/mpath_persist_int.h +++ b/libmpathpersist/mpath_persist_int.h @@ -1,5 +1,5 @@ -#ifndef _MPATH_PERSIST_INT_H -#define _MPATH_PERSIST_INT_H +#ifndef MPATH_PERSIST_INT_H_INCLUDED +#define MPATH_PERSIST_INT_H_INCLUDED /* * This header file contains symbols that are used by multipath-tools @@ -22,4 +22,4 @@ int prout_do_scsi_ioctl( char * dev, int rq_servact, int rq_scope, void dumpHex(const char* , int len, int no_ascii); int update_map_pr(struct multipath *mpp); -#endif /* _MPATH_PERSIST_INT_H */ +#endif /* MPATH_PERSIST_INT_H_INCLUDED */ diff --git a/libmpathpersist/mpath_pr_ioctl.h b/libmpathpersist/mpath_pr_ioctl.h index 625490f78..b1d9be1a8 100644 --- a/libmpathpersist/mpath_pr_ioctl.h +++ b/libmpathpersist/mpath_pr_ioctl.h @@ -1,3 +1,6 @@ +#ifndef MPATH_PR_IOCTL_H_INCLUDED +#define MPATH_PR_IOCTL_H_INCLUDED + #define MPATH_XFER_HOST_DEV 0 /*data transfer from initiator to target */ #define MPATH_XFER_DEV_HOST 1 /*data transfer from target to initiator */ #define MPATH_XFER_NONE 2 /*no data transfer */ @@ -107,3 +110,5 @@ typedef struct SenseData /* Driver status */ #define DRIVER_OK 0x00 + +#endif diff --git a/libmpathpersist/mpathpr.h b/libmpathpersist/mpathpr.h index 39a7d8ed0..cc1a5673c 100644 --- a/libmpathpersist/mpathpr.h +++ b/libmpathpersist/mpathpr.h @@ -1,5 +1,5 @@ -#ifndef MPATHPR_H -#define MPATHPR_H +#ifndef MPATHPR_H_INCLUDED +#define MPATHPR_H_INCLUDED /* * This header file contains symbols that are only used by diff --git a/libmpathutil/debug.h b/libmpathutil/debug.h index 705a5d733..c2a2f6e60 100644 --- a/libmpathutil/debug.h +++ b/libmpathutil/debug.h @@ -1,5 +1,5 @@ -#ifndef _DEBUG_H -#define _DEBUG_H +#ifndef DEBUG_H_INCLUDED +#define DEBUG_H_INCLUDED void dlog (int prio, const char *fmt, ...) __attribute__((format(printf, 2, 3))); @@ -29,4 +29,4 @@ enum { if (__p <= MAX_VERBOSITY && __p <= libmp_verbosity) \ dlog(__p, fmt "\n", ##args); \ } while (0) -#endif /* _DEBUG_H */ +#endif /* DEBUG_H_INCLUDED */ diff --git a/libmpathutil/globals.h b/libmpathutil/globals.h index a4d4d4e26..fbb140167 100644 --- a/libmpathutil/globals.h +++ b/libmpathutil/globals.h @@ -1,5 +1,5 @@ -#ifndef _GLOBALS_H -#define _GLOBALS_H +#ifndef GLOBALS_H_INCLUDED +#define GLOBALS_H_INCLUDED struct config; diff --git a/libmpathutil/log.h b/libmpathutil/log.h index fa224e4dd..e3d269c4f 100644 --- a/libmpathutil/log.h +++ b/libmpathutil/log.h @@ -1,5 +1,5 @@ -#ifndef LOG_H -#define LOG_H +#ifndef LOG_H_INCLUDED +#define LOG_H_INCLUDED #define DEFAULT_AREA_SIZE 16384 #define MAX_MSG_SIZE 256 @@ -40,4 +40,4 @@ int log_dequeue (void *); void log_syslog (void *); void dump_logmsg (void *); -#endif /* LOG_H */ +#endif /* LOG_H_INCLUDED */ diff --git a/libmpathutil/log_pthread.h b/libmpathutil/log_pthread.h index 810ac9201..dea57b876 100644 --- a/libmpathutil/log_pthread.h +++ b/libmpathutil/log_pthread.h @@ -1,5 +1,5 @@ -#ifndef _LOG_PTHREAD_H -#define _LOG_PTHREAD_H +#ifndef LOG_PTHREAD_H_INCLUDED +#define LOG_PTHREAD_H_INCLUDED #include @@ -9,4 +9,4 @@ void log_thread_start(pthread_attr_t *attr); void log_thread_reset (void); void log_thread_stop(void); -#endif /* _LOG_PTHREAD_H */ +#endif /* LOG_PTHREAD_H_INCLUDED */ diff --git a/libmpathutil/msort.h b/libmpathutil/msort.h index caef9b6b7..edfa4388c 100644 --- a/libmpathutil/msort.h +++ b/libmpathutil/msort.h @@ -1,5 +1,5 @@ -#ifndef __MSORT_H -#define __MSORT_H +#ifndef MSORT_H_INCLUDED +#define MSORT_H_INCLUDED typedef int(*__compar_fn_t)(const void *, const void *); void msort (void *b, size_t n, size_t s, __compar_fn_t cmp); diff --git a/libmpathutil/parser.h b/libmpathutil/parser.h index 9d9d948d5..baa9c5573 100644 --- a/libmpathutil/parser.h +++ b/libmpathutil/parser.h @@ -20,8 +20,8 @@ * 2 of the License, or (at your option) any later version. */ -#ifndef _PARSER_H -#define _PARSER_H +#ifndef PARSER_H_INCLUDED +#define PARSER_H_INCLUDED /* system includes */ #include diff --git a/libmpathutil/strbuf.h b/libmpathutil/strbuf.h index ae863417e..68f21dee3 100644 --- a/libmpathutil/strbuf.h +++ b/libmpathutil/strbuf.h @@ -2,8 +2,8 @@ * Copyright (c) 2021 SUSE LLC * SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef _STRBUF_H -#define _STRBUF_H +#ifndef STRBUF_H_INCLUDED +#define STRBUF_H_INCLUDED #include #include diff --git a/libmpathutil/time-util.h b/libmpathutil/time-util.h index 4a80ebd32..dfffe4b1c 100644 --- a/libmpathutil/time-util.h +++ b/libmpathutil/time-util.h @@ -1,5 +1,5 @@ -#ifndef _TIME_UTIL_H_ -#define _TIME_UTIL_H_ +#ifndef TIME_UTIL_H_INCLUDED +#define TIME_UTIL_H_INCLUDED #include @@ -12,4 +12,4 @@ void timespecsub(const struct timespec *a, const struct timespec *b, struct timespec *res); int timespeccmp(const struct timespec *a, const struct timespec *b); -#endif /* _TIME_UTIL_H_ */ +#endif /* TIME_UTIL_H_INCLUDED */ diff --git a/libmpathutil/util.h b/libmpathutil/util.h index 7bad85592..110b2f68f 100644 --- a/libmpathutil/util.h +++ b/libmpathutil/util.h @@ -1,5 +1,5 @@ -#ifndef _UTIL_H -#define _UTIL_H +#ifndef UTIL_H_INCLUDED +#define UTIL_H_INCLUDED #include #include @@ -147,4 +147,4 @@ void cleanup_charp(char **p); void cleanup_ucharp(unsigned char **p); void cleanup_udev_device(struct udev_device **udd); -#endif /* _UTIL_H */ +#endif /* UTIL_H_INCLUDED */ diff --git a/libmpathutil/uxsock.h b/libmpathutil/uxsock.h index e3d28cf5f..815706043 100644 --- a/libmpathutil/uxsock.h +++ b/libmpathutil/uxsock.h @@ -1,7 +1,10 @@ /* some prototypes */ +#ifndef UXSOCK_H_INCLUDED +#define UXSOCK_H_INCLUDED + int ux_socket_listen(const char *name); int send_packet(int fd, const char *buf); int recv_packet(int fd, char **buf, unsigned int timeout); #define _MAX_CMD_LEN 512 - +#endif diff --git a/libmpathutil/vector.h b/libmpathutil/vector.h index a41f15740..2df15051d 100644 --- a/libmpathutil/vector.h +++ b/libmpathutil/vector.h @@ -20,8 +20,8 @@ * 2 of the License, or (at your option) any later version. */ -#ifndef _VECTOR_H -#define _VECTOR_H +#ifndef VECTOR_H_INCLUDED +#define VECTOR_H_INCLUDED #include diff --git a/libmpathvalid/mpath_valid.h b/libmpathvalid/mpath_valid.h index 636f16343..de165a2d4 100644 --- a/libmpathvalid/mpath_valid.h +++ b/libmpathvalid/mpath_valid.h @@ -17,8 +17,8 @@ * along with this program. If not, see . */ -#ifndef LIB_MPATH_VALID_H -#define LIB_MPATH_VALID_H +#ifndef MPATH_VALID_H_INCLUDED +#define MPATH_VALID_H_INCLUDED #ifdef __cplusplus extern "C" { @@ -152,4 +152,4 @@ int mpathvalid_is_path(const char *name, unsigned int mode, char **wwid, #ifdef __cplusplus } #endif -#endif /* LIB_PATH_VALID_H */ +#endif /* MPATH_VALID_H_INCLUDED */ diff --git a/libmultipath/alias.h b/libmultipath/alias.h index 629e8d566..eb3c15b8a 100644 --- a/libmultipath/alias.h +++ b/libmultipath/alias.h @@ -1,5 +1,5 @@ -#ifndef _ALIAS_H -#define _ALIAS_H +#ifndef ALIAS_H_INCLUDED +#define ALIAS_H_INCLUDED int valid_alias(const char *alias); int get_user_friendly_wwid(const char *alias, char *buff); @@ -11,4 +11,4 @@ int check_alias_settings(const struct config *); void cleanup_bindings(void); struct inotify_event; void handle_bindings_file_inotify(const struct inotify_event *event); -#endif /* _ALIAS_H */ +#endif /* ALIAS_H_INCLUDED */ diff --git a/libmultipath/blacklist.h b/libmultipath/blacklist.h index dde5cea45..244c59d93 100644 --- a/libmultipath/blacklist.h +++ b/libmultipath/blacklist.h @@ -1,5 +1,5 @@ -#ifndef _BLACKLIST_H -#define _BLACKLIST_H +#ifndef BLACKLIST_H_INCLUDED +#define BLACKLIST_H_INCLUDED #include #include @@ -54,4 +54,4 @@ void free_blacklist_device (vector); void merge_blacklist(vector); void merge_blacklist_device(vector); -#endif /* _BLACKLIST_H */ +#endif /* BLACKLIST_H_INCLUDED */ diff --git a/libmultipath/checkers.h b/libmultipath/checkers.h index ea1e8af62..51ceea0df 100644 --- a/libmultipath/checkers.h +++ b/libmultipath/checkers.h @@ -1,5 +1,5 @@ -#ifndef _CHECKERS_H -#define _CHECKERS_H +#ifndef CHECKERS_H_INCLUDED +#define CHECKERS_H_INCLUDED #include #include "list.h" @@ -199,4 +199,4 @@ void *libcheck_thread(struct checker_context *ctx); */ extern const char *libcheck_msgtable[]; -#endif /* _CHECKERS_H */ +#endif /* CHECKERS_H_INCLUDED */ diff --git a/libmultipath/checkers/cciss.h b/libmultipath/checkers/cciss.h index cf2094656..bdb118424 100644 --- a/libmultipath/checkers/cciss.h +++ b/libmultipath/checkers/cciss.h @@ -1,5 +1,5 @@ -#ifndef CCISS_H -#define CCISS_H +#ifndef CCISS_H_INCLUDED +#define CCISS_H_INCLUDED #include #include diff --git a/libmultipath/checkers/directio.h b/libmultipath/checkers/directio.h index 1865b1fcd..15b3da497 100644 --- a/libmultipath/checkers/directio.h +++ b/libmultipath/checkers/directio.h @@ -1,8 +1,8 @@ -#ifndef _DIRECTIO_H -#define _DIRECTIO_H +#ifndef DIRECTIO_H_INCLUDED +#define DIRECTIO_H_INCLUDED int directio (struct checker *); int directio_init (struct checker *); void directio_free (struct checker *); -#endif /* _DIRECTIO_H */ +#endif /* DIRECTIO_H_INCLUDED */ diff --git a/libmultipath/checkers/emc_clariion.h b/libmultipath/checkers/emc_clariion.h index a1018a666..ee85dd530 100644 --- a/libmultipath/checkers/emc_clariion.h +++ b/libmultipath/checkers/emc_clariion.h @@ -1,8 +1,8 @@ -#ifndef _EMC_CLARIION_H -#define _EMC_CLARIION_H +#ifndef EMC_CLARIION_H_INCLUDED +#define EMC_CLARIION_H_INCLUDED int emc_clariion (struct checker *); int emc_clariion_init (struct checker *); void emc_clariion_free (struct checker *); -#endif /* _EMC_CLARIION_H */ +#endif /* EMC_CLARIION_H_INCLUDED */ diff --git a/libmultipath/checkers/hp_sw.h b/libmultipath/checkers/hp_sw.h index 3be0d8eab..058935135 100644 --- a/libmultipath/checkers/hp_sw.h +++ b/libmultipath/checkers/hp_sw.h @@ -1,8 +1,8 @@ -#ifndef _HP_SW_H -#define _HP_SW_H +#ifndef HP_SW_H_INCLUDED +#define HP_SW_H_INCLUDED int hp_sw (struct checker *); int hp_sw_init (struct checker *); void hp_sw_free (struct checker *); -#endif /* _HP_SW_H */ +#endif /* HP_SW_H_INCLUDED */ diff --git a/libmultipath/checkers/rdac.h b/libmultipath/checkers/rdac.h index d7bf8124b..5a92b285c 100644 --- a/libmultipath/checkers/rdac.h +++ b/libmultipath/checkers/rdac.h @@ -1,8 +1,8 @@ -#ifndef _RDAC_H -#define _RDAC_H +#ifndef RDAC_H_INCLUDED +#define RDAC_H_INCLUDED int rdac(struct checker *); int rdac_init(struct checker *); void rdac_free(struct checker *); -#endif /* _RDAC_H */ +#endif /* RDAC_H_INCLUDED */ diff --git a/libmultipath/checkers/readsector0.h b/libmultipath/checkers/readsector0.h index 0f5d65438..486613d4e 100644 --- a/libmultipath/checkers/readsector0.h +++ b/libmultipath/checkers/readsector0.h @@ -1,8 +1,8 @@ -#ifndef _READSECTOR0_H -#define _READSECTOR0_H +#ifndef READSECTOR0_H_INCLUDED +#define READSECTOR0_H_INCLUDED int readsector0 (struct checker *); int readsector0_init (struct checker *); void readsector0_free (struct checker *); -#endif /* _READSECTOR0_H */ +#endif /* READSECTOR0_H_INCLUDED */ diff --git a/libmultipath/checkers/tur.h b/libmultipath/checkers/tur.h index a2e8c8883..62a47d126 100644 --- a/libmultipath/checkers/tur.h +++ b/libmultipath/checkers/tur.h @@ -1,8 +1,8 @@ -#ifndef _TUR_H -#define _TUR_H +#ifndef TUR_H_INCLUDED +#define TUR_H_INCLUDED int tur (struct checker *); int tur_init (struct checker *); void tur_free (struct checker *); -#endif /* _TUR_H */ +#endif /* TUR_H_INCLUDED */ diff --git a/libmultipath/config.h b/libmultipath/config.h index 800c0ca9c..181b78ab7 100644 --- a/libmultipath/config.h +++ b/libmultipath/config.h @@ -1,5 +1,5 @@ -#ifndef _CONFIG_H -#define _CONFIG_H +#ifndef CONFIG_H_INCLUDED +#define CONFIG_H_INCLUDED #include #include diff --git a/libmultipath/configure.h b/libmultipath/configure.h index 9d935db3f..ca34442eb 100644 --- a/libmultipath/configure.h +++ b/libmultipath/configure.h @@ -1,3 +1,6 @@ +#ifndef CONFIGURE_H_INCLUDED +#define CONFIGURE_H_INCLUDED + /* * configurator actions */ @@ -63,3 +66,4 @@ void trigger_paths_udev_change(struct multipath *mpp, bool is_mpath); void trigger_partitions_udev_change(struct udev_device *dev, const char *action, int len); int check_daemon(void); +#endif diff --git a/libmultipath/defaults.h b/libmultipath/defaults.h index ed08c2516..02f7e57c1 100644 --- a/libmultipath/defaults.h +++ b/libmultipath/defaults.h @@ -1,5 +1,6 @@ -#ifndef _DEFAULTS_H -#define _DEFAULTS_H +#ifndef DEFAULTS_H_INCLUDED +#define DEFAULTS_H_INCLUDED + #include #include @@ -78,4 +79,4 @@ static inline char *set_default(char *str) return strdup(str); } extern const char *const default_partition_delim; -#endif /* _DEFAULTS_H */ +#endif /* DEFAULTS_H_INCLUDED */ diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index a26dc1e5d..b5330ab3b 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -1,5 +1,6 @@ -#ifndef _DEVMAPPER_H -#define _DEVMAPPER_H +#ifndef DEVMAPPER_H_INCLUDED +#define DEVMAPPER_H_INCLUDED + #include #include #include "autoconfig.h" @@ -210,4 +211,4 @@ int libmp_dm_task_run(struct dm_task *dmt); condlog(lvl, "%s: libdm task=%d error: %s", __func__, \ cmd, strerror(dm_task_get_errno(dmt))) \ -#endif /* _DEVMAPPER_H */ +#endif /* DEVMAPPER_H_INCLUDED */ diff --git a/libmultipath/dict.h b/libmultipath/dict.h index e17945379..97c91c8e8 100644 --- a/libmultipath/dict.h +++ b/libmultipath/dict.h @@ -1,10 +1,7 @@ -#ifndef _DICT_H -#define _DICT_H +#ifndef DICT_H_INCLUDED +#define DICT_H_INCLUDED -#ifndef _VECTOR_H #include "vector.h" -#endif - #include "byteorder.h" struct strbuf; @@ -19,4 +16,4 @@ int print_dev_loss(struct strbuf *buff, unsigned long v); int print_off_int_undef(struct strbuf *buff, long v); int print_auto_resize(struct strbuf *buff, long v); int print_flush_on_last_del(struct strbuf *buff, long v); -#endif /* _DICT_H */ +#endif /* DICT_H_INCLUDED */ diff --git a/libmultipath/discovery.h b/libmultipath/discovery.h index acd517928..5bd35caa6 100644 --- a/libmultipath/discovery.h +++ b/libmultipath/discovery.h @@ -1,5 +1,5 @@ -#ifndef DISCOVERY_H -#define DISCOVERY_H +#ifndef DISCOVERY_H_INCLUDED +#define DISCOVERY_H_INCLUDED #define SYSFS_PATH_SIZE 255 #define INQUIRY_CMDLEN 6 @@ -84,4 +84,4 @@ enum discovery_mode { #define DI_ALL (DI_SYSFS | DI_SERIAL | DI_CHECKER | DI_PRIO | \ DI_WWID) -#endif /* DISCOVERY_H */ +#endif /* DISCOVERY_H_INCLUDED */ diff --git a/libmultipath/dm-generic.h b/libmultipath/dm-generic.h index 986429f52..9055ce1ce 100644 --- a/libmultipath/dm-generic.h +++ b/libmultipath/dm-generic.h @@ -14,8 +14,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#ifndef _DM_GENERIC_H -#define _DM_GENERIC_H +#ifndef DM_GENERIC_H_INCLUDED +#define DM_GENERIC_H_INCLUDED #include "generic.h" #include "list.h" /* for container_of */ #include "structs.h" @@ -36,4 +36,4 @@ extern const struct gen_multipath_ops dm_gen_multipath_ops; extern const struct gen_pathgroup_ops dm_gen_pathgroup_ops; extern const struct gen_path_ops dm_gen_path_ops; -#endif /* _DM_GENERIC_H */ +#endif /* DM_GENERIC_H_INCLUDED */ diff --git a/libmultipath/dmparser.h b/libmultipath/dmparser.h index 666ae74ed..43454c379 100644 --- a/libmultipath/dmparser.h +++ b/libmultipath/dmparser.h @@ -1,3 +1,8 @@ +#ifndef DMPARSER_H_INCLUDED +#define DMPARSER_H_INCLUDED + int assemble_map (struct multipath *, char **); int disassemble_map (const struct _vector *, const char *, struct multipath *); int disassemble_status (const char *, struct multipath *); + +#endif diff --git a/libmultipath/file.h b/libmultipath/file.h index 3c75c9050..57b517f66 100644 --- a/libmultipath/file.h +++ b/libmultipath/file.h @@ -2,8 +2,8 @@ * Copyright (c) 2010 Benjamin Marzinski, Redhat */ -#ifndef _FILE_H -#define _FILE_H +#ifndef FILE_H_INCLUDED +#define FILE_H_INCLUDED #include @@ -11,4 +11,4 @@ int ensure_directories_exist(const char *str, mode_t dir_mode); int open_file(const char *file, int *can_write, const char *header); -#endif /* _FILE_H */ +#endif /* FILE_H_INCLUDED */ diff --git a/libmultipath/foreign.h b/libmultipath/foreign.h index b9cdb36e7..db1592c7c 100644 --- a/libmultipath/foreign.h +++ b/libmultipath/foreign.h @@ -14,8 +14,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#ifndef _FOREIGN_H -#define _FOREIGN_H +#ifndef FOREIGN_H_INCLUDED +#define FOREIGN_H_INCLUDED + #include #include #define LIBMP_FOREIGN_API ((1 << 8) | 2) @@ -320,4 +321,4 @@ is_claimed_by_foreign(struct udev_device *ud) return (rc == FOREIGN_CLAIMED || rc == FOREIGN_OK); } -#endif /* _FOREIGN_H */ +#endif /* FOREIGN_H_INCLUDED */ diff --git a/libmultipath/generic.h b/libmultipath/generic.h index e89848f37..c8fe31cb6 100644 --- a/libmultipath/generic.h +++ b/libmultipath/generic.h @@ -14,8 +14,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#ifndef _GENERIC_H -#define _GENERIC_H +#ifndef GENERIC_H_INCLUDED +#define GENERIC_H_INCLUDED #include "vector.h" /* @@ -138,4 +138,4 @@ struct gen_path { int generic_style(const struct gen_multipath*, struct strbuf *buf, int verbosity); -#endif /* _GENERIC_H */ +#endif /* GENERIC_H_INCLUDED */ diff --git a/libmultipath/hwtable.h b/libmultipath/hwtable.h index 13c570119..737e821c7 100644 --- a/libmultipath/hwtable.h +++ b/libmultipath/hwtable.h @@ -1,6 +1,6 @@ -#ifndef _HWTABLE_H -#define _HWTABLE_H +#ifndef HWTABLE_H_INCLUDED +#define HWTABLE_H_INCLUDED int setup_default_hwtable (vector hw); -#endif /* _HWTABLE_H */ +#endif /* HWTABLE_H_INCLUDED */ diff --git a/libmultipath/io_err_stat.h b/libmultipath/io_err_stat.h index 53d6d7deb..8dc298b50 100644 --- a/libmultipath/io_err_stat.h +++ b/libmultipath/io_err_stat.h @@ -1,5 +1,5 @@ -#ifndef _IO_ERR_STAT_H -#define _IO_ERR_STAT_H +#ifndef IO_ERR_STAT_H_INCLUDED +#define IO_ERR_STAT_H_INCLUDED #include "vector.h" #include "lock.h" @@ -12,4 +12,4 @@ void stop_io_err_stat_thread(void); int io_err_stat_handle_pathfail(struct path *path); int need_io_err_check(struct path *pp); -#endif /* _IO_ERR_STAT_H */ +#endif /* IO_ERR_STAT_H_INCLUDED */ diff --git a/libmultipath/libsg.h b/libmultipath/libsg.h index 3994f458c..76eb30d47 100644 --- a/libmultipath/libsg.h +++ b/libmultipath/libsg.h @@ -1,9 +1,9 @@ -#ifndef _LIBSG_H -#define _LIBSG_H +#ifndef LIBSG_H_INCLUDED +#define LIBSG_H_INCLUDED #define SENSE_BUFF_LEN 32 int sg_read (int sg_fd, unsigned char * buff, int buff_len, unsigned char * sense, int sense_len, unsigned int timeout); -#endif /* _LIBSG_H */ +#endif /* LIBSG_H_INCLUDED */ diff --git a/libmultipath/list.h b/libmultipath/list.h index 248f72bc4..8f485209e 100644 --- a/libmultipath/list.h +++ b/libmultipath/list.h @@ -5,8 +5,8 @@ * */ -#ifndef _LIST_H -#define _LIST_H +#ifndef LIST_H_INCLUDED +#define LIST_H_INCLUDED #include @@ -415,4 +415,4 @@ static inline struct list_head *list_pop(struct list_head *head) &pos->member != (to); \ pos = n, n = list_entry(n->member.prev, typeof(*n), member)) -#endif /* _LIST_H */ +#endif /* LIST_H_INCLUDED */ diff --git a/libmultipath/lock.h b/libmultipath/lock.h index ac80d1d85..1c05a77e7 100644 --- a/libmultipath/lock.h +++ b/libmultipath/lock.h @@ -1,5 +1,5 @@ -#ifndef _LOCK_H -#define _LOCK_H +#ifndef LOCK_H_INCLUDED +#define LOCK_H_INCLUDED #include #include @@ -65,4 +65,4 @@ static inline bool lock_has_waiters(struct mutex_lock *a) void cleanup_lock (void * data); void set_wakeup_fn(struct mutex_lock *lock, wakeup_fn *fn); -#endif /* _LOCK_H */ +#endif /* LOCK_H_INCLUDED */ diff --git a/libmultipath/nvme-lib.h b/libmultipath/nvme-lib.h index 448dd9939..059dca8ab 100644 --- a/libmultipath/nvme-lib.h +++ b/libmultipath/nvme-lib.h @@ -1,5 +1,5 @@ -#ifndef NVME_LIB_H -#define NVME_LIB_H +#ifndef NVME_LIB_H_INCLUDED +#define NVME_LIB_H_INCLUDED #include "nvme.h" @@ -36,4 +36,4 @@ int nvme_id_ctrl_ana(int fd, struct nvme_id_ctrl *ctrl); #undef le64_to_cpu #endif -#endif /* NVME_LIB_H */ +#endif /* NVME_LIB_H_INCLUDED */ diff --git a/libmultipath/nvme/argconfig.h b/libmultipath/nvme/argconfig.h index adb192b6a..e6c544534 100644 --- a/libmultipath/nvme/argconfig.h +++ b/libmultipath/nvme/argconfig.h @@ -30,8 +30,8 @@ // //////////////////////////////////////////////////////////////////////// -#ifndef argconfig_H -#define argconfig_H +#ifndef NVME_ARGCONFIG_H_INCLUDED +#define NVME_ARGCONFIG_H_INCLUDED #include #include diff --git a/libmultipath/nvme/json.h b/libmultipath/nvme/json.h index c4ea53160..70df52851 100644 --- a/libmultipath/nvme/json.h +++ b/libmultipath/nvme/json.h @@ -1,5 +1,5 @@ -#ifndef __JSON__H -#define __JSON__H +#ifndef NVME_JSON_H_INCLUDED +#define NVME_JSON_H_INCLUDED struct json_object; struct json_array; diff --git a/libmultipath/nvme/linux/nvme.h b/libmultipath/nvme/linux/nvme.h index 9fc2ae7fa..f0cb29055 100644 --- a/libmultipath/nvme/linux/nvme.h +++ b/libmultipath/nvme/linux/nvme.h @@ -12,8 +12,8 @@ * more details. */ -#ifndef _LINUX_NVME_H -#define _LINUX_NVME_H +#ifndef LINUX_NVME_H_INCLUDED +#define LINUX_NVME_H_INCLUDED #include #include @@ -1525,4 +1525,4 @@ struct nvme_completion { #define NVME_MINOR(ver) (((ver) >> 8) & 0xff) #define NVME_TERTIARY(ver) ((ver) & 0xff) -#endif /* _LINUX_NVME_H */ +#endif /* LINUX_NVME_H_INCLUDED */ diff --git a/libmultipath/nvme/linux/nvme_ioctl.h b/libmultipath/nvme/linux/nvme_ioctl.h index d25a53225..3f6623c89 100644 --- a/libmultipath/nvme/linux/nvme_ioctl.h +++ b/libmultipath/nvme/linux/nvme_ioctl.h @@ -12,8 +12,8 @@ * more details. */ -#ifndef _UAPI_LINUX_NVME_IOCTL_H -#define _UAPI_LINUX_NVME_IOCTL_H +#ifndef LINUX_NVME_IOCTL_H_INCLUDED +#define LINUX_NVME_IOCTL_H_INCLUDED #include #include @@ -64,4 +64,4 @@ struct nvme_passthru_cmd { #define NVME_IOCTL_SUBSYS_RESET _IO('N', 0x45) #define NVME_IOCTL_RESCAN _IO('N', 0x46) -#endif /* _UAPI_LINUX_NVME_IOCTL_H */ +#endif /* LINUX_NVME_IOCTL_H_INCLUDED */ diff --git a/libmultipath/nvme/nvme-ioctl.h b/libmultipath/nvme/nvme-ioctl.h index 565f7648e..246f02e0a 100644 --- a/libmultipath/nvme/nvme-ioctl.h +++ b/libmultipath/nvme/nvme-ioctl.h @@ -1,5 +1,5 @@ -#ifndef _NVME_LIB_H -#define _NVME_LIB_H +#ifndef NVME_NVME_IOCTL_H_INCLUDED +#define NVME_NVME_IOCTL_H_INCLUDED #include #include @@ -155,4 +155,4 @@ int nvme_sanitize(int fd, __u8 sanact, __u8 ause, __u8 owpass, __u8 oipbp, int nvme_self_test_start(int fd, __u32 nsid, __u32 cdw10); int nvme_self_test_log(int fd, struct nvme_self_test_log *self_test_log); int nvme_virtual_mgmt(int fd, __u32 cdw10, __u32 cdw11, __u32 *result); -#endif /* _NVME_LIB_H */ +#endif /* NVME_NVME_IOCTL_H_INCLUDED */ diff --git a/libmultipath/nvme/nvme.h b/libmultipath/nvme/nvme.h index 57f82a311..019bce1bf 100644 --- a/libmultipath/nvme/nvme.h +++ b/libmultipath/nvme/nvme.h @@ -12,8 +12,8 @@ * more details. */ -#ifndef _NVME_H -#define _NVME_H +#ifndef NVME_NVME_H_INCLUDED +#define NVME_NVME_H_INCLUDED #include #include @@ -237,4 +237,4 @@ static inline bool is_64bit_reg(__u32 offset) return false; } -#endif /* _NVME_H */ +#endif /* NVME_NVME_H_INCLUDED */ diff --git a/libmultipath/nvme/plugin.h b/libmultipath/nvme/plugin.h index 91079fbec..6f12946b2 100644 --- a/libmultipath/nvme/plugin.h +++ b/libmultipath/nvme/plugin.h @@ -1,5 +1,5 @@ -#ifndef PLUGIN_H -#define PLUGIN_H +#ifndef NVME_PLUGIN_H_INCLUDED +#define NVME_PLUGIN_H_INCLUDED #include diff --git a/libmultipath/pgpolicies.h b/libmultipath/pgpolicies.h index 9e4ddda25..4469f8b6e 100644 --- a/libmultipath/pgpolicies.h +++ b/libmultipath/pgpolicies.h @@ -1,5 +1,5 @@ -#ifndef _PGPOLICIES_H -#define _PGPOLICIES_H +#ifndef PGPOLICIES_H_INCLUDED +#define PGPOLICIES_H_INCLUDED #if 0 #ifndef _MAIN_H diff --git a/libmultipath/print.h b/libmultipath/print.h index 52f5b2566..eb4cbc233 100644 --- a/libmultipath/print.h +++ b/libmultipath/print.h @@ -1,5 +1,5 @@ -#ifndef _PRINT_H -#define _PRINT_H +#ifndef PRINT_H_INCLUDED +#define PRINT_H_INCLUDED #include "dm-generic.h" #define PRINT_PATH_CHECKER "%i %d %D %p %t %T %o %C" @@ -73,4 +73,4 @@ int snprint_multipath_attr(const struct gen_multipath* gm, struct strbuf *buf, char wildcard); int snprint_multipath_style(const struct gen_multipath *gmp, struct strbuf *style, int verbosity); -#endif /* _PRINT_H */ +#endif /* PRINT_H_INCLUDED */ diff --git a/libmultipath/prio.h b/libmultipath/prio.h index 318d26088..119b75f25 100644 --- a/libmultipath/prio.h +++ b/libmultipath/prio.h @@ -1,5 +1,5 @@ -#ifndef _PRIO_H -#define _PRIO_H +#ifndef PRIO_H_INCLUDED +#define PRIO_H_INCLUDED /* * knowing about path struct gives flexibility to prioritizers @@ -67,4 +67,4 @@ int prio_set_args (struct prio *, const char *); /* The only function exported by prioritizer dynamic libraries (.so) */ int getprio(struct path *, char *); -#endif /* _PRIO_H */ +#endif /* PRIO_H_INCLUDED */ diff --git a/libmultipath/prioritizers/alua.h b/libmultipath/prioritizers/alua.h index 78a3d1554..88fd6af4e 100644 --- a/libmultipath/prioritizers/alua.h +++ b/libmultipath/prioritizers/alua.h @@ -1,5 +1,5 @@ -#ifndef _ALUA_H -#define _ALUA_H +#ifndef ALUA_H_INCLUDED +#define ALUA_H_INCLUDED #include "alua_rtpg.h" diff --git a/libmultipath/prioritizers/alua_rtpg.h b/libmultipath/prioritizers/alua_rtpg.h index c5f9a8f94..ff6ec0ef0 100644 --- a/libmultipath/prioritizers/alua_rtpg.h +++ b/libmultipath/prioritizers/alua_rtpg.h @@ -12,8 +12,8 @@ * * This file is released under the GPL. */ -#ifndef __RTPG_H__ -#define __RTPG_H__ +#ifndef ALUA_RTPG_H_INCLUDED +#define ALUA_RTPG_H_INCLUDED #include "alua_spc3.h" #define RTPG_SUCCESS 0 @@ -26,4 +26,4 @@ int get_target_port_group_support(const struct path *pp); int get_target_port_group(const struct path *pp); int get_asymmetric_access_state(const struct path *pp, unsigned int tpg); -#endif /* __RTPG_H__ */ +#endif /* ALUA_RTPG_H_INCLUDED */ diff --git a/libmultipath/prioritizers/alua_spc3.h b/libmultipath/prioritizers/alua_spc3.h index e1a6c0711..6011c4d6b 100644 --- a/libmultipath/prioritizers/alua_spc3.h +++ b/libmultipath/prioritizers/alua_spc3.h @@ -12,8 +12,8 @@ * * This file is released under the GPL. */ -#ifndef __SPC3_H__ -#define __SPC3_H__ +#ifndef ALUA_SPC3_H_INCLUDED +#define ALUA_SPC3_H_INCLUDED #include "../unaligned.h" /*============================================================================= @@ -323,4 +323,4 @@ struct rtpg_data { ) \ ) -#endif /* __SPC3_H__ */ +#endif /* ALUA_SPC3_H_INCLUDED */ diff --git a/libmultipath/prioritizers/weightedpath.h b/libmultipath/prioritizers/weightedpath.h index a1b268fe4..a8030fdf0 100644 --- a/libmultipath/prioritizers/weightedpath.h +++ b/libmultipath/prioritizers/weightedpath.h @@ -1,5 +1,5 @@ -#ifndef _WEIGHTED_PATH_H -#define _WEIGHTED_PATH_H +#ifndef WEIGHTEDPATH_H_INCLUDED +#define WEIGHTEDPATH_H_INCLUDED #define PRIO_WEIGHTED_PATH "weightedpath" #define HBTL "hbtl" diff --git a/libmultipath/prkey.h b/libmultipath/prkey.h index 43afd5e42..a89a617bd 100644 --- a/libmultipath/prkey.h +++ b/libmultipath/prkey.h @@ -1,5 +1,5 @@ -#ifndef _PRKEY_H -#define _PRKEY_H +#ifndef PRKEY_H_INCLUDED +#define PRKEY_H_INCLUDED #include "structs.h" #include @@ -20,4 +20,4 @@ int set_prkey(struct config *conf, struct multipath *mpp, uint64_t prkey, uint8_t sa_flags); int get_prkey(struct multipath *mpp, uint64_t *prkey, uint8_t *sa_flags); -#endif /* _PRKEY_H */ +#endif /* PRKEY_H_INCLUDED */ diff --git a/libmultipath/propsel.h b/libmultipath/propsel.h index 73615c2f0..559300506 100644 --- a/libmultipath/propsel.h +++ b/libmultipath/propsel.h @@ -1,3 +1,5 @@ +#ifndef PROPSEL_H_INCLUDED +#define PROPSEL_H_INCLUDED int select_rr_weight (struct config *conf, struct multipath * mp); int select_pgfailback (struct config *conf, struct multipath * mp); int select_detect_pgpolicy (struct config *conf, struct multipath * mp); @@ -42,3 +44,4 @@ void reconcile_features_with_options(const char *id, char **features, int *retain_hwhandler); int select_all_tg_pt (struct config *conf, struct multipath * mp); int select_vpd_vendor_id (struct path *pp); +#endif diff --git a/libmultipath/sg_include.h b/libmultipath/sg_include.h index 750a13add..43bff2d5a 100644 --- a/libmultipath/sg_include.h +++ b/libmultipath/sg_include.h @@ -1,3 +1,5 @@ +#ifndef SG_INCLUDE_H_INCLUDED +#define SG_INCLUDE_H_INCLUDED #define __user #include @@ -23,3 +25,4 @@ * retry or fail IO */ #define DID_TRANSPORT_FAILFAST 0x0f /* Transport class fastfailed the io */ #endif +#endif diff --git a/libmultipath/structs.h b/libmultipath/structs.h index 91509881c..6b5de7a81 100644 --- a/libmultipath/structs.h +++ b/libmultipath/structs.h @@ -1,5 +1,5 @@ -#ifndef _STRUCTS_H -#define _STRUCTS_H +#ifndef STRUCTS_H_INCLUDED +#define STRUCTS_H_INCLUDED #include #include @@ -584,4 +584,4 @@ int pathcmp (const struct pathgroup *, const struct pathgroup *); int add_feature (char **, const char *); int remove_feature (char **, const char *); -#endif /* _STRUCTS_H */ +#endif /* STRUCTS_H_INCLUDED */ diff --git a/libmultipath/structs_vec.h b/libmultipath/structs_vec.h index 01f5dc421..541327da4 100644 --- a/libmultipath/structs_vec.h +++ b/libmultipath/structs_vec.h @@ -1,5 +1,5 @@ -#ifndef _STRUCTS_VEC_H -#define _STRUCTS_VEC_H +#ifndef STRUCTS_VEC_H_INCLUDED +#define STRUCTS_VEC_H_INCLUDED #include "vector.h" #include "config.h" @@ -39,4 +39,4 @@ int update_multipath_table (struct multipath *mpp, vector pathvec, int flags); int update_multipath_status (struct multipath *mpp); vector get_used_hwes(const struct _vector *pathvec); -#endif /* _STRUCTS_VEC_H */ +#endif /* STRUCTS_VEC_H_INCLUDED */ diff --git a/libmultipath/switchgroup.h b/libmultipath/switchgroup.h index 9365e2e2e..e499b92ac 100644 --- a/libmultipath/switchgroup.h +++ b/libmultipath/switchgroup.h @@ -1,2 +1,7 @@ +#ifndef SWITCHGROUP_H_INCLUDED +#define SWITCHGROUP_H_INCLUDED + void path_group_prio_update (struct pathgroup * pgp); int select_path_group (struct multipath * mpp); + +#endif diff --git a/libmultipath/sysfs.h b/libmultipath/sysfs.h index 3be3f665e..45f24c379 100644 --- a/libmultipath/sysfs.h +++ b/libmultipath/sysfs.h @@ -2,8 +2,8 @@ * sysfs.h */ -#ifndef _LIBMULTIPATH_SYSFS_H -#define _LIBMULTIPATH_SYSFS_H +#ifndef SYSFS_H_INCLUDED +#define SYSFS_H_INCLUDED #include #include "strbuf.h" diff --git a/libmultipath/uevent.h b/libmultipath/uevent.h index 53a7ca29c..69296789f 100644 --- a/libmultipath/uevent.h +++ b/libmultipath/uevent.h @@ -1,5 +1,5 @@ -#ifndef _UEVENT_H -#define _UEVENT_H +#ifndef UEVENT_H_INCLUDED +#define UEVENT_H_INCLUDED /* * buffer for environment variables, the kernel's size in @@ -69,4 +69,4 @@ static inline char *uevent_get_dm_action(const struct uevent *uev) return uevent_get_dm_str(uev, "DM_ACTION"); } -#endif /* _UEVENT_H */ +#endif /* UEVENT_H_INCLUDED */ diff --git a/libmultipath/unaligned.h b/libmultipath/unaligned.h index b9eaa7cbc..ea8b4a977 100644 --- a/libmultipath/unaligned.h +++ b/libmultipath/unaligned.h @@ -1,5 +1,5 @@ -#ifndef _UNALIGNED_H_ -#define _UNALIGNED_H_ +#ifndef UNALIGNED_H_INCLUDED +#define UNALIGNED_H_INCLUDED #include @@ -51,4 +51,4 @@ static inline void put_unaligned_be64(uint64_t val, void *ptr) put_unaligned_be32(val, p + 4); } -#endif /* _UNALIGNED_H_ */ +#endif /* UNALIGNED_H_INCLUDED */ diff --git a/libmultipath/valid.h b/libmultipath/valid.h index 731e6eff6..96ba5545e 100644 --- a/libmultipath/valid.h +++ b/libmultipath/valid.h @@ -14,8 +14,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#ifndef _VALID_H -#define _VALID_H +#ifndef VALID_H_INCLUDED +#define VALID_H_INCLUDED /* * PATH_IS_VALID_NO_CHECK is returned when multipath should claim @@ -39,4 +39,4 @@ enum is_path_valid_result { int is_path_valid(const char *name, struct config *conf, struct path *pp, bool check_multipathd); -#endif /* _VALID_D */ +#endif /* VALID_H_INCLUDED */ diff --git a/libmultipath/version.h b/libmultipath/version.h index 271d8e74e..5dae23341 100644 --- a/libmultipath/version.h +++ b/libmultipath/version.h @@ -17,8 +17,8 @@ * * Copyright (c) 2006 Christophe Varoqui */ -#ifndef _VERSION_H -#define _VERSION_H +#ifndef VERSION_H_INCLUDED +#define VERSION_H_INCLUDED #define VERSION_CODE 0x000909 /* MMDDYY, in hex */ @@ -35,4 +35,4 @@ MULTIPATH_VERSION(VERSION_CODE), \ MULTIPATH_VERSION(DATE_CODE) -#endif /* _VERSION_H */ +#endif /* VERSION_H_INCLUDED */ diff --git a/libmultipath/wwids.h b/libmultipath/wwids.h index 0c6ee54d5..ee47ad9fa 100644 --- a/libmultipath/wwids.h +++ b/libmultipath/wwids.h @@ -2,8 +2,8 @@ * Copyright (c) 2010 Benjamin Marzinski, Redhat */ -#ifndef _WWIDS_H -#define _WWIDS_H +#ifndef WWIDS_H_INCLUDED +#define WWIDS_H_INCLUDED #define WWIDS_FILE_HEADER \ "# Multipath wwids, Version : 1.0\n" \ @@ -29,4 +29,4 @@ enum { int is_failed_wwid(const char *wwid); int mark_failed_wwid(const char *wwid); int unmark_failed_wwid(const char *wwid); -#endif /* _WWIDS_H */ +#endif /* WWIDS_H_INCLUDED */ diff --git a/mpathpersist/main.h b/mpathpersist/main.h index bfbb82e29..fc0bb2664 100644 --- a/mpathpersist/main.h +++ b/mpathpersist/main.h @@ -1,3 +1,6 @@ +#ifndef MPATHPERSIST_MAIN_H_INCLUDED +#define MPATHPERSIST_MAIN_H_INCLUDED + static struct option long_options[] = { {"verbose", 1, NULL, 'v'}, {"clear", 0, NULL, 'C'}, @@ -28,3 +31,4 @@ static struct option long_options[] = { }; static void usage(void); +#endif diff --git a/multipathd/cli.h b/multipathd/cli.h index c6b79c9d8..294083205 100644 --- a/multipathd/cli.h +++ b/multipathd/cli.h @@ -1,5 +1,5 @@ -#ifndef _CLI_H_ -#define _CLI_H_ +#ifndef CLI_H_INCLUDED +#define CLI_H_INCLUDED #include @@ -157,4 +157,4 @@ vector get_keys(void); vector get_handlers(void); struct key *find_key (const char * str); -#endif /* _CLI_H_ */ +#endif /* CLI_H_INCLUDED */ diff --git a/multipathd/cli_handlers.h b/multipathd/cli_handlers.h index 7eaf847e2..2303d8a9b 100644 --- a/multipathd/cli_handlers.h +++ b/multipathd/cli_handlers.h @@ -1,5 +1,5 @@ -#ifndef _CLI_HANDLERS_H -#define _CLI_HANDLERS_H +#ifndef CLI_HANDLERS_H_INCLUDED +#define CLI_HANDLERS_H_INCLUDED void init_handler_callbacks(void); diff --git a/multipathd/dmevents.h b/multipathd/dmevents.h index 012fbad9c..debb3da0f 100644 --- a/multipathd/dmevents.h +++ b/multipathd/dmevents.h @@ -1,5 +1,5 @@ -#ifndef _DMEVENTS_H -#define _DMEVENTS_H +#ifndef DMEVENTS_H_INCLUDED +#define DMEVENTS_H_INCLUDED #include "structs_vec.h" @@ -10,4 +10,4 @@ int watch_dmevents(char *name); void unwatch_all_dmevents(void); void *wait_dmevents (void *unused); -#endif /* _DMEVENTS_H */ +#endif /* DMEVENTS_H_INCLUDED */ diff --git a/multipathd/fpin.h b/multipathd/fpin.h index 3c374441a..981140a7c 100644 --- a/multipathd/fpin.h +++ b/multipathd/fpin.h @@ -1,5 +1,5 @@ -#ifndef __FPIN_H__ -#define __FPIN_H__ +#ifndef FPIN_H_INCLUDED +#define FPIN_H_INCLUDED #include "autoconfig.h" #ifdef FPIN_EVENT_HANDLER diff --git a/multipathd/init_unwinder.h b/multipathd/init_unwinder.h index ada09f827..edaa8bec8 100644 --- a/multipathd/init_unwinder.h +++ b/multipathd/init_unwinder.h @@ -1,5 +1,5 @@ -#ifndef _INIT_UNWINDER_H -#define _INIT_UNWINDER_H 1 +#ifndef INIT_UNWINDER_H_INCLUDED +#define INIT_UNWINDER_H_INCLUDED /* * init_unwinder(): make sure unwinder symbols are loaded diff --git a/multipathd/main.h b/multipathd/main.h index ef838a022..c94362e4b 100644 --- a/multipathd/main.h +++ b/multipathd/main.h @@ -1,5 +1,5 @@ -#ifndef MAIN_H -#define MAIN_H +#ifndef MAIN_H_INCLUDED +#define MAIN_H_INCLUDED #define MAPGCINT 5 @@ -52,4 +52,4 @@ bool check_path_wwid_change(struct path *pp); int finish_path_init(struct path *pp, struct vectors * vecs); int resize_map(struct multipath *mpp, unsigned long long size, struct vectors *vecs); -#endif /* MAIN_H */ +#endif /* MAIN_H_INCLUDED */ diff --git a/multipathd/pidfile.h b/multipathd/pidfile.h index d308892e9..fae5774f6 100644 --- a/multipathd/pidfile.h +++ b/multipathd/pidfile.h @@ -1 +1,5 @@ +#ifndef PIDFILE_H_INCLUDED +#define PIDFILE_H_INCLUDED int pidfile_create(const char *pidFile, pid_t pid); +#endif + diff --git a/multipathd/uxclnt.h b/multipathd/uxclnt.h index 8e2cdcea8..dd66c528f 100644 --- a/multipathd/uxclnt.h +++ b/multipathd/uxclnt.h @@ -1 +1,6 @@ +#ifndef UXCLNT_H_INCLUDED +#define UXCLNT_H_INCLUDED + int uxclnt(char * inbuf, unsigned int timeout); + +#endif diff --git a/multipathd/uxlsnr.h b/multipathd/uxlsnr.h index 3e45930bd..a14a66787 100644 --- a/multipathd/uxlsnr.h +++ b/multipathd/uxlsnr.h @@ -1,5 +1,5 @@ -#ifndef _UXLSNR_H -#define _UXLSNR_H +#ifndef UXLSNR_H_INCLUDED +#define UXLSNR_H_INCLUDED #include diff --git a/multipathd/waiter.h b/multipathd/waiter.h index 28e0f6d55..7b02272a5 100644 --- a/multipathd/waiter.h +++ b/multipathd/waiter.h @@ -1,5 +1,5 @@ -#ifndef _WAITER_H -#define _WAITER_H +#ifndef WAITER_H_INCLUDED +#define WAITER_H_INCLUDED extern pthread_attr_t waiter_attr; @@ -14,4 +14,4 @@ struct event_thread { void stop_waiter_thread (struct multipath *mpp); int start_waiter_thread (struct multipath *mpp, struct vectors *vecs); -#endif /* _WAITER_H */ +#endif /* WAITER_H_INCLUDED */ diff --git a/tests/test-lib.h b/tests/test-lib.h index efd03a7e4..61e67b29f 100644 --- a/tests/test-lib.h +++ b/tests/test-lib.h @@ -1,5 +1,5 @@ -#ifndef __LIB_H -#define __LIB_H +#ifndef TEST_LIB_H_INCLUDED +#define TEST_LIB_H_INCLUDED extern const int default_mask; extern const char default_devnode[]; diff --git a/tests/test-log.h b/tests/test-log.h index 6d22cd233..48c0c1758 100644 --- a/tests/test-log.h +++ b/tests/test-log.h @@ -1,5 +1,5 @@ -#ifndef _TEST_LOG_H -#define _TEST_LOG_H +#ifndef TEST_LOG_H_INCLUDED +#define TEST_LOG_H_INCLUDED __attribute__((format(printf, 2, 0))) void __wrap_dlog (int prio, const char * fmt, ...); diff --git a/tests/wrap64.h b/tests/wrap64.h index af6cc2ba5..fe985a714 100644 --- a/tests/wrap64.h +++ b/tests/wrap64.h @@ -1,5 +1,5 @@ -#ifndef _WRAP64_H -#define _WRAP64_H 1 +#ifndef WRAP64_H_INCLUDED +#define WRAP64_H_INCLUDED #include #include /* The following include is required for LIBAIO_REDIRECT */ From f00dbc3f94cfcb64d147a9b3d85ab513f3fd8147 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 18:54:12 +0200 Subject: [PATCH 104/145] libmpathcmd: rename __mpath_connect() to mpath_connect__() Identifiers starting with double underscore are forbidden, see https://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathcmd/libmpathcmd.version | 4 ++-- libmpathcmd/mpath_cmd.c | 4 ++-- libmpathcmd/mpath_cmd.h | 2 +- libmultipath/valid.c | 2 +- tests/valid.c | 12 ++++++------ 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/libmpathcmd/libmpathcmd.version b/libmpathcmd/libmpathcmd.version index f1006280a..a786c2573 100644 --- a/libmpathcmd/libmpathcmd.version +++ b/libmpathcmd/libmpathcmd.version @@ -10,10 +10,10 @@ * * See libmultipath.version for general policy about version numbers. */ -LIBMPATHCMD_1.0.0 { +LIBMPATHCMD_2.0.0 { global: - __mpath_connect; mpath_connect; + mpath_connect__; mpath_disconnect; mpath_process_cmd; mpath_recv_reply; diff --git a/libmpathcmd/mpath_cmd.c b/libmpathcmd/mpath_cmd.c index d7c3371e7..1fa036cee 100644 --- a/libmpathcmd/mpath_cmd.c +++ b/libmpathcmd/mpath_cmd.c @@ -94,7 +94,7 @@ static size_t write_all(int fd, const void *buf, size_t len) /* * connect to a unix domain socket */ -int __mpath_connect(int nonblocking) +int mpath_connect__(int nonblocking) { int fd; size_t len; @@ -138,7 +138,7 @@ int __mpath_connect(int nonblocking) */ int mpath_connect(void) { - return __mpath_connect(0); + return mpath_connect__(0); } int mpath_disconnect(int fd) diff --git a/libmpathcmd/mpath_cmd.h b/libmpathcmd/mpath_cmd.h index b58aaac5f..bf30c1ebb 100644 --- a/libmpathcmd/mpath_cmd.h +++ b/libmpathcmd/mpath_cmd.h @@ -47,7 +47,7 @@ extern "C" { * RETURNS: * A file descriptor on success. -1 on failure (with errno set). */ -int __mpath_connect(int nonblocking); +int mpath_connect__(int nonblocking); /* * DESCRIPTION: diff --git a/libmultipath/valid.c b/libmultipath/valid.c index b7e0cc9b6..d75178098 100644 --- a/libmultipath/valid.c +++ b/libmultipath/valid.c @@ -315,7 +315,7 @@ is_path_valid(const char *name, struct config *conf, struct path *pp, } if (check_multipathd) { - fd = __mpath_connect(1); + fd = mpath_connect__(1); if (fd < 0) { if (errno != EAGAIN) { condlog(3, "multipathd not running"); diff --git a/tests/valid.c b/tests/valid.c index ecaeb4677..cb5673446 100644 --- a/tests/valid.c +++ b/tests/valid.c @@ -52,7 +52,7 @@ bool __wrap_sysfs_is_multipathed(struct path *pp, bool set_wwid) return is_multipathed; } -int __wrap___mpath_connect(int nonblocking) +int __wrap_mpath_connect__(int nonblocking) { bool connected = mock_type(bool); assert_int_equal(nonblocking, 1); @@ -223,10 +223,10 @@ static void setup_passing(char *name, char *wwid, unsigned int check_multipathd, if (stage == STAGE_IS_MULTIPATHED) return; if (check_multipathd == CHECK_MPATHD_RUNNING) - will_return(__wrap___mpath_connect, true); + will_return(__wrap_mpath_connect__, true); else if (check_multipathd == CHECK_MPATHD_EAGAIN) { - will_return(__wrap___mpath_connect, false); - will_return(__wrap___mpath_connect, EAGAIN); + will_return(__wrap_mpath_connect__, false); + will_return(__wrap_mpath_connect__, EAGAIN); } /* nothing for CHECK_MPATHD_SKIP */ @@ -332,8 +332,8 @@ static void test_check_multipathd(void **state) conf.find_multipaths = FIND_MULTIPATHS_STRICT; /* test failed check to see if multipathd is active */ will_return(__wrap_sysfs_is_multipathed, false); - will_return(__wrap___mpath_connect, false); - will_return(__wrap___mpath_connect, ECONNREFUSED); + will_return(__wrap_mpath_connect__, false); + will_return(__wrap_mpath_connect__, ECONNREFUSED); assert_int_equal(is_path_valid(name, &conf, &pp, true), PATH_IS_NOT_VALID); From 999ee16d3492ceedccf5a51c63ac4d42a885e751 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 22:08:09 +0200 Subject: [PATCH 105/145] libmpathutil: rename _MAX_CMD_LEN Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libdmmp/libdmmp.c | 2 +- libmpathutil/uxsock.h | 2 +- multipathd/uxlsnr.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libdmmp/libdmmp.c b/libdmmp/libdmmp.c index fcfba06ed..1bfdbedcb 100644 --- a/libdmmp/libdmmp.c +++ b/libdmmp/libdmmp.c @@ -46,7 +46,7 @@ #define _DMMP_JSON_MAPS_KEY "maps" #define _ERRNO_STR_BUFF_SIZE 256 #define _IPC_MAX_CMD_LEN 512 -/* ^ Was _MAX_CMD_LEN in ./libmultipath/uxsock.h */ +/* ^ Was MAX_CMD_LEN in ./libmultipath/uxsock.h */ #define _LAST_ERR_MSG_BUFF_SIZE 1024 struct dmmp_context { diff --git a/libmpathutil/uxsock.h b/libmpathutil/uxsock.h index 815706043..1726a9604 100644 --- a/libmpathutil/uxsock.h +++ b/libmpathutil/uxsock.h @@ -6,5 +6,5 @@ int ux_socket_listen(const char *name); int send_packet(int fd, const char *buf); int recv_packet(int fd, char **buf, unsigned int timeout); -#define _MAX_CMD_LEN 512 +#define MAX_CMD_LEN 512 #endif diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c index 185e0a0ad..198f3823e 100644 --- a/multipathd/uxlsnr.c +++ b/multipathd/uxlsnr.c @@ -59,7 +59,7 @@ struct client { int fd; vector cmdvec; /* NUL byte at end */ - char cmd[_MAX_CMD_LEN + 1]; + char cmd[MAX_CMD_LEN + 1]; struct strbuf reply; struct handler *handler; size_t cmd_len, len; @@ -477,7 +477,7 @@ static int client_state_machine(struct client *c, struct vectors *vecs, condlog(1, "%s: cli[%d]: failed to receive reply len: %zd", __func__, c->fd, n); c->error = -ECONNRESET; - } else if (len <= 0 || len > _MAX_CMD_LEN) { + } else if (len <= 0 || len > MAX_CMD_LEN) { condlog(1, "%s: cli[%d]: invalid command length (%zu bytes)", __func__, c->fd, len); c->error = -ECONNRESET; From dd9be760785e0e1dfb911a3bbdc11ebbc5c677f5 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 19:28:15 +0200 Subject: [PATCH 106/145] libmpathutil: rename __append_strbuf_str() and __get_strbuf_buf() Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathutil/libmpathutil.version | 4 ++-- libmpathutil/parser.c | 4 ++-- libmpathutil/strbuf.c | 6 +++--- libmpathutil/strbuf.h | 6 +++--- libmultipath/alias.c | 2 +- libmultipath/discovery.c | 8 ++++---- libmultipath/print.c | 10 +++++----- tests/strbuf.c | 12 ++++++------ 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/libmpathutil/libmpathutil.version b/libmpathutil/libmpathutil.version index 8393b91cf..270dcd808 100644 --- a/libmpathutil/libmpathutil.version +++ b/libmpathutil/libmpathutil.version @@ -47,8 +47,8 @@ LIBMPATHUTIL_4.0 { global: alloc_bitfield; alloc_strvec; - __append_strbuf_str; append_strbuf_str; + append_strbuf_str__; append_strbuf_quoted; basenamecpy; cleanup_charp; @@ -71,7 +71,7 @@ global: free_strvec; get_linux_version_code; get_monotonic_time; - __get_strbuf_buf; + get_strbuf_buf__; get_next_string; get_strbuf_len; get_strbuf_str; diff --git a/libmpathutil/parser.c b/libmpathutil/parser.c index 29b212ce3..ab7d1aabe 100644 --- a/libmpathutil/parser.c +++ b/libmpathutil/parser.c @@ -167,7 +167,7 @@ snprint_keyword(struct strbuf *buff, const char *fmt, struct keyword *kw, goto out; } if (f != fmt && - (r = __append_strbuf_str(&sbuf, fmt, f - fmt)) < 0) + (r = append_strbuf_str__(&sbuf, fmt, f - fmt)) < 0) goto out; fmt = f + 1; switch(*fmt) { @@ -191,7 +191,7 @@ snprint_keyword(struct strbuf *buff, const char *fmt, struct keyword *kw, } while (*fmt++); out: if (r >= 0) - r = __append_strbuf_str(buff, get_strbuf_str(&sbuf), + r = append_strbuf_str__(buff, get_strbuf_str(&sbuf), get_strbuf_len(&sbuf)); return r; } diff --git a/libmpathutil/strbuf.c b/libmpathutil/strbuf.c index 6e53c3f3e..491a343aa 100644 --- a/libmpathutil/strbuf.c +++ b/libmpathutil/strbuf.c @@ -15,7 +15,7 @@ static const char empty_str[] = ""; -char *__get_strbuf_buf(struct strbuf *buf) +char *get_strbuf_buf__(struct strbuf *buf) { return buf->buf; } @@ -110,7 +110,7 @@ static int expand_strbuf(struct strbuf *buf, int addsz) return 0; } -int __append_strbuf_str(struct strbuf *buf, const char *str, int slen) +int append_strbuf_str__(struct strbuf *buf, const char *str, int slen) { int ret; @@ -135,7 +135,7 @@ int append_strbuf_str(struct strbuf *buf, const char *str) if (slen > INT_MAX) return -ERANGE; - return __append_strbuf_str(buf, str, slen); + return append_strbuf_str__(buf, str, slen); } int fill_strbuf(struct strbuf *buf, char c, int slen) diff --git a/libmpathutil/strbuf.h b/libmpathutil/strbuf.h index 68f21dee3..790dc233c 100644 --- a/libmpathutil/strbuf.h +++ b/libmpathutil/strbuf.h @@ -66,7 +66,7 @@ struct strbuf *new_strbuf(void); * If @strbuf was never written to, the function returns NULL. * The return value of this function must not be free()d. */ -char *__get_strbuf_buf(struct strbuf *buf); +char *get_strbuf_buf__(struct strbuf *buf); /** * get_strbuf_str(): retrieve string from strbuf @@ -112,7 +112,7 @@ size_t get_strbuf_len(const struct strbuf *buf); int truncate_strbuf(struct strbuf *buf, size_t offs); /** - * __append_strbuf_str(): append string of known length + * append_strbuf_str__(): append string of known length * @param buf: the struct strbuf to write to * @param str: the string to append, not necessarily 0-terminated * @param slen: max number of characters to append, must be non-negative @@ -123,7 +123,7 @@ int truncate_strbuf(struct strbuf *buf, size_t offs); * 0-bytes possibly contained in the first @slen characters are copied into * the output. If the function returns an error, @strbuf is unchanged. */ -int __append_strbuf_str(struct strbuf *buf, const char *str, int slen); +int append_strbuf_str__(struct strbuf *buf, const char *str, int slen); /** * append_strbuf_str(): append string diff --git a/libmultipath/alias.c b/libmultipath/alias.c index c4eb5d8d3..5c8ac9350 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -242,7 +242,7 @@ static int write_bindings_file(const Bindings *bindings, int fd, int i; size_t len; - if (__append_strbuf_str(&content, BINDINGS_FILE_HEADER, + if (append_strbuf_str__(&content, BINDINGS_FILE_HEADER, sizeof(BINDINGS_FILE_HEADER) - 1) == -1) return -1; diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 380e0e959..f130a5c90 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -1336,14 +1336,14 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len, vpd += 4; len = vpd_len - 4; - if ((err = __append_strbuf_str(&buf, (const char *)vpd, len)) < 0) + if ((err = append_strbuf_str__(&buf, (const char *)vpd, len)) < 0) return err; /* The input is 0-padded, make sure the length is correct */ truncate_strbuf(&buf, strlen(get_strbuf_str(&buf))); len = get_strbuf_len(&buf); if (type != '8') { - char *buffer = __get_strbuf_buf(&buf); + char *buffer = get_strbuf_buf__(&buf); for (i = 0; i < len; ++i) buffer[i] = tolower(buffer[i]); @@ -1357,7 +1357,7 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len, return err; while (vpd && (p = memchr(vpd, ' ', vpd_len))) { p_len = p - vpd; - if ((err = __append_strbuf_str(&buf, (const char *)vpd, + if ((err = append_strbuf_str__(&buf, (const char *)vpd, p_len)) < 0) return err; vpd = p; @@ -1370,7 +1370,7 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len, return err; } if (vpd_len > 0) { - if ((err = __append_strbuf_str(&buf, (const char *)vpd, + if ((err = append_strbuf_str__(&buf, (const char *)vpd, vpd_len)) < 0) return err; } diff --git a/libmultipath/print.c b/libmultipath/print.c index b7af91379..db0aa3560 100644 --- a/libmultipath/print.c +++ b/libmultipath/print.c @@ -1090,7 +1090,7 @@ int snprint_multipath_header(struct strbuf *line, const char *format, for (f = strchr(format, '%'); f; f = strchr(++format, '%')) { int iwc; - if ((rc = __append_strbuf_str(line, format, f - format)) < 0) + if ((rc = append_strbuf_str__(line, format, f - format)) < 0) return rc; format = f + 1; @@ -1121,7 +1121,7 @@ int _snprint_multipath(const struct gen_multipath *gmp, for (f = strchr(format, '%'); f; f = strchr(++format, '%')) { int iwc; - if ((rc = __append_strbuf_str(line, format, f - format)) < 0) + if ((rc = append_strbuf_str__(line, format, f - format)) < 0) return rc; format = f + 1; @@ -1151,7 +1151,7 @@ int snprint_path_header(struct strbuf *line, const char *format, for (f = strchr(format, '%'); f; f = strchr(++format, '%')) { int iwc; - if ((rc = __append_strbuf_str(line, format, f - format)) < 0) + if ((rc = append_strbuf_str__(line, format, f - format)) < 0) return rc; format = f + 1; @@ -1181,7 +1181,7 @@ int _snprint_path(const struct gen_path *gp, struct strbuf *line, for (f = strchr(format, '%'); f; f = strchr(++format, '%')) { int iwc; - if ((rc = __append_strbuf_str(line, format, f - format)) < 0) + if ((rc = append_strbuf_str__(line, format, f - format)) < 0) return rc; format = f + 1; @@ -1208,7 +1208,7 @@ int _snprint_pathgroup(const struct gen_pathgroup *ggp, struct strbuf *line, int rc; for (f = strchr(format, '%'); f; f = strchr(++format, '%')) { - if ((rc = __append_strbuf_str(line, format, f - format)) < 0) + if ((rc = append_strbuf_str__(line, format, f - format)) < 0) return rc; format = f + 1; diff --git a/tests/strbuf.c b/tests/strbuf.c index d7d4cd94e..1cc161898 100644 --- a/tests/strbuf.c +++ b/tests/strbuf.c @@ -78,7 +78,7 @@ static void test_strbuf_00(void **state) assert_string_equal(p, ""); free(p); - assert_int_equal(__append_strbuf_str(&buf, "x", 0), 0); + assert_int_equal(append_strbuf_str__(&buf, "x", 0), 0); /* appending a 0-length string allocates memory */ assert_in_range(buf.size, 1, SIZE_MAX); assert_int_equal(buf.offs, 0); @@ -181,9 +181,9 @@ static void test_strbuf_nul(void **state) STRBUF_ON_STACK(buf); char greet[] = "hello, sir!"; - assert_int_equal(__append_strbuf_str(&buf, greet, 6), 6); + assert_int_equal(append_strbuf_str__(&buf, greet, 6), 6); assert_string_equal(get_strbuf_str(&buf), "hello,"); - assert_int_equal(__append_strbuf_str(&buf, greet, 6), 6); + assert_int_equal(append_strbuf_str__(&buf, greet, 6), 6); assert_string_equal(get_strbuf_str(&buf), "hello,hello,"); /* overwrite comma with NUL; append_strbuf_str() stops at NUL byte */ @@ -196,14 +196,14 @@ static void test_strbuf_nul(void **state) assert_int_equal(get_strbuf_len(&buf), 10); assert_string_equal(get_strbuf_str(&buf), "hellohello"); - /* __append_strbuf_str() appends full memory, including NUL bytes */ + /* append_strbuf_str__() appends full memory, including NUL bytes */ reset_strbuf(&buf); - assert_int_equal(__append_strbuf_str(&buf, greet, sizeof(greet) - 1), + assert_int_equal(append_strbuf_str__(&buf, greet, sizeof(greet) - 1), sizeof(greet) - 1); assert_int_equal(get_strbuf_len(&buf), sizeof(greet) - 1); assert_string_equal(get_strbuf_str(&buf), "hello"); assert_string_equal(get_strbuf_str(&buf) + get_strbuf_len(&buf) - 5, " sir!"); - assert_int_equal(__append_strbuf_str(&buf, greet, sizeof(greet) - 1), + assert_int_equal(append_strbuf_str__(&buf, greet, sizeof(greet) - 1), sizeof(greet) - 1); assert_string_equal(get_strbuf_str(&buf), "hello"); assert_int_equal(get_strbuf_len(&buf), 2 * (sizeof(greet) - 1)); From 005570b016470c3bbb18e73590fdf3ccc4b3bfd5 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 8 Aug 2024 13:10:36 +0200 Subject: [PATCH 107/145] libmpathutil: rename _log_bitfield_overflow() Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathutil/libmpathutil.version | 2 +- libmpathutil/util.c | 2 +- libmpathutil/util.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libmpathutil/libmpathutil.version b/libmpathutil/libmpathutil.version index 270dcd808..2dcaa3591 100644 --- a/libmpathutil/libmpathutil.version +++ b/libmpathutil/libmpathutil.version @@ -81,7 +81,7 @@ global: install_sublevel_end; is_quote; keyword_alloc; - _log_bitfield_overflow; + log_bitfield_overflow__; libmp_basename; libmp_strlcat; libmp_strlcpy; diff --git a/libmpathutil/util.c b/libmpathutil/util.c index 136aa5954..125597427 100644 --- a/libmpathutil/util.c +++ b/libmpathutil/util.c @@ -354,7 +354,7 @@ struct bitfield *alloc_bitfield(unsigned int maxbit) return bf; } -void _log_bitfield_overflow(const char *f, unsigned int bit, unsigned int len) +void log_bitfield_overflow__(const char *f, unsigned int bit, unsigned int len) { condlog(0, "%s: bitfield overflow: %u >= %u", f, bit, len); } diff --git a/libmpathutil/util.h b/libmpathutil/util.h index 110b2f68f..b1772e3f7 100644 --- a/libmpathutil/util.h +++ b/libmpathutil/util.h @@ -103,9 +103,9 @@ struct bitfield { struct bitfield *alloc_bitfield(unsigned int maxbit); -void _log_bitfield_overflow(const char *f, unsigned int bit, unsigned int len); +void log_bitfield_overflow__(const char *f, unsigned int bit, unsigned int len); #define log_bitfield_overflow(bit, len) \ - _log_bitfield_overflow(__func__, bit, len) + log_bitfield_overflow__(__func__, bit, len) static inline bool is_bit_set_in_bitfield(unsigned int bit, const struct bitfield *bf) From 0a64696e375397e3d5fa17780cf642bd8c535641 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 8 Aug 2024 12:54:59 +0200 Subject: [PATCH 108/145] libmpathutil: rename _install_keyword() to install_keyword__() Also, remove some superfluous extern declarations in parser.h. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathutil/libmpathutil.version | 2 +- libmpathutil/parser.c | 2 +- libmpathutil/parser.h | 28 ++++++++++++++-------------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/libmpathutil/libmpathutil.version b/libmpathutil/libmpathutil.version index 2dcaa3591..fb92f7282 100644 --- a/libmpathutil/libmpathutil.version +++ b/libmpathutil/libmpathutil.version @@ -76,7 +76,7 @@ global: get_strbuf_len; get_strbuf_str; get_word; - _install_keyword; + install_keyword__; install_sublevel; install_sublevel_end; is_quote; diff --git a/libmpathutil/parser.c b/libmpathutil/parser.c index ab7d1aabe..217a87797 100644 --- a/libmpathutil/parser.c +++ b/libmpathutil/parser.c @@ -70,7 +70,7 @@ install_sublevel_end(void) } int -_install_keyword(vector keywords, char *string, +install_keyword__(vector keywords, char *string, handler_fn *handler, print_fn *print, int unique) diff --git a/libmpathutil/parser.h b/libmpathutil/parser.h index baa9c5573..179aeca8d 100644 --- a/libmpathutil/parser.h +++ b/libmpathutil/parser.h @@ -63,22 +63,22 @@ struct keyword { for (i = 0; i < (k)->sub->allocated && ((p) = (k)->sub->slot[i]); i++) /* Prototypes */ -extern int keyword_alloc(vector keywords, char *string, handler_fn *handler, - print_fn *print, int unique); +int keyword_alloc(vector keywords, char *string, handler_fn *handler, + print_fn *print, int unique); #define install_keyword_root(str, h) keyword_alloc(keywords, str, h, NULL, 1) -extern void install_sublevel(void); -extern void install_sublevel_end(void); +void install_sublevel(void); +void install_sublevel_end(void); -extern int _install_keyword(vector keywords, char *string, handler_fn *handler, - print_fn *print, int unique); -#define install_keyword(str, vec, pri) _install_keyword(keywords, str, vec, pri, 1) -#define install_keyword_multi(str, vec, pri) _install_keyword(keywords, str, vec, pri, 0) -extern void dump_keywords(vector keydump, int level); -extern void free_keywords(vector keywords); -extern vector alloc_strvec(char *string); -extern void *set_value(vector strvec); -extern int process_file(struct config *conf, const char *conf_file); -extern struct keyword * find_keyword(vector keywords, vector v, char * name); +int install_keyword__(vector keywords, char *string, handler_fn *handler, + print_fn *print, int unique); +#define install_keyword(str, vec, pri) install_keyword__(keywords, str, vec, pri, 1) +#define install_keyword_multi(str, vec, pri) install_keyword__(keywords, str, vec, pri, 0) +void dump_keywords(vector keydump, int level); +void free_keywords(vector keywords); +vector alloc_strvec(char *string); +void *set_value(vector strvec); +int process_file(struct config *conf, const char *conf_file); +struct keyword * find_keyword(vector keywords, vector v, char * name); int snprint_keyword(struct strbuf *buff, const char *fmt, struct keyword *kw, const void *data); bool is_quote(const char* token); From 346a0a0d60c6b66c43f61cee2df55ca1d7ee9ee1 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 22:11:12 +0200 Subject: [PATCH 109/145] libmultipath: rename _NVME_LIB_C Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/nvme-lib.c | 2 +- libmultipath/nvme-lib.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libmultipath/nvme-lib.c b/libmultipath/nvme-lib.c index f30e7698e..0c2be4f63 100644 --- a/libmultipath/nvme-lib.c +++ b/libmultipath/nvme-lib.c @@ -1,6 +1,6 @@ #include /* avoid inclusion of standard API */ -#define _NVME_LIB_C 1 +#define NVME_LIB_C 1 #include "nvme-lib.h" #include "nvme-ioctl.c" #include "debug.h" diff --git a/libmultipath/nvme-lib.h b/libmultipath/nvme-lib.h index 059dca8ab..6aa9bd223 100644 --- a/libmultipath/nvme-lib.h +++ b/libmultipath/nvme-lib.h @@ -16,7 +16,7 @@ int libmp_nvme_ana_log(int fd, void *ana_log, size_t ana_log_len, int rgo); */ int nvme_id_ctrl_ana(int fd, struct nvme_id_ctrl *ctrl); -#ifndef _NVME_LIB_C +#ifndef NVME_LIB_C /* * In all files except nvme-lib.c, the nvme functions can be called * by their usual name. From 5f36d98adc305cae168bcca048ccc22e35bd7670 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 17:34:21 +0200 Subject: [PATCH 110/145] libmultipath: checkers.h: fix __CHECKER_FIRST_MSG in comment Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/checkers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmultipath/checkers.h b/libmultipath/checkers.h index 51ceea0df..102351f6d 100644 --- a/libmultipath/checkers.h +++ b/libmultipath/checkers.h @@ -194,7 +194,7 @@ void *libcheck_thread(struct checker_context *ctx); * message IDs. * Message IDs available to checkers start at CHECKER_FIRST_MSG. * The msgtable array is 0-based, i.e. msgtable[0] is the message - * for msgid == __CHECKER_FIRST_MSG. + * for msgid == CHECKER_FIRST_MSG. * The table ends with a NULL element. */ extern const char *libcheck_msgtable[]; From 88f101da33f46a7420540f30da55c1764535a27a Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 21:49:45 +0200 Subject: [PATCH 111/145] libmultipath: rename identifiers with leading underscores in devmapper.h Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 16 ++++++++-------- libmultipath/devmapper.h | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index fe604f1bb..0a4b586ce 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -86,10 +86,10 @@ const char *dmp_errstr(int rc) [DMP_OK] = "success", [DMP_NOT_FOUND] = "not found", [DMP_NO_MATCH] = "target type mismatch", - [__DMP_LAST__] = "**invalid**", + [DMP_LAST__] = "**invalid**", }; - if (rc < 0 || rc > __DMP_LAST__) - rc = __DMP_LAST__; + if (rc < 0 || rc > DMP_LAST__) + rc = DMP_LAST__; return str[rc]; } @@ -624,7 +624,7 @@ has_dm_info(const struct multipath *mpp) static int libmp_set_map_identifier(int flags, mapid_t id, struct dm_task *dmt) { - switch (flags & __DM_MAP_BY_MASK) { + switch (flags & DM_MAP_BY_MASK__) { case DM_MAP_BY_UUID: if (!id.str || !(*id.str)) return 0; @@ -682,7 +682,7 @@ static int libmp_mapinfo__(int flags, mapid_t id, mapinfo_t info, const char *ma */ if (info.target && !info.status) ioctl_nr = DM_DEVICE_TABLE; - else if (info.status || info.size || flags & __MAPINFO_TGT_TYPE) + else if (info.status || info.size || flags & MAPINFO_TGT_TYPE__) ioctl_nr = DM_DEVICE_STATUS; else ioctl_nr = DM_DEVICE_INFO; @@ -715,7 +715,7 @@ static int libmp_mapinfo__(int flags, mapid_t id, mapinfo_t info, const char *ma return DMP_NOT_FOUND; } - if (info.target || info.status || info.size || flags & __MAPINFO_TGT_TYPE) { + if (info.target || info.status || info.size || flags & MAPINFO_TGT_TYPE__) { if (dm_get_next_target(dmt, NULL, &start, &length, &target_type, ¶ms) != NULL) { condlog(2, "%s: map %s has multiple targets", fname__, map_id); @@ -725,7 +725,7 @@ static int libmp_mapinfo__(int flags, mapid_t id, mapinfo_t info, const char *ma condlog(2, "%s: map %s has no targets", fname__, map_id); return DMP_NOT_FOUND; } - if (flags & __MAPINFO_TGT_TYPE) { + if (flags & MAPINFO_TGT_TYPE__) { const char *tgt_type = flags & MAPINFO_MPATH_ONLY ? TGT_MPATH : TGT_PART; if (strcmp(target_type, tgt_type)) { @@ -797,7 +797,7 @@ static int libmp_mapinfo__(int flags, mapid_t id, mapinfo_t info, const char *ma /* Helper: format a string describing the map for log messages */ static const char* libmp_map_identifier(int flags, mapid_t id, char buf[BLK_DEV_SIZE]) { - switch (flags & __DM_MAP_BY_MASK) { + switch (flags & DM_MAP_BY_MASK__) { case DM_MAP_BY_NAME: case DM_MAP_BY_UUID: return id.str; diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index b5330ab3b..d9c08fd88 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -35,15 +35,15 @@ enum { DMP_OK, DMP_NOT_FOUND, DMP_NO_MATCH, - __DMP_LAST__, + DMP_LAST__, }; const char* dmp_errstr(int rc); /** - * enum mapinfo_flags: input flags for libmp_mapinfo() + * input flags for libmp_mapinfo() */ -enum __mapinfo_flags { +enum { /** DM_MAP_BY_NAME: identify map by device-mapper name from @name */ DM_MAP_BY_NAME = 0, /** DM_MAP_BY_UUID: identify map by device-mapper UUID from @uuid */ @@ -52,12 +52,12 @@ enum __mapinfo_flags { DM_MAP_BY_DEV, /** DM_MAP_BY_DEVT: identify map by a dev_t */ DM_MAP_BY_DEVT, - __DM_MAP_BY_MASK = (1 << 8) - 1, + DM_MAP_BY_MASK__ = (1 << 8) - 1, /* Fail if target type is not multipath */ MAPINFO_MPATH_ONLY = (1 << 8), /* Fail if target type is not "partition" (linear) */ MAPINFO_PART_ONLY = (1 << 9), - __MAPINFO_TGT_TYPE = (MAPINFO_MPATH_ONLY | MAPINFO_PART_ONLY), + MAPINFO_TGT_TYPE__ = (MAPINFO_MPATH_ONLY | MAPINFO_PART_ONLY), /* Fail if the UUID doesn't match the multipath UUID format */ MAPINFO_CHECK_UUID = (1 << 10), }; @@ -92,7 +92,7 @@ typedef struct libmp_map_info { /** * libmp_mapinfo(): obtain information about a map from the kernel - * @param flags: see __mapinfo_flags above. + * @param flags: see enum values above. * Exactly one of DM_MAP_BY_NAME, DM_MAP_BY_UUID, and DM_MAP_BY_DEV must be set. * @param id: string or major/minor to identify the map to query * @param info: output parameters, see above. Non-NULL elements will be filled in. From 49267896d9e9f19d53d128234b838bdddf22ceed Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 21:52:01 +0200 Subject: [PATCH 112/145] libmultipath: rename identifiers with leading underscores in discovery.h Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/discovery.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/libmultipath/discovery.h b/libmultipath/discovery.h index 5bd35caa6..c93abf1c2 100644 --- a/libmultipath/discovery.h +++ b/libmultipath/discovery.h @@ -62,24 +62,24 @@ bool is_vpd_page_supported(int fd, int pg); * discovery bitmask */ enum discovery_mode { - __DI_SYSFS, - __DI_SERIAL, - __DI_CHECKER, - __DI_PRIO, - __DI_WWID, - __DI_BLACKLIST, - __DI_NOIO, - __DI_NOFALLBACK, + DI_SYSFS__, + DI_SERIAL__, + DI_CHECKER__, + DI_PRIO__, + DI_WWID__, + DI_BLACKLIST__, + DI_NOIO__, + DI_NOFALLBACK__, }; -#define DI_SYSFS (1 << __DI_SYSFS) -#define DI_SERIAL (1 << __DI_SERIAL) -#define DI_CHECKER (1 << __DI_CHECKER) -#define DI_PRIO (1 << __DI_PRIO) -#define DI_WWID (1 << __DI_WWID) -#define DI_BLACKLIST (1 << __DI_BLACKLIST) -#define DI_NOIO (1 << __DI_NOIO) /* Avoid IO on the device */ -#define DI_NOFALLBACK (1 << __DI_NOFALLBACK) /* do not allow wwid fallback */ +#define DI_SYSFS (1 << DI_SYSFS__) +#define DI_SERIAL (1 << DI_SERIAL__) +#define DI_CHECKER (1 << DI_CHECKER__) +#define DI_PRIO (1 << DI_PRIO__) +#define DI_WWID (1 << DI_WWID__) +#define DI_BLACKLIST (1 << DI_BLACKLIST__) +#define DI_NOIO (1 << DI_NOIO__) /* Avoid IO on the device */ +#define DI_NOFALLBACK (1 << DI_NOFALLBACK__) /* do not allow wwid fallback */ #define DI_ALL (DI_SYSFS | DI_SERIAL | DI_CHECKER | DI_PRIO | \ DI_WWID) From 901330c51f1da0d702f6368952b876eb3f695425 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 21:55:05 +0200 Subject: [PATCH 113/145] libmultipath: rename __snprint_config() Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/libmultipath.version | 10 +++------- libmultipath/print.c | 4 ++-- libmultipath/print.h | 2 +- multipathd/cli_handlers.c | 2 +- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index 0ec45271a..e6c6daf1b 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -43,7 +43,7 @@ LIBMPATHCOMMON_1.0.0 { put_multipath_config; }; -LIBMULTIPATH_25.0.0 { +LIBMULTIPATH_26.0.0 { global: /* symbols referenced by multipath and multipathd */ add_foreign; @@ -74,6 +74,7 @@ global: dm_cancel_deferred_remove; dm_enablegroup; dm_fail_path; + dm_find_map_by_wwid; _dm_flush_map; dm_flush_map_nopaths; dm_flush_maps; @@ -172,7 +173,7 @@ global: should_multipath; skip_libmp_dm_init; snprint_blacklist_report; - __snprint_config; + snprint_config__; snprint_config; snprint_devices; snprint_foreign_multipaths; @@ -241,8 +242,3 @@ global: local: *; }; - -LIBMULTIPATH_25.1.0 { -global: - dm_find_map_by_wwid; -} LIBMULTIPATH_25.0.0; diff --git a/libmultipath/print.c b/libmultipath/print.c index db0aa3560..b911802a9 100644 --- a/libmultipath/print.c +++ b/libmultipath/print.c @@ -1908,7 +1908,7 @@ static int snprint_blacklist_except(const struct config *conf, return get_strbuf_len(buff) - initial_len; } -int __snprint_config(const struct config *conf, struct strbuf *buff, +int snprint_config__(const struct config *conf, struct strbuf *buff, const struct _vector *hwtable, const struct _vector *mpvec) { int rc; @@ -1934,7 +1934,7 @@ char *snprint_config(const struct config *conf, int *len, { STRBUF_ON_STACK(buff); char *reply; - int rc = __snprint_config(conf, &buff, hwtable, mpvec); + int rc = snprint_config__(conf, &buff, hwtable, mpvec); if (rc < 0) return NULL; diff --git a/libmultipath/print.h b/libmultipath/print.h index eb4cbc233..4dd2ef2d6 100644 --- a/libmultipath/print.h +++ b/libmultipath/print.h @@ -40,7 +40,7 @@ int _snprint_multipath_topology (const struct gen_multipath *, struct strbuf *, #define snprint_multipath_topology(buf, mpp, v, w) \ _snprint_multipath_topology (dm_multipath_to_gen(mpp), buf, v, w) int snprint_multipath_topology_json(struct strbuf *, const struct vectors *vecs); -int __snprint_config(const struct config *conf, struct strbuf *buff, +int snprint_config__(const struct config *conf, struct strbuf *buff, const struct _vector *hwtable, const struct _vector *mpvec); char *snprint_config(const struct config *conf, int *len, const struct _vector *hwtable, diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c index ef5f53e25..2efe23fcb 100644 --- a/multipathd/cli_handlers.c +++ b/multipathd/cli_handlers.c @@ -165,7 +165,7 @@ show_config (struct strbuf *reply, const struct _vector *hwtable, conf = get_multipath_config(); pthread_cleanup_push(put_multipath_config, conf); - rc = __snprint_config(conf, reply, hwtable, mpvec); + rc = snprint_config__(conf, reply, hwtable, mpvec); pthread_cleanup_pop(1); if (rc < 0) return 1; From 323c5068282652a48af2fc3891c6674c8e410e05 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 22:25:01 +0200 Subject: [PATCH 114/145] libmultipath: rename __unlock() Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/lock.c | 4 ++-- libmultipath/lock.h | 2 +- multipathd/uxlsnr.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libmultipath/lock.c b/libmultipath/lock.c index 93b48dbbd..4d18d82cd 100644 --- a/libmultipath/lock.c +++ b/libmultipath/lock.c @@ -5,7 +5,7 @@ void cleanup_lock (void * data) struct mutex_lock *lock = data; wakeup_fn *fn = lock->wakeup; - __unlock(lock); + unlock__(lock); if (fn) fn(); } @@ -14,5 +14,5 @@ void set_wakeup_fn(struct mutex_lock *lck, wakeup_fn *fn) { lock(lck); lck->wakeup = fn; - __unlock(lck); + unlock__(lck); } diff --git a/libmultipath/lock.h b/libmultipath/lock.h index 1c05a77e7..38473a8cd 100644 --- a/libmultipath/lock.h +++ b/libmultipath/lock.h @@ -50,7 +50,7 @@ static inline int timedlock(struct mutex_lock *a, struct timespec *tmo) return pthread_mutex_timedlock(&a->mutex, tmo); } -static inline void __unlock(struct mutex_lock *a) +static inline void unlock__(struct mutex_lock *a) { pthread_mutex_unlock(&a->mutex); } diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c index 198f3823e..d74bb3555 100644 --- a/multipathd/uxlsnr.c +++ b/multipathd/uxlsnr.c @@ -527,7 +527,7 @@ static int client_state_machine(struct client *c, struct vectors *vecs, case CLT_LOCKED_WORK: if (trylock(&vecs->lock) == 0) { /* don't use cleanup_lock(), lest we wakeup ourselves */ - pthread_cleanup_push_cast(__unlock, &vecs->lock); + pthread_cleanup_push_cast(unlock__, &vecs->lock); c->error = execute_handler(c, vecs); check_for_locked_work(c); pthread_cleanup_pop(1); From d6d0dd23e568563b31c49a24c15e0b0e0b9130be Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 22:31:41 +0200 Subject: [PATCH 115/145] libmultipath: rename __sysfs_attr_get_value() Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/sysfs.c | 6 +++--- tests/sysfs.c | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/libmultipath/sysfs.c b/libmultipath/sysfs.c index afe9de914..b2c1ce024 100644 --- a/libmultipath/sysfs.c +++ b/libmultipath/sysfs.c @@ -45,7 +45,7 @@ * as libudev lacks the capability to update an attribute value. * So for modified attributes we need to implement our own function. */ -static ssize_t __sysfs_attr_get_value(struct udev_device *dev, const char *attr_name, +static ssize_t sysfs_attr_get_value__(struct udev_device *dev, const char *attr_name, char *value, size_t value_len, bool binary) { const char *syspath; @@ -100,13 +100,13 @@ static ssize_t __sysfs_attr_get_value(struct udev_device *dev, const char *attr_ ssize_t sysfs_attr_get_value(struct udev_device *dev, const char *attr_name, char *value, size_t value_len) { - return __sysfs_attr_get_value(dev, attr_name, value, value_len, false); + return sysfs_attr_get_value__(dev, attr_name, value, value_len, false); } ssize_t sysfs_bin_attr_get_value(struct udev_device *dev, const char *attr_name, unsigned char *value, size_t value_len) { - return __sysfs_attr_get_value(dev, attr_name, (char *)value, + return sysfs_attr_get_value__(dev, attr_name, (char *)value, value_len, true); } diff --git a/tests/sysfs.c b/tests/sysfs.c index c623d1bb7..6dfa9f3f5 100644 --- a/tests/sysfs.c +++ b/tests/sysfs.c @@ -90,7 +90,7 @@ static int teardown(void **state) static void expect_sagv_invalid(void) { - expect_condlog(1, "__sysfs_attr_get_value: invalid parameters"); + expect_condlog(1, "sysfs_attr_get_value__: invalid parameters"); } static void test_sagv_invalid(void **state) @@ -132,12 +132,12 @@ static void test_sagv_invalid(void **state) static void test_sagv_bad_udev(void **state) { will_return(__wrap_udev_device_get_syspath, NULL); - expect_condlog(3, "__sysfs_attr_get_value: invalid udevice"); + expect_condlog(3, "sysfs_attr_get_value__: invalid udevice"); assert_int_equal(sysfs_attr_get_value((void *)state, (void *)state, (void *)state, 1), -EINVAL); will_return(__wrap_udev_device_get_syspath, NULL); - expect_condlog(3, "__sysfs_attr_get_value: invalid udevice"); + expect_condlog(3, "sysfs_attr_get_value__: invalid udevice"); assert_int_equal(sysfs_bin_attr_get_value((void *)state, (void *)state, (void *)state, 1), -EINVAL); } @@ -151,11 +151,11 @@ static void test_sagv_bad_snprintf(void **state) longstr[sizeof(longstr) - 1] = '\0'; will_return(__wrap_udev_device_get_syspath, "/foo"); - expect_condlog(3, "__sysfs_attr_get_value: devpath overflow"); + expect_condlog(3, "sysfs_attr_get_value__: devpath overflow"); assert_int_equal(sysfs_attr_get_value((void *)state, longstr, buf, sizeof(buf)), -EOVERFLOW); will_return(__wrap_udev_device_get_syspath, "/foo"); - expect_condlog(3, "__sysfs_attr_get_value: devpath overflow"); + expect_condlog(3, "sysfs_attr_get_value__: devpath overflow"); assert_int_equal(sysfs_bin_attr_get_value((void *)state, longstr, (unsigned char *)buf, sizeof(buf)), -EOVERFLOW); @@ -171,7 +171,7 @@ static void test_sagv_open_fail(void **state) expect_value(WRAP_OPEN, flags, O_RDONLY); errno = ENOENT; wrap_will_return(WRAP_OPEN, -1); - expect_condlog(3, "__sysfs_attr_get_value: attribute '/foo/bar' cannot be opened"); + expect_condlog(3, "sysfs_attr_get_value__: attribute '/foo/bar' cannot be opened"); assert_int_equal(sysfs_attr_get_value((void *)state, "bar", buf, sizeof(buf)), -ENOENT); } @@ -190,7 +190,7 @@ static void test_sagv_read_fail(void **state) errno = EISDIR; will_return(__wrap_read, -1); will_return(__wrap_read, NULL); - expect_condlog(3, "__sysfs_attr_get_value: read from /foo/bar failed:"); + expect_condlog(3, "sysfs_attr_get_value__: read from /foo/bar failed:"); will_return(__wrap_close, 0); assert_int_equal(sysfs_attr_get_value((void *)state, "bar", buf, sizeof(buf)), -EISDIR); @@ -205,7 +205,7 @@ static void test_sagv_read_fail(void **state) errno = EPERM; will_return(__wrap_read, -1); will_return(__wrap_read, NULL); - expect_condlog(3, "__sysfs_attr_get_value: read from /foo/baz failed:"); + expect_condlog(3, "sysfs_attr_get_value__: read from /foo/baz failed:"); will_return(__wrap_close, 0); assert_int_equal(sysfs_bin_attr_get_value((void *)state, "baz", (unsigned char *)buf, sizeof(buf)), @@ -235,7 +235,7 @@ static void _test_sagv_read(void **state, unsigned int bufsz) if (bufsz <= sizeof(input) - 1) { n = bufsz; trunc = 1; - expect_condlog(3, "__sysfs_attr_get_value: overflow reading from /foo/bar"); + expect_condlog(3, "sysfs_attr_get_value__: overflow reading from /foo/bar"); } else { n = sizeof(input) - 1; trunc = 0; @@ -311,7 +311,7 @@ static void _test_sagv_read_zeroes(void **state, unsigned int bufsz) if (bufsz <= sizeof(input) - 1) { n = bufsz; - expect_condlog(3, "__sysfs_attr_get_value: overflow reading from /foo/bar"); + expect_condlog(3, "sysfs_attr_get_value__: overflow reading from /foo/bar"); } else n = 0; From aafcf62a0e4637296cb4976d515b3b1ad13f7de5 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 22:32:57 +0200 Subject: [PATCH 116/145] libmultipath: rename __snprint_foreign_topology() ... and __LAST_FOREIGN_RETCODE. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/foreign.c | 6 +++--- libmultipath/foreign.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libmultipath/foreign.c b/libmultipath/foreign.c index d01a5ef0c..2a42df539 100644 --- a/libmultipath/foreign.c +++ b/libmultipath/foreign.c @@ -499,7 +499,7 @@ void foreign_multipath_layout(fieldwidth_t *width) pthread_cleanup_pop(1); } -static int __snprint_foreign_topology(struct strbuf *buf, int verbosity, +static int snprint_foreign_topology__(struct strbuf *buf, int verbosity, const fieldwidth_t *width) { struct foreign *fgn; @@ -540,7 +540,7 @@ int snprint_foreign_topology(struct strbuf *buf, int verbosity, return 0; } pthread_cleanup_push(unlock_foreigns, NULL); - rc = __snprint_foreign_topology(buf, verbosity, width); + rc = snprint_foreign_topology__(buf, verbosity, width); pthread_cleanup_pop(1); return rc; } @@ -570,7 +570,7 @@ void print_foreign_topology(int verbosity) fgn->release_paths(fgn->context, vec); pthread_cleanup_pop(1); } - __snprint_foreign_topology(&buf, verbosity, width); + snprint_foreign_topology__(&buf, verbosity, width); pthread_cleanup_pop(1); printf("%s", get_strbuf_str(&buf)); } diff --git a/libmultipath/foreign.h b/libmultipath/foreign.h index db1592c7c..f3bc1b2bd 100644 --- a/libmultipath/foreign.h +++ b/libmultipath/foreign.h @@ -32,7 +32,7 @@ enum foreign_retcode { FOREIGN_UNCLAIMED, FOREIGN_NODEV, FOREIGN_ERR, - __LAST_FOREIGN_RETCODE, + LAST_FOREIGN_RETCODE__, }; /** From 848d5edca1dc084636963b76408417f4d5d6ac06 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 22:36:41 +0200 Subject: [PATCH 117/145] libmultipath: rename macros with double underscores in propsel.c Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/propsel.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libmultipath/propsel.c b/libmultipath/propsel.c index e2dcb3166..a3fce2039 100644 --- a/libmultipath/propsel.c +++ b/libmultipath/propsel.c @@ -48,7 +48,7 @@ do { \ } \ } while(0) -#define __do_set_from_vec(type, var, src, dest) \ +#define do_set_from_vec__(type, var, src, dest) \ ({ \ type *_p; \ bool _found = false; \ @@ -64,11 +64,11 @@ do { \ _found; \ }) -#define __do_set_from_hwe(var, src, dest) \ - __do_set_from_vec(struct hwentry, var, (src)->hwe, dest) +#define do_set_from_hwe__(var, src, dest) \ + do_set_from_vec__(struct hwentry, var, (src)->hwe, dest) #define do_set_from_hwe(var, src, dest, msg) \ - if (src->hwe && __do_set_from_hwe(var, src, dest)) { \ + if (src->hwe && do_set_from_hwe__(var, src, dest)) { \ origin = msg; \ goto out; \ } @@ -660,7 +660,7 @@ check_rdac(struct path * pp) if (pp->bus != SYSFS_BUS_SCSI) return 0; /* Avoid checking 0xc9 if this is likely not an RDAC array */ - if (!__do_set_from_hwe(checker_name, pp, checker_name) && + if (!do_set_from_hwe__(checker_name, pp, checker_name) && !is_vpd_page_supported(pp->fd, 0xC9)) return 0; if (checker_name && strcmp(checker_name, RDAC)) From 528f00c165e64813a9223b51af213b7418dedd8e Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 22:38:08 +0200 Subject: [PATCH 118/145] libmultipath: rename enum values with double underscores in structs.h Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/dict.c | 4 ++-- libmultipath/print.c | 2 +- libmultipath/structs.h | 4 ++-- libmultipath/valid.c | 2 +- tests/mpathvalid.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libmultipath/dict.c b/libmultipath/dict.c index 546103f29..a06a6138a 100644 --- a/libmultipath/dict.c +++ b/libmultipath/dict.c @@ -568,7 +568,7 @@ def_find_multipaths_handler(struct config *conf, vector strvec, if (!buff) return 1; - for (i = FIND_MULTIPATHS_OFF; i < __FIND_MULTIPATHS_LAST; i++) { + for (i = FIND_MULTIPATHS_OFF; i < FIND_MULTIPATHS_LAST__; i++) { if (find_multipaths_optvals[i] != NULL && !strcmp(buff, find_multipaths_optvals[i])) { conf->find_multipaths = i; @@ -576,7 +576,7 @@ def_find_multipaths_handler(struct config *conf, vector strvec, } } - if (i >= __FIND_MULTIPATHS_LAST) { + if (i >= FIND_MULTIPATHS_LAST__) { if (strcmp(buff, "no") == 0 || strcmp(buff, "0") == 0) conf->find_multipaths = FIND_MULTIPATHS_OFF; else if (strcmp(buff, "yes") == 0 || strcmp(buff, "1") == 0) diff --git a/libmultipath/print.c b/libmultipath/print.c index b911802a9..b8868ea6d 100644 --- a/libmultipath/print.c +++ b/libmultipath/print.c @@ -575,7 +575,7 @@ static int snprint_initialized(struct strbuf *buff, const struct path * pp) }; const char *str; - if (pp->initialized < INIT_NEW || pp->initialized >= __INIT_LAST) + if (pp->initialized < INIT_NEW || pp->initialized >= INIT_LAST__) str = "undef"; else str = init_state_name[pp->initialized]; diff --git a/libmultipath/structs.h b/libmultipath/structs.h index 6b5de7a81..56fb74ba6 100644 --- a/libmultipath/structs.h +++ b/libmultipath/structs.h @@ -99,7 +99,7 @@ enum find_multipaths_states { FIND_MULTIPATHS_GREEDY, FIND_MULTIPATHS_SMART, FIND_MULTIPATHS_STRICT, - __FIND_MULTIPATHS_LAST, + FIND_MULTIPATHS_LAST__, }; enum marginal_pathgroups_mode { @@ -258,7 +258,7 @@ enum initialized_states { * change uevent is received. */ INIT_PARTIAL, - __INIT_LAST, + INIT_LAST__, }; enum prkey_sources { diff --git a/libmultipath/valid.c b/libmultipath/valid.c index d75178098..5df9b02f9 100644 --- a/libmultipath/valid.c +++ b/libmultipath/valid.c @@ -302,7 +302,7 @@ is_path_valid(const char *name, struct config *conf, struct path *pp, return PATH_IS_ERROR; if (conf->find_multipaths <= FIND_MULTIPATHS_UNDEF || - conf->find_multipaths >= __FIND_MULTIPATHS_LAST) + conf->find_multipaths >= FIND_MULTIPATHS_LAST__) return PATH_IS_ERROR; if (safe_sprintf(pp->dev, "%s", name)) diff --git a/tests/mpathvalid.c b/tests/mpathvalid.c index df66ed6ae..134dfc9d6 100644 --- a/tests/mpathvalid.c +++ b/tests/mpathvalid.c @@ -130,7 +130,7 @@ void make_config_file(int findmp) char buf[64]; assert_true(findmp > FIND_MULTIPATHS_UNDEF && - findmp < __FIND_MULTIPATHS_LAST); + findmp < FIND_MULTIPATHS_LAST__); r = snprintf(buf, sizeof(buf), "defaults {\nfind_multipaths %s\n}\n", find_multipaths_optvals[findmp]); From 8eed2f7f63cbbf65813bfdabf27117a4a0c48adb Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 22:39:03 +0200 Subject: [PATCH 119/145] libmultipath: rename macros starting with underscore Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/checkers/directio.c | 8 ++++---- libmultipath/checkers/emc_clariion.c | 20 ++++++++++---------- libmultipath/checkers/rdac.c | 20 ++++++++++---------- libmultipath/checkers/tur.c | 10 +++++----- libmultipath/foreign/nvme.c | 26 +++++++++++++------------- 5 files changed, 42 insertions(+), 42 deletions(-) diff --git a/libmultipath/checkers/directio.c b/libmultipath/checkers/directio.c index 12b8be494..8e87878b6 100644 --- a/libmultipath/checkers/directio.c +++ b/libmultipath/checkers/directio.c @@ -49,11 +49,11 @@ enum { MSG_DIRECTIO_BLOCKSIZE, }; -#define _IDX(x) (MSG_DIRECTIO_##x - CHECKER_FIRST_MSGID) +#define IDX_(x) (MSG_DIRECTIO_##x - CHECKER_FIRST_MSGID) const char *libcheck_msgtable[] = { - [_IDX(UNKNOWN)] = " is not available", - [_IDX(PENDING)] = " is waiting on aio", - [_IDX(BLOCKSIZE)] = " cannot get blocksize, set default", + [IDX_(UNKNOWN)] = " is not available", + [IDX_(PENDING)] = " is waiting on aio", + [IDX_(BLOCKSIZE)] = " cannot get blocksize, set default", NULL, }; diff --git a/libmultipath/checkers/emc_clariion.c b/libmultipath/checkers/emc_clariion.c index 04635b5c7..bf0baabc0 100644 --- a/libmultipath/checkers/emc_clariion.c +++ b/libmultipath/checkers/emc_clariion.c @@ -57,20 +57,20 @@ enum { MSG_CLARIION_PASSIVE_GOOD, }; -#define _IDX(x) (MSG_CLARIION_ ## x - CHECKER_FIRST_MSGID) +#define IDX_(x) (MSG_CLARIION_ ## x - CHECKER_FIRST_MSGID) const char *libcheck_msgtable[] = { - [_IDX(QUERY_FAILED)] = ": sending query command failed", - [_IDX(QUERY_ERROR)] = ": query command indicates error", - [_IDX(PATH_CONFIG)] = + [IDX_(QUERY_FAILED)] = ": sending query command failed", + [IDX_(QUERY_ERROR)] = ": query command indicates error", + [IDX_(PATH_CONFIG)] = ": Path not correctly configured for failover", - [_IDX(UNIT_REPORT)] = + [IDX_(UNIT_REPORT)] = ": Path unit report page in unknown format", - [_IDX(PATH_NOT_AVAIL)] = + [IDX_(PATH_NOT_AVAIL)] = ": Path not available for normal operations", - [_IDX(LUN_UNBOUND)] = ": Logical Unit is unbound or LUNZ", - [_IDX(WWN_CHANGED)] = ": Logical Unit WWN has changed", - [_IDX(READ_ERROR)] = ": Read error", - [_IDX(PASSIVE_GOOD)] = ": Active path is healthy", + [IDX_(LUN_UNBOUND)] = ": Logical Unit is unbound or LUNZ", + [IDX_(WWN_CHANGED)] = ": Logical Unit WWN has changed", + [IDX_(READ_ERROR)] = ": Read error", + [IDX_(PASSIVE_GOOD)] = ": Active path is healthy", NULL, }; diff --git a/libmultipath/checkers/rdac.c b/libmultipath/checkers/rdac.c index 9a3860fd2..87b8872a1 100644 --- a/libmultipath/checkers/rdac.c +++ b/libmultipath/checkers/rdac.c @@ -234,19 +234,19 @@ enum { RDAC_MSGID_INQUIRY_FAILED, }; -#define _IDX(x) (RDAC_MSGID_##x - CHECKER_FIRST_MSGID) +#define IDX_(x) (RDAC_MSGID_##x - CHECKER_FIRST_MSGID) const char *libcheck_msgtable[] = { - [_IDX(NOT_CONN)] = MSG_RDAC_DOWN_TYPE("lun not connected"), - [_IDX(IN_STARTUP)] = MSG_RDAC_DOWN_TYPE("ctlr is in startup sequence"), - [_IDX(NON_RESPONSIVE)] = + [IDX_(NOT_CONN)] = MSG_RDAC_DOWN_TYPE("lun not connected"), + [IDX_(IN_STARTUP)] = MSG_RDAC_DOWN_TYPE("ctlr is in startup sequence"), + [IDX_(NON_RESPONSIVE)] = MSG_RDAC_DOWN_TYPE("non-responsive to queries"), - [_IDX(IN_RESET)] = MSG_RDAC_DOWN_TYPE("ctlr held in reset"), - [_IDX(FW_DOWNLOADING)] = + [IDX_(IN_RESET)] = MSG_RDAC_DOWN_TYPE("ctlr held in reset"), + [IDX_(FW_DOWNLOADING)] = MSG_RDAC_DOWN_TYPE("ctlr firmware downloading"), - [_IDX(QUIESCED)] = MSG_RDAC_DOWN_TYPE("ctlr quiesced by admin request"), - [_IDX(SERVICE_MODE)] = MSG_RDAC_DOWN_TYPE("ctlr is in service mode"), - [_IDX(UNAVAILABLE)] = MSG_RDAC_DOWN_TYPE("ctlr is unavailable"), - [_IDX(INQUIRY_FAILED)] = MSG_RDAC_DOWN_TYPE("inquiry failed"), + [IDX_(QUIESCED)] = MSG_RDAC_DOWN_TYPE("ctlr quiesced by admin request"), + [IDX_(SERVICE_MODE)] = MSG_RDAC_DOWN_TYPE("ctlr is in service mode"), + [IDX_(UNAVAILABLE)] = MSG_RDAC_DOWN_TYPE("ctlr is unavailable"), + [IDX_(INQUIRY_FAILED)] = MSG_RDAC_DOWN_TYPE("inquiry failed"), NULL, }; diff --git a/libmultipath/checkers/tur.c b/libmultipath/checkers/tur.c index 2800446d6..a2905af58 100644 --- a/libmultipath/checkers/tur.c +++ b/libmultipath/checkers/tur.c @@ -35,12 +35,12 @@ enum { MSG_TUR_TRANSITIONING, }; -#define _IDX(x) (MSG_ ## x - CHECKER_FIRST_MSGID) +#define IDX_(x) (MSG_ ## x - CHECKER_FIRST_MSGID) const char *libcheck_msgtable[] = { - [_IDX(TUR_RUNNING)] = " still running", - [_IDX(TUR_TIMEOUT)] = " timed out", - [_IDX(TUR_FAILED)] = " failed to initialize", - [_IDX(TUR_TRANSITIONING)] = " reports path is transitioning", + [IDX_(TUR_RUNNING)] = " still running", + [IDX_(TUR_TIMEOUT)] = " timed out", + [IDX_(TUR_FAILED)] = " failed to initialize", + [IDX_(TUR_TRANSITIONING)] = " reports path is transitioning", NULL, }; diff --git a/libmultipath/foreign/nvme.c b/libmultipath/foreign/nvme.c index 6f2d8800c..9b2676497 100644 --- a/libmultipath/foreign/nvme.c +++ b/libmultipath/foreign/nvme.c @@ -955,18 +955,18 @@ void release_paths(__attribute__((unused)) const struct context *ctx, } /* compile-time check whether all methods are present and correctly typed */ -#define _METHOD_INIT(x) .x = x +#define METHOD_INIT(x) .x = x static struct foreign __methods __attribute__((unused)) = { - _METHOD_INIT(init), - _METHOD_INIT(cleanup), - _METHOD_INIT(change), - _METHOD_INIT(delete), - _METHOD_INIT(delete_all), - _METHOD_INIT(check), - _METHOD_INIT(lock), - _METHOD_INIT(unlock), - _METHOD_INIT(get_multipaths), - _METHOD_INIT(release_multipaths), - _METHOD_INIT(get_paths), - _METHOD_INIT(release_paths), + METHOD_INIT(init), + METHOD_INIT(cleanup), + METHOD_INIT(change), + METHOD_INIT(delete), + METHOD_INIT(delete_all), + METHOD_INIT(check), + METHOD_INIT(lock), + METHOD_INIT(unlock), + METHOD_INIT(get_multipaths), + METHOD_INIT(release_multipaths), + METHOD_INIT(get_paths), + METHOD_INIT(release_paths), }; From 26980bea3efea765758896782ff915734599b187 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 22:45:45 +0200 Subject: [PATCH 120/145] libmultipath: rename __internal_config variable Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/config.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libmultipath/config.c b/libmultipath/config.c index a59533b55..34cbb4350 100644 --- a/libmultipath/config.c +++ b/libmultipath/config.c @@ -72,13 +72,13 @@ void libmultipath_exit(void) pthread_once(&_exit_once, _libmultipath_exit); } -static struct config __internal_config; +static struct config internal_config; struct config *libmp_get_multipath_config(void) { - if (!__internal_config.hwtable) + if (!internal_config.hwtable) /* not initialized */ return NULL; - return &__internal_config; + return &internal_config; } struct config *get_multipath_config(void) @@ -734,7 +734,7 @@ static void _uninit_config(struct config *conf) int i; if (!conf) - conf = &__internal_config; + conf = &internal_config; if (conf->selector) free(conf->selector); @@ -791,14 +791,14 @@ static void _uninit_config(struct config *conf) void uninit_config(void) { - _uninit_config(&__internal_config); + _uninit_config(&internal_config); } void free_config(struct config *conf) { if (!conf) return; - else if (conf == &__internal_config) { + else if (conf == &internal_config) { condlog(0, "ERROR: %s called for internal config. Use uninit_config() instead", __func__); return; @@ -883,7 +883,7 @@ static int _init_config (const char *file, struct config *conf); int init_config(const char *file) { - return _init_config(file, &__internal_config); + return _init_config(file, &internal_config); } struct config *load_config(const char *file) @@ -901,7 +901,7 @@ int _init_config (const char *file, struct config *conf) { if (!conf) - conf = &__internal_config; + conf = &internal_config; /* * Processing the config file will overwrite conf->verbosity if set From 2f024766a99d83070e52c5ce3f5ea69902005fa5 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 8 Aug 2024 13:01:53 +0200 Subject: [PATCH 121/145] libmultipath: rename _dm_flush_map() to dm_flush_map__() Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 4 ++-- libmultipath/devmapper.h | 8 ++++---- libmultipath/libmultipath.version | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 0a4b586ce..c497c2250 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -965,7 +965,7 @@ int mpath_in_use(const char *name) return 0; } -int _dm_flush_map (const char *mapname, int flags, int retries) +int dm_flush_map__ (const char *mapname, int flags, int retries) { int r; int queue_if_no_path = 0; @@ -1050,7 +1050,7 @@ dm_flush_map_nopaths(const char *mapname, int deferred_remove DR_UNUSED__) deferred_remove == DEFERRED_REMOVE_IN_PROGRESS) ? DMFL_DEFERRED : 0); #endif - return _dm_flush_map(mapname, flags, 0); + return dm_flush_map__(mapname, flags, 0); } int dm_flush_maps(int retries) diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index d9c08fd88..ba05e0a1a 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -161,11 +161,11 @@ enum { DMFL_NO_FLUSH = 1 << 3, }; -int _dm_flush_map (const char *mapname, int flags, int retries); -#define dm_flush_map(mapname) _dm_flush_map(mapname, DMFL_NEED_SYNC, 0) -#define dm_flush_map_nosync(mapname) _dm_flush_map(mapname, DMFL_NONE, 0) +int dm_flush_map__ (const char *mapname, int flags, int retries); +#define dm_flush_map(mapname) dm_flush_map__(mapname, DMFL_NEED_SYNC, 0) +#define dm_flush_map_nosync(mapname) dm_flush_map__(mapname, DMFL_NONE, 0) #define dm_suspend_and_flush_map(mapname, retries) \ - _dm_flush_map(mapname, DMFL_NEED_SYNC|DMFL_SUSPEND, retries) + dm_flush_map__(mapname, DMFL_NEED_SYNC|DMFL_SUSPEND, retries) int dm_flush_map_nopaths(const char * mapname, int deferred_remove); int dm_cancel_deferred_remove(struct multipath *mpp); int dm_flush_maps (int retries); diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index e6c6daf1b..f92f759a6 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -75,7 +75,7 @@ global: dm_enablegroup; dm_fail_path; dm_find_map_by_wwid; - _dm_flush_map; + dm_flush_map__; dm_flush_map_nopaths; dm_flush_maps; dm_geteventnr; From dd919400addffaaeac62d5e7bbc035edbc095e89 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 8 Aug 2024 13:24:40 +0200 Subject: [PATCH 122/145] libmultipath: foreign: rename _check() to check__() Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/foreign/nvme.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libmultipath/foreign/nvme.c b/libmultipath/foreign/nvme.c index 9b2676497..40b88f7ba 100644 --- a/libmultipath/foreign/nvme.c +++ b/libmultipath/foreign/nvme.c @@ -891,7 +891,7 @@ int delete(struct context *ctx, struct udev_device *ud) return rc; } -void _check(struct context *ctx) +void check__(struct context *ctx) { struct gen_multipath *gm; int i; @@ -908,7 +908,7 @@ void check(struct context *ctx) condlog(4, "%s called for \"%s\"", __func__, THIS); lock(ctx); pthread_cleanup_push(unlock, ctx); - _check(ctx); + check__(ctx); pthread_cleanup_pop(1); return; } From 8fd343fb0f1cdcf29e795e402beb12f59305218b Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 8 Aug 2024 13:26:22 +0200 Subject: [PATCH 123/145] libmultipath: rename _cleanup_foreign() Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/foreign.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libmultipath/foreign.c b/libmultipath/foreign.c index 2a42df539..5ec2d0b2f 100644 --- a/libmultipath/foreign.c +++ b/libmultipath/foreign.c @@ -84,7 +84,7 @@ static void free_foreign(struct foreign *fgn) free(fgn); } -void _cleanup_foreign(void) +void cleanup_foreign__(void) { struct foreign *fgn; int i; @@ -103,7 +103,7 @@ void _cleanup_foreign(void) void cleanup_foreign(void) { wrlock_foreigns(); - _cleanup_foreign(); + cleanup_foreign__(); unlock_foreigns(NULL); } @@ -164,7 +164,7 @@ static int _init_foreign(const char *enable) r = -errno; condlog(1, "%s: error scanning foreign multipath libraries: %m", __func__); - _cleanup_foreign(); + cleanup_foreign__(); goto out_free_pre; } From a471102ec0da7a9823b1be1194fe32d9dea7183b Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 8 Aug 2024 13:27:39 +0200 Subject: [PATCH 124/145] libmultipath: rename _init_config() Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/config.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libmultipath/config.c b/libmultipath/config.c index 34cbb4350..b742fb4e0 100644 --- a/libmultipath/config.c +++ b/libmultipath/config.c @@ -879,25 +879,25 @@ static void set_max_checkint_from_watchdog(struct config *conf) } #endif -static int _init_config (const char *file, struct config *conf); +static int init_config__ (const char *file, struct config *conf); int init_config(const char *file) { - return _init_config(file, &internal_config); + return init_config__(file, &internal_config); } struct config *load_config(const char *file) { struct config *conf = alloc_config(); - if (conf && !_init_config(file, conf)) + if (conf && !init_config__(file, conf)) return conf; free(conf); return NULL; } -int _init_config (const char *file, struct config *conf) +int init_config__ (const char *file, struct config *conf) { if (!conf) From 579bc65d402fbc02b01b453384f3fdf1dc47d2fe Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 8 Aug 2024 12:59:09 +0200 Subject: [PATCH 125/145] libmultipath: rename symbols starting with underscore in print.h Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/foreign.c | 12 +++++------ libmultipath/foreign.h | 2 +- libmultipath/libmultipath.version | 8 ++++---- libmultipath/print.c | 34 +++++++++++++++---------------- libmultipath/print.h | 20 +++++++++--------- 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/libmultipath/foreign.c b/libmultipath/foreign.c index 5ec2d0b2f..d23439e91 100644 --- a/libmultipath/foreign.c +++ b/libmultipath/foreign.c @@ -458,7 +458,7 @@ void foreign_path_layout(fieldwidth_t *width) vec = fgn->get_paths(fgn->context); if (vec != NULL) { - _get_path_layout(vec, LAYOUT_RESET_NOT, width); + get_path_layout__(vec, LAYOUT_RESET_NOT, width); } fgn->release_paths(fgn->context, vec); @@ -489,7 +489,7 @@ void foreign_multipath_layout(fieldwidth_t *width) vec = fgn->get_multipaths(fgn->context); if (vec != NULL) { - _get_multipath_layout(vec, LAYOUT_RESET_NOT, width); + get_multipath_layout__(vec, LAYOUT_RESET_NOT, width); } fgn->release_multipaths(fgn->context, vec); @@ -517,7 +517,7 @@ static int snprint_foreign_topology__(struct strbuf *buf, int verbosity, vec = fgn->get_multipaths(fgn->context); if (vec != NULL) { vector_foreach_slot(vec, gm, j) { - if (_snprint_multipath_topology( + if (snprint_multipath_topology__( gm, buf, verbosity, width) < 0) break; } @@ -566,7 +566,7 @@ void print_foreign_topology(int verbosity) fgn->lock(fgn->context); pthread_cleanup_push(fgn->unlock, fgn->context); vec = fgn->get_paths(fgn->context); - _get_multipath_layout(vec, LAYOUT_RESET_NOT, width); + get_multipath_layout__(vec, LAYOUT_RESET_NOT, width); fgn->release_paths(fgn->context, vec); pthread_cleanup_pop(1); } @@ -600,7 +600,7 @@ int snprint_foreign_paths(struct strbuf *buf, const char *style, vec = fgn->get_paths(fgn->context); if (vec != NULL) { vector_foreach_slot(vec, gp, j) { - ret = _snprint_path(gp, buf, style, width); + ret = snprint_path__(gp, buf, style, width); if (ret < 0) break; } @@ -640,7 +640,7 @@ int snprint_foreign_multipaths(struct strbuf *buf, const char *style, vec = fgn->get_multipaths(fgn->context); if (vec != NULL) { vector_foreach_slot(vec, gm, j) { - ret = _snprint_multipath(gm, buf, + ret = snprint_multipath__(gm, buf, style, width); if (ret < 0) break; diff --git a/libmultipath/foreign.h b/libmultipath/foreign.h index f3bc1b2bd..809824dd6 100644 --- a/libmultipath/foreign.h +++ b/libmultipath/foreign.h @@ -271,7 +271,7 @@ void foreign_multipath_layout(fieldwidth_t *width); * '\0' - terminated. * @param buf: output buffer * @param verbosity: verbosity level - * @param width: an array of field widths, initialized by _get_path_layout() + * @param width: an array of field widths, initialized by get_path_layout__() * @returns: number of printed characters excluding trailing '\0'. */ int snprint_foreign_topology(struct strbuf *buf, int verbosity, diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index f92f759a6..21d48da6a 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -149,7 +149,7 @@ global: path_offline; print_all_paths; print_foreign_topology; - _print_multipath_topology; + print_multipath_topology__; reinstate_paths; remember_wwid; remove_feature; @@ -179,12 +179,12 @@ global: snprint_foreign_multipaths; snprint_foreign_paths; snprint_foreign_topology; - _snprint_multipath; + snprint_multipath__; snprint_multipath_header; snprint_multipath_map_json; - _snprint_multipath_topology; + snprint_multipath_topology__; snprint_multipath_topology_json; - _snprint_path; + snprint_path__; snprint_path_header; snprint_status; snprint_wildcards; diff --git a/libmultipath/print.c b/libmultipath/print.c index b8868ea6d..190c82396 100644 --- a/libmultipath/print.c +++ b/libmultipath/print.c @@ -924,7 +924,7 @@ void get_path_layout(vector pathvec, int header, fieldwidth_t *width) { vector gpvec = vector_convert(NULL, pathvec, struct path, dm_path_to_gen); - _get_path_layout(gpvec, + get_path_layout__(gpvec, header ? LAYOUT_RESET_HEADER : LAYOUT_RESET_ZERO, width); vector_free(gpvec); @@ -946,7 +946,7 @@ reset_width(fieldwidth_t *width, enum layout_reset reset, const char *header) } } -void _get_path_layout (const struct _vector *gpvec, enum layout_reset reset, +void get_path_layout__ (const struct _vector *gpvec, enum layout_reset reset, fieldwidth_t *width) { unsigned int i, j; @@ -980,14 +980,14 @@ fieldwidth_t *alloc_multipath_layout(void) { void get_multipath_layout (vector mpvec, int header, fieldwidth_t *width) { vector gmvec = vector_convert(NULL, mpvec, struct multipath, dm_multipath_to_gen); - _get_multipath_layout(gmvec, + get_multipath_layout__(gmvec, header ? LAYOUT_RESET_HEADER : LAYOUT_RESET_ZERO, width); vector_free(gmvec); } void -_get_multipath_layout (const struct _vector *gmvec, enum layout_reset reset, +get_multipath_layout__ (const struct _vector *gmvec, enum layout_reset reset, fieldwidth_t *width) { unsigned int i, j; @@ -1110,7 +1110,7 @@ int snprint_multipath_header(struct strbuf *line, const char *format, return get_strbuf_len(line) - initial_len; } -int _snprint_multipath(const struct gen_multipath *gmp, +int snprint_multipath__(const struct gen_multipath *gmp, struct strbuf *line, const char *format, const fieldwidth_t *width) { @@ -1171,7 +1171,7 @@ int snprint_path_header(struct strbuf *line, const char *format, return get_strbuf_len(line) - initial_len; } -int _snprint_path(const struct gen_path *gp, struct strbuf *line, +int snprint_path__(const struct gen_path *gp, struct strbuf *line, const char *format, const fieldwidth_t *width) { int initial_len = get_strbuf_len(line); @@ -1200,7 +1200,7 @@ int _snprint_path(const struct gen_path *gp, struct strbuf *line, return get_strbuf_len(line) - initial_len; } -int _snprint_pathgroup(const struct gen_pathgroup *ggp, struct strbuf *line, +int snprint_pathgroup__(const struct gen_pathgroup *ggp, struct strbuf *line, const char *format) { int initial_len = get_strbuf_len(line); @@ -1223,9 +1223,9 @@ int _snprint_pathgroup(const struct gen_pathgroup *ggp, struct strbuf *line, } #define snprint_pathgroup(line, fmt, pgp) \ - _snprint_pathgroup(dm_pathgroup_to_gen(pgp), line, fmt) + snprint_pathgroup__(dm_pathgroup_to_gen(pgp), line, fmt) -void _print_multipath_topology(const struct gen_multipath *gmp, int verbosity) +void print_multipath_topology__(const struct gen_multipath *gmp, int verbosity) { STRBUF_ON_STACK(buff); fieldwidth_t *p_width __attribute__((cleanup(cleanup_ucharp))) = NULL; @@ -1241,13 +1241,13 @@ void _print_multipath_topology(const struct gen_multipath *gmp, int verbosity) pathvec = gpg->ops->get_paths(gpg); if (pathvec == NULL) continue; - _get_path_layout(pathvec, LAYOUT_RESET_NOT, p_width); + get_path_layout__(pathvec, LAYOUT_RESET_NOT, p_width); gpg->ops->rel_paths(gpg, pathvec); } gmp->ops->rel_pathgroups(gmp, pgvec); } - _snprint_multipath_topology(gmp, &buff, verbosity, p_width); + snprint_multipath_topology__(gmp, &buff, verbosity, p_width); printf("%s", get_strbuf_str(&buff)); } @@ -1266,7 +1266,7 @@ int snprint_multipath_style(const struct gen_multipath *gmp, need_wwid ? " (%w)" : "", " %d %s"); } -int _snprint_multipath_topology(const struct gen_multipath *gmp, +int snprint_multipath_topology__(const struct gen_multipath *gmp, struct strbuf *buff, int verbosity, const fieldwidth_t *p_width) { @@ -1284,7 +1284,7 @@ int _snprint_multipath_topology(const struct gen_multipath *gmp, return -ENOMEM; if (verbosity == 1) - return _snprint_multipath(gmp, buff, "%n", width); + return snprint_multipath__(gmp, buff, "%n", width); if(isatty(1) && (rc = print_strbuf(&style, "%c[%dm", 0x1B, 1)) < 0) /* bold on */ @@ -1295,8 +1295,8 @@ int _snprint_multipath_topology(const struct gen_multipath *gmp, (rc = print_strbuf(&style, "%c[%dm", 0x1B, 0)) < 0) /* bold off */ return rc; - if ((rc = _snprint_multipath(gmp, buff, get_strbuf_str(&style), width)) < 0 - || (rc = _snprint_multipath(gmp, buff, PRINT_MAP_PROPS, width)) < 0) + if ((rc = snprint_multipath__(gmp, buff, get_strbuf_str(&style), width)) < 0 + || (rc = snprint_multipath__(gmp, buff, PRINT_MAP_PROPS, width)) < 0) return rc; pgvec = gmp->ops->get_pathgroups(gmp); @@ -1310,7 +1310,7 @@ int _snprint_multipath_topology(const struct gen_multipath *gmp, if ((rc = print_strbuf(buff, "%c-+- ", last_group ? '`' : '|')) < 0 || - (rc = _snprint_pathgroup(gpg, buff, PRINT_PG_INDENT)) < 0) + (rc = snprint_pathgroup__(gpg, buff, PRINT_PG_INDENT)) < 0) return rc; pathvec = gpg->ops->get_paths(gpg); @@ -1322,7 +1322,7 @@ int _snprint_multipath_topology(const struct gen_multipath *gmp, last_group ? ' ' : '|', i + 1 == VECTOR_SIZE(pathvec) ? '`': '|')) < 0 || - (rc = _snprint_path(gp, buff, + (rc = snprint_path__(gp, buff, PRINT_PATH_INDENT, p_width)) < 0) return rc; } diff --git a/libmultipath/print.h b/libmultipath/print.h index 4dd2ef2d6..9c2aea47c 100644 --- a/libmultipath/print.h +++ b/libmultipath/print.h @@ -17,28 +17,28 @@ enum layout_reset { /* fieldwidth_t is defined in generic.h */ fieldwidth_t *alloc_path_layout(void); -void _get_path_layout (const struct _vector *gpvec, enum layout_reset, +void get_path_layout__ (const struct _vector *gpvec, enum layout_reset, fieldwidth_t *width); void get_path_layout (vector pathvec, int header, fieldwidth_t *width); fieldwidth_t *alloc_multipath_layout(void); -void _get_multipath_layout (const struct _vector *gmvec, enum layout_reset, +void get_multipath_layout__ (const struct _vector *gmvec, enum layout_reset, fieldwidth_t *width); void get_multipath_layout (vector mpvec, int header, fieldwidth_t *width); int snprint_path_header(struct strbuf *, const char *, const fieldwidth_t *); int snprint_multipath_header(struct strbuf *, const char *, const fieldwidth_t *); -int _snprint_path (const struct gen_path *, struct strbuf *, const char *, +int snprint_path__ (const struct gen_path *, struct strbuf *, const char *, const fieldwidth_t *); #define snprint_path(buf, fmt, pp, w) \ - _snprint_path(dm_path_to_gen(pp), buf, fmt, w) -int _snprint_multipath (const struct gen_multipath *, struct strbuf *, + snprint_path__(dm_path_to_gen(pp), buf, fmt, w) +int snprint_multipath__ (const struct gen_multipath *, struct strbuf *, const char *, const fieldwidth_t *); #define snprint_multipath(buf, fmt, mp, w) \ - _snprint_multipath(dm_multipath_to_gen(mp), buf, fmt, w) -int _snprint_multipath_topology (const struct gen_multipath *, struct strbuf *, + snprint_multipath__(dm_multipath_to_gen(mp), buf, fmt, w) +int snprint_multipath_topology__ (const struct gen_multipath *, struct strbuf *, int verbosity, const fieldwidth_t *); #define snprint_multipath_topology(buf, mpp, v, w) \ - _snprint_multipath_topology (dm_multipath_to_gen(mpp), buf, v, w) + snprint_multipath_topology__ (dm_multipath_to_gen(mpp), buf, v, w) int snprint_multipath_topology_json(struct strbuf *, const struct vectors *vecs); int snprint_config__(const struct config *conf, struct strbuf *buff, const struct _vector *hwtable, const struct _vector *mpvec); @@ -58,10 +58,10 @@ int snprint_tgt_wwpn(struct strbuf *, const struct path *); #define PROTOCOL_BUF_SIZE sizeof("scsi:unspec") int snprint_path_protocol(struct strbuf *, const struct path *); -void _print_multipath_topology (const struct gen_multipath * gmp, +void print_multipath_topology__ (const struct gen_multipath * gmp, int verbosity); #define print_multipath_topology(mpp, v) \ - _print_multipath_topology(dm_multipath_to_gen(mpp), v) + print_multipath_topology__(dm_multipath_to_gen(mpp), v) void print_all_paths (vector pathvec, int banner); From 73bce14fe32048735e69c73d72ac39113db750e3 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 22:13:16 +0200 Subject: [PATCH 126/145] libmultipath: remove dead code in pgpolicies.h Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/pgpolicies.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/libmultipath/pgpolicies.h b/libmultipath/pgpolicies.h index 4469f8b6e..c1983e18f 100644 --- a/libmultipath/pgpolicies.h +++ b/libmultipath/pgpolicies.h @@ -1,12 +1,6 @@ #ifndef PGPOLICIES_H_INCLUDED #define PGPOLICIES_H_INCLUDED -#if 0 -#ifndef _MAIN_H -#include "main.h" -#endif -#endif - #define POLICY_NAME_SIZE 32 /* Storage controllers capabilities */ From dc97e65c511424c8aac610b5ad4dbd3e341ab5fb Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 22:42:53 +0200 Subject: [PATCH 127/145] libmultipath: remove struct and union names in cciss.h Only the typedef names are used in the rest of the code, so we don't need these struct names. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/checkers/cciss.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libmultipath/checkers/cciss.h b/libmultipath/checkers/cciss.h index bdb118424..19450c2b8 100644 --- a/libmultipath/checkers/cciss.h +++ b/libmultipath/checkers/cciss.h @@ -42,7 +42,7 @@ #pragma pack(1) //Command List Structure -typedef union _SCSI3Addr_struct { +typedef union { struct { BYTE Dev; BYTE Bus:6; @@ -61,27 +61,27 @@ typedef union _SCSI3Addr_struct { } LogUnit; } SCSI3Addr_struct; -typedef struct _PhysDevAddr_struct { +typedef struct { DWORD TargetId:24; DWORD Bus:6; DWORD Mode:2; SCSI3Addr_struct Target[2]; //2 level target device addr } PhysDevAddr_struct; -typedef struct _LogDevAddr_struct { +typedef struct { DWORD VolId:30; DWORD Mode:2; BYTE reserved[4]; } LogDevAddr_struct; -typedef union _LUNAddr_struct { +typedef union { BYTE LunAddrBytes[8]; SCSI3Addr_struct SCSI3Lun[4]; PhysDevAddr_struct PhysDev; LogDevAddr_struct LogDev; } LUNAddr_struct; -typedef struct _RequestBlock_struct { +typedef struct { BYTE CDBLen; struct { BYTE Type:3; @@ -92,7 +92,7 @@ typedef struct _RequestBlock_struct { BYTE CDB[16]; } RequestBlock_struct; -typedef union _MoreErrInfo_struct{ +typedef union { struct { BYTE Reserved[3]; BYTE Type; @@ -106,7 +106,7 @@ typedef union _MoreErrInfo_struct{ } Invalid_Cmd; } MoreErrInfo_struct; -typedef struct _ErrorInfo_struct { +typedef struct { BYTE ScsiStatus; BYTE SenseLen; HWORD CommandStatus; @@ -117,7 +117,7 @@ typedef struct _ErrorInfo_struct { #pragma pack() -typedef struct _IOCTL_Command_struct { +typedef struct { LUNAddr_struct LUN_info; RequestBlock_struct Request; ErrorInfo_struct error_info; @@ -125,7 +125,7 @@ typedef struct _IOCTL_Command_struct { BYTE *buf; } IOCTL_Command_struct; -typedef struct _LogvolInfo_struct{ +typedef struct { __u32 LunID; int num_opens; /* number of opens on the logical volume */ int num_parts; /* number of partitions configured on logvol */ From b958d9628845d0457a72550275047d9e084b0f7f Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 19:03:30 +0200 Subject: [PATCH 128/145] libmpathpersist: rename functions with double leading underscore Also remove some superfluous "extern" qualifiers in mpath_persist.h. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathpersist/libmpathpersist.version | 6 ++-- libmpathpersist/mpath_persist.c | 22 +++++++------- libmpathpersist/mpath_persist.h | 39 ++++++++++++------------- mpathpersist/main.c | 6 ++-- 4 files changed, 35 insertions(+), 38 deletions(-) diff --git a/libmpathpersist/libmpathpersist.version b/libmpathpersist/libmpathpersist.version index a8c6aae77..f467d99b9 100644 --- a/libmpathpersist/libmpathpersist.version +++ b/libmpathpersist/libmpathpersist.version @@ -10,7 +10,7 @@ * * See libmultipath.version for general policy about version numbers. */ -LIBMPATHPERSIST_2.1.0 { +LIBMPATHPERSIST_3.0.0 { global: /* public API as defined in mpath_persist.h */ libmpathpersist_exit; @@ -19,10 +19,10 @@ global: mpath_lib_init; mpath_mx_alloc_len; mpath_persistent_reserve_free_vecs; - __mpath_persistent_reserve_in; + mpath_persistent_reserve_in__; mpath_persistent_reserve_in; mpath_persistent_reserve_init_vecs; - __mpath_persistent_reserve_out; + mpath_persistent_reserve_out__; mpath_persistent_reserve_out; local: *; }; diff --git a/libmpathpersist/mpath_persist.c b/libmpathpersist/mpath_persist.c index 6cfcddee5..ace91d73c 100644 --- a/libmpathpersist/mpath_persist.c +++ b/libmpathpersist/mpath_persist.c @@ -74,7 +74,7 @@ int libmpathpersist_exit(void) static vector curmp; static vector pathvec; -static void __mpath_persistent_reserve_free_vecs(vector curmp, vector pathvec) +static void mpath_persistent_reserve_free_vecs__(vector curmp, vector pathvec) { free_multipathvec(curmp, KEEP_PATHS); free_pathvec(pathvec, FREE_PATHS); @@ -82,11 +82,11 @@ static void __mpath_persistent_reserve_free_vecs(vector curmp, vector pathvec) void mpath_persistent_reserve_free_vecs(void) { - __mpath_persistent_reserve_free_vecs(curmp, pathvec); + mpath_persistent_reserve_free_vecs__(curmp, pathvec); curmp = pathvec = NULL; } -static int __mpath_persistent_reserve_init_vecs(vector *curmp_p, +static int mpath_persistent_reserve_init_vecs__(vector *curmp_p, vector *pathvec_p, int verbose) { libmp_verbosity = verbose; @@ -110,17 +110,17 @@ static int __mpath_persistent_reserve_init_vecs(vector *curmp_p, return MPATH_PR_SUCCESS; err: - __mpath_persistent_reserve_free_vecs(*curmp_p, *pathvec_p); + mpath_persistent_reserve_free_vecs__(*curmp_p, *pathvec_p); *curmp_p = *pathvec_p = NULL; return MPATH_PR_DMMP_ERROR; } int mpath_persistent_reserve_init_vecs(int verbose) { - return __mpath_persistent_reserve_init_vecs(&curmp, &pathvec, verbose); + return mpath_persistent_reserve_init_vecs__(&curmp, &pathvec, verbose); } -int __mpath_persistent_reserve_in (int fd, int rq_servact, +int mpath_persistent_reserve_in__(int fd, int rq_servact, struct prin_resp *resp, int noisy) { return do_mpath_persistent_reserve_in(curmp, pathvec, fd, rq_servact, @@ -128,7 +128,7 @@ int __mpath_persistent_reserve_in (int fd, int rq_servact, } -int __mpath_persistent_reserve_out ( int fd, int rq_servact, int rq_scope, +int mpath_persistent_reserve_out__( int fd, int rq_servact, int rq_scope, unsigned int rq_type, struct prout_param_descriptor *paramp, int noisy) { return do_mpath_persistent_reserve_out(curmp, pathvec, fd, rq_servact, @@ -140,14 +140,14 @@ int mpath_persistent_reserve_in (int fd, int rq_servact, struct prin_resp *resp, int noisy, int verbose) { vector curmp = NULL, pathvec; - int ret = __mpath_persistent_reserve_init_vecs(&curmp, &pathvec, + int ret = mpath_persistent_reserve_init_vecs__(&curmp, &pathvec, verbose); if (ret != MPATH_PR_SUCCESS) return ret; ret = do_mpath_persistent_reserve_in(curmp, pathvec, fd, rq_servact, resp, noisy); - __mpath_persistent_reserve_free_vecs(curmp, pathvec); + mpath_persistent_reserve_free_vecs__(curmp, pathvec); return ret; } @@ -155,13 +155,13 @@ int mpath_persistent_reserve_out ( int fd, int rq_servact, int rq_scope, unsigned int rq_type, struct prout_param_descriptor *paramp, int noisy, int verbose) { vector curmp = NULL, pathvec; - int ret = __mpath_persistent_reserve_init_vecs(&curmp, &pathvec, + int ret = mpath_persistent_reserve_init_vecs__(&curmp, &pathvec, verbose); if (ret != MPATH_PR_SUCCESS) return ret; ret = do_mpath_persistent_reserve_out(curmp, pathvec, fd, rq_servact, rq_scope, rq_type, paramp, noisy); - __mpath_persistent_reserve_free_vecs(curmp, pathvec); + mpath_persistent_reserve_free_vecs__(curmp, pathvec); return ret; } diff --git a/libmpathpersist/mpath_persist.h b/libmpathpersist/mpath_persist.h index 9c88e151b..d94205f08 100644 --- a/libmpathpersist/mpath_persist.h +++ b/libmpathpersist/mpath_persist.h @@ -3,7 +3,6 @@ #ifndef MPATH_PERSIST_H_INCLUDED #define MPATH_PERSIST_H_INCLUDED - #ifdef __cplusplus extern "C" { #endif @@ -81,12 +80,8 @@ extern "C" { #define MPATH_WWUI_DEVICE_NAME 0x00 /* World wide unique initiator device name */ #define MPATH_WWUI_PORT_IDENTIFIER 0x40 /* World wide unique initiator port identifier */ - - extern unsigned int mpath_mx_alloc_len; - - struct prin_readdescr { uint32_t prgeneration; @@ -183,7 +178,7 @@ struct prout_param_descriptor { /* PROUT parameter descriptor */ * * RETURNS: 0->Success, 1->Failed. */ -extern int libmpathpersist_init (void); +int libmpathpersist_init(void); /* * DESCRIPTION : @@ -197,7 +192,7 @@ extern int libmpathpersist_init (void); * * RETURNS: struct config ->Success, NULL->Failed. */ -extern struct config * mpath_lib_init (void); +struct config *mpath_lib_init(void); /* @@ -209,7 +204,7 @@ extern struct config * mpath_lib_init (void); * * RETURNS: 0->Success, 1->Failed. */ -extern int mpath_lib_exit (struct config *conf); +int mpath_lib_exit(struct config *conf); /* * DESCRIPTION : @@ -221,7 +216,7 @@ extern int mpath_lib_exit (struct config *conf); * * RETURNS: 0->Success, 1->Failed. */ -extern int libmpathpersist_exit (void); +int libmpathpersist_exit(void); /* @@ -241,8 +236,8 @@ extern int libmpathpersist_exit (void); * above in RETURN_STATUS. * */ -extern int mpath_persistent_reserve_in (int fd, int rq_servact, struct prin_resp *resp, - int noisy, int verbose); +int mpath_persistent_reserve_in(int fd, int rq_servact, struct prin_resp *resp, + int noisy, int verbose); /* * DESCRIPTION : @@ -254,8 +249,8 @@ extern int mpath_persistent_reserve_in (int fd, int rq_servact, struct prin_resp * RESTRICTIONS: * This function uses static internal variables, and is not thread-safe. */ -extern int __mpath_persistent_reserve_in(int fd, int rq_servact, - struct prin_resp *resp, int noisy); +int mpath_persistent_reserve_in__(int fd, int rq_servact, + struct prin_resp *resp, int noisy); /* * DESCRIPTION : @@ -279,9 +274,10 @@ extern int __mpath_persistent_reserve_in(int fd, int rq_servact, * RETURNS: MPATH_PR_SUCCESS if PR command successful else returns any of the status specified * above in RETURN_STATUS. */ -extern int mpath_persistent_reserve_out ( int fd, int rq_servact, int rq_scope, - unsigned int rq_type, struct prout_param_descriptor *paramp, int noisy, - int verbose); +int mpath_persistent_reserve_out(int fd, int rq_servact, int rq_scope, + unsigned int rq_type, + struct prout_param_descriptor *paramp, + int noisy, int verbose); /* * DESCRIPTION : * This function is like mpath_persistent_reserve_out(), except that it @@ -292,15 +288,16 @@ extern int mpath_persistent_reserve_out ( int fd, int rq_servact, int rq_scope, * RESTRICTIONS: * This function uses static internal variables, and is not thread-safe. */ -extern int __mpath_persistent_reserve_out( int fd, int rq_servact, int rq_scope, - unsigned int rq_type, struct prout_param_descriptor *paramp, - int noisy); +int mpath_persistent_reserve_out__(int fd, int rq_servact, int rq_scope, + unsigned int rq_type, + struct prout_param_descriptor *paramp, + int noisy); /* * DESCRIPTION : * This function allocates data structures and performs basic initialization and - * device discovery for later calls of __mpath_persistent_reserve_in() or - * __mpath_persistent_reserve_out(). + * device discovery for later calls of mpath_persistent_reserve_in__() or + * mpath_persistent_reserve_out__(). * @verbose: Set verbosity level. Input argument. value:0 to 3. 0->disabled, 3->Max verbose * * RESTRICTIONS: diff --git a/mpathpersist/main.c b/mpathpersist/main.c index b6617902f..efb46b95e 100644 --- a/mpathpersist/main.c +++ b/mpathpersist/main.c @@ -505,7 +505,7 @@ static int handle_args(int argc, char * argv[], int nline) goto out_fd; } - ret = __mpath_persistent_reserve_in (fd, prin_sa, resp, noisy); + ret = mpath_persistent_reserve_in__(fd, prin_sa, resp, noisy); if (ret != MPATH_PR_SUCCESS ) { fprintf (stderr, "Persistent Reserve IN command failed\n"); @@ -575,8 +575,8 @@ static int handle_args(int argc, char * argv[], int nline) } /* PROUT commands other than 'register and move' */ - ret = __mpath_persistent_reserve_out (fd, prout_sa, 0, prout_type, - paramp, noisy); + ret = mpath_persistent_reserve_out__(fd, prout_sa, 0, prout_type, + paramp, noisy); free_prout_param_descriptor(paramp); } From 49a0d2175ef95ec361ff92ad3f5e1980856103af Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 22:05:25 +0200 Subject: [PATCH 129/145] libdmmp: rename macros starting with _DMMP Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libdmmp/libdmmp.c | 60 +++++++++++++++++++-------------------- libdmmp/libdmmp_misc.c | 6 ++-- libdmmp/libdmmp_pg.c | 6 ++-- libdmmp/libdmmp_private.h | 2 +- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/libdmmp/libdmmp.c b/libdmmp/libdmmp.c index 1bfdbedcb..47f5b5393 100644 --- a/libdmmp/libdmmp.c +++ b/libdmmp/libdmmp.c @@ -35,19 +35,19 @@ #include "libdmmp/libdmmp.h" #include "libdmmp_private.h" -#define _DEFAULT_UXSOCK_TIMEOUT 60000 +#define DEFAULT_UXSOCK_TIMEOUT 60000 /* ^ 60 seconds. On system with 10k sdX, dmmp_mpath_array_get() * only take 3.5 seconds, so this default value should be OK for most users. */ -#define _DMMP_IPC_SHOW_JSON_CMD "show maps json" -#define _DMMP_JSON_MAJOR_KEY "major_version" -#define _DMMP_JSON_MAJOR_VERSION 0 -#define _DMMP_JSON_MAPS_KEY "maps" -#define _ERRNO_STR_BUFF_SIZE 256 -#define _IPC_MAX_CMD_LEN 512 +#define DMMP_IPC_SHOW_JSON_CMD "show maps json" +#define DMMP_JSON_MAJOR_KEY "major_version" +#define DMMP_JSON_MAJOR_VERSION 0 +#define DMMP_JSON_MAPS_KEY "maps" +#define ERRNO_STR_BUFF_SIZE 256 +#define IPC_MAX_CMD_LEN 512 /* ^ Was MAX_CMD_LEN in ./libmultipath/uxsock.h */ -#define _LAST_ERR_MSG_BUFF_SIZE 1024 +#define LAST_ERR_MSG_BUFF_SIZE 1024 struct dmmp_context { void (*log_func)(struct dmmp_context *ctx, int priority, @@ -56,7 +56,7 @@ struct dmmp_context { int log_priority; void *userdata; unsigned int tmo; - char last_err_msg[_LAST_ERR_MSG_BUFF_SIZE]; + char last_err_msg[LAST_ERR_MSG_BUFF_SIZE]; }; /* @@ -99,7 +99,7 @@ void _dmmp_log(struct dmmp_context *ctx, int priority, const char *file, va_start(args, format); ctx->log_func(ctx, priority, file, line, func_name, format, args); if (priority == DMMP_LOG_PRIORITY_ERROR) - vsnprintf(ctx->last_err_msg, _LAST_ERR_MSG_BUFF_SIZE, + vsnprintf(ctx->last_err_msg, LAST_ERR_MSG_BUFF_SIZE, format, args); va_end(args); } @@ -116,8 +116,8 @@ struct dmmp_context *dmmp_context_new(void) ctx->log_func = _dmmp_log_stderr; ctx->log_priority = DMMP_LOG_PRIORITY_DEFAULT; ctx->userdata = NULL; - ctx->tmo = _DEFAULT_UXSOCK_TIMEOUT; - memset(ctx->last_err_msg, 0, _LAST_ERR_MSG_BUFF_SIZE); + ctx->tmo = DEFAULT_UXSOCK_TIMEOUT; + memset(ctx->last_err_msg, 0, LAST_ERR_MSG_BUFF_SIZE); return ctx; } @@ -180,7 +180,7 @@ int dmmp_mpath_array_get(struct dmmp_context *ctx, _good(_ipc_connect(ctx, &ipc_fd), rc, out); - _good(_process_cmd(ctx, ipc_fd, _DMMP_IPC_SHOW_JSON_CMD, &j_str), + _good(_process_cmd(ctx, ipc_fd, DMMP_IPC_SHOW_JSON_CMD, &j_str), rc, out); _debug(ctx, "Got json output from multipathd: '%s'", j_str); @@ -202,20 +202,20 @@ int dmmp_mpath_array_get(struct dmmp_context *ctx, } _json_obj_get_value(ctx, j_obj, cur_json_major_version, - _DMMP_JSON_MAJOR_KEY, json_type_int, + DMMP_JSON_MAJOR_KEY, json_type_int, json_object_get_int, rc, out); - if (cur_json_major_version != _DMMP_JSON_MAJOR_VERSION) { + if (cur_json_major_version != DMMP_JSON_MAJOR_VERSION) { rc = DMMP_ERR_INCOMPATIBLE; _error(ctx, "Incompatible multipathd JSON major version %d, " "should be %d", cur_json_major_version, - _DMMP_JSON_MAJOR_VERSION); + DMMP_JSON_MAJOR_VERSION); goto out; } _debug(ctx, "multipathd JSON major version(%d) check pass", - _DMMP_JSON_MAJOR_VERSION); + DMMP_JSON_MAJOR_VERSION); - _json_obj_get_value(ctx, j_obj, ar_maps, _DMMP_JSON_MAPS_KEY, + _json_obj_get_value(ctx, j_obj, ar_maps, DMMP_JSON_MAPS_KEY, json_type_array, json_object_get_array, rc, out); if (ar_maps == NULL) { @@ -279,7 +279,7 @@ static int _process_cmd(struct dmmp_context *ctx, int fd, const char *cmd, { int errno_save = 0; int rc = DMMP_OK; - char errno_str_buff[_ERRNO_STR_BUFF_SIZE]; + char errno_str_buff[ERRNO_STR_BUFF_SIZE]; struct timespec start_ts; struct timespec cur_ts; unsigned int ipc_tmo = 0; @@ -300,7 +300,7 @@ static int _process_cmd(struct dmmp_context *ctx, int fd, const char *cmd, ipc_tmo = ctx->tmo; if (ctx->tmo == 0) - ipc_tmo = _DEFAULT_UXSOCK_TIMEOUT; + ipc_tmo = DEFAULT_UXSOCK_TIMEOUT; invoke: _debug(ctx, "Invoking IPC command '%s' with IPC tmo %u milliseconds", @@ -308,8 +308,8 @@ static int _process_cmd(struct dmmp_context *ctx, int fd, const char *cmd, flag_check_tmo = false; if (mpath_process_cmd(fd, cmd, output, ipc_tmo) != 0) { errno_save = errno; - memset(errno_str_buff, 0, _ERRNO_STR_BUFF_SIZE); - strerror_r(errno_save, errno_str_buff, _ERRNO_STR_BUFF_SIZE); + memset(errno_str_buff, 0, ERRNO_STR_BUFF_SIZE); + strerror_r(errno_save, errno_str_buff, ERRNO_STR_BUFF_SIZE); if (errno_save == ETIMEDOUT) { flag_check_tmo = true; } else { @@ -397,7 +397,7 @@ static int _ipc_connect(struct dmmp_context *ctx, int *fd) { int rc = DMMP_OK; int errno_save = 0; - char errno_str_buff[_ERRNO_STR_BUFF_SIZE]; + char errno_str_buff[ERRNO_STR_BUFF_SIZE]; assert(ctx != NULL); assert(fd != NULL); @@ -407,8 +407,8 @@ static int _ipc_connect(struct dmmp_context *ctx, int *fd) *fd = mpath_connect(); if (*fd == -1) { errno_save = errno; - memset(errno_str_buff, 0, _ERRNO_STR_BUFF_SIZE); - strerror_r(errno_save, errno_str_buff, _ERRNO_STR_BUFF_SIZE); + memset(errno_str_buff, 0, ERRNO_STR_BUFF_SIZE); + strerror_r(errno_save, errno_str_buff, ERRNO_STR_BUFF_SIZE); if (errno_save == ECONNREFUSED) { rc = DMMP_ERR_NO_DAEMON; _error(ctx, "Socket connection refuse. " @@ -426,14 +426,14 @@ int dmmp_flush_mpath(struct dmmp_context *ctx, const char *mpath_name) { int rc = DMMP_OK; int ipc_fd = -1; - char cmd[_IPC_MAX_CMD_LEN]; + char cmd[IPC_MAX_CMD_LEN]; char *output = NULL; assert(ctx != NULL); assert(mpath_name != NULL); - snprintf(cmd, _IPC_MAX_CMD_LEN, "del map %s", mpath_name); - if (strlen(cmd) == _IPC_MAX_CMD_LEN - 1) { + snprintf(cmd, IPC_MAX_CMD_LEN, "del map %s", mpath_name); + if (strlen(cmd) == IPC_MAX_CMD_LEN - 1) { rc = DMMP_ERR_INVALID_ARGUMENT; _error(ctx, "Invalid mpath name %s", mpath_name); goto out; @@ -461,9 +461,9 @@ int dmmp_reconfig(struct dmmp_context *ctx) int rc = DMMP_OK; int ipc_fd = -1; char *output = NULL; - char cmd[_IPC_MAX_CMD_LEN]; + char cmd[IPC_MAX_CMD_LEN]; - snprintf(cmd, _IPC_MAX_CMD_LEN, "%s", "reconfigure"); + snprintf(cmd, IPC_MAX_CMD_LEN, "%s", "reconfigure"); _good(_ipc_connect(ctx, &ipc_fd), rc, out); _good(_process_cmd(ctx, ipc_fd, cmd, &output), rc, out); diff --git a/libdmmp/libdmmp_misc.c b/libdmmp/libdmmp_misc.c index 69b5a2028..51c71cdda 100644 --- a/libdmmp/libdmmp_misc.c +++ b/libdmmp/libdmmp_misc.c @@ -30,7 +30,7 @@ #include "libdmmp/libdmmp.h" #include "libdmmp_private.h" -#define _DMMP_LOG_STRERR_ALIGN_WIDTH 80 +#define DMMP_LOG_STRERR_ALIGN_WIDTH 80 /* ^ Only used in _dmmp_log_stderr() for pretty log output. * When provided log message is less than 80 bytes, fill it with space, then * print code file name, function name, line after the 80th bytes. @@ -81,9 +81,9 @@ void _dmmp_log_stderr(struct dmmp_context *ctx, int priority, * bypass clang static analyzer about unused ctx argument warning */ - if (printed_bytes < _DMMP_LOG_STRERR_ALIGN_WIDTH) { + if (printed_bytes < DMMP_LOG_STRERR_ALIGN_WIDTH) { fprintf(stderr, "%*s # %s:%s():%d\n", - _DMMP_LOG_STRERR_ALIGN_WIDTH - printed_bytes, "", file, + DMMP_LOG_STRERR_ALIGN_WIDTH - printed_bytes, "", file, func_name, line); } else { fprintf(stderr, " # %s:%s():%d\n", file, func_name, line); diff --git a/libdmmp/libdmmp_pg.c b/libdmmp/libdmmp_pg.c index 5149161cd..6be2316ac 100644 --- a/libdmmp/libdmmp_pg.c +++ b/libdmmp/libdmmp_pg.c @@ -78,7 +78,7 @@ struct dmmp_path_group *_dmmp_path_group_new(void) malloc(sizeof(struct dmmp_path_group)); if (dmmp_pg != NULL) { - dmmp_pg->id = _DMMP_PATH_GROUP_ID_UNKNOWN; + dmmp_pg->id = DMMP_PATH_GROUP_ID_UNKNOWN; dmmp_pg->status = DMMP_PATH_GROUP_STATUS_UNKNOWN; dmmp_pg->priority = 0; dmmp_pg->selector = NULL; @@ -127,10 +127,10 @@ int _dmmp_path_group_update(struct dmmp_context *ctx, dmmp_pg->id = id; - if (dmmp_pg->id == _DMMP_PATH_GROUP_ID_UNKNOWN) { + if (dmmp_pg->id == DMMP_PATH_GROUP_ID_UNKNOWN) { rc = DMMP_ERR_BUG; _error(ctx, "BUG: Got unknown(%d) path group ID", - _DMMP_PATH_GROUP_ID_UNKNOWN); + DMMP_PATH_GROUP_ID_UNKNOWN); goto out; } diff --git a/libdmmp/libdmmp_private.h b/libdmmp/libdmmp_private.h index 9606fb39b..0c497b39d 100644 --- a/libdmmp/libdmmp_private.h +++ b/libdmmp/libdmmp_private.h @@ -46,7 +46,7 @@ extern "C" { goto out; \ } while(0) -#define _DMMP_PATH_GROUP_ID_UNKNOWN 0 +#define DMMP_PATH_GROUP_ID_UNKNOWN 0 struct DMMP_DLL_LOCAL _num_str_conv; struct _num_str_conv { From f9e7f3efc19b3610ffa3b0c58258a0eaf9f469cd Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 22:55:55 +0200 Subject: [PATCH 130/145] libdmmp: rename enum values and variables starting with _DMMP_ Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libdmmp/libdmmp_path.c | 14 +++++++------- libdmmp/libdmmp_pg.c | 18 +++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/libdmmp/libdmmp_path.c b/libdmmp/libdmmp_path.c index 21714b156..0650f8d62 100644 --- a/libdmmp/libdmmp_path.c +++ b/libdmmp/libdmmp_path.c @@ -27,17 +27,17 @@ #include "libdmmp/libdmmp.h" #include "libdmmp_private.h" -#define _DMMP_SHOW_PS_INDEX_BLK_NAME 0 -#define _DMMP_SHOW_PS_INDEX_STATUS 1 -#define _DMMP_SHOW_PS_INDEX_WWID 2 -#define _DMMP_SHOW_PS_INDEX_PGID 3 +#define DMMP_SHOW_PS_INDEX_BLK_NAME 0 +#define DMMP_SHOW_PS_INDEX_STATUS 1 +#define DMMP_SHOW_PS_INDEX_WWID 2 +#define DMMP_SHOW_PS_INDEX_PGID 3 struct dmmp_path { char *blk_name; uint32_t status; }; -static const struct _num_str_conv _DMMP_PATH_STATUS_CONV[] = { +static const struct _num_str_conv DMMP_PATH_STATUS_CONV[] = { {DMMP_PATH_STATUS_UNKNOWN, "undef"}, {DMMP_PATH_STATUS_UP, "ready"}, {DMMP_PATH_STATUS_DOWN, "faulty"}, @@ -49,10 +49,10 @@ static const struct _num_str_conv _DMMP_PATH_STATUS_CONV[] = { }; _dmmp_str_func_gen(dmmp_path_status_str, uint32_t, path_status, - _DMMP_PATH_STATUS_CONV); + DMMP_PATH_STATUS_CONV); _dmmp_str_conv_func_gen(_dmmp_path_status_str_conv, ctx, path_status_str, uint32_t, DMMP_PATH_STATUS_UNKNOWN, - _DMMP_PATH_STATUS_CONV); + DMMP_PATH_STATUS_CONV); _dmmp_getter_func_gen(dmmp_path_blk_name_get, struct dmmp_path, dmmp_p, blk_name, const char *); diff --git a/libdmmp/libdmmp_pg.c b/libdmmp/libdmmp_pg.c index 6be2316ac..42e87fe7e 100644 --- a/libdmmp/libdmmp_pg.c +++ b/libdmmp/libdmmp_pg.c @@ -28,12 +28,12 @@ #include "libdmmp/libdmmp.h" #include "libdmmp_private.h" -#define _DMMP_SHOW_PGS_CMD "show groups raw format %w|%g|%p|%t|%s" -#define _DMMP_SHOW_PG_INDEX_WWID 0 -#define _DMMP_SHOW_PG_INDEX_PG_ID 1 -#define _DMMP_SHOW_PG_INDEX_PRI 2 -#define _DMMP_SHOW_PG_INDEX_STATUS 3 -#define _DMMP_SHOW_PG_INDEX_SELECTOR 4 +#define DMMP_SHOW_PGS_CMD "show groups raw format %w|%g|%p|%t|%s" +#define DMMP_SHOW_PG_INDEX_WWID 0 +#define DMMP_SHOW_PG_INDEX_PG_ID 1 +#define DMMP_SHOW_PG_INDEX_PRI 2 +#define DMMP_SHOW_PG_INDEX_STATUS 3 +#define DMMP_SHOW_PG_INDEX_SELECTOR 4 struct dmmp_path_group { uint32_t id; @@ -45,7 +45,7 @@ struct dmmp_path_group { struct dmmp_path **dmmp_ps; }; -static const struct _num_str_conv _DMMP_PATH_GROUP_STATUS_CONV[] = { +static const struct _num_str_conv DMMP_PATH_GROUP_STATUS_CONV[] = { {DMMP_PATH_GROUP_STATUS_UNKNOWN, "undef"}, {DMMP_PATH_GROUP_STATUS_ACTIVE, "active"}, {DMMP_PATH_GROUP_STATUS_DISABLED, "disabled"}, @@ -53,10 +53,10 @@ static const struct _num_str_conv _DMMP_PATH_GROUP_STATUS_CONV[] = { }; _dmmp_str_func_gen(dmmp_path_group_status_str, uint32_t, pg_status, - _DMMP_PATH_GROUP_STATUS_CONV); + DMMP_PATH_GROUP_STATUS_CONV); _dmmp_str_conv_func_gen(_dmmp_path_group_status_str_conv, ctx, pg_status_str, uint32_t, DMMP_PATH_GROUP_STATUS_UNKNOWN, - _DMMP_PATH_GROUP_STATUS_CONV); + DMMP_PATH_GROUP_STATUS_CONV); _dmmp_getter_func_gen(dmmp_path_group_id_get, struct dmmp_path_group, dmmp_pg, id, uint32_t); From 7df01290f8f8f30941c4780de783943e906279b6 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 8 Aug 2024 13:23:28 +0200 Subject: [PATCH 131/145] libdmmp: rename non-static functions starting with underscore Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libdmmp/libdmmp.c | 10 +++++----- libdmmp/libdmmp_misc.c | 4 ++-- libdmmp/libdmmp_mp.c | 12 ++++++------ libdmmp/libdmmp_path.c | 8 ++++---- libdmmp/libdmmp_pg.c | 16 ++++++++-------- libdmmp/libdmmp_private.h | 24 ++++++++++++------------ 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/libdmmp/libdmmp.c b/libdmmp/libdmmp.c index 47f5b5393..8b9686a69 100644 --- a/libdmmp/libdmmp.c +++ b/libdmmp/libdmmp.c @@ -86,9 +86,9 @@ _dmmp_getter_func_gen(dmmp_last_error_msg, struct dmmp_context, ctx, last_err_msg, const char *); _dmmp_array_free_func_gen(dmmp_mpath_array_free, struct dmmp_mpath, - _dmmp_mpath_free); + dmmp_mpath_free); -void _dmmp_log(struct dmmp_context *ctx, int priority, const char *file, +void dmmp_log(struct dmmp_context *ctx, int priority, const char *file, int line, const char *func_name, const char *format, ...) { va_list args; @@ -113,7 +113,7 @@ struct dmmp_context *dmmp_context_new(void) if (ctx == NULL) return NULL; - ctx->log_func = _dmmp_log_stderr; + ctx->log_func = dmmp_log_stderr; ctx->log_priority = DMMP_LOG_PRIORITY_DEFAULT; ctx->userdata = NULL; ctx->tmo = DEFAULT_UXSOCK_TIMEOUT; @@ -250,10 +250,10 @@ int dmmp_mpath_array_get(struct dmmp_context *ctx, goto out; } - dmmp_mp = _dmmp_mpath_new(); + dmmp_mp = dmmp_mpath_new(); _dmmp_alloc_null_check(ctx, dmmp_mp, rc, out); (*dmmp_mps)[i] = dmmp_mp; - _good(_dmmp_mpath_update(ctx, dmmp_mp, j_obj_map), rc, out); + _good(dmmp_mpath_update(ctx, dmmp_mp, j_obj_map), rc, out); } out: diff --git a/libdmmp/libdmmp_misc.c b/libdmmp/libdmmp_misc.c index 51c71cdda..92bbf8d32 100644 --- a/libdmmp/libdmmp_misc.c +++ b/libdmmp/libdmmp_misc.c @@ -31,7 +31,7 @@ #include "libdmmp_private.h" #define DMMP_LOG_STRERR_ALIGN_WIDTH 80 -/* ^ Only used in _dmmp_log_stderr() for pretty log output. +/* ^ Only used in dmmp_log_stderr() for pretty log output. * When provided log message is less than 80 bytes, fill it with space, then * print code file name, function name, line after the 80th bytes. */ @@ -62,7 +62,7 @@ static const struct _num_str_conv _DMMP_PRI_CONV[] = { }; _dmmp_str_func_gen(dmmp_log_priority_str, int, priority, _DMMP_PRI_CONV); -void _dmmp_log_stderr(struct dmmp_context *ctx, int priority, +void dmmp_log_stderr(struct dmmp_context *ctx, int priority, const char *file, int line, const char *func_name, const char *format, va_list args) { diff --git a/libdmmp/libdmmp_mp.c b/libdmmp/libdmmp_mp.c index bc48d0e35..1be8ba1aa 100644 --- a/libdmmp/libdmmp_mp.c +++ b/libdmmp/libdmmp_mp.c @@ -44,7 +44,7 @@ _dmmp_getter_func_gen(dmmp_mpath_wwid_get, struct dmmp_mpath, dmmp_mp, _dmmp_getter_func_gen(dmmp_mpath_kdev_name_get, struct dmmp_mpath, dmmp_mp, kdev_name, const char *); -struct dmmp_mpath *_dmmp_mpath_new(void) +struct dmmp_mpath *dmmp_mpath_new(void) { struct dmmp_mpath *dmmp_mp = NULL; @@ -59,7 +59,7 @@ struct dmmp_mpath *_dmmp_mpath_new(void) return dmmp_mp; } -int _dmmp_mpath_update(struct dmmp_context *ctx, struct dmmp_mpath *dmmp_mp, +int dmmp_mpath_update(struct dmmp_context *ctx, struct dmmp_mpath *dmmp_mp, json_object *j_obj_map) { int rc = DMMP_OK; @@ -113,10 +113,10 @@ int _dmmp_mpath_update(struct dmmp_context *ctx, struct dmmp_mpath *dmmp_mp, dmmp_mp->dmmp_pgs[i] = NULL; for (i = 0; i < dmmp_mp->dmmp_pg_count; ++i) { - dmmp_pg = _dmmp_path_group_new(); + dmmp_pg = dmmp_path_group_new(); _dmmp_alloc_null_check(ctx, dmmp_pg, rc, out); dmmp_mp->dmmp_pgs[i] = dmmp_pg; - _good(_dmmp_path_group_update(ctx, dmmp_pg, + _good(dmmp_path_group_update(ctx, dmmp_pg, array_list_get_idx(ar_pgs, i)), rc, out); } @@ -126,11 +126,11 @@ int _dmmp_mpath_update(struct dmmp_context *ctx, struct dmmp_mpath *dmmp_mp, out: if (rc != DMMP_OK) - _dmmp_mpath_free(dmmp_mp); + dmmp_mpath_free(dmmp_mp); return rc; } -void _dmmp_mpath_free(struct dmmp_mpath *dmmp_mp) +void dmmp_mpath_free(struct dmmp_mpath *dmmp_mp) { if (dmmp_mp == NULL) return ; diff --git a/libdmmp/libdmmp_path.c b/libdmmp/libdmmp_path.c index 0650f8d62..96a96f4aa 100644 --- a/libdmmp/libdmmp_path.c +++ b/libdmmp/libdmmp_path.c @@ -59,7 +59,7 @@ _dmmp_getter_func_gen(dmmp_path_blk_name_get, struct dmmp_path, dmmp_p, _dmmp_getter_func_gen(dmmp_path_status_get, struct dmmp_path, dmmp_p, status, uint32_t); -struct dmmp_path *_dmmp_path_new(void) +struct dmmp_path *dmmp_path_new(void) { struct dmmp_path *dmmp_p = NULL; @@ -72,7 +72,7 @@ struct dmmp_path *_dmmp_path_new(void) return dmmp_p; } -int _dmmp_path_update(struct dmmp_context *ctx, struct dmmp_path *dmmp_p, +int dmmp_path_update(struct dmmp_context *ctx, struct dmmp_path *dmmp_p, json_object *j_obj_p) { int rc = DMMP_OK; @@ -102,11 +102,11 @@ int _dmmp_path_update(struct dmmp_context *ctx, struct dmmp_path *dmmp_p, out: if (rc != DMMP_OK) - _dmmp_path_free(dmmp_p); + dmmp_path_free(dmmp_p); return rc; } -void _dmmp_path_free(struct dmmp_path *dmmp_p) +void dmmp_path_free(struct dmmp_path *dmmp_p) { if (dmmp_p == NULL) return; diff --git a/libdmmp/libdmmp_pg.c b/libdmmp/libdmmp_pg.c index 42e87fe7e..68f1917f7 100644 --- a/libdmmp/libdmmp_pg.c +++ b/libdmmp/libdmmp_pg.c @@ -67,10 +67,10 @@ _dmmp_getter_func_gen(dmmp_path_group_priority_get, struct dmmp_path_group, _dmmp_getter_func_gen(dmmp_path_group_selector_get, struct dmmp_path_group, dmmp_pg, selector, const char *); _dmmp_array_free_func_gen(_dmmp_path_group_array_free, struct dmmp_path_group, - _dmmp_path_group_free); + dmmp_path_group_free); -struct dmmp_path_group *_dmmp_path_group_new(void) +struct dmmp_path_group *dmmp_path_group_new(void) { struct dmmp_path_group *dmmp_pg = NULL; @@ -87,7 +87,7 @@ struct dmmp_path_group *_dmmp_path_group_new(void) } return dmmp_pg; } -int _dmmp_path_group_update(struct dmmp_context *ctx, +int dmmp_path_group_update(struct dmmp_context *ctx, struct dmmp_path_group *dmmp_pg, json_object *j_obj_pg) { @@ -157,10 +157,10 @@ int _dmmp_path_group_update(struct dmmp_context *ctx, dmmp_pg->dmmp_ps[i] = NULL; for (i = 0; i < dmmp_pg->dmmp_p_count; ++i) { - dmmp_p = _dmmp_path_new(); + dmmp_p = dmmp_path_new(); _dmmp_alloc_null_check(ctx, dmmp_p, rc, out); dmmp_pg->dmmp_ps[i] = dmmp_p; - _good(_dmmp_path_update(ctx, dmmp_p, + _good(dmmp_path_update(ctx, dmmp_p, array_list_get_idx(ar_ps, i)), rc, out); } @@ -173,11 +173,11 @@ int _dmmp_path_group_update(struct dmmp_context *ctx, out: if (rc != DMMP_OK) - _dmmp_path_group_free(dmmp_pg); + dmmp_path_group_free(dmmp_pg); return rc; } -void _dmmp_path_group_free(struct dmmp_path_group *dmmp_pg) +void dmmp_path_group_free(struct dmmp_path_group *dmmp_pg) { uint32_t i = 0; @@ -188,7 +188,7 @@ void _dmmp_path_group_free(struct dmmp_path_group *dmmp_pg) if (dmmp_pg->dmmp_ps != NULL) { for (i = 0; i < dmmp_pg->dmmp_p_count; ++i) { - _dmmp_path_free(dmmp_pg->dmmp_ps[i]); + dmmp_path_free(dmmp_pg->dmmp_ps[i]); } free(dmmp_pg->dmmp_ps); } diff --git a/libdmmp/libdmmp_private.h b/libdmmp/libdmmp_private.h index 0c497b39d..d154146ce 100644 --- a/libdmmp/libdmmp_private.h +++ b/libdmmp/libdmmp_private.h @@ -110,33 +110,33 @@ do { \ DMMP_DLL_LOCAL int _dmmp_ipc_exec(struct dmmp_context *ctx, const char *cmd, char **output); -DMMP_DLL_LOCAL struct dmmp_mpath *_dmmp_mpath_new(void); -DMMP_DLL_LOCAL struct dmmp_path_group *_dmmp_path_group_new(void); -DMMP_DLL_LOCAL struct dmmp_path *_dmmp_path_new(void); +DMMP_DLL_LOCAL struct dmmp_mpath *dmmp_mpath_new(void); +DMMP_DLL_LOCAL struct dmmp_path_group *dmmp_path_group_new(void); +DMMP_DLL_LOCAL struct dmmp_path *dmmp_path_new(void); -DMMP_DLL_LOCAL int _dmmp_mpath_update(struct dmmp_context *ctx, +DMMP_DLL_LOCAL int dmmp_mpath_update(struct dmmp_context *ctx, struct dmmp_mpath *dmmp_mp, json_object *j_obj_map); -DMMP_DLL_LOCAL int _dmmp_path_group_update(struct dmmp_context *ctx, +DMMP_DLL_LOCAL int dmmp_path_group_update(struct dmmp_context *ctx, struct dmmp_path_group *dmmp_pg, json_object *j_obj_pg); -DMMP_DLL_LOCAL int _dmmp_path_update(struct dmmp_context *ctx, +DMMP_DLL_LOCAL int dmmp_path_update(struct dmmp_context *ctx, struct dmmp_path *dmmp_p, json_object *j_obj_p); -DMMP_DLL_LOCAL void _dmmp_mpath_free(struct dmmp_mpath *dmmp_mp); -DMMP_DLL_LOCAL void _dmmp_path_group_free(struct dmmp_path_group *dmmp_pg); +DMMP_DLL_LOCAL void dmmp_mpath_free(struct dmmp_mpath *dmmp_mp); +DMMP_DLL_LOCAL void dmmp_path_group_free(struct dmmp_path_group *dmmp_pg); DMMP_DLL_LOCAL void _dmmp_path_group_array_free (struct dmmp_path_group **dmmp_pgs, uint32_t dmmp_pg_count); -DMMP_DLL_LOCAL void _dmmp_path_free(struct dmmp_path *dmmp_p); -DMMP_DLL_LOCAL void _dmmp_log(struct dmmp_context *ctx, int priority, +DMMP_DLL_LOCAL void dmmp_path_free(struct dmmp_path *dmmp_p); +DMMP_DLL_LOCAL void dmmp_log(struct dmmp_context *ctx, int priority, const char *file, int line, const char *func_name, const char *format, ...) __attribute__((format(printf, 6, 7))); DMMP_DLL_LOCAL void _dmmp_log_err_str(struct dmmp_context *ctx, int rc); -DMMP_DLL_LOCAL void _dmmp_log_stderr(struct dmmp_context *ctx, int priority, +DMMP_DLL_LOCAL void dmmp_log_stderr(struct dmmp_context *ctx, int priority, const char *file, int line, const char *func_name, const char *format, va_list args) @@ -146,7 +146,7 @@ DMMP_DLL_LOCAL void _dmmp_log_stderr(struct dmmp_context *ctx, int priority, #define _dmmp_log_cond(ctx, prio, arg...) \ do { \ if (dmmp_context_log_priority_get(ctx) >= prio) \ - _dmmp_log(ctx, prio, __FILE__, __LINE__, __FUNCTION__, \ + dmmp_log(ctx, prio, __FILE__, __LINE__, __FUNCTION__, \ ## arg); \ } while (0) From dd350c40b4f10634f16aa7a9f4e6d030eadf3257 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 21:56:44 +0200 Subject: [PATCH 132/145] multipathd: rename symbols with double leading underscore Also remove last mentions of __setup_multipath(), which has been removed in e5debe0 ("multipathd: don't modify the multipath device on show commands"). Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- multipathd/cli.c | 2 +- multipathd/cli.h | 6 +++--- multipathd/dmevents.c | 2 +- multipathd/main.c | 30 +++++++++++++++--------------- multipathd/waiter.c | 2 +- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/multipathd/cli.c b/multipathd/cli.c index 0c89b7cd9..139a4c494 100644 --- a/multipathd/cli.c +++ b/multipathd/cli.c @@ -114,7 +114,7 @@ find_handler (uint32_t fp) } int -__set_handler_callback (uint32_t fp, cli_handler *fn, bool locked) +set_handler_callback__ (uint32_t fp, cli_handler *fn, bool locked) { struct handler *h; diff --git a/multipathd/cli.h b/multipathd/cli.h index 294083205..dd26a2c21 100644 --- a/multipathd/cli.h +++ b/multipathd/cli.h @@ -137,9 +137,9 @@ struct handler { }; int alloc_handlers (void); -int __set_handler_callback (uint32_t fp, cli_handler *fn, bool locked); -#define set_handler_callback(fp, fn) __set_handler_callback(fp, fn, true) -#define set_unlocked_handler_callback(fp, fn) __set_handler_callback(fp, fn, false) +int set_handler_callback__ (uint32_t fp, cli_handler *fn, bool locked); +#define set_handler_callback(fp, fn) set_handler_callback__(fp, fn, true) +#define set_unlocked_handler_callback(fp, fn) set_handler_callback__(fp, fn, false) int get_cmdvec (char *cmd, vector *v, bool allow_incomplete); struct handler *find_handler_for_cmdvec(const struct _vector *v); diff --git a/multipathd/dmevents.c b/multipathd/dmevents.c index af1e12e71..7a78b8f74 100644 --- a/multipathd/dmevents.c +++ b/multipathd/dmevents.c @@ -202,7 +202,7 @@ static int dm_get_events(void) return -1; } -/* You must call __setup_multipath() after calling this function, to +/* You must call setup_multipath() after calling this function, to * deal with any events that came in before the device was added */ int watch_dmevents(char *name) { diff --git a/multipathd/main.c b/multipathd/main.c index bb19c9792..229b516a0 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -131,7 +131,7 @@ static int poll_dmevents = 1; /* Don't access this variable without holding config_lock */ static enum daemon_status running_state = DAEMON_INIT; /* Don't access this variable without holding config_lock */ -static bool __delayed_reconfig; +static bool delayed_reconfig; /* Don't access this variable without holding config_lock */ static enum force_reload_types reconfigure_pending = FORCE_RELOAD_NONE; pid_t daemon_pid; @@ -243,7 +243,7 @@ static void config_cleanup(__attribute__((unused)) void *arg) pthread_mutex_unlock(&config_lock); } -#define __wait_for_state_change(condition, ms) \ +#define wait_for_state_change__(condition, ms) \ ({ \ struct timespec tmo; \ int rc = 0; \ @@ -275,14 +275,14 @@ enum daemon_status wait_for_state_change_if(enum daemon_status oldstate, pthread_mutex_lock(&config_lock); pthread_cleanup_push(config_cleanup, NULL); - __wait_for_state_change(running_state == oldstate, ms); + wait_for_state_change__(running_state == oldstate, ms); st = running_state; pthread_cleanup_pop(1); return st; } /* must be called with config_lock held */ -static void __post_config_state(enum daemon_status state) +static void post_config_state__(enum daemon_status state) { if (state != running_state && running_state != DAEMON_SHUTDOWN) { enum daemon_status old_state = running_state; @@ -299,7 +299,7 @@ void post_config_state(enum daemon_status state) { pthread_mutex_lock(&config_lock); pthread_cleanup_push(config_cleanup, NULL); - __post_config_state(state); + post_config_state__(state); pthread_cleanup_pop(1); } @@ -308,15 +308,15 @@ static bool unblock_reconfigure(void) bool was_delayed; pthread_mutex_lock(&config_lock); - was_delayed = __delayed_reconfig; + was_delayed = delayed_reconfig; if (was_delayed) { - __delayed_reconfig = false; + delayed_reconfig = false; /* * In IDLE state, make sure child() is woken up * Otherwise it will wake up when state switches to IDLE */ if (running_state == DAEMON_IDLE) - __post_config_state(DAEMON_CONFIGURE); + post_config_state__(DAEMON_CONFIGURE); } pthread_mutex_unlock(&config_lock); if (was_delayed) @@ -350,7 +350,7 @@ void schedule_reconfigure(enum force_reload_types requested_type) break; case DAEMON_IDLE: reconfigure_pending = type; - __post_config_state(DAEMON_CONFIGURE); + post_config_state__(DAEMON_CONFIGURE); break; case DAEMON_CONFIGURE: case DAEMON_RUNNING: @@ -378,7 +378,7 @@ static enum daemon_status set_config_state(enum daemon_status state) } if (rc == 0 && running_state == DAEMON_IDLE && state != DAEMON_IDLE) - __post_config_state(state); + post_config_state__(state); st = running_state; pthread_cleanup_pop(1); @@ -3749,17 +3749,17 @@ child (__attribute__((unused)) void *param) /* * Check if another reconfigure request was scheduled * while we last ran reconfigure(). - * We have to test __delayed_reconfig here + * We have to test delayed_reconfig here * to avoid a busy loop */ (reconfigure_pending == FORCE_RELOAD_NONE - || __delayed_reconfig)) + || delayed_reconfig)) pthread_cond_wait(&config_cond, &config_lock); if (running_state != DAEMON_CONFIGURE && running_state != DAEMON_SHUTDOWN) /* This sets running_state to DAEMON_CONFIGURE */ - __post_config_state(DAEMON_CONFIGURE); + post_config_state__(DAEMON_CONFIGURE); state = running_state; pthread_cleanup_pop(1); if (state == DAEMON_SHUTDOWN) @@ -3776,13 +3776,13 @@ child (__attribute__((unused)) void *param) reload_type = reconfigure_pending == FORCE_RELOAD_YES ? FORCE_RELOAD_YES : FORCE_RELOAD_WEAK; reconfigure_pending = FORCE_RELOAD_NONE; - __delayed_reconfig = false; + delayed_reconfig = false; pthread_mutex_unlock(&config_lock); rc = reconfigure(vecs, reload_type); } else { pthread_mutex_lock(&config_lock); - __delayed_reconfig = true; + delayed_reconfig = true; pthread_mutex_unlock(&config_lock); condlog(3, "delaying reconfigure()"); } diff --git a/multipathd/waiter.c b/multipathd/waiter.c index 1dd93c5b2..f251c5002 100644 --- a/multipathd/waiter.c +++ b/multipathd/waiter.c @@ -56,7 +56,7 @@ void stop_waiter_thread (struct multipath *mpp) mpp->alias); return; } - /* Don't cancel yourself. __setup_multipath is called by + /* Don't cancel yourself. setup_multipath is called by by the waiter thread, and may remove a multipath device */ if (pthread_equal(mpp->waiter, pthread_self())) return; From c065b9016ace208fb0e4a5144391da02d28c0864 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 21:58:36 +0200 Subject: [PATCH 133/145] multipath-tools tests: rename functions with double underscores Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- tests/alias.c | 42 +++++++++++++++++++++--------------------- tests/test-lib.c | 4 ++-- tests/test-lib.h | 16 ++++++++-------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/tests/alias.c b/tests/alias.c index 4f23cf960..163d9a7d5 100644 --- a/tests/alias.c +++ b/tests/alias.c @@ -25,7 +25,7 @@ #define MPATH_ID_INT_MAX_p1 "fxshrxx" #endif -static int __set_errno(int err) +static int set_errno__(int err) { if (err >= 0) { errno = 0; @@ -63,12 +63,12 @@ ssize_t __wrap_write(int fd, const void *buf, size_t count) start = strstr(start, binding); check_expected(count); assert_ptr_not_equal(start, NULL); - return __set_errno(mock_type(int)); + return set_errno__(mock_type(int)); } int __wrap_rename(const char *old, const char *new) { - return __set_errno(mock_type(int)); + return set_errno__(mock_type(int)); } int WRAP_FUNC(mkstemp)(char *template) @@ -134,7 +134,7 @@ int __wrap_pthread_mutex_unlock(pthread_mutex_t *mutex) #define TEST_FPTR ((FILE *) 0xaffe) /* strbuf wrapper for the old format_devname() */ -static int __format_devname(char *name, int id, size_t len, const char *prefix) +static int format_devname__(char *name, int id, size_t len, const char *prefix) { STRBUF_ON_STACK(buf); @@ -151,7 +151,7 @@ static void fd_mpatha(void **state) char buf[32]; int rc; - rc = __format_devname(buf, 1, sizeof(buf), "FOO"); + rc = format_devname__(buf, 1, sizeof(buf), "FOO"); assert_int_equal(rc, 4); assert_string_equal(buf, "FOOa"); } @@ -162,7 +162,7 @@ static void fd_mpathz(void **state) char buf[5]; int rc; - rc = __format_devname(buf, 26, sizeof(buf), "FOO"); + rc = format_devname__(buf, 26, sizeof(buf), "FOO"); assert_int_equal(rc, 4); assert_string_equal(buf, "FOOz"); } @@ -172,7 +172,7 @@ static void fd_mpathaa(void **state) char buf[32]; int rc; - rc = __format_devname(buf, 26 + 1, sizeof(buf), "FOO"); + rc = format_devname__(buf, 26 + 1, sizeof(buf), "FOO"); assert_int_equal(rc, 5); assert_string_equal(buf, "FOOaa"); } @@ -182,7 +182,7 @@ static void fd_mpathzz(void **state) char buf[32]; int rc; - rc = __format_devname(buf, 26*26 + 26, sizeof(buf), "FOO"); + rc = format_devname__(buf, 26*26 + 26, sizeof(buf), "FOO"); assert_int_equal(rc, 5); assert_string_equal(buf, "FOOzz"); } @@ -192,7 +192,7 @@ static void fd_mpathaaa(void **state) char buf[32]; int rc; - rc = __format_devname(buf, 26*26 + 27, sizeof(buf), "FOO"); + rc = format_devname__(buf, 26*26 + 27, sizeof(buf), "FOO"); assert_int_equal(rc, 6); assert_string_equal(buf, "FOOaaa"); } @@ -202,7 +202,7 @@ static void fd_mpathzzz(void **state) char buf[32]; int rc; - rc = __format_devname(buf, 26*26*26 + 26*26 + 26, sizeof(buf), "FOO"); + rc = format_devname__(buf, 26*26*26 + 26*26 + 26, sizeof(buf), "FOO"); assert_int_equal(rc, 6); assert_string_equal(buf, "FOOzzz"); } @@ -212,7 +212,7 @@ static void fd_mpathaaaa(void **state) char buf[32]; int rc; - rc = __format_devname(buf, 26*26*26 + 26*26 + 27, sizeof(buf), "FOO"); + rc = format_devname__(buf, 26*26*26 + 26*26 + 27, sizeof(buf), "FOO"); assert_int_equal(rc, 7); assert_string_equal(buf, "FOOaaaa"); } @@ -222,7 +222,7 @@ static void fd_mpathzzzz(void **state) char buf[32]; int rc; - rc = __format_devname(buf, 26*26*26*26 + 26*26*26 + 26*26 + 26, + rc = format_devname__(buf, 26*26*26*26 + 26*26*26 + 26*26 + 26, sizeof(buf), "FOO"); assert_int_equal(rc, 7); assert_string_equal(buf, "FOOzzzz"); @@ -234,7 +234,7 @@ static void fd_mpath_max(void **state) char buf[32]; int rc; - rc = __format_devname(buf, INT_MAX, sizeof(buf), ""); + rc = format_devname__(buf, INT_MAX, sizeof(buf), ""); assert_int_equal(rc, strlen(MPATH_ID_INT_MAX)); assert_string_equal(buf, MPATH_ID_INT_MAX); } @@ -245,7 +245,7 @@ static void fd_mpath_max1(void **state) char buf[32]; int rc; - rc = __format_devname(buf, INT_MIN, sizeof(buf), ""); + rc = format_devname__(buf, INT_MIN, sizeof(buf), ""); assert_int_equal(rc, -1); } @@ -254,7 +254,7 @@ static void fd_mpath_short(void **state) char buf[4]; int rc; - rc = __format_devname(buf, 1, sizeof(buf), "FOO"); + rc = format_devname__(buf, 1, sizeof(buf), "FOO"); assert_int_equal(rc, -1); } @@ -263,7 +263,7 @@ static void fd_mpath_short1(void **state) char buf[5]; int rc; - rc = __format_devname(buf, 27, sizeof(buf), "FOO"); + rc = format_devname__(buf, 27, sizeof(buf), "FOO"); assert_int_equal(rc, -1); } @@ -388,7 +388,7 @@ static void sd_fd_many(void **state) int rc, i; for (i = 1; i < 5000; i++) { - rc = __format_devname(buf, i, sizeof(buf), "MPATH"); + rc = format_devname__(buf, i, sizeof(buf), "MPATH"); assert_in_range(rc, 6, 8); rc = scan_devname(buf, "MPATH"); assert_int_equal(rc, i); @@ -403,7 +403,7 @@ static void sd_fd_random(void **state) srandom(1); for (i = 1; i < 1000; i++) { n = random() & 0xffff; - rc = __format_devname(buf, n, sizeof(buf), "MPATH"); + rc = format_devname__(buf, n, sizeof(buf), "MPATH"); assert_in_range(rc, 6, 9); rc = scan_devname(buf, "MPATH"); assert_int_equal(rc, n); @@ -483,7 +483,7 @@ static void mock_self_alias(const char *alias, const char *wwid) expect_condlog(3, USED_STR(alias, wwid)); \ } while(0) -static void __mock_bindings_file(const char *content, bool conflict_ok) +static void mock_bindings_file__(const char *content, bool conflict_ok) { char *cnt __attribute__((cleanup(cleanup_charp))) = NULL; char *token, *savep = NULL; @@ -509,7 +509,7 @@ static void __mock_bindings_file(const char *content, bool conflict_ok) } static void mock_bindings_file(const char *content) { - return __mock_bindings_file(content, false); + return mock_bindings_file__(content, false); } static int teardown_bindings(void **state) @@ -1918,7 +1918,7 @@ static void order_test(int n, const struct random_aliases ra[], bool conflict_ok for (j = 0; j < n; j++) fill_bindings_random(&buf, ra[j].start, ra[j].end, ra[j].prefix); - __mock_bindings_file(get_strbuf_str(&buf), conflict_ok); + mock_bindings_file__(get_strbuf_str(&buf), conflict_ok); for (j = 0; j < n; j++) { bdg = VECTOR_SLOT(bindings, 0); diff --git a/tests/test-lib.c b/tests/test-lib.c index 88f35e947..99becccde 100644 --- a/tests/test-lib.c +++ b/tests/test-lib.c @@ -367,7 +367,7 @@ void mock_store_pathinfo(int mask, const struct mocked_path *mp) mock_pathinfo(mask, mp); } -struct path *__mock_path(vector pathvec, +struct path *mock_path__(vector pathvec, const char *vnd, const char *prd, const char *rev, const char *wwid, const char *dev, @@ -395,7 +395,7 @@ struct path *__mock_path(vector pathvec, } -struct multipath *__mock_multipath(struct vectors *vecs, struct path *pp) +struct multipath *mock_multipath__(struct vectors *vecs, struct path *pp) { struct multipath *mp; struct config *conf; diff --git a/tests/test-lib.h b/tests/test-lib.h index 61e67b29f..ff548342c 100644 --- a/tests/test-lib.h +++ b/tests/test-lib.h @@ -40,29 +40,29 @@ struct mocked_path *mocked_path_from_path(struct mocked_path *mp, void mock_pathinfo(int mask, const struct mocked_path *mp); void mock_store_pathinfo(int mask, const struct mocked_path *mp); -struct path *__mock_path(vector pathvec, +struct path *mock_path__(vector pathvec, const char *vnd, const char *prd, const char *rev, const char *wwid, const char *dev, unsigned int flags, int mask); #define mock_path(v, p) \ - __mock_path(hwt->vecs->pathvec, (v), (p), "0", NULL, NULL, \ + mock_path__(hwt->vecs->pathvec, (v), (p), "0", NULL, NULL, \ 0, default_mask) #define mock_path_flags(v, p, f) \ - __mock_path(hwt->vecs->pathvec, (v), (p), "0", NULL, NULL, \ + mock_path__(hwt->vecs->pathvec, (v), (p), "0", NULL, NULL, \ (f), default_mask) #define mock_path_blacklisted(v, p) \ - __mock_path(hwt->vecs->pathvec, (v), (p), "0", NULL, NULL, \ + mock_path__(hwt->vecs->pathvec, (v), (p), "0", NULL, NULL, \ BL_BY_DEVICE, default_mask) #define mock_path_wwid(v, p, w) \ - __mock_path(hwt->vecs->pathvec, (v), (p), "0", (w), NULL, \ + mock_path__(hwt->vecs->pathvec, (v), (p), "0", (w), NULL, \ 0, default_mask) #define mock_path_wwid_flags(v, p, w, f) \ - __mock_path(hwt->vecs->pathvec, (v), (p), "0", (w), \ + mock_path__(hwt->vecs->pathvec, (v), (p), "0", (w), \ NULL, (f), default_mask) -struct multipath *__mock_multipath(struct vectors *vecs, struct path *pp); -#define mock_multipath(pp) __mock_multipath(hwt->vecs, (pp)) +struct multipath *mock_multipath__(struct vectors *vecs, struct path *pp); +#define mock_multipath(pp) mock_multipath__(hwt->vecs, (pp)) #endif From 950d746a29ae74dc072b30047b747ec3fb133c17 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 23:18:07 +0200 Subject: [PATCH 134/145] kpartx: rename macros with leading underscores Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- kpartx/devmapper.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/kpartx/devmapper.c b/kpartx/devmapper.c index bf078388a..d49c6806a 100644 --- a/kpartx/devmapper.c +++ b/kpartx/devmapper.c @@ -13,16 +13,16 @@ #include "devmapper.h" #include "kpartx.h" -#define _UUID_PREFIX "part" -#define UUID_PREFIX _UUID_PREFIX "%d-" -#define _UUID_PREFIX_LEN (sizeof(_UUID_PREFIX) - 1) -#define MAX_PREFIX_LEN (_UUID_PREFIX_LEN + 4) +#define UUID_PREFIX_ "part" +#define UUID_PREFIX UUID_PREFIX_ "%d-" +#define UUID_PREFIX_LEN (sizeof(UUID_PREFIX_) - 1) +#define MAX_PREFIX_LEN (UUID_PREFIX_LEN + 4) #define PARAMS_SIZE 1024 #ifdef LIBDM_API_COOKIE -# define __DM_API_COOKIE_UNUSED__ /* empty */ +# define DM_API_COOKIE_UNUSED__ /* empty */ #else -# define __DM_API_COOKIE_UNUSED__ __attribute__((unused)) +# define DM_API_COOKIE_UNUSED__ __attribute__((unused)) #endif int dm_prereq(char * str, uint32_t x, uint32_t y, uint32_t z) @@ -60,7 +60,7 @@ int dm_prereq(char * str, uint32_t x, uint32_t y, uint32_t z) return r; } -int dm_simplecmd(int task, const char *name, int no_flush, __DM_API_COOKIE_UNUSED__ uint16_t udev_flags) +int dm_simplecmd(int task, const char *name, int no_flush, DM_API_COOKIE_UNUSED__ uint16_t udev_flags) { int r = 0; #ifdef LIBDM_API_COOKIE @@ -496,12 +496,12 @@ dm_compare_uuid(const char *mapuuid, const char *partname) if (!partuuid) return 1; - if (!strncmp(partuuid, _UUID_PREFIX, _UUID_PREFIX_LEN)) { - char *p = partuuid + _UUID_PREFIX_LEN; + if (!strncmp(partuuid, UUID_PREFIX_, UUID_PREFIX_LEN)) { + char *p = partuuid + UUID_PREFIX_LEN; /* skip partition number */ while (isdigit(*p)) p++; - if (p != partuuid + _UUID_PREFIX_LEN && *p == '-' && + if (p != partuuid + UUID_PREFIX_LEN && *p == '-' && !strcmp(mapuuid, p + 1)) r = 0; } From 3757ed625663e5489cc13e0832cecd75724c259b Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 8 Aug 2024 13:48:45 +0200 Subject: [PATCH 135/145] libmpathutil: rename struct _vector to vector_s This isn't strictly required by glibc, but "struct _vector" is now the only public identifier starting with underscore, so let's replace it, too. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathutil/vector.c | 2 +- libmpathutil/vector.h | 6 +++--- libmultipath/alias.c | 2 +- libmultipath/blacklist.c | 14 +++++++------- libmultipath/blacklist.h | 8 ++++---- libmultipath/config.c | 8 ++++---- libmultipath/config.h | 6 +++--- libmultipath/configure.c | 2 +- libmultipath/configure.h | 2 +- libmultipath/discovery.c | 10 +++++----- libmultipath/dm-generic.c | 8 ++++---- libmultipath/dmparser.c | 2 +- libmultipath/dmparser.h | 2 +- libmultipath/foreign.c | 12 ++++++------ libmultipath/foreign.h | 8 ++++---- libmultipath/foreign/nvme.c | 20 ++++++++++---------- libmultipath/generic.h | 8 ++++---- libmultipath/io_err_stat.c | 4 ++-- libmultipath/print.c | 22 +++++++++++----------- libmultipath/print.h | 10 +++++----- libmultipath/structs.c | 12 ++++++------ libmultipath/structs.h | 12 ++++++------ libmultipath/structs_vec.c | 2 +- libmultipath/structs_vec.h | 2 +- libmultipath/valid.c | 10 +++++----- multipathd/cli.c | 4 ++-- multipathd/cli.h | 4 ++-- multipathd/cli_handlers.c | 6 +++--- multipathd/main.c | 4 ++-- tests/valid.c | 4 ++-- 30 files changed, 108 insertions(+), 108 deletions(-) diff --git a/libmpathutil/vector.c b/libmpathutil/vector.c index 7c3ce43d4..5392b3793 100644 --- a/libmpathutil/vector.c +++ b/libmpathutil/vector.c @@ -30,7 +30,7 @@ vector vector_alloc(void) { - vector v = (vector) calloc(1, sizeof (struct _vector)); + vector v = (vector) calloc(1, sizeof (struct vector_s)); return v; } diff --git a/libmpathutil/vector.h b/libmpathutil/vector.h index 2df15051d..8c5617ba1 100644 --- a/libmpathutil/vector.h +++ b/libmpathutil/vector.h @@ -26,11 +26,11 @@ #include /* vector definition */ -struct _vector { +struct vector_s { int allocated; void **slot; }; -typedef struct _vector *vector; +typedef struct vector_s *vector; #define VECTOR_DEFAULT_SIZE 1 #define VECTOR_SIZE(V) ((V) ? ((V)->allocated) / VECTOR_DEFAULT_SIZE : 0) @@ -53,7 +53,7 @@ typedef struct _vector *vector; */ #define vector_convert(new, vec, type, conv) \ ({ \ - const struct _vector *__v = (vec); \ + const struct vector_s *__v = (vec); \ vector __t = (new); \ type *__j; \ int __i; \ diff --git a/libmultipath/alias.c b/libmultipath/alias.c index 5c8ac9350..ea6c7b4fc 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -70,7 +70,7 @@ struct binding { * Perhaps one day we'll implement this more efficiently, thus use * an abstract type. */ -typedef struct _vector Bindings; +typedef struct vector_s Bindings; /* Protect global_bindings */ static pthread_mutex_t bindings_mutex = PTHREAD_MUTEX_INITIALIZER; diff --git a/libmultipath/blacklist.c b/libmultipath/blacklist.c index 75100b207..17e1b54a3 100644 --- a/libmultipath/blacklist.c +++ b/libmultipath/blacklist.c @@ -141,7 +141,7 @@ int set_ble_device(vector blist, const char *vendor, const char *product, int or } static int -match_reglist (const struct _vector *blist, const char *str) +match_reglist (const struct vector_s *blist, const char *str) { int i; struct blentry * ble; @@ -154,7 +154,7 @@ match_reglist (const struct _vector *blist, const char *str) } static int -match_reglist_device (const struct _vector *blist, const char *vendor, +match_reglist_device (const struct vector_s *blist, const char *vendor, const char * product) { int i; @@ -175,7 +175,7 @@ match_reglist_device (const struct _vector *blist, const char *vendor, } static int -find_blacklist_device (const struct _vector *blist, const char *vendor, +find_blacklist_device (const struct vector_s *blist, const char *vendor, const char *product) { int i; @@ -316,7 +316,7 @@ log_filter (const char *dev, const char *vendor, const char *product, } int -filter_device (const struct _vector *blist, const struct _vector *elist, +filter_device (const struct vector_s *blist, const struct vector_s *elist, const char *vendor, const char * product, const char *dev) { int r = MATCH_NOTHING; @@ -333,7 +333,7 @@ filter_device (const struct _vector *blist, const struct _vector *elist, } int -filter_devnode (const struct _vector *blist, const struct _vector *elist, +filter_devnode (const struct vector_s *blist, const struct vector_s *elist, const char *dev) { int r = MATCH_NOTHING; @@ -350,7 +350,7 @@ filter_devnode (const struct _vector *blist, const struct _vector *elist, } int -filter_wwid (const struct _vector *blist, const struct _vector *elist, +filter_wwid (const struct vector_s *blist, const struct vector_s *elist, const char *wwid, const char *dev) { int r = MATCH_NOTHING; @@ -367,7 +367,7 @@ filter_wwid (const struct _vector *blist, const struct _vector *elist, } int -filter_protocol(const struct _vector *blist, const struct _vector *elist, +filter_protocol(const struct vector_s *blist, const struct vector_s *elist, const struct path *pp) { STRBUF_ON_STACK(buf); diff --git a/libmultipath/blacklist.h b/libmultipath/blacklist.h index 244c59d93..f32b58299 100644 --- a/libmultipath/blacklist.h +++ b/libmultipath/blacklist.h @@ -36,16 +36,16 @@ struct blentry_device { int setup_default_blist (struct config *); int alloc_ble_device (vector); -int filter_devnode (const struct _vector *, const struct _vector *, +int filter_devnode (const struct vector_s *, const struct vector_s *, const char *); -int filter_wwid (const struct _vector *, const struct _vector *, +int filter_wwid (const struct vector_s *, const struct vector_s *, const char *, const char *); -int filter_device (const struct _vector *, const struct _vector *, +int filter_device (const struct vector_s *, const struct vector_s *, const char *, const char *, const char *); int filter_path (const struct config *, const struct path *); int filter_property(const struct config *, struct udev_device *, int, const char*); -int filter_protocol(const struct _vector *, const struct _vector *, +int filter_protocol(const struct vector_s *, const struct vector_s *, const struct path *); int store_ble (vector, const char *, int); int set_ble_device (vector, const char *, const char *, int); diff --git a/libmultipath/config.c b/libmultipath/config.c index b742fb4e0..2d2b50742 100644 --- a/libmultipath/config.c +++ b/libmultipath/config.c @@ -114,7 +114,7 @@ hwe_strmatch (const struct hwentry *hwe1, const struct hwentry *hwe2) } static struct hwentry * -find_hwe_strmatch (const struct _vector *hwtable, const struct hwentry *hwe) +find_hwe_strmatch (const struct vector_s *hwtable, const struct hwentry *hwe) { int i; struct hwentry *tmp, *ret = NULL; @@ -179,7 +179,7 @@ static void _log_match(const char *fn, const struct hwentry *h, #define log_match(h, v, p, r) _log_match(__func__, (h), (v), (p), (r)) int -find_hwe (const struct _vector *hwtable, +find_hwe (const struct vector_s *hwtable, const char * vendor, const char * product, const char * revision, vector result) { @@ -222,7 +222,7 @@ struct mpentry *find_mpe(vector mptable, char *wwid) return NULL; } -const char *get_mpe_wwid(const struct _vector *mptable, const char *alias) +const char *get_mpe_wwid(const struct vector_s *mptable, const char *alias) { int i; struct mpentry * mpe; @@ -1089,7 +1089,7 @@ int init_config__ (const char *file, struct config *conf) const char *get_uid_attribute_by_attrs(const struct config *conf, const char *path_dev) { - const struct _vector *uid_attrs = &conf->uid_attrs; + const struct vector_s *uid_attrs = &conf->uid_attrs; int j; char *att, *col; diff --git a/libmultipath/config.h b/libmultipath/config.h index 181b78ab7..94cdf252f 100644 --- a/libmultipath/config.h +++ b/libmultipath/config.h @@ -206,7 +206,7 @@ struct config { int auto_resize; char * selector; - struct _vector uid_attrs; + struct vector_s uid_attrs; char * uid_attribute; char * features; char * hwhandler; @@ -286,11 +286,11 @@ int libmultipath_init(void); */ void libmultipath_exit(void); -int find_hwe (const struct _vector *hwtable, +int find_hwe (const struct vector_s *hwtable, const char * vendor, const char * product, const char *revision, vector result); struct mpentry * find_mpe (vector mptable, char * wwid); -const char *get_mpe_wwid (const struct _vector *mptable, const char *alias); +const char *get_mpe_wwid (const struct vector_s *mptable, const char *alias); struct hwentry * alloc_hwe (void); struct mpentry * alloc_mpe (void); diff --git a/libmultipath/configure.c b/libmultipath/configure.c index 34158e31b..a72579812 100644 --- a/libmultipath/configure.c +++ b/libmultipath/configure.c @@ -630,7 +630,7 @@ select_reload_action(struct multipath *mpp, const char *reason) condlog(3, "%s: set ACT_RELOAD (%s)", mpp->alias, reason); } -void select_action (struct multipath *mpp, const struct _vector *curmp, +void select_action (struct multipath *mpp, const struct vector_s *curmp, int force_reload) { struct multipath * cmpp; diff --git a/libmultipath/configure.h b/libmultipath/configure.h index ca34442eb..f98a3b21e 100644 --- a/libmultipath/configure.h +++ b/libmultipath/configure.h @@ -53,7 +53,7 @@ enum { struct vectors; int setup_map (struct multipath * mpp, char **params, struct vectors *vecs); -void select_action (struct multipath *mpp, const struct _vector *curmp, +void select_action (struct multipath *mpp, const struct vector_s *curmp, int force_reload); int domap (struct multipath * mpp, char * params, int is_daemon); int reinstate_paths (struct multipath *mpp); diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index f130a5c90..e94705bf2 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -1523,7 +1523,7 @@ get_vpd_sgio (int fd, int pg, int vend_id, char * str, int maxlen) } static int -scsi_sysfs_pathinfo (struct path *pp, const struct _vector *hwtable) +scsi_sysfs_pathinfo (struct path *pp, const struct vector_s *hwtable) { struct udev_device *parent; const char *attr_path = NULL; @@ -1594,7 +1594,7 @@ scsi_sysfs_pathinfo (struct path *pp, const struct _vector *hwtable) } static int -nvme_sysfs_pathinfo (struct path *pp, const struct _vector *hwtable) +nvme_sysfs_pathinfo (struct path *pp, const struct vector_s *hwtable) { struct udev_device *parent; const char *attr_path = NULL; @@ -1653,7 +1653,7 @@ nvme_sysfs_pathinfo (struct path *pp, const struct _vector *hwtable) } static int -ccw_sysfs_pathinfo (struct path *pp, const struct _vector *hwtable) +ccw_sysfs_pathinfo (struct path *pp, const struct vector_s *hwtable) { struct udev_device *parent; char attr_buff[NAME_SIZE]; @@ -1714,7 +1714,7 @@ ccw_sysfs_pathinfo (struct path *pp, const struct _vector *hwtable) } static int -cciss_sysfs_pathinfo (struct path *pp, const struct _vector *hwtable) +cciss_sysfs_pathinfo (struct path *pp, const struct vector_s *hwtable) { const char * attr_path = NULL; struct udev_device *parent; @@ -1872,7 +1872,7 @@ path_offline (struct path * pp) } static int -sysfs_pathinfo(struct path *pp, const struct _vector *hwtable) +sysfs_pathinfo(struct path *pp, const struct vector_s *hwtable) { int r = common_sysfs_pathinfo(pp); diff --git a/libmultipath/dm-generic.c b/libmultipath/dm-generic.c index 1b42fa0bc..e49f9bbf5 100644 --- a/libmultipath/dm-generic.c +++ b/libmultipath/dm-generic.c @@ -24,7 +24,7 @@ #include "config.h" #include "print.h" -static const struct _vector* +static const struct vector_s* dm_mp_get_pgs(const struct gen_multipath *gmp) { return vector_convert(NULL, gen_multipath_to_dm(gmp)->pg, @@ -33,12 +33,12 @@ dm_mp_get_pgs(const struct gen_multipath *gmp) static void dm_mp_rel_pgs(__attribute__((unused)) const struct gen_multipath *gmp, - const struct _vector* v) + const struct vector_s* v) { vector_free_const(v); } -static const struct _vector* +static const struct vector_s* dm_pg_get_paths(const struct gen_pathgroup *gpg) { return vector_convert(NULL, gen_pathgroup_to_dm(gpg)->paths, @@ -47,7 +47,7 @@ dm_pg_get_paths(const struct gen_pathgroup *gpg) static void dm_mp_rel_paths(__attribute__((unused)) const struct gen_pathgroup *gpg, - const struct _vector* v) + const struct vector_s* v) { vector_free_const(v); } diff --git a/libmultipath/dmparser.c b/libmultipath/dmparser.c index 3d85e6eea..1d0506df8 100644 --- a/libmultipath/dmparser.c +++ b/libmultipath/dmparser.c @@ -117,7 +117,7 @@ int assemble_map(struct multipath *mp, char **params) * Call update_pathvec_from_dm() after this function to make sure * all data structures are in a sane state. */ -int disassemble_map(const struct _vector *pathvec, +int disassemble_map(const struct vector_s *pathvec, const char *params, struct multipath *mpp) { char * word; diff --git a/libmultipath/dmparser.h b/libmultipath/dmparser.h index 43454c379..181967b82 100644 --- a/libmultipath/dmparser.h +++ b/libmultipath/dmparser.h @@ -2,7 +2,7 @@ #define DMPARSER_H_INCLUDED int assemble_map (struct multipath *, char **); -int disassemble_map (const struct _vector *, const char *, struct multipath *); +int disassemble_map (const struct vector_s *, const char *, struct multipath *); int disassemble_status (const char *, struct multipath *); #endif diff --git a/libmultipath/foreign.c b/libmultipath/foreign.c index d23439e91..28d1b1158 100644 --- a/libmultipath/foreign.c +++ b/libmultipath/foreign.c @@ -451,7 +451,7 @@ void foreign_path_layout(fieldwidth_t *width) pthread_cleanup_push(unlock_foreigns, NULL); vector_foreach_slot(foreigns, fgn, i) { - const struct _vector *vec; + const struct vector_s *vec; fgn->lock(fgn->context); pthread_cleanup_push(fgn->unlock, fgn->context); @@ -482,7 +482,7 @@ void foreign_multipath_layout(fieldwidth_t *width) pthread_cleanup_push(unlock_foreigns, NULL); vector_foreach_slot(foreigns, fgn, i) { - const struct _vector *vec; + const struct vector_s *vec; fgn->lock(fgn->context); pthread_cleanup_push(fgn->unlock, fgn->context); @@ -507,7 +507,7 @@ static int snprint_foreign_topology__(struct strbuf *buf, int verbosity, size_t initial_len = get_strbuf_len(buf); vector_foreach_slot(foreigns, fgn, i) { - const struct _vector *vec; + const struct vector_s *vec; const struct gen_multipath *gm; int j; @@ -561,7 +561,7 @@ void print_foreign_topology(int verbosity) } pthread_cleanup_push(unlock_foreigns, NULL); vector_foreach_slot(foreigns, fgn, i) { - const struct _vector *vec; + const struct vector_s *vec; fgn->lock(fgn->context); pthread_cleanup_push(fgn->unlock, fgn->context); @@ -590,7 +590,7 @@ int snprint_foreign_paths(struct strbuf *buf, const char *style, pthread_cleanup_push(unlock_foreigns, NULL); vector_foreach_slot(foreigns, fgn, i) { - const struct _vector *vec; + const struct vector_s *vec; const struct gen_path *gp; int j, ret = 0; @@ -630,7 +630,7 @@ int snprint_foreign_multipaths(struct strbuf *buf, const char *style, pthread_cleanup_push(unlock_foreigns, NULL); vector_foreach_slot(foreigns, fgn, i) { - const struct _vector *vec; + const struct vector_s *vec; const struct gen_multipath *gm; int j, ret = 0; diff --git a/libmultipath/foreign.h b/libmultipath/foreign.h index 809824dd6..485fb2d85 100644 --- a/libmultipath/foreign.h +++ b/libmultipath/foreign.h @@ -155,7 +155,7 @@ struct foreign { * @returns a vector of "struct gen_multipath*" with the map devices * belonging to this library (see generic.h). */ - const struct _vector* (*get_multipaths)(const struct context *); + const struct vector_s* (*get_multipaths)(const struct context *); /** * method: release_multipaths(context, mpvec) @@ -165,7 +165,7 @@ struct foreign { * @param[in] mpvec the vector allocated with get_multipaths() */ void (*release_multipaths)(const struct context *ctx, - const struct _vector* mpvec); + const struct vector_s* mpvec); /** * method: get_paths @@ -176,7 +176,7 @@ struct foreign { * @returns a vector of "struct gen_path*" with the path devices * belonging to this library (see generic.h) */ - const struct _vector* (*get_paths)(const struct context *); + const struct vector_s* (*get_paths)(const struct context *); /** * release data structures obtained with get_multipaths (if any) @@ -185,7 +185,7 @@ struct foreign { * @param[in] ppvec the vector allocated with get_paths() */ void (*release_paths)(const struct context *ctx, - const struct _vector* ppvec); + const struct vector_s* ppvec); void *handle; struct context *context; diff --git a/libmultipath/foreign/nvme.c b/libmultipath/foreign/nvme.c index 40b88f7ba..0b7f4eabd 100644 --- a/libmultipath/foreign/nvme.c +++ b/libmultipath/foreign/nvme.c @@ -45,7 +45,7 @@ const char *THIS; struct nvme_map; struct nvme_pathgroup { struct gen_pathgroup gen; - struct _vector pathvec; + struct vector_s pathvec; }; struct nvme_path { @@ -66,7 +66,7 @@ struct nvme_map { struct udev_device *udev; struct udev_device *subsys; dev_t devt; - struct _vector pgvec; + struct vector_s pgvec; int nr_live; int ana_supported; }; @@ -114,7 +114,7 @@ static void cleanup_nvme_map(struct nvme_map *map) free(map); } -static const struct _vector* +static const struct vector_s* nvme_mp_get_pgs(const struct gen_multipath *gmp) { const struct nvme_map *nvme = const_gen_mp_to_nvme(gmp); @@ -124,7 +124,7 @@ nvme_mp_get_pgs(const struct gen_multipath *gmp) { static void nvme_mp_rel_pgs(__attribute__((unused)) const struct gen_multipath *gmp, - __attribute__((unused)) const struct _vector *v) + __attribute__((unused)) const struct vector_s *v) { /* empty */ } @@ -201,7 +201,7 @@ static int snprint_nvme_map(const struct gen_multipath *gmp, return append_strbuf_str(buff, N_A); } -static const struct _vector* +static const struct vector_s* nvme_pg_get_paths(const struct gen_pathgroup *gpg) { const struct nvme_pathgroup *gp = const_gen_pg_to_nvme(gpg); @@ -211,7 +211,7 @@ nvme_pg_get_paths(const struct gen_pathgroup *gpg) { static void nvme_pg_rel_paths(__attribute__((unused)) const struct gen_pathgroup *gpg, - __attribute__((unused)) const struct _vector *v) + __attribute__((unused)) const struct vector_s *v) { /* empty */ } @@ -916,14 +916,14 @@ void check(struct context *ctx) /* * It's safe to pass our internal pointer, this is only used under the lock. */ -const struct _vector *get_multipaths(const struct context *ctx) +const struct vector_s *get_multipaths(const struct context *ctx) { condlog(5, "%s called for \"%s\"", __func__, THIS); return ctx->mpvec; } void release_multipaths(__attribute__((unused)) const struct context *ctx, - __attribute__((unused)) const struct _vector *mpvec) + __attribute__((unused)) const struct vector_s *mpvec) { condlog(5, "%s called for \"%s\"", __func__, THIS); /* NOP */ @@ -932,7 +932,7 @@ void release_multipaths(__attribute__((unused)) const struct context *ctx, /* * It's safe to pass our internal pointer, this is only used under the lock. */ -const struct _vector * get_paths(const struct context *ctx) +const struct vector_s * get_paths(const struct context *ctx) { vector paths = NULL; const struct gen_multipath *gm; @@ -948,7 +948,7 @@ const struct _vector * get_paths(const struct context *ctx) } void release_paths(__attribute__((unused)) const struct context *ctx, - const struct _vector *mpvec) + const struct vector_s *mpvec) { condlog(5, "%s called for \"%s\"", __func__, THIS); vector_free_const(mpvec); diff --git a/libmultipath/generic.h b/libmultipath/generic.h index c8fe31cb6..2e4673bea 100644 --- a/libmultipath/generic.h +++ b/libmultipath/generic.h @@ -43,7 +43,7 @@ struct gen_multipath_ops { * @param gmp: generic multipath object to act on * @returns a vector of const struct gen_pathgroup* */ - const struct _vector* (*get_pathgroups)(const struct gen_multipath*); + const struct vector_s* (*get_pathgroups)(const struct gen_multipath*); /** * method: rel_pathgroups(gmp, v) * free data allocated by get_pathgroups(), if any @@ -51,7 +51,7 @@ struct gen_multipath_ops { * @param v the value returned by get_pathgroups() */ void (*rel_pathgroups)(const struct gen_multipath*, - const struct _vector*); + const struct vector_s*); /** * method: snprint(gmp, buf, len, wildcard) * prints the property of the multipath map matching @@ -89,14 +89,14 @@ struct gen_pathgroup_ops { * @param gpg: generic pathgroup object to act on * @returns a vector of const struct gen_path* */ - const struct _vector* (*get_paths)(const struct gen_pathgroup*); + const struct vector_s* (*get_paths)(const struct gen_pathgroup*); /** * method: rel_paths(gpg, v) * free data allocated by get_paths(), if any * @param gmp: generic pathgroup object to act on * @param v the value returned by get_paths() */ - void (*rel_paths)(const struct gen_pathgroup*, const struct _vector*); + void (*rel_paths)(const struct gen_pathgroup*, const struct vector_s*); /** * Method snprint() * see gen_multipath_ops->snprint() above diff --git a/libmultipath/io_err_stat.c b/libmultipath/io_err_stat.c index 1c5944517..4996c0b04 100644 --- a/libmultipath/io_err_stat.c +++ b/libmultipath/io_err_stat.c @@ -619,9 +619,9 @@ static void process_async_ios_event(int timeout_nsecs, char *dev) static void service_paths(void) { - struct _vector _pathvec = { .allocated = 0 }; + struct vector_s _pathvec = { .allocated = 0 }; /* avoid gcc warnings that &_pathvec will never be NULL in vector ops */ - struct _vector * const tmp_pathvec = &_pathvec; + struct vector_s * const tmp_pathvec = &_pathvec; struct io_err_stat_path *pp; int i; diff --git a/libmultipath/print.c b/libmultipath/print.c index 190c82396..e536c5c09 100644 --- a/libmultipath/print.c +++ b/libmultipath/print.c @@ -946,7 +946,7 @@ reset_width(fieldwidth_t *width, enum layout_reset reset, const char *header) } } -void get_path_layout__ (const struct _vector *gpvec, enum layout_reset reset, +void get_path_layout__ (const struct vector_s *gpvec, enum layout_reset reset, fieldwidth_t *width) { unsigned int i, j; @@ -987,7 +987,7 @@ void get_multipath_layout (vector mpvec, int header, fieldwidth_t *width) { } void -get_multipath_layout__ (const struct _vector *gmvec, enum layout_reset reset, +get_multipath_layout__ (const struct vector_s *gmvec, enum layout_reset reset, fieldwidth_t *width) { unsigned int i, j; @@ -1230,7 +1230,7 @@ void print_multipath_topology__(const struct gen_multipath *gmp, int verbosity) STRBUF_ON_STACK(buff); fieldwidth_t *p_width __attribute__((cleanup(cleanup_ucharp))) = NULL; const struct gen_pathgroup *gpg; - const struct _vector *pgvec, *pathvec; + const struct vector_s *pgvec, *pathvec; int j; p_width = alloc_path_layout(); @@ -1271,7 +1271,7 @@ int snprint_multipath_topology__(const struct gen_multipath *gmp, const fieldwidth_t *p_width) { int j, i, rc; - const struct _vector *pgvec; + const struct vector_s *pgvec; const struct gen_pathgroup *gpg; STRBUF_ON_STACK(style); size_t initial_len = get_strbuf_len(buff); @@ -1304,7 +1304,7 @@ int snprint_multipath_topology__(const struct gen_multipath *gmp, goto out; vector_foreach_slot (pgvec, gpg, j) { - const struct _vector *pathvec; + const struct vector_s *pathvec; struct gen_path *gp; bool last_group = j + 1 == VECTOR_SIZE(pgvec); @@ -1482,7 +1482,7 @@ snprint_pcentry (const struct config *conf, struct strbuf *buff, static int snprint_pctable (const struct config *conf, struct strbuf *buff, - const struct _vector *pctable) + const struct vector_s *pctable) { int i, rc; struct pcentry *pce; @@ -1526,7 +1526,7 @@ snprint_hwentry (const struct config *conf, } static int snprint_hwtable(const struct config *conf, struct strbuf *buff, - const struct _vector *hwtable) + const struct vector_s *hwtable) { int i, rc; struct hwentry * hwe; @@ -1552,7 +1552,7 @@ static int snprint_hwtable(const struct config *conf, struct strbuf *buff, static int snprint_mpentry (const struct config *conf, struct strbuf *buff, - const struct mpentry * mpe, const struct _vector *mpvec) + const struct mpentry * mpe, const struct vector_s *mpvec) { int i, rc; struct keyword * kw; @@ -1587,7 +1587,7 @@ snprint_mpentry (const struct config *conf, struct strbuf *buff, } static int snprint_mptable(const struct config *conf, struct strbuf *buff, - const struct _vector *mpvec) + const struct vector_s *mpvec) { int i, rc; struct mpentry * mpe; @@ -1909,7 +1909,7 @@ static int snprint_blacklist_except(const struct config *conf, } int snprint_config__(const struct config *conf, struct strbuf *buff, - const struct _vector *hwtable, const struct _vector *mpvec) + const struct vector_s *hwtable, const struct vector_s *mpvec) { int rc; @@ -1930,7 +1930,7 @@ int snprint_config__(const struct config *conf, struct strbuf *buff, } char *snprint_config(const struct config *conf, int *len, - const struct _vector *hwtable, const struct _vector *mpvec) + const struct vector_s *hwtable, const struct vector_s *mpvec) { STRBUF_ON_STACK(buff); char *reply; diff --git a/libmultipath/print.h b/libmultipath/print.h index 9c2aea47c..489f1e7a5 100644 --- a/libmultipath/print.h +++ b/libmultipath/print.h @@ -17,11 +17,11 @@ enum layout_reset { /* fieldwidth_t is defined in generic.h */ fieldwidth_t *alloc_path_layout(void); -void get_path_layout__ (const struct _vector *gpvec, enum layout_reset, +void get_path_layout__ (const struct vector_s *gpvec, enum layout_reset, fieldwidth_t *width); void get_path_layout (vector pathvec, int header, fieldwidth_t *width); fieldwidth_t *alloc_multipath_layout(void); -void get_multipath_layout__ (const struct _vector *gmvec, enum layout_reset, +void get_multipath_layout__ (const struct vector_s *gmvec, enum layout_reset, fieldwidth_t *width); void get_multipath_layout (vector mpvec, int header, fieldwidth_t *width); int snprint_path_header(struct strbuf *, const char *, const fieldwidth_t *); @@ -41,10 +41,10 @@ int snprint_multipath_topology__ (const struct gen_multipath *, struct strbuf *, snprint_multipath_topology__ (dm_multipath_to_gen(mpp), buf, v, w) int snprint_multipath_topology_json(struct strbuf *, const struct vectors *vecs); int snprint_config__(const struct config *conf, struct strbuf *buff, - const struct _vector *hwtable, const struct _vector *mpvec); + const struct vector_s *hwtable, const struct vector_s *mpvec); char *snprint_config(const struct config *conf, int *len, - const struct _vector *hwtable, - const struct _vector *mpvec); + const struct vector_s *hwtable, + const struct vector_s *mpvec); int snprint_multipath_map_json(struct strbuf *, const struct multipath *mpp); int snprint_blacklist_report(struct config *, struct strbuf *); int snprint_wildcards(struct strbuf *); diff --git a/libmultipath/structs.c b/libmultipath/structs.c index 232b42304..61c8f32c3 100644 --- a/libmultipath/structs.c +++ b/libmultipath/structs.c @@ -433,7 +433,7 @@ store_adaptergroup(vector adapters, struct adapter_group * agp) } struct multipath * -find_mp_by_minor (const struct _vector *mpvec, unsigned int minor) +find_mp_by_minor (const struct vector_s *mpvec, unsigned int minor) { int i; struct multipath * mpp; @@ -452,7 +452,7 @@ find_mp_by_minor (const struct _vector *mpvec, unsigned int minor) } struct multipath * -find_mp_by_wwid (const struct _vector *mpvec, const char * wwid) +find_mp_by_wwid (const struct vector_s *mpvec, const char * wwid) { int i; struct multipath * mpp; @@ -468,7 +468,7 @@ find_mp_by_wwid (const struct _vector *mpvec, const char * wwid) } struct multipath * -find_mp_by_alias (const struct _vector *mpvec, const char * alias) +find_mp_by_alias (const struct vector_s *mpvec, const char * alias) { int i; size_t len; @@ -491,7 +491,7 @@ find_mp_by_alias (const struct _vector *mpvec, const char * alias) } struct multipath * -find_mp_by_str (const struct _vector *mpvec, const char * str) +find_mp_by_str (const struct vector_s *mpvec, const char * str) { int minor; char dummy; @@ -510,7 +510,7 @@ find_mp_by_str (const struct _vector *mpvec, const char * str) } struct path * -find_path_by_dev (const struct _vector *pathvec, const char *dev) +find_path_by_dev (const struct vector_s *pathvec, const char *dev) { int i; struct path * pp; @@ -527,7 +527,7 @@ find_path_by_dev (const struct _vector *pathvec, const char *dev) } struct path * -find_path_by_devt (const struct _vector *pathvec, const char * dev_t) +find_path_by_devt (const struct vector_s *pathvec, const char * dev_t) { int i; struct path * pp; diff --git a/libmultipath/structs.h b/libmultipath/structs.h index 56fb74ba6..074faca6f 100644 --- a/libmultipath/structs.h +++ b/libmultipath/structs.h @@ -564,14 +564,14 @@ int store_hostgroup(vector hostgroupvec, struct host_group *hgp); int store_path (vector pathvec, struct path * pp); int add_pathgroup(struct multipath*, struct pathgroup *); -struct multipath * find_mp_by_alias (const struct _vector *mp, const char *alias); -struct multipath * find_mp_by_wwid (const struct _vector *mp, const char *wwid); -struct multipath * find_mp_by_str (const struct _vector *mp, const char *wwid); -struct multipath * find_mp_by_minor (const struct _vector *mp, +struct multipath * find_mp_by_alias (const struct vector_s *mp, const char *alias); +struct multipath * find_mp_by_wwid (const struct vector_s *mp, const char *wwid); +struct multipath * find_mp_by_str (const struct vector_s *mp, const char *wwid); +struct multipath * find_mp_by_minor (const struct vector_s *mp, unsigned int minor); -struct path * find_path_by_devt (const struct _vector *pathvec, const char *devt); -struct path * find_path_by_dev (const struct _vector *pathvec, const char *dev); +struct path * find_path_by_devt (const struct vector_s *pathvec, const char *devt); +struct path * find_path_by_dev (const struct vector_s *pathvec, const char *dev); struct path * first_path (const struct multipath *mpp); struct path *mp_find_path_by_devt(const struct multipath *mpp, const char *devt); diff --git a/libmultipath/structs_vec.c b/libmultipath/structs_vec.c index 50b17e665..5df495b3e 100644 --- a/libmultipath/structs_vec.c +++ b/libmultipath/structs_vec.c @@ -891,7 +891,7 @@ void update_queue_mode_add_path(struct multipath *mpp) condlog(2, "%s: remaining active paths: %d", mpp->alias, active); } -vector get_used_hwes(const struct _vector *pathvec) +vector get_used_hwes(const struct vector_s *pathvec) { int i, j; struct path *pp; diff --git a/libmultipath/structs_vec.h b/libmultipath/structs_vec.h index 541327da4..03bf8ee16 100644 --- a/libmultipath/structs_vec.h +++ b/libmultipath/structs_vec.h @@ -37,6 +37,6 @@ int update_multipath_table__ (struct multipath *mpp, vector pathvec, int flags, const char *params, const char *status); int update_multipath_table (struct multipath *mpp, vector pathvec, int flags); int update_multipath_status (struct multipath *mpp); -vector get_used_hwes(const struct _vector *pathvec); +vector get_used_hwes(const struct vector_s *pathvec); #endif /* STRUCTS_VEC_H_INCLUDED */ diff --git a/libmultipath/valid.c b/libmultipath/valid.c index 5df9b02f9..f23ee6b27 100644 --- a/libmultipath/valid.c +++ b/libmultipath/valid.c @@ -120,7 +120,7 @@ static int check_holders(const char *syspath) return sr.n; } -static int check_all_holders(const struct _vector *parts) +static int check_all_holders(const struct vector_s *parts) { char syspath[PATH_MAX]; const char *sysname; @@ -168,7 +168,7 @@ static void cleanup_cache(void *arg) * check if any of the partitions in the vector is referenced in the table. * Note that mnt_table_find_srcpath() also resolves mounts by symlinks. */ -static int check_mnt_table(const struct _vector *parts, +static int check_mnt_table(const struct vector_s *parts, struct libmnt_table *tbl, const char *table_name) { @@ -188,7 +188,7 @@ static int check_mnt_table(const struct _vector *parts, return 0; } -static int check_mountinfo(const struct _vector *parts) +static int check_mountinfo(const struct vector_s *parts) { static const char mountinfo[] = "/proc/self/mountinfo"; struct libmnt_table *tbl; @@ -223,7 +223,7 @@ static int check_mountinfo(const struct _vector *parts) } #ifdef LIBMOUNT_SUPPORTS_SWAP -static int check_swaps(const struct _vector *parts) +static int check_swaps(const struct vector_s *parts) { struct libmnt_table *tbl; struct libmnt_cache *cache; @@ -248,7 +248,7 @@ static int check_swaps(const struct _vector *parts) return used; } #else -static int check_swaps(const struct _vector *parts __attribute__((unused))) +static int check_swaps(const struct vector_s *parts __attribute__((unused))) { return 0; } diff --git a/multipathd/cli.c b/multipathd/cli.c index 139a4c494..34588290d 100644 --- a/multipathd/cli.c +++ b/multipathd/cli.c @@ -335,7 +335,7 @@ int get_cmdvec (char *cmd, vector *v, bool allow_incomplete) return r; } -uint32_t fingerprint(const struct _vector *vec) +uint32_t fingerprint(const struct vector_s *vec) { int i; uint32_t fp = 0; @@ -352,7 +352,7 @@ uint32_t fingerprint(const struct _vector *vec) return fp; } -struct handler *find_handler_for_cmdvec(const struct _vector *v) +struct handler *find_handler_for_cmdvec(const struct vector_s *v) { return find_handler(fingerprint(v)); } diff --git a/multipathd/cli.h b/multipathd/cli.h index dd26a2c21..9fa501451 100644 --- a/multipathd/cli.h +++ b/multipathd/cli.h @@ -142,7 +142,7 @@ int set_handler_callback__ (uint32_t fp, cli_handler *fn, bool locked); #define set_unlocked_handler_callback(fp, fn) set_handler_callback__(fp, fn, false) int get_cmdvec (char *cmd, vector *v, bool allow_incomplete); -struct handler *find_handler_for_cmdvec(const struct _vector *v); +struct handler *find_handler_for_cmdvec(const struct vector_s *v); void genhelp_handler (const char *cmd, int error, struct strbuf *reply); int load_keys (void); @@ -152,7 +152,7 @@ void free_keys (vector vec); void free_handlers (void); int cli_init (void); void cli_exit(void); -uint32_t fingerprint(const struct _vector *vec); +uint32_t fingerprint(const struct vector_s *vec); vector get_keys(void); vector get_handlers(void); struct key *find_key (const char * str); diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c index 2efe23fcb..42603544a 100644 --- a/multipathd/cli_handlers.c +++ b/multipathd/cli_handlers.c @@ -33,7 +33,7 @@ #include "cli_handlers.h" static struct path * -find_path_by_str(const struct _vector *pathvec, const char *str, +find_path_by_str(const struct vector_s *pathvec, const char *str, const char *action_str) { struct path *pp; @@ -157,8 +157,8 @@ show_map_json (struct strbuf *reply, struct multipath * mpp, } static int -show_config (struct strbuf *reply, const struct _vector *hwtable, - const struct _vector *mpvec) +show_config (struct strbuf *reply, const struct vector_s *hwtable, + const struct vector_s *mpvec) { struct config *conf; int rc; diff --git a/multipathd/main.c b/multipathd/main.c index 229b516a0..1b7fd04f1 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -3140,8 +3140,8 @@ void rcu_free_config(struct rcu_head *head) free_config(conf); } -static bool reconfigure_check_uid_attrs(const struct _vector *old_attrs, - const struct _vector *new_attrs) +static bool reconfigure_check_uid_attrs(const struct vector_s *old_attrs, + const struct vector_s *new_attrs) { int i; char *old; diff --git a/tests/valid.c b/tests/valid.c index cb5673446..c5a1eac02 100644 --- a/tests/valid.c +++ b/tests/valid.c @@ -106,14 +106,14 @@ const char *__wrap_udev_device_get_sysname(struct udev_device *udev_device) } /* called from pathinfo() */ -int __wrap_filter_devnode(struct config *conf, const struct _vector *elist, +int __wrap_filter_devnode(struct config *conf, const struct vector_s *elist, const char *vendor, const char * product, const char *dev) { return mock_type(int); } /* called from pathinfo() */ -int __wrap_filter_device(const struct _vector *blist, const struct _vector *elist, +int __wrap_filter_device(const struct vector_s *blist, const struct vector_s *elist, const char *vendor, const char * product, const char *dev) { return mock_type(int); From 563ad90383273e328b8c5bd423b85c948f694177 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 7 Aug 2024 22:47:18 +0200 Subject: [PATCH 136/145] libmultipath: don't define __user This may have been necessary in the old days, but it isn't necessary any more now. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/prioritizers/alua_rtpg.c | 1 - libmultipath/sg_include.h | 1 - 2 files changed, 2 deletions(-) diff --git a/libmultipath/prioritizers/alua_rtpg.c b/libmultipath/prioritizers/alua_rtpg.c index dd2224c42..e53f44751 100644 --- a/libmultipath/prioritizers/alua_rtpg.c +++ b/libmultipath/prioritizers/alua_rtpg.c @@ -21,7 +21,6 @@ #include #include -#define __user #include #include "../structs.h" diff --git a/libmultipath/sg_include.h b/libmultipath/sg_include.h index 43bff2d5a..443819b28 100644 --- a/libmultipath/sg_include.h +++ b/libmultipath/sg_include.h @@ -1,6 +1,5 @@ #ifndef SG_INCLUDE_H_INCLUDED #define SG_INCLUDE_H_INCLUDED -#define __user #include #ifndef DID_OK From 9794e12d3dc73eb781a358f6d582ac83f84d563f Mon Sep 17 00:00:00 2001 From: Xose Vazquez Perez Date: Mon, 12 Aug 2024 21:13:38 +0200 Subject: [PATCH 137/145] multipath-tools: add more info about the tur checker to the man page Hardware dependent, and only for SCSI devices. Cc: Martin Wilck Cc: Benjamin Marzinski Cc: Christophe Varoqui Cc: DM-DEVEL ML Signed-off-by: Xose Vazquez Perez Reviewed-by: Martin Wilck --- multipath/multipath.conf.5.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/multipath/multipath.conf.5.in b/multipath/multipath.conf.5.in index e0794bacb..677b0823f 100644 --- a/multipath/multipath.conf.5.in +++ b/multipath/multipath.conf.5.in @@ -526,7 +526,8 @@ second, until \fIchecker_timeout\fR seconds have elapsed. Possible values are: deprecated, please use \fItur\fR or \fIdirectio\fR instead. .TP .I tur -Issue a \fITEST UNIT READY\fR command to the device. +(Hardware-dependent) +Issue a \fITEST UNIT READY\fR command to a SCSI device. .TP .I emc_clariion (Hardware-dependent) From 0802e9dfd27e2333615e8068d7fa55a614bef92e Mon Sep 17 00:00:00 2001 From: Kou Wenqi Date: Tue, 13 Aug 2024 10:12:36 +0800 Subject: [PATCH 138/145] multipath: display the correct configuration when dumping config "multipath -t" and "multipath -T" might show the wrong multipathd configuration items "retrigger_tries" and "force_sync". Make sure they don't. Signed-off-by: Kou Wenqi Reviewed-by: Martin Wilck --- multipath/main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/multipath/main.c b/multipath/main.c index 4b19d2ea8..28e3a0555 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -853,8 +853,6 @@ main (int argc, char *argv[]) if (atexit(uninit_config)) condlog(1, "failed to register cleanup handler for config: %m"); conf = get_multipath_config(); - conf->retrigger_tries = 0; - conf->force_sync = 1; if (atexit(cleanup_vecs)) condlog(1, "failed to register cleanup handler for vecs: %m"); if (atexit(cleanup_bindings)) @@ -1001,6 +999,11 @@ main (int argc, char *argv[]) libmp_udev_set_sync_support(1); + if (cmd != CMD_DUMP_CONFIG) { + conf->retrigger_tries = 0; + conf->force_sync = 1; + } + if ((cmd == CMD_LIST_SHORT || cmd == CMD_LIST_LONG) && enable_foreign) conf->enable_foreign = strdup(""); From 31861b7009d3aebf51c97615e29212bc6ece47c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=B0=D0=B1=D0=B8=D1=87=20=D0=92=D0=BB=D0=B0=D0=B4?= =?UTF-8?q?=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9F=D0=B0=D0=B2=D0=BB=D0=BE=D0=B2?= =?UTF-8?q?=D0=B8=D1=87?= Date: Tue, 13 Aug 2024 12:49:05 +0300 Subject: [PATCH 139/145] libmpathutil: removed duplicate check for subsection devices Reviewed-by: Martin Wilck --- libmpathutil/parser.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libmpathutil/parser.c b/libmpathutil/parser.c index 217a87797..b1db433f4 100644 --- a/libmpathutil/parser.c +++ b/libmpathutil/parser.c @@ -406,8 +406,7 @@ int is_sublevel_keyword(char *str) { return (strcmp(str, "defaults") == 0 || strcmp(str, "blacklist") == 0 || - strcmp(str, "blacklist_exceptions") == 0 || - strcmp(str, "devices") == 0 || strcmp(str, "devices") == 0 || + strcmp(str, "blacklist_exceptions") == 0 || strcmp(str, "devices") == 0 || strcmp(str, "device") == 0 || strcmp(str, "multipaths") == 0 || strcmp(str, "multipath") == 0); } From a583dcd1fced0555168cf21a0c93fcbb85ef067b Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Mon, 12 Aug 2024 21:46:33 +0200 Subject: [PATCH 140/145] libmpathcmd: reinstate ABI 1.0.0 __mpath_connect() was part of our public ABI. Instead of removing it completely, define it as a weak alias of the new mpath_connect__(). This way, programs linked against previous versions of libmpathcmd will continue to work. This shouldn't interfere with general symbol naming rules, as a weak symbol won't override a library symbol of the same name. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathcmd/libmpathcmd.version | 12 ++++++++---- libmpathcmd/mpath_cmd.c | 3 +++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/libmpathcmd/libmpathcmd.version b/libmpathcmd/libmpathcmd.version index a786c2573..81bdb2b7d 100644 --- a/libmpathcmd/libmpathcmd.version +++ b/libmpathcmd/libmpathcmd.version @@ -10,16 +10,20 @@ * * See libmultipath.version for general policy about version numbers. */ -LIBMPATHCMD_2.0.0 { + +LIBMPATHCMD_1.0.0 { global: mpath_connect; - mpath_connect__; + __mpath_connect; mpath_disconnect; mpath_process_cmd; mpath_recv_reply; mpath_recv_reply_len; mpath_recv_reply_data; mpath_send_cmd; -local: - *; }; + +LIBMPATHCMD_1.1.0 { +global: + mpath_connect__; +} LIBMPATHCMD_1.0.0; diff --git a/libmpathcmd/mpath_cmd.c b/libmpathcmd/mpath_cmd.c index 1fa036cee..a38e8b612 100644 --- a/libmpathcmd/mpath_cmd.c +++ b/libmpathcmd/mpath_cmd.c @@ -133,6 +133,9 @@ int mpath_connect__(int nonblocking) return fd; } +extern int __mpath_connect(int) + __attribute__((weak, alias("mpath_connect__"))); + /* * connect to a unix domain socket */ From ced5e53714b04dfb6261e9d0e2f72061c34545e8 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Mon, 12 Aug 2024 21:48:52 +0200 Subject: [PATCH 141/145] libmpathpersist: reinstate ABI 2.1.0 __mpath_persistent_reserve_{in,out}() were part of our public ABI. Instead of removing them completely, define it as a weak aliases. This way, programs linked against previous versions of libmpathpersist will continue to work. This shouldn't interfere with general symbol naming rules, as a weak symbol won't override a library symbol of the same name. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathpersist/libmpathpersist.version | 17 ++++++++++++----- libmpathpersist/mpath_persist.c | 6 ++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/libmpathpersist/libmpathpersist.version b/libmpathpersist/libmpathpersist.version index f467d99b9..c7ddafb72 100644 --- a/libmpathpersist/libmpathpersist.version +++ b/libmpathpersist/libmpathpersist.version @@ -10,23 +10,30 @@ * * See libmultipath.version for general policy about version numbers. */ -LIBMPATHPERSIST_3.0.0 { +/* Previous API for backward compatibility */ +LIBMPATHPERSIST_2.1.0 { global: - /* public API as defined in mpath_persist.h */ libmpathpersist_exit; libmpathpersist_init; mpath_lib_exit; mpath_lib_init; mpath_mx_alloc_len; mpath_persistent_reserve_free_vecs; - mpath_persistent_reserve_in__; + __mpath_persistent_reserve_in; mpath_persistent_reserve_in; mpath_persistent_reserve_init_vecs; - mpath_persistent_reserve_out__; + __mpath_persistent_reserve_out; mpath_persistent_reserve_out; -local: *; +local: + *; }; +LIBMPATHPERSIST_2.2.0 { +global: + mpath_persistent_reserve_in__; + mpath_persistent_reserve_out__; +} LIBMPATHPERSIST_2.1.0; + __LIBMPATHPERSIST_INT_1.0.0 { /* Internal use by multipath-tools */ dumpHex; diff --git a/libmpathpersist/mpath_persist.c b/libmpathpersist/mpath_persist.c index ace91d73c..f5267ebf1 100644 --- a/libmpathpersist/mpath_persist.c +++ b/libmpathpersist/mpath_persist.c @@ -127,6 +127,8 @@ int mpath_persistent_reserve_in__(int fd, int rq_servact, resp, noisy); } +extern int __mpath_persistent_reserve_in(int, int, struct prin_resp *, int) + __attribute__((weak, alias("mpath_persistent_reserve_in__"))); int mpath_persistent_reserve_out__( int fd, int rq_servact, int rq_scope, unsigned int rq_type, struct prout_param_descriptor *paramp, int noisy) @@ -136,6 +138,10 @@ int mpath_persistent_reserve_out__( int fd, int rq_servact, int rq_scope, noisy); } +extern int __mpath_persistent_reserve_out(int, int, int, unsigned int, + struct prout_param_descriptor *, int) + __attribute__((weak, alias("mpath_persistent_reserve_out__"))); + int mpath_persistent_reserve_in (int fd, int rq_servact, struct prin_resp *resp, int noisy, int verbose) { From 730059ed86c6c706e412edad85c298272471f0f4 Mon Sep 17 00:00:00 2001 From: Xose Vazquez Perez Date: Thu, 15 Aug 2024 17:23:57 +0200 Subject: [PATCH 142/145] multipath-tools: update info about path_grouping_policy in the man page It's hardware dependent. Cc: Martin Wilck Cc: Benjamin Marzinski Cc: Christophe Varoqui Cc: DM-DEVEL ML Signed-off-by: Xose Vazquez Perez Reviewed-by: Martin Wilck --- multipath/multipath.conf.5.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/multipath/multipath.conf.5.in b/multipath/multipath.conf.5.in index 677b0823f..4388baad8 100644 --- a/multipath/multipath.conf.5.in +++ b/multipath/multipath.conf.5.in @@ -6,7 +6,7 @@ .\" Update the date below if you make any significant change. .\" ---------------------------------------------------------------------------- . -.TH MULTIPATH.CONF 5 2024-04-25 Linux +.TH MULTIPATH.CONF 5 2024-08-15 Linux . . .\" ---------------------------------------------------------------------------- @@ -220,7 +220,7 @@ The default is: \fBservice-time 0\fR . .TP .B path_grouping_policy -The default path grouping policy to apply to unspecified +(Hardware-dependent) The default path grouping policy to apply to unspecified multipaths. Possible values are: .RS .TP 12 From 5721ade296043915c93acfce9e0978c3e12da452 Mon Sep 17 00:00:00 2001 From: ns <0n-s@users.noreply.github.com> Date: Mon, 10 Jun 2024 18:55:13 +0000 Subject: [PATCH 143/145] libmultipath, libmpathutil: explicitly annotate {get,put}_multipath_config as weak When linking libmultipath & libmpathutil with -Bsymbolic-non-weak-functions, multipathd segfaults because the weak nature of these symbols is not recognized. Add the necessary attributes to make that clear to the linker. Fixes: https://github.com/opensvc/multipath-tools/issues/26 # sort of Tested-by: ns <0n-s@users.noreply.github.com> Reviewed-by: Martin Wilck --- libmpathutil/globals.c | 4 ++-- libmultipath/config.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libmpathutil/globals.c b/libmpathutil/globals.c index 0f6033e07..4d913496f 100644 --- a/libmpathutil/globals.c +++ b/libmpathutil/globals.c @@ -2,10 +2,10 @@ #include #include "globals.h" -struct config *get_multipath_config(void) +__attribute__((weak)) struct config *get_multipath_config(void) { return NULL; } -void put_multipath_config(void *p __attribute__((unused))) +__attribute__((weak)) void put_multipath_config(void *p __attribute__((unused))) {} diff --git a/libmultipath/config.c b/libmultipath/config.c index 2d2b50742..0e3a5cc18 100644 --- a/libmultipath/config.c +++ b/libmultipath/config.c @@ -82,7 +82,7 @@ struct config *libmp_get_multipath_config(void) } struct config *get_multipath_config(void) - __attribute__((alias("libmp_get_multipath_config"))); + __attribute__((weak, alias("libmp_get_multipath_config"))); void libmp_put_multipath_config(void *conf __attribute__((unused))) { @@ -90,7 +90,7 @@ void libmp_put_multipath_config(void *conf __attribute__((unused))) } void put_multipath_config(void *conf) - __attribute__((alias("libmp_put_multipath_config"))); + __attribute__((weak, alias("libmp_put_multipath_config"))); static int hwe_strmatch (const struct hwentry *hwe1, const struct hwentry *hwe2) From 9d905104c6c2fdd98a073eed91d197846a5ed465 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 15 Aug 2024 19:14:34 +0200 Subject: [PATCH 144/145] Updated NEWS.md Signed-off-by: Martin Wilck --- .github/actions/spelling/expect.txt | 1 + NEWS.md | 52 ++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index ccb04baad..934f582ed 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -15,6 +15,7 @@ barbie BINDIR blkid bmarzins +Bsymbolic cciss CFLAGS cgroups diff --git a/NEWS.md b/NEWS.md index cb0639def..4638bd081 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,19 +1,29 @@ # multipath-tools Release Notes -## multipath-tools 0.9.x (in preparation) +## multipath-tools 0.10.0, 2024/08 ### User-Visible Changes -* Add hardware defaults for Huawei storage arrays and XSG1 vendors +* The `multipathd show daemon` command now shows `(reconfigure pending)` + if a reconfiguration has been triggered but not finished yet. ### Other major changes +* Refactored the path checker loop. Paths are now checked for each multipath + map in turn, rather than walking linearly through the list of paths. Paths + for different multipath maps will be checked at different time offsets in + the `polling_interval` time span, which distributes the load caused by + path checking more evenly over time. * Refactored a significant part of the libmultipath / libdevmapper interface. All functions that retrieve information about DM maps have been converted to use just one worker function, libmp_mapinfo(). This reduces code size while providing more flexibility and efficiency (less device-mapper ioctls). Also, cleanup attributes are used consistently in the libdevmapper-related code. -* Made map removal more efficient by avoiding unnecessary recursion. +* Renamed public functions, variables, and macros to comply with the + glibc [policy for reserved names](https://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html). + For backward compatibility reasons, the exported functions from `libmpathcmd` + and `libmpathpersist` that start with double underscore are kept as weak + symbols. Fixes [#91](https://github.com/opensvc/multipath-tools/issues/91). ### Bug fixes @@ -23,17 +33,35 @@ 0.9.9). * Fixed old mpathpersist bug leading to the error message "configured reservation key doesn't match: 0x0" when `reservation_key` was configured in the - multipaths section of `multipath.conf`. + multipaths section of `multipath.conf` + (Fixes [#92](https://github.com/opensvc/multipath-tools/issues/92)). +* Fixed output of `multipath -t` and `multipath -T` for the options + `force_sync` and `retrigger_tries`. + (Fixes [#88](https://github.com/opensvc/multipath-tools/pull/93)) +* Fixed adding maps by WWID in CLI (command `add map $WWID`). ### Other +* Removed hardcoded paths and make them configurable instead. + This should improve compatibility e.g. with NixOS. +* Improved handling of paths with changed WWIDs. +* Improved synchronization between kernel state and multipathd's internal + state. +* Made map removal more efficient by avoiding unnecessary recursion. +* Added hardware defaults for Huawei storage arrays and XSG1 vendors. * Use `-fexceptions` during compilation to make sure cleanup code is executed when threads are cancelled +* Use `weak` attribute for `get_multipath_config()` and + `put_multipath_config()` in order to enable linking with + `-Bsymbolic-non-weak-functions` + (Fixes [#86](https://github.com/opensvc/multipath-tools/pull/87)). * Fixed CI for ARM/v7 -* Remove hardcoded paths and make them configurable instead. - This should improve compatibility e.g. with NixOS. * Fixed directio CI test for real devices, run more "real" tests in CI * Fixed minor issues detected by coverity. +* Fixed a minor bug in the config file parser + (Fixes [#93](https://github.com/opensvc/multipath-tools/pull/93)). +* Minor documentation fixes + (Fixes [#87](https://github.com/opensvc/multipath-tools/pull/87)). ## multipath-tools 0.9.9, 2024/05 @@ -128,8 +156,8 @@ versions earlier than 0.9.9. See "Other major changes" below. had been sent before. * Error messages sent from multipathd to the command line client have been improved. The user will now see messages like "map or partition in use" or - "device not found" instead of just "fail". - + "device not found" instead of just "fail". + ### Other Major Changes * multipathd now tracks the queueing mode of maps in its internal features @@ -144,7 +172,7 @@ versions earlier than 0.9.9. See "Other major changes" below. * A segmentation fault in the 0.9.7 autoresize code has been fixed. * Fixed a bug introduced in 0.9.6 that had caused map reloads being omitted - when path priorities changed. + when path priorities changed. * Fixed compilation with gcc 14. (Fixes [#80](https://github.com/opensvc/multipath-tools/issues/80)) * Minor fixes for issues detected by coverity. * Spelling fixes and other minor fixes. @@ -166,7 +194,7 @@ versions earlier than 0.9.9. See "Other major changes" below. * Added `max_retries` config option to limit SCSI retries. * Added `auto_resize` config option to enable resizing multipath maps automatically. * Added support for handling FPIN-Li events for FC-NVMe. - + ### Other Major Changes * Rework of alias selection code: @@ -219,7 +247,7 @@ and the directio checker (fixes * Fix handling of `dev_loss_tmo` in cases where it wasn't explicitly configured. * Syntax fixes in udev rules (Fixes [#69](https://github.com/opensvc/multipath-tools/pull/69)). - + ### Other * Adapt HITACHI/OPEN- config to work with alua and multibus. @@ -228,7 +256,7 @@ and the directio checker (fixes ## multipath-tools 0.9.5, 2023/04 ### User-Visible Changes - + * Always use directio path checker for Linux TCM (LIO) targets (Fixes [#54](https://github.com/opensvc/multipath-tools/issues/54). * `multipath -u` now checks if path devices are already in use From 86b969286a581f0adae2c90d336e8278576dce0f Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 15 Aug 2024 19:16:05 +0200 Subject: [PATCH 145/145] libmultipath: bump version to 0.10.0 Signed-off-by: Martin Wilck --- NEWS.md | 4 ++-- libmultipath/version.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 4638bd081..69acda47c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -37,7 +37,7 @@ (Fixes [#92](https://github.com/opensvc/multipath-tools/issues/92)). * Fixed output of `multipath -t` and `multipath -T` for the options `force_sync` and `retrigger_tries`. - (Fixes [#88](https://github.com/opensvc/multipath-tools/pull/93)) + (Fixes [#88](https://github.com/opensvc/multipath-tools/pull/88)) * Fixed adding maps by WWID in CLI (command `add map $WWID`). ### Other @@ -54,7 +54,7 @@ * Use `weak` attribute for `get_multipath_config()` and `put_multipath_config()` in order to enable linking with `-Bsymbolic-non-weak-functions` - (Fixes [#86](https://github.com/opensvc/multipath-tools/pull/87)). + (Fixes [#86](https://github.com/opensvc/multipath-tools/pull/86)). * Fixed CI for ARM/v7 * Fixed directio CI test for real devices, run more "real" tests in CI * Fixed minor issues detected by coverity. diff --git a/libmultipath/version.h b/libmultipath/version.h index 5dae23341..8ad403ef4 100644 --- a/libmultipath/version.h +++ b/libmultipath/version.h @@ -20,9 +20,9 @@ #ifndef VERSION_H_INCLUDED #define VERSION_H_INCLUDED -#define VERSION_CODE 0x000909 +#define VERSION_CODE 0x000A00 /* MMDDYY, in hex */ -#define DATE_CODE 0x050318 +#define DATE_CODE 0x080F18 #define PROG "multipath-tools"