multipath-tools/.git
2 months agolibmultipath: fix compilation with -fno-common
Martin Wilck [Thu, 16 Jan 2020 21:55:14 +0000 (22:55 +0100)]
libmultipath: fix compilation with -fno-common

This never-used variable must be declared extern in order to avoid
a link stage error with -fno-common.

2 months agolibmultipath: fix ALUA autodetection when paths are down
Martin Wilck [Fri, 15 Nov 2019 14:41:54 +0000 (14:41 +0000)]
libmultipath: fix ALUA autodetection when paths are down

If a single path was offline when detect_alua() was called,
multipathd would assume ALUA was generally unsupported.

Fix that by assuming that if at least one path has ALUA support and
no path explicitly does not have it, ALUA is supported.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: fix (max_)polling_interval setting logic
Martin Wilck [Fri, 15 Nov 2019 14:41:52 +0000 (14:41 +0000)]
libmultipath: fix (max_)polling_interval setting logic

checkint should never be larger than max_checkint. The WATCHDOG_USEC
setting should be honored on "reconfigure", too, not only on startup.
Pathological values for checkint and integer overflows should be avoided.
The logic should work reasonably well if both polling_interval and
max_polling_interval, just one of them, or neither is set.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: drop mpp->nr_active field
Martin Wilck [Fri, 15 Nov 2019 14:41:50 +0000 (14:41 +0000)]
libmultipath: drop mpp->nr_active field

The tracking of nr_active has turned out to be error prone and hard
to verify. Calculating it on the fly is a quick operation, so
do this rather than trying to track nr_active. Use a boolean
field instead to track whether a map is currently in recovery mode.

Moreover, clean up the recovery logic by making set_no_path_retry()
the place that checks the current configuration and state, sets
"queue_if_no_path" if necessary, and enters or leaves recovery
mode if necessary. This ensures that consistent logic is applied.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: dict.c: rename duplicate set_no_path_retry()
Martin Wilck [Fri, 15 Nov 2019 14:41:48 +0000 (14:41 +0000)]
libmultipath: dict.c: rename duplicate set_no_path_retry()

We have two functions called set_no_path_retry(). Fix that by
renaming the function in dict.c to no_path_retry_helper().

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipathd: move set_no_path_retry() back to libmultipath
Martin Wilck [Fri, 15 Nov 2019 14:41:46 +0000 (14:41 +0000)]
multipathd: move set_no_path_retry() back to libmultipath

This function is useful elsewhere, too. No code changes except
for changing the linkage.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agoALUA support for PURE FlashArray
Brian Bunker [Mon, 2 Mar 2020 14:53:54 +0000 (15:53 +0100)]
ALUA support for PURE FlashArray

Hello all,

It has been some time since we updated our PURE FlashArray
configuration. The Linux vendors that we had been seeing in the field
were using very old versions of multipath-tools, so we haven’t needed to
change anything for some time. With the release of RHEL8, some of our
earlier values have been lost by upstream changes.

In addition we have our Active Cluster feature which leverages ALUA
since our last patch. The ALUA confguration will work for all
FlashArrays with or without Active Cluster.

We are changing 3 things.

1. ALUA support
2. Fast fail timeout from the default of 5 seconds to 10 seconds (We
   need this for our FC NPIV port migration).
3. Maximum sector size of 4MB. Some Linux vendors don’t honor the block
   limits VPD page of INQUIRY).

Thanks,
Brian

Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: DM-DEVEL ML <dm-devel@redhat.com>
Signed-off-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
Signed-off-by: Brian Bunker <brian@purestorage.com>
2 months agolibmultipath: nvme: update to nvme-cli v1.9
Martin Wilck [Sat, 12 Oct 2019 21:28:58 +0000 (21:28 +0000)]
libmultipath: nvme: update to nvme-cli v1.9

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipath-tools: Makefile.inc: fix TEST_CC_OPTION
Martin Wilck [Sat, 12 Oct 2019 21:28:59 +0000 (21:28 +0000)]
multipath-tools: Makefile.inc: fix TEST_CC_OPTION

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: cleanup old issues with directio checker
Benjamin Marzinski [Wed, 19 Feb 2020 20:21:45 +0000 (14:21 -0600)]
libmultipath: cleanup old issues with directio checker

The directio checker manually aligns its directio buffer, instead of
using posix_memalign(). It also defaults the block size for the read to
512, which may be too small for 4k devices, and it only waits for 5 ns
for IO completion before giving up and setting the path to pending,
which means that in will virtually always set the path to pending on the
check when the IO is issued.

Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agolibmultipath: change directio get_events() timeout handling
Benjamin Marzinski [Wed, 19 Feb 2020 20:21:44 +0000 (14:21 -0600)]
libmultipath: change directio get_events() timeout handling

get_events() used a NULL or a zeroed timeout to mean "don't wait".
io_getevents() uses a NULL timeout to mean "wait forever" and a
zeroed timeout to mean "don't wait". Make get_events() work like
io_getevents().

Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agolibmultipath: change loading and resetting in directio
Benjamin Marzinski [Wed, 19 Feb 2020 20:21:43 +0000 (14:21 -0600)]
libmultipath: change loading and resetting in directio

The directio checker previously made sure to always keep an aio_group
around after loading or resetting the checker. There is no need to do
this, and removing this code simplifies the checker.  With this change,
there is no longer a need for a load or unload checker function, only a
reset function which is run when the checker is reset or unloaded.
Changing this broke a number of tests, so the unit tests have been
updated as well.

Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agotests: make directio tests able to work on a real device
Benjamin Marzinski [Wed, 19 Feb 2020 06:48:40 +0000 (00:48 -0600)]
tests: make directio tests able to work on a real device

There is now a file in tests called directio_test_dev. If the commented
out test device line is uncommented and set to a device, it can be used
to test the directio checker on that device, instead of faking the
device.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agofixup! libmultipath: make directio checker share io contexts
Martin Wilck [Wed, 19 Feb 2020 06:48:39 +0000 (00:48 -0600)]
fixup! libmultipath: make directio checker share io contexts

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agolibmultipath: make directio checker share io contexts
Benjamin Marzinski [Wed, 19 Feb 2020 06:48:36 +0000 (00:48 -0600)]
libmultipath: make directio checker share io contexts

On systems with a large number of cores (>500), io_destroy() can take
tens to hundreds of milliseconds to complete, due to RCU
synchronization. If there are a large number of paths using the directio
checker on such a system, this can lead to multipath taking almost a
minute to complete, with the vast majority of time taken up by
io_destroy().

To solve this, the directio checker now allocates one aio context for
every 1024 checkers. This reduces the io_destroy() delay to a thousandth
of its previous level. However, this means that muliple checkers are
sharing the same aio context, and must be able to handle getting results
for other checkers.  Because only one checker is ever running at a
time, this doesn't require any locking.  However, locking could be added
in the future if necessary, to allow multiple checkers to run at the
same time.

When checkers are freed, they usually no longer destroy the io context.
Instead, they attempt to cancel any outstanding request. If that fails,
they put the request on an orphan list, so that it can be freed by other
checkers, once it has completed. IO contexts are only destroyed at three
times, during reconfigure (to deal with the possibility that multipathd
is holding more aio events than it needs to be, since there is a single
limit for the whole system), when the checker class is unloaded, and
in a corner case when checkers are freed. If an aio_group (which
contains the aio context) is entirely full of orphaned requests, then
no checker can use it. Since no checker is using it, there is no checker
to clear out the orphaned requests. In this (likely rare) case, the
last checker from that group to be freed and leave behind an orphaned
request will call io_destroy() and remove the group.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agolibmultipath: turn pp->vpd_data into a pointer
Benjamin Marzinski [Wed, 19 Feb 2020 20:21:42 +0000 (14:21 -0600)]
libmultipath: turn pp->vpd_data into a pointer

Instead of always allocating space in the path structure for vpd_data,
only allocte it when necessary.

Also, fix comments on vpd tests

Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agofixup! libmultipath: add code to get vendor specific vpd data
Martin Wilck [Wed, 19 Feb 2020 06:48:38 +0000 (00:48 -0600)]
fixup! libmultipath: add code to get vendor specific vpd data

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agomultipath: fix issues found by compiling with gcc 10
Benjamin Marzinski [Wed, 19 Feb 2020 20:21:41 +0000 (14:21 -0600)]
multipath: fix issues found by compiling with gcc 10

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agolibmultipath: fix -Wsign-compare warnings with snprintf()
Martin Wilck [Thu, 7 Nov 2019 09:27:41 +0000 (09:27 +0000)]
libmultipath: fix -Wsign-compare warnings with snprintf()

snprintf() returns int, but the size argument "n" is size_t.
Use safe_snprintf() to avoid -Wsign-compare warnings. At the same
time, improve these macros to check for errors in snprintf(), too.

Note: there are more uses of snprintf() in our code that may
need review, too. For now, I'm fixing only those that were causing
warnings.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agotests: add directio unit tests
Benjamin Marzinski [Wed, 19 Feb 2020 06:48:37 +0000 (00:48 -0600)]
tests: add directio unit tests

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agolibmultipath: add new checker class functions
Benjamin Marzinski [Wed, 19 Feb 2020 06:48:35 +0000 (00:48 -0600)]
libmultipath: add new checker class functions

This commit adds the optional functions libcheck_load, libcheck_unload,
and libcheck_reset. libcheck_load is called when a checker is first
loaded, libcheck_unload is called when it is unloaded, and
libcheck_reset is called during reconfigure, after all the current
paths have been removed. They are designed to setup, reset, and destroy
global state that all checkers of this class use. They will be used
in future commits.

Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agomultipathd: add new paths under vecs lock
Benjamin Marzinski [Wed, 19 Feb 2020 06:48:34 +0000 (00:48 -0600)]
multipathd: add new paths under vecs lock

Right now, multipathd only ever calls pathinfo on a path outside of the
vecs lock in one circumstance, when it's adding a new path from a
uevent. Doing this can cause weirdness or crash multipathd.

First off, the path checker code is written assuming that only one
checker instance will be active at a time.  If this isn't the case, two
processes can modify the checker's refcounts at the same time,
potentially causing a checker to get removed while still in use (if two
threads try to increment the refcount at the same time, causing it to
only increment once).

Another issue is that since the vecs lock isn't grabbed until after all
of the pathinfo is gathered, and the vecs lock is the only thing keeping
the uevent servicing thread from running at the same time as a
reconfigure is happening, it is possible to have multipathd add a path
using the old config after reconfigure has already added that path using
the new config. Leading to two versions of the path on the pathvec.
There are possibly other issues with running pathinfo outside of the
vecs lock that I haven't noticed, as well.

The easiest solution is to call pathinfo on the path while holding the
vecs lock, to keep other threads from modifying the checker structure or
the config while setting up the path. This is what happens every other
time multipathd calls pathinfo, including when a path is added through
the multipathd command interface.

This does mean that any time spent calling pathinfo on new paths will
block other threads that need the vecs lock, but since the checker is
now always called in async mode, and the prio function will use a
short timeout if called on a failed path, this shouldn't be any more
noticeable than the calls to check_path() for already existing paths.

Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agolibmultipath: change failed path prio timeout
Benjamin Marzinski [Wed, 19 Feb 2020 06:48:33 +0000 (00:48 -0600)]
libmultipath: change failed path prio timeout

multipath will try to get the priority from a PATH_DOWN path, if the
path doesn't currently have a valid priority. However, if the priority
code needs to contact the device to get the priority, this is likely to
fail for PATH_DOWN paths.  This code dates back to when multipathd could
not easily reload device tables with failed paths, so getting the
correct priority was important to have a correctly configured device.
Now multipathd can simply reload the device to move the path to the
correct pathgroup when the path comes back up.  Since there are a number
of prioritizers that don't require talking to the device, multipath
shouldn't completely skip attempting to get the priority of these paths,
but it should set a small timeout, so that it isn't hanging in the
case where it needs to contact a device through a failed path.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agolibmultipath: change how the checker async is set
Benjamin Marzinski [Wed, 19 Feb 2020 06:48:32 +0000 (00:48 -0600)]
libmultipath: change how the checker async is set

The way that the checkers async mode worked in multipathd didn't make
much sense. When multipathd starts up, all checker classes are in the
sync mode, and any pathinfo() calls on devices would run the checker in
sync mode. However, the First time a checker class was used in
checkerloop, it would set that checker class to async (assuming
force_sync wasn't set).  After that, no matter when a checker from that
class was called, it would always run in async mode.  Multipathd doesn't
need to run checkers in sync mode at all, so don't.

Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agolibmultipath: add code to get vendor specific vpd data
Benjamin Marzinski [Wed, 19 Feb 2020 06:48:31 +0000 (00:48 -0600)]
libmultipath: add code to get vendor specific vpd data

This adds the wildcard 'g' for multipath and path formatted printing,
which returns extra data from a device's vendor specific vpd page.  The
specific vendor vpd page to use, and the vendor/product id to decode it
can be set in the hwentry with vpd_vendor_pg and vpd_vendor_id. It can
be configured in the devices section of multipath.conf with the
vpd_vendor parameter. Currently, the only devices that use this are HPE
3PAR arrays, to return the Volume Name.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agolibmultipath: add vend_id to get_vpd_sgio
Benjamin Marzinski [Wed, 19 Feb 2020 06:48:30 +0000 (00:48 -0600)]
libmultipath: add vend_id to get_vpd_sgio

This tells multipath how it should decode vendor specific pages. It will
be used by a future patch.

Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agolibmultipath: fix sgio_get_vpd looping
Benjamin Marzinski [Wed, 19 Feb 2020 06:48:29 +0000 (00:48 -0600)]
libmultipath: fix sgio_get_vpd looping

If do_inq returns a page with a length that is less than maxlen, but
larger than DEFAULT_SGIO_LEN, this function will loop forever. Also
if do_inq returns with a length equal to or greater than maxlen,
sgio_get_vpd will exit immediately, even if it hasn't read the entire
page.  Fix these issues, modify the tests to verify the new behavior.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agolibmultipath: add missing hwe mpe variable merges
Benjamin Marzinski [Wed, 19 Feb 2020 06:48:28 +0000 (00:48 -0600)]
libmultipath: add missing hwe mpe variable merges

There were some variables in the hwe and mpe structs that weren't being
merged by merge_hwe() and merge_mpe().

Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agolibmultipath: constify get_unaligned_be*
Benjamin Marzinski [Wed, 19 Feb 2020 06:48:27 +0000 (00:48 -0600)]
libmultipath: constify get_unaligned_be*

Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agolibmultipath: remove unused path->prio_args
Benjamin Marzinski [Wed, 19 Feb 2020 06:48:26 +0000 (00:48 -0600)]
libmultipath: remove unused path->prio_args

Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agoFix leak in mpathpersist
Benjamin Marzinski [Wed, 19 Feb 2020 06:48:25 +0000 (00:48 -0600)]
Fix leak in mpathpersist

If the persistent in command fails, the response buffer must be freed.
Found by Coverity

Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agomultipathd: staticify uxlsnr variables/functions
Benjamin Marzinski [Wed, 19 Feb 2020 06:48:24 +0000 (00:48 -0600)]
multipathd: staticify uxlsnr variables/functions

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agomultipathd: warn when configuration has been changed.
Benjamin Marzinski [Wed, 19 Feb 2020 06:48:23 +0000 (00:48 -0600)]
multipathd: warn when configuration has been changed.

It would be helpful if multipathd could log a message when
multipath.conf or files in the config_dir have been written to, both so
that it can be used to send a notification to users, and to help with
determining after the fact if multipathd was running with an older
config, when the logs of multipathd's behaviour don't match with the
current multipath.conf.

To do this, the multipathd uxlsnr thread now sets up inotify watches on
both /etc/multipath.conf and the config_dir to watch if the files are
deleted or closed after being opened for writing.  In order to keep
uxlsnr from polling repeatedly if the multipath.conf or the config_dir
aren't present, it will only set up the watches once per reconfigure.
However, since multipath.conf is far more likely to be replaced by a
text editor than modified in place, if it gets removed, multipathd will
immediately try to restart the watch on it (which will succeed if the
file was simply replaced by a new copy).  This does mean that if
multipath.conf or the config_dir are actually removed and then later
re-added, multipathd won't log any more messages for changes until the
next reconfigure. But that seems like a fair trade-off to avoid
repeatedly polling for files that aren't likely to appear.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agomultipath-tools: Makefile.inc: test for -Wno-clobbered support
Martin Wilck [Sat, 12 Oct 2019 21:29:07 +0000 (21:29 +0000)]
multipath-tools: Makefile.inc: test for -Wno-clobbered support

clang doesn't support this option.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipath-tools: Makefile.inc: enable -Werror
Martin Wilck [Sat, 12 Oct 2019 21:29:06 +0000 (21:29 +0000)]
multipath-tools: Makefile.inc: enable -Werror

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipath tests: Makefile: avoid gcc 4.8 missing initializers failure
Martin Wilck [Sat, 12 Oct 2019 21:29:04 +0000 (21:29 +0000)]
multipath tests: Makefile: avoid gcc 4.8 missing initializers failure

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

struct A {
       int a, b;
};

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

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipath tests: Makefile: fix "clean" target
Martin Wilck [Sat, 12 Oct 2019 21:29:03 +0000 (21:29 +0000)]
multipath tests: Makefile: fix "clean" target

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipath-tools: Makefile: use proper directory recursion
Martin Wilck [Sat, 12 Oct 2019 21:29:02 +0000 (21:29 +0000)]
multipath-tools: Makefile: use proper directory recursion

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipath-tools: Makefile.inc: use -Wp,... for compiling only
Martin Wilck [Sat, 12 Oct 2019 21:29:01 +0000 (21:29 +0000)]
multipath-tools: Makefile.inc: use -Wp,... for compiling only

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipath tests: util: fix clang strlcpy warnings
Martin Wilck [Sat, 12 Oct 2019 21:28:57 +0000 (21:28 +0000)]
multipath tests: util: fix clang strlcpy warnings

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipath tests: fix -Wformat-literal warning
Martin Wilck [Sat, 12 Oct 2019 21:28:56 +0000 (21:28 +0000)]
multipath tests: fix -Wformat-literal warning

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipath tests: hwtable: fix strncat() invocation
Martin Wilck [Sat, 12 Oct 2019 21:28:54 +0000 (21:28 +0000)]
multipath tests: hwtable: fix strncat() invocation

clang detected this error.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipath tests: blacklist: remove always-true condition
Martin Wilck [Sat, 12 Oct 2019 21:28:53 +0000 (21:28 +0000)]
multipath tests: blacklist: remove always-true condition

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: fix clang -Wformat-literal warnings
Martin Wilck [Sat, 12 Oct 2019 21:28:52 +0000 (21:28 +0000)]
libmultipath: fix clang -Wformat-literal warnings

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibdmmp: fix clang -Wformat-nonliteral warnings
Martin Wilck [Sat, 12 Oct 2019 21:28:50 +0000 (21:28 +0000)]
libdmmp: fix clang -Wformat-nonliteral warnings

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipath-tools: Makefile.inc: enable -Wsign-compare
Martin Wilck [Sat, 12 Oct 2019 21:28:49 +0000 (21:28 +0000)]
multipath-tools: Makefile.inc: enable -Wsign-compare

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agokpartx: use unsigned int for "ns" argument of ptreader
Martin Wilck [Sat, 12 Oct 2019 21:28:48 +0000 (21:28 +0000)]
kpartx: use unsigned int for "ns" argument of ptreader

ns, the number of slices, should be positive.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agokpartx: use unsigned arguments in dm_devn() and dm_prereq()
Martin Wilck [Sat, 12 Oct 2019 21:28:46 +0000 (21:28 +0000)]
kpartx: use unsigned arguments in dm_devn() and dm_prereq()

In both cases, the corresponding libdevmapper values are unsigned.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmpathpersist: fix -Wsign-compare warnings
Martin Wilck [Sat, 12 Oct 2019 21:28:45 +0000 (21:28 +0000)]
libmpathpersist: fix -Wsign-compare warnings

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmpathcmd: fix -Wsign-compare warnings
Martin Wilck [Sat, 12 Oct 2019 21:28:44 +0000 (21:28 +0000)]
libmpathcmd: fix -Wsign-compare warnings

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath, kpartx: byteorder: always use unsigned types
Martin Wilck [Sat, 12 Oct 2019 21:28:42 +0000 (21:28 +0000)]
libmultipath, kpartx: byteorder: always use unsigned types

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: use unsigned blksize in directio context
Martin Wilck [Sat, 12 Oct 2019 21:28:41 +0000 (21:28 +0000)]
libmultipath: use unsigned blksize in directio context

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: make "checkint" unsigned
Martin Wilck [Sat, 12 Oct 2019 21:28:40 +0000 (21:28 +0000)]
libmultipath: make "checkint" unsigned

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: set_int(): add error check and set_uint()
Martin Wilck [Sat, 12 Oct 2019 21:28:39 +0000 (21:28 +0000)]
libmultipath: set_int(): add error check and set_uint()

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: vector_for_each_slot: fix -Wsign-compare warnings
Martin Wilck [Sat, 12 Oct 2019 21:28:38 +0000 (21:28 +0000)]
libmultipath: vector_for_each_slot: fix -Wsign-compare warnings

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: print: use unsigned int for "width" field
Martin Wilck [Sat, 12 Oct 2019 21:28:36 +0000 (21:28 +0000)]
libmultipath: print: use unsigned int for "width" field

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: parse_vpd_pg83(): fix -Wsign-compare warnings
Martin Wilck [Sat, 12 Oct 2019 21:28:35 +0000 (21:28 +0000)]
libmultipath: parse_vpd_pg83(): fix -Wsign-compare warnings

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: parse_vpd_pg83(): sanitize indentation
Martin Wilck [Sat, 12 Oct 2019 21:28:34 +0000 (21:28 +0000)]
libmultipath: parse_vpd_pg83(): sanitize indentation

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: trivial changes for -Wsign-compare
Martin Wilck [Sat, 12 Oct 2019 21:28:32 +0000 (21:28 +0000)]
libmultipath: trivial changes for -Wsign-compare

All these are obious fixes.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: dev_loss_tmo is unsigned
Martin Wilck [Sat, 12 Oct 2019 21:28:31 +0000 (21:28 +0000)]
libmultipath: dev_loss_tmo is unsigned

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

Cc: Hannes Reinecke <hare@suse.de>
Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipath-tools: Makefile.inc: remove -Wno-unused-parameter
Martin Wilck [Sat, 12 Oct 2019 21:28:29 +0000 (21:28 +0000)]
multipath-tools: Makefile.inc: remove -Wno-unused-parameter

All warnings have been eliminated now.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipath-tools tests: add -Wno-unused-parameter
Martin Wilck [Sat, 12 Oct 2019 21:28:28 +0000 (21:28 +0000)]
multipath-tools tests: add -Wno-unused-parameter

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmpathpersist: fix copy-paste error in mpath_format_readresv()
Martin Wilck [Sat, 12 Oct 2019 21:28:27 +0000 (21:28 +0000)]
libmpathpersist: fix copy-paste error in mpath_format_readresv()

This would swap bytes for the wrong field.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmpathpersist: remove unused "noisy" argument in various functions
Martin Wilck [Sat, 12 Oct 2019 21:28:25 +0000 (21:28 +0000)]
libmpathpersist: remove unused "noisy" argument in various functions

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipathd: use -Wno-unused-parameter for cli_handlers.c
Martin Wilck [Sat, 12 Oct 2019 21:28:24 +0000 (21:28 +0000)]
multipathd: use -Wno-unused-parameter for cli_handlers.c

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: use -Wno-unused-parameter for dict.c
Martin Wilck [Sat, 12 Oct 2019 21:28:23 +0000 (21:28 +0000)]
libmultipath: use -Wno-unused-parameter for dict.c

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipath: delegate_to_multipathd: mark unused arguments
Martin Wilck [Sat, 12 Oct 2019 21:28:22 +0000 (21:28 +0000)]
multipath: delegate_to_multipathd: mark unused arguments

... for now.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: snprint_multipath_map_json(): remove unused argument
Martin Wilck [Sat, 12 Oct 2019 21:28:20 +0000 (21:28 +0000)]
libmultipath: snprint_multipath_map_json(): remove unused argument

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: get_pgpolicy_name(): use "len" parameter
Martin Wilck [Sat, 12 Oct 2019 21:28:19 +0000 (21:28 +0000)]
libmultipath: get_pgpolicy_name(): use "len" parameter

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: mark missing arguments in functions matching prototypes
Martin Wilck [Sat, 12 Oct 2019 21:28:18 +0000 (21:28 +0000)]
libmultipath: mark missing arguments in functions matching prototypes

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agokpartx: mark unused arguments in ptreader methods
Martin Wilck [Sat, 12 Oct 2019 21:28:17 +0000 (21:28 +0000)]
kpartx: mark unused arguments in ptreader methods

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agokpartx: gpt: remove unused arg in read_lastoddsector()
Martin Wilck [Sat, 12 Oct 2019 21:28:16 +0000 (21:28 +0000)]
kpartx: gpt: remove unused arg in read_lastoddsector()

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipath tools: mark unused arguments in thread routines
Martin Wilck [Sat, 12 Oct 2019 21:28:14 +0000 (21:28 +0000)]
multipath tools: mark unused arguments in thread routines

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipathd: stop_waiter_thread(): removed unused parameter
Martin Wilck [Sat, 12 Oct 2019 21:28:13 +0000 (21:28 +0000)]
multipathd: stop_waiter_thread(): removed unused parameter

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: checkers: mark unused arguments in methods
Martin Wilck [Sat, 12 Oct 2019 21:28:12 +0000 (21:28 +0000)]
libmultipath: checkers: mark unused arguments in methods

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: hp_sw: remove usused argument in do_inq()
Martin Wilck [Sat, 12 Oct 2019 21:28:11 +0000 (21:28 +0000)]
libmultipath: hp_sw: remove usused argument in do_inq()

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: mark unused params in getprio() methods
Martin Wilck [Sat, 12 Oct 2019 21:28:09 +0000 (21:28 +0000)]
libmultipath: mark unused params in getprio() methods

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: get_ana_info(): remove unused parameter
Martin Wilck [Sat, 12 Oct 2019 21:28:08 +0000 (21:28 +0000)]
libmultipath: get_ana_info(): remove unused parameter

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipath-tools: mark unused params in signal and cleanup handlers
Martin Wilck [Sat, 12 Oct 2019 21:28:07 +0000 (21:28 +0000)]
multipath-tools: mark unused params in signal and cleanup handlers

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: scsi_ioctl_pathinfo(): remove unused argument
Martin Wilck [Sat, 12 Oct 2019 21:28:06 +0000 (21:28 +0000)]
libmultipath: scsi_ioctl_pathinfo(): remove unused argument

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: mark unused arguments in partmap functions
Martin Wilck [Sat, 12 Oct 2019 21:28:04 +0000 (21:28 +0000)]
libmultipath: mark unused arguments in partmap functions

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: process_config_dir(): remove unused argument
Martin Wilck [Sat, 12 Oct 2019 21:28:03 +0000 (21:28 +0000)]
libmultipath: process_config_dir(): remove unused argument

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: _init_foreign(): fix possible memory leak
Martin Wilck [Sat, 12 Oct 2019 21:28:02 +0000 (21:28 +0000)]
libmultipath: _init_foreign(): fix possible memory leak

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: remove_wwids(): fix possible leaks
Martin Wilck [Sat, 12 Oct 2019 21:28:00 +0000 (21:28 +0000)]
libmultipath: remove_wwids(): fix possible leaks

... of fd and memory.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: replace_wwids(): fix possible fd leak
Martin Wilck [Sat, 12 Oct 2019 21:27:59 +0000 (21:27 +0000)]
libmultipath: replace_wwids(): fix possible fd leak

... in case the thread is cancelled.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: uevent_listen(): fix poll() retval check
Martin Wilck [Sat, 12 Oct 2019 21:27:58 +0000 (21:27 +0000)]
libmultipath: uevent_listen(): fix poll() retval check

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: make path_discovery() pthread_cancel()-safe
Martin Wilck [Sat, 12 Oct 2019 21:27:57 +0000 (21:27 +0000)]
libmultipath: make path_discovery() pthread_cancel()-safe

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: path_discovery: handle libudev errors
Martin Wilck [Sat, 12 Oct 2019 21:27:55 +0000 (21:27 +0000)]
libmultipath: path_discovery: handle libudev errors

pass out if any libudev helpers return an error code.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipath tests: use -lpthread for alias test
Martin Wilck [Sat, 12 Oct 2019 21:27:54 +0000 (21:27 +0000)]
multipath tests: use -lpthread for alias test

This becomes necessary because of the previous patch.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: alias.c: prepare for cancel-safe allocation
Martin Wilck [Sat, 12 Oct 2019 21:27:53 +0000 (21:27 +0000)]
libmultipath: alias.c: prepare for cancel-safe allocation

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipath tests: alias: add format/scan test
Martin Wilck [Sat, 12 Oct 2019 21:27:52 +0000 (21:27 +0000)]
multipath tests: alias: add format/scan test

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipath tests: alias: add tests for allocate_binding()
Martin Wilck [Sat, 12 Oct 2019 21:27:50 +0000 (21:27 +0000)]
multipath tests: alias: add tests for allocate_binding()

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: allocate_binding(): detect line overflow
Martin Wilck [Sat, 12 Oct 2019 21:27:49 +0000 (21:27 +0000)]
libmultipath: allocate_binding(): detect line overflow

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: allocate_binding(): error out for id=0
Martin Wilck [Sat, 12 Oct 2019 21:27:48 +0000 (21:27 +0000)]
libmultipath: allocate_binding(): error out for id=0

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: rlookup_binding(): removed unused parameter
Martin Wilck [Sat, 12 Oct 2019 21:27:46 +0000 (21:27 +0000)]
libmultipath: rlookup_binding(): removed unused parameter

The parameter "prefix" is unused in this function.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: lookup_binding(): don't rely on int overflow
Martin Wilck [Sat, 12 Oct 2019 21:27:45 +0000 (21:27 +0000)]
libmultipath: lookup_binding(): don't rely on int overflow

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

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

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: scan_devname: fix int overflow detection
Martin Wilck [Sat, 12 Oct 2019 21:27:44 +0000 (21:27 +0000)]
libmultipath: scan_devname: fix int overflow detection

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

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

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: format_devname: avoid buffer overflow
Martin Wilck [Sat, 12 Oct 2019 21:27:43 +0000 (21:27 +0000)]
libmultipath: format_devname: avoid buffer overflow

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

Also, assert sufficient buffer length, and positive id.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: alias.c: use strlcpy(), and 2 minor fixes
Martin Wilck [Sat, 12 Oct 2019 21:27:41 +0000 (21:27 +0000)]
libmultipath: alias.c: use strlcpy(), and 2 minor fixes

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: alias.c: constify function arguments
Martin Wilck [Sat, 12 Oct 2019 21:27:40 +0000 (21:27 +0000)]
libmultipath: alias.c: constify function arguments

Signed-off-by: Martin Wilck <mwilck@suse.com>