multipath-tools: cleanup and warning enablement
Subsystems (3)
cover multipath-tools: cleanup and warning enablement
From: Martin Wilck <[email protected]>
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
Signature · 1 line
2.23.0
PATCH 1/72 multipath tests: move condlog test wrappers to separate file
From: Martin Wilck <[email protected]>
These helpers can be useful in other tests.
--- 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
tests/Makefile +1 -0
@@ -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
tests/blacklist.c +1 -19
@@ -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;
tests/test-log.c new file +26 -0
@@ -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); +} +
tests/test-log.h new file +7 -0
@@ -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
Signature · 1 line
2.23.0
PATCH 2/72 multipath tests: add tests for alias handling
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
Some of these tests fail with the current code base.
--- tests/Makefile | 3 +- tests/alias.c | 590 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 592 insertions(+), 1 deletion(-) create mode 100644 tests/alias.c
tests/Makefile +2 -1
@@ -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
tests/alias.c new file +590 -0
590 lines not on this page · raw message
Signature · 1 line
2.23.0
PATCH 3/72 libmultipath: alias.c: constify function arguments
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- libmultipath/alias.c | 29 ++++++++++++++++------------- libmultipath/alias.h | 12 +++++++----- 2 files changed, 23 insertions(+), 18 deletions(-)
libmultipath/alias.c +16 -13
@@ -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;
libmultipath/alias.h +7 -5
@@ -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);
Signature · 1 line
2.23.0
PATCH 4/72 libmultipath: alias.c: use strlcpy(), and 2 minor fixes
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- libmultipath/alias.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
libmultipath/alias.c +4 -4
@@ -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);
Signature · 1 line
2.23.0
PATCH 5/72 libmultipath: format_devname: avoid buffer overflow
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
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.
--- libmultipath/alias.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
libmultipath/alias.c +13 -4
@@ -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' ;
Signature · 1 line
2.23.0
PATCH 6/72 libmultipath: scan_devname: fix int overflow detection
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
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.
--- libmultipath/alias.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
libmultipath/alias.c +3 -2
@@ -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++; }
Signature · 1 line
2.23.0
PATCH 7/72 libmultipath: lookup_binding(): don't rely on int overflow
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
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.
--- libmultipath/alias.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-)
libmultipath/alias.c +30 -11
@@ -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);
Signature · 1 line
2.23.0
PATCH 8/72 libmultipath: rlookup_binding(): removed unused parameter
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
The parameter "prefix" is unused in this function.
--- libmultipath/alias.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
libmultipath/alias.c +3 -3
@@ -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 ;
Signature · 1 line
2.23.0
PATCH 9/72 libmultipath: allocate_binding(): error out for id=0
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
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.
--- libmultipath/alias.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
libmultipath/alias.c +3 -2
@@ -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 ; }
Signature · 1 line
2.23.0
PATCH 10/72 libmultipath: allocate_binding(): detect line overflow
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
Be sure not to truncate the WWID. This shouldn't happen under normal circumstances, but play it safe.
--- libmultipath/alias.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
libmultipath/alias.c +4 -1
@@ -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 );
Signature · 1 line
2.23.0
PATCH 11/72 multipath tests: alias: add tests for allocate_binding()
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- tests/alias.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+)
tests/alias.c +124 -0
@@ -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; }
Signature · 1 line
2.23.0
PATCH 12/72 multipath tests: alias: add format/scan test
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
Test scan_devname(format_devname(id)) == id.
--- tests/alias.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
tests/alias.c +30 -0
@@ -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 );
Signature · 1 line
2.23.0
PATCH 13/72 libmultipath: alias.c: prepare for cancel-safe allocation
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
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).
--- libmultipath/alias.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
libmultipath/alias.c +12 -10
@@ -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; }
Signature · 1 line
2.23.0
Benjamin Marzinski
maintainerRe: [PATCH 13/72] libmultipath: alias.c: prepare for cancel-safe allocation
Quoted 6 lines · Martin Wilck
From: Martin Wilck <[email protected]>
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, callpthread_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
Quoted 65 lines
Signed-off-by Martin Wilck <[email protected]>--- libmultipath/alias.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)libmultipath/alias.c +12
-10@@ -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; }Signature · 1 line
2.23.0
PATCH 14/72 multipath tests: use -lpthread for alias test
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
This becomes necessary because of the previous patch.
--- tests/Makefile | 1 + 1 file changed, 1 insertion(+)
tests/Makefile +1 -0
@@ -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
Signature · 1 line
2.23.0
PATCH 15/72 libmultipath: path_discovery: handle libudev errors
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
pass out if any libudev helpers return an error code.
--- libmultipath/discovery.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
libmultipath/discovery.c +11 -5
@@ -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) \
Signature · 1 line
2.23.0
PATCH 16/72 libmultipath: make path_discovery() pthread_cancel()-safe
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
The udev_enumerate and udev_device refs wouldn't be released if the thread was cancelled. Fix it.
--- libmultipath/discovery.c | 51 +++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 11 deletions(-)
libmultipath/discovery.c +40 -11
@@ -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; }
Signature · 1 line
2.23.0
Benjamin Marzinski
maintainerRe: [PATCH 16/72] libmultipath: make path_discovery() pthread_cancel()-safe
Quoted 77 lines · Martin Wilck
From: Martin Wilck <[email protected]>
The
udev_enumerateandudev_devicerefs wouldn't be released if the thread was cancelled. Fix it.Signed-off-by Martin Wilck <[email protected]>--- libmultipath/discovery.c | 51 +++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 11 deletions(-)libmultipath/discovery.c +35
-5@@ -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);
libmultipath/discovery.c path_discovery (vector pathvec, int flag) · line 179
Quoted 5 lines
libmultipath/discovery.c +0
-2@@ -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
Quoted 21 lines
libmultipath/discovery.c +5
-4if (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; }Signature · 1 line
2.23.0
Re: [PATCH 16/72] libmultipath: make path_discovery() pthread_cancel()-safe
Hi Ben,
thanks for looking into this.
Quoted 82 lines · Benjamin Marzinski
Quoted 81 lines · Martin Wilck
From: Martin Wilck <[email protected]>
The
udev_enumerateandudev_devicerefs wouldn't be released if the thread was cancelled. Fix it.Signed-off-by Martin Wilck <[email protected]>--- libmultipath/discovery.c | 51 +++++++++++++++++++++++++++++++----- ---- 1 file changed, 40 insertions(+), 11 deletions(-)libmultipath/discovery.c +33
-5@@ -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||
libmultipath/discovery.c +2
-0udev_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);libmultipath/discovery.c +0
-0udevice =udev_device_new_from_syspath (udev, devpath);@@ -175,19 +205,18 @@ path_discovery (vector pathvec, int flag)
Quoted 8 lines
libmultipath/discovery.c path_discovery (vector pathvec, int flag)
Quoted 6 lines
libmultipath/discovery.c +0
-2devtype =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.
Quoted 5 lines
All things being
equal, it seems like we'd rather hold this for less time, andrcu_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
Benjamin Marzinski
maintainerRe: [PATCH 16/72] libmultipath: make path_discovery() pthread_cancel()-safe
Quoted 122 lines · Martin Wilck
Hi Ben,
thanks for looking into this.
Quoted 82 lines · Benjamin Marzinski
Quoted 81 lines · Martin Wilck
From: Martin Wilck <[email protected]>
The
udev_enumerateandudev_devicerefs wouldn't be released if the thread was cancelled. Fix it.Signed-off-by Martin Wilck <[email protected]>--- libmultipath/discovery.c | 51 +++++++++++++++++++++++++++++++----- ---- 1 file changed, 40 insertions(+), 11 deletions(-)libmultipath/discovery.c +33
-5@@ -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||
libmultipath/discovery.c +2
-0udev_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);libmultipath/discovery.c +0
-0udevice =udev_device_new_from_syspath (udev, devpath);@@ -175,19 +205,18 @@ path_discovery (vector pathvec, int flag)Quoted 8 lines
libmultipath/discovery.c path_discovery (vector pathvec, int flag)
Quoted 6 lines
libmultipath/discovery.c +0
-2devtype =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.
Quoted 5 lines
All things being
equal, it seems like we'd rather hold this for less time, andrcu_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 theconfigure()call is finished, we will go through yet another full reconfigure cycle. IOW: Do we seriously want to callpathinfo()for the different paths in the system with different configuration, once with and once without "user_friendly_names", for example?
Quoted 7 lines
Given that the code we're talking about is only called from
reconfigure(),multipath_confhaving 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 ofconfigure(), but I haven't thought about that in detail yet.Does this make sense?
Sure. ACK
-Ben
Quoted 6 lines
Besides, to my taste at least, it improves readability of the code to move
get_multipath_config()out of certain loops.Thanks,
Martin
PATCH 17/72 libmultipath: uevent_listen(): fix poll() retval check
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
Only check revents if poll() returns a positive value.
--- libmultipath/uevent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libmultipath/uevent.c +1 -1
@@ -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) {
Signature · 1 line
2.23.0
PATCH 18/72 libmultipath: replace_wwids(): fix possible fd leak
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
... in case the thread is cancelled.
--- libmultipath/wwids.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
libmultipath/wwids.c +6 -2
@@ -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; }
Signature · 1 line
2.23.0
PATCH 19/72 libmultipath: remove_wwids(): fix possible leaks
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
... of fd and memory.
--- libmultipath/wwids.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)
libmultipath/wwids.c +16 -9
@@ -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; }
Signature · 1 line
2.23.0
PATCH 20/72 libmultipath: _init_foreign(): fix possible memory leak
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
free_pre() wasn't called if scandir() failed. Fix it.
--- libmultipath/foreign.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
libmultipath/foreign.c +9 -7
@@ -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)
Signature · 1 line
2.23.0
PATCH 21/72 libmultipath: process_config_dir(): remove unused argument
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- libmultipath/config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
libmultipath/config.c +2 -2
@@ -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
Signature · 1 line
2.23.0
PATCH 22/72 libmultipath: mark unused arguments in partmap functions
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- libmultipath/devmapper.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
libmultipath/devmapper.c +3 -2
@@ -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);
Signature · 1 line
2.23.0
PATCH 23/72 libmultipath: scsi_ioctl_pathinfo(): remove unused argument
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- libmultipath/discovery.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
libmultipath/discovery.c +2 -2
@@ -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);
Signature · 1 line
2.23.0
PATCH 24/72 multipath-tools: mark unused params in signal and cleanup handlers
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
These parameters are all rightfully unused, yet need to be declared because of the function prototypes.
--- 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(-)
libmultipath/file.c +1 -1
@@ -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 */ }
libmultipath/foreign.c +1 -1
@@ -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); }
libmultipath/io_err_stat.c +2 -2
@@ -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 ); }
mpathpersist/main.c +1 -1
@@ -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 */ }
multipath/main.c +1 -1
@@ -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 */ }
multipathd/dmevents.c +2 -2
@@ -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;
multipathd/main.c +7 -7
@@ -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" ); }
Signature · 1 line
2.23.0
PATCH 25/72 libmultipath: get_ana_info(): remove unused parameter
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- libmultipath/prioritizers/ana.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
libmultipath/prioritizers/ana.c +2 -2
@@ -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 :
Signature · 1 line
2.23.0
PATCH 26/72 libmultipath: mark unused params in getprio() methods
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- 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(-)
libmultipath/prioritizers/ana.c +2 -1
@@ -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;
libmultipath/prioritizers/const.c +3 -1
@@ -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 ; }
libmultipath/prioritizers/datacore.c +2 -1
@@ -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); }
libmultipath/prioritizers/emc.c +2 -1
@@ -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); }
libmultipath/prioritizers/hds.c +2 -1
@@ -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); }
libmultipath/prioritizers/hp_sw.c +2 -1
@@ -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); }
libmultipath/prioritizers/iet.c +2 -1
@@ -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); }
libmultipath/prioritizers/ontap.c +2 -1
@@ -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); }
libmultipath/prioritizers/random.c +3 -1
@@ -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;
libmultipath/prioritizers/rdac.c +2 -1
@@ -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); }
libmultipath/prioritizers/sysfs.c +2 -1
@@ -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 ];
libmultipath/prioritizers/weightedpath.c +2 -1
@@ -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); }
Signature · 1 line
2.23.0
PATCH 27/72 libmultipath: hp_sw: remove usused argument in do_inq()
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- libmultipath/checkers/hp_sw.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
libmultipath/checkers/hp_sw.c +2 -2
@@ -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 ;
Signature · 1 line
2.23.0
PATCH 28/72 libmultipath: checkers: mark unused arguments in methods
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- 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(-)
libmultipath/checkers/cciss_tur.c +2 -2
@@ -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 ; }
libmultipath/checkers/hp_sw.c +2 -2
@@ -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 ; }
libmultipath/checkers/rdac.c +1 -1
@@ -133,7 +133,7 @@ out:return 0 ; } -void libcheck_free (struct checker * c) +void libcheck_free (__attribute__((unused))struct checker *c) {return ; }
libmultipath/checkers/readsector0.c +2 -2
@@ -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 ; }
Signature · 1 line
2.23.0
PATCH 29/72 multipathd: stop_waiter_thread(): removed unused parameter
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- multipathd/main.c | 4 ++-- multipathd/waiter.c | 2 +- multipathd/waiter.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
multipathd/main.c +2 -2
@@ -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 ();
multipathd/waiter.c +1 -1
@@ -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;
multipathd/waiter.h +1 -1
@@ -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 */
Signature · 1 line
2.23.0
PATCH 30/72 multipath tools: mark unused arguments in thread routines
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- libmultipath/log_pthread.c | 2 +- multipathd/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
libmultipath/log_pthread.c +1 -1
@@ -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;
multipathd/main.c +1 -1
@@ -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;
Signature · 1 line
2.23.0
PATCH 31/72 kpartx: gpt: remove unused arg in read_lastoddsector()
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- kpartx/gpt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kpartx/gpt.c +2 -2
@@ -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; }
Signature · 1 line
2.23.0
PATCH 32/72 kpartx: mark unused arguments in ptreader methods
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- kpartx/dasd.c | 3 ++- kpartx/gpt.c | 3 ++- kpartx/mac.c | 3 ++- kpartx/ps3.c | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-)
kpartx/dasd.c +2 -1
@@ -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;
kpartx/gpt.c +2 -1
@@ -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 ;
kpartx/mac.c +2 -1
@@ -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;
kpartx/ps3.c +2 -1
@@ -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;
Signature · 1 line
2.23.0
PATCH 33/72 libmultipath: mark missing arguments in functions matching prototypes
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- 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(-)
libmultipath/dm-generic.c +4 -2
@@ -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);
libmultipath/foreign/nvme.c +13 -7
@@ -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);
libmultipath/generic.c +1 -1
@@ -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 ];
libmultipath/print.c +4 -2
@@ -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" ,"--" ); }
Signature · 1 line
2.23.0
PATCH 34/72 libmultipath: get_pgpolicy_name(): use "len" parameter
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- libmultipath/pgpolicies.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libmultipath/pgpolicies.c +1 -1
@@ -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); }
Signature · 1 line
2.23.0
PATCH 35/72 libmultipath: snprint_multipath_map_json(): remove unused argument
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- libmultipath/print.c | 4 ++-- libmultipath/print.h | 2 +- multipathd/cli_handlers.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
libmultipath/print.c +2 -2
@@ -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);
libmultipath/print.h +1 -1
@@ -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 *);
multipathd/cli_handlers.c +1 -1
@@ -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);
Signature · 1 line
2.23.0
PATCH 36/72 multipath: delegate_to_multipathd: mark unused arguments
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
... for now.
--- multipath/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
multipath/main.c +4 -2
@@ -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 ;
Signature · 1 line
2.23.0
PATCH 37/72 libmultipath: use -Wno-unused-parameter for dict.c
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
This file contains just too many "handler" and "snprintf" methods which don't use every argument.
--- libmultipath/Makefile | 5 +++++ 1 file changed, 5 insertions(+)
libmultipath/Makefile +5 -0
@@ -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
Signature · 1 line
2.23.0
PATCH 38/72 multipathd: use -Wno-unused-parameter for cli_handlers.c
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
This file contains many handlers that don't use all their arguments.
--- multipathd/Makefile | 3 +++ 1 file changed, 3 insertions(+)
multipathd/Makefile +3 -0
@@ -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)
Signature · 1 line
2.23.0
PATCH 39/72 libmpathpersist: remove unused "noisy" argument in various functions
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- libmpathpersist/mpath_pr_ioctl.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-)
libmpathpersist/mpath_pr_ioctl.c +12 -14
@@ -23,10 +23,8 @@#define MAXRETRY 5int 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 noireturn ; } -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);
Signature · 1 line
2.23.0
PATCH 40/72 libmpathpersist: fix copy-paste error in mpath_format_readresv()
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
This would swap bytes for the wrong field.
--- libmpathpersist/mpath_pr_ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
libmpathpersist/mpath_pr_ioctl.c +2 -2
@@ -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 ; }
Signature · 1 line
2.23.0
PATCH 41/72 multipath-tools tests: add -Wno-unused-parameter
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
Too many unused "void **state" parameters unders tests.
--- tests/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tests/Makefile +2 -1
@@ -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:
Signature · 1 line
2.23.0
Re: [PATCH 41/72] multipath-tools tests: add -Wno-unused-parameter
tests/Makefile dep_clean: · line 62
Quoted 9 lines · Martin Wilck
TESTS := uevent parser util dmevents hwtable blacklist unaligned vpd pgpolicy alias
tests/Makefile +1
-0@@ -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.
PATCH 42/72 multipath-tools: Makefile.inc: remove -Wno-unused-parameter
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
All warnings have been eliminated now.
--- Makefile.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile.inc +1 -1
@@ -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
Signature · 1 line
2.23.0
PATCH 43/72 libmultipath: dev_loss_tmo is unsigned
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
Make MAX_DEV_LOSS_TMO reflect the fact that the kernel supports timeouts up to UINT_MAX, and fix comparisons in discovery.c.
--- libmultipath/defaults.h | 4 +++- libmultipath/discovery.c | 13 ++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-)
libmultipath/defaults.h +3 -1
@@ -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"
libmultipath/discovery.c +8 -5
@@ -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 ;
Signature · 1 line
2.23.0
PATCH 44/72 libmultipath: trivial changes for -Wsign-compare
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
All these are obious fixes.
--- 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(-)
libmultipath/alias.c +1 -1
@@ -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 */
libmultipath/devmapper.c +2 -1
@@ -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);
libmultipath/discovery.c +10 -7
@@ -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;
libmultipath/file.c +2 -1
@@ -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,
libmultipath/foreign.c +1 -1
@@ -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;
libmultipath/parser.c +1 -1
@@ -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 ;
libmultipath/prioritizers/alua_rtpg.c +1 -1
@@ -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;
libmultipath/prioritizers/ana.c +4 -3
@@ -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);
libmultipath/structs.c +2 -2
@@ -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)
libmultipath/structs.h +2 -1
@@ -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);
libmultipath/sysfs.c +3 -3
@@ -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 ;
libmultipath/time-util.c +3 -3
@@ -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++; } }
libmultipath/uevent.c +2 -1
@@ -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 )
libmultipath/util.c +2 -2
@@ -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;
libmultipath/util.h +3 -1
@@ -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]))
libmultipath/uxsock.c +2 -1
@@ -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
libmultipath/wwids.c +2 -2
@@ -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 */
multipathd/main.c +4 -2
@@ -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;
multipathd/pidfile.c +1 -1
@@ -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;
Signature · 1 line
2.23.0
PATCH 45/72 libmultipath: fix -Wsign-compare warnings with snprintf()
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
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.
--- 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(-)
kpartx/devmapper.c +2 -1
@@ -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 ;
kpartx/kpartx.h +1 -1
@@ -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 */
libmultipath/foreign/nvme.c +2 -2
@@ -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,
libmultipath/sysfs.c +2 -2
@@ -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 );
libmultipath/util.c +2 -1
@@ -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 ;
libmultipath/util.h +2 -2
@@ -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))
libmultipath/wwids.c +1 -1
@@ -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 ; }
multipath/main.c +1 -1
@@ -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 ; }
Signature · 1 line
2.23.0
Re: [PATCH 45/72] libmultipath: fix -Wsign-compare warnings with snprintf()
kpartx/devmapper.c strip_slash (char * device) · line 112
Quoted 4 lines · Martin Wilck
kpartx/devmapper.c +2
-1-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.
Re: [PATCH 45/72] libmultipath: fix -Wsign-compare warnings with snprintf()
Hello Bart,
Quoted 10 lines · Bart Van Assche
kpartx/devmapper.c strip_slash (char * device) · line 112
Quoted 5 lines · Martin Wilck
(quoted diff) +0
-1- if (snprintf(buf, bufsiz, "%s%s%d", mapname, delim, part) >=bufsiz)
kpartx/devmapper.c +2
-0+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
Re: [PATCH 45/72] libmultipath: fix -Wsign-compare warnings with snprintf()
Quoted 21 lines · Martin Wilck
Hello Bart,
Quoted 10 lines · Bart Van Assche
kpartx/devmapper.c strip_slash (char * device) · line 112
Quoted 5 lines · Martin Wilck
(quoted diff) +0
-1- if (snprintf(buf, bufsiz, "%s%s%d", mapname, delim, part) >=bufsiz)
kpartx/devmapper.c +2
-0+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?
Quoted 8 lines
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.
Re: [PATCH 45/72] libmultipath: fix -Wsign-compare warnings with snprintf()
Quoted 14 lines · Bart Van Assche
Quoted 8 lines · Martin Wilck
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.Quoted 4 lines
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?
Quoted 6 lines
Hi Martin,
Have you considered to use
asprintf()instead ofsnprintf()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
Re: [PATCH 45/72] libmultipath: fix -Wsign-compare warnings with snprintf()
Quoted 6 lines · Martin Wilck
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.
Re: [PATCH 45/72] libmultipath: fix -Wsign-compare warnings with snprintf()
Hello Bart,
Quoted 2 lines · Bart Van Assche
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
PATCH 46/72 libmultipath: parse_vpd_pg83(): sanitize indentation
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
This just moves a lot of code to the left. No functional change.
--- libmultipath/discovery.c | 174 ++++++++++++++++++++------------------- 1 file changed, 88 insertions(+), 86 deletions(-)
libmultipath/discovery.c +88 -86
@@ -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;
Signature · 1 line
2.23.0
PATCH 47/72 libmultipath: parse_vpd_pg83(): fix -Wsign-compare warnings
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
Most of this is trivial. Changes are: return early if there is obviously not enough space. Check vpd_len for designator type 8.
--- libmultipath/discovery.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)
libmultipath/discovery.c +16 -9
@@ -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 ; }
Signature · 1 line
2.23.0
PATCH 48/72 libmultipath: print: use unsigned int for "width" field
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- libmultipath/print.c | 4 ++-- libmultipath/print.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-)
libmultipath/print.c +2 -2
@@ -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 :
libmultipath/print.h +3 -3
@@ -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); };
Signature · 1 line
2.23.0
PATCH 49/72 libmultipath: vector_for_each_slot: fix -Wsign-compare warnings
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- libmultipath/vector.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
libmultipath/vector.h +2 -2
@@ -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--)
Signature · 1 line
2.23.0
PATCH 50/72 libmultipath: set_int(): add error check and set_uint()
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
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.
--- libmultipath/dict.c | 48 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-)
libmultipath/dict.c +45 -3
@@ -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
Signature · 1 line
2.23.0
PATCH 51/72 libmultipath: make "checkint" unsigned
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
path->checkint was unsigned already, now use this type everywhere.
--- 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(-)
libmultipath/config.h +2 -2
@@ -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;
libmultipath/dict.c +2 -2
@@ -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)
libmultipath/discovery.c +1 -1
@@ -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;
libmultipath/discovery.h +1 -1
@@ -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);
libmultipath/io_err_stat.c +1 -1
@@ -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;
libmultipath/structs_vec.c +1 -1
@@ -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);
multipathd/main.c +6 -4
@@ -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) {
Signature · 1 line
2.23.0
PATCH 52/72 libmultipath: use unsigned blksize in directio context
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- libmultipath/checkers/directio.c | 2 +- libmultipath/io_err_stat.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
libmultipath/checkers/directio.c +1 -1
@@ -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;
libmultipath/io_err_stat.c +2 -2
@@ -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 )
Signature · 1 line
2.23.0
PATCH 53/72 libmultipath, kpartx: byteorder: always use unsigned types
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
The swapped results are unsigned, so the non-swapped ones should be unsigned, too.
--- kpartx/gpt.c | 6 +++--- libmultipath/byteorder.h | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-)
kpartx/gpt.c +3 -3
@@ -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)
libmultipath/byteorder.h +6 -6
@@ -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
Signature · 1 line
2.23.0
PATCH 54/72 libmpathcmd: fix -Wsign-compare warnings
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- libmpathcmd/mpath_cmd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
libmpathcmd/mpath_cmd.c +3 -2
@@ -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 ; }
Signature · 1 line
2.23.0
PATCH 55/72 libmpathpersist: fix -Wsign-compare warnings
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- libmpathpersist/mpath_persist.c | 3 ++- libmpathpersist/mpath_pr_ioctl.c | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-)
libmpathpersist/mpath_persist.c +2 -1
@@ -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)) {
libmpathpersist/mpath_pr_ioctl.c +5 -5
@@ -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 );
Signature · 1 line
2.23.0
PATCH 56/72 kpartx: use unsigned arguments in dm_devn() and dm_prereq()
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
In both cases, the corresponding libdevmapper values are unsigned.
--- kpartx/devmapper.c | 10 +++++----- kpartx/devmapper.h | 7 ++++--- kpartx/kpartx.h | 7 ++++--- 3 files changed, 13 insertions(+), 11 deletions(-)
kpartx/devmapper.c +5 -5
@@ -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;
kpartx/devmapper.h +4 -3
@@ -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 */
kpartx/kpartx.h +4 -3
@@ -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;
Signature · 1 line
2.23.0
PATCH 57/72 kpartx: use unsigned int for "ns" argument of ptreader
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
ns, the number of slices, should be positive.
--- 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(-)
kpartx/bsd.c +2 -2
@@ -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 )
kpartx/dasd.c +1 -1
@@ -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;
kpartx/dos.c +2 -2
@@ -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 ;
kpartx/gpt.c +2 -2
@@ -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 ;
kpartx/gpt.h +1 -1
@@ -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
kpartx/kpartx.h +2 -2
@@ -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 ); }
kpartx/mac.c +2 -2
@@ -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 );
kpartx/ps3.c +2 -2
@@ -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;
kpartx/solaris.c +2 -2
@@ -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 */
kpartx/sun.c +2 -2
@@ -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);
kpartx/unixware.c +2 -2
@@ -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 )
Signature · 1 line
2.23.0
PATCH 58/72 multipath-tools: Makefile.inc: enable -Wsign-compare
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
With the previous patches, there are no signedness warnings any more.
--- Makefile.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile.inc +1 -1
@@ -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
Signature · 1 line
2.23.0
PATCH 59/72 libdmmp: fix clang -Wformat-nonliteral warnings
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
clang enables -Wformat-nonliteral with our compiler flags, and thus needs these format(printf, ...) attributes.
--- libdmmp/libdmmp_private.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
libdmmp/libdmmp_private.h +5 -3
@@ -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 )
Signature · 1 line
2.23.0
PATCH 60/72 libmultipath: fix clang -Wformat-literal warnings
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- libmultipath/devmapper.c | 2 +- libmultipath/log.h | 3 ++- libmultipath/log_pthread.h | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-)
libmultipath/devmapper.c +1 -1
@@ -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;
libmultipath/log.h +2 -1
@@ -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 *);
libmultipath/log_pthread.h +2 -1
@@ -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 );
Signature · 1 line
2.23.0
PATCH 61/72 multipath tests: blacklist: remove always-true condition
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
clang warns about this (udev_device->property_list can't be NULL).
--- tests/blacklist.c | 2 -- 1 file changed, 2 deletions(-)
tests/blacklist.c +0 -2
@@ -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;
Signature · 1 line
2.23.0
PATCH 62/72 multipath tests: hwtable: fix strncat() invocation
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
clang detected this error.
--- tests/hwtable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/hwtable.c +1 -1
@@ -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);
Signature · 1 line
2.23.0
PATCH 63/72 multipath tests: fix -Wformat-literal warning
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- tests/test-log.c | 1 + 1 file changed, 1 insertion(+)
tests/test-log.c +1 -0
@@ -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 ];
Signature · 1 line
2.23.0
PATCH 64/72 multipath tests: util: fix clang strlcpy warnings
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
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.
--- tests/util.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
tests/util.c +9 -7
@@ -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); }
Signature · 1 line
2.23.0
PATCH 65/72 libmultipath: nvme: update to nvme-cli v1.9
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
Update nvme code to nvme-cli v1.9 (977e7d4, Thu Aug 15 2019).
--- 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(-)
libmultipath/nvme/linux/nvme.h +107 -29
@@ -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, };
libmultipath/nvme/nvme-ioctl.c +144 -85
324 lines not on this page · raw message
libmultipath/nvme/nvme-ioctl.h +25 -6
@@ -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 */
libmultipath/nvme/nvme.h +99 -22
163 lines not on this page · raw message
Signature · 7 lines
2.23.0 -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
PATCH 66/72 multipath-tools: Makefile.inc: fix TEST_CC_OPTION
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
The test works only if the compiler actually errors out for an unsupported warning option, which requires setting -Werror.
--- Makefile.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Makefile.inc +2 -1
@@ -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 \
Signature · 1 line
2.23.0
PATCH 67/72 multipath-tools: Makefile.inc: use -Wp, ... for compiling only
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
clang-3.9 errors out if -Wp,... preprocessor flags are used in the linking stage.
--- Makefile.inc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
Makefile.inc +3 -4
@@ -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 $@ $<
Signature · 1 line
2.23.0
Benjamin Marzinski
maintainerRe: [PATCH 67/72] multipath-tools: Makefile.inc: use -Wp, ... for compiling only
Quoted 15 lines · Martin Wilck
From: Martin Wilck <[email protected]>
clang-3.9 errors out if -Wp,... preprocessor flags are used in the linking stage.
Signed-off-by Martin Wilck <[email protected]>--- Makefile.inc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)Makefile.inc +0
-0
Makefile.inc OPTFLAGS = -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int \ · line 100
Quoted 8 lines
Makefile.inc +2
-3@@ -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
Quoted 11 lines
Makefile.inc +1
-1CFLAGS := $(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 $@ $<Signature · 1 line
2.23.0
PATCH 68/72 multipath-tools: Makefile: use proper directory recursion
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
"make -k" didn't work with the Makefile's subdirectory handling. Do it the proper "make" way.
--- Makefile | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-)
Makefile +18 -20
@@ -2,7 +2,7 @@ # Copyright (C) 2003 Christophe Varoqui, <[email protected]> # -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
Signature · 1 line
2.23.0
PATCH 69/72 multipath tests: Makefile: fix "clean" target
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- tests/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/Makefile +1 -1
@@ -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)
Signature · 1 line
2.23.0
PATCH 70/72 multipath tests: Makefile: avoid gcc 4.8 missing initializers failure
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
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.
--- tests/Makefile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
tests/Makefile +10 -1
@@ -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
Signature · 1 line
2.23.0
PATCH 71/72 multipath-tools: Makefile.inc: enable -Werror
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
--- Makefile.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile.inc +1 -1
@@ -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) \
Signature · 1 line
2.23.0
PATCH 72/72 multipath-tools: Makefile.inc: test for -Wno-clobbered support
In reply to Martin WilckFrom: Martin Wilck <[email protected]>
clang doesn't support this option.
--- Makefile.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Makefile.inc +2 -1
@@ -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
Signature · 1 line
2.23.0