multipath-tools/.git
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 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>
5 months agomultipath tests: add tests for alias handling
Martin Wilck [Sat, 12 Oct 2019 21:27:39 +0000 (21:27 +0000)]
multipath tests: add tests for alias handling

Some of these tests fail with the current code base.

Signed-off-by: Martin Wilck <mwilck@suse.com>
5 months agomultipath tests: move condlog test wrappers to separate file
Martin Wilck [Sat, 12 Oct 2019 21:27:38 +0000 (21:27 +0000)]
multipath tests: move condlog test wrappers to separate file

These helpers can be useful in other tests.

Signed-off-by: Martin Wilck <mwilck@suse.com>
10 months agoBump version to 0.8.3 0.8.3
Christophe Varoqui [Wed, 2 Oct 2019 07:15:03 +0000 (09:15 +0200)]
Bump version to 0.8.3

10 months agomultipath-tools: cosmetic changes in hwtable
Xose Vazquez Perez [Sat, 21 Sep 2019 23:40:39 +0000 (01:40 +0200)]
multipath-tools: cosmetic changes in hwtable

Tegile IntelliFlash was acquired by DDN, from WD.

HPE Primera is also identified as 3PARdata/VV

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>
10 months agomultipathd: "san_path_err" failure optimization
Chongyun Wu [Wed, 2 Oct 2019 06:48:07 +0000 (06:48 +0000)]
multipathd: "san_path_err" failure optimization

Let san_path_err_recovery_time path unstable can be
detected and not reinstate it until this path keep up in
san_path_err_recovery_time. It will fix heavy IO delay
caused by parts of paths state shaky in multipath device.

Test and result:
Run up eth1 30s and down eth1 30s with 100 loops script to
make some paths shaky in each multipath devices.
Using below multipath.conf configure in defaults section:
    san_path_err_recovery_time 30
    san_path_err_threshold 2
    san_path_err_forget_rate 6
After test, not found any IO delay logs except several logs in the very
beginning which before san_path_err filter shaky path works .
If without above config and this patch there will be lots of IO delay
in syslog and some paths state change from up to down again and again.

Signed-off-by: Chongyun Wu <wu.chongyun@h3c.com>
10 months agomultipath.conf.5: document foreign library support
Martin Wilck [Wed, 2 Oct 2019 06:48:05 +0000 (06:48 +0000)]
multipath.conf.5: document foreign library support

Add documentation for foreign library support, and for the
"enable_foreign" parameter.

Signed-off-by: Martin Wilck <mwilck@suse.com>
10 months agomultipath.conf: add "enable_foreign" parameter
Martin Wilck [Wed, 2 Oct 2019 06:48:04 +0000 (06:48 +0000)]
multipath.conf: add "enable_foreign" parameter

This new configuration parameter can be used to selectively
enable foreign libraries. The value is a regular expression,
against which foreign library names such as "nvme" are matched.
By setting this to a value that matches no foreign library
(e.g. "^$" or "NONE"), foreign code is completely disabled.
By default, all available foreign libraries are loaded.

Signed-off-by: Martin Wilck <mwilck@suse.com>
10 months agomultipath-tools (coverity): assert availability of CLOCK_MONOTONIC
Martin Wilck [Tue, 9 Jul 2019 07:40:03 +0000 (07:40 +0000)]
multipath-tools (coverity): assert availability of CLOCK_MONOTONIC

clock_gettime() fails only if either an invalid pointer is passed,
or if the requested clock ID is not available. While availability of
CLOCK_REALTIME is guaranteed, CLOCK_MONOTONIC is not, at least not
by POSIX (Linux seems to have it, always). Provide a wrapper that
can be called without error checking, and which aborts in the highly
unlikely case that the monotonic clock can't be obtained. That saves
us from checking the error code of clock_gettime() at every invocation
(handling this sort of error "correctly" is almost impossible anyway),
and should still satisfy coverity.

Not doing this for libdmmp here, as it has it's own error checking
and doesn't use headers from libmultipath.

----
v2: Fix mistake that with -DNDEBUG, clock_gettime wouldn't be called
at all (Bart van Assche).

Signed-off-by: Martin Wilck <mwilck@suse.com>
10 months agokpartx: recognize DASD on loop devices again
Martin Wilck [Tue, 9 Jul 2019 07:40:02 +0000 (07:40 +0000)]
kpartx: recognize DASD on loop devices again

Since 4d57b868, DASD partition tables are only recognized on
DASD hardware. This turns out to break certain software that works
e.g. with DASD partition tables on loop devices. The problem that
4d57b868 attempted to fix was that "unlabeled disk" format has
no signature at all and is detected on any volume, including
empty ones.

With this patch, DASD partition table formats other than "unlabeled
disk" are detected on non-DASD devices again.

Fixes: 4d57b868 "kpartx: only recognize dasd part table on DASD"
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
10 months agomultipath-tools: reorder vendor in hwtable
Xose Vazquez Perez [Fri, 26 Jul 2019 19:19:30 +0000 (21:19 +0200)]
multipath-tools: reorder vendor in hwtable

Nexenta was acquired by DDN.

Cc: Yacine Kheddache <yacine@alyseo.com>
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>
10 months agomultipath-tools: delete examples from mpathpersist output
Xose Vazquez Perez [Fri, 26 Jul 2019 19:19:29 +0000 (21:19 +0200)]
multipath-tools: delete examples from mpathpersist output

The manual page is more complete and detailed.

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>
10 months agomultipath-tools: delete outdated comment at multipath/multipath.conf.5
Xose Vazquez Perez [Fri, 26 Jul 2019 19:19:28 +0000 (21:19 +0200)]
multipath-tools: delete outdated comment at multipath/multipath.conf.5

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>
10 months agolibmultipath: fix mpcontext initialization
Benjamin Marzinski [Fri, 13 Sep 2019 22:04:04 +0000 (17:04 -0500)]
libmultipath: fix mpcontext initialization

If a path is discovered before there is a multipath device for it to
belong to, the checker will not have its mpcontext initialized, even if
that path later belongs to a multipath device. A checker's mpcontext is
only set when the checker is selected, and is set to NULL if there is no
multipath device associated with the path. This only impacts the emc
checker. However, it makes the emc checker unable to determine if a
passive path is connected to an inactive snapshot or not.

This can be solved by adding a new checker class function, mp_init().
This is called when the checker is first initialized, and whenever the
checker is called, if the checker's mpcontext hasn't been initialized.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>