All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/72] multipath-tools: cleanup and warning enablement
@ 2019-10-12 21:27 Martin Wilck
  2019-10-12 21:27 ` [PATCH 01/72] multipath tests: move condlog test wrappers to separate file Martin Wilck
                   ` (71 more replies)
  0 siblings, 72 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:27 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Hi Christophe, hi Ben,

here is a series with cleanup patches and minor fixes for multipath-tools.
Sorry about the number of patches, I hope this way the series will be easier
to review. There are lots of obvious, short hunks. In terms of LoC, most
of the changes are in a new unit test, in the NVMe code update, and in
a (necessary) indentation change in the VPD code.

Patch 01-14 are part of a recent effort to go over the multipath-tools
code, re-review, and modernize the code a bit. Part of that is adding "const"
qualifiers to function arguments, as I did before. I happened to start with
"alias.c", for alphabetic reasons. Other parts of the code will hopefully
follow.

15-20 are misc fixes for stuff I came across while working on the
"-Wclobbered" flag (see below).

The rest of the series is an attempt to get rid of the disablement of
warnings that we had so far in multipath-tools. I believe we agree that
warning-free code is a good thing and that disabling warnings should be
avoided if possible. My goal was to be able to set "-Werror" and compile
successfully with all currently relevant compilers.

Patch 21-42 fix issues with -Wunused-parameter and finally enable that
warning. -Wno-unused-parameter is only kept in place for
libmultipath/dict.c and multipathd/cli-handlers.c, which basically consist
only of implementations of certain prototypes where many functions don't
use every argument, and hundreds of "unused" attributes would pollute the
code too much. Patch 53-58 fix issues with "-Wsign-compare". This was
actually a good excercise, because I was forced to think twice which
signedness was correct for certain variables and expressions. Patch 59-64
fix some warnings that are issued by clang with our current warning settings
(in particular, -Wformat-literal).

Patch 65 is an update of our nvme code from nvme-cli 1.9. Patch 66-71
contain some make file fixes and cleanups, and adaptations for older
compilers. Finally, Patch 71 enables -Werror, and patch 72 tests for
"-Wno-clobbered", which clang doesn't support.

I can proudly say that multipath-tools now compiles without warnings or
errors with -Werror and with a large set of compilers. I tested gcc 4.8,
7, 8, 9 and clang 3.9, 6, 7, and 8.

The only "-Wno" option that now remains is "-Wclobbered". I have put
considerable work into trying to eliminate that as well. The result
can be examined in the "Wclobbered" branch of my github fork:
https://github.com/mwilck/multipath-tools/commits/Wclobbered
(yes, that's another 37 patches on top of this already long series).

I have pondered this back and forth whether to submit that part of the
series, too. All the -Wclobbered warnings are caused by pthread_cleanup_push()
calls, of which our code has a lot, and which glibc implements using a
sigsetjmp() call. These warnings are arguably a false positives, and
a bug of either gcc, glibc, or both
(see e.g. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61118). 

Eliminating these warnings is possible, but it requires a lot of changes
in the code. Some of them are actually beneficial for readability, but
others are rather not. Some are outright mysterious (e.g.
https://github.com/mwilck/multipath-tools/commit/bb53d666777f072e60372979eed51752db03cec4),
and finding the workarounds was trial-and error work. Also, there are
variations between gcc versions.

The bottom line is, while I feel sorry about the vain effort 
I put into this, my personal opinion is that silencing just this single
warning isn't worth that big amount of changes.

Reviews and opinions welcome.

Regards
Martin

Martin Wilck (72):
  multipath tests: move condlog test wrappers to separate file
  multipath tests: add tests for alias handling
  libmultipath: alias.c: constify function arguments
  libmultipath: alias.c: use strlcpy(), and 2 minor fixes
  libmultipath: format_devname: avoid buffer overflow
  libmultipath: scan_devname: fix int overflow detection
  libmultipath: lookup_binding(): don't rely on int overflow
  libmultipath: rlookup_binding(): removed unused parameter
  libmultipath: allocate_binding(): error out for id=0
  libmultipath: allocate_binding(): detect line overflow
  multipath tests: alias: add tests for allocate_binding()
  multipath tests: alias: add format/scan test
  libmultipath: alias.c: prepare for cancel-safe allocation
  multipath tests: use -lpthread for alias test
  libmultipath: path_discovery: handle libudev errors
  libmultipath: make path_discovery() pthread_cancel()-safe
  libmultipath: uevent_listen(): fix poll() retval check
  libmultipath: replace_wwids(): fix possible fd leak
  libmultipath: remove_wwids(): fix possible leaks
  libmultipath: _init_foreign(): fix possible memory leak
  libmultipath: process_config_dir(): remove unused argument
  libmultipath: mark unused arguments in partmap functions
  libmultipath: scsi_ioctl_pathinfo(): remove unused argument
  multipath-tools: mark unused params in signal and cleanup handlers
  libmultipath: get_ana_info(): remove unused parameter
  libmultipath: mark unused params in getprio() methods
  libmultipath: hp_sw: remove usused argument in do_inq()
  libmultipath: checkers: mark unused arguments in methods
  multipathd: stop_waiter_thread(): removed unused parameter
  multipath tools: mark unused arguments in thread routines
  kpartx: gpt: remove unused arg in read_lastoddsector()
  kpartx: mark unused arguments in ptreader methods
  libmultipath: mark missing arguments in functions matching prototypes
  libmultipath: get_pgpolicy_name(): use "len" parameter
  libmultipath: snprint_multipath_map_json(): remove unused argument
  multipath: delegate_to_multipathd: mark unused arguments
  libmultipath: use -Wno-unused-parameter for dict.c
  multipathd: use -Wno-unused-parameter for cli_handlers.c
  libmpathpersist: remove unused "noisy" argument in various functions
  libmpathpersist: fix copy-paste error in mpath_format_readresv()
  multipath-tools tests: add -Wno-unused-parameter
  multipath-tools: Makefile.inc: remove -Wno-unused-parameter
  libmultipath: dev_loss_tmo is unsigned
  libmultipath: trivial changes for -Wsign-compare
  libmultipath: fix -Wsign-compare warnings with snprintf()
  libmultipath: parse_vpd_pg83(): sanitize indentation
  libmultipath: parse_vpd_pg83(): fix -Wsign-compare warnings
  libmultipath: print: use unsigned int for "width" field
  libmultipath: vector_for_each_slot: fix -Wsign-compare warnings
  libmultipath: set_int(): add error check and set_uint()
  libmultipath: make "checkint" unsigned
  libmultipath: use unsigned blksize in directio context
  libmultipath, kpartx: byteorder: always use unsigned types
  libmpathcmd: fix -Wsign-compare warnings
  libmpathpersist: fix -Wsign-compare warnings
  kpartx: use unsigned arguments in dm_devn() and dm_prereq()
  kpartx: use unsigned int for "ns" argument of ptreader
  multipath-tools: Makefile.inc: enable -Wsign-compare
  libdmmp: fix clang -Wformat-nonliteral warnings
  libmultipath: fix clang -Wformat-literal warnings
  multipath tests: blacklist: remove always-true condition
  multipath tests: hwtable: fix strncat() invocation
  multipath tests: fix -Wformat-literal warning
  multipath tests: util: fix clang strlcpy warnings
  libmultipath: nvme: update to nvme-cli v1.9
  multipath-tools: Makefile.inc: fix TEST_CC_OPTION
  multipath-tools: Makefile.inc: use -Wp,... for compiling only
  multipath-tools: Makefile: use proper directory recursion
  multipath tests: Makefile: fix "clean" target
  multipath tests: Makefile: avoid gcc 4.8 missing initializers failure
  multipath-tools: Makefile.inc: enable -Werror
  multipath-tools: Makefile.inc: test for -Wno-clobbered support

 Makefile                                 |  38 +-
 Makefile.inc                             |  15 +-
 kpartx/bsd.c                             |   4 +-
 kpartx/dasd.c                            |   3 +-
 kpartx/devmapper.c                       |  13 +-
 kpartx/devmapper.h                       |   7 +-
 kpartx/dos.c                             |   4 +-
 kpartx/gpt.c                             |  15 +-
 kpartx/gpt.h                             |   2 +-
 kpartx/kpartx.h                          |  11 +-
 kpartx/mac.c                             |   5 +-
 kpartx/ps3.c                             |   5 +-
 kpartx/solaris.c                         |   4 +-
 kpartx/sun.c                             |   4 +-
 kpartx/unixware.c                        |   4 +-
 libdmmp/libdmmp_private.h                |   8 +-
 libmpathcmd/mpath_cmd.c                  |   5 +-
 libmpathpersist/mpath_persist.c          |   3 +-
 libmpathpersist/mpath_pr_ioctl.c         |  40 +-
 libmultipath/Makefile                    |   5 +
 libmultipath/alias.c                     | 134 ++--
 libmultipath/alias.h                     |  12 +-
 libmultipath/byteorder.h                 |  12 +-
 libmultipath/checkers/cciss_tur.c        |   4 +-
 libmultipath/checkers/directio.c         |   2 +-
 libmultipath/checkers/hp_sw.c            |   8 +-
 libmultipath/checkers/rdac.c             |   2 +-
 libmultipath/checkers/readsector0.c      |   4 +-
 libmultipath/config.c                    |   4 +-
 libmultipath/config.h                    |   4 +-
 libmultipath/defaults.h                  |   4 +-
 libmultipath/devmapper.c                 |  10 +-
 libmultipath/dict.c                      |  52 +-
 libmultipath/discovery.c                 | 284 +++++----
 libmultipath/discovery.h                 |   2 +-
 libmultipath/dm-generic.c                |   6 +-
 libmultipath/file.c                      |   5 +-
 libmultipath/foreign.c                   |  20 +-
 libmultipath/foreign/nvme.c              |  24 +-
 libmultipath/generic.c                   |   2 +-
 libmultipath/io_err_stat.c               |  10 +-
 libmultipath/log.h                       |   3 +-
 libmultipath/log_pthread.c               |   2 +-
 libmultipath/log_pthread.h               |   3 +-
 libmultipath/nvme/linux/nvme.h           | 136 ++++-
 libmultipath/nvme/nvme-ioctl.c           | 229 ++++---
 libmultipath/nvme/nvme-ioctl.h           |  31 +-
 libmultipath/nvme/nvme.h                 | 121 +++-
 libmultipath/parser.c                    |   2 +-
 libmultipath/pgpolicies.c                |   2 +-
 libmultipath/print.c                     |  14 +-
 libmultipath/print.h                     |   8 +-
 libmultipath/prioritizers/alua_rtpg.c    |   2 +-
 libmultipath/prioritizers/ana.c          |  14 +-
 libmultipath/prioritizers/const.c        |   4 +-
 libmultipath/prioritizers/datacore.c     |   3 +-
 libmultipath/prioritizers/emc.c          |   3 +-
 libmultipath/prioritizers/hds.c          |   3 +-
 libmultipath/prioritizers/hp_sw.c        |   3 +-
 libmultipath/prioritizers/iet.c          |   3 +-
 libmultipath/prioritizers/ontap.c        |   3 +-
 libmultipath/prioritizers/random.c       |   4 +-
 libmultipath/prioritizers/rdac.c         |   3 +-
 libmultipath/prioritizers/sysfs.c        |   3 +-
 libmultipath/prioritizers/weightedpath.c |   3 +-
 libmultipath/structs.c                   |   4 +-
 libmultipath/structs.h                   |   3 +-
 libmultipath/structs_vec.c               |   2 +-
 libmultipath/sysfs.c                     |  10 +-
 libmultipath/time-util.c                 |   6 +-
 libmultipath/uevent.c                    |   5 +-
 libmultipath/util.c                      |   7 +-
 libmultipath/util.h                      |   8 +-
 libmultipath/uxsock.c                    |   3 +-
 libmultipath/vector.h                    |   4 +-
 libmultipath/wwids.c                     |  39 +-
 mpathpersist/main.c                      |   2 +-
 multipath/main.c                         |  10 +-
 multipathd/Makefile                      |   3 +
 multipathd/cli_handlers.c                |   2 +-
 multipathd/dmevents.c                    |   4 +-
 multipathd/main.c                        |  36 +-
 multipathd/pidfile.c                     |   2 +-
 multipathd/waiter.c                      |   2 +-
 multipathd/waiter.h                      |   2 +-
 tests/Makefile                           |  19 +-
 tests/alias.c                            | 744 +++++++++++++++++++++++
 tests/blacklist.c                        |  22 +-
 tests/hwtable.c                          |   2 +-
 tests/test-log.c                         |  27 +
 tests/test-log.h                         |   7 +
 tests/util.c                             |  16 +-
 92 files changed, 1802 insertions(+), 591 deletions(-)
 create mode 100644 tests/alias.c
 create mode 100644 tests/test-log.c
 create mode 100644 tests/test-log.h

-- 
2.23.0

^ permalink raw reply	[flat|nested] 85+ messages in thread

* [PATCH 01/72] multipath tests: move condlog test wrappers to separate file
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
@ 2019-10-12 21:27 ` Martin Wilck
  2019-10-12 21:27 ` [PATCH 02/72] multipath tests: add tests for alias handling Martin Wilck
                   ` (70 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:27 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

These helpers can be useful in other tests.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 tests/Makefile    |  1 +
 tests/blacklist.c | 20 +-------------------
 tests/test-log.c  | 26 ++++++++++++++++++++++++++
 tests/test-log.h  |  7 +++++++
 4 files changed, 35 insertions(+), 19 deletions(-)
 create mode 100644 tests/test-log.c
 create mode 100644 tests/test-log.h

diff --git a/tests/Makefile b/tests/Makefile
index a5cdf390..fb3c067b 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -23,6 +23,7 @@ hwtable-test_TESTDEPS := test-lib.o
 hwtable-test_OBJDEPS := ../libmultipath/discovery.o ../libmultipath/blacklist.o \
 	../libmultipath/prio.o ../libmultipath/callout.o ../libmultipath/structs.o
 hwtable-test_LIBDEPS := -ludev -lpthread -ldl
+blacklist-test_TESTDEPS := test-log.o
 blacklist-test_OBJDEPS := ../libmultipath/blacklist.o
 blacklist-test_LIBDEPS := -ludev
 vpd-test_OBJDEPS :=  ../libmultipath/discovery.o
diff --git a/tests/blacklist.c b/tests/blacklist.c
index 362c44d9..733ee398 100644
--- a/tests/blacklist.c
+++ b/tests/blacklist.c
@@ -21,7 +21,7 @@
 #include <cmocka.h>
 #include "globals.c"
 #include "blacklist.h"
-#include "log.h"
+#include "test-log.h"
 
 struct udev_device {
 	const char *sysname;
@@ -62,24 +62,6 @@ __wrap_udev_list_entry_get_name(struct udev_list_entry *list_entry)
 	return *(const char **)list_entry;
 }
 
-void __wrap_dlog (int sink, int prio, const char * fmt, ...)
-{
-	char buff[MAX_MSG_SIZE];
-	va_list ap;
-
-	assert_int_equal(prio, mock_type(int));
-	va_start(ap, fmt);
-	vsnprintf(buff, MAX_MSG_SIZE, fmt, ap);
-	va_end(ap);
-	assert_string_equal(buff, mock_ptr_type(char *));
-}
-
-void expect_condlog(int prio, char *string)
-{
-	will_return(__wrap_dlog, prio);
-	will_return(__wrap_dlog, string);
-}
-
 vector blist_devnode_sdb;
 vector blist_all;
 vector blist_device_foo_bar;
diff --git a/tests/test-log.c b/tests/test-log.c
new file mode 100644
index 00000000..76a266eb
--- /dev/null
+++ b/tests/test-log.c
@@ -0,0 +1,26 @@
+#include <setjmp.h>
+#include <stddef.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <cmocka.h>
+#include "log.h"
+#include "test-log.h"
+
+void __wrap_dlog (int sink, int prio, const char * fmt, ...)
+{
+	char buff[MAX_MSG_SIZE];
+	va_list ap;
+
+	assert_int_equal(prio, mock_type(int));
+	va_start(ap, fmt);
+	vsnprintf(buff, MAX_MSG_SIZE, fmt, ap);
+	va_end(ap);
+	assert_string_equal(buff, mock_ptr_type(char *));
+}
+
+void expect_condlog(int prio, char *string)
+{
+	will_return(__wrap_dlog, prio);
+	will_return(__wrap_dlog, string);
+}
+
diff --git a/tests/test-log.h b/tests/test-log.h
new file mode 100644
index 00000000..2c878c63
--- /dev/null
+++ b/tests/test-log.h
@@ -0,0 +1,7 @@
+#ifndef _TEST_LOG_H
+#define _TEST_LOG_H
+
+void __wrap_dlog (int sink, int prio, const char * fmt, ...);
+void expect_condlog(int prio, char *string);
+
+#endif
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 02/72] multipath tests: add tests for alias handling
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
  2019-10-12 21:27 ` [PATCH 01/72] multipath tests: move condlog test wrappers to separate file Martin Wilck
@ 2019-10-12 21:27 ` Martin Wilck
  2019-10-12 21:27 ` [PATCH 03/72] libmultipath: alias.c: constify function arguments Martin Wilck
                   ` (69 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:27 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Some of these tests fail with the current code base.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 tests/Makefile |   3 +-
 tests/alias.c  | 590 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 592 insertions(+), 1 deletion(-)
 create mode 100644 tests/alias.c

diff --git a/tests/Makefile b/tests/Makefile
index fb3c067b..0ce318c6 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -3,7 +3,7 @@ include ../Makefile.inc
 CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathcmddir)
 LIBDEPS += -L$(multipathdir) -lmultipath -lcmocka
 
-TESTS := uevent parser util dmevents hwtable blacklist unaligned vpd pgpolicy
+TESTS := uevent parser util dmevents hwtable blacklist unaligned vpd pgpolicy alias
 
 .SILENT: $(TESTS:%=%.o)
 .PRECIOUS: $(TESTS:%=%-test)
@@ -28,6 +28,7 @@ blacklist-test_OBJDEPS := ../libmultipath/blacklist.o
 blacklist-test_LIBDEPS := -ludev
 vpd-test_OBJDEPS :=  ../libmultipath/discovery.o
 vpd-test_LIBDEPS := -ludev -lpthread -ldl
+alias-test_TESTDEPS := test-log.o
 
 lib/libchecktur.so:
 	mkdir lib
diff --git a/tests/alias.c b/tests/alias.c
new file mode 100644
index 00000000..32fdc697
--- /dev/null
+++ b/tests/alias.c
@@ -0,0 +1,590 @@
+#include <stdint.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <cmocka.h>
+#include "util.h"
+#include "alias.h"
+#include "test-log.h"
+
+#include "globals.c"
+#include "../libmultipath/alias.c"
+
+#if INT_MAX == 0x7fffffff
+/* user_friendly_name for map #INT_MAX */
+#define MPATH_ID_INT_MAX "fxshrxw"
+/* ... and one less */
+#define MPATH_ID_INT_MAX_m1 "fxshrxv"
+/* ... and one more */
+#define MPATH_ID_INT_MAX_p1 "fxshrxx"
+#endif
+
+void __wrap_rewind(FILE *stream)
+{}
+
+char *__wrap_fgets(char *buf, int n, FILE *stream)
+{
+	char *val = mock_ptr_type(char *);
+	if (!val)
+		return NULL;
+	strlcpy(buf, val, n);
+	return buf;
+}
+
+static void fd_mpatha(void **state)
+{
+	char buf[32];
+	int rc;
+
+	rc = format_devname(buf, 1, sizeof(buf), "FOO");
+	assert_int_equal(rc, 4);
+	assert_string_equal(buf, "FOOa");
+}
+
+static void fd_mpathz(void **state)
+{
+	/* This also tests a "short" buffer, see fd_mpath_short1 */
+	char buf[5];
+	int rc;
+
+	rc = format_devname(buf, 26, sizeof(buf), "FOO");
+	assert_int_equal(rc, 4);
+	assert_string_equal(buf, "FOOz");
+}
+
+static void fd_mpathaa(void **state)
+{
+	char buf[32];
+	int rc;
+
+	rc = format_devname(buf, 26 + 1, sizeof(buf), "FOO");
+	assert_int_equal(rc, 5);
+	assert_string_equal(buf, "FOOaa");
+}
+
+static void fd_mpathzz(void **state)
+{
+	char buf[32];
+	int rc;
+
+	rc = format_devname(buf, 26*26 + 26, sizeof(buf), "FOO");
+	assert_int_equal(rc, 5);
+	assert_string_equal(buf, "FOOzz");
+}
+
+static void fd_mpathaaa(void **state)
+{
+	char buf[32];
+	int rc;
+
+	rc = format_devname(buf, 26*26 + 27, sizeof(buf), "FOO");
+	assert_int_equal(rc, 6);
+	assert_string_equal(buf, "FOOaaa");
+}
+
+static void fd_mpathzzz(void **state)
+{
+	char buf[32];
+	int rc;
+
+	rc = format_devname(buf, 26*26*26 + 26*26 + 26, sizeof(buf), "FOO");
+	assert_int_equal(rc, 6);
+	assert_string_equal(buf, "FOOzzz");
+}
+
+static void fd_mpathaaaa(void **state)
+{
+	char buf[32];
+	int rc;
+
+	rc = format_devname(buf, 26*26*26 + 26*26 + 27, sizeof(buf), "FOO");
+	assert_int_equal(rc, 7);
+	assert_string_equal(buf, "FOOaaaa");
+}
+
+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,
+			    sizeof(buf), "FOO");
+	assert_int_equal(rc, 7);
+	assert_string_equal(buf, "FOOzzzz");
+}
+
+#ifdef MPATH_ID_INT_MAX
+static void fd_mpath_max(void **state)
+{
+	char buf[32];
+	int rc;
+
+	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);
+}
+#endif
+
+static void fd_mpath_max1(void **state)
+{
+	char buf[32];
+	int rc;
+
+	rc  = format_devname(buf, INT_MIN, sizeof(buf), "");
+	assert_int_equal(rc, -1);
+}
+
+static void fd_mpath_short(void **state)
+{
+	char buf[4];
+	int rc;
+
+	rc = format_devname(buf, 1, sizeof(buf), "FOO");
+	assert_int_equal(rc, -1);
+}
+
+static void fd_mpath_short1(void **state)
+{
+	char buf[5];
+	int rc;
+
+	rc = format_devname(buf, 27, sizeof(buf), "FOO");
+	assert_int_equal(rc, -1);
+}
+
+static int test_format_devname(void)
+{
+	const struct CMUnitTest tests[] = {
+		cmocka_unit_test(fd_mpatha),
+		cmocka_unit_test(fd_mpathz),
+		cmocka_unit_test(fd_mpathaa),
+		cmocka_unit_test(fd_mpathzz),
+		cmocka_unit_test(fd_mpathaaa),
+		cmocka_unit_test(fd_mpathzzz),
+		cmocka_unit_test(fd_mpathaaaa),
+		cmocka_unit_test(fd_mpathzzzz),
+#ifdef MPATH_ID_INT_MAX
+		cmocka_unit_test(fd_mpath_max),
+#endif
+		cmocka_unit_test(fd_mpath_max1),
+		cmocka_unit_test(fd_mpath_short),
+		cmocka_unit_test(fd_mpath_short1),
+	};
+
+	return cmocka_run_group_tests(tests, NULL, NULL);
+}
+
+static void sd_mpatha(void **state)
+{
+	int rc = scan_devname("MPATHa", "MPATH");
+
+	assert_int_equal(rc, 1);
+}
+
+/*
+ * Text after whitespace is ignored. But an overlong input
+ * errors out, even if it's just whitespace.
+ * It's kind of strange that scan_devname() treats whitespace
+ * like this. But I'm not sure if some corner case depends
+ * on this behavior.
+ */
+static void sd_mpatha_spc(void **state)
+{
+	int rc = scan_devname("MPATHa  00", "MPATH");
+
+	assert_int_equal(rc, 1);
+}
+
+static void sd_mpatha_tab(void **state)
+{
+	int rc = scan_devname("MPATHa\t00", "MPATH");
+
+	assert_int_equal(rc, 1);
+}
+
+static void sd_overlong(void **state)
+{
+	int rc = scan_devname("MPATHa       ", "MPATH");
+
+	assert_int_equal(rc, -1);
+}
+
+static void sd_overlong1(void **state)
+{
+	int rc = scan_devname("MPATHabcdefgh", "MPATH");
+
+	assert_int_equal(rc, -1);
+}
+
+static void sd_noprefix(void **state)
+{
+	int rc = scan_devname("MPATHa", NULL);
+
+	assert_int_equal(rc, -1);
+}
+
+static void sd_nomatchprefix(void **state)
+{
+	int rc = scan_devname("MPATHa", "mpath");
+
+	assert_int_equal(rc, -1);
+}
+
+static void sd_eq_prefix(void **state)
+{
+	int rc = scan_devname("MPATH", "MPATH");
+
+	assert_int_equal(rc, -1);
+}
+
+static void sd_bad_1(void **state)
+{
+	int rc = scan_devname("MPATH0", "MPATH");
+
+	assert_int_equal(rc, -1);
+}
+
+static void sd_bad_2(void **state)
+{
+	int rc = scan_devname("MPATHa0c", "MPATH");
+
+	assert_int_equal(rc, -1);
+}
+
+#ifdef MPATH_ID_INT_MAX
+static void sd_max(void **state)
+{
+	int rc = scan_devname("MPATH" MPATH_ID_INT_MAX, "MPATH");
+
+	assert_int_equal(rc, INT_MAX);
+}
+
+static void sd_max_p1(void **state)
+{
+	int rc = scan_devname("MPATH" MPATH_ID_INT_MAX_p1, "MPATH");
+
+	assert_int_equal(rc, -1);
+}
+#endif
+
+static int test_scan_devname(void)
+{
+	const struct CMUnitTest tests[] = {
+		cmocka_unit_test(sd_mpatha),
+		cmocka_unit_test(sd_mpatha_spc),
+		cmocka_unit_test(sd_mpatha_tab),
+		cmocka_unit_test(sd_overlong),
+		cmocka_unit_test(sd_overlong1),
+		cmocka_unit_test(sd_noprefix),
+		cmocka_unit_test(sd_nomatchprefix),
+		cmocka_unit_test(sd_eq_prefix),
+		cmocka_unit_test(sd_bad_1),
+		cmocka_unit_test(sd_bad_2),
+#ifdef MPATH_ID_INT_MAX
+		cmocka_unit_test(sd_max),
+		cmocka_unit_test(sd_max_p1),
+#endif
+	};
+
+	return cmocka_run_group_tests(tests, NULL, NULL);
+}
+
+static void lb_empty(void **state)
+{
+	int rc;
+	char *alias;
+
+	will_return(__wrap_fgets, NULL);
+	expect_condlog(3, "No matching wwid [WWID0] in bindings file.\n");
+	rc = lookup_binding(NULL, "WWID0", &alias, NULL);
+	assert_int_equal(rc, 1);
+	assert_ptr_equal(alias, NULL);
+}
+
+static void lb_match_a(void **state)
+{
+	int rc;
+	char *alias;
+
+	will_return(__wrap_fgets, "MPATHa WWID0\n");
+	expect_condlog(3, "Found matching wwid [WWID0] in bindings file."
+		       " Setting alias to MPATHa\n");
+	rc = lookup_binding(NULL, "WWID0", &alias, "MPATH");
+	assert_int_equal(rc, 0);
+	assert_ptr_not_equal(alias, NULL);
+	assert_string_equal(alias, "MPATHa");
+	free(alias);
+}
+
+static void lb_nomatch_a(void **state)
+{
+	int rc;
+	char *alias;
+
+	will_return(__wrap_fgets, "MPATHa WWID0\n");
+	will_return(__wrap_fgets, NULL);
+	expect_condlog(3, "No matching wwid [WWID1] in bindings file.\n");
+	rc = lookup_binding(NULL, "WWID1", &alias, "MPATH");
+	assert_int_equal(rc, 2);
+	assert_ptr_equal(alias, NULL);
+}
+
+static void lb_match_c(void **state)
+{
+	int rc;
+	char *alias;
+
+	will_return(__wrap_fgets, "MPATHa WWID0\n");
+	will_return(__wrap_fgets, "MPATHc WWID1\n");
+	expect_condlog(3, "Found matching wwid [WWID1] in bindings file."
+		       " Setting alias to MPATHc\n");
+	rc = lookup_binding(NULL, "WWID1", &alias, "MPATH");
+	assert_int_equal(rc, 0);
+	assert_ptr_not_equal(alias, NULL);
+	assert_string_equal(alias, "MPATHc");
+	free(alias);
+}
+
+static void lb_nomatch_a_c(void **state)
+{
+	int rc;
+	char *alias;
+
+	will_return(__wrap_fgets, "MPATHa WWID0\n");
+	will_return(__wrap_fgets, "MPATHc WWID1\n");
+	will_return(__wrap_fgets, NULL);
+	expect_condlog(3, "No matching wwid [WWID2] in bindings file.\n");
+	rc = lookup_binding(NULL, "WWID2", &alias, "MPATH");
+	assert_int_equal(rc, 2);
+	assert_ptr_equal(alias, NULL);
+}
+
+static void lb_nomatch_c_a(void **state)
+{
+	int rc;
+	char *alias;
+
+	will_return(__wrap_fgets, "MPATHc WWID1\n");
+	will_return(__wrap_fgets, "MPATHa WWID0\n");
+	will_return(__wrap_fgets, NULL);
+	expect_condlog(3, "No matching wwid [WWID2] in bindings file.\n");
+	rc = lookup_binding(NULL, "WWID2", &alias, "MPATH");
+	assert_int_equal(rc, 2);
+	assert_ptr_equal(alias, NULL);
+}
+
+static void lb_nomatch_a_b(void **state)
+{
+	int rc;
+	char *alias;
+
+	will_return(__wrap_fgets, "MPATHa WWID0\n");
+	will_return(__wrap_fgets, "MPATHz WWID26\n");
+	will_return(__wrap_fgets, "MPATHb WWID1\n");
+	will_return(__wrap_fgets, NULL);
+	expect_condlog(3, "No matching wwid [WWID2] in bindings file.\n");
+	rc = lookup_binding(NULL, "WWID2", &alias, "MPATH");
+	assert_int_equal(rc, 3);
+	assert_ptr_equal(alias, NULL);
+}
+
+static void lb_nomatch_a_b_bad(void **state)
+{
+	int rc;
+	char *alias;
+
+	will_return(__wrap_fgets, "MPATHa WWID0\n");
+	will_return(__wrap_fgets, "MPATHz WWID26\n");
+	will_return(__wrap_fgets, "MPATHb\n");
+	will_return(__wrap_fgets, NULL);
+	expect_condlog(3, "Ignoring malformed line 3 in bindings file\n");
+	expect_condlog(3, "No matching wwid [WWID2] in bindings file.\n");
+	rc = lookup_binding(NULL, "WWID2", &alias, "MPATH");
+	assert_int_equal(rc, 3);
+	assert_ptr_equal(alias, NULL);
+}
+
+static void lb_nomatch_b_a(void **state)
+{
+	int rc;
+	char *alias;
+
+	will_return(__wrap_fgets, "MPATHb WWID1\n");
+	will_return(__wrap_fgets, "MPATHz WWID26\n");
+	will_return(__wrap_fgets, "MPATHa WWID0\n");
+	will_return(__wrap_fgets, NULL);
+	expect_condlog(3, "No matching wwid [WWID2] in bindings file.\n");
+	rc = lookup_binding(NULL, "WWID2", &alias, "MPATH");
+	assert_int_equal(rc, 27);
+	assert_ptr_equal(alias, NULL);
+}
+
+#ifdef MPATH_ID_INT_MAX
+static void lb_nomatch_int_max(void **state)
+{
+	int rc;
+	char *alias;
+
+	will_return(__wrap_fgets, "MPATHb WWID1\n");
+	will_return(__wrap_fgets, "MPATH" MPATH_ID_INT_MAX " WWIDMAX\n");
+	will_return(__wrap_fgets, "MPATHa WWID0\n");
+	will_return(__wrap_fgets, NULL);
+	expect_condlog(0, "no more available user_friendly_names\n");
+	rc = lookup_binding(NULL, "WWID2", &alias, "MPATH");
+	assert_int_equal(rc, -1);
+	assert_ptr_equal(alias, NULL);
+}
+
+static void lb_nomatch_int_max_m1(void **state)
+{
+	int rc;
+	char *alias;
+
+	will_return(__wrap_fgets, "MPATHb WWID1\n");
+	will_return(__wrap_fgets, "MPATH" MPATH_ID_INT_MAX_m1 " WWIDMAX\n");
+	will_return(__wrap_fgets, "MPATHa WWID0\n");
+	will_return(__wrap_fgets, NULL);
+	expect_condlog(3, "No matching wwid [WWID2] in bindings file.\n");
+	rc = lookup_binding(NULL, "WWID2", &alias, "MPATH");
+	assert_int_equal(rc, INT_MAX);
+	assert_ptr_equal(alias, NULL);
+}
+#endif
+
+static int test_lookup_binding(void)
+{
+	const struct CMUnitTest tests[] = {
+		cmocka_unit_test(lb_empty),
+		cmocka_unit_test(lb_match_a),
+		cmocka_unit_test(lb_nomatch_a),
+		cmocka_unit_test(lb_match_c),
+		cmocka_unit_test(lb_nomatch_a_c),
+		cmocka_unit_test(lb_nomatch_c_a),
+		cmocka_unit_test(lb_nomatch_a_b),
+		cmocka_unit_test(lb_nomatch_a_b_bad),
+		cmocka_unit_test(lb_nomatch_b_a),
+#ifdef MPATH_ID_INT_MAX
+		cmocka_unit_test(lb_nomatch_int_max),
+		cmocka_unit_test(lb_nomatch_int_max_m1),
+#endif
+	};
+
+	return cmocka_run_group_tests(tests, NULL, NULL);
+}
+
+static void rl_empty(void **state)
+{
+	int rc;
+	char buf[WWID_SIZE];
+
+	buf[0] = '\0';
+	will_return(__wrap_fgets, NULL);
+	expect_condlog(3, "No matching alias [MPATHa] in bindings file.\n");
+	rc = rlookup_binding(NULL, buf, "MPATHa");
+	assert_int_equal(rc, -1);
+	assert_string_equal(buf, "");
+}
+
+static void rl_match_a(void **state)
+{
+	int rc;
+	char buf[WWID_SIZE];
+
+	buf[0] = '\0';
+	will_return(__wrap_fgets, "MPATHa WWID0\n");
+	expect_condlog(3, "Found matching alias [MPATHa] in bindings file.\n"
+		       "Setting wwid to WWID0\n");
+	rc = rlookup_binding(NULL, buf, "MPATHa");
+	assert_int_equal(rc, 0);
+	assert_string_equal(buf, "WWID0");
+}
+
+static void rl_nomatch_a(void **state)
+{
+	int rc;
+	char buf[WWID_SIZE];
+
+	buf[0] = '\0';
+	will_return(__wrap_fgets, "MPATHa WWID0\n");
+	will_return(__wrap_fgets, NULL);
+	expect_condlog(3, "No matching alias [MPATHb] in bindings file.\n");
+	rc = rlookup_binding(NULL, buf, "MPATHb");
+	assert_int_equal(rc, -1);
+	assert_string_equal(buf, "");
+}
+
+static void rl_malformed_a(void **state)
+{
+	int rc;
+	char buf[WWID_SIZE];
+
+	buf[0] = '\0';
+	will_return(__wrap_fgets, "MPATHa     \n");
+	will_return(__wrap_fgets, NULL);
+	expect_condlog(3, "Ignoring malformed line 1 in bindings file\n");
+	expect_condlog(3, "No matching alias [MPATHa] in bindings file.\n");
+	rc = rlookup_binding(NULL, buf, "MPATHa");
+	assert_int_equal(rc, -1);
+	assert_string_equal(buf, "");
+}
+
+static void rl_overlong_a(void **state)
+{
+	int rc;
+	char buf[WWID_SIZE];
+	char line[WWID_SIZE + 10];
+
+	snprintf(line, sizeof(line), "MPATHa ");
+	memset(line + strlen(line), 'W', sizeof(line) - 2 - strlen(line));
+	snprintf(line + sizeof(line) - 2, 2, "\n");
+
+	buf[0] = '\0';
+	will_return(__wrap_fgets, line);
+	will_return(__wrap_fgets, NULL);
+	expect_condlog(3, "Ignoring too large wwid at 1 in bindings file\n");
+	expect_condlog(3, "No matching alias [MPATHa] in bindings file.\n");
+	rc = rlookup_binding(NULL, buf, "MPATHa");
+	assert_int_equal(rc, -1);
+	assert_string_equal(buf, "");
+}
+
+static void rl_match_b(void **state)
+{
+	int rc;
+	char buf[WWID_SIZE];
+
+	buf[0] = '\0';
+	will_return(__wrap_fgets, "MPATHa WWID0\n");
+	will_return(__wrap_fgets, "MPATHz WWID26\n");
+	will_return(__wrap_fgets, "MPATHb WWID2\n");
+	expect_condlog(3, "Found matching alias [MPATHb] in bindings file.\n"
+		       "Setting wwid to WWID2\n");
+	rc = rlookup_binding(NULL, buf, "MPATHb");
+	assert_int_equal(rc, 0);
+	assert_string_equal(buf, "WWID2");
+}
+
+static int test_rlookup_binding(void)
+{
+	const struct CMUnitTest tests[] = {
+		cmocka_unit_test(rl_empty),
+		cmocka_unit_test(rl_match_a),
+		cmocka_unit_test(rl_nomatch_a),
+		cmocka_unit_test(rl_malformed_a),
+		cmocka_unit_test(rl_overlong_a),
+		cmocka_unit_test(rl_match_b),
+	};
+
+	return cmocka_run_group_tests(tests, NULL, NULL);
+}
+
+int main(void)
+{
+	int ret = 0;
+
+	ret += test_format_devname();
+	ret += test_scan_devname();
+	ret += test_lookup_binding();
+	ret += test_rlookup_binding();
+
+	return ret;
+}
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 03/72] libmultipath: alias.c: constify function arguments
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
  2019-10-12 21:27 ` [PATCH 01/72] multipath tests: move condlog test wrappers to separate file Martin Wilck
  2019-10-12 21:27 ` [PATCH 02/72] multipath tests: add tests for alias handling Martin Wilck
@ 2019-10-12 21:27 ` Martin Wilck
  2019-10-12 21:27 ` [PATCH 04/72] libmultipath: alias.c: use strlcpy(), and 2 minor fixes Martin Wilck
                   ` (68 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:27 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/alias.c | 29 ++++++++++++++++-------------
 libmultipath/alias.h | 12 +++++++-----
 2 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/libmultipath/alias.c b/libmultipath/alias.c
index fd6b7f91..5b05ff69 100644
--- a/libmultipath/alias.c
+++ b/libmultipath/alias.c
@@ -37,7 +37,7 @@
  */
 
 int
-valid_alias(char *alias)
+valid_alias(const char *alias)
 {
 	if (strchr(alias, '/') != NULL)
 		return 0;
@@ -46,7 +46,7 @@ valid_alias(char *alias)
 
 
 static int
-format_devname(char *name, int id, int len, char *prefix)
+format_devname(char *name, int id, int len, const char *prefix)
 {
 	int pos;
 	int prefix_len = strlen(prefix);
@@ -66,9 +66,9 @@ format_devname(char *name, int id, int len, char *prefix)
 }
 
 static int
-scan_devname(char *alias, char *prefix)
+scan_devname(const char *alias, const char *prefix)
 {
-	char *c;
+	const char *c;
 	int i, n = 0;
 
 	if (!prefix || strncmp(alias, prefix, strlen(prefix)))
@@ -97,7 +97,8 @@ scan_devname(char *alias, char *prefix)
 }
 
 static int
-lookup_binding(FILE *f, char *map_wwid, char **map_alias, char *prefix)
+lookup_binding(FILE *f, const char *map_wwid, char **map_alias,
+	       const char *prefix)
 {
 	char buf[LINE_MAX];
 	unsigned int line_nr = 0;
@@ -109,7 +110,8 @@ lookup_binding(FILE *f, char *map_wwid, char **map_alias, char *prefix)
 
 	rewind(f);
 	while (fgets(buf, LINE_MAX, f)) {
-		char *c, *alias, *wwid;
+		const char *alias, *wwid;
+		char *c;
 		int curr_id;
 
 		line_nr++;
@@ -154,7 +156,7 @@ lookup_binding(FILE *f, char *map_wwid, char **map_alias, char *prefix)
 }
 
 static int
-rlookup_binding(FILE *f, char *buff, char *map_alias, char *prefix)
+rlookup_binding(FILE *f, char *buff, const char *map_alias, const char *prefix)
 {
 	char line[LINE_MAX];
 	unsigned int line_nr = 0;
@@ -162,7 +164,8 @@ rlookup_binding(FILE *f, char *buff, char *map_alias, char *prefix)
 	buff[0] = '\0';
 
 	while (fgets(line, LINE_MAX, f)) {
-		char *c, *alias, *wwid;
+		char *c;
+		const char *alias, *wwid;
 
 		line_nr++;
 		c = strpbrk(line, "#\n\r");
@@ -197,7 +200,7 @@ rlookup_binding(FILE *f, char *buff, char *map_alias, char *prefix)
 }
 
 static char *
-allocate_binding(int fd, char *wwid, int id, char *prefix)
+allocate_binding(int fd, const char *wwid, int id, const char *prefix)
 {
 	char buf[LINE_MAX];
 	off_t offset;
@@ -243,8 +246,8 @@ allocate_binding(int fd, char *wwid, int id, char *prefix)
 }
 
 char *
-use_existing_alias (char *wwid, char *file, char *alias_old,
-		char *prefix, int bindings_read_only)
+use_existing_alias (const char *wwid, const char *file, const char *alias_old,
+		    const char *prefix, int bindings_read_only)
 {
 	char *alias = NULL;
 	int id = 0;
@@ -311,7 +314,7 @@ out:
 }
 
 char *
-get_user_friendly_alias(char *wwid, char *file, char *prefix,
+get_user_friendly_alias(const char *wwid, const char *file, const char *prefix,
 			int bindings_read_only)
 {
 	char *alias;
@@ -358,7 +361,7 @@ get_user_friendly_alias(char *wwid, char *file, char *prefix,
 }
 
 int
-get_user_friendly_wwid(char *alias, char *buff, char *file)
+get_user_friendly_wwid(const char *alias, char *buff, const char *file)
 {
 	int fd, unused;
 	FILE *f;
diff --git a/libmultipath/alias.h b/libmultipath/alias.h
index 95473ff9..7c4b302b 100644
--- a/libmultipath/alias.h
+++ b/libmultipath/alias.h
@@ -7,9 +7,11 @@
 "# alias wwid\n" \
 "#\n"
 
-int valid_alias(char *alias);
-char *get_user_friendly_alias(char *wwid, char *file, char *prefix,
+int valid_alias(const char *alias);
+char *get_user_friendly_alias(const char *wwid, const char *file,
+			      const char *prefix,
 			      int bindings_readonly);
-int get_user_friendly_wwid(char *alias, char *buff, char *file);
-char *use_existing_alias (char *wwid, char *file, char *alias_old,
-		char *prefix, int bindings_read_only);
+int get_user_friendly_wwid(const char *alias, char *buff, const char *file);
+char *use_existing_alias (const char *wwid, const char *file,
+			  const char *alias_old,
+			  const char *prefix, int bindings_read_only);
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 04/72] libmultipath: alias.c: use strlcpy(), and 2 minor fixes
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (2 preceding siblings ...)
  2019-10-12 21:27 ` [PATCH 03/72] libmultipath: alias.c: constify function arguments Martin Wilck
@ 2019-10-12 21:27 ` Martin Wilck
  2019-10-12 21:27 ` [PATCH 05/72] libmultipath: format_devname: avoid buffer overflow Martin Wilck
                   ` (67 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:27 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/alias.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libmultipath/alias.c b/libmultipath/alias.c
index 5b05ff69..412ab5b4 100644
--- a/libmultipath/alias.c
+++ b/libmultipath/alias.c
@@ -10,6 +10,7 @@
 #include <stdio.h>
 
 #include "debug.h"
+#include "util.h"
 #include "uxsock.h"
 #include "alias.h"
 #include "file.h"
@@ -189,8 +190,7 @@ rlookup_binding(FILE *f, char *buff, const char *map_alias, const char *prefix)
 		if (strcmp(alias, map_alias) == 0){
 			condlog(3, "Found matching alias [%s] in bindings file."
 				"\nSetting wwid to %s", alias, wwid);
-			strncpy(buff, wwid, WWID_SIZE);
-			buff[WWID_SIZE - 1] = '\0';
+			strlcpy(buff, wwid, WWID_SIZE);
 			return 0;
 		}
 	}
@@ -214,7 +214,7 @@ allocate_binding(int fd, const char *wwid, int id, const char *prefix)
 
 	i = format_devname(buf, id, LINE_MAX, prefix);
 	c = buf + i;
-	snprintf(c,LINE_MAX - i, " %s\n", wwid);
+	snprintf(c, LINE_MAX - i, " %s\n", wwid);
 	buf[LINE_MAX - 1] = '\0';
 
 	offset = lseek(fd, 0, SEEK_END);
@@ -265,7 +265,7 @@ use_existing_alias (const char *wwid, const char *file, const char *alias_old,
 		close(fd);
 		return NULL;
 	}
-	/* lookup the binding. if it exsists, the wwid will be in buff
+	/* lookup the binding. if it exists, the wwid will be in buff
 	 * either way, id contains the id for the alias
 	 */
 	rlookup_binding(f, buff, alias_old, prefix);
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 05/72] libmultipath: format_devname: avoid buffer overflow
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (3 preceding siblings ...)
  2019-10-12 21:27 ` [PATCH 04/72] libmultipath: alias.c: use strlcpy(), and 2 minor fixes Martin Wilck
@ 2019-10-12 21:27 ` Martin Wilck
  2019-10-12 21:27 ` [PATCH 06/72] libmultipath: scan_devname: fix int overflow detection Martin Wilck
                   ` (66 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:27 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

If the buffer was too short, the current code could write
the terminating 0 byte after the actual buffer.

Also, assert sufficient buffer length, and positive id.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/alias.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/libmultipath/alias.c b/libmultipath/alias.c
index 412ab5b4..0fb206d1 100644
--- a/libmultipath/alias.c
+++ b/libmultipath/alias.c
@@ -52,18 +52,24 @@ format_devname(char *name, int id, int len, const char *prefix)
 	int pos;
 	int prefix_len = strlen(prefix);
 
-	memset(name,0, len);
+	if (len <= prefix_len + 1 || id <= 0)
+		return -1;
+
+	memset(name, 0, len);
 	strcpy(name, prefix);
-	for (pos = len - 1; pos >= prefix_len; pos--) {
+	name[len - 1] = '\0';
+	for (pos = len - 2; pos >= prefix_len; pos--) {
 		id--;
 		name[pos] = 'a' + id % 26;
 		if (id < 26)
 			break;
 		id /= 26;
 	}
+	if (pos < prefix_len)
+		return -1;
+
 	memmove(name + prefix_len, name + pos, len - pos);
-	name[prefix_len + len - pos] = '\0';
-	return (prefix_len + len - pos);
+	return (prefix_len + len - pos - 1);
 }
 
 static int
@@ -213,6 +219,9 @@ allocate_binding(int fd, const char *wwid, int id, const char *prefix)
 	}
 
 	i = format_devname(buf, id, LINE_MAX, prefix);
+	if (i == -1)
+		return NULL;
+
 	c = buf + i;
 	snprintf(c, LINE_MAX - i, " %s\n", wwid);
 	buf[LINE_MAX - 1] = '\0';
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 06/72] libmultipath: scan_devname: fix int overflow detection
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (4 preceding siblings ...)
  2019-10-12 21:27 ` [PATCH 05/72] libmultipath: format_devname: avoid buffer overflow Martin Wilck
@ 2019-10-12 21:27 ` Martin Wilck
  2019-10-12 21:27 ` [PATCH 07/72] libmultipath: lookup_binding(): don't rely on int overflow Martin Wilck
                   ` (65 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:27 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

For an int n, it's possible that n > 0 and (26 * n) > 0, but
and still 26 * n overflows the int.
E.g. n = 0x0ec4ec4e; 26 * n = 0x17fffffec, truncated to 32 bit
yields 0x7fffffec, which is > 0.

And anyway, relying on a signed int overflow to detect a problem
is wrong, as the result of such operations is undefined in C.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/alias.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libmultipath/alias.c b/libmultipath/alias.c
index 0fb206d1..a96ba5cc 100644
--- a/libmultipath/alias.c
+++ b/libmultipath/alias.c
@@ -77,6 +77,7 @@ scan_devname(const char *alias, const char *prefix)
 {
 	const char *c;
 	int i, n = 0;
+	static const int last_26 = INT_MAX / 26;
 
 	if (!prefix || strncmp(alias, prefix, strlen(prefix)))
 		return -1;
@@ -93,9 +94,9 @@ scan_devname(const char *alias, const char *prefix)
 		if (*c < 'a' || *c > 'z')
 			return -1;
 		i = *c - 'a';
-		n = ( n * 26 ) + i;
-		if (n < 0)
+		if (n > last_26 || (n == last_26 && i >= INT_MAX % 26))
 			return -1;
+		n = n * 26 + i;
 		c++;
 		n++;
 	}
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 07/72] libmultipath: lookup_binding(): don't rely on int overflow
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (5 preceding siblings ...)
  2019-10-12 21:27 ` [PATCH 06/72] libmultipath: scan_devname: fix int overflow detection Martin Wilck
@ 2019-10-12 21:27 ` Martin Wilck
  2019-10-12 21:27 ` [PATCH 08/72] libmultipath: rlookup_binding(): removed unused parameter Martin Wilck
                   ` (64 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:27 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

lookup_binding() would return a negative result and issue an error
message if variable "id" became negative. But id is only incremented,
starting from 1. Relying on an int overflow is wrong, because the result
is undefined behavior in C. Also, an overflow might as well (actually, more
likely) occur if biggest_id == INT_MAX.

Also, lookup_binding() would return 0 both in an error case and if a
matching wwid was found. While the two cases could be distinguished
by checking if *map_alias was NULL after return, this is highly
non-standard and confusing. Return -1 in error case.

Because of the semantics of lookup_binding(), the test for "id" before calling
allocate_binding() in get_user_friendly_alias() is redundant.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/alias.c | 41 ++++++++++++++++++++++++++++++-----------
 1 file changed, 30 insertions(+), 11 deletions(-)

diff --git a/libmultipath/alias.c b/libmultipath/alias.c
index a96ba5cc..ac342a54 100644
--- a/libmultipath/alias.c
+++ b/libmultipath/alias.c
@@ -104,6 +104,13 @@ scan_devname(const char *alias, const char *prefix)
 	return n;
 }
 
+/*
+ * Returns: 0   if matching entry in WWIDs file found
+ *         -1   if an error occurs
+ *         >0   a free ID that could be used for the WWID at hand
+ * *map_alias is set to a freshly allocated string with the matching alias if
+ * the function returns 0, or to NULL otherwise.
+ */
 static int
 lookup_binding(FILE *f, const char *map_wwid, char **map_alias,
 	       const char *prefix)
@@ -130,8 +137,14 @@ lookup_binding(FILE *f, const char *map_wwid, char **map_alias,
 		if (!alias) /* blank line */
 			continue;
 		curr_id = scan_devname(alias, prefix);
-		if (curr_id == id)
-			id++;
+		if (curr_id == id) {
+			if (id < INT_MAX)
+				id++;
+			else {
+				id = -1;
+				break;
+			}
+		}
 		if (curr_id > biggest_id)
 			biggest_id = curr_id;
 		if (curr_id > id && curr_id < smallest_bigger_id)
@@ -147,20 +160,26 @@ lookup_binding(FILE *f, const char *map_wwid, char **map_alias,
 			condlog(3, "Found matching wwid [%s] in bindings file."
 				" Setting alias to %s", wwid, alias);
 			*map_alias = strdup(alias);
-			if (*map_alias == NULL)
+			if (*map_alias == NULL) {
 				condlog(0, "Cannot copy alias from bindings "
-					"file : %s", strerror(errno));
+					"file: out of memory");
+				return -1;
+			}
 			return 0;
 		}
 	}
-	condlog(3, "No matching wwid [%s] in bindings file.", map_wwid);
+	if (id >= smallest_bigger_id) {
+		if (biggest_id < INT_MAX)
+			id = biggest_id + 1;
+		else
+			id = -1;
+	}
 	if (id < 0) {
 		condlog(0, "no more available user_friendly_names");
-		return 0;
-	}
-	if (id < smallest_bigger_id)
-		return id;
-	return biggest_id + 1;
+		return -1;
+	} else
+		condlog(3, "No matching wwid [%s] in bindings file.", map_wwid);
+	return id;
 }
 
 static int
@@ -363,7 +382,7 @@ get_user_friendly_alias(const char *wwid, const char *file, const char *prefix,
 		return NULL;
 	}
 
-	if (!alias && can_write && !bindings_read_only && id)
+	if (can_write && !bindings_read_only && !alias)
 		alias = allocate_binding(fd, wwid, id, prefix);
 
 	fclose(f);
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 08/72] libmultipath: rlookup_binding(): removed unused parameter
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (6 preceding siblings ...)
  2019-10-12 21:27 ` [PATCH 07/72] libmultipath: lookup_binding(): don't rely on int overflow Martin Wilck
@ 2019-10-12 21:27 ` Martin Wilck
  2019-10-12 21:27 ` [PATCH 09/72] libmultipath: allocate_binding(): error out for id=0 Martin Wilck
                   ` (63 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:27 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

The parameter "prefix" is unused in this function.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/alias.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libmultipath/alias.c b/libmultipath/alias.c
index ac342a54..767800d0 100644
--- a/libmultipath/alias.c
+++ b/libmultipath/alias.c
@@ -183,7 +183,7 @@ lookup_binding(FILE *f, const char *map_wwid, char **map_alias,
 }
 
 static int
-rlookup_binding(FILE *f, char *buff, const char *map_alias, const char *prefix)
+rlookup_binding(FILE *f, char *buff, const char *map_alias)
 {
 	char line[LINE_MAX];
 	unsigned int line_nr = 0;
@@ -297,7 +297,7 @@ use_existing_alias (const char *wwid, const char *file, const char *alias_old,
 	/* lookup the binding. if it exists, the wwid will be in buff
 	 * either way, id contains the id for the alias
 	 */
-	rlookup_binding(f, buff, alias_old, prefix);
+	rlookup_binding(f, buff, alias_old);
 
 	if (strlen(buff) > 0) {
 		/* if buff is our wwid, it's already
@@ -412,7 +412,7 @@ get_user_friendly_wwid(const char *alias, char *buff, const char *file)
 		return -1;
 	}
 
-	rlookup_binding(f, buff, alias, NULL);
+	rlookup_binding(f, buff, alias);
 	if (!strlen(buff)) {
 		fclose(f);
 		return -1;
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 09/72] libmultipath: allocate_binding(): error out for id=0
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (7 preceding siblings ...)
  2019-10-12 21:27 ` [PATCH 08/72] libmultipath: rlookup_binding(): removed unused parameter Martin Wilck
@ 2019-10-12 21:27 ` Martin Wilck
  2019-10-12 21:27 ` [PATCH 10/72] libmultipath: allocate_binding(): detect line overflow Martin Wilck
                   ` (62 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:27 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Only for positive id can we allocate a binding. All current
callers make sure the id is positive. Yet, fix the implementation
in allocate_binding(), too.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/alias.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libmultipath/alias.c b/libmultipath/alias.c
index 767800d0..2df34f32 100644
--- a/libmultipath/alias.c
+++ b/libmultipath/alias.c
@@ -233,8 +233,9 @@ allocate_binding(int fd, const char *wwid, int id, const char *prefix)
 	char *alias, *c;
 	int i;
 
-	if (id < 0) {
-		condlog(0, "Bindings file full. Cannot allocate new binding");
+	if (id <= 0) {
+		condlog(0, "%s: cannot allocate new binding for id %d",
+			__func__, id);
 		return NULL;
 	}
 
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 10/72] libmultipath: allocate_binding(): detect line overflow
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (8 preceding siblings ...)
  2019-10-12 21:27 ` [PATCH 09/72] libmultipath: allocate_binding(): error out for id=0 Martin Wilck
@ 2019-10-12 21:27 ` Martin Wilck
  2019-10-12 21:27 ` [PATCH 11/72] multipath tests: alias: add tests for allocate_binding() Martin Wilck
                   ` (61 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:27 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Be sure not to truncate the WWID. This shouldn't happen under
normal circumstances, but play it safe.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/alias.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libmultipath/alias.c b/libmultipath/alias.c
index 2df34f32..15bbc8ed 100644
--- a/libmultipath/alias.c
+++ b/libmultipath/alias.c
@@ -244,7 +244,10 @@ allocate_binding(int fd, const char *wwid, int id, const char *prefix)
 		return NULL;
 
 	c = buf + i;
-	snprintf(c, LINE_MAX - i, " %s\n", wwid);
+	if (snprintf(c, LINE_MAX - i, " %s\n", wwid) >= LINE_MAX - i) {
+		condlog(1, "%s: line too long for %s\n", __func__, wwid);
+		return NULL;
+	}
 	buf[LINE_MAX - 1] = '\0';
 
 	offset = lseek(fd, 0, SEEK_END);
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 11/72] multipath tests: alias: add tests for allocate_binding()
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (9 preceding siblings ...)
  2019-10-12 21:27 ` [PATCH 10/72] libmultipath: allocate_binding(): detect line overflow Martin Wilck
@ 2019-10-12 21:27 ` Martin Wilck
  2019-10-12 21:27 ` [PATCH 12/72] multipath tests: alias: add format/scan test Martin Wilck
                   ` (60 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:27 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 tests/alias.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 124 insertions(+)

diff --git a/tests/alias.c b/tests/alias.c
index 32fdc697..170ebbeb 100644
--- a/tests/alias.c
+++ b/tests/alias.c
@@ -5,6 +5,7 @@
 #include "util.h"
 #include "alias.h"
 #include "test-log.h"
+#include <errno.h>
 
 #include "globals.c"
 #include "../libmultipath/alias.c"
@@ -30,6 +31,36 @@ char *__wrap_fgets(char *buf, int n, FILE *stream)
 	return buf;
 }
 
+static int __set_errno(int err)
+{
+	if (err >= 0) {
+		errno = 0;
+		return err;
+	} else {
+		errno = -err;
+		return -1;
+	}
+}
+
+off_t __wrap_lseek(int fd, off_t offset, int whence)
+{
+	return __set_errno(mock_type(int));
+
+}
+
+ssize_t __wrap_write(int fd, const void *buf, size_t count)
+{
+	check_expected(count);
+	check_expected(buf);
+	return __set_errno(mock_type(int));
+}
+
+int __wrap_ftruncate(int fd, off_t length)
+{
+	check_expected(length);
+	return __set_errno(mock_type(int));
+}
+
 static void fd_mpatha(void **state)
 {
 	char buf[32];
@@ -577,6 +608,98 @@ static int test_rlookup_binding(void)
 	return cmocka_run_group_tests(tests, NULL, NULL);
 }
 
+static void al_a(void **state)
+{
+	static const char ln[] = "MPATHa WWIDa\n";
+	char *alias;
+
+	will_return(__wrap_lseek, 0);
+	expect_value(__wrap_write, count, strlen(ln));
+	expect_string(__wrap_write, buf, ln);
+	will_return(__wrap_write, strlen(ln));
+	expect_condlog(3, "Created new binding [MPATHa] for WWID [WWIDa]\n");
+
+	alias = allocate_binding(0, "WWIDa", 1, "MPATH");
+	assert_ptr_not_equal(alias, NULL);
+	assert_string_equal(alias, "MPATHa");
+}
+
+static void al_zz(void **state)
+{
+	static const char ln[] = "MPATHzz WWIDzz\n";
+	char *alias;
+
+	will_return(__wrap_lseek, 0);
+	expect_value(__wrap_write, count, strlen(ln));
+	expect_string(__wrap_write, buf, ln);
+	will_return(__wrap_write, strlen(ln));
+	expect_condlog(3, "Created new binding [MPATHzz] for WWID [WWIDzz]\n");
+
+	alias = allocate_binding(0, "WWIDzz", 26*26 + 26, "MPATH");
+	assert_ptr_not_equal(alias, NULL);
+	assert_string_equal(alias, "MPATHzz");
+}
+
+static void al_0(void **state)
+{
+	char *alias;
+
+	expect_condlog(0, "allocate_binding: cannot allocate new binding for id 0\n");
+	alias = allocate_binding(0, "WWIDa", 0, "MPATH");
+	assert_ptr_equal(alias, NULL);
+}
+
+static void al_m2(void **state)
+{
+	char *alias;
+
+	expect_condlog(0, "allocate_binding: cannot allocate new binding for id -2\n");
+	alias = allocate_binding(0, "WWIDa", -2, "MPATH");
+	assert_ptr_equal(alias, NULL);
+}
+
+static void al_lseek_err(void **state)
+{
+	char *alias;
+
+	will_return(__wrap_lseek, -ENODEV);
+	expect_condlog(0, "Cannot seek to end of bindings file : No such device\n");
+	alias = allocate_binding(0, "WWIDa", 1, "MPATH");
+	assert_ptr_equal(alias, NULL);
+}
+
+static void al_write_err(void **state)
+{
+	static const char ln[] = "MPATHa WWIDa\n";
+	const int offset = 20;
+	char *alias;
+
+	will_return(__wrap_lseek, offset);
+	expect_value(__wrap_write, count, strlen(ln));
+	expect_string(__wrap_write, buf, ln);
+	will_return(__wrap_write, strlen(ln) - 1);
+	expect_value(__wrap_ftruncate, length, offset);
+	will_return(__wrap_ftruncate, 0);
+	expect_condlog(0, "Cannot write binding to bindings file : Success\n");
+
+	alias = allocate_binding(0, "WWIDa", 1, "MPATH");
+	assert_ptr_equal(alias, NULL);
+}
+
+static int test_allocate_binding(void)
+{
+	const struct CMUnitTest tests[] = {
+		cmocka_unit_test(al_a),
+		cmocka_unit_test(al_zz),
+		cmocka_unit_test(al_0),
+		cmocka_unit_test(al_m2),
+		cmocka_unit_test(al_lseek_err),
+		cmocka_unit_test(al_write_err),
+	};
+
+	return cmocka_run_group_tests(tests, NULL, NULL);
+}
+
 int main(void)
 {
 	int ret = 0;
@@ -585,6 +708,7 @@ int main(void)
 	ret += test_scan_devname();
 	ret += test_lookup_binding();
 	ret += test_rlookup_binding();
+	ret += test_allocate_binding();
 
 	return ret;
 }
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 12/72] multipath tests: alias: add format/scan test
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (10 preceding siblings ...)
  2019-10-12 21:27 ` [PATCH 11/72] multipath tests: alias: add tests for allocate_binding() Martin Wilck
@ 2019-10-12 21:27 ` Martin Wilck
  2019-10-12 21:27 ` [PATCH 13/72] libmultipath: alias.c: prepare for cancel-safe allocation Martin Wilck
                   ` (59 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:27 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Test scan_devname(format_devname(id)) == id.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 tests/alias.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/tests/alias.c b/tests/alias.c
index 170ebbeb..30414db0 100644
--- a/tests/alias.c
+++ b/tests/alias.c
@@ -297,6 +297,34 @@ static void sd_max_p1(void **state)
 }
 #endif
 
+static void sd_fd_many(void **state)
+{
+	char buf[32];
+	int rc, i;
+
+	for (i = 1; i < 5000; i++) {
+		rc = format_devname(buf, i, sizeof(buf), "MPATH");
+		assert_in_range(rc, 6, 8);
+		rc = scan_devname(buf, "MPATH");
+		assert_int_equal(rc, i);
+	}
+}
+
+static void sd_fd_random(void **state)
+{
+	char buf[32];
+	int rc, i, n;
+
+	srandom(1);
+	for (i = 1; i < 1000; i++) {
+		n = random() & 0xffff;
+		rc = format_devname(buf, n, sizeof(buf), "MPATH");
+		assert_in_range(rc, 6, 9);
+		rc = scan_devname(buf, "MPATH");
+		assert_int_equal(rc, n);
+	}
+}
+
 static int test_scan_devname(void)
 {
 	const struct CMUnitTest tests[] = {
@@ -314,6 +342,8 @@ static int test_scan_devname(void)
 		cmocka_unit_test(sd_max),
 		cmocka_unit_test(sd_max_p1),
 #endif
+		cmocka_unit_test(sd_fd_many),
+		cmocka_unit_test(sd_fd_random),
 	};
 
 	return cmocka_run_group_tests(tests, NULL, NULL);
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 13/72] libmultipath: alias.c: prepare for cancel-safe allocation
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (11 preceding siblings ...)
  2019-10-12 21:27 ` [PATCH 12/72] multipath tests: alias: add format/scan test Martin Wilck
@ 2019-10-12 21:27 ` Martin Wilck
  2019-10-30 14:47   ` Benjamin Marzinski
  2019-10-12 21:27 ` [PATCH 14/72] multipath tests: use -lpthread for alias test Martin Wilck
                   ` (58 subsequent siblings)
  71 siblings, 1 reply; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:27 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

In functions that return newly allocated memory, avoid cancellation
points before returning, and if that's not possible, guard the code
that contains cancellation points with a cleanup function calling
free(), and immediately before returning, call pthread_cleanup_pop(0).

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/alias.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/libmultipath/alias.c b/libmultipath/alias.c
index 15bbc8ed..0fc9e542 100644
--- a/libmultipath/alias.c
+++ b/libmultipath/alias.c
@@ -268,13 +268,12 @@ allocate_binding(int fd, const char *wwid, int id, const char *prefix)
 	c = strchr(buf, ' ');
 	if (c)
 		*c = '\0';
+
+	condlog(3, "Created new binding [%s] for WWID [%s]", buf, wwid);
 	alias = strdup(buf);
 	if (alias == NULL)
-		condlog(0, "cannot copy new alias from bindings file : %s",
-			strerror(errno));
-	else
-		condlog(3, "Created new binding [%s] for WWID [%s]", alias,
-			wwid);
+		condlog(0, "cannot copy new alias from bindings file: out of memory");
+
 	return alias;
 }
 
@@ -342,7 +341,9 @@ use_existing_alias (const char *wwid, const char *file, const char *alias_old,
 	}
 
 out:
+	pthread_cleanup_push(free, alias);
 	fclose(f);
+	pthread_cleanup_pop(0);
 	return alias;
 }
 
@@ -378,18 +379,19 @@ get_user_friendly_alias(const char *wwid, const char *file, const char *prefix,
 		return NULL;
 	}
 
+	pthread_cleanup_push(free, alias);
+
 	if (fflush(f) != 0) {
 		condlog(0, "cannot fflush bindings file stream : %s",
 			strerror(errno));
 		free(alias);
-		fclose(f);
-		return NULL;
-	}
-
-	if (can_write && !bindings_read_only && !alias)
+		alias = NULL;
+	} else if (can_write && !bindings_read_only && !alias)
 		alias = allocate_binding(fd, wwid, id, prefix);
 
 	fclose(f);
+
+	pthread_cleanup_pop(0);
 	return alias;
 }
 
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 14/72] multipath tests: use -lpthread for alias test
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (12 preceding siblings ...)
  2019-10-12 21:27 ` [PATCH 13/72] libmultipath: alias.c: prepare for cancel-safe allocation Martin Wilck
@ 2019-10-12 21:27 ` Martin Wilck
  2019-10-12 21:27 ` [PATCH 15/72] libmultipath: path_discovery: handle libudev errors Martin Wilck
                   ` (57 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:27 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

This becomes necessary because of the previous patch.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 tests/Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/Makefile b/tests/Makefile
index 0ce318c6..0dce8571 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -29,6 +29,7 @@ blacklist-test_LIBDEPS := -ludev
 vpd-test_OBJDEPS :=  ../libmultipath/discovery.o
 vpd-test_LIBDEPS := -ludev -lpthread -ldl
 alias-test_TESTDEPS := test-log.o
+alias-test_LIBDEPS := -lpthread -ldl
 
 lib/libchecktur.so:
 	mkdir lib
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 15/72] libmultipath: path_discovery: handle libudev errors
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (13 preceding siblings ...)
  2019-10-12 21:27 ` [PATCH 14/72] multipath tests: use -lpthread for alias test Martin Wilck
@ 2019-10-12 21:27 ` Martin Wilck
  2019-10-12 21:27 ` [PATCH 16/72] libmultipath: make path_discovery() pthread_cancel()-safe Martin Wilck
                   ` (56 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:27 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

pass out if any libudev helpers return an error code.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/discovery.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
index 72f455e8..e68b0e9f 100644
--- a/libmultipath/discovery.c
+++ b/libmultipath/discovery.c
@@ -148,15 +148,19 @@ path_discovery (vector pathvec, int flag)
 	struct udev_device *udevice;
 	struct config *conf;
 	const char *devpath;
-	int num_paths = 0, total_paths = 0;
+	int num_paths = 0, total_paths = 0, ret;
 
 	udev_iter = udev_enumerate_new(udev);
 	if (!udev_iter)
 		return -ENOMEM;
 
-	udev_enumerate_add_match_subsystem(udev_iter, "block");
-	udev_enumerate_add_match_is_initialized(udev_iter);
-	udev_enumerate_scan_devices(udev_iter);
+	if (udev_enumerate_add_match_subsystem(udev_iter, "block") < 0 ||
+	    udev_enumerate_add_match_is_initialized(udev_iter) < 0 ||
+	    udev_enumerate_scan_devices(udev_iter) < 0) {
+		condlog(1, "%s: error setting up udev_enumerate: %m", __func__);
+		ret = -1;
+		goto out;
+	}
 
 	udev_list_entry_foreach(entry,
 				udev_enumerate_get_list_entry(udev_iter)) {
@@ -180,9 +184,11 @@ path_discovery (vector pathvec, int flag)
 		}
 		udev_device_unref(udevice);
 	}
+	ret = total_paths - num_paths;
+out:
 	udev_enumerate_unref(udev_iter);
 	condlog(4, "Discovered %d/%d paths", num_paths, total_paths);
-	return (total_paths - num_paths);
+	return ret;
 }
 
 #define declare_sysfs_get_str(fname)					\
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 16/72] libmultipath: make path_discovery() pthread_cancel()-safe
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (14 preceding siblings ...)
  2019-10-12 21:27 ` [PATCH 15/72] libmultipath: path_discovery: handle libudev errors Martin Wilck
@ 2019-10-12 21:27 ` Martin Wilck
  2019-10-30 14:53   ` Benjamin Marzinski
  2019-10-12 21:27 ` [PATCH 17/72] libmultipath: uevent_listen(): fix poll() retval check Martin Wilck
                   ` (55 subsequent siblings)
  71 siblings, 1 reply; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:27 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

The udev_enumerate and udev_device refs wouldn't be released
if the thread was cancelled. Fix it.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/discovery.c | 51 +++++++++++++++++++++++++++++++---------
 1 file changed, 40 insertions(+), 11 deletions(-)

diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
index e68b0e9f..d217ca92 100644
--- a/libmultipath/discovery.c
+++ b/libmultipath/discovery.c
@@ -140,19 +140,47 @@ path_discover (vector pathvec, struct config * conf,
 	return pathinfo(pp, conf, flag);
 }
 
+static void cleanup_udev_enumerate_ptr(void *arg)
+{
+	struct udev_enumerate *ue;
+
+	if (!arg)
+		return;
+	ue = *((struct udev_enumerate**) arg);
+	if (ue)
+		(void)udev_enumerate_unref(ue);
+}
+
+static void cleanup_udev_device_ptr(void *arg)
+{
+	struct udev_device *ud;
+
+	if (!arg)
+		return;
+	ud = *((struct udev_device**) arg);
+	if (ud)
+		(void)udev_device_unref(ud);
+}
+
 int
 path_discovery (vector pathvec, int flag)
 {
-	struct udev_enumerate *udev_iter;
+	struct udev_enumerate *udev_iter = NULL;
 	struct udev_list_entry *entry;
-	struct udev_device *udevice;
+	struct udev_device *udevice = NULL;
 	struct config *conf;
-	const char *devpath;
 	int num_paths = 0, total_paths = 0, ret;
 
+	pthread_cleanup_push(cleanup_udev_enumerate_ptr, &udev_iter);
+	pthread_cleanup_push(cleanup_udev_device_ptr, &udevice);
+	conf = get_multipath_config();
+	pthread_cleanup_push(put_multipath_config, conf);
+
 	udev_iter = udev_enumerate_new(udev);
-	if (!udev_iter)
-		return -ENOMEM;
+	if (!udev_iter) {
+		ret = -ENOMEM;
+		goto out;
+	}
 
 	if (udev_enumerate_add_match_subsystem(udev_iter, "block") < 0 ||
 	    udev_enumerate_add_match_is_initialized(udev_iter) < 0 ||
@@ -165,6 +193,8 @@ path_discovery (vector pathvec, int flag)
 	udev_list_entry_foreach(entry,
 				udev_enumerate_get_list_entry(udev_iter)) {
 		const char *devtype;
+		const char *devpath;
+
 		devpath = udev_list_entry_get_name(entry);
 		condlog(4, "Discover device %s", devpath);
 		udevice = udev_device_new_from_syspath(udev, devpath);
@@ -175,19 +205,18 @@ path_discovery (vector pathvec, int flag)
 		devtype = udev_device_get_devtype(udevice);
 		if(devtype && !strncmp(devtype, "disk", 4)) {
 			total_paths++;
-			conf = get_multipath_config();
-			pthread_cleanup_push(put_multipath_config, conf);
 			if (path_discover(pathvec, conf,
 					  udevice, flag) == PATHINFO_OK)
 				num_paths++;
-			pthread_cleanup_pop(1);
 		}
-		udev_device_unref(udevice);
+		udevice = udev_device_unref(udevice);
 	}
 	ret = total_paths - num_paths;
-out:
-	udev_enumerate_unref(udev_iter);
 	condlog(4, "Discovered %d/%d paths", num_paths, total_paths);
+out:
+	pthread_cleanup_pop(1);
+	pthread_cleanup_pop(1);
+	pthread_cleanup_pop(1);
 	return ret;
 }
 
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 17/72] libmultipath: uevent_listen(): fix poll() retval check
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (15 preceding siblings ...)
  2019-10-12 21:27 ` [PATCH 16/72] libmultipath: make path_discovery() pthread_cancel()-safe Martin Wilck
@ 2019-10-12 21:27 ` Martin Wilck
  2019-10-12 21:27 ` [PATCH 18/72] libmultipath: replace_wwids(): fix possible fd leak Martin Wilck
                   ` (54 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:27 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Only check revents if poll() returns a positive value.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/uevent.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libmultipath/uevent.c b/libmultipath/uevent.c
index 8f7b2ef5..f128ced2 100644
--- a/libmultipath/uevent.c
+++ b/libmultipath/uevent.c
@@ -853,7 +853,7 @@ int uevent_listen(struct udev *udev)
 		poll_timeout = timeout * 1000;
 		errno = 0;
 		fdcount = poll(&ev_poll, 1, poll_timeout);
-		if (fdcount && ev_poll.revents & POLLIN) {
+		if (fdcount > 0 && ev_poll.revents & POLLIN) {
 			timeout = uevent_burst(&start_time, events + 1) ? 1 : 0;
 			dev = udev_monitor_receive_device(monitor);
 			if (!dev) {
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 18/72] libmultipath: replace_wwids(): fix possible fd leak
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (16 preceding siblings ...)
  2019-10-12 21:27 ` [PATCH 17/72] libmultipath: uevent_listen(): fix poll() retval check Martin Wilck
@ 2019-10-12 21:27 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 19/72] libmultipath: remove_wwids(): fix possible leaks Martin Wilck
                   ` (53 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:27 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

... in case the thread is cancelled.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/wwids.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libmultipath/wwids.c b/libmultipath/wwids.c
index ef748125..f69ed6f5 100644
--- a/libmultipath/wwids.c
+++ b/libmultipath/wwids.c
@@ -7,6 +7,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
+#include "util.h"
 #include "checkers.h"
 #include "vector.h"
 #include "structs.h"
@@ -87,7 +88,8 @@ write_out_wwid(int fd, char *wwid) {
 int
 replace_wwids(vector mp)
 {
-	int i, fd, can_write;
+	int i, can_write;
+	long fd;
 	struct multipath * mpp;
 	size_t len;
 	int ret = -1;
@@ -99,6 +101,8 @@ replace_wwids(vector mp)
 	pthread_cleanup_pop(1);
 	if (fd < 0)
 		goto out;
+
+	pthread_cleanup_push(close_fd, (void*)fd);
 	if (!can_write) {
 		condlog(0, "cannot replace wwids. wwids file is read-only");
 		goto out_file;
@@ -132,7 +136,7 @@ replace_wwids(vector mp)
 	}
 	ret = 0;
 out_file:
-	close(fd);
+	pthread_cleanup_pop(1);
 out:
 	return ret;
 }
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 19/72] libmultipath: remove_wwids(): fix possible leaks
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (17 preceding siblings ...)
  2019-10-12 21:27 ` [PATCH 18/72] libmultipath: replace_wwids(): fix possible fd leak Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 20/72] libmultipath: _init_foreign(): fix possible memory leak Martin Wilck
                   ` (52 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

... of fd and memory.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/wwids.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/libmultipath/wwids.c b/libmultipath/wwids.c
index f69ed6f5..d02a7072 100644
--- a/libmultipath/wwids.c
+++ b/libmultipath/wwids.c
@@ -195,7 +195,8 @@ do_remove_wwid(int fd, char *str) {
 
 int
 remove_wwid(char *wwid) {
-	int fd, len, can_write;
+	long fd;
+	int len, can_write;
 	char *str;
 	int ret = -1;
 	struct config *conf;
@@ -207,8 +208,10 @@ remove_wwid(char *wwid) {
 			strerror(errno));
 		return -1;
 	}
+	pthread_cleanup_push(free, str);
 	if (snprintf(str, len, "/%s/\n", wwid) >= len) {
 		condlog(0, "string overflow trying to remove wwid");
+		ret = -1;
 		goto out;
 	}
 	condlog(3, "removing line '%s' from wwids file", str);
@@ -216,18 +219,22 @@ remove_wwid(char *wwid) {
 	pthread_cleanup_push(put_multipath_config, conf);
 	fd = open_file(conf->wwids_file, &can_write, WWIDS_FILE_HEADER);
 	pthread_cleanup_pop(1);
-	if (fd < 0)
+
+	if (fd < 0) {
+		ret = -1;
 		goto out;
-	if (!can_write) {
-		condlog(0, "cannot remove wwid. wwids file is read-only");
-		goto out_file;
 	}
-	ret = do_remove_wwid(fd, str);
 
-out_file:
-	close(fd);
+	pthread_cleanup_push(close_fd, (void*)fd);
+	if (!can_write) {
+		ret = -1;
+		condlog(0, "cannot remove wwid. wwids file is read-only");
+	} else
+		ret = do_remove_wwid(fd, str);
+	pthread_cleanup_pop(1);
 out:
-	free(str);
+	/* free(str) */
+	pthread_cleanup_pop(1);
 	return ret;
 }
 
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 20/72] libmultipath: _init_foreign(): fix possible memory leak
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (18 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 19/72] libmultipath: remove_wwids(): fix possible leaks Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 21/72] libmultipath: process_config_dir(): remove unused argument Martin Wilck
                   ` (51 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

free_pre() wasn't called if scandir() failed. Fix it.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/foreign.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/libmultipath/foreign.c b/libmultipath/foreign.c
index 4b34e141..9ef8ad19 100644
--- a/libmultipath/foreign.c
+++ b/libmultipath/foreign.c
@@ -148,7 +148,7 @@ static int _init_foreign(const char *multipath_dir, const char *enable)
 			(void)regerror(r, enable_re, errbuf, sizeof(errbuf));
 			condlog (2, "%s: error compiling enable_foreign = \"%s\": \"%s\"",
 				 __func__, str, errbuf);
-			free_pre(&enable_re);
+			goto out_free_pre;
 		}
 	}
 
@@ -157,13 +157,13 @@ static int _init_foreign(const char *multipath_dir, const char *enable)
 	if (r == 0) {
 		condlog(3, "%s: no foreign multipath libraries found",
 			__func__);
-		return 0;
+		goto out_free_pre;
 	} else if (r < 0) {
-		r = errno;
-		condlog(1, "%s: error %d scanning foreign multipath libraries",
-			__func__, r);
+		r = -errno;
+		condlog(1, "%s: error scanning foreign multipath libraries: %m",
+			__func__);
 		_cleanup_foreign();
-		return -r;
+		goto out_free_pre;
 	}
 
 	sr.di = di;
@@ -249,9 +249,11 @@ static int _init_foreign(const char *multipath_dir, const char *enable)
 	dl_err:
 		free_foreign(fgn);
 	}
+	r = 0;
 	pthread_cleanup_pop(1); /* free_scandir_result */
+out_free_pre:
 	pthread_cleanup_pop(1); /* free_pre */
-	return 0;
+	return r;
 }
 
 int init_foreign(const char *multipath_dir, const char *enable)
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 21/72] libmultipath: process_config_dir(): remove unused argument
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (19 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 20/72] libmultipath: _init_foreign(): fix possible memory leak Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 22/72] libmultipath: mark unused arguments in partmap functions Martin Wilck
                   ` (50 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/config.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libmultipath/config.c b/libmultipath/config.c
index 20e3b8bf..49723add 100644
--- a/libmultipath/config.c
+++ b/libmultipath/config.c
@@ -644,7 +644,7 @@ free_config (struct config * conf)
 /* if multipath fails to process the config directory, it should continue,
  * with just a warning message */
 static void
-process_config_dir(struct config *conf, vector keywords, char *dir)
+process_config_dir(struct config *conf, char *dir)
 {
 	struct dirent **namelist;
 	struct scandir_result sr;
@@ -749,7 +749,7 @@ load_config (char * file)
 	if (conf->config_dir == NULL)
 		conf->config_dir = set_default(DEFAULT_CONFIG_DIR);
 	if (conf->config_dir && conf->config_dir[0] != '\0')
-		process_config_dir(conf, conf->keywords, conf->config_dir);
+		process_config_dir(conf, conf->config_dir);
 
 	/*
 	 * fill the voids left in the config file
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 22/72] libmultipath: mark unused arguments in partmap functions
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (20 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 21/72] libmultipath: process_config_dir(): remove unused argument Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 23/72] libmultipath: scsi_ioctl_pathinfo(): remove unused argument Martin Wilck
                   ` (49 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/devmapper.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
index 0f0c3a34..f478ac2d 100644
--- a/libmultipath/devmapper.c
+++ b/libmultipath/devmapper.c
@@ -812,7 +812,8 @@ dm_get_major_minor(const char *name, int *major, int *minor)
 }
 
 static int
-has_partmap(const char *name, void *data)
+has_partmap(const char *name __attribute__((unused)),
+	    void *data __attribute__((unused)))
 {
 	return 1;
 }
@@ -1308,7 +1309,7 @@ dm_remove_partmaps (const char * mapname, int need_sync, int deferred_remove)
 #ifdef LIBDM_API_DEFERRED
 
 static int
-cancel_remove_partmap (const char *name, void *unused)
+cancel_remove_partmap (const char *name, void *unused __attribute__((unused)))
 {
 	if (dm_get_opencount(name))
 		dm_cancel_remove_partmaps(name);
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 23/72] libmultipath: scsi_ioctl_pathinfo(): remove unused argument
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (21 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 22/72] libmultipath: mark unused arguments in partmap functions Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 24/72] multipath-tools: mark unused params in signal and cleanup handlers Martin Wilck
                   ` (48 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/discovery.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
index d217ca92..4d93c91b 100644
--- a/libmultipath/discovery.c
+++ b/libmultipath/discovery.c
@@ -1571,7 +1571,7 @@ sysfs_pathinfo(struct path * pp, vector hwtable)
 }
 
 static void
-scsi_ioctl_pathinfo (struct path * pp, struct config *conf, int mask)
+scsi_ioctl_pathinfo (struct path * pp, int mask)
 {
 	struct udev_device *parent;
 	const char *attr_path = NULL;
@@ -2050,7 +2050,7 @@ int pathinfo(struct path *pp, struct config *conf, int mask)
 		get_geometry(pp);
 
 	if (path_state == PATH_UP && pp->bus == SYSFS_BUS_SCSI)
-		scsi_ioctl_pathinfo(pp, conf, mask);
+		scsi_ioctl_pathinfo(pp, mask);
 
 	if (pp->bus == SYSFS_BUS_CCISS && mask & DI_SERIAL)
 		cciss_ioctl_pathinfo(pp);
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 24/72] multipath-tools: mark unused params in signal and cleanup handlers
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (22 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 23/72] libmultipath: scsi_ioctl_pathinfo(): remove unused argument Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 25/72] libmultipath: get_ana_info(): remove unused parameter Martin Wilck
                   ` (47 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

These parameters are all rightfully unused, yet need to be declared
because of the function prototypes.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/file.c        |  2 +-
 libmultipath/foreign.c     |  2 +-
 libmultipath/io_err_stat.c |  4 ++--
 mpathpersist/main.c        |  2 +-
 multipath/main.c           |  2 +-
 multipathd/dmevents.c      |  4 ++--
 multipathd/main.c          | 14 +++++++-------
 7 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/libmultipath/file.c b/libmultipath/file.c
index 8727f160..5cb06e1f 100644
--- a/libmultipath/file.c
+++ b/libmultipath/file.c
@@ -74,7 +74,7 @@ ensure_directories_exist(const char *str, mode_t dir_mode)
 }
 
 static void
-sigalrm(int sig)
+sigalrm(__attribute__((unused)) int sig)
 {
 	/* do nothing */
 }
diff --git a/libmultipath/foreign.c b/libmultipath/foreign.c
index 9ef8ad19..f05db162 100644
--- a/libmultipath/foreign.c
+++ b/libmultipath/foreign.c
@@ -50,7 +50,7 @@ static void wrlock_foreigns(void)
 	pthread_rwlock_wrlock(&foreign_lock);
 }
 
-static void unlock_foreigns(void *unused)
+static void unlock_foreigns(__attribute__((unused)) void *unused)
 {
 	pthread_rwlock_unlock(&foreign_lock);
 }
diff --git a/libmultipath/io_err_stat.c b/libmultipath/io_err_stat.c
index 554b7778..6b3a3e19 100644
--- a/libmultipath/io_err_stat.c
+++ b/libmultipath/io_err_stat.c
@@ -84,7 +84,7 @@ io_context_t	ioctx;
 
 static void cancel_inflight_io(struct io_err_stat_path *pp);
 
-static void rcu_unregister(void *param)
+static void rcu_unregister(__attribute__((unused)) void *param)
 {
 	rcu_unregister_thread();
 }
@@ -689,7 +689,7 @@ static void cleanup_unlock(void *arg)
 	pthread_mutex_unlock((pthread_mutex_t*) arg);
 }
 
-static void cleanup_exited(void *arg)
+static void cleanup_exited(__attribute__((unused)) void *arg)
 {
 	uatomic_set(&io_err_thread_running, 0);
 }
diff --git a/mpathpersist/main.c b/mpathpersist/main.c
index 278b8d51..56761668 100644
--- a/mpathpersist/main.c
+++ b/mpathpersist/main.c
@@ -50,7 +50,7 @@ struct config *get_multipath_config(void)
 	return multipath_conf;
 }
 
-void put_multipath_config(void * arg)
+void put_multipath_config(__attribute__((unused)) void * arg)
 {
 	/* Noop for now */
 }
diff --git a/multipath/main.c b/multipath/main.c
index 4f4d8e89..b3f8c99b 100644
--- a/multipath/main.c
+++ b/multipath/main.c
@@ -86,7 +86,7 @@ struct config *get_multipath_config(void)
 	return multipath_conf;
 }
 
-void put_multipath_config(void *arg)
+void put_multipath_config(__attribute__((unused)) void *arg)
 {
 	/* Noop for now */
 }
diff --git a/multipathd/dmevents.c b/multipathd/dmevents.c
index 00348926..b22b47d2 100644
--- a/multipathd/dmevents.c
+++ b/multipathd/dmevents.c
@@ -370,12 +370,12 @@ static int dmevent_loop (void)
 	return -1; /* never reach there */
 }
 
-static void rcu_unregister(void *param)
+static void rcu_unregister(__attribute__((unused)) void *param)
 {
 	rcu_unregister_thread();
 }
 
-void *wait_dmevents (void *unused)
+void *wait_dmevents (__attribute__((unused)) void *unused)
 {
 	int r;
 
diff --git a/multipathd/main.c b/multipathd/main.c
index 34a57689..ef128a32 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -215,7 +215,7 @@ static void do_sd_notify(enum daemon_status old_state,
 }
 #endif
 
-static void config_cleanup(void *arg)
+static void config_cleanup(__attribute__((unused)) void *arg)
 {
 	pthread_mutex_unlock(&config_lock);
 }
@@ -306,7 +306,7 @@ struct config *get_multipath_config(void)
 	return rcu_dereference(multipath_conf);
 }
 
-void put_multipath_config(void *arg)
+void put_multipath_config(__attribute__((unused)) void *arg)
 {
 	rcu_read_unlock();
 }
@@ -1503,7 +1503,7 @@ out:
 	return r;
 }
 
-static void rcu_unregister(void *param)
+static void rcu_unregister(__attribute__((unused)) void *param)
 {
 	rcu_unregister_thread();
 }
@@ -2685,25 +2685,25 @@ handle_signals(bool nonfatal)
 }
 
 static void
-sighup (int sig)
+sighup(__attribute__((unused)) int sig)
 {
 	reconfig_sig = 1;
 }
 
 static void
-sigend (int sig)
+sigend(__attribute__((unused)) int sig)
 {
 	exit_sig = 1;
 }
 
 static void
-sigusr1 (int sig)
+sigusr1(__attribute__((unused)) int sig)
 {
 	log_reset_sig = 1;
 }
 
 static void
-sigusr2 (int sig)
+sigusr2(__attribute__((unused)) int sig)
 {
 	condlog(3, "SIGUSR2 received");
 }
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 25/72] libmultipath: get_ana_info(): remove unused parameter
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (23 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 24/72] multipath-tools: mark unused params in signal and cleanup handlers Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 26/72] libmultipath: mark unused params in getprio() methods Martin Wilck
                   ` (46 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/prioritizers/ana.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libmultipath/prioritizers/ana.c b/libmultipath/prioritizers/ana.c
index 2673d9d9..bcb1dbf8 100644
--- a/libmultipath/prioritizers/ana.c
+++ b/libmultipath/prioritizers/ana.c
@@ -106,7 +106,7 @@ static int get_ana_state(__u32 nsid, __u32 anagrpid, void *ana_log,
 	return -ANA_ERR_GETANAS_NOTFOUND;
 }
 
-int get_ana_info(struct path * pp, unsigned int timeout)
+static int get_ana_info(struct path * pp)
 {
 	int	rc;
 	__u32 nsid;
@@ -209,7 +209,7 @@ int getprio(struct path *pp, char *args, unsigned int timeout)
 	if (pp->fd < 0)
 		rc = -ANA_ERR_NO_INFORMATION;
 	else
-		rc = get_ana_info(pp, timeout);
+		rc = get_ana_info(pp);
 
 	switch (rc) {
 	case NVME_ANA_OPTIMIZED:
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 26/72] libmultipath: mark unused params in getprio() methods
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (24 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 25/72] libmultipath: get_ana_info(): remove unused parameter Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 27/72] libmultipath: hp_sw: remove usused argument in do_inq() Martin Wilck
                   ` (45 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/prioritizers/ana.c          | 3 ++-
 libmultipath/prioritizers/const.c        | 4 +++-
 libmultipath/prioritizers/datacore.c     | 3 ++-
 libmultipath/prioritizers/emc.c          | 3 ++-
 libmultipath/prioritizers/hds.c          | 3 ++-
 libmultipath/prioritizers/hp_sw.c        | 3 ++-
 libmultipath/prioritizers/iet.c          | 3 ++-
 libmultipath/prioritizers/ontap.c        | 3 ++-
 libmultipath/prioritizers/random.c       | 4 +++-
 libmultipath/prioritizers/rdac.c         | 3 ++-
 libmultipath/prioritizers/sysfs.c        | 3 ++-
 libmultipath/prioritizers/weightedpath.c | 3 ++-
 12 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/libmultipath/prioritizers/ana.c b/libmultipath/prioritizers/ana.c
index bcb1dbf8..9f7adfa5 100644
--- a/libmultipath/prioritizers/ana.c
+++ b/libmultipath/prioritizers/ana.c
@@ -202,7 +202,8 @@ static int get_ana_info(struct path * pp)
  * - ALUA's LBA-dependent state has no ANA equivalent.
  */
 
-int getprio(struct path *pp, char *args, unsigned int timeout)
+int getprio(struct path *pp, __attribute__((unused)) char *args,
+	    __attribute__((unused)) unsigned int timeout)
 {
 	int rc;
 
diff --git a/libmultipath/prioritizers/const.c b/libmultipath/prioritizers/const.c
index aad69274..059d8593 100644
--- a/libmultipath/prioritizers/const.c
+++ b/libmultipath/prioritizers/const.c
@@ -2,7 +2,9 @@
 
 #include "prio.h"
 
-int getprio(struct path * pp, char * args, unsigned int timeout)
+int getprio(__attribute__((unused)) struct path * pp,
+	    __attribute__((unused)) char * args,
+	    __attribute__((unused)) unsigned int timeout)
 {
 	return 1;
 }
diff --git a/libmultipath/prioritizers/datacore.c b/libmultipath/prioritizers/datacore.c
index 59c98164..02dc2e27 100644
--- a/libmultipath/prioritizers/datacore.c
+++ b/libmultipath/prioritizers/datacore.c
@@ -98,7 +98,8 @@ int datacore_prio (const char *dev, int sg_fd, char * args)
 	return 0;
 }
 
-int getprio(struct path * pp, char * args, unsigned int timeout)
+int getprio(struct path * pp, char * args,
+	    __attribute__((unused)) unsigned int timeout)
 {
 	return datacore_prio(pp->dev, pp->fd, args);
 }
diff --git a/libmultipath/prioritizers/emc.c b/libmultipath/prioritizers/emc.c
index a2f74875..3b63cca0 100644
--- a/libmultipath/prioritizers/emc.c
+++ b/libmultipath/prioritizers/emc.c
@@ -81,7 +81,8 @@ out:
 	return(ret);
 }
 
-int getprio (struct path * pp, char * args, unsigned int timeout)
+int getprio (struct path *pp, __attribute__((unused)) char *args,
+	     unsigned int timeout)
 {
 	return emc_clariion_prio(pp->dev, pp->fd, timeout);
 }
diff --git a/libmultipath/prioritizers/hds.c b/libmultipath/prioritizers/hds.c
index 70fb5d19..88cac5f0 100644
--- a/libmultipath/prioritizers/hds.c
+++ b/libmultipath/prioritizers/hds.c
@@ -168,7 +168,8 @@ int hds_modular_prio (const char *dev, int fd, unsigned int timeout)
 	return -1;
 }
 
-int getprio (struct path * pp, char * args, unsigned int timeout)
+int getprio (struct path * pp, __attribute__((unused)) char *args,
+	     unsigned int timeout)
 {
 	return hds_modular_prio(pp->dev, pp->fd, timeout);
 }
diff --git a/libmultipath/prioritizers/hp_sw.c b/libmultipath/prioritizers/hp_sw.c
index 6b0ed398..5b85ad2e 100644
--- a/libmultipath/prioritizers/hp_sw.c
+++ b/libmultipath/prioritizers/hp_sw.c
@@ -95,7 +95,8 @@ out:
 	return(ret);
 }
 
-int getprio (struct path * pp, char * args, unsigned int timeout)
+int getprio (struct path *pp, __attribute__((unused)) char *args,
+	     unsigned int timeout)
 {
 	return hp_sw_prio(pp->dev, pp->fd, timeout);
 }
diff --git a/libmultipath/prioritizers/iet.c b/libmultipath/prioritizers/iet.c
index a4ea61ef..e98773cf 100644
--- a/libmultipath/prioritizers/iet.c
+++ b/libmultipath/prioritizers/iet.c
@@ -138,7 +138,8 @@ int iet_prio(const char *dev, char * args)
 	return 10;
 }
 
-int getprio(struct path * pp, char * args, unsigned int timeout)
+int getprio(struct path * pp, char * args,
+	    __attribute__((unused)) unsigned int timeout)
 {
 	return iet_prio(pp->dev, args);
 }
diff --git a/libmultipath/prioritizers/ontap.c b/libmultipath/prioritizers/ontap.c
index 6505033f..262e69d2 100644
--- a/libmultipath/prioritizers/ontap.c
+++ b/libmultipath/prioritizers/ontap.c
@@ -241,7 +241,8 @@ prio_select:
 	}
 }
 
-int getprio (struct path * pp, char * args, unsigned int timeout)
+int getprio (struct path *pp, __attribute__((unused)) char *args,
+	     unsigned int timeout)
 {
 	return ontap_prio(pp->dev, pp->fd, timeout);
 }
diff --git a/libmultipath/prioritizers/random.c b/libmultipath/prioritizers/random.c
index 4a27123b..b742ac23 100644
--- a/libmultipath/prioritizers/random.c
+++ b/libmultipath/prioritizers/random.c
@@ -5,7 +5,9 @@
 
 #include "prio.h"
 
-int getprio(struct path * pp, char * args, unsigned int timeout)
+int getprio(__attribute__((unused)) struct path *pp,
+	    __attribute__((unused)) char *args,
+	    __attribute__((unused)) unsigned int timeout)
 {
 	struct timeval tv;
 
diff --git a/libmultipath/prioritizers/rdac.c b/libmultipath/prioritizers/rdac.c
index f5df0321..92a2fb85 100644
--- a/libmultipath/prioritizers/rdac.c
+++ b/libmultipath/prioritizers/rdac.c
@@ -91,7 +91,8 @@ out:
 	return(ret);
 }
 
-int getprio (struct path * pp, char * args, unsigned int timeout)
+int getprio (struct path *pp, __attribute__((unused)) char *args,
+	     unsigned int timeout)
 {
 	return rdac_prio(pp->dev, pp->fd, timeout);
 }
diff --git a/libmultipath/prioritizers/sysfs.c b/libmultipath/prioritizers/sysfs.c
index ff567df7..a6feb421 100644
--- a/libmultipath/prioritizers/sysfs.c
+++ b/libmultipath/prioritizers/sysfs.c
@@ -36,7 +36,8 @@ int get_exclusive_pref_arg(char *args)
 	return 1;
 }
 
-int getprio (struct path * pp, char * args, unsigned int timeout)
+int getprio (struct path * pp, char *args,
+	     __attribute__((unused)) unsigned int timeout)
 {
 	int prio = 0, rc, i;
 	char buff[512];
diff --git a/libmultipath/prioritizers/weightedpath.c b/libmultipath/prioritizers/weightedpath.c
index e0f3efbb..916970df 100644
--- a/libmultipath/prioritizers/weightedpath.c
+++ b/libmultipath/prioritizers/weightedpath.c
@@ -143,7 +143,8 @@ int prio_path_weight(struct path *pp, char *prio_args)
 	return priority;
 }
 
-int getprio(struct path *pp, char *args, unsigned int timeout)
+int getprio(struct path *pp, char *args,
+	    __attribute__((unused)) unsigned int timeout)
 {
 	return prio_path_weight(pp, args);
 }
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 27/72] libmultipath: hp_sw: remove usused argument in do_inq()
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (25 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 26/72] libmultipath: mark unused params in getprio() methods Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 28/72] libmultipath: checkers: mark unused arguments in methods Martin Wilck
                   ` (44 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/checkers/hp_sw.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libmultipath/checkers/hp_sw.c b/libmultipath/checkers/hp_sw.c
index 1a820223..eabfa93c 100644
--- a/libmultipath/checkers/hp_sw.c
+++ b/libmultipath/checkers/hp_sw.c
@@ -44,7 +44,7 @@ void libcheck_free (struct checker * c)
 
 static int
 do_inq(int sg_fd, int cmddt, int evpd, unsigned int pg_op,
-       void *resp, int mx_resp_len, int noisy, unsigned int timeout)
+       void *resp, int mx_resp_len, unsigned int timeout)
 {
 	unsigned char inqCmdBlk[INQUIRY_CMDLEN] =
 		{ INQUIRY_CMD, 0, 0, 0, 0, 0 };
@@ -130,7 +130,7 @@ do_tur (int fd, unsigned int timeout)
 int libcheck_check(struct checker * c)
 {
 	char buff[MX_ALLOC_LEN];
-	int ret = do_inq(c->fd, 0, 1, 0x80, buff, MX_ALLOC_LEN, 0, c->timeout);
+	int ret = do_inq(c->fd, 0, 1, 0x80, buff, MX_ALLOC_LEN, c->timeout);
 
 	if (ret == PATH_WILD) {
 		c->msgid = CHECKER_MSGID_UNSUPPORTED;
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 28/72] libmultipath: checkers: mark unused arguments in methods
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (26 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 27/72] libmultipath: hp_sw: remove usused argument in do_inq() Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 29/72] multipathd: stop_waiter_thread(): removed unused parameter Martin Wilck
                   ` (43 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/checkers/cciss_tur.c   | 4 ++--
 libmultipath/checkers/hp_sw.c       | 4 ++--
 libmultipath/checkers/rdac.c        | 2 +-
 libmultipath/checkers/readsector0.c | 4 ++--
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/libmultipath/checkers/cciss_tur.c b/libmultipath/checkers/cciss_tur.c
index ea843742..eaf67b35 100644
--- a/libmultipath/checkers/cciss_tur.c
+++ b/libmultipath/checkers/cciss_tur.c
@@ -46,12 +46,12 @@ struct cciss_tur_checker_context {
 	void * dummy;
 };
 
-int libcheck_init (struct checker * c)
+int libcheck_init (__attribute__((unused)) struct checker * c)
 {
 	return 0;
 }
 
-void libcheck_free (struct checker * c)
+void libcheck_free (__attribute__((unused)) struct checker * c)
 {
 	return;
 }
diff --git a/libmultipath/checkers/hp_sw.c b/libmultipath/checkers/hp_sw.c
index eabfa93c..915918c0 100644
--- a/libmultipath/checkers/hp_sw.c
+++ b/libmultipath/checkers/hp_sw.c
@@ -32,12 +32,12 @@ struct sw_checker_context {
 	void * dummy;
 };
 
-int libcheck_init (struct checker * c)
+int libcheck_init (__attribute__((unused)) struct checker * c)
 {
 	return 0;
 }
 
-void libcheck_free (struct checker * c)
+void libcheck_free (__attribute__((unused)) struct checker * c)
 {
 	return;
 }
diff --git a/libmultipath/checkers/rdac.c b/libmultipath/checkers/rdac.c
index 8a3b73ec..d924a9f7 100644
--- a/libmultipath/checkers/rdac.c
+++ b/libmultipath/checkers/rdac.c
@@ -133,7 +133,7 @@ out:
 	return 0;
 }
 
-void libcheck_free (struct checker * c)
+void libcheck_free(__attribute__((unused)) struct checker *c)
 {
 	return;
 }
diff --git a/libmultipath/checkers/readsector0.c b/libmultipath/checkers/readsector0.c
index cf79e067..b041f110 100644
--- a/libmultipath/checkers/readsector0.c
+++ b/libmultipath/checkers/readsector0.c
@@ -10,12 +10,12 @@ struct readsector0_checker_context {
 	void * dummy;
 };
 
-int libcheck_init (struct checker * c)
+int libcheck_init (__attribute__((unused)) struct checker * c)
 {
 	return 0;
 }
 
-void libcheck_free (struct checker * c)
+void libcheck_free (__attribute__((unused)) struct checker * c)
 {
 	return;
 }
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 29/72] multipathd: stop_waiter_thread(): removed unused parameter
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (27 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 28/72] libmultipath: checkers: mark unused arguments in methods Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 30/72] multipath tools: mark unused arguments in thread routines Martin Wilck
                   ` (42 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 multipathd/main.c   | 4 ++--
 multipathd/waiter.c | 2 +-
 multipathd/waiter.h | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/multipathd/main.c b/multipathd/main.c
index ef128a32..43ae42d4 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -377,7 +377,7 @@ remove_map_and_stop_waiter(struct multipath *mpp, struct vectors *vecs)
 	 * so they don't need to be manually removed here */
 	condlog(3, "%s: removing map from internal tables", mpp->alias);
 	if (!poll_dmevents)
-		stop_waiter_thread(mpp, vecs);
+		stop_waiter_thread(mpp);
 	remove_map(mpp, vecs, PURGE_VEC);
 }
 
@@ -392,7 +392,7 @@ remove_maps_and_stop_waiters(struct vectors *vecs)
 
 	if (!poll_dmevents) {
 		vector_foreach_slot(vecs->mpvec, mpp, i)
-			stop_waiter_thread(mpp, vecs);
+			stop_waiter_thread(mpp);
 	}
 	else
 		unwatch_all_dmevents();
diff --git a/multipathd/waiter.c b/multipathd/waiter.c
index eb8d6996..e6457663 100644
--- a/multipathd/waiter.c
+++ b/multipathd/waiter.c
@@ -49,7 +49,7 @@ static void free_waiter (void *data)
 	FREE(wp);
 }
 
-void stop_waiter_thread (struct multipath *mpp, struct vectors *vecs)
+void stop_waiter_thread (struct multipath *mpp)
 {
 	pthread_t thread;
 
diff --git a/multipathd/waiter.h b/multipathd/waiter.h
index 0cfae46f..28e0f6d5 100644
--- a/multipathd/waiter.h
+++ b/multipathd/waiter.h
@@ -11,7 +11,7 @@ struct event_thread {
 	struct vectors *vecs;
 };
 
-void stop_waiter_thread (struct multipath *mpp, struct vectors *vecs);
+void stop_waiter_thread (struct multipath *mpp);
 int start_waiter_thread (struct multipath *mpp, struct vectors *vecs);
 
 #endif /* _WAITER_H */
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 30/72] multipath tools: mark unused arguments in thread routines
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (28 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 29/72] multipathd: stop_waiter_thread(): removed unused parameter Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 31/72] kpartx: gpt: remove unused arg in read_lastoddsector() Martin Wilck
                   ` (41 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/log_pthread.c | 2 +-
 multipathd/main.c          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libmultipath/log_pthread.c b/libmultipath/log_pthread.c
index be57bb1a..15baef88 100644
--- a/libmultipath/log_pthread.c
+++ b/libmultipath/log_pthread.c
@@ -56,7 +56,7 @@ static void flush_logqueue (void)
 	} while (empty == 0);
 }
 
-static void * log_thread (void * et)
+static void * log_thread (__attribute__((unused)) void * et)
 {
 	int running;
 
diff --git a/multipathd/main.c b/multipathd/main.c
index 43ae42d4..e55f2795 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -2792,7 +2792,7 @@ set_oom_adj (void)
 }
 
 static int
-child (void * param)
+child (__attribute__((unused)) void *param)
 {
 	pthread_t check_thr, uevent_thr, uxlsnr_thr, uevq_thr, dmevent_thr;
 	pthread_attr_t log_attr, misc_attr, uevent_attr;
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 31/72] kpartx: gpt: remove unused arg in read_lastoddsector()
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (29 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 30/72] multipath tools: mark unused arguments in thread routines Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 32/72] kpartx: mark unused arguments in ptreader methods Martin Wilck
                   ` (40 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 kpartx/gpt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kpartx/gpt.c b/kpartx/gpt.c
index e31611a3..f3216ba2 100644
--- a/kpartx/gpt.c
+++ b/kpartx/gpt.c
@@ -182,7 +182,7 @@ last_lba(int filedes)
 
 
 static ssize_t
-read_lastoddsector(int fd, uint64_t lba, void *buffer, size_t count)
+read_lastoddsector(int fd, void *buffer, size_t count)
 {
 	int rc;
 	struct blkdev_ioctl_param ioctl_param;
@@ -221,7 +221,7 @@ read_lba(int fd, uint64_t lba, void *buffer, size_t bytes)
 	   one sector, so we don't have to be fancy.
 	*/
 	if (!bytesread && !(lastlba & 1) && lba == lastlba) {
-		bytesread = read_lastoddsector(fd, lba, buffer, bytes);
+		bytesread = read_lastoddsector(fd, buffer, bytes);
 	}
 	return bytesread;
 }
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 32/72] kpartx: mark unused arguments in ptreader methods
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (30 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 31/72] kpartx: gpt: remove unused arg in read_lastoddsector() Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 33/72] libmultipath: mark missing arguments in functions matching prototypes Martin Wilck
                   ` (39 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 kpartx/dasd.c | 3 ++-
 kpartx/gpt.c  | 3 ++-
 kpartx/mac.c  | 3 ++-
 kpartx/ps3.c  | 3 ++-
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/kpartx/dasd.c b/kpartx/dasd.c
index 4e7e4743..4f3f744e 100644
--- a/kpartx/dasd.c
+++ b/kpartx/dasd.c
@@ -65,7 +65,8 @@ typedef unsigned int __attribute__((__may_alias__)) label_ints_t;
 /*
  */
 int
-read_dasd_pt(int fd, struct slice all, struct slice *sp, int ns)
+read_dasd_pt(int fd, __attribute__((unused)) struct slice all,
+	     struct slice *sp, __attribute__((unused)) int ns)
 {
 	int retval = -1;
 	int blocksize;
diff --git a/kpartx/gpt.c b/kpartx/gpt.c
index f3216ba2..4f88d486 100644
--- a/kpartx/gpt.c
+++ b/kpartx/gpt.c
@@ -601,7 +601,8 @@ fail:
  *
  */
 int
-read_gpt_pt (int fd, struct slice all, struct slice *sp, int ns)
+read_gpt_pt (int fd, __attribute__((unused)) struct slice all,
+	     struct slice *sp, int ns)
 {
 	gpt_header *gpt = NULL;
 	gpt_entry *ptes = NULL;
diff --git a/kpartx/mac.c b/kpartx/mac.c
index 6e82c95e..6aeac4e9 100644
--- a/kpartx/mac.c
+++ b/kpartx/mac.c
@@ -5,7 +5,8 @@
 #include "mac.h"
 
 int
-read_mac_pt(int fd, struct slice all, struct slice *sp, int ns) {
+read_mac_pt(int fd, __attribute__((unused)) struct slice all,
+	    struct slice *sp, int ns) {
 	struct mac_driver_desc *md;
 	struct mac_partition *part;
 	unsigned secsize;
diff --git a/kpartx/ps3.c b/kpartx/ps3.c
index 84550978..2cf4ffa2 100644
--- a/kpartx/ps3.c
+++ b/kpartx/ps3.c
@@ -48,7 +48,8 @@ read_disklabel(int fd, struct disklabel *label) {
 }
 
 int
-read_ps3_pt(int fd, struct slice all, struct slice *sp, int ns) {
+read_ps3_pt(int fd, __attribute__((unused)) struct slice all,
+	    struct slice *sp, __attribute__((unused)) int ns) {
 	struct disklabel label;
 	int n = 0;
 	int i;
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 33/72] libmultipath: mark missing arguments in functions matching prototypes
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (31 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 32/72] kpartx: mark unused arguments in ptreader methods Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 34/72] libmultipath: get_pgpolicy_name(): use "len" parameter Martin Wilck
                   ` (38 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/dm-generic.c   |  6 ++++--
 libmultipath/foreign/nvme.c | 20 +++++++++++++-------
 libmultipath/generic.c      |  2 +-
 libmultipath/print.c        |  6 ++++--
 4 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/libmultipath/dm-generic.c b/libmultipath/dm-generic.c
index d7529919..1b42fa0b 100644
--- a/libmultipath/dm-generic.c
+++ b/libmultipath/dm-generic.c
@@ -31,7 +31,8 @@ dm_mp_get_pgs(const struct gen_multipath *gmp)
 			      struct pathgroup, dm_pathgroup_to_gen);
 }
 
-static void dm_mp_rel_pgs(const struct gen_multipath *gmp,
+static void dm_mp_rel_pgs(__attribute__((unused))
+			  const struct gen_multipath *gmp,
 			  const struct _vector* v)
 {
 	vector_free_const(v);
@@ -44,7 +45,8 @@ dm_pg_get_paths(const struct gen_pathgroup *gpg)
 			      struct path, dm_path_to_gen);
 }
 
-static void dm_mp_rel_paths(const struct gen_pathgroup *gpg,
+static void dm_mp_rel_paths(__attribute__((unused))
+			    const struct gen_pathgroup *gpg,
 			    const struct _vector* v)
 {
 	vector_free_const(v);
diff --git a/libmultipath/foreign/nvme.c b/libmultipath/foreign/nvme.c
index 7e654ec5..e8ca516c 100644
--- a/libmultipath/foreign/nvme.c
+++ b/libmultipath/foreign/nvme.c
@@ -123,7 +123,8 @@ nvme_mp_get_pgs(const struct gen_multipath *gmp) {
 }
 
 static void
-nvme_mp_rel_pgs(const struct gen_multipath *gmp, const struct _vector *v)
+nvme_mp_rel_pgs(__attribute__((unused)) const struct gen_multipath *gmp,
+		__attribute__((unused)) const struct _vector *v)
 {
 	/* empty */
 }
@@ -207,7 +208,8 @@ nvme_pg_get_paths(const struct gen_pathgroup *gpg) {
 }
 
 static void
-nvme_pg_rel_paths(const struct gen_pathgroup *gpg, const struct _vector *v)
+nvme_pg_rel_paths(__attribute__((unused)) const struct gen_pathgroup *gpg,
+		  __attribute__((unused)) const struct _vector *v)
 {
 	/* empty */
 }
@@ -331,8 +333,9 @@ static int snprint_nvme_pg(const struct gen_pathgroup *gmp,
 	}
 }
 
-static int nvme_style(const struct gen_multipath* gm,
-		      char *buf, int len, int verbosity)
+static int nvme_style(__attribute__((unused)) const struct gen_multipath* gm,
+		      char *buf, int len,
+		      __attribute__((unused)) int verbosity)
 {
 	int n = snprintf(buf, len, "%%w [%%G]:%%d %%s");
 
@@ -821,7 +824,8 @@ int add(struct context *ctx, struct udev_device *ud)
 	return rc;
 }
 
-int change(struct context *ctx, struct udev_device *ud)
+int change(__attribute__((unused)) struct context *ctx,
+	   __attribute__((unused)) struct udev_device *ud)
 {
 	condlog(5, "%s called for \"%s\"", __func__, THIS);
 	return FOREIGN_IGNORED;
@@ -903,7 +907,8 @@ const struct _vector *get_multipaths(const struct context *ctx)
 	return ctx->mpvec;
 }
 
-void release_multipaths(const struct context *ctx, const struct _vector *mpvec)
+void release_multipaths(__attribute__((unused)) const struct context *ctx,
+			__attribute__((unused)) const struct _vector *mpvec)
 {
 	condlog(5, "%s called for \"%s\"", __func__, THIS);
 	/* NOP */
@@ -927,7 +932,8 @@ const struct _vector * get_paths(const struct context *ctx)
 	return paths;
 }
 
-void release_paths(const struct context *ctx, const struct _vector *mpvec)
+void release_paths(__attribute__((unused)) const struct context *ctx,
+		   const struct _vector *mpvec)
 {
 	condlog(5, "%s called for \"%s\"", __func__, THIS);
 	vector_free_const(mpvec);
diff --git a/libmultipath/generic.c b/libmultipath/generic.c
index 0d1e632a..5f03b9e0 100644
--- a/libmultipath/generic.c
+++ b/libmultipath/generic.c
@@ -21,7 +21,7 @@
 #include "structs.h"
 
 int generic_style(const struct gen_multipath* gm,
-		  char *buf, int len, int verbosity)
+		  char *buf, int len, __attribute__((unused)) int verbosity)
 {
 	char alias_buf[WWID_SIZE];
 	char wwid_buf[WWID_SIZE];
diff --git a/libmultipath/print.c b/libmultipath/print.c
index 907469ad..74c0d62d 100644
--- a/libmultipath/print.c
+++ b/libmultipath/print.c
@@ -334,7 +334,8 @@ snprint_multipath_rev (char * buff, size_t len, const struct multipath * mpp)
 }
 
 static int
-snprint_multipath_foreign (char * buff, size_t len, const struct multipath * pp)
+snprint_multipath_foreign (char * buff, size_t len,
+			   __attribute__((unused)) const struct multipath * pp)
 {
 	return snprintf(buff, len, "%s", "--");
 }
@@ -627,7 +628,8 @@ snprint_path_checker (char * buff, size_t len, const struct path * pp)
 }
 
 static int
-snprint_path_foreign (char * buff, size_t len, const struct path * pp)
+snprint_path_foreign (char * buff, size_t len,
+		      __attribute__((unused)) const struct path * pp)
 {
 	return snprintf(buff, len, "%s", "--");
 }
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 34/72] libmultipath: get_pgpolicy_name(): use "len" parameter
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (32 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 33/72] libmultipath: mark missing arguments in functions matching prototypes Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 35/72] libmultipath: snprint_multipath_map_json(): remove unused argument Martin Wilck
                   ` (37 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/pgpolicies.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libmultipath/pgpolicies.c b/libmultipath/pgpolicies.c
index 8f7c6b13..02cafdc7 100644
--- a/libmultipath/pgpolicies.c
+++ b/libmultipath/pgpolicies.c
@@ -54,7 +54,7 @@ int get_pgpolicy_name(char * buff, int len, int id)
 		s = "undefined";
 		break;
 	}
-	return snprintf(buff, POLICY_NAME_SIZE, "%s", s);
+	return snprintf(buff, len, "%s", s);
 }
 
 
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 35/72] libmultipath: snprint_multipath_map_json(): remove unused argument
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (33 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 34/72] libmultipath: get_pgpolicy_name(): use "len" parameter Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 36/72] multipath: delegate_to_multipathd: mark unused arguments Martin Wilck
                   ` (36 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/print.c      | 4 ++--
 libmultipath/print.h      | 2 +-
 multipathd/cli_handlers.c | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libmultipath/print.c b/libmultipath/print.c
index 74c0d62d..8fa86267 100644
--- a/libmultipath/print.c
+++ b/libmultipath/print.c
@@ -1339,8 +1339,8 @@ snprint_multipath_fields_json (char * buff, int len,
 }
 
 int
-snprint_multipath_map_json (char * buff, int len,
-		const struct multipath * mpp, int last){
+snprint_multipath_map_json (char * buff, int len, const struct multipath * mpp)
+{
 	int fwd = 0;
 
 	fwd +=  snprint_json_header(buff, len);
diff --git a/libmultipath/print.h b/libmultipath/print.h
index 7e36ec63..0c909e75 100644
--- a/libmultipath/print.h
+++ b/libmultipath/print.h
@@ -125,7 +125,7 @@ char *snprint_config(const struct config *conf, int *len,
 		     const struct _vector *hwtable,
 		     const struct _vector *mpvec);
 int snprint_multipath_map_json (char * buff, int len,
-				const struct multipath * mpp, int last);
+				const struct multipath * mpp);
 int snprint_blacklist_report (struct config *, char *, int);
 int snprint_wildcards (char *, int);
 int snprint_status (char *, int, const struct vectors *);
diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c
index 8a899049..371b0a79 100644
--- a/multipathd/cli_handlers.c
+++ b/multipathd/cli_handlers.c
@@ -237,7 +237,7 @@ show_map_json (char ** r, int * len, struct multipath * mpp,
 
 		c = reply;
 
-		c += snprint_multipath_map_json(c, maxlen, mpp, 1);
+		c += snprint_multipath_map_json(c, maxlen, mpp);
 		again = ((c - reply) == maxlen);
 
 		REALLOC_REPLY(reply, again, maxlen);
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 36/72] multipath: delegate_to_multipathd: mark unused arguments
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (34 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 35/72] libmultipath: snprint_multipath_map_json(): remove unused argument Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 37/72] libmultipath: use -Wno-unused-parameter for dict.c Martin Wilck
                   ` (35 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

... for now.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 multipath/main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/multipath/main.c b/multipath/main.c
index b3f8c99b..c2ef8c7b 100644
--- a/multipath/main.c
+++ b/multipath/main.c
@@ -811,8 +811,10 @@ enum {
 	NOT_DELEGATED = 1,
 };
 
-int delegate_to_multipathd(enum mpath_cmds cmd, const char *dev,
-			   enum devtypes dev_type, const struct config *conf)
+int delegate_to_multipathd(enum mpath_cmds cmd,
+			   __attribute__((unused)) const char *dev,
+			   __attribute__((unused)) enum devtypes dev_type,
+			   const struct config *conf)
 {
 	int fd;
 	char command[1024], *p, *reply = NULL;
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 37/72] libmultipath: use -Wno-unused-parameter for dict.c
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (35 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 36/72] multipath: delegate_to_multipathd: mark unused arguments Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 38/72] multipathd: use -Wno-unused-parameter for cli_handlers.c Martin Wilck
                   ` (34 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

This file contains just too many "handler" and "snprintf" methods
which don't use every argument.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/Makefile | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/libmultipath/Makefile b/libmultipath/Makefile
index a2be42ea..e5651e49 100644
--- a/libmultipath/Makefile
+++ b/libmultipath/Makefile
@@ -50,6 +50,11 @@ all: $(LIBS)
 nvme-lib.o: nvme-lib.c nvme-ioctl.c nvme-ioctl.h
 	$(CC) $(CFLAGS) -Wno-unused-function -c -o $@ $<
 
+# there are lots of "unused parameters" in dict.c
+# because not all handler / snprint methods nees all parameters
+dict.o:	dict.c
+	$(CC) $(CFLAGS) -Wno-unused-parameter -c -o $@ $<
+
 make_static = $(shell sed '/^static/!s/^\([a-z]\{1,\} \)/static \1/' <$1 >$2)
 
 nvme-ioctl.c: nvme/nvme-ioctl.c
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 38/72] multipathd: use -Wno-unused-parameter for cli_handlers.c
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (36 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 37/72] libmultipath: use -Wno-unused-parameter for dict.c Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 39/72] libmpathpersist: remove unused "noisy" argument in various functions Martin Wilck
                   ` (33 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

This file contains many handlers that don't use all their arguments.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 multipathd/Makefile | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/multipathd/Makefile b/multipathd/Makefile
index d1a98637..8d901178 100644
--- a/multipathd/Makefile
+++ b/multipathd/Makefile
@@ -36,6 +36,9 @@ $(EXEC): $(OBJS) $(multipathdir)/libmultipath.so $(mpathcmddir)/libmpathcmd.so
 	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(EXEC) $(LIBDEPS)
 	$(GZIP) $(EXEC).8 > $(EXEC).8.gz
 
+cli_handlers.o:	cli_handlers.c
+	$(CC) $(CFLAGS) -Wno-unused-parameter -c -o $@ $<
+
 install:
 	$(INSTALL_PROGRAM) -d $(DESTDIR)$(bindir)
 	$(INSTALL_PROGRAM) -m 755 $(EXEC) $(DESTDIR)$(bindir)
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 39/72] libmpathpersist: remove unused "noisy" argument in various functions
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (37 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 38/72] multipathd: use -Wno-unused-parameter for cli_handlers.c Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 40/72] libmpathpersist: fix copy-paste error in mpath_format_readresv() Martin Wilck
                   ` (32 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmpathpersist/mpath_pr_ioctl.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/libmpathpersist/mpath_pr_ioctl.c b/libmpathpersist/mpath_pr_ioctl.c
index cf528feb..209892f6 100644
--- a/libmpathpersist/mpath_pr_ioctl.c
+++ b/libmpathpersist/mpath_pr_ioctl.c
@@ -23,10 +23,8 @@
 #define MAXRETRY 5
 
 int prin_do_scsi_ioctl(char * dev, int rq_servact, struct prin_resp *resp, int noisy);
-void mpath_format_readkeys(struct prin_resp *pr_buff, int len , int noisy);
-void mpath_format_readfullstatus(struct prin_resp *pr_buff, int len, int noisy);
 int mpath_translate_response (char * dev, struct sg_io_hdr io_hdr,
-			      SenseData_t *Sensedata, int noisy);
+			      SenseData_t *Sensedata);
 void dumpHex(const char* str, int len, int no_ascii);
 int prout_do_scsi_ioctl( char * dev, int rq_servact, int rq_scope,
 		unsigned int rq_type, struct prout_param_descriptor *paramp, int noisy);
@@ -115,7 +113,7 @@ retry :
 
 	condlog(4, "%s: Duration=%u (ms)", dev, io_hdr.duration);
 
-	status = mpath_translate_response(dev, io_hdr, &Sensedata, noisy);
+	status = mpath_translate_response(dev, io_hdr, &Sensedata);
 	condlog(3, "%s: status = %d", dev, status);
 
 	if (status == MPATH_PR_SENSE_UNIT_ATTENTION && (retry > 0))
@@ -181,13 +179,13 @@ uint32_t  format_transportids(struct prout_param_descriptor *paramp)
 	return buff_offset;
 }
 
-void mpath_format_readkeys( struct prin_resp *pr_buff, int len, int noisy)
+static void mpath_format_readkeys(struct prin_resp *pr_buff)
 {
 	convert_be32_to_cpu(&pr_buff->prin_descriptor.prin_readkeys.prgeneration);
 	convert_be32_to_cpu(&pr_buff->prin_descriptor.prin_readkeys.additional_length);
 }
 
-void mpath_format_readresv(struct prin_resp *pr_buff, int len, int noisy)
+static void mpath_format_readresv(struct prin_resp *pr_buff)
 {
 
 	convert_be32_to_cpu(&pr_buff->prin_descriptor.prin_readkeys.prgeneration);
@@ -196,7 +194,7 @@ void mpath_format_readresv(struct prin_resp *pr_buff, int len, int noisy)
 	return;
 }
 
-void mpath_format_reportcapabilities(struct prin_resp *pr_buff, int len, int noisy)
+static void mpath_format_reportcapabilities(struct prin_resp *pr_buff)
 {
 	convert_be16_to_cpu(&pr_buff->prin_descriptor.prin_readcap.length);
 	convert_be16_to_cpu(&pr_buff->prin_descriptor.prin_readcap.pr_type_mask);
@@ -204,7 +202,7 @@ void mpath_format_reportcapabilities(struct prin_resp *pr_buff, int len, int noi
 	return;
 }
 
-void mpath_format_readfullstatus(struct prin_resp *pr_buff, int len, int noisy)
+static void mpath_format_readfullstatus(struct prin_resp *pr_buff)
 {
 	int num, k, tid_len_len=0;
 	uint32_t fdesc_count=0;
@@ -361,7 +359,7 @@ retry :
 	condlog(3, "%s: duration = %u (ms)", dev, io_hdr.duration);
 	condlog(4, "%s: persistent reservation in: requested %d bytes but got %d bytes)", dev, mx_resp_len, got);
 
-	status = mpath_translate_response(dev, io_hdr, &Sensedata, noisy);
+	status = mpath_translate_response(dev, io_hdr, &Sensedata);
 
 	if (status == MPATH_PR_SENSE_UNIT_ATTENTION && (retry > 0))
 	{
@@ -389,16 +387,16 @@ retry :
 	switch (rq_servact)
 	{
 		case MPATH_PRIN_RKEY_SA :
-			mpath_format_readkeys(resp, got, noisy);
+			mpath_format_readkeys(resp);
 			break;
 		case MPATH_PRIN_RRES_SA :
-			mpath_format_readresv(resp, got, noisy);
+			mpath_format_readresv(resp);
 			break;
 		case MPATH_PRIN_RCAP_SA :
-			mpath_format_reportcapabilities(resp, got, noisy);
+			mpath_format_reportcapabilities(resp);
 			break;
 		case MPATH_PRIN_RFSTAT_SA :
-			mpath_format_readfullstatus(resp, got, noisy);
+			mpath_format_readfullstatus(resp);
 	}
 
 out:
@@ -407,7 +405,7 @@ out:
 }
 
 int mpath_translate_response (char * dev, struct sg_io_hdr io_hdr,
-			      SenseData_t *Sensedata, int noisy)
+			      SenseData_t *Sensedata)
 {
 	condlog(3, "%s: status driver:%02x host:%02x scsi:%02x", dev,
 			io_hdr.driver_status, io_hdr.host_status ,io_hdr.status);
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 40/72] libmpathpersist: fix copy-paste error in mpath_format_readresv()
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (38 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 39/72] libmpathpersist: remove unused "noisy" argument in various functions Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 41/72] multipath-tools tests: add -Wno-unused-parameter Martin Wilck
                   ` (31 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

This would swap bytes for the wrong field.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmpathpersist/mpath_pr_ioctl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libmpathpersist/mpath_pr_ioctl.c b/libmpathpersist/mpath_pr_ioctl.c
index 209892f6..05b30b56 100644
--- a/libmpathpersist/mpath_pr_ioctl.c
+++ b/libmpathpersist/mpath_pr_ioctl.c
@@ -188,8 +188,8 @@ static void mpath_format_readkeys(struct prin_resp *pr_buff)
 static void mpath_format_readresv(struct prin_resp *pr_buff)
 {
 
-	convert_be32_to_cpu(&pr_buff->prin_descriptor.prin_readkeys.prgeneration);
-	convert_be32_to_cpu(&pr_buff->prin_descriptor.prin_readkeys.additional_length);
+	convert_be32_to_cpu(&pr_buff->prin_descriptor.prin_readresv.prgeneration);
+	convert_be32_to_cpu(&pr_buff->prin_descriptor.prin_readresv.additional_length);
 
 	return;
 }
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 41/72] multipath-tools tests: add -Wno-unused-parameter
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (39 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 40/72] libmpathpersist: fix copy-paste error in mpath_format_readresv() Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 23:01   ` Bart Van Assche
  2019-10-12 21:28 ` [PATCH 42/72] multipath-tools: Makefile.inc: remove -Wno-unused-parameter Martin Wilck
                   ` (30 subsequent siblings)
  71 siblings, 1 reply; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Too many unused "void **state" parameters unders tests.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 tests/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/Makefile b/tests/Makefile
index 0dce8571..60338f14 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,6 +1,6 @@
 include ../Makefile.inc
 
-CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathcmddir)
+CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathcmddir) -Wno-unused-parameter
 LIBDEPS += -L$(multipathdir) -lmultipath -lcmocka
 
 TESTS := uevent parser util dmevents hwtable blacklist unaligned vpd pgpolicy alias
@@ -56,6 +56,7 @@ dep_clean:
 	@sed -n 's/^.*__wrap_\([a-zA-Z0-9_]*\).*$$/-Wl,--wrap=\1/p' $< | \
 		sort -u | tr '\n' ' ' >$@
 
+
 # COLON will get expanded during second expansion below
 COLON:=:
 .SECONDEXPANSION:
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 42/72] multipath-tools: Makefile.inc: remove -Wno-unused-parameter
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (40 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 41/72] multipath-tools tests: add -Wno-unused-parameter Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 43/72] libmultipath: dev_loss_tmo is unsigned Martin Wilck
                   ` (29 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

All warnings have been eliminated now.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 Makefile.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile.inc b/Makefile.inc
index 56c3eda0..da9a3d7d 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -93,7 +93,7 @@ ERROR_DISCARDED_QUALIFIERS := $(call TEST_CC_OPTION,-Werror=discarded-qualifiers
 
 OPTFLAGS	= -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int \
 		  -Werror=implicit-function-declaration -Werror=format-security \
-		  -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered \
+		  -Wno-sign-compare -Wno-clobbered \
 		  -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS) \
 		  -Wp,-D_FORTIFY_SOURCE=2 $(STACKPROT) \
 		  --param=ssp-buffer-size=4
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 43/72] libmultipath: dev_loss_tmo is unsigned
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (41 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 42/72] multipath-tools: Makefile.inc: remove -Wno-unused-parameter Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 44/72] libmultipath: trivial changes for -Wsign-compare Martin Wilck
                   ` (28 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Make MAX_DEV_LOSS_TMO reflect the fact that the kernel supports
timeouts up to UINT_MAX, and fix comparisons in discovery.c.

Cc: Hannes Reinecke <hare@suse.de>
Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/defaults.h  |  4 +++-
 libmultipath/discovery.c | 13 ++++++++-----
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/libmultipath/defaults.h b/libmultipath/defaults.h
index 4dfe007c..d7034655 100644
--- a/libmultipath/defaults.h
+++ b/libmultipath/defaults.h
@@ -1,5 +1,7 @@
 #ifndef _DEFAULTS_H
 #define _DEFAULTS_H
+#include <limits.h>
+
 /*
  * If you add or modify a value also update multipath/multipath.conf.5
  * and the TEMPLATE in libmultipath/hwtable.c
@@ -55,7 +57,7 @@
 #define DEFAULT_CHECKINT	5
 #define MAX_CHECKINT(a)		(a << 2)
 
-#define MAX_DEV_LOSS_TMO	0x7FFFFFFF
+#define MAX_DEV_LOSS_TMO	UINT_MAX
 #define DEFAULT_PIDFILE		"/" RUN_DIR "/multipathd.pid"
 #define DEFAULT_SOCKET		"/org/kernel/linux/storage/multipathd"
 #define DEFAULT_CONFIGFILE	"/etc/multipath.conf"
diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
index 4d93c91b..5fbc2ac7 100644
--- a/libmultipath/discovery.c
+++ b/libmultipath/discovery.c
@@ -624,9 +624,10 @@ sysfs_set_rport_tmo(struct multipath *mpp, struct path *pp)
 	    mpp->fast_io_fail != MP_FAST_IO_FAIL_ZERO &&
 	    mpp->fast_io_fail != MP_FAST_IO_FAIL_OFF) {
 		/* Check if we need to temporarily increase dev_loss_tmo */
-		if (mpp->fast_io_fail >= tmo) {
+		if ((unsigned int)mpp->fast_io_fail >= tmo) {
 			/* Increase dev_loss_tmo temporarily */
-			snprintf(value, 16, "%u", mpp->fast_io_fail + 1);
+			snprintf(value, sizeof(value), "%u",
+				 (unsigned int)mpp->fast_io_fail + 1);
 			ret = sysfs_attr_set_value(rport_dev, "dev_loss_tmo",
 						   value, strlen(value));
 			if (ret <= 0) {
@@ -757,10 +758,11 @@ sysfs_set_scsi_tmo (struct multipath *mpp, int checkint)
 {
 	struct path *pp;
 	int i;
-	int dev_loss_tmo = mpp->dev_loss;
+	unsigned int dev_loss_tmo = mpp->dev_loss;
 
 	if (mpp->no_path_retry > 0) {
-		uint64_t no_path_retry_tmo = (uint64_t)mpp->no_path_retry * checkint;
+		uint64_t no_path_retry_tmo =
+			(uint64_t)mpp->no_path_retry * checkint;
 
 		if (no_path_retry_tmo > MAX_DEV_LOSS_TMO)
 			no_path_retry_tmo = MAX_DEV_LOSS_TMO;
@@ -774,7 +776,8 @@ sysfs_set_scsi_tmo (struct multipath *mpp, int checkint)
 			mpp->alias, dev_loss_tmo);
 	}
 	mpp->dev_loss = dev_loss_tmo;
-	if (mpp->dev_loss && mpp->fast_io_fail >= (int)mpp->dev_loss) {
+	if (mpp->dev_loss && mpp->fast_io_fail > 0 &&
+	    (unsigned int)mpp->fast_io_fail >= mpp->dev_loss) {
 		condlog(3, "%s: turning off fast_io_fail (%d is not smaller than dev_loss_tmo)",
 			mpp->alias, mpp->fast_io_fail);
 		mpp->fast_io_fail = MP_FAST_IO_FAIL_OFF;
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 44/72] libmultipath: trivial changes for -Wsign-compare
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (42 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 43/72] libmultipath: dev_loss_tmo is unsigned Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 45/72] libmultipath: fix -Wsign-compare warnings with snprintf() Martin Wilck
                   ` (27 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

All these are obious fixes.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/alias.c                  |  2 +-
 libmultipath/devmapper.c              |  3 ++-
 libmultipath/discovery.c              | 17 ++++++++++-------
 libmultipath/file.c                   |  3 ++-
 libmultipath/foreign.c                |  2 +-
 libmultipath/parser.c                 |  2 +-
 libmultipath/prioritizers/alua_rtpg.c |  2 +-
 libmultipath/prioritizers/ana.c       |  7 ++++---
 libmultipath/structs.c                |  4 ++--
 libmultipath/structs.h                |  3 ++-
 libmultipath/sysfs.c                  |  6 +++---
 libmultipath/time-util.c              |  6 +++---
 libmultipath/uevent.c                 |  3 ++-
 libmultipath/util.c                   |  4 ++--
 libmultipath/util.h                   |  4 +++-
 libmultipath/uxsock.c                 |  3 ++-
 libmultipath/wwids.c                  |  4 ++--
 multipathd/main.c                     |  6 ++++--
 multipathd/pidfile.c                  |  2 +-
 19 files changed, 48 insertions(+), 35 deletions(-)

diff --git a/libmultipath/alias.c b/libmultipath/alias.c
index 0fc9e542..14401cae 100644
--- a/libmultipath/alias.c
+++ b/libmultipath/alias.c
@@ -256,7 +256,7 @@ allocate_binding(int fd, const char *wwid, int id, const char *prefix)
 			strerror(errno));
 		return NULL;
 	}
-	if (write(fd, buf, strlen(buf)) != strlen(buf)){
+	if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf)){
 		condlog(0, "Cannot write binding to bindings file : %s",
 			strerror(errno));
 		/* clear partial write */
diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
index f478ac2d..4bff37d0 100644
--- a/libmultipath/devmapper.c
+++ b/libmultipath/devmapper.c
@@ -1561,7 +1561,8 @@ int dm_reassign(const char *mapname)
 	struct dm_task *dmt;
 	struct dm_info info;
 	char dev_t[32], dm_dep[32];
-	int r = 0, i;
+	int r = 0;
+	unsigned int i;
 
 	if (dm_dev_t(mapname, &dev_t[0], 32)) {
 		condlog(3, "%s: failed to get device number", mapname);
diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
index 5fbc2ac7..c6c57430 100644
--- a/libmultipath/discovery.c
+++ b/libmultipath/discovery.c
@@ -224,7 +224,7 @@ out:
 ssize_t									\
 sysfs_get_##fname (struct udev_device * udev, char * buff, size_t len)	\
 {									\
-	int l;							\
+	size_t l;							\
 	const char * attr;						\
 	const char * devname;						\
 									\
@@ -945,7 +945,10 @@ get_geometry(struct path *pp)
 static int
 parse_vpd_pg80(const unsigned char *in, char *out, size_t out_len)
 {
-	int len = get_unaligned_be16(&in[2]);
+	size_t len = get_unaligned_be16(&in[2]);
+
+	if (out_len == 0)
+		return 0;
 
 	/*
 	 * Strip leading and trailing whitespace
@@ -958,8 +961,8 @@ parse_vpd_pg80(const unsigned char *in, char *out, size_t out_len)
 	}
 
 	if (len >= out_len) {
-		condlog(2, "vpd pg80 overflow, %d/%d bytes required",
-			len + 1, (int)out_len);
+		condlog(2, "vpd pg80 overflow, %lu/%lu bytes required",
+			len + 1, out_len);
 		len = out_len - 1;
 	}
 	if (len > 0) {
@@ -1725,7 +1728,7 @@ get_prio (struct path * pp)
  * Returns a pointer to the position where "end" was moved to.
  */
 static char
-*skip_zeroes_backward(char* start, int *len, char *end)
+*skip_zeroes_backward(char* start, size_t *len, char *end)
 {
 	char *p = end;
 
@@ -1751,10 +1754,10 @@ static char
  * Otherwise, returns 0.
  */
 static int
-fix_broken_nvme_wwid(struct path *pp, const char *value, int size)
+fix_broken_nvme_wwid(struct path *pp, const char *value, size_t size)
 {
 	static const char _nvme[] = "nvme.";
-	int len, i;
+	size_t len, i;
 	char mangled[256];
 	char *p;
 
diff --git a/libmultipath/file.c b/libmultipath/file.c
index 5cb06e1f..72f1d246 100644
--- a/libmultipath/file.c
+++ b/libmultipath/file.c
@@ -157,7 +157,8 @@ open_file(const char *file, int *can_write, const char *header)
 		if (*can_write == 0)
 			goto fail;
 		/* If file is empty, write the header */
-		size_t len = strlen(header);
+		int len = strlen(header);
+
 		if (write(fd, header, len) != len) {
 			condlog(0,
 				"Cannot write header to file %s : %s", file,
diff --git a/libmultipath/foreign.c b/libmultipath/foreign.c
index f05db162..0159a83a 100644
--- a/libmultipath/foreign.c
+++ b/libmultipath/foreign.c
@@ -172,7 +172,7 @@ static int _init_foreign(const char *multipath_dir, const char *enable)
 	for (i = 0; i < r; i++) {
 		const char *msg, *fn, *c;
 		struct foreign *fgn;
-		int len, namesz;
+		size_t len, namesz;
 
 		fn = di[i]->d_name;
 
diff --git a/libmultipath/parser.c b/libmultipath/parser.c
index e00c5fff..d478b177 100644
--- a/libmultipath/parser.c
+++ b/libmultipath/parser.c
@@ -124,7 +124,7 @@ find_keyword(vector keywords, vector v, char * name)
 {
 	struct keyword *keyword;
 	int i;
-	int len;
+	size_t len;
 
 	if (!name || !keywords)
 		return NULL;
diff --git a/libmultipath/prioritizers/alua_rtpg.c b/libmultipath/prioritizers/alua_rtpg.c
index 271a019d..bbf5aac0 100644
--- a/libmultipath/prioritizers/alua_rtpg.c
+++ b/libmultipath/prioritizers/alua_rtpg.c
@@ -371,7 +371,7 @@ get_asymmetric_access_state(const struct path *pp, unsigned int tpg,
 	struct rtpg_data *	tpgd;
 	struct rtpg_tpg_dscr *	dscr;
 	int			rc;
-	int			buflen;
+	unsigned int		buflen;
 	uint64_t		scsi_buflen;
 	int fd = pp->fd;
 
diff --git a/libmultipath/prioritizers/ana.c b/libmultipath/prioritizers/ana.c
index 9f7adfa5..b5c7873d 100644
--- a/libmultipath/prioritizers/ana.c
+++ b/libmultipath/prioritizers/ana.c
@@ -62,7 +62,7 @@ static const char *anas_string[] = {
 static const char *aas_print_string(int rc)
 {
 	rc &= 0xff;
-	if (rc >= 0 && rc < ARRAY_SIZE(anas_string) &&
+	if (rc >= 0 && rc < (int)ARRAY_SIZE(anas_string) &&
 	    anas_string[rc] != NULL)
 		return anas_string[rc];
 
@@ -78,7 +78,8 @@ static int get_ana_state(__u32 nsid, __u32 anagrpid, void *ana_log,
 	size_t offset = sizeof(struct nvme_ana_rsp_hdr);
 	__u32 nr_nsids;
 	size_t nsid_buf_size;
-	int i, j;
+	int i;
+	unsigned int j;
 
 	for (i = 0; i < le16_to_cpu(hdr->ngrps); i++) {
 		ana_desc = base + offset;
@@ -225,7 +226,7 @@ int getprio(struct path *pp, __attribute__((unused)) char *args,
 	default:
 		break;
 	}
-	if (rc < 0 && -rc < ARRAY_SIZE(ana_errmsg))
+	if (rc < 0 && -rc < (int)ARRAY_SIZE(ana_errmsg))
 		condlog(2, "%s: ANA error: %s", pp->dev, ana_errmsg[-rc]);
 	else
 		condlog(1, "%s: invalid ANA rc code %d", pp->dev, rc);
diff --git a/libmultipath/structs.c b/libmultipath/structs.c
index bf7fdd73..f420ee5c 100644
--- a/libmultipath/structs.c
+++ b/libmultipath/structs.c
@@ -350,7 +350,7 @@ store_adaptergroup(vector adapters, struct adapter_group * agp)
 }
 
 struct multipath *
-find_mp_by_minor (const struct _vector *mpvec, int minor)
+find_mp_by_minor (const struct _vector *mpvec, unsigned int minor)
 {
 	int i;
 	struct multipath * mpp;
@@ -388,7 +388,7 @@ struct multipath *
 find_mp_by_alias (const struct _vector *mpvec, const char * alias)
 {
 	int i;
-	int len;
+	size_t len;
 	struct multipath * mpp;
 
 	if (!mpvec)
diff --git a/libmultipath/structs.h b/libmultipath/structs.h
index a3adf906..3665b89a 100644
--- a/libmultipath/structs.h
+++ b/libmultipath/structs.h
@@ -440,7 +440,8 @@ 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, int minor);
+struct multipath * find_mp_by_minor (const struct _vector *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);
diff --git a/libmultipath/sysfs.c b/libmultipath/sysfs.c
index 65904d7b..923b529b 100644
--- a/libmultipath/sysfs.c
+++ b/libmultipath/sysfs.c
@@ -88,7 +88,7 @@ ssize_t sysfs_attr_get_value(struct udev_device *dev, const char *attr_name,
 		condlog(4, "read from %s failed: %s", devpath, strerror(errno));
 		size = -errno;
 		value[0] = '\0';
-	} else if (size == value_len) {
+	} else if (size == (ssize_t)value_len) {
 		value[size - 1] = '\0';
 		condlog(4, "overflow while reading from %s", devpath);
 		size = 0;
@@ -146,7 +146,7 @@ ssize_t sysfs_bin_attr_get_value(struct udev_device *dev, const char *attr_name,
 	if (size < 0) {
 		condlog(4, "read from %s failed: %s", devpath, strerror(errno));
 		size = -errno;
-	} else if (size == value_len) {
+	} else if (size == (ssize_t)value_len) {
 		condlog(4, "overflow while reading from %s", devpath);
 		size = 0;
 	}
@@ -200,7 +200,7 @@ ssize_t sysfs_attr_set_value(struct udev_device *dev, const char *attr_name,
 	if (size < 0) {
 		condlog(4, "write to %s failed: %s", devpath, strerror(errno));
 		size = -errno;
-	} else if (size < value_len) {
+	} else if (size < (ssize_t)value_len) {
 		condlog(4, "tried to write %ld to %s. Wrote %ld",
 			(long)value_len, devpath, (long)size);
 		size = 0;
diff --git a/libmultipath/time-util.c b/libmultipath/time-util.c
index a3739a2d..55f366cc 100644
--- a/libmultipath/time-util.c
+++ b/libmultipath/time-util.c
@@ -32,11 +32,11 @@ void pthread_cond_init_mono(pthread_cond_t *cond)
 void normalize_timespec(struct timespec *ts)
 {
 	while (ts->tv_nsec < 0) {
-		ts->tv_nsec += 1000UL * 1000 * 1000;
+		ts->tv_nsec += 1000L * 1000 * 1000;
 		ts->tv_sec--;
 	}
-	while (ts->tv_nsec >= 1000UL * 1000 * 1000) {
-		ts->tv_nsec -= 1000UL * 1000 * 1000;
+	while (ts->tv_nsec >= 1000L * 1000 * 1000) {
+		ts->tv_nsec -= 1000L * 1000 * 1000;
 		ts->tv_sec++;
 	}
 }
diff --git a/libmultipath/uevent.c b/libmultipath/uevent.c
index f128ced2..d38e8a7f 100644
--- a/libmultipath/uevent.c
+++ b/libmultipath/uevent.c
@@ -108,7 +108,8 @@ uevq_cleanup(struct list_head *tmpq)
 static const char* uevent_get_env_var(const struct uevent *uev,
 				      const char *attr)
 {
-	int i, len;
+	int i;
+	size_t len;
 	const char *p = NULL;
 
 	if (attr == NULL)
diff --git a/libmultipath/util.c b/libmultipath/util.c
index 28cbf4b9..ccc0de29 100644
--- a/libmultipath/util.c
+++ b/libmultipath/util.c
@@ -44,7 +44,7 @@ basenamecpy (const char *src, char *dst, size_t size)
 	p = basename(src);
 
 	for (e = p + strlen(p) - 1; e >= p && isspace(*e); --e) ;
-	if (e < p || e - p > size - 2)
+	if (e < p || (size_t)(e - p) > size - 2)
 		return 0;
 
 	strlcpy(dst, p, e - p + 2);
@@ -428,7 +428,7 @@ int safe_write(int fd, const void *buf, size_t count)
 	return 0;
 }
 
-void set_max_fds(int max_fds)
+void set_max_fds(rlim_t max_fds)
 {
 	struct rlimit fd_limit;
 
diff --git a/libmultipath/util.h b/libmultipath/util.h
index 693991c1..913ab7c2 100644
--- a/libmultipath/util.h
+++ b/libmultipath/util.h
@@ -2,6 +2,8 @@
 #define _UTIL_H
 
 #include <sys/types.h>
+/* for rlim_t */
+#include <sys/resource.h>
 #include <inttypes.h>
 #include <stdbool.h>
 
@@ -21,7 +23,7 @@ int get_linux_version_code(void);
 int parse_prkey(char *ptr, uint64_t *prkey);
 int parse_prkey_flags(char *ptr, uint64_t *prkey, uint8_t *flags);
 int safe_write(int fd, const void *buf, size_t count);
-void set_max_fds(int max_fds);
+void set_max_fds(rlim_t max_fds);
 
 #define KERNEL_VERSION(maj, min, ptc) ((((maj) * 256) + (min)) * 256 + (ptc))
 #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
diff --git a/libmultipath/uxsock.c b/libmultipath/uxsock.c
index 9b4e9784..6adeedfc 100644
--- a/libmultipath/uxsock.c
+++ b/libmultipath/uxsock.c
@@ -40,7 +40,8 @@ static int _recv_packet(int fd, char **buf, unsigned int timeout,
  */
 int ux_socket_listen(const char *name)
 {
-	int fd, len;
+	int fd;
+	size_t len;
 #ifdef USE_SYSTEMD
 	int num;
 #endif
diff --git a/libmultipath/wwids.c b/libmultipath/wwids.c
index d02a7072..291db8f5 100644
--- a/libmultipath/wwids.c
+++ b/libmultipath/wwids.c
@@ -74,7 +74,7 @@ write_out_wwid(int fd, char *wwid) {
 			strerror(errno));
 		return -1;
 	}
-	if (write(fd, buf, strlen(buf)) != strlen(buf)) {
+	if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf)) {
 		condlog(0, "cannot write wwid to wwids file : %s",
 			strerror(errno));
 		if (ftruncate(fd, offset))
@@ -117,7 +117,7 @@ replace_wwids(vector mp)
 		goto out_file;
 	}
 	len = strlen(WWIDS_FILE_HEADER);
-	if (write(fd, WWIDS_FILE_HEADER, len) != len) {
+	if (write(fd, WWIDS_FILE_HEADER, len) != (ssize_t)len) {
 		condlog(0, "Can't write wwid file header : %s",
 			strerror(errno));
 		/* cleanup partially written header */
diff --git a/multipathd/main.c b/multipathd/main.c
index e55f2795..26d5aa9c 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -1949,8 +1949,9 @@ static int check_path_reinstate_state(struct path * pp) {
 	 * so that the cutomer can rectify the issue within this time. After
 	 * the completion of san_path_err_recovery_time it should
 	 * automatically reinstate the path
+	 * (note: we know that san_path_err_threshold > 0 here).
 	 */
-	if (pp->path_failures > pp->mpp->san_path_err_threshold) {
+	if (pp->path_failures > (unsigned int)pp->mpp->san_path_err_threshold) {
 		condlog(2, "%s : hit error threshold. Delaying path reinstatement", pp->dev);
 		pp->dis_reinstate_time = curr_time.tv_sec;
 		pp->disable_reinstate = 1;
@@ -3247,7 +3248,8 @@ main (int argc, char *argv[])
 void *  mpath_pr_event_handler_fn (void * pathp )
 {
 	struct multipath * mpp;
-	int i, ret, isFound;
+	unsigned int i;
+	int ret, isFound;
 	struct path * pp = (struct path *)pathp;
 	struct prout_param_descriptor *param;
 	struct prin_resp *resp;
diff --git a/multipathd/pidfile.c b/multipathd/pidfile.c
index 47d18e2c..cc0fbec1 100644
--- a/multipathd/pidfile.c
+++ b/multipathd/pidfile.c
@@ -42,7 +42,7 @@ int pidfile_create(const char *pidFile, pid_t pid)
 	}
 	memset(buf, 0, sizeof(buf));
 	snprintf(buf, sizeof(buf)-1, "%u", pid);
-	if (write(fd, buf, strlen(buf)) != strlen(buf)) {
+	if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf)) {
 		condlog(0, "Cannot write pid to pidfile [%s], error was [%s]",
 			pidFile, strerror(errno));
 		goto fail;
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 45/72] libmultipath: fix -Wsign-compare warnings with snprintf()
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (43 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 44/72] libmultipath: trivial changes for -Wsign-compare Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 22:59   ` Bart Van Assche
  2019-10-12 21:28 ` [PATCH 46/72] libmultipath: parse_vpd_pg83(): sanitize indentation Martin Wilck
                   ` (26 subsequent siblings)
  71 siblings, 1 reply; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

snprintf() returns int, and thus its result needs to be compared
with a signed int. In theory, snprintf can return -1 with errno
EOVERFLOW if the "size" argument exceeds INT_MAX, but this can
be quite safely ignored for now.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 kpartx/devmapper.c          | 3 ++-
 kpartx/kpartx.h             | 2 +-
 libmultipath/foreign/nvme.c | 4 ++--
 libmultipath/sysfs.c        | 4 ++--
 libmultipath/util.c         | 3 ++-
 libmultipath/util.h         | 4 ++--
 libmultipath/wwids.c        | 2 +-
 multipath/main.c            | 2 +-
 8 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/kpartx/devmapper.c b/kpartx/devmapper.c
index 3aa4988d..7e599e07 100644
--- a/kpartx/devmapper.c
+++ b/kpartx/devmapper.c
@@ -107,7 +107,8 @@ strip_slash (char * device)
 static int format_partname(char *buf, size_t bufsiz,
 			   const char *mapname, const char *delim, int part)
 {
-	if (snprintf(buf, bufsiz, "%s%s%d", mapname, delim, part) >= bufsiz)
+	if (snprintf(buf, bufsiz, "%s%s%d", mapname, delim, part)
+	    >= (int)bufsiz)
 		return 0;
 	strip_slash(buf);
 	return 1;
diff --git a/kpartx/kpartx.h b/kpartx/kpartx.h
index 52920e43..3ec13dbc 100644
--- a/kpartx/kpartx.h
+++ b/kpartx/kpartx.h
@@ -17,7 +17,7 @@
 #define unlikely(x)     __builtin_expect(!!(x), 0)
 
 #define safe_sprintf(var, format, args...)	\
-	snprintf(var, sizeof(var), format, ##args) >= sizeof(var)
+	snprintf(var, sizeof(var), format, ##args) >= (int)sizeof(var)
 
 #ifndef BLKSSZGET
 #define BLKSSZGET  _IO(0x12,104)	/* get block device sector size */
diff --git a/libmultipath/foreign/nvme.c b/libmultipath/foreign/nvme.c
index e8ca516c..17569b36 100644
--- a/libmultipath/foreign/nvme.c
+++ b/libmultipath/foreign/nvme.c
@@ -592,7 +592,7 @@ static void test_ana_support(struct nvme_map *map, struct udev_device *ctl)
 
 	dev_t = udev_device_get_sysattr_value(ctl, "dev");
 	if (snprintf(sys_path, sizeof(sys_path), "/dev/char/%s", dev_t)
-	    >= sizeof(sys_path))
+	    >= (int)sizeof(sys_path))
 		return;
 
 	fd = open(sys_path, O_RDONLY);
@@ -664,7 +664,7 @@ static void _find_controllers(struct context *ctx, struct nvme_map *map)
 		struct udev_device *ctrl, *udev;
 
 		if (snprintf(pathbuf + n, sizeof(pathbuf) - n, "/%s", fn)
-		    >= sizeof(pathbuf) - n)
+		    >= (int)(sizeof(pathbuf) - n))
 			continue;
 		if (realpath(pathbuf, realbuf) == NULL) {
 			condlog(3, "%s: %s: realpath: %s", __func__, THIS,
diff --git a/libmultipath/sysfs.c b/libmultipath/sysfs.c
index 923b529b..eb1f03e1 100644
--- a/libmultipath/sysfs.c
+++ b/libmultipath/sysfs.c
@@ -306,7 +306,7 @@ bool sysfs_is_multipathed(const struct path *pp)
 	n = snprintf(pathbuf, sizeof(pathbuf), "/sys/block/%s/holders",
 		     pp->dev);
 
-	if (n >= sizeof(pathbuf)) {
+	if (n >= (int)sizeof(pathbuf)) {
 		condlog(1, "%s: pathname overflow", __func__);
 		return false;
 	}
@@ -329,7 +329,7 @@ bool sysfs_is_multipathed(const struct path *pp)
 
 		if (snprintf(pathbuf + n, sizeof(pathbuf) - n,
 			     "/%s/dm/uuid", di[i]->d_name)
-		    >= sizeof(pathbuf) - n)
+		    >= (int)(sizeof(pathbuf) - n))
 			continue;
 
 		fd = open(pathbuf, O_RDONLY);
diff --git a/libmultipath/util.c b/libmultipath/util.c
index ccc0de29..4657e7db 100644
--- a/libmultipath/util.c
+++ b/libmultipath/util.c
@@ -213,7 +213,8 @@ int devt2devname(char *devname, int devname_len, char *devt)
 
 		if ((major == tmpmaj) && (minor == tmpmin)) {
 			if (snprintf(block_path, sizeof(block_path),
-				     "/sys/block/%s", dev) >= sizeof(block_path)) {
+				     "/sys/block/%s", dev)
+			    >= (int)sizeof(block_path)) {
 				condlog(0, "device name %s is too long", dev);
 				fclose(fd);
 				return 1;
diff --git a/libmultipath/util.h b/libmultipath/util.h
index 913ab7c2..cfc3b7a9 100644
--- a/libmultipath/util.h
+++ b/libmultipath/util.h
@@ -29,9 +29,9 @@ void set_max_fds(rlim_t max_fds);
 #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
 
 #define safe_sprintf(var, format, args...)	\
-	snprintf(var, sizeof(var), format, ##args) >= sizeof(var)
+	snprintf((var), sizeof(var), (format), ##args) >= (int)sizeof(var)
 #define safe_snprintf(var, size, format, args...)      \
-	snprintf(var, size, format, ##args) >= size
+	snprintf(var, size, format, ##args) >= (int)size
 
 #define pthread_cleanup_push_cast(f, arg)		\
 	pthread_cleanup_push(((void (*)(void *))&f), (arg))
diff --git a/libmultipath/wwids.c b/libmultipath/wwids.c
index 291db8f5..57c2707b 100644
--- a/libmultipath/wwids.c
+++ b/libmultipath/wwids.c
@@ -394,7 +394,7 @@ static int _failed_wwid_op(const char *wwid, bool rw,
 	int r = -1;
 
 	if (snprintf(path, sizeof(path), "%s/%s", shm_dir, wwid)
-	    >= sizeof(path)) {
+	    >= (int)sizeof(path)) {
 		condlog(1, "%s: path name overflow", __func__);
 		return -1;
 	}
diff --git a/multipath/main.c b/multipath/main.c
index c2ef8c7b..8d518585 100644
--- a/multipath/main.c
+++ b/multipath/main.c
@@ -424,7 +424,7 @@ static int find_multipaths_check_timeout(const struct path *pp, long tmo,
 	clock_gettime(CLOCK_REALTIME, &now);
 
 	if (snprintf(path, sizeof(path), "%s/%s", shm_find_mp_dir, pp->dev_t)
-	    >= sizeof(path)) {
+	    >= (int)sizeof(path)) {
 		condlog(1, "%s: path name overflow", __func__);
 		return FIND_MULTIPATHS_ERROR;
 	}
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 46/72] libmultipath: parse_vpd_pg83(): sanitize indentation
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (44 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 45/72] libmultipath: fix -Wsign-compare warnings with snprintf() Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 47/72] libmultipath: parse_vpd_pg83(): fix -Wsign-compare warnings Martin Wilck
                   ` (25 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

This just moves a lot of code to the left. No functional change.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/discovery.c | 174 ++++++++++++++++++++-------------------
 1 file changed, 88 insertions(+), 86 deletions(-)

diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
index c6c57430..0d0a6bc1 100644
--- a/libmultipath/discovery.c
+++ b/libmultipath/discovery.c
@@ -1045,100 +1045,102 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len,
 		}
 		d += d[3] + 4;
 	}
-	if (prio > 0) {
-		vpd_type = vpd[1] & 0xf;
-		vpd_len = vpd[3];
+
+	if (prio <= 0)
+		return -ENODATA;
+
+	vpd_type = vpd[1] & 0xf;
+	vpd_len = vpd[3];
+	vpd += 4;
+	if (vpd_type == 0x2 || vpd_type == 0x3) {
+		int i;
+
+		assert(out_len >= 2);
+		len = sprintf(out, "%d", vpd_type);
+		if (2 * vpd_len >= out_len - len) {
+			condlog(1, "%s: WWID overflow, type %d, %d/%lu bytes required",
+				__func__, vpd_type,
+				2 * vpd_len + len + 1, out_len);
+			vpd_len = (out_len - len - 1) / 2;
+		}
+		for (i = 0; i < vpd_len; i++)
+			len += sprintf(out + len,
+				       "%02x", vpd[i]);
+	} else if (vpd_type == 0x8) {
+		if (!memcmp("eui.", vpd, 4))
+			out[0] =  '2';
+		else if (!memcmp("naa.", vpd, 4))
+			out[0] = '3';
+		else
+			out[0] = '8';
+
 		vpd += 4;
-		if (vpd_type == 0x2 || vpd_type == 0x3) {
-			int i;
-
-			assert(out_len >= 2);
-			len = sprintf(out, "%d", vpd_type);
-			if (2 * vpd_len >= out_len - len) {
-				condlog(1, "%s: WWID overflow, type %d, %d/%lu bytes required",
-					__func__, vpd_type,
-					2 * vpd_len + len + 1, out_len);
-				vpd_len = (out_len - len - 1) / 2;
-			}
-			for (i = 0; i < vpd_len; i++)
-				len += sprintf(out + len,
-					       "%02x", vpd[i]);
-		} else if (vpd_type == 0x8) {
-			if (!memcmp("eui.", vpd, 4))
-				out[0] =  '2';
-			else if (!memcmp("naa.", vpd, 4))
-				out[0] = '3';
-			else
-				out[0] = '8';
-
-			vpd += 4;
-			len = vpd_len - 4;
-			while (len > 2 && vpd[len - 2] == '\0')
-				--len;
-			if (len > out_len - 1) {
-				condlog(1, "%s: WWID overflow, type 8/%c, %d/%lu bytes required",
-					__func__, out[0], len + 1, out_len);
-				len = out_len - 1;
-			}
+		len = vpd_len - 4;
+		while (len > 2 && vpd[len - 2] == '\0')
+			--len;
+		if (len > out_len - 1) {
+			condlog(1, "%s: WWID overflow, type 8/%c, %d/%lu bytes required",
+				__func__, out[0], len + 1, out_len);
+			len = out_len - 1;
+		}
 
-			if (out[0] == '8')
-				for (i = 0; i < len; ++i)
-					out[1 + i] = vpd[i];
-			else
-				for (i = 0; i < len; ++i)
-					out[1 + i] = tolower(vpd[i]);
+		if (out[0] == '8')
+			for (i = 0; i < len; ++i)
+				out[1 + i] = vpd[i];
+		else
+			for (i = 0; i < len; ++i)
+				out[1 + i] = tolower(vpd[i]);
 
-			/* designator should be 0-terminated, but let's make sure */
-			out[len] = '\0';
+		/* designator should be 0-terminated, but let's make sure */
+		out[len] = '\0';
 
-		} else if (vpd_type == 0x1) {
-			const unsigned char *p;
-			int p_len;
-
-			out[0] = '1';
-			len = 1;
-			p = vpd;
-			while ((p = memchr(vpd, ' ', vpd_len))) {
-				p_len = p - vpd;
-				if (len + p_len > out_len - 1) {
-					condlog(1, "%s: WWID overflow, type 1, %d/%lu bytes required",
-						__func__, len + p_len, out_len);
-					p_len = out_len - len - 1;
-				}
-				memcpy(out + len, vpd, p_len);
-				len += p_len;
-				if (len >= out_len - 1) {
-					out[len] = '\0';
-					break;
-				}
-				out[len] = '_';
-				len ++;
-				if (len >= out_len - 1) {
-					out[len] = '\0';
-					break;
-				}
-				vpd = p;
-				vpd_len -= p_len;
-				while (vpd && *vpd == ' ') {
-					vpd++;
-					vpd_len --;
-				}
+	} else if (vpd_type == 0x1) {
+		const unsigned char *p;
+		int p_len;
+
+		out[0] = '1';
+		len = 1;
+		p = vpd;
+		while ((p = memchr(vpd, ' ', vpd_len))) {
+			p_len = p - vpd;
+			if (len + p_len > out_len - 1) {
+				condlog(1, "%s: WWID overflow, type 1, %d/%lu bytes required",
+					__func__, len + p_len, out_len);
+				p_len = out_len - len - 1;
 			}
-			p_len = vpd_len;
-			if (p_len > 0 && len < out_len - 1) {
-				if (len + p_len > out_len - 1) {
-					condlog(1, "%s: WWID overflow, type 1, %d/%lu bytes required",
-						__func__, len + p_len + 1, out_len);
-					p_len = out_len - len - 1;
-				}
-				memcpy(out + len, vpd, p_len);
-				len += p_len;
+			memcpy(out + len, vpd, p_len);
+			len += p_len;
+			if (len >= out_len - 1) {
 				out[len] = '\0';
+				break;
 			}
-			if (len > 1 && out[len - 1] == '_') {
-				out[len - 1] = '\0';
-				len--;
+			out[len] = '_';
+			len ++;
+			if (len >= out_len - 1) {
+				out[len] = '\0';
+				break;
 			}
+			vpd = p;
+			vpd_len -= p_len;
+			while (vpd && *vpd == ' ') {
+				vpd++;
+				vpd_len --;
+			}
+		}
+		p_len = vpd_len;
+		if (p_len > 0 && len < out_len - 1) {
+			if (len + p_len > out_len - 1) {
+				condlog(1, "%s: WWID overflow, type 1, %d/%lu bytes required",
+					__func__, len + p_len + 1, out_len);
+				p_len = out_len - len - 1;
+			}
+			memcpy(out + len, vpd, p_len);
+			len += p_len;
+			out[len] = '\0';
+		}
+		if (len > 1 && out[len - 1] == '_') {
+			out[len - 1] = '\0';
+			len--;
 		}
 	}
 	return len;
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 47/72] libmultipath: parse_vpd_pg83(): fix -Wsign-compare warnings
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (45 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 46/72] libmultipath: parse_vpd_pg83(): sanitize indentation Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 48/72] libmultipath: print: use unsigned int for "width" field Martin Wilck
                   ` (24 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Most of this is trivial. Changes are: return early if there
is obviously not enough space. Check vpd_len for designator
type 8.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/discovery.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
index 0d0a6bc1..6288c3e0 100644
--- a/libmultipath/discovery.c
+++ b/libmultipath/discovery.c
@@ -978,7 +978,8 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len,
 {
 	const unsigned char *d;
 	const unsigned char *vpd = NULL;
-	int len = -ENODATA, vpd_type, vpd_len, prio = -1, i, naa_prio;
+	size_t len, vpd_len, i;
+	int vpd_type, prio = -1, naa_prio;
 
 	d = in + 4;
 	while (d < in + in_len) {
@@ -1048,17 +1049,20 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len,
 
 	if (prio <= 0)
 		return -ENODATA;
+	/* Need space at least for one digit */
+	else if (out_len <= 1)
+		return 0;
 
+	len = 0;
 	vpd_type = vpd[1] & 0xf;
 	vpd_len = vpd[3];
 	vpd += 4;
 	if (vpd_type == 0x2 || vpd_type == 0x3) {
-		int i;
+		size_t i;
 
-		assert(out_len >= 2);
 		len = sprintf(out, "%d", vpd_type);
 		if (2 * vpd_len >= out_len - len) {
-			condlog(1, "%s: WWID overflow, type %d, %d/%lu bytes required",
+			condlog(1, "%s: WWID overflow, type %d, %lu/%lu bytes required",
 				__func__, vpd_type,
 				2 * vpd_len + len + 1, out_len);
 			vpd_len = (out_len - len - 1) / 2;
@@ -1066,6 +1070,10 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len,
 		for (i = 0; i < vpd_len; i++)
 			len += sprintf(out + len,
 				       "%02x", vpd[i]);
+	} else if (vpd_type == 0x8 && vpd_len < 4) {
+		condlog(1, "%s: VPD length %lu too small for designator type 8",
+			__func__, vpd_len);
+		return -EINVAL;
 	} else if (vpd_type == 0x8) {
 		if (!memcmp("eui.", vpd, 4))
 			out[0] =  '2';
@@ -1079,7 +1087,7 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len,
 		while (len > 2 && vpd[len - 2] == '\0')
 			--len;
 		if (len > out_len - 1) {
-			condlog(1, "%s: WWID overflow, type 8/%c, %d/%lu bytes required",
+			condlog(1, "%s: WWID overflow, type 8/%c, %lu/%lu bytes required",
 				__func__, out[0], len + 1, out_len);
 			len = out_len - 1;
 		}
@@ -1096,15 +1104,14 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len,
 
 	} else if (vpd_type == 0x1) {
 		const unsigned char *p;
-		int p_len;
+		size_t p_len;
 
 		out[0] = '1';
 		len = 1;
-		p = vpd;
 		while ((p = memchr(vpd, ' ', vpd_len))) {
 			p_len = p - vpd;
 			if (len + p_len > out_len - 1) {
-				condlog(1, "%s: WWID overflow, type 1, %d/%lu bytes required",
+				condlog(1, "%s: WWID overflow, type 1, %lu/%lu bytes required",
 					__func__, len + p_len, out_len);
 				p_len = out_len - len - 1;
 			}
@@ -1130,7 +1137,7 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len,
 		p_len = vpd_len;
 		if (p_len > 0 && len < out_len - 1) {
 			if (len + p_len > out_len - 1) {
-				condlog(1, "%s: WWID overflow, type 1, %d/%lu bytes required",
+				condlog(1, "%s: WWID overflow, type 1, %lu/%lu bytes required",
 					__func__, len + p_len + 1, out_len);
 				p_len = out_len - len - 1;
 			}
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 48/72] libmultipath: print: use unsigned int for "width" field
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (46 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 47/72] libmultipath: parse_vpd_pg83(): fix -Wsign-compare warnings Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 49/72] libmultipath: vector_for_each_slot: fix -Wsign-compare warnings Martin Wilck
                   ` (23 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/print.c | 4 ++--
 libmultipath/print.h | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/libmultipath/print.c b/libmultipath/print.c
index 8fa86267..b98e9bda 100644
--- a/libmultipath/print.c
+++ b/libmultipath/print.c
@@ -36,7 +36,7 @@
 #define NOPAD    s = c
 #define PAD(x) \
 do { \
-	while ((int)(c - s) < (x) && (c < (line + len - 1))) \
+	while (c < (s + x) && (c < (line + len - 1))) \
 		*c++ = ' '; \
 	s = c; \
 } while (0)
@@ -783,7 +783,7 @@ get_path_layout(vector pathvec, int header)
 }
 
 static void
-reset_width(int *width, enum layout_reset reset, const char *header)
+reset_width(unsigned int *width, enum layout_reset reset, const char *header)
 {
 	switch (reset) {
 	case LAYOUT_RESET_HEADER:
diff --git a/libmultipath/print.h b/libmultipath/print.h
index 0c909e75..e8260d03 100644
--- a/libmultipath/print.h
+++ b/libmultipath/print.h
@@ -78,21 +78,21 @@
 struct path_data {
 	char wildcard;
 	char * header;
-	int width;
+	unsigned int width;
 	int (*snprint)(char * buff, size_t len, const struct path * pp);
 };
 
 struct multipath_data {
 	char wildcard;
 	char * header;
-	int width;
+	unsigned int width;
 	int (*snprint)(char * buff, size_t len, const struct multipath * mpp);
 };
 
 struct pathgroup_data {
 	char wildcard;
 	char * header;
-	int width;
+	unsigned int width;
 	int (*snprint)(char * buff, size_t len, const struct pathgroup * pgp);
 };
 
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 49/72] libmultipath: vector_for_each_slot: fix -Wsign-compare warnings
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (47 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 48/72] libmultipath: print: use unsigned int for "width" field Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 50/72] libmultipath: set_int(): add error check and set_uint() Martin Wilck
                   ` (22 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/vector.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libmultipath/vector.h b/libmultipath/vector.h
index 344dffd5..e16ec461 100644
--- a/libmultipath/vector.h
+++ b/libmultipath/vector.h
@@ -36,9 +36,9 @@ typedef struct _vector *vector;
 #define VECTOR_LAST_SLOT(V)   (((V) && VECTOR_SIZE(V) > 0) ? (V)->slot[(VECTOR_SIZE(V) - 1)] : NULL)
 
 #define vector_foreach_slot(v,p,i) \
-	for (i = 0; (v) && i < VECTOR_SIZE(v) && ((p) = (v)->slot[i]); i++)
+	for (i = 0; (v) && (int)i < VECTOR_SIZE(v) && ((p) = (v)->slot[i]); i++)
 #define vector_foreach_slot_after(v,p,i) \
-	for (; (v) && i < VECTOR_SIZE(v) && ((p) = (v)->slot[i]); i++)
+	for (; (v) && (int)i < VECTOR_SIZE(v) && ((p) = (v)->slot[i]); i++)
 #define vector_foreach_slot_backwards(v,p,i) \
 	for (i = VECTOR_SIZE(v) - 1; (int)i >= 0 && ((p) = (v)->slot[i]); i--)
 
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 50/72] libmultipath: set_int(): add error check and set_uint()
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (48 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 49/72] libmultipath: vector_for_each_slot: fix -Wsign-compare warnings Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 51/72] libmultipath: make "checkint" unsigned Martin Wilck
                   ` (21 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Use strtol() to check for valid input, but don't return error
as that would cause config file parsing to fail because of a
single typo. Also, add set_uint() to parse an unsigned parameter.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/dict.c | 48 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 45 insertions(+), 3 deletions(-)

diff --git a/libmultipath/dict.c b/libmultipath/dict.c
index 2b046e1d..c23d525b 100644
--- a/libmultipath/dict.c
+++ b/libmultipath/dict.c
@@ -31,16 +31,58 @@ static int
 set_int(vector strvec, void *ptr)
 {
 	int *int_ptr = (int *)ptr;
-	char * buff;
+	char *buff, *eptr;
+	long res;
+	int rc;
 
 	buff = set_value(strvec);
 	if (!buff)
 		return 1;
 
-	*int_ptr = atoi(buff);
+	res = strtol(buff, &eptr, 10);
+	if (eptr > buff)
+		while (isspace(*eptr))
+			eptr++;
+	if (*buff == '\0' || *eptr != '\0' || res > INT_MAX || res < INT_MIN) {
+		condlog(1, "%s: invalid value for %s: \"%s\"",
+			__func__, (char*)VECTOR_SLOT(strvec, 0), buff);
+		rc = 1;
+	} else {
+		rc = 0;
+		*int_ptr = res;
+	}
 
 	FREE(buff);
-	return 0;
+	return rc;
+}
+
+static int
+set_uint(vector strvec, void *ptr)
+{
+	unsigned int *uint_ptr = (unsigned int *)ptr;
+	char *buff, *eptr;
+	long res;
+	int rc;
+
+	buff = set_value(strvec);
+	if (!buff)
+		return 1;
+
+	res = strtol(buff, &eptr, 10);
+	if (eptr > buff)
+		while (isspace(*eptr))
+			eptr++;
+	if (*buff == '\0' || *eptr != '\0' || res < 0 || res > UINT_MAX) {
+		condlog(1, "%s: invalid value for %s: \"%s\"",
+			__func__, (char*)VECTOR_SLOT(strvec, 0), buff);
+		rc = 1;
+	} else {
+		rc = 0;
+		*uint_ptr = res;
+	}
+
+	FREE(buff);
+	return rc;
 }
 
 static int
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 51/72] libmultipath: make "checkint" unsigned
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (49 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 50/72] libmultipath: set_int(): add error check and set_uint() Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 52/72] libmultipath: use unsigned blksize in directio context Martin Wilck
                   ` (20 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

path->checkint was unsigned already, now use this type everywhere.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/config.h      |  4 ++--
 libmultipath/dict.c        |  4 ++--
 libmultipath/discovery.c   |  2 +-
 libmultipath/discovery.h   |  2 +-
 libmultipath/io_err_stat.c |  2 +-
 libmultipath/structs_vec.c |  2 +-
 multipathd/main.c          | 10 ++++++----
 7 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/libmultipath/config.h b/libmultipath/config.h
index ffec3103..2ab7b42c 100644
--- a/libmultipath/config.h
+++ b/libmultipath/config.h
@@ -137,8 +137,8 @@ struct config {
 	int pgpolicy;
 	int minio;
 	int minio_rq;
-	int checkint;
-	int max_checkint;
+	unsigned int checkint;
+	unsigned int max_checkint;
 	int pgfailback;
 	int remove;
 	int rr_weight;
diff --git a/libmultipath/dict.c b/libmultipath/dict.c
index c23d525b..a90690fa 100644
--- a/libmultipath/dict.c
+++ b/libmultipath/dict.c
@@ -314,7 +314,7 @@ snprint_mp_ ## option (struct config *conf, char * buff, int len,	\
 
 static int checkint_handler(struct config *conf, vector strvec)
 {
-	int rc = set_int(strvec, &conf->checkint);
+	int rc = set_uint(strvec, &conf->checkint);
 
 	if (rc)
 		return rc;
@@ -325,7 +325,7 @@ static int checkint_handler(struct config *conf, vector strvec)
 
 declare_def_snprint(checkint, print_int)
 
-declare_def_handler(max_checkint, set_int)
+declare_def_handler(max_checkint, set_uint)
 declare_def_snprint(max_checkint, print_int)
 
 declare_def_handler(verbosity, set_int)
diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
index 6288c3e0..4288c9fd 100644
--- a/libmultipath/discovery.c
+++ b/libmultipath/discovery.c
@@ -754,7 +754,7 @@ sysfs_set_nexus_loss_tmo(struct multipath *mpp, struct path *pp)
 }
 
 int
-sysfs_set_scsi_tmo (struct multipath *mpp, int checkint)
+sysfs_set_scsi_tmo (struct multipath *mpp, unsigned int checkint)
 {
 	struct path *pp;
 	int i;
diff --git a/libmultipath/discovery.h b/libmultipath/discovery.h
index 8d04c2af..0516e41b 100644
--- a/libmultipath/discovery.h
+++ b/libmultipath/discovery.h
@@ -42,7 +42,7 @@ int alloc_path_with_pathinfo (struct config *conf, struct udev_device *udevice,
 int store_pathinfo (vector pathvec, struct config *conf,
 		    struct udev_device *udevice, int flag,
 		    struct path **pp_ptr);
-int sysfs_set_scsi_tmo (struct multipath *mpp, int checkint);
+int sysfs_set_scsi_tmo (struct multipath *mpp, unsigned int checkint);
 int sysfs_get_timeout(const struct path *pp, unsigned int *timeout);
 int sysfs_get_host_pci_name(const struct path *pp, char *pci_name);
 int sysfs_get_iscsi_ip_address(const struct path *pp, char *ip_address);
diff --git a/libmultipath/io_err_stat.c b/libmultipath/io_err_stat.c
index 6b3a3e19..d7e296fa 100644
--- a/libmultipath/io_err_stat.c
+++ b/libmultipath/io_err_stat.c
@@ -357,7 +357,7 @@ int io_err_stat_handle_pathfail(struct path *path)
 		if (path->state != PATH_DOWN) {
 			struct config *conf;
 			int oldstate = path->state;
-			int checkint;
+			unsigned int checkint;
 
 			conf = get_multipath_config();
 			checkint = conf->checkint;
diff --git a/libmultipath/structs_vec.c b/libmultipath/structs_vec.c
index c43b58fb..6991f9ac 100644
--- a/libmultipath/structs_vec.c
+++ b/libmultipath/structs_vec.c
@@ -292,7 +292,7 @@ update_multipath_strings(struct multipath *mpp, vector pathvec, int is_daemon)
 
 void enter_recovery_mode(struct multipath *mpp)
 {
-	int checkint;
+	unsigned int checkint;
 	struct config *conf = get_multipath_config();
 	checkint = conf->checkint;
 	put_multipath_config(conf);
diff --git a/multipathd/main.c b/multipathd/main.c
index 26d5aa9c..bb5c1f1d 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -493,7 +493,7 @@ int update_multipath (struct vectors *vecs, char *mapname, int reset)
 			if (pp->state != PATH_DOWN) {
 				struct config *conf;
 				int oldstate = pp->state;
-				int checkint;
+				unsigned int checkint;
 
 				conf = get_multipath_config();
 				checkint = conf->checkint;
@@ -1985,7 +1985,7 @@ should_skip_path(struct path *pp){
  * and '0' otherwise
  */
 int
-check_path (struct vectors * vecs, struct path * pp, int ticks)
+check_path (struct vectors * vecs, struct path * pp, unsigned int ticks)
 {
 	int newstate;
 	int new_path_up = 0;
@@ -1993,7 +1993,8 @@ check_path (struct vectors * vecs, struct path * pp, int ticks)
 	int add_active;
 	int disable_reinstate = 0;
 	int oldchkrstate = pp->chkrstate;
-	int retrigger_tries, checkint, max_checkint, verbosity;
+	int retrigger_tries, verbosity;
+	unsigned int checkint, max_checkint;
 	struct config *conf;
 	int marginal_pathgroups, marginal_changed = 0;
 	int ret;
@@ -2333,7 +2334,8 @@ checkerloop (void *ap)
 
 	while (1) {
 		struct timespec diff_time, start_time, end_time;
-		int num_paths = 0, ticks = 0, strict_timing, rc = 0;
+		int num_paths = 0, strict_timing, rc = 0;
+		unsigned int ticks = 0;
 
 		get_monotonic_time(&start_time);
 		if (start_time.tv_sec && last_time.tv_sec) {
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 52/72] libmultipath: use unsigned blksize in directio context
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (50 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 51/72] libmultipath: make "checkint" unsigned Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 53/72] libmultipath, kpartx: byteorder: always use unsigned types Martin Wilck
                   ` (19 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/checkers/directio.c | 2 +-
 libmultipath/io_err_stat.c       | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libmultipath/checkers/directio.c b/libmultipath/checkers/directio.c
index 1b00b775..239a811c 100644
--- a/libmultipath/checkers/directio.c
+++ b/libmultipath/checkers/directio.c
@@ -37,7 +37,7 @@ const char *libcheck_msgtable[] = {
 struct directio_context {
 	int		running;
 	int		reset_flags;
-	int		blksize;
+	unsigned int	blksize;
 	unsigned char *	buf;
 	unsigned char * ptr;
 	io_context_t	ioctx;
diff --git a/libmultipath/io_err_stat.c b/libmultipath/io_err_stat.c
index d7e296fa..dcc8690d 100644
--- a/libmultipath/io_err_stat.c
+++ b/libmultipath/io_err_stat.c
@@ -54,7 +54,7 @@ struct io_err_stat_pathvec {
 
 struct dio_ctx {
 	struct timespec	io_starttime;
-	int		blksize;
+	unsigned int	blksize;
 	void		*buf;
 	struct iocb	io;
 };
@@ -128,7 +128,7 @@ static int setup_directio_ctx(struct io_err_stat_path *p)
 {
 	unsigned long pgsize = getpagesize();
 	char fpath[PATH_MAX];
-	int blksize = 0;
+	unsigned int blksize = 0;
 	int i;
 
 	if (snprintf(fpath, PATH_MAX, "/dev/%s", p->devname) >= PATH_MAX)
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 53/72] libmultipath, kpartx: byteorder: always use unsigned types
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (51 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 52/72] libmultipath: use unsigned blksize in directio context Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 54/72] libmpathcmd: fix -Wsign-compare warnings Martin Wilck
                   ` (18 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

The swapped results are unsigned, so the non-swapped ones should
be unsigned, too.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 kpartx/gpt.c             |  6 +++---
 libmultipath/byteorder.h | 12 ++++++------
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/kpartx/gpt.c b/kpartx/gpt.c
index 4f88d486..aa2a440c 100644
--- a/kpartx/gpt.c
+++ b/kpartx/gpt.c
@@ -40,9 +40,9 @@
 #include "kpartx.h"
 
 #if BYTE_ORDER == LITTLE_ENDIAN
-#  define __le16_to_cpu(x) (x)
-#  define __le32_to_cpu(x) (x)
-#  define __le64_to_cpu(x) (x)
+#  define __le16_to_cpu(x) (uint16_t)(x)
+#  define __le32_to_cpu(x) (uint32_t)(x)
+#  define __le64_to_cpu(x) (uint64_t)(x)
 #  define __cpu_to_le32(x) (x)
 #elif BYTE_ORDER == BIG_ENDIAN
 #  define __le16_to_cpu(x) bswap_16(x)
diff --git a/libmultipath/byteorder.h b/libmultipath/byteorder.h
index 5c771467..0a862447 100644
--- a/libmultipath/byteorder.h
+++ b/libmultipath/byteorder.h
@@ -9,19 +9,19 @@
 #endif
 
 #if BYTE_ORDER == LITTLE_ENDIAN
-#  define le16_to_cpu(x) (x)
+#  define le16_to_cpu(x) (uint16_t)(x)
 #  define be16_to_cpu(x) bswap_16(x)
-#  define le32_to_cpu(x) (x)
-#  define le64_to_cpu(x) (x)
+#  define le32_to_cpu(x) (uint32_t)(x)
+#  define le64_to_cpu(x) (uint64_t)(x)
 #  define be32_to_cpu(x) bswap_32(x)
 #  define be64_to_cpu(x) bswap_64(x)
 #elif BYTE_ORDER == BIG_ENDIAN
 #  define le16_to_cpu(x) bswap_16(x)
-#  define be16_to_cpu(x) (x)
+#  define be16_to_cpu(x) (uint16_t)(x)
 #  define le32_to_cpu(x) bswap_32(x)
 #  define le64_to_cpu(x) bswap_64(x)
-#  define be32_to_cpu(x) (x)
-#  define be64_to_cpu(x) (x)
+#  define be32_to_cpu(x) (uint32_t)(x)
+#  define be64_to_cpu(x) (uint64_t)(x)
 #else
 #  error unsupported
 #endif
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 54/72] libmpathcmd: fix -Wsign-compare warnings
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (52 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 53/72] libmultipath, kpartx: byteorder: always use unsigned types Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 55/72] libmpathpersist: " Martin Wilck
                   ` (17 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmpathcmd/mpath_cmd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libmpathcmd/mpath_cmd.c b/libmpathcmd/mpath_cmd.c
index f00bf7e1..60b2d965 100644
--- a/libmpathcmd/mpath_cmd.c
+++ b/libmpathcmd/mpath_cmd.c
@@ -96,7 +96,8 @@ static size_t write_all(int fd, const void *buf, size_t len)
  */
 int __mpath_connect(int nonblocking)
 {
-	int fd, len;
+	int fd;
+	size_t len;
 	struct sockaddr_un addr;
 	int flags = 0;
 
@@ -172,7 +173,7 @@ int mpath_recv_reply_data(int fd, char *reply, size_t len,
 	ret = read_all(fd, reply, len, timeout);
 	if (ret < 0)
 		return ret;
-	if (ret != len) {
+	if ((size_t)ret != len) {
 		errno = EIO;
 		return -1;
 	}
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 55/72] libmpathpersist: fix -Wsign-compare warnings
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (53 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 54/72] libmpathcmd: fix -Wsign-compare warnings Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 56/72] kpartx: use unsigned arguments in dm_devn() and dm_prereq() Martin Wilck
                   ` (16 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmpathpersist/mpath_persist.c  |  3 ++-
 libmpathpersist/mpath_pr_ioctl.c | 10 +++++-----
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/libmpathpersist/mpath_persist.c b/libmpathpersist/mpath_persist.c
index 603cfc3b..0c57dd92 100644
--- a/libmpathpersist/mpath_persist.c
+++ b/libmpathpersist/mpath_persist.c
@@ -854,7 +854,8 @@ int update_map_pr(struct multipath *mpp)
 {
 	int noisy=0;
 	struct prin_resp *resp;
-	int i, ret, isFound;
+	unsigned int i;
+	int ret, isFound;
 
 	if (!get_be64(mpp->reservation_key))
 	{
diff --git a/libmpathpersist/mpath_pr_ioctl.c b/libmpathpersist/mpath_pr_ioctl.c
index 05b30b56..74b26b0c 100644
--- a/libmpathpersist/mpath_pr_ioctl.c
+++ b/libmpathpersist/mpath_pr_ioctl.c
@@ -140,7 +140,7 @@ retry :
 
 uint32_t  format_transportids(struct prout_param_descriptor *paramp)
 {
-	int i = 0, len;
+	unsigned int i = 0, len;
 	uint32_t buff_offset = 4;
 	memset(paramp->private_buffer, 0, MPATH_MAX_PARAM_LEN);
 	for (i=0; i < paramp->num_transportid; i++ )
@@ -204,11 +204,11 @@ static void mpath_format_reportcapabilities(struct prin_resp *pr_buff)
 
 static void mpath_format_readfullstatus(struct prin_resp *pr_buff)
 {
-	int num, k, tid_len_len=0;
+	int num;
 	uint32_t fdesc_count=0;
 	unsigned char *p;
 	char  *ppbuff;
-	uint32_t additional_length;
+	uint32_t additional_length, k, tid_len_len = 0;
 	char tempbuff[MPATH_MAX_PARAM_LEN];
 	struct prin_fulldescr fdesc;
 
@@ -269,8 +269,8 @@ static void mpath_format_readfullstatus(struct prin_resp *pr_buff)
 void
 decode_transport_id(struct prin_fulldescr *fdesc, unsigned char * p, int length)
 {
-	int num, k;
-	int jump;
+	unsigned int num;
+	int jump, k;
 	for (k = 0, jump = 24; k < length; k += jump, p += jump) {
 		fdesc->trnptid.format_code = ((p[0] >> 6) & 0x3);
 		fdesc->trnptid.protocol_id = (p[0] & 0xf);
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 56/72] kpartx: use unsigned arguments in dm_devn() and dm_prereq()
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (54 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 55/72] libmpathpersist: " Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 57/72] kpartx: use unsigned int for "ns" argument of ptreader Martin Wilck
                   ` (15 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

In both cases, the corresponding libdevmapper values are unsigned.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 kpartx/devmapper.c | 10 +++++-----
 kpartx/devmapper.h |  7 ++++---
 kpartx/kpartx.h    |  7 ++++---
 3 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/kpartx/devmapper.c b/kpartx/devmapper.c
index 7e599e07..9a3dd5f8 100644
--- a/kpartx/devmapper.c
+++ b/kpartx/devmapper.c
@@ -17,7 +17,7 @@
 #define MAX_PREFIX_LEN (_UUID_PREFIX_LEN + 4)
 #define PARAMS_SIZE 1024
 
-int dm_prereq(char * str, int x, int y, int z)
+int dm_prereq(char * str, uint32_t x, uint32_t y, uint32_t z)
 {
 	int r = 1;
 	struct dm_task *dmt;
@@ -359,7 +359,7 @@ out:
 }
 
 int
-dm_devn (const char * mapname, int *major, int *minor)
+dm_devn (const char * mapname, unsigned int *major, unsigned int *minor)
 {
 	int r = 1;
 	struct dm_task *dmt;
@@ -528,7 +528,7 @@ do_foreach_partmaps (const char * mapname, const char *uuid,
 	struct remove_data *rd = data;
 	unsigned next = 0;
 	char params[PARAMS_SIZE];
-	int major, minor;
+	unsigned int major, minor;
 	char dev_t[32];
 	int r = 1;
 	int is_dmdev = 1;
@@ -645,7 +645,7 @@ int dm_find_part(const char *parent, const char *delim, int part,
 	char params[PARAMS_SIZE];
 	char *tmp;
 	char *uuid;
-	int major, minor;
+	unsigned int major, minor;
 	char dev_t[32];
 
 	if (!format_partname(name, namesiz, parent, delim, part)) {
@@ -715,7 +715,7 @@ char *nondm_create_uuid(dev_t devt)
 	return uuid_buf;
 }
 
-int nondm_parse_uuid(const char *uuid, int *major, int *minor)
+int nondm_parse_uuid(const char *uuid, unsigned int *major, unsigned int *minor)
 {
 	const char *p;
 	char *e;
diff --git a/kpartx/devmapper.h b/kpartx/devmapper.h
index 73b80f2f..701bdf6e 100644
--- a/kpartx/devmapper.h
+++ b/kpartx/devmapper.h
@@ -9,14 +9,14 @@
 
 extern int udev_sync;
 
-int dm_prereq (char *, int, int, int);
+int dm_prereq (char *, uint32_t, uint32_t, uint32_t);
 int dm_simplecmd (int, const char *, int, uint16_t);
 int dm_addmap (int, const char *, const char *, const char *, uint64_t,
 	       int, const char *, int, mode_t, uid_t, gid_t);
 char * dm_mapname(int major, int minor);
 dev_t dm_get_first_dep(char *devname);
 char * dm_mapuuid(const char *mapname);
-int dm_devn (const char * mapname, int *major, int *minor);
+int dm_devn (const char * mapname, unsigned int *major, unsigned int *minor);
 int dm_remove_partmaps (char * mapname, char *uuid, dev_t devt, int verbose);
 int dm_find_part(const char *parent, const char *delim, int part,
 		 const char *parent_uuid,
@@ -34,5 +34,6 @@ int dm_find_part(const char *parent, const char *delim, int part,
 #define NONDM_UUID_PREFIX "devnode"
 #define NONDM_UUID_SUFFIX "Wh5pYvM"
 char *nondm_create_uuid(dev_t devt);
-int nondm_parse_uuid(const char *uuid, int *major, int *minor);
+int nondm_parse_uuid(const char *uuid,
+		     unsigned int *major, unsigned int *minor);
 #endif /* _KPARTX_DEVMAPPER_H */
diff --git a/kpartx/kpartx.h b/kpartx/kpartx.h
index 3ec13dbc..015dcab4 100644
--- a/kpartx/kpartx.h
+++ b/kpartx/kpartx.h
@@ -33,11 +33,12 @@ struct slice {
 	uint64_t start;
 	uint64_t size;
 	int container;
-	int major;
-	int minor;
+	unsigned int major;
+	unsigned int minor;
 };
 
-typedef int (ptreader)(int fd, struct slice all, struct slice *sp, int ns);
+typedef int (ptreader)(int fd, struct slice all, struct slice *sp,
+		       int ns);
 
 extern int force_gpt;
 
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 57/72] kpartx: use unsigned int for "ns" argument of ptreader
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (55 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 56/72] kpartx: use unsigned arguments in dm_devn() and dm_prereq() Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 58/72] multipath-tools: Makefile.inc: enable -Wsign-compare Martin Wilck
                   ` (14 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

ns, the number of slices, should be positive.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 kpartx/bsd.c      | 4 ++--
 kpartx/dasd.c     | 2 +-
 kpartx/dos.c      | 4 ++--
 kpartx/gpt.c      | 4 ++--
 kpartx/gpt.h      | 2 +-
 kpartx/kpartx.h   | 4 ++--
 kpartx/mac.c      | 4 ++--
 kpartx/ps3.c      | 4 ++--
 kpartx/solaris.c  | 4 ++--
 kpartx/sun.c      | 4 ++--
 kpartx/unixware.c | 4 ++--
 11 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/kpartx/bsd.c b/kpartx/bsd.c
index f87175e2..0e661fbc 100644
--- a/kpartx/bsd.c
+++ b/kpartx/bsd.c
@@ -47,13 +47,13 @@ struct bsd_disklabel {
 };
 
 int
-read_bsd_pt(int fd, struct slice all, struct slice *sp, int ns) {
+read_bsd_pt(int fd, struct slice all, struct slice *sp, unsigned int ns) {
 	struct bsd_disklabel *l;
 	struct bsd_partition *p;
 	unsigned int offset = all.start, end;
 	int max_partitions;
 	char *bp;
-	int n = 0, i, j;
+	unsigned int n = 0, i, j;
 
 	bp = getblock(fd, offset+1);    /* 1 sector suffices */
 	if (bp == NULL)
diff --git a/kpartx/dasd.c b/kpartx/dasd.c
index 4f3f744e..1486ccaa 100644
--- a/kpartx/dasd.c
+++ b/kpartx/dasd.c
@@ -66,7 +66,7 @@ typedef unsigned int __attribute__((__may_alias__)) label_ints_t;
  */
 int
 read_dasd_pt(int fd, __attribute__((unused)) struct slice all,
-	     struct slice *sp, __attribute__((unused)) int ns)
+	     struct slice *sp, __attribute__((unused)) unsigned int ns)
 {
 	int retval = -1;
 	int blocksize;
diff --git a/kpartx/dos.c b/kpartx/dos.c
index 4985152c..0c706690 100644
--- a/kpartx/dos.c
+++ b/kpartx/dos.c
@@ -74,10 +74,10 @@ is_gpt(int type) {
 }
 
 int
-read_dos_pt(int fd, struct slice all, struct slice *sp, int ns) {
+read_dos_pt(int fd, struct slice all, struct slice *sp, unsigned int ns) {
 	struct partition p;
 	unsigned long offset = all.start;
-	int i, n=4;
+	unsigned int i, n=4;
 	unsigned char *bp;
 	uint64_t  sector_size_mul = get_sector_size(fd)/512;
 
diff --git a/kpartx/gpt.c b/kpartx/gpt.c
index aa2a440c..785b34ea 100644
--- a/kpartx/gpt.c
+++ b/kpartx/gpt.c
@@ -602,11 +602,11 @@ fail:
  */
 int
 read_gpt_pt (int fd, __attribute__((unused)) struct slice all,
-	     struct slice *sp, int ns)
+	     struct slice *sp, unsigned int ns)
 {
 	gpt_header *gpt = NULL;
 	gpt_entry *ptes = NULL;
-	uint32_t i;
+	unsigned int i;
 	int n = 0;
 	int last_used_index=-1;
 	int sector_size_mul = get_sector_size(fd)/512;
diff --git a/kpartx/gpt.h b/kpartx/gpt.h
index 7bb54b74..4e1b49aa 100644
--- a/kpartx/gpt.h
+++ b/kpartx/gpt.h
@@ -105,7 +105,7 @@ typedef struct _legacy_mbr {
 #define EFI_GPT_PRIMARY_PARTITION_TABLE_LBA 1
 
 /* Functions */
-int read_gpt_pt (int fd, struct slice all, struct slice *sp, int ns);
+int read_gpt_pt (int fd, struct slice all, struct slice *sp, unsigned int ns);
 
 
 #endif
diff --git a/kpartx/kpartx.h b/kpartx/kpartx.h
index 015dcab4..dfc66c5d 100644
--- a/kpartx/kpartx.h
+++ b/kpartx/kpartx.h
@@ -38,7 +38,7 @@ struct slice {
 };
 
 typedef int (ptreader)(int fd, struct slice all, struct slice *sp,
-		       int ns);
+		       unsigned int ns);
 
 extern int force_gpt;
 
@@ -54,7 +54,7 @@ extern ptreader read_ps3_pt;
 
 char *getblock(int fd, unsigned int secnr);
 
-static inline int
+static inline unsigned int
 four2int(unsigned char *p) {
 	return p[0] + (p[1]<<8) + (p[2]<<16) + (p[3]<<24);
 }
diff --git a/kpartx/mac.c b/kpartx/mac.c
index 6aeac4e9..c21ac702 100644
--- a/kpartx/mac.c
+++ b/kpartx/mac.c
@@ -6,12 +6,12 @@
 
 int
 read_mac_pt(int fd, __attribute__((unused)) struct slice all,
-	    struct slice *sp, int ns) {
+	    struct slice *sp, unsigned int ns) {
 	struct mac_driver_desc *md;
 	struct mac_partition *part;
 	unsigned secsize;
 	char *data;
-	int blk, blocks_in_map;
+	unsigned int blk, blocks_in_map;
 	int n = 0;
 
 	md = (struct mac_driver_desc *) getblock(fd, 0);
diff --git a/kpartx/ps3.c b/kpartx/ps3.c
index 2cf4ffa2..42551bcc 100644
--- a/kpartx/ps3.c
+++ b/kpartx/ps3.c
@@ -34,7 +34,7 @@ struct disklabel {
 static int
 read_disklabel(int fd, struct disklabel *label) {
 	unsigned char *data;
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < sizeof(struct disklabel) / SECTOR_SIZE; i++) {
 		data = (unsigned char *) getblock(fd, i);
@@ -49,7 +49,7 @@ read_disklabel(int fd, struct disklabel *label) {
 
 int
 read_ps3_pt(int fd, __attribute__((unused)) struct slice all,
-	    struct slice *sp, __attribute__((unused)) int ns) {
+	    struct slice *sp, __attribute__((unused)) unsigned int ns) {
 	struct disklabel label;
 	int n = 0;
 	int i;
diff --git a/kpartx/solaris.c b/kpartx/solaris.c
index e7826c62..c2480b50 100644
--- a/kpartx/solaris.c
+++ b/kpartx/solaris.c
@@ -28,11 +28,11 @@ struct solaris_x86_vtoc {
 };
 
 int
-read_solaris_pt(int fd, struct slice all, struct slice *sp, int ns) {
+read_solaris_pt(int fd, struct slice all, struct slice *sp, unsigned int ns) {
 	struct solaris_x86_vtoc *v;
 	struct solaris_x86_slice *s;
 	unsigned int offset = all.start;
-	int i, n;
+	unsigned int i, n;
 	char *bp;
 
 	bp = getblock(fd, offset+1);	/* 1 sector suffices */
diff --git a/kpartx/sun.c b/kpartx/sun.c
index 276066d1..df630a7c 100644
--- a/kpartx/sun.c
+++ b/kpartx/sun.c
@@ -59,11 +59,11 @@ sun_verify_checksum (struct sun_disk_label *label)
 }
 
 int
-read_sun_pt(int fd, struct slice all, struct slice *sp, int ns) {
+read_sun_pt(int fd, struct slice all, struct slice *sp, unsigned int ns) {
 	struct sun_disk_label *l;
 	struct sun_raw_part *s;
 	unsigned int offset = all.start, end;
-	int i, j, n;
+	unsigned int i, j, n;
 	char *bp;
 
 	bp = getblock(fd, offset);
diff --git a/kpartx/unixware.c b/kpartx/unixware.c
index c7b9786e..2f663af0 100644
--- a/kpartx/unixware.c
+++ b/kpartx/unixware.c
@@ -48,12 +48,12 @@ struct unixware_disklabel {
 };  /* 408 */
 
 int
-read_unixware_pt(int fd, struct slice all, struct slice *sp, int ns) {
+read_unixware_pt(int fd, struct slice all, struct slice *sp, unsigned int ns) {
 	struct unixware_disklabel *l;
 	struct unixware_slice *p;
 	unsigned int offset = all.start;
 	char *bp;
-	int n = 0;
+	unsigned int n = 0;
 
 	bp = getblock(fd, offset+29);	/* 1 sector suffices */
 	if (bp == NULL)
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 58/72] multipath-tools: Makefile.inc: enable -Wsign-compare
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (56 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 57/72] kpartx: use unsigned int for "ns" argument of ptreader Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 59/72] libdmmp: fix clang -Wformat-nonliteral warnings Martin Wilck
                   ` (13 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

With the previous patches, there are no signedness warnings any more.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 Makefile.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile.inc b/Makefile.inc
index da9a3d7d..0c800ab3 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -93,7 +93,7 @@ ERROR_DISCARDED_QUALIFIERS := $(call TEST_CC_OPTION,-Werror=discarded-qualifiers
 
 OPTFLAGS	= -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int \
 		  -Werror=implicit-function-declaration -Werror=format-security \
-		  -Wno-sign-compare -Wno-clobbered \
+		  -Wno-clobbered \
 		  -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS) \
 		  -Wp,-D_FORTIFY_SOURCE=2 $(STACKPROT) \
 		  --param=ssp-buffer-size=4
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 59/72] libdmmp: fix clang -Wformat-nonliteral warnings
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (57 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 58/72] multipath-tools: Makefile.inc: enable -Wsign-compare Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 60/72] libmultipath: fix clang -Wformat-literal warnings Martin Wilck
                   ` (12 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

clang enables -Wformat-nonliteral with our compiler flags, and
thus needs these format(printf, ...) attributes.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libdmmp/libdmmp_private.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libdmmp/libdmmp_private.h b/libdmmp/libdmmp_private.h
index 3e813cb4..ac85b63f 100644
--- a/libdmmp/libdmmp_private.h
+++ b/libdmmp/libdmmp_private.h
@@ -131,13 +131,15 @@ 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, ...);
+			      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,
 				     const char *file, int line,
 				     const char *func_name, const char *format,
-				     va_list args);
+				     va_list args)
+	__attribute__((format(printf, 6, 0)));
 
 
 #define _dmmp_log_cond(ctx, prio, arg...) \
@@ -164,7 +166,7 @@ DMMP_DLL_LOCAL void _dmmp_log_stderr(struct dmmp_context *ctx, int priority,
 	do { \
 		if (ptr == NULL) { \
 			rc = DMMP_ERR_NO_MEMORY; \
-			_error(ctx, dmmp_strerror(rc)); \
+			_error(ctx, "%s", dmmp_strerror(rc));	\
 			goto goto_out; \
 		} \
 	} while(0)
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 60/72] libmultipath: fix clang -Wformat-literal warnings
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (58 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 59/72] libdmmp: fix clang -Wformat-nonliteral warnings Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 61/72] multipath tests: blacklist: remove always-true condition Martin Wilck
                   ` (11 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/devmapper.c   | 2 +-
 libmultipath/log.h         | 3 ++-
 libmultipath/log_pthread.h | 3 ++-
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
index 4bff37d0..acf576aa 100644
--- a/libmultipath/devmapper.c
+++ b/libmultipath/devmapper.c
@@ -59,7 +59,7 @@ void dm_udev_set_sync_support(int c)
 
 #endif
 
-static void
+__attribute__((format(printf, 4, 5))) static void
 dm_write_log (int level, const char *file, int line, const char *f, ...)
 {
 	va_list ap;
diff --git a/libmultipath/log.h b/libmultipath/log.h
index 6551b5cf..d2448f6a 100644
--- a/libmultipath/log.h
+++ b/libmultipath/log.h
@@ -34,7 +34,8 @@ extern struct logarea* la;
 int log_init (char * progname, int size);
 void log_close (void);
 void log_reset (char * progname);
-int log_enqueue (int prio, const char * fmt, va_list ap);
+int log_enqueue (int prio, const char * fmt, va_list ap)
+	__attribute__((format(printf, 2, 0)));
 int log_dequeue (void *);
 void log_syslog (void *);
 void dump_logmsg (void *);
diff --git a/libmultipath/log_pthread.h b/libmultipath/log_pthread.h
index 7e138a00..810ac920 100644
--- a/libmultipath/log_pthread.h
+++ b/libmultipath/log_pthread.h
@@ -3,7 +3,8 @@
 
 #include <pthread.h>
 
-void log_safe(int prio, const char * fmt, va_list ap);
+void log_safe(int prio, const char * fmt, va_list ap)
+	__attribute__((format(printf, 2, 0)));
 void log_thread_start(pthread_attr_t *attr);
 void log_thread_reset (void);
 void log_thread_stop(void);
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 61/72] multipath tests: blacklist: remove always-true condition
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (59 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 60/72] libmultipath: fix clang -Wformat-literal warnings Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 62/72] multipath tests: hwtable: fix strncat() invocation Martin Wilck
                   ` (10 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

clang warns about this (udev_device->property_list can't be NULL).

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 tests/blacklist.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/tests/blacklist.c b/tests/blacklist.c
index 733ee398..6e7c1864 100644
--- a/tests/blacklist.c
+++ b/tests/blacklist.c
@@ -40,8 +40,6 @@ struct udev_list_entry *
 __wrap_udev_device_get_properties_list_entry(struct udev_device *udev_device)
 {
 	assert_non_null(udev_device);
-	if (!udev_device->property_list)
-		return NULL;
 	if (!*udev_device->property_list)
 		return NULL;
 	return (struct udev_list_entry *)udev_device->property_list;
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 62/72] multipath tests: hwtable: fix strncat() invocation
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (60 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 61/72] multipath tests: blacklist: remove always-true condition Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 63/72] multipath tests: fix -Wformat-literal warning Martin Wilck
                   ` (9 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

clang detected this error.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 tests/hwtable.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/hwtable.c b/tests/hwtable.c
index 977a5663..473028b7 100644
--- a/tests/hwtable.c
+++ b/tests/hwtable.c
@@ -261,7 +261,7 @@ static void write_defaults(const struct hwt_state *hwt)
 	defaults[0].value = hwt->dirname;
 	defaults[1].value = buf;
 	assert_ptr_not_equal(getcwd(dirbuf, sizeof(dirbuf)), NULL);
-	strncat(dirbuf, "/lib", sizeof(dirbuf));
+	strncat(dirbuf, "/lib", sizeof(dirbuf) - 5);
 	defaults[2].value = dirbuf;
 	write_section(hwt->config_file, "defaults",
 		      ARRAY_SIZE(defaults), defaults);
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 63/72] multipath tests: fix -Wformat-literal warning
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (61 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 62/72] multipath tests: hwtable: fix strncat() invocation Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 64/72] multipath tests: util: fix clang strlcpy warnings Martin Wilck
                   ` (8 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 tests/test-log.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/test-log.c b/tests/test-log.c
index 76a266eb..d685d582 100644
--- a/tests/test-log.c
+++ b/tests/test-log.c
@@ -6,6 +6,7 @@
 #include "log.h"
 #include "test-log.h"
 
+__attribute__((format(printf, 3, 0)))
 void __wrap_dlog (int sink, int prio, const char * fmt, ...)
 {
 	char buff[MAX_MSG_SIZE];
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 64/72] multipath tests: util: fix clang strlcpy warnings
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (62 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 63/72] multipath tests: fix -Wformat-literal warning Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 65/72] libmultipath: nvme: update to nvme-cli v1.9 Martin Wilck
                   ` (7 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

clang erroneously thought that we were using the size of the source
for the destination, while they are equal. Trick it into accepting
the code.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 tests/util.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/tests/util.c b/tests/util.c
index 4e04a480..7c486fca 100644
--- a/tests/util.c
+++ b/tests/util.c
@@ -328,11 +328,12 @@ static void test_strlcpy_5(void **state)
 {
 	char *tst;
 	int rc;
+	const int sz = sizeof(src_str);
 
-	tst = malloc(sizeof(src_str));
+	tst = malloc(sz);
 	memset(tst, 'f', sizeof(src_str));
 
-	rc = strlcpy(tst, src_str, sizeof(src_str));
+	rc = strlcpy(tst, src_str, sz);
 	assert_int_equal(rc, strlen(src_str));
 	assert_string_equal(src_str, tst);
 
@@ -344,15 +345,16 @@ static void test_strlcpy_6(void **state)
 {
 	char *tst;
 	int rc;
+	const int sz = sizeof(src_str);
 
-	tst = malloc(sizeof(src_str) + 2);
-	memset(tst, 'f', sizeof(src_str) + 2);
+	tst = malloc(sz + 2);
+	memset(tst, 'f', sz + 2);
 
-	rc = strlcpy(tst, src_str, sizeof(src_str) + 2);
+	rc = strlcpy(tst, src_str, sz + 2);
 	assert_int_equal(rc, strlen(src_str));
 	assert_string_equal(src_str, tst);
-	assert_int_equal(tst[sizeof(src_str)], 'f');
-	assert_int_equal(tst[sizeof(src_str) + 1], 'f');
+	assert_int_equal(tst[sz], 'f');
+	assert_int_equal(tst[sz + 1], 'f');
 
 	free(tst);
 }
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 65/72] libmultipath: nvme: update to nvme-cli v1.9
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (63 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 64/72] multipath tests: util: fix clang strlcpy warnings Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:28 ` [PATCH 66/72] multipath-tools: Makefile.inc: fix TEST_CC_OPTION Martin Wilck
                   ` (6 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Update nvme code to nvme-cli v1.9 (977e7d4, Thu Aug 15 2019).

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/nvme/linux/nvme.h | 136 +++++++++++++++-----
 libmultipath/nvme/nvme-ioctl.c | 229 +++++++++++++++++++++------------
 libmultipath/nvme/nvme-ioctl.h |  31 ++++-
 libmultipath/nvme/nvme.h       | 121 +++++++++++++----
 4 files changed, 375 insertions(+), 142 deletions(-)

diff --git a/libmultipath/nvme/linux/nvme.h b/libmultipath/nvme/linux/nvme.h
index 68000eb8..a6975549 100644
--- a/libmultipath/nvme/linux/nvme.h
+++ b/libmultipath/nvme/linux/nvme.h
@@ -124,6 +124,9 @@ enum {
 	NVME_REG_BPINFO	= 0x0040,	/* Boot Partition Information */
 	NVME_REG_BPRSEL	= 0x0044,	/* Boot Partition Read Select */
 	NVME_REG_BPMBL	= 0x0048,	/* Boot Partition Memory Buffer Location */
+	NVME_REG_PMRCAP = 0x0e00,	/* Persistent Memory Capabilities */
+	NVME_REG_PMRCTL = 0x0e04,	/* Persistent Memory Region Control */
+	NVME_REG_PMRSTS = 0x0e08,	/* Persistent Memory Region Status */
 	NVME_REG_DBS	= 0x1000,	/* SQ 0 Tail Doorbell */
 };
 
@@ -221,7 +224,11 @@ struct nvme_id_ctrl {
 	__le32			oaes;
 	__le32			ctratt;
 	__le16			rrls;
-	__u8			rsvd102[154];
+	__u8			rsvd102[26];
+	__le16			crdt1;
+	__le16			crdt2;
+	__le16			crdt3;
+	__u8			rsvd134[122];
 	__le16			oacs;
 	__u8			acl;
 	__u8			aerl;
@@ -302,6 +309,8 @@ enum {
 	NVME_CTRL_CTRATT_READ_RECV_LVLS		= 1 << 3,
 	NVME_CTRL_CTRATT_ENDURANCE_GROUPS	= 1 << 4,
 	NVME_CTRL_CTRATT_PREDICTABLE_LAT	= 1 << 5,
+	NVME_CTRL_CTRATT_NAMESPACE_GRANULARITY	= 1 << 7,
+	NVME_CTRL_CTRATT_UUID_LIST		= 1 << 9,
 };
 
 struct nvme_lbaf {
@@ -332,7 +341,12 @@ struct nvme_id_ns {
 	__le16			nabspf;
 	__le16			noiob;
 	__u8			nvmcap[16];
-	__u8			rsvd64[28];
+	__le16			npwg;
+	__le16			npwa;
+	__le16			npdg;
+	__le16			npda;
+	__le16			nows;
+	__u8			rsvd74[18];
 	__le32			anagrpid;
 	__u8			rsvd96[3];
 	__u8			nsattr;
@@ -355,6 +369,9 @@ enum {
 	NVME_ID_CNS_NS_PRESENT		= 0x11,
 	NVME_ID_CNS_CTRL_NS_LIST	= 0x12,
 	NVME_ID_CNS_CTRL_LIST		= 0x13,
+	NVME_ID_CNS_SCNDRY_CTRL_LIST	= 0x15,
+	NVME_ID_CNS_NS_GRANULARITY	= 0x16,
+	NVME_ID_CNS_UUID_LIST		= 0x17,
 };
 
 enum {
@@ -425,26 +442,56 @@ struct nvme_id_nvmset {
 	struct nvme_nvmset_attr_entry	ent[NVME_MAX_NVMSET];
 };
 
-/* Derived from 1.3a Figure 101: Get Log Page – Telemetry Host
- * -Initiated Log (Log Identifier 07h)
+struct nvme_id_ns_granularity_list_entry {
+	__le64			namespace_size_granularity;
+	__le64			namespace_capacity_granularity;
+};
+
+struct nvme_id_ns_granularity_list {
+	__le32			attributes;
+	__u8			num_descriptors;
+	__u8			rsvd[27];
+	struct nvme_id_ns_granularity_list_entry entry[16];
+};
+
+#define NVME_MAX_UUID_ENTRIES	128
+struct nvme_id_uuid_list_entry {
+	__u8			header;
+	__u8			rsvd1[15];
+	__u8			uuid[16];
+};
+
+struct nvme_id_uuid_list {
+	struct nvme_id_uuid_list_entry	entry[NVME_MAX_UUID_ENTRIES];
+};
+
+/**
+ * struct nvme_telemetry_log_page_hdr - structure for telemetry log page
+ * @lpi: Log page identifier
+ * @iee_oui: IEEE OUI Identifier
+ * @dalb1: Data area 1 last block
+ * @dalb2: Data area 2 last block
+ * @dalb3: Data area 3 last block
+ * @ctrlavail: Controller initiated data available
+ * @ctrldgn: Controller initiated telemetry Data Generation Number
+ * @rsnident: Reason Identifier
+ * @telemetry_dataarea: Contains telemetry data block
+ *
+ * This structure can be used for both telemetry host-initiated log page
+ * and controller-initiated log page.
  */
 struct nvme_telemetry_log_page_hdr {
-	__u8    lpi; /* Log page identifier */
-	__u8    rsvd[4];
-	__u8    iee_oui[3];
-	__u16   dalb1; /* Data area 1 last block */
-	__u16   dalb2; /* Data area 2 last block */
-	__u16   dalb3; /* Data area 3 last block */
-	__u8    rsvd1[368]; /* TODO verify */
-	__u8    ctrlavail; /* Controller initiated data avail?*/
-	__u8    ctrldgn; /* Controller initiated telemetry Data Gen # */
-	__u8    rsnident[128];
-	/* We'll have to double fetch so we can get the header,
-	 * parse dalb1->3 determine how much size we need for the
-	 * log then alloc below. Or just do a secondary non-struct
-	 * allocation.
-	 */
-	__u8    telemetry_dataarea[0];
+	__u8	lpi;
+	__u8	rsvd[4];
+	__u8	iee_oui[3];
+	__le16	dalb1;
+	__le16	dalb2;
+	__le16	dalb3;
+	__u8	rsvd1[368];
+	__u8	ctrlavail;
+	__u8	ctrldgn;
+	__u8	rsnident[128];
+	__u8	telemetry_dataarea[0];
 };
 
 struct nvme_endurance_group_log {
@@ -513,6 +560,21 @@ struct nvme_fw_slot_info_log {
 	__u8			rsvd64[448];
 };
 
+struct nvme_lba_status_desc {
+	__u64 dslba;
+	__u32 nlb;
+	__u8 rsvd_12;
+	__u8 status;
+	__u8 rsvd_15_14[2];
+};
+
+struct nvme_lba_status {
+	__u32 nlsd;
+	__u8 cmpc;
+	__u8 rsvd_7_5[3];
+	struct nvme_lba_status_desc descs[0];
+};
+
 /* NVMe Namespace Write Protect State */
 enum {
 	NVME_NS_NO_WRITE_PROTECT = 0,
@@ -534,6 +596,7 @@ enum {
 	NVME_CMD_EFFECTS_NIC		= 1 << 3,
 	NVME_CMD_EFFECTS_CCC		= 1 << 4,
 	NVME_CMD_EFFECTS_CSE_MASK	= 3 << 16,
+	NVME_CMD_EFFECTS_UUID_SEL	= 1 << 19,
 };
 
 struct nvme_effects_log {
@@ -581,9 +644,6 @@ enum {
 	NVME_AER_SMART			= 1,
 	NVME_AER_CSS			= 6,
 	NVME_AER_VS			= 7,
-	NVME_AER_NOTICE_NS_CHANGED	= 0x0002,
-	NVME_AER_NOTICE_ANA		= 0x0003,
-	NVME_AER_NOTICE_FW_ACT_STARTING = 0x0102,
 };
 
 struct nvme_lba_range_type {
@@ -606,12 +666,13 @@ enum {
 	NVME_LBART_ATTRIB_HIDE	= 1 << 1,
 };
 
+/* Predictable Latency Mode - Deterministic Threshold Configuration Data */
 struct nvme_plm_config {
-	__u16	enable_event;
+	__le16	enable_event;
 	__u8	rsvd2[30];
-	__u64	dtwin_reads_thresh;
-	__u64	dtwin_writes_thresh;
-	__u64	dtwin_time_thresh;
+	__le64	dtwin_reads_thresh;
+	__le64	dtwin_writes_thresh;
+	__le64	dtwin_time_thresh;
 	__u8	rsvd56[456];
 };
 
@@ -665,6 +726,7 @@ enum nvme_opcode {
 	nvme_cmd_compare	= 0x05,
 	nvme_cmd_write_zeroes	= 0x08,
 	nvme_cmd_dsm		= 0x09,
+	nvme_cmd_verify		= 0x0c,
 	nvme_cmd_resv_register	= 0x0d,
 	nvme_cmd_resv_report	= 0x0e,
 	nvme_cmd_resv_acquire	= 0x11,
@@ -892,6 +954,7 @@ enum nvme_admin_opcode {
 	nvme_admin_security_send	= 0x81,
 	nvme_admin_security_recv	= 0x82,
 	nvme_admin_sanitize_nvm		= 0x84,
+	nvme_admin_get_lba_status	= 0x86,
 };
 
 enum {
@@ -921,6 +984,8 @@ enum {
 	NVME_FEAT_RRL		= 0x12,
 	NVME_FEAT_PLM_CONFIG	= 0x13,
 	NVME_FEAT_PLM_WINDOW	= 0x14,
+	NVME_FEAT_HOST_BEHAVIOR	= 0x16,
+	NVME_FEAT_SANITIZE	= 0x17,
 	NVME_FEAT_SW_PROGRESS	= 0x80,
 	NVME_FEAT_HOST_ID	= 0x81,
 	NVME_FEAT_RESV_MASK	= 0x82,
@@ -972,6 +1037,7 @@ enum {
 	NVME_SANITIZE_LOG_COMPLETED_SUCCESS	= 0x0001,
 	NVME_SANITIZE_LOG_IN_PROGESS		= 0x0002,
 	NVME_SANITIZE_LOG_COMPLETED_FAILED	= 0x0003,
+	NVME_SANITIZE_LOG_ND_COMPLETED_SUCCESS	= 0x0004,
 };
 
 enum {
@@ -1131,6 +1197,9 @@ struct nvme_sanitize_log_page {
 	__le32			est_ovrwrt_time;
 	__le32			est_blk_erase_time;
 	__le32			est_crypto_erase_time;
+	__le32			est_ovrwrt_time_with_no_deallocate;
+	__le32			est_blk_erase_time_with_no_deallocate;
+	__le32			est_crypto_erase_time_with_no_deallocate;
 };
 
 /*
@@ -1314,6 +1383,12 @@ static inline bool nvme_is_write(struct nvme_command *cmd)
 	return cmd->common.opcode & 1;
 }
 
+enum {
+	NVME_SCT_GENERIC		= 0x0,
+	NVME_SCT_CMD_SPECIFIC		= 0x1,
+	NVME_SCT_MEDIA			= 0x2,
+};
+
 enum {
 	/*
 	 * Generic Command Status:
@@ -1344,6 +1419,7 @@ enum {
 	NVME_SC_SANITIZE_IN_PROGRESS	= 0x1D,
 
 	NVME_SC_NS_WRITE_PROTECTED	= 0x20,
+	NVME_SC_CMD_INTERRUPTED		= 0x21,
 
 	NVME_SC_LBA_RANGE		= 0x80,
 	NVME_SC_CAP_EXCEEDED		= 0x81,
@@ -1372,9 +1448,9 @@ enum {
 	NVME_SC_FW_NEEDS_SUBSYS_RESET	= 0x110,
 	NVME_SC_FW_NEEDS_RESET		= 0x111,
 	NVME_SC_FW_NEEDS_MAX_TIME	= 0x112,
-	NVME_SC_FW_ACIVATE_PROHIBITED	= 0x113,
+	NVME_SC_FW_ACTIVATE_PROHIBITED	= 0x113,
 	NVME_SC_OVERLAPPING_RANGE	= 0x114,
-	NVME_SC_NS_INSUFFICENT_CAP	= 0x115,
+	NVME_SC_NS_INSUFFICIENT_CAP	= 0x115,
 	NVME_SC_NS_ID_UNAVAILABLE	= 0x116,
 	NVME_SC_NS_ALREADY_ATTACHED	= 0x118,
 	NVME_SC_NS_IS_PRIVATE		= 0x119,
@@ -1382,6 +1458,7 @@ enum {
 	NVME_SC_THIN_PROV_NOT_SUPP	= 0x11b,
 	NVME_SC_CTRL_LIST_INVALID	= 0x11c,
 	NVME_SC_BP_WRITE_PROHIBITED	= 0x11e,
+	NVME_SC_PMR_SAN_PROHIBITED	= 0x123,
 
 	/*
 	 * I/O Command Set Specific - NVM commands:
@@ -1422,6 +1499,7 @@ enum {
 	NVME_SC_ANA_INACCESSIBLE	= 0x302,
 	NVME_SC_ANA_TRANSITION		= 0x303,
 
+	NVME_SC_CRD			= 0x1800,
 	NVME_SC_DNR			= 0x4000,
 };
 
diff --git a/libmultipath/nvme/nvme-ioctl.c b/libmultipath/nvme/nvme-ioctl.c
index 70a16ced..69599763 100644
--- a/libmultipath/nvme/nvme-ioctl.c
+++ b/libmultipath/nvme/nvme-ioctl.c
@@ -1,3 +1,4 @@
+#include <assert.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <string.h>
@@ -177,6 +178,22 @@ int nvme_compare(int fd, __u64 slba, __u16 nblocks, __u16 control, __u32 dsmgmt,
 		       reftag, apptag, appmask, data, metadata);
 }
 
+int nvme_verify(int fd, __u32 nsid, __u64 slba, __u16 nblocks,
+		__u16 control, __u32 reftag, __u16 apptag, __u16 appmask)
+{
+	struct nvme_passthru_cmd cmd = {
+		.opcode		= nvme_cmd_verify,
+		.nsid		= nsid,
+		.cdw10		= slba & 0xffffffff,
+		.cdw11		= slba >> 32,
+		.cdw12		= nblocks | (control << 16),
+		.cdw14		= reftag,
+		.cdw15		= apptag | (appmask << 16),
+	};
+
+	return nvme_submit_io_passthru(fd, &cmd);
+}
+
 int nvme_passthru_io(int fd, __u8 opcode, __u8 flags, __u16 rsvd,
 		     __u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10,
 		     __u32 cdw11, __u32 cdw12, __u32 cdw13, __u32 cdw14,
@@ -370,6 +387,11 @@ int nvme_identify_ctrl_list(int fd, __u32 nsid, __u16 cntid, void *data)
 	return nvme_identify(fd, nsid, (cntid << 16) | cns, data);
 }
 
+int nvme_identify_secondary_ctrl_list(int fd, __u32 nsid, __u16 cntid, void *data)
+{
+	return nvme_identify(fd, nsid, (cntid << 16) | NVME_ID_CNS_SCNDRY_CTRL_LIST, data);
+}
+
 int nvme_identify_ns_descs(int fd, __u32 nsid, void *data)
 {
 
@@ -381,8 +403,18 @@ int nvme_identify_nvmset(int fd, __u16 nvmset_id, void *data)
 	return nvme_identify13(fd, 0, NVME_ID_CNS_NVMSET_LIST, nvmset_id, data);
 }
 
-int nvme_get_log13(int fd, __u32 nsid, __u8 log_id, __u8 lsp, __u64 lpo,
-                 __u16 lsi, bool rae, __u32 data_len, void *data)
+int nvme_identify_ns_granularity(int fd, void *data)
+{
+	return nvme_identify13(fd, 0, NVME_ID_CNS_NS_GRANULARITY, 0, data);
+}
+
+int nvme_identify_uuid(int fd, void *data)
+{
+	return nvme_identify(fd, 0, NVME_ID_CNS_UUID_LIST, data);
+}
+
+int nvme_get_log14(int fd, __u32 nsid, __u8 log_id, __u8 lsp, __u64 lpo,
+                 __u16 lsi, bool rae, __u8 uuid_ix, __u32 data_len, void *data)
 {
 	struct nvme_admin_cmd cmd = {
 		.opcode		= nvme_admin_get_log_page,
@@ -400,6 +432,7 @@ int nvme_get_log13(int fd, __u32 nsid, __u8 log_id, __u8 lsp, __u64 lpo,
 	cmd.cdw11 = numdu | (lsi << 16);
 	cmd.cdw12 = lpo;
 	cmd.cdw13 = (lpo >> 32);
+	cmd.cdw14 = uuid_ix;
 
 	return nvme_submit_admin_passthru(fd, &cmd);
 
@@ -498,7 +531,7 @@ int nvme_self_test_log(int fd, struct nvme_self_test_log *self_test_log)
 
 int nvme_effects_log(int fd, struct nvme_effects_log_page *effects_log)
 {
-	return nvme_get_log(fd, 0, NVME_LOG_CMD_EFFECTS, false,
+	return nvme_get_log(fd, NVME_NSID_ALL, NVME_LOG_CMD_EFFECTS, false,
 			sizeof(*effects_log), effects_log);
 }
 
@@ -542,77 +575,61 @@ int nvme_set_feature(int fd, __u32 nsid, __u8 fid, __u32 value, __u32 cdw12,
 			    cdw12, data_len, data, result);
 }
 
-static int nvme_property(int fd, __u8 fctype, __le32 off, __le64 *value, __u8 attrib)
-{
-	int err;
-	struct nvme_admin_cmd cmd = {
-		.opcode		= nvme_fabrics_command,
-		.cdw10		= attrib,
-		.cdw11		= off,
-	};
-
-	if (!value) {
-		errno = EINVAL;
-		return -errno;
-	}
-
-	if (fctype == nvme_fabrics_type_property_get){
-		cmd.nsid = nvme_fabrics_type_property_get;
-	} else if(fctype == nvme_fabrics_type_property_set) {
-		cmd.nsid = nvme_fabrics_type_property_set;
-		cmd.cdw12 = *value;
-	} else {
-		errno = EINVAL;
-		return -errno;
-	}
 
-	err = nvme_submit_admin_passthru(fd, &cmd);
-	if (!err && fctype == nvme_fabrics_type_property_get)
-		*value = cpu_to_le64(cmd.result);
-	return err;
+/*
+ * Perform the opposite operation of the byte-swapping code at the start of the
+ * kernel function nvme_user_cmd().
+ */
+static void nvme_to_passthru_cmd(struct nvme_passthru_cmd *pcmd,
+				 const struct nvme_command *ncmd)
+{
+	assert(sizeof(*ncmd) < sizeof(*pcmd));
+	memset(pcmd, 0, sizeof(*pcmd));
+	pcmd->opcode = ncmd->common.opcode;
+	pcmd->flags = ncmd->common.flags;
+	pcmd->rsvd1 = ncmd->common.command_id;
+	pcmd->nsid = le32_to_cpu(ncmd->common.nsid);
+	pcmd->cdw2 = le32_to_cpu(ncmd->common.cdw2[0]);
+	pcmd->cdw3 = le32_to_cpu(ncmd->common.cdw2[1]);
+	/* Skip metadata and addr */
+	pcmd->cdw10 = le32_to_cpu(ncmd->common.cdw10[0]);
+	pcmd->cdw11 = le32_to_cpu(ncmd->common.cdw10[1]);
+	pcmd->cdw12 = le32_to_cpu(ncmd->common.cdw10[2]);
+	pcmd->cdw13 = le32_to_cpu(ncmd->common.cdw10[3]);
+	pcmd->cdw14 = le32_to_cpu(ncmd->common.cdw10[4]);
+	pcmd->cdw15 = le32_to_cpu(ncmd->common.cdw10[5]);
 }
 
-static int get_property_helper(int fd, int offset, void *value, int *advance)
+int nvme_get_property(int fd, int offset, uint64_t *value)
 {
-	__le64 value64;
-	int err = -EINVAL;
-
-	switch (offset) {
-	case NVME_REG_CAP:
-	case NVME_REG_ASQ:
-	case NVME_REG_ACQ:
-		*advance = 8;
-		break;
-	default:
-		*advance = 4;
-	}
-
-	if (!value)
-		return err;
-
-	err = nvme_property(fd, nvme_fabrics_type_property_get,
-			cpu_to_le32(offset), &value64, (*advance == 8));
+	struct nvme_passthru_cmd pcmd;
+	struct nvmf_property_get_command pg = {
+		.opcode	= nvme_fabrics_command,
+		.fctype	= nvme_fabrics_type_property_get,
+		.offset	= cpu_to_le32(offset),
+		.attrib = is_64bit_reg(offset),
+	};
+	struct nvme_command gcmd;
+	int err;
 
+	gcmd.prop_get = pg;
+	nvme_to_passthru_cmd(&pcmd, &gcmd);
+	err = nvme_submit_admin_passthru(fd, &pcmd);
 	if (!err) {
-		if (*advance == 8)
-			*((uint64_t *)value) = le64_to_cpu(value64);
-		else
-			*((uint32_t *)value) = le32_to_cpu(value64);
+		/*
+		 * nvme_submit_admin_passthru() stores the lower 32 bits
+		 * of the property value in pcmd.result using CPU endianness.
+		 */
+		*value = pcmd.result;
 	}
-
 	return err;
 }
 
-int nvme_get_property(int fd, int offset, uint64_t *value)
-{
-	int advance;
-	return get_property_helper(fd, offset, value, &advance);
-}
-
 int nvme_get_properties(int fd, void **pbar)
 {
-	int offset, advance;
-	int err, ret = -EINVAL;
+	int offset;
+	uint64_t value;
+	int err;
 	int size = getpagesize();
 
 	*pbar = malloc(size);
@@ -622,33 +639,42 @@ int nvme_get_properties(int fd, void **pbar)
 	}
 
 	memset(*pbar, 0xff, size);
-	for (offset = NVME_REG_CAP; offset <= NVME_REG_CMBSZ; offset += advance) {
-		err = get_property_helper(fd, offset, *pbar + offset, &advance);
-		if (!err)
-			ret = 0;
+	for (offset = NVME_REG_CAP; offset <= NVME_REG_CMBSZ;) {
+		err = nvme_get_property(fd, offset, &value);
+		if (err > 0 && (err & 0xff) == NVME_SC_INVALID_FIELD) {
+			err = 0;
+			value = -1;
+		} else if (err) {
+			free(*pbar);
+			break;
+		}
+		if (is_64bit_reg(offset)) {
+			*(uint64_t *)(*pbar + offset) = value;
+			offset += 8;
+		} else {
+			*(uint32_t *)(*pbar + offset) = value;
+			offset += 4;
+		}
 	}
 
-	return ret;
+	return err;
 }
 
-int nvme_set_property(int fd, int offset, int value)
+int nvme_set_property(int fd, int offset, uint64_t value)
 {
-	__le64 val = cpu_to_le64(value);
-	__le32 off = cpu_to_le32(offset);
-	bool is64bit;
-
-	switch (off) {
-	case NVME_REG_CAP:
-	case NVME_REG_ASQ:
-	case NVME_REG_ACQ:
-		is64bit = true;
-		break;
-	default:
-		is64bit = false;
-	}
+	struct nvmf_property_set_command ps = {
+		.opcode	= nvme_fabrics_command,
+		.fctype	= nvme_fabrics_type_property_set,
+		.offset	= cpu_to_le32(offset),
+		.value = cpu_to_le64(value),
+		.attrib = is_64bit_reg(offset),
+	};
+	struct nvme_command scmd;
+	struct nvme_passthru_cmd pcmd;
 
-	return nvme_property(fd, nvme_fabrics_type_property_set,
-			off, &val, is64bit ? 1: 0);
+	scmd.prop_set = ps;
+	nvme_to_passthru_cmd(&pcmd, &scmd);
+	return nvme_submit_admin_passthru(fd, &pcmd);
 }
 
 int nvme_get_feature(int fd, __u32 nsid, __u8 fid, __u8 sel, __u32 cdw11,
@@ -675,7 +701,7 @@ int nvme_format(int fd, __u32 nsid, __u8 lbaf, __u8 ses, __u8 pi,
 }
 
 int nvme_ns_create(int fd, __u64 nsze, __u64 ncap, __u8 flbas,
-		   __u8 dps, __u8 nmic, __u32 *result)
+		   __u8 dps, __u8 nmic, __u32 timeout, __u32 *result)
 {
 	struct nvme_id_ns ns = {
 		.nsze		= cpu_to_le64(nsze),
@@ -689,6 +715,7 @@ int nvme_ns_create(int fd, __u64 nsze, __u64 ncap, __u8 flbas,
 		.addr		= (__u64)(uintptr_t) ((void *)&ns),
 		.cdw10		= 0,
 		.data_len	= 0x1000,
+		.timeout_ms	= timeout,
 	};
 	int err;
 
@@ -698,12 +725,13 @@ int nvme_ns_create(int fd, __u64 nsze, __u64 ncap, __u8 flbas,
 	return err;
 }
 
-int nvme_ns_delete(int fd, __u32 nsid)
+int nvme_ns_delete(int fd, __u32 nsid, __u32 timeout)
 {
 	struct nvme_admin_cmd cmd = {
 		.opcode		= nvme_admin_ns_mgmt,
 		.nsid		= nsid,
 		.cdw10		= 1,
+		.timeout_ms	= timeout,
 	};
 
 	return nvme_submit_admin_passthru(fd, &cmd);
@@ -803,6 +831,21 @@ int nvme_sec_recv(int fd, __u32 nsid, __u8 nssf, __u16 spsp,
 	return err;
 }
 
+int nvme_get_lba_status(int fd, __u64 slba, __u32 mndw, __u8 atype, __u16 rl,
+		void *data)
+{
+	struct nvme_admin_cmd cmd = {
+		.opcode =  nvme_admin_get_lba_status,
+		.addr = (__u64)(uintptr_t) data,
+		.cdw10 = slba & 0xffffffff,
+		.cdw11 = slba >> 32,
+		.cdw12 = mndw,
+		.cdw13 = (atype << 24) | rl,
+	};
+
+	return nvme_submit_admin_passthru(fd, &cmd);
+}
+
 int nvme_dir_send(int fd, __u32 nsid, __u16 dspec, __u8 dtype, __u8 doper,
                   __u32 data_len, __u32 dw12, void *data, __u32 *result)
 {
@@ -867,3 +910,19 @@ int nvme_self_test_start(int fd, __u32 nsid, __u32 cdw10)
 
 	return nvme_submit_admin_passthru(fd, &cmd);
 }
+
+int nvme_virtual_mgmt(int fd, __u32 cdw10, __u32 cdw11, __u32 *result)
+{
+	struct nvme_admin_cmd cmd = {
+		.opcode = nvme_admin_virtual_mgmt,
+		.cdw10  = cdw10,
+		.cdw11  = cdw11,
+	};
+	int err;
+
+	err = nvme_submit_admin_passthru(fd, &cmd);
+	if (!err && result)
+		*result = cmd.result;
+
+	return err;
+}
diff --git a/libmultipath/nvme/nvme-ioctl.h b/libmultipath/nvme/nvme-ioctl.h
index 3fb740c3..565f7648 100644
--- a/libmultipath/nvme/nvme-ioctl.h
+++ b/libmultipath/nvme/nvme-ioctl.h
@@ -6,6 +6,8 @@
 #include "linux/nvme_ioctl.h"
 #include "nvme.h"
 
+#define NVME_IOCTL_TIMEOUT 120000 /* in milliseconds */
+
 int nvme_get_nsid(int fd);
 
 /* Generic passthrough */
@@ -36,6 +38,9 @@ int nvme_compare(int fd, __u64 slba, __u16 nblocks, __u16 control,
 		 __u32 dsmgmt, __u32 reftag, __u16 apptag,
 		 __u16 appmask, void *data, void *metadata);
 
+int nvme_verify(int fd, __u32 nsid, __u64 slba, __u16 nblocks,
+		__u16 control, __u32 reftag, __u16 apptag, __u16 appmask);
+
 /* NVME_IO_CMD */
 int nvme_passthru_io(int fd, __u8 opcode, __u8 flags, __u16 rsvd,
 		     __u32 nsid, __u32 cdw2, __u32 cdw3,
@@ -73,11 +78,22 @@ int nvme_identify_ns_list(int fd, __u32 nsid, bool all, void *data);
 int nvme_identify_ctrl_list(int fd, __u32 nsid, __u16 cntid, void *data);
 int nvme_identify_ns_descs(int fd, __u32 nsid, void *data);
 int nvme_identify_nvmset(int fd, __u16 nvmset_id, void *data);
-int nvme_get_log13(int fd, __u32 nsid, __u8 log_id, __u8 lsp, __u64 lpo,
-		   __u16 group_id, bool rae, __u32 data_len, void *data);
+int nvme_identify_uuid(int fd, void *data);
+int nvme_identify_secondary_ctrl_list(int fd, __u32 nsid, __u16 cntid, void *data);
+int nvme_identify_ns_granularity(int fd, void *data);
 int nvme_get_log(int fd, __u32 nsid, __u8 log_id, bool rae,
 		 __u32 data_len, void *data);
-
+int nvme_get_log14(int fd, __u32 nsid, __u8 log_id, __u8 lsp, __u64 lpo,
+		   __u16 group_id, bool rae, __u8 uuid_ix,
+		   __u32 data_len, void *data);
+
+static inline int nvme_get_log13(int fd, __u32 nsid, __u8 log_id, __u8 lsp,
+				 __u64 lpo, __u16 lsi, bool rae, __u32 data_len,
+				 void *data)
+{
+	return nvme_get_log14(fd, nsid, log_id, lsp, lpo, lsi, rae, 0,
+			      data_len, data);
+}
 
 int nvme_get_telemetry_log(int fd, void *lp, int generate_report,
 			   int ctrl_gen, size_t log_page_size, __u64 offset);
@@ -105,8 +121,8 @@ int nvme_format(int fd, __u32 nsid, __u8 lbaf, __u8 ses, __u8 pi,
 		__u8 pil, __u8 ms, __u32 timeout);
 
 int nvme_ns_create(int fd, __u64 nsze, __u64 ncap, __u8 flbas,
-		   __u8 dps, __u8 nmic, __u32 *result);
-int nvme_ns_delete(int fd, __u32 nsid);
+		   __u8 dps, __u8 nmic, __u32 timeout, __u32 *result);
+int nvme_ns_delete(int fd, __u32 nsid, __u32 timeout);
 
 int nvme_ns_attachment(int fd, __u32 nsid, __u16 num_ctrls,
 		       __u16 *ctrlist, bool attach);
@@ -125,15 +141,18 @@ int nvme_subsystem_reset(int fd);
 int nvme_reset_controller(int fd);
 int nvme_ns_rescan(int fd);
 
+int nvme_get_lba_status(int fd, __u64 slba, __u32 mndw, __u8 atype, __u16 rl,
+		void *data);
 int nvme_dir_send(int fd, __u32 nsid, __u16 dspec, __u8 dtype, __u8 doper,
 		  __u32 data_len, __u32 dw12, void *data, __u32 *result);
 int nvme_dir_recv(int fd, __u32 nsid, __u16 dspec, __u8 dtype, __u8 doper,
 		  __u32 data_len, __u32 dw12, void *data, __u32 *result);
 int nvme_get_properties(int fd, void **pbar);
-int nvme_set_property(int fd, int offset, int value);
+int nvme_set_property(int fd, int offset, uint64_t value);
 int nvme_get_property(int fd, int offset, uint64_t *value);
 int nvme_sanitize(int fd, __u8 sanact, __u8 ause, __u8 owpass, __u8 oipbp,
 		  __u8 no_dealloc, __u32 ovrpat);
 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 */
diff --git a/libmultipath/nvme/nvme.h b/libmultipath/nvme/nvme.h
index 685d1799..7e0278b5 100644
--- a/libmultipath/nvme/nvme.h
+++ b/libmultipath/nvme/nvme.h
@@ -40,16 +40,16 @@ struct nvme_effects_log_page {
 };
 
 struct nvme_error_log_page {
-	__u64	error_count;
-	__u16	sqid;
-	__u16	cmdid;
-	__u16	status_field;
-	__u16	parm_error_location;
-	__u64	lba;
-	__u32	nsid;
+	__le64	error_count;
+	__le16	sqid;
+	__le16	cmdid;
+	__le16	status_field;
+	__le16	parm_error_location;
+	__le64	lba;
+	__le32	nsid;
 	__u8	vs;
 	__u8	resv[3];
-	__u64	cs;
+	__le64	cs;
 	__u8	resv2[24];
 };
 
@@ -87,13 +87,30 @@ struct nvme_controller_list {
 	__le16 identifier[];
 };
 
+struct nvme_secondary_controller_entry {
+	__le16 scid;	/* Secondary Controller Identifier */
+	__le16 pcid;	/* Primary Controller Identifier */
+	__u8   scs;	/* Secondary Controller State */
+	__u8   rsvd5[3];
+	__le16 vfn;	/* Virtual Function Number */
+	__le16 nvq;	/* Number of VQ Flexible Resources Assigned */
+	__le16 nvi;	/* Number of VI Flexible Resources Assigned */
+	__u8   rsvd14[18];
+};
+
+struct nvme_secondary_controllers_list {
+	__u8   num;
+	__u8   rsvd[31];
+	struct nvme_secondary_controller_entry sc_entry[127];
+};
+
 struct nvme_bar_cap {
 	__u16	mqes;
 	__u8	ams_cqr;
 	__u8	to;
 	__u16	bps_css_nssrs_dstrd;
 	__u8	mpsmax_mpsmin;
-	__u8	reserved;
+	__u8	rsvd_pmrs;
 };
 
 #ifdef __CHECKER__
@@ -102,19 +119,31 @@ struct nvme_bar_cap {
 #define __force
 #endif
 
-#define cpu_to_le16(x) \
-	((__force __le16)htole16(x))
-#define cpu_to_le32(x) \
-	((__force __le32)htole32(x))
-#define cpu_to_le64(x) \
-	((__force __le64)htole64(x))
-
-#define le16_to_cpu(x) \
-	le16toh((__force __u16)(x))
-#define le32_to_cpu(x) \
-	le32toh((__force __u32)(x))
-#define le64_to_cpu(x) \
-	le64toh((__force __u64)(x))
+static inline __le16 cpu_to_le16(uint16_t x)
+{
+	return (__force __le16)htole16(x);
+}
+static inline __le32 cpu_to_le32(uint32_t x)
+{
+	return (__force __le32)htole32(x);
+}
+static inline __le64 cpu_to_le64(uint64_t x)
+{
+	return (__force __le64)htole64(x);
+}
+
+static inline uint16_t le16_to_cpu(__le16 x)
+{
+	return le16toh((__force __u16)x);
+}
+static inline uint32_t le32_to_cpu(__le32 x)
+{
+	return le32toh((__force __u32)x);
+}
+static inline uint64_t le64_to_cpu(__le64 x)
+{
+	return le64toh((__force __u64)x);
+}
 
 #define MAX_LIST_ITEMS 256
 struct list_item {
@@ -131,6 +160,10 @@ struct ctrl_list_item {
 	char *transport;
 	char *state;
 	char *ana_state;
+	char *subsysnqn;
+	char *traddr;
+	char *trsvcid;
+	char *host_traddr;
 };
 
 struct subsys_list_item {
@@ -146,6 +179,26 @@ enum {
 	BINARY,
 };
 
+struct connect_args {
+	char *subsysnqn;
+	char *transport;
+	char *traddr;
+	char *trsvcid;
+	char *host_traddr;
+};
+
+#define SYS_NVME		"/sys/class/nvme"
+
+bool ctrl_matches_connectargs(char *name, struct connect_args *args);
+char *find_ctrl_with_connectargs(struct connect_args *args);
+char *__parse_connect_arg(char *conargs, const char delim, const char *fieldnm);
+
+extern const char *conarg_nqn;
+extern const char *conarg_transport;
+extern const char *conarg_traddr;
+extern const char *conarg_trsvcid;
+extern const char *conarg_host_traddr;
+
 void register_extension(struct plugin *plugin);
 
 #include "argconfig.h"
@@ -160,4 +213,28 @@ int	validate_output_format(char *format);
 struct subsys_list_item *get_subsys_list(int *subcnt, char *subsysnqn, __u32 nsid);
 void free_subsys_list(struct subsys_list_item *slist, int n);
 char *nvme_char_from_block(char *block);
+
+/*
+ * is_64bit_reg - It checks whether given offset of the controller register is
+ *                64bit or not.
+ * @offset: offset of controller register field in bytes
+ *
+ * It gives true if given offset is 64bit register, otherwise it returns false.
+ *
+ * Notes:  This function does not care about transport so that the offset is
+ * not going to be checked inside of this function for the unsupported fields
+ * in a specific transport.  For example, BPMBL(Boot Partition Memory Buffer
+ * Location) register is not supported by fabrics, but it can be chcked here.
+ */
+static inline bool is_64bit_reg(__u32 offset)
+{
+	if (offset == NVME_REG_CAP ||
+			offset == NVME_REG_ASQ ||
+			offset == NVME_REG_ACQ ||
+			offset == NVME_REG_BPMBL)
+		return true;
+
+	return false;
+}
+
 #endif /* _NVME_H */
-- 
2.23.0


--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 66/72] multipath-tools: Makefile.inc: fix TEST_CC_OPTION
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (64 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 65/72] libmultipath: nvme: update to nvme-cli v1.9 Martin Wilck
@ 2019-10-12 21:28 ` Martin Wilck
  2019-10-12 21:29 ` [PATCH 67/72] multipath-tools: Makefile.inc: use -Wp, ... for compiling only Martin Wilck
                   ` (5 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:28 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

The test works only if the compiler actually errors out for an
unsupported warning option, which requires setting -Werror.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 Makefile.inc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Makefile.inc b/Makefile.inc
index 0c800ab3..d4d08fe9 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -81,7 +81,8 @@ INSTALL_PROGRAM	= install
 # Test if the C compiler supports the option.
 # Evaluates to "option" if yes, and "fallback" otherwise.
 TEST_CC_OPTION = $(shell \
-	if echo 'int main(void){return 0;}' | $(CC) -o /dev/null -c "$(1)" -xc - >/dev/null 2>&1; \
+	if echo 'int main(void){return 0;}' | \
+		$(CC) -o /dev/null -c -Werror "$(1)" -xc - >/dev/null 2>&1; \
 	then \
 		echo "$(1)"; \
 	else \
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 67/72] multipath-tools: Makefile.inc: use -Wp, ... for compiling only
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (65 preceding siblings ...)
  2019-10-12 21:28 ` [PATCH 66/72] multipath-tools: Makefile.inc: fix TEST_CC_OPTION Martin Wilck
@ 2019-10-12 21:29 ` Martin Wilck
  2019-10-30 14:55   ` Benjamin Marzinski
  2019-10-12 21:29 ` [PATCH 68/72] multipath-tools: Makefile: use proper directory recursion Martin Wilck
                   ` (4 subsequent siblings)
  71 siblings, 1 reply; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:29 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

clang-3.9 errors out if -Wp,... preprocessor flags are used in the
linking stage.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 Makefile.inc | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/Makefile.inc b/Makefile.inc
index d4d08fe9..f309a274 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -96,9 +96,8 @@ OPTFLAGS	= -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int \
 		  -Werror=implicit-function-declaration -Werror=format-security \
 		  -Wno-clobbered \
 		  -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS) \
-		  -Wp,-D_FORTIFY_SOURCE=2 $(STACKPROT) \
-		  --param=ssp-buffer-size=4
-
+		  $(STACKPROT) --param=ssp-buffer-size=4
+CPPFLAGS	:= -Wp,-D_FORTIFY_SOURCE=2 
 CFLAGS		:= $(OPTFLAGS) -DBIN_DIR=\"$(bindir)\" -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\" \
 		   -MMD -MP $(CFLAGS)
 BIN_CFLAGS	= -fPIE -DPIE
@@ -135,4 +134,4 @@ check_file = $(shell \
 
 %.o:	%.c
 	@echo building $@ because of $?
-	$(CC) $(CFLAGS) -c -o $@ $<
+	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 68/72] multipath-tools: Makefile: use proper directory recursion
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (66 preceding siblings ...)
  2019-10-12 21:29 ` [PATCH 67/72] multipath-tools: Makefile.inc: use -Wp, ... for compiling only Martin Wilck
@ 2019-10-12 21:29 ` Martin Wilck
  2019-10-12 21:29 ` [PATCH 69/72] multipath tests: Makefile: fix "clean" target Martin Wilck
                   ` (3 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:29 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

"make -k" didn't work with the Makefile's subdirectory handling.
Do it the proper "make" way.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 Makefile | 38 ++++++++++++++++++--------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/Makefile b/Makefile
index 4b145c59..1dee3680 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
 # Copyright (C) 2003 Christophe Varoqui, <christophe.varoqui@opensvc.com>
 #
 
-BUILDDIRS = \
+BUILDDIRS := \
 	libmpathcmd \
 	libmultipath \
 	libmultipath/prioritizers \
@@ -19,32 +19,30 @@ BUILDDIRS += \
 	libdmmp
 endif
 
-all: recurse
+BUILDDIRS.clean := $(BUILDDIRS:=.clean) tests.clean
 
-recurse:
-	@for dir in $(BUILDDIRS); do $(MAKE) -C $$dir || exit $?; done
+.PHONY:	$(BUILDDIRS) $(BUILDDIRS:=.uninstall) $(BUILDDIRS:=.install) $(BUILDDIRS.clean)
 
-recurse_clean:
-	@for dir in $(BUILDDIRS); do \
-	$(MAKE) -C $$dir clean || exit $?; \
-	done
-	$(MAKE) -C tests clean
+all:	$(BUILDDIRS)
 
-recurse_install:
-	@for dir in $(BUILDDIRS); do \
-	$(MAKE) -C $$dir install || exit $?; \
-	done
+$(BUILDDIRS):
+	$(MAKE) -C $@
 
-recurse_uninstall:
-	@for dir in $(BUILDDIRS); do \
-	$(MAKE) -C $$dir uninstall || exit $?; \
-	done
+multipath multipathd mpathpersist: libmultipath
+mpathpersist:  libmpathpersist
 
-clean: recurse_clean
+$(BUILDDIRS.clean):
+	$(MAKE) -C ${@:.clean=} clean
 
-install: recurse_install
+$(BUILDDIRS:=.install):
+	$(MAKE) -C ${@:.install=} install
 
-uninstall: recurse_uninstall
+$(BUILDDIRS:=.uninstall):
+	$(MAKE) -C ${@:.uninstall=} uninstall
+
+clean: $(BUILDDIRS.clean)
+install: $(BUILDDIRS:=.install)
+uninstall: $(BUILDDIRS:=.uninstall)
 
 test:	all
 	$(MAKE) -C tests
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 69/72] multipath tests: Makefile: fix "clean" target
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (67 preceding siblings ...)
  2019-10-12 21:29 ` [PATCH 68/72] multipath-tools: Makefile: use proper directory recursion Martin Wilck
@ 2019-10-12 21:29 ` Martin Wilck
  2019-10-12 21:29 ` [PATCH 70/72] multipath tests: Makefile: avoid gcc 4.8 missing initializers failure Martin Wilck
                   ` (2 subsequent siblings)
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:29 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 tests/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/Makefile b/tests/Makefile
index 60338f14..c70b8399 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -42,7 +42,7 @@ lib/libchecktur.so:
 OBJS = $(TESTS:%=%.o) test-lib.o
 
 clean: dep_clean
-	$(RM) $(TESTS:%=%-test) $(TESTS:%=%.out) $(OBJS)
+	$(RM) $(TESTS:%=%-test) $(TESTS:%=%.out) $(OBJS) *.o.wrap
 	$(RM) -rf lib
 
 .SECONDARY: $(OBJS)
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 70/72] multipath tests: Makefile: avoid gcc 4.8 missing initializers failure
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (68 preceding siblings ...)
  2019-10-12 21:29 ` [PATCH 69/72] multipath tests: Makefile: fix "clean" target Martin Wilck
@ 2019-10-12 21:29 ` Martin Wilck
  2019-10-12 21:29 ` [PATCH 71/72] multipath-tools: Makefile.inc: enable -Werror Martin Wilck
  2019-10-12 21:29 ` [PATCH 72/72] multipath-tools: Makefile.inc: test for -Wno-clobbered support Martin Wilck
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:29 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

With -Wmissing-field-initializers (implied by our current compiler flags),
gcc 4.8 errors out if nested initializers are missing:

struct A {
       int a, b;
};

struct B {
       struct A a;
       int c;
} b = { .a.a = 1; }

Later gcc versions and clang accept it just fine.
Add a test to tests/Makefile and use -Wno-missing-initializers if gcc 4.8
behavior is detected.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 tests/Makefile | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/tests/Makefile b/tests/Makefile
index c70b8399..c9406e75 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,6 +1,15 @@
 include ../Makefile.inc
 
-CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathcmddir) -Wno-unused-parameter
+# Test special behavior of gcc 4.8 with nested initializers
+# gcc 4.8 compiles blacklist.c only with -Wno-missing-field-initializers
+TEST_MISSING_INITIALIZERS = $(shell \
+	echo 'struct A {int a, b;}; struct B {struct A a; int b;} b = {.a.a=1};' | \
+		$(CC) -c -Werror -Wmissing-field-initializers -o /dev/null -xc - >/dev/null 2>&1 \
+	|| echo -Wno-missing-field-initializers)
+W_MISSING_INITIALIZERS := $(call TEST_MISSING_INITIALIZERS)
+
+CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathcmddir) \
+	-Wno-unused-parameter $(W_MISSING_INITIALIZERS)
 LIBDEPS += -L$(multipathdir) -lmultipath -lcmocka
 
 TESTS := uevent parser util dmevents hwtable blacklist unaligned vpd pgpolicy alias
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 71/72] multipath-tools: Makefile.inc: enable -Werror
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (69 preceding siblings ...)
  2019-10-12 21:29 ` [PATCH 70/72] multipath tests: Makefile: avoid gcc 4.8 missing initializers failure Martin Wilck
@ 2019-10-12 21:29 ` Martin Wilck
  2019-10-12 21:29 ` [PATCH 72/72] multipath-tools: Makefile.inc: test for -Wno-clobbered support Martin Wilck
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:29 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 Makefile.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile.inc b/Makefile.inc
index f309a274..59a36cd3 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -92,7 +92,7 @@ TEST_CC_OPTION = $(shell \
 STACKPROT := $(call TEST_CC_OPTION,-fstack-protector-strong,-fstack-protector)
 ERROR_DISCARDED_QUALIFIERS := $(call TEST_CC_OPTION,-Werror=discarded-qualifiers,)
 
-OPTFLAGS	= -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int \
+OPTFLAGS	= -O2 -g -pipe -Werror -Wall -Wextra -Wformat=2 -Werror=implicit-int \
 		  -Werror=implicit-function-declaration -Werror=format-security \
 		  -Wno-clobbered \
 		  -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS) \
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* [PATCH 72/72] multipath-tools: Makefile.inc: test for -Wno-clobbered support
  2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
                   ` (70 preceding siblings ...)
  2019-10-12 21:29 ` [PATCH 71/72] multipath-tools: Makefile.inc: enable -Werror Martin Wilck
@ 2019-10-12 21:29 ` Martin Wilck
  71 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-12 21:29 UTC (permalink / raw)
  To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

clang doesn't support this option.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 Makefile.inc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Makefile.inc b/Makefile.inc
index 59a36cd3..d4d1e0dd 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -91,10 +91,11 @@ TEST_CC_OPTION = $(shell \
 
 STACKPROT := $(call TEST_CC_OPTION,-fstack-protector-strong,-fstack-protector)
 ERROR_DISCARDED_QUALIFIERS := $(call TEST_CC_OPTION,-Werror=discarded-qualifiers,)
+WNOCLOBBERED := $(call TEST_CC_OPTION,-Wno-clobbered,)
 
 OPTFLAGS	= -O2 -g -pipe -Werror -Wall -Wextra -Wformat=2 -Werror=implicit-int \
 		  -Werror=implicit-function-declaration -Werror=format-security \
-		  -Wno-clobbered \
+		  $(WNOCLOBBERED) \
 		  -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS) \
 		  $(STACKPROT) --param=ssp-buffer-size=4
 CPPFLAGS	:= -Wp,-D_FORTIFY_SOURCE=2 
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 85+ messages in thread

* Re: [PATCH 45/72] libmultipath: fix -Wsign-compare warnings with snprintf()
  2019-10-12 21:28 ` [PATCH 45/72] libmultipath: fix -Wsign-compare warnings with snprintf() Martin Wilck
@ 2019-10-12 22:59   ` Bart Van Assche
  2019-10-22 16:07     ` Martin Wilck
  0 siblings, 1 reply; 85+ messages in thread
From: Bart Van Assche @ 2019-10-12 22:59 UTC (permalink / raw)
  To: Martin Wilck, Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel

On 2019-10-12 14:28, Martin Wilck wrote:
> -	if (snprintf(buf, bufsiz, "%s%s%d", mapname, delim, part) >= bufsiz)
> +	if (snprintf(buf, bufsiz, "%s%s%d", mapname, delim, part)
> +	    >= (int)bufsiz)
>  		return 0;

Please don't insert casts like this. I think enabling -Wsign-compare is
wrong because it makes the source code ugly.

Thank,

Bart.

^ permalink raw reply	[flat|nested] 85+ messages in thread

* Re: [PATCH 41/72] multipath-tools tests: add -Wno-unused-parameter
  2019-10-12 21:28 ` [PATCH 41/72] multipath-tools tests: add -Wno-unused-parameter Martin Wilck
@ 2019-10-12 23:01   ` Bart Van Assche
  0 siblings, 0 replies; 85+ messages in thread
From: Bart Van Assche @ 2019-10-12 23:01 UTC (permalink / raw)
  To: Martin Wilck, Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel

On 2019-10-12 14:28, Martin Wilck wrote:
>  TESTS := uevent parser util dmevents hwtable blacklist unaligned vpd pgpolicy alias
> @@ -56,6 +56,7 @@ dep_clean:
>  	@sed -n 's/^.*__wrap_\([a-zA-Z0-9_]*\).*$$/-Wl,--wrap=\1/p' $< | \
>  		sort -u | tr '\n' ' ' >$@
>  
> +
>  # COLON will get expanded during second expansion below
>  COLON:=:
>  .SECONDEXPANSION:

Is this change useful?

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 85+ messages in thread

* Re: [PATCH 45/72] libmultipath: fix -Wsign-compare warnings with snprintf()
  2019-10-12 22:59   ` Bart Van Assche
@ 2019-10-22 16:07     ` Martin Wilck
  2019-10-22 16:47       ` Bart Van Assche
  0 siblings, 1 reply; 85+ messages in thread
From: Martin Wilck @ 2019-10-22 16:07 UTC (permalink / raw)
  To: bmarzins, bvanassche, christophe.varoqui; +Cc: dm-devel

Hello Bart,

On Sat, 2019-10-12 at 15:59 -0700, Bart Van Assche wrote:
> On 2019-10-12 14:28, Martin Wilck wrote:
> > -	if (snprintf(buf, bufsiz, "%s%s%d", mapname, delim, part) >=
> > bufsiz)
> > +	if (snprintf(buf, bufsiz, "%s%s%d", mapname, delim, part)
> > +	    >= (int)bufsiz)
> >  		return 0;
> 
> Please don't insert casts like this. I think enabling -Wsign-compare
> is
> wrong because it makes the source code ugly.

The casts make it explicit which signedness is intended, which is a
good thing IMO, better than the compiler trying to figure it out
using implicit type conversion. Enabling the warning will help avoid
subtle programming errors in the future, by forcing us to think twice
about signedness. Considering that, isn't this ugliness - which I don't
dispute - a relatively minor issue?

In this particular case, we're dealing with a historically-caused
property of snprintf(), as you are probably aware 
(https://stackoverflow.com/questions/45740276/why-does-printf-return-an-int-instead-of-a-size-t-in-c),
so I'd argue the ugliness is forced upon us, sort of.

We can hide the ugliness in a macro if you prefer. Actually, we have
safe_snprintf() already. We just need to use it in all places where
this kind of comparison is made. Would that be acceptable to you?

Thanks,
Martin

^ permalink raw reply	[flat|nested] 85+ messages in thread

* Re: [PATCH 45/72] libmultipath: fix -Wsign-compare warnings with snprintf()
  2019-10-22 16:07     ` Martin Wilck
@ 2019-10-22 16:47       ` Bart Van Assche
  2019-10-22 20:34         ` Martin Wilck
  0 siblings, 1 reply; 85+ messages in thread
From: Bart Van Assche @ 2019-10-22 16:47 UTC (permalink / raw)
  To: Martin Wilck, bmarzins, christophe.varoqui; +Cc: dm-devel

On 2019-10-22 09:07, Martin Wilck wrote:
> Hello Bart,
> 
> On Sat, 2019-10-12 at 15:59 -0700, Bart Van Assche wrote:
>> On 2019-10-12 14:28, Martin Wilck wrote:
>>> -	if (snprintf(buf, bufsiz, "%s%s%d", mapname, delim, part) >=
>>> bufsiz)
>>> +	if (snprintf(buf, bufsiz, "%s%s%d", mapname, delim, part)
>>> +	    >= (int)bufsiz)
>>>  		return 0;
>>
>> Please don't insert casts like this. I think enabling -Wsign-compare
>> is
>> wrong because it makes the source code ugly.
> 
> The casts make it explicit which signedness is intended, which is a
> good thing IMO, better than the compiler trying to figure it out
> using implicit type conversion. Enabling the warning will help avoid
> subtle programming errors in the future, by forcing us to think twice
> about signedness. Considering that, isn't this ugliness - which I don't
> dispute - a relatively minor issue?
> 
> In this particular case, we're dealing with a historically-caused
> property of snprintf(), as you are probably aware 
> (https://stackoverflow.com/questions/45740276/why-does-printf-return-an-int-instead-of-a-size-t-in-c),
> so I'd argue the ugliness is forced upon us, sort of.
> 
> We can hide the ugliness in a macro if you prefer. Actually, we have
> safe_snprintf() already. We just need to use it in all places where
> this kind of comparison is made. Would that be acceptable to you?

Hi Martin,

Have you considered to use asprintf() instead of snprintf() and a check
whether the output buffer overflows? I think the former is a more
elegant solution.

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 85+ messages in thread

* Re: [PATCH 45/72] libmultipath: fix -Wsign-compare warnings with snprintf()
  2019-10-22 16:47       ` Bart Van Assche
@ 2019-10-22 20:34         ` Martin Wilck
  2019-10-22 21:32           ` Bart Van Assche
  0 siblings, 1 reply; 85+ messages in thread
From: Martin Wilck @ 2019-10-22 20:34 UTC (permalink / raw)
  To: bmarzins, bvanassche, christophe.varoqui; +Cc: dm-devel

On Tue, 2019-10-22 at 09:47 -0700, Bart Van Assche wrote:
> On 2019-10-22 09:07, Martin Wilck wrote:
> > 
> > In this particular case, we're dealing with a historically-caused
> > property of snprintf(), as you are probably aware 
> > (
> > https://stackoverflow.com/questions/45740276/why-does-printf-return-an-int-instead-of-a-size-t-in-c
> > ),
> > so I'd argue the ugliness is forced upon us, sort of.
> > 
> > We can hide the ugliness in a macro if you prefer. Actually, we
> > have
> > safe_snprintf() already. We just need to use it in all places where
> > this kind of comparison is made. Would that be acceptable to you?
> 
> Hi Martin,
> 
> Have you considered to use asprintf() instead of snprintf() and a
> check
> whether the output buffer overflows? I think the former is a more
> elegant solution.

Most uses of snprintf() are in libmultipath printing code, where items
are printed sequentially into a big buffer, advancing the buffer
pointer on the way. asprintf() doesn't match that use case well,
AFAICS. But in some other places, switching to asprintf would certainly
make sense. Anyway, I'd like to do that in a separate patch set if you
don't mind; this one is big enough already.

Thanks,
Martin

^ permalink raw reply	[flat|nested] 85+ messages in thread

* Re: [PATCH 45/72] libmultipath: fix -Wsign-compare warnings with snprintf()
  2019-10-22 20:34         ` Martin Wilck
@ 2019-10-22 21:32           ` Bart Van Assche
  2019-10-23  9:11             ` Martin Wilck
  0 siblings, 1 reply; 85+ messages in thread
From: Bart Van Assche @ 2019-10-22 21:32 UTC (permalink / raw)
  To: Martin Wilck, bmarzins, christophe.varoqui; +Cc: dm-devel

On 2019-10-22 13:34, Martin Wilck wrote:
> Most uses of snprintf() are in libmultipath printing code, where items
> are printed sequentially into a big buffer, advancing the buffer
> pointer on the way. asprintf() doesn't match that use case well,
> AFAICS. But in some other places, switching to asprintf would certainly
> make sense. Anyway, I'd like to do that in a separate patch set if you
> don't mind; this one is big enough already.

Hi Martin,

For this patch, have you considered to change the type of the 'bufsiz'
argument of format_partname() from size_t into int or unsigned int? I do
not expect that the output string will ever exceed 65535 characters. As
you probably know the C standard guarantees that there are at least 16
bits in an int.

I'd like to reiterate that introducing -Wsign-compare seems dubious to me.

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 85+ messages in thread

* Re: [PATCH 45/72] libmultipath: fix -Wsign-compare warnings with snprintf()
  2019-10-22 21:32           ` Bart Van Assche
@ 2019-10-23  9:11             ` Martin Wilck
  0 siblings, 0 replies; 85+ messages in thread
From: Martin Wilck @ 2019-10-23  9:11 UTC (permalink / raw)
  To: bmarzins, bvanassche, christophe.varoqui; +Cc: dm-devel

Hello Bart,

On Tue, 2019-10-22 at 14:32 -0700, Bart Van Assche wrote:
> I'd like to reiterate that introducing -Wsign-compare seems dubious
> to me.

While I disagree with this general statement, I now realized that
my approach to use (int) casts in this specific patch was indeed wrong,
because it prevents detection of negative snprintf() return values.

I'm going to rework this patch.

Regards,
Martin

^ permalink raw reply	[flat|nested] 85+ messages in thread

* Re: [PATCH 13/72] libmultipath: alias.c: prepare for cancel-safe allocation
  2019-10-12 21:27 ` [PATCH 13/72] libmultipath: alias.c: prepare for cancel-safe allocation Martin Wilck
@ 2019-10-30 14:47   ` Benjamin Marzinski
  0 siblings, 0 replies; 85+ messages in thread
From: Benjamin Marzinski @ 2019-10-30 14:47 UTC (permalink / raw)
  To: Martin Wilck; +Cc: dm-devel

On Sat, Oct 12, 2019 at 09:27:53PM +0000, Martin Wilck wrote:
> From: Martin Wilck <mwilck@suse.com>
> 
> In functions that return newly allocated memory, avoid cancellation
> points before returning, and if that's not possible, guard the code
> that contains cancellation points with a cleanup function calling
> free(), and immediately before returning, call pthread_cleanup_pop(0).

This is certainly an improvement. But if we're worried about leaking
memory from a cancellation during this function, shouldn't we be equally
worried about leaking the open file.

-Ben

> 
> Signed-off-by: Martin Wilck <mwilck@suse.com>
> ---
>  libmultipath/alias.c | 22 ++++++++++++----------
>  1 file changed, 12 insertions(+), 10 deletions(-)
> 
> diff --git a/libmultipath/alias.c b/libmultipath/alias.c
> index 15bbc8ed..0fc9e542 100644
> --- a/libmultipath/alias.c
> +++ b/libmultipath/alias.c
> @@ -268,13 +268,12 @@ allocate_binding(int fd, const char *wwid, int id, const char *prefix)
>  	c = strchr(buf, ' ');
>  	if (c)
>  		*c = '\0';
> +
> +	condlog(3, "Created new binding [%s] for WWID [%s]", buf, wwid);
>  	alias = strdup(buf);
>  	if (alias == NULL)
> -		condlog(0, "cannot copy new alias from bindings file : %s",
> -			strerror(errno));
> -	else
> -		condlog(3, "Created new binding [%s] for WWID [%s]", alias,
> -			wwid);
> +		condlog(0, "cannot copy new alias from bindings file: out of memory");
> +
>  	return alias;
>  }
>  
> @@ -342,7 +341,9 @@ use_existing_alias (const char *wwid, const char *file, const char *alias_old,
>  	}
>  
>  out:
> +	pthread_cleanup_push(free, alias);
>  	fclose(f);
> +	pthread_cleanup_pop(0);
>  	return alias;
>  }
>  
> @@ -378,18 +379,19 @@ get_user_friendly_alias(const char *wwid, const char *file, const char *prefix,
>  		return NULL;
>  	}
>  
> +	pthread_cleanup_push(free, alias);
> +
>  	if (fflush(f) != 0) {
>  		condlog(0, "cannot fflush bindings file stream : %s",
>  			strerror(errno));
>  		free(alias);
> -		fclose(f);
> -		return NULL;
> -	}
> -
> -	if (can_write && !bindings_read_only && !alias)
> +		alias = NULL;
> +	} else if (can_write && !bindings_read_only && !alias)
>  		alias = allocate_binding(fd, wwid, id, prefix);
>  
>  	fclose(f);
> +
> +	pthread_cleanup_pop(0);
>  	return alias;
>  }
>  
> -- 
> 2.23.0

^ permalink raw reply	[flat|nested] 85+ messages in thread

* Re: [PATCH 16/72] libmultipath: make path_discovery() pthread_cancel()-safe
  2019-10-12 21:27 ` [PATCH 16/72] libmultipath: make path_discovery() pthread_cancel()-safe Martin Wilck
@ 2019-10-30 14:53   ` Benjamin Marzinski
  2019-11-04  8:29     ` Martin Wilck
  0 siblings, 1 reply; 85+ messages in thread
From: Benjamin Marzinski @ 2019-10-30 14:53 UTC (permalink / raw)
  To: Martin Wilck; +Cc: dm-devel

On Sat, Oct 12, 2019 at 09:27:57PM +0000, Martin Wilck wrote:
> From: Martin Wilck <mwilck@suse.com>
> 
> The udev_enumerate and udev_device refs wouldn't be released
> if the thread was cancelled. Fix it.
> 
> Signed-off-by: Martin Wilck <mwilck@suse.com>
> ---
>  libmultipath/discovery.c | 51 +++++++++++++++++++++++++++++++---------
>  1 file changed, 40 insertions(+), 11 deletions(-)
> 
> diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
> index e68b0e9f..d217ca92 100644
> --- a/libmultipath/discovery.c
> +++ b/libmultipath/discovery.c
> @@ -140,19 +140,47 @@ path_discover (vector pathvec, struct config * conf,
>  	return pathinfo(pp, conf, flag);
>  }
>  
> +static void cleanup_udev_enumerate_ptr(void *arg)
> +{
> +	struct udev_enumerate *ue;
> +
> +	if (!arg)
> +		return;
> +	ue = *((struct udev_enumerate**) arg);
> +	if (ue)
> +		(void)udev_enumerate_unref(ue);
> +}
> +
> +static void cleanup_udev_device_ptr(void *arg)
> +{
> +	struct udev_device *ud;
> +
> +	if (!arg)
> +		return;
> +	ud = *((struct udev_device**) arg);
> +	if (ud)
> +		(void)udev_device_unref(ud);
> +}
> +
>  int
>  path_discovery (vector pathvec, int flag)
>  {
> -	struct udev_enumerate *udev_iter;
> +	struct udev_enumerate *udev_iter = NULL;
>  	struct udev_list_entry *entry;
> -	struct udev_device *udevice;
> +	struct udev_device *udevice = NULL;
>  	struct config *conf;
> -	const char *devpath;
>  	int num_paths = 0, total_paths = 0, ret;
>  
> +	pthread_cleanup_push(cleanup_udev_enumerate_ptr, &udev_iter);
> +	pthread_cleanup_push(cleanup_udev_device_ptr, &udevice);
> +	conf = get_multipath_config();
> +	pthread_cleanup_push(put_multipath_config, conf);
> +
>  	udev_iter = udev_enumerate_new(udev);
> -	if (!udev_iter)
> -		return -ENOMEM;
> +	if (!udev_iter) {
> +		ret = -ENOMEM;
> +		goto out;
> +	}
>  
>  	if (udev_enumerate_add_match_subsystem(udev_iter, "block") < 0 ||
>  	    udev_enumerate_add_match_is_initialized(udev_iter) < 0 ||
> @@ -165,6 +193,8 @@ path_discovery (vector pathvec, int flag)
>  	udev_list_entry_foreach(entry,
>  				udev_enumerate_get_list_entry(udev_iter)) {
>  		const char *devtype;
> +		const char *devpath;
> +
>  		devpath = udev_list_entry_get_name(entry);
>  		condlog(4, "Discover device %s", devpath);
>  		udevice = udev_device_new_from_syspath(udev, devpath);
> @@ -175,19 +205,18 @@ path_discovery (vector pathvec, int flag)
>  		devtype = udev_device_get_devtype(udevice);
>  		if(devtype && !strncmp(devtype, "disk", 4)) {
>  			total_paths++;
> -			conf = get_multipath_config();
> -			pthread_cleanup_push(put_multipath_config, conf);

Why move grabbing the config RCU lock out of the loop? All things being
equal, it seems like we'd rather hold this for less time, and
rcu_read_lock() is designed to be lightweight, so calling it more times
shouldn't be an issue. 

-Ben

>  			if (path_discover(pathvec, conf,
>  					  udevice, flag) == PATHINFO_OK)
>  				num_paths++;
> -			pthread_cleanup_pop(1);
>  		}
> -		udev_device_unref(udevice);
> +		udevice = udev_device_unref(udevice);
>  	}
>  	ret = total_paths - num_paths;
> -out:
> -	udev_enumerate_unref(udev_iter);
>  	condlog(4, "Discovered %d/%d paths", num_paths, total_paths);
> +out:
> +	pthread_cleanup_pop(1);
> +	pthread_cleanup_pop(1);
> +	pthread_cleanup_pop(1);
>  	return ret;
>  }
>  
> -- 
> 2.23.0

^ permalink raw reply	[flat|nested] 85+ messages in thread

* Re: [PATCH 67/72] multipath-tools: Makefile.inc: use -Wp, ... for compiling only
  2019-10-12 21:29 ` [PATCH 67/72] multipath-tools: Makefile.inc: use -Wp, ... for compiling only Martin Wilck
@ 2019-10-30 14:55   ` Benjamin Marzinski
  0 siblings, 0 replies; 85+ messages in thread
From: Benjamin Marzinski @ 2019-10-30 14:55 UTC (permalink / raw)
  To: Martin Wilck; +Cc: dm-devel

On Sat, Oct 12, 2019 at 09:29:01PM +0000, Martin Wilck wrote:
> From: Martin Wilck <mwilck@suse.com>
> 
> clang-3.9 errors out if -Wp,... preprocessor flags are used in the
> linking stage.
> 
> Signed-off-by: Martin Wilck <mwilck@suse.com>
> ---
>  Makefile.inc | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/Makefile.inc b/Makefile.inc
> index d4d08fe9..f309a274 100644
> --- a/Makefile.inc
> +++ b/Makefile.inc
> @@ -96,9 +96,8 @@ OPTFLAGS	= -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int \
>  		  -Werror=implicit-function-declaration -Werror=format-security \
>  		  -Wno-clobbered \
>  		  -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS) \
> -		  -Wp,-D_FORTIFY_SOURCE=2 $(STACKPROT) \
> -		  --param=ssp-buffer-size=4
> -
> +		  $(STACKPROT) --param=ssp-buffer-size=4
> +CPPFLAGS	:= -Wp,-D_FORTIFY_SOURCE=2 

Just a nit. The above line adds trailing whitespace.

-Ben

>  CFLAGS		:= $(OPTFLAGS) -DBIN_DIR=\"$(bindir)\" -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\" \
>  		   -MMD -MP $(CFLAGS)
>  BIN_CFLAGS	= -fPIE -DPIE
> @@ -135,4 +134,4 @@ check_file = $(shell \
>  
>  %.o:	%.c
>  	@echo building $@ because of $?
> -	$(CC) $(CFLAGS) -c -o $@ $<
> +	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
> -- 
> 2.23.0

^ permalink raw reply	[flat|nested] 85+ messages in thread

* Re: [PATCH 16/72] libmultipath: make path_discovery() pthread_cancel()-safe
  2019-10-30 14:53   ` Benjamin Marzinski
@ 2019-11-04  8:29     ` Martin Wilck
  2019-11-06 20:51       ` Benjamin Marzinski
  0 siblings, 1 reply; 85+ messages in thread
From: Martin Wilck @ 2019-11-04  8:29 UTC (permalink / raw)
  To: bmarzins; +Cc: dm-devel

Hi Ben,

thanks for looking into this.

On Wed, 2019-10-30 at 09:53 -0500, Benjamin Marzinski wrote:
> On Sat, Oct 12, 2019 at 09:27:57PM +0000, Martin Wilck wrote:
> > From: Martin Wilck <mwilck@suse.com>
> > 
> > The udev_enumerate and udev_device refs wouldn't be released
> > if the thread was cancelled. Fix it.
> > 
> > Signed-off-by: Martin Wilck <mwilck@suse.com>
> > ---
> >  libmultipath/discovery.c | 51 +++++++++++++++++++++++++++++++-----
> > ----
> >  1 file changed, 40 insertions(+), 11 deletions(-)
> > 
> > diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
> > index e68b0e9f..d217ca92 100644
> > --- a/libmultipath/discovery.c
> > +++ b/libmultipath/discovery.c
> > @@ -140,19 +140,47 @@ path_discover (vector pathvec, struct config
> > * conf,
> >  	return pathinfo(pp, conf, flag);
> >  }
> >  
> > +static void cleanup_udev_enumerate_ptr(void *arg)
> > +{
> > +	struct udev_enumerate *ue;
> > +
> > +	if (!arg)
> > +		return;
> > +	ue = *((struct udev_enumerate**) arg);
> > +	if (ue)
> > +		(void)udev_enumerate_unref(ue);
> > +}
> > +
> > +static void cleanup_udev_device_ptr(void *arg)
> > +{
> > +	struct udev_device *ud;
> > +
> > +	if (!arg)
> > +		return;
> > +	ud = *((struct udev_device**) arg);
> > +	if (ud)
> > +		(void)udev_device_unref(ud);
> > +}
> > +
> >  int
> >  path_discovery (vector pathvec, int flag)
> >  {
> > -	struct udev_enumerate *udev_iter;
> > +	struct udev_enumerate *udev_iter = NULL;
> >  	struct udev_list_entry *entry;
> > -	struct udev_device *udevice;
> > +	struct udev_device *udevice = NULL;
> >  	struct config *conf;
> > -	const char *devpath;
> >  	int num_paths = 0, total_paths = 0, ret;
> >  
> > +	pthread_cleanup_push(cleanup_udev_enumerate_ptr, &udev_iter);
> > +	pthread_cleanup_push(cleanup_udev_device_ptr, &udevice);
> > +	conf = get_multipath_config();
> > +	pthread_cleanup_push(put_multipath_config, conf);
> > +
> >  	udev_iter = udev_enumerate_new(udev);
> > -	if (!udev_iter)
> > -		return -ENOMEM;
> > +	if (!udev_iter) {
> > +		ret = -ENOMEM;
> > +		goto out;
> > +	}
> >  
> >  	if (udev_enumerate_add_match_subsystem(udev_iter, "block") < 0
> > ||
> >  	    udev_enumerate_add_match_is_initialized(udev_iter) < 0 ||
> > @@ -165,6 +193,8 @@ path_discovery (vector pathvec, int flag)
> >  	udev_list_entry_foreach(entry,
> >  				udev_enumerate_get_list_entry(udev_iter
> > )) {
> >  		const char *devtype;
> > +		const char *devpath;
> > +
> >  		devpath = udev_list_entry_get_name(entry);
> >  		condlog(4, "Discover device %s", devpath);
> >  		udevice = udev_device_new_from_syspath(udev, devpath);
> > @@ -175,19 +205,18 @@ path_discovery (vector pathvec, int flag)
> >  		devtype = udev_device_get_devtype(udevice);
> >  		if(devtype && !strncmp(devtype, "disk", 4)) {
> >  			total_paths++;
> > -			conf = get_multipath_config();
> > -			pthread_cleanup_push(put_multipath_config,
> > conf);
> 
> Why move grabbing the config RCU lock out of the loop? 

Yes, that was the idea.

> All things being
> equal, it seems like we'd rather hold this for less time, and
> rcu_read_lock() is designed to be lightweight, so calling it more
> times
> shouldn't be an issue. 

It's not the execution time of rcu_read_lock() that I'm concerned
about. 

In this particular loop, my estimate is that >90% of time is spent in
path_discover()/pathinfo(), so time-during-which-lock-is-held-wise, we
gain little by taking and releasing the RCU lock in every iteration. 

Right, we might catch a configuration change _earlier_ if we release
the lock between pathinfo() invocations. But - do we actually want
that? This lock protects us against corruption of the multipathd
configuration, basically against someone calling "multipathd
reconfigure" while our code is running. But if the configuration ins
really changed, what we're currently doing is vain anyway - once the
configure() call is finished, we will go through yet another full
reconfigure cycle. IOW: Do we seriously want to call pathinfo() for the
different paths in the system with  different configuration, once with
and once without "user_friendly_names", for example?

Given that the code we're talking about is only called from
reconfigure(), multipath_conf having just been reassigned, IMO it's an
improvement to hold the lock through the entire loop. It might even be
good to hold the lock for the complete invocation of configure(), but I
haven't thought about that in detail yet.

Does this make sense?

Besides, to my taste at least, it improves readability of the code to
move get_multipath_config() out of certain loops.

Thanks,
Martin

^ permalink raw reply	[flat|nested] 85+ messages in thread

* Re: [PATCH 16/72] libmultipath: make path_discovery() pthread_cancel()-safe
  2019-11-04  8:29     ` Martin Wilck
@ 2019-11-06 20:51       ` Benjamin Marzinski
  0 siblings, 0 replies; 85+ messages in thread
From: Benjamin Marzinski @ 2019-11-06 20:51 UTC (permalink / raw)
  To: Martin Wilck; +Cc: dm-devel

On Mon, Nov 04, 2019 at 08:29:21AM +0000, Martin Wilck wrote:
> Hi Ben,
> 
> thanks for looking into this.
> 
> On Wed, 2019-10-30 at 09:53 -0500, Benjamin Marzinski wrote:
> > On Sat, Oct 12, 2019 at 09:27:57PM +0000, Martin Wilck wrote:
> > > From: Martin Wilck <mwilck@suse.com>
> > > 
> > > The udev_enumerate and udev_device refs wouldn't be released
> > > if the thread was cancelled. Fix it.
> > > 
> > > Signed-off-by: Martin Wilck <mwilck@suse.com>
> > > ---
> > >  libmultipath/discovery.c | 51 +++++++++++++++++++++++++++++++-----
> > > ----
> > >  1 file changed, 40 insertions(+), 11 deletions(-)
> > > 
> > > diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
> > > index e68b0e9f..d217ca92 100644
> > > --- a/libmultipath/discovery.c
> > > +++ b/libmultipath/discovery.c
> > > @@ -140,19 +140,47 @@ path_discover (vector pathvec, struct config
> > > * conf,
> > >  	return pathinfo(pp, conf, flag);
> > >  }
> > >  
> > > +static void cleanup_udev_enumerate_ptr(void *arg)
> > > +{
> > > +	struct udev_enumerate *ue;
> > > +
> > > +	if (!arg)
> > > +		return;
> > > +	ue = *((struct udev_enumerate**) arg);
> > > +	if (ue)
> > > +		(void)udev_enumerate_unref(ue);
> > > +}
> > > +
> > > +static void cleanup_udev_device_ptr(void *arg)
> > > +{
> > > +	struct udev_device *ud;
> > > +
> > > +	if (!arg)
> > > +		return;
> > > +	ud = *((struct udev_device**) arg);
> > > +	if (ud)
> > > +		(void)udev_device_unref(ud);
> > > +}
> > > +
> > >  int
> > >  path_discovery (vector pathvec, int flag)
> > >  {
> > > -	struct udev_enumerate *udev_iter;
> > > +	struct udev_enumerate *udev_iter = NULL;
> > >  	struct udev_list_entry *entry;
> > > -	struct udev_device *udevice;
> > > +	struct udev_device *udevice = NULL;
> > >  	struct config *conf;
> > > -	const char *devpath;
> > >  	int num_paths = 0, total_paths = 0, ret;
> > >  
> > > +	pthread_cleanup_push(cleanup_udev_enumerate_ptr, &udev_iter);
> > > +	pthread_cleanup_push(cleanup_udev_device_ptr, &udevice);
> > > +	conf = get_multipath_config();
> > > +	pthread_cleanup_push(put_multipath_config, conf);
> > > +
> > >  	udev_iter = udev_enumerate_new(udev);
> > > -	if (!udev_iter)
> > > -		return -ENOMEM;
> > > +	if (!udev_iter) {
> > > +		ret = -ENOMEM;
> > > +		goto out;
> > > +	}
> > >  
> > >  	if (udev_enumerate_add_match_subsystem(udev_iter, "block") < 0
> > > ||
> > >  	    udev_enumerate_add_match_is_initialized(udev_iter) < 0 ||
> > > @@ -165,6 +193,8 @@ path_discovery (vector pathvec, int flag)
> > >  	udev_list_entry_foreach(entry,
> > >  				udev_enumerate_get_list_entry(udev_iter
> > > )) {
> > >  		const char *devtype;
> > > +		const char *devpath;
> > > +
> > >  		devpath = udev_list_entry_get_name(entry);
> > >  		condlog(4, "Discover device %s", devpath);
> > >  		udevice = udev_device_new_from_syspath(udev, devpath);
> > > @@ -175,19 +205,18 @@ path_discovery (vector pathvec, int flag)
> > >  		devtype = udev_device_get_devtype(udevice);
> > >  		if(devtype && !strncmp(devtype, "disk", 4)) {
> > >  			total_paths++;
> > > -			conf = get_multipath_config();
> > > -			pthread_cleanup_push(put_multipath_config,
> > > conf);
> > 
> > Why move grabbing the config RCU lock out of the loop? 
> 
> Yes, that was the idea.
> 
> > All things being
> > equal, it seems like we'd rather hold this for less time, and
> > rcu_read_lock() is designed to be lightweight, so calling it more
> > times
> > shouldn't be an issue. 
> 
> It's not the execution time of rcu_read_lock() that I'm concerned
> about. 
> 
> In this particular loop, my estimate is that >90% of time is spent in
> path_discover()/pathinfo(), so time-during-which-lock-is-held-wise, we
> gain little by taking and releasing the RCU lock in every iteration. 
> 
> Right, we might catch a configuration change _earlier_ if we release
> the lock between pathinfo() invocations. But - do we actually want
> that? This lock protects us against corruption of the multipathd
> configuration, basically against someone calling "multipathd
> reconfigure" while our code is running. But if the configuration ins
> really changed, what we're currently doing is vain anyway - once the
> configure() call is finished, we will go through yet another full
> reconfigure cycle. IOW: Do we seriously want to call pathinfo() for the
> different paths in the system with  different configuration, once with
> and once without "user_friendly_names", for example?
> 
> Given that the code we're talking about is only called from
> reconfigure(), multipath_conf having just been reassigned, IMO it's an
> improvement to hold the lock through the entire loop. It might even be
> good to hold the lock for the complete invocation of configure(), but I
> haven't thought about that in detail yet.
> 
> Does this make sense?

Sure. ACK

-Ben
 
> Besides, to my taste at least, it improves readability of the code to
> move get_multipath_config() out of certain loops.
> 
> Thanks,
> Martin
> 

^ permalink raw reply	[flat|nested] 85+ messages in thread

end of thread, other threads:[~2019-11-06 20:51 UTC | newest]

Thread overview: 85+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-12 21:27 [PATCH 00/72] multipath-tools: cleanup and warning enablement Martin Wilck
2019-10-12 21:27 ` [PATCH 01/72] multipath tests: move condlog test wrappers to separate file Martin Wilck
2019-10-12 21:27 ` [PATCH 02/72] multipath tests: add tests for alias handling Martin Wilck
2019-10-12 21:27 ` [PATCH 03/72] libmultipath: alias.c: constify function arguments Martin Wilck
2019-10-12 21:27 ` [PATCH 04/72] libmultipath: alias.c: use strlcpy(), and 2 minor fixes Martin Wilck
2019-10-12 21:27 ` [PATCH 05/72] libmultipath: format_devname: avoid buffer overflow Martin Wilck
2019-10-12 21:27 ` [PATCH 06/72] libmultipath: scan_devname: fix int overflow detection Martin Wilck
2019-10-12 21:27 ` [PATCH 07/72] libmultipath: lookup_binding(): don't rely on int overflow Martin Wilck
2019-10-12 21:27 ` [PATCH 08/72] libmultipath: rlookup_binding(): removed unused parameter Martin Wilck
2019-10-12 21:27 ` [PATCH 09/72] libmultipath: allocate_binding(): error out for id=0 Martin Wilck
2019-10-12 21:27 ` [PATCH 10/72] libmultipath: allocate_binding(): detect line overflow Martin Wilck
2019-10-12 21:27 ` [PATCH 11/72] multipath tests: alias: add tests for allocate_binding() Martin Wilck
2019-10-12 21:27 ` [PATCH 12/72] multipath tests: alias: add format/scan test Martin Wilck
2019-10-12 21:27 ` [PATCH 13/72] libmultipath: alias.c: prepare for cancel-safe allocation Martin Wilck
2019-10-30 14:47   ` Benjamin Marzinski
2019-10-12 21:27 ` [PATCH 14/72] multipath tests: use -lpthread for alias test Martin Wilck
2019-10-12 21:27 ` [PATCH 15/72] libmultipath: path_discovery: handle libudev errors Martin Wilck
2019-10-12 21:27 ` [PATCH 16/72] libmultipath: make path_discovery() pthread_cancel()-safe Martin Wilck
2019-10-30 14:53   ` Benjamin Marzinski
2019-11-04  8:29     ` Martin Wilck
2019-11-06 20:51       ` Benjamin Marzinski
2019-10-12 21:27 ` [PATCH 17/72] libmultipath: uevent_listen(): fix poll() retval check Martin Wilck
2019-10-12 21:27 ` [PATCH 18/72] libmultipath: replace_wwids(): fix possible fd leak Martin Wilck
2019-10-12 21:28 ` [PATCH 19/72] libmultipath: remove_wwids(): fix possible leaks Martin Wilck
2019-10-12 21:28 ` [PATCH 20/72] libmultipath: _init_foreign(): fix possible memory leak Martin Wilck
2019-10-12 21:28 ` [PATCH 21/72] libmultipath: process_config_dir(): remove unused argument Martin Wilck
2019-10-12 21:28 ` [PATCH 22/72] libmultipath: mark unused arguments in partmap functions Martin Wilck
2019-10-12 21:28 ` [PATCH 23/72] libmultipath: scsi_ioctl_pathinfo(): remove unused argument Martin Wilck
2019-10-12 21:28 ` [PATCH 24/72] multipath-tools: mark unused params in signal and cleanup handlers Martin Wilck
2019-10-12 21:28 ` [PATCH 25/72] libmultipath: get_ana_info(): remove unused parameter Martin Wilck
2019-10-12 21:28 ` [PATCH 26/72] libmultipath: mark unused params in getprio() methods Martin Wilck
2019-10-12 21:28 ` [PATCH 27/72] libmultipath: hp_sw: remove usused argument in do_inq() Martin Wilck
2019-10-12 21:28 ` [PATCH 28/72] libmultipath: checkers: mark unused arguments in methods Martin Wilck
2019-10-12 21:28 ` [PATCH 29/72] multipathd: stop_waiter_thread(): removed unused parameter Martin Wilck
2019-10-12 21:28 ` [PATCH 30/72] multipath tools: mark unused arguments in thread routines Martin Wilck
2019-10-12 21:28 ` [PATCH 31/72] kpartx: gpt: remove unused arg in read_lastoddsector() Martin Wilck
2019-10-12 21:28 ` [PATCH 32/72] kpartx: mark unused arguments in ptreader methods Martin Wilck
2019-10-12 21:28 ` [PATCH 33/72] libmultipath: mark missing arguments in functions matching prototypes Martin Wilck
2019-10-12 21:28 ` [PATCH 34/72] libmultipath: get_pgpolicy_name(): use "len" parameter Martin Wilck
2019-10-12 21:28 ` [PATCH 35/72] libmultipath: snprint_multipath_map_json(): remove unused argument Martin Wilck
2019-10-12 21:28 ` [PATCH 36/72] multipath: delegate_to_multipathd: mark unused arguments Martin Wilck
2019-10-12 21:28 ` [PATCH 37/72] libmultipath: use -Wno-unused-parameter for dict.c Martin Wilck
2019-10-12 21:28 ` [PATCH 38/72] multipathd: use -Wno-unused-parameter for cli_handlers.c Martin Wilck
2019-10-12 21:28 ` [PATCH 39/72] libmpathpersist: remove unused "noisy" argument in various functions Martin Wilck
2019-10-12 21:28 ` [PATCH 40/72] libmpathpersist: fix copy-paste error in mpath_format_readresv() Martin Wilck
2019-10-12 21:28 ` [PATCH 41/72] multipath-tools tests: add -Wno-unused-parameter Martin Wilck
2019-10-12 23:01   ` Bart Van Assche
2019-10-12 21:28 ` [PATCH 42/72] multipath-tools: Makefile.inc: remove -Wno-unused-parameter Martin Wilck
2019-10-12 21:28 ` [PATCH 43/72] libmultipath: dev_loss_tmo is unsigned Martin Wilck
2019-10-12 21:28 ` [PATCH 44/72] libmultipath: trivial changes for -Wsign-compare Martin Wilck
2019-10-12 21:28 ` [PATCH 45/72] libmultipath: fix -Wsign-compare warnings with snprintf() Martin Wilck
2019-10-12 22:59   ` Bart Van Assche
2019-10-22 16:07     ` Martin Wilck
2019-10-22 16:47       ` Bart Van Assche
2019-10-22 20:34         ` Martin Wilck
2019-10-22 21:32           ` Bart Van Assche
2019-10-23  9:11             ` Martin Wilck
2019-10-12 21:28 ` [PATCH 46/72] libmultipath: parse_vpd_pg83(): sanitize indentation Martin Wilck
2019-10-12 21:28 ` [PATCH 47/72] libmultipath: parse_vpd_pg83(): fix -Wsign-compare warnings Martin Wilck
2019-10-12 21:28 ` [PATCH 48/72] libmultipath: print: use unsigned int for "width" field Martin Wilck
2019-10-12 21:28 ` [PATCH 49/72] libmultipath: vector_for_each_slot: fix -Wsign-compare warnings Martin Wilck
2019-10-12 21:28 ` [PATCH 50/72] libmultipath: set_int(): add error check and set_uint() Martin Wilck
2019-10-12 21:28 ` [PATCH 51/72] libmultipath: make "checkint" unsigned Martin Wilck
2019-10-12 21:28 ` [PATCH 52/72] libmultipath: use unsigned blksize in directio context Martin Wilck
2019-10-12 21:28 ` [PATCH 53/72] libmultipath, kpartx: byteorder: always use unsigned types Martin Wilck
2019-10-12 21:28 ` [PATCH 54/72] libmpathcmd: fix -Wsign-compare warnings Martin Wilck
2019-10-12 21:28 ` [PATCH 55/72] libmpathpersist: " Martin Wilck
2019-10-12 21:28 ` [PATCH 56/72] kpartx: use unsigned arguments in dm_devn() and dm_prereq() Martin Wilck
2019-10-12 21:28 ` [PATCH 57/72] kpartx: use unsigned int for "ns" argument of ptreader Martin Wilck
2019-10-12 21:28 ` [PATCH 58/72] multipath-tools: Makefile.inc: enable -Wsign-compare Martin Wilck
2019-10-12 21:28 ` [PATCH 59/72] libdmmp: fix clang -Wformat-nonliteral warnings Martin Wilck
2019-10-12 21:28 ` [PATCH 60/72] libmultipath: fix clang -Wformat-literal warnings Martin Wilck
2019-10-12 21:28 ` [PATCH 61/72] multipath tests: blacklist: remove always-true condition Martin Wilck
2019-10-12 21:28 ` [PATCH 62/72] multipath tests: hwtable: fix strncat() invocation Martin Wilck
2019-10-12 21:28 ` [PATCH 63/72] multipath tests: fix -Wformat-literal warning Martin Wilck
2019-10-12 21:28 ` [PATCH 64/72] multipath tests: util: fix clang strlcpy warnings Martin Wilck
2019-10-12 21:28 ` [PATCH 65/72] libmultipath: nvme: update to nvme-cli v1.9 Martin Wilck
2019-10-12 21:28 ` [PATCH 66/72] multipath-tools: Makefile.inc: fix TEST_CC_OPTION Martin Wilck
2019-10-12 21:29 ` [PATCH 67/72] multipath-tools: Makefile.inc: use -Wp, ... for compiling only Martin Wilck
2019-10-30 14:55   ` Benjamin Marzinski
2019-10-12 21:29 ` [PATCH 68/72] multipath-tools: Makefile: use proper directory recursion Martin Wilck
2019-10-12 21:29 ` [PATCH 69/72] multipath tests: Makefile: fix "clean" target Martin Wilck
2019-10-12 21:29 ` [PATCH 70/72] multipath tests: Makefile: avoid gcc 4.8 missing initializers failure Martin Wilck
2019-10-12 21:29 ` [PATCH 71/72] multipath-tools: Makefile.inc: enable -Werror Martin Wilck
2019-10-12 21:29 ` [PATCH 72/72] multipath-tools: Makefile.inc: test for -Wno-clobbered support Martin Wilck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.