multipath-tools/.git
15 months agolibmultipath/hwtable: remove inherited props from ONTAP NVMe
Martin Wilck [Fri, 8 Jun 2018 10:20:29 +0000 (12:20 +0200)]
libmultipath/hwtable: remove inherited props from ONTAP NVMe

With the new hwtable code, properties inherited from generic NVMe
don't need to be duplicated.

Signed-off-by: Martin Wilck <mwilck@suse.com>
15 months agolibmultipath: merge hwentries inside a conf file
Martin Wilck [Fri, 8 Jun 2018 10:20:28 +0000 (12:20 +0200)]
libmultipath: merge hwentries inside a conf file

Merging hwentries with identical vendor/product/revision is still useful,
although it's not strictly necessary any more. But such identical entries
should always be merged, not only if they appear in different configuration
files. This requires changing the logic of factorize_hwtable.

By setting -DCHECK_BUILTIN_HWTABLE at compile time, the built-in hwtable
can be checked against duplicates as well.

Signed-off-by: Martin Wilck <mwilck@suse.com>
15 months agolibmultipath: don't merge hwentries by regex
Martin Wilck [Fri, 8 Jun 2018 10:20:27 +0000 (12:20 +0200)]
libmultipath: don't merge hwentries by regex

Merging by regular expression is wrong, because regular expressions can't be
matched against each other. Unexpected results for hardware properties may
result. Don't do it any more.

Signed-off-by: Martin Wilck <mwilck@suse.com>
15 months agolibmultipath: allow more than one hwentry
Martin Wilck [Fri, 8 Jun 2018 10:20:26 +0000 (12:20 +0200)]
libmultipath: allow more than one hwentry

The previous patch "use vector for for pp->hwe and mp->hwe" changed the
data structure for hwentries. This patch changes actual behavior by
allowing more than one hwentry to match a given path (or multipath).

This fixes several currently broken test cases. The test code is adapted
accordingly.

Signed-off-by: Martin Wilck <mwilck@suse.com>
15 months agolibmultipath: use vector for for pp->hwe and mp->hwe
Martin Wilck [Fri, 8 Jun 2018 10:20:25 +0000 (12:20 +0200)]
libmultipath: use vector for for pp->hwe and mp->hwe

Change the data structure of "struct path" and "struct multipath"
such that the "hwe" entry is a vector of hwentry structures rather
than a single hwentry structure. Add respective code to the
constructors and destructors (note that mp->hwe is never allocated,
it's always a pointer to a path hwe).

Change find_hwe() to fill in the passed vector rather than returning
a hwentry pointer. Change the propsel code to look through vectors
of hwentries to determine a given property.

This patch just creates the new data structure and the functions to
deal with them, it doesn't introduce semantic changes.

Signed-off-by: Martin Wilck <mwilck@suse.com>
15 months agolibmultipath: add debug messages to hwentry lookup/merging code
Martin Wilck [Fri, 8 Jun 2018 10:20:24 +0000 (12:20 +0200)]
libmultipath: add debug messages to hwentry lookup/merging code

Signed-off-by: Martin Wilck <mwilck@suse.com>
15 months agotests/hwtable: tests for config file handling and hwentry merging
Martin Wilck [Fri, 8 Jun 2018 10:20:23 +0000 (12:20 +0200)]
tests/hwtable: tests for config file handling and hwentry merging

Add unit tests for parsing "device" and "blacklist" configuration entries and
hwtable entry merging. The tests work by creating a multipath.conf file and one
or more config_dir/*.conf files, reading device entries from both, simulating
discovery of fake paths and multipaths, and verifying these are configured as
expected. The focus is on the behavior if several hwtable or blacklist entries
match a single device.

Most of these tests in this file serve as regression test for follow-up changes.
But Some of the tests are meant to illustrate problems problems with
the current code, which behaves inconsistently in certain cases. By
changing the BROKEN macro at the top of the file, the user can control if broken
behavior causes test failure, or succeeds with a warning. Subsequent patches
will remove the BROKEN tests. Reviewers are encouraged to focus on the BROKEN
tests, which annotate current behavior that follow-up patches are going to change.

Problems with the current code are mainly found in two areas:

 1. It currently makes a difference whether several entries matching the same
 device are in in the same configuration file (default "multipath.conf") or
 distributed over "multipath.conf" and other files under config_dir. This is
 highly unexpected behavior.
 Moreover, in this context, the built-in hwtable can be viewed as yet another
 "configuration file" which is parsed before "multipath.conf". The same problem
 arises: adding a hwentry to "multipath.conf" doesn't necessarily have the same
 effect as adding the same entry to the built-in hwtable and recompiling,
 because different merging logic applies (in short: entries from different
 "configuration files" are merged, but entries from the same "file" aren't).

 This is a major blocker for using the configuration dumped with
 "multipath -t" as input for multipath-tools, because a built-in entry which
 is dumped ends up in "multipath.conf" or a config_dir file, which may change
 the way it's merged with other entries.

  2. The vendor/product/rev IDs are regular expressions, and merging of entries
  by regular expressions simply doesn't work. Entries are merged if a later
  regex, interpreted as a string, matches an earlier added regex. But that's
  incorrect. Except in trivial cases, matching of a regex r2 by another regex
  r1 doesn't say anything about whether strings matched by r2 will be matched
  by r1 as well.

Another, minor issue is the treatment of double quotes.

The way these tests are implemented using the test_driver() function may seem
weird in the first place. The reason is that in a later patch, when we have
configuration-dumping-and-reloading basically working, test_driver() will be
extended to run the same test both with the initial and dumped configuration
and ensure that there are no differences. If I didn't introduce test_driver()
right away, I'd have major, confusing changes in the test code when this
functionality is added.

Signed-off-by: Martin Wilck <mwilck@suse.com>
15 months agotests/test-lib: cmocka helpers to simulate path and map discovery
Martin Wilck [Fri, 8 Jun 2018 10:20:22 +0000 (12:20 +0200)]
tests/test-lib: cmocka helpers to simulate path and map discovery

These functions simulate path discovery and multipath setup with cmocka. They will be
used in the hwtable test case, but may be useful for other future test cases,
too.

Signed-off-by: Martin Wilck <mwilck@suse.com>
15 months agotests/Makefile: autogenerate list of symbols to be wrapped
Martin Wilck [Fri, 8 Jun 2018 10:20:21 +0000 (12:20 +0200)]
tests/Makefile: autogenerate list of symbols to be wrapped

Rather than manually listing all the -Wl,--wrap=... options, autogenerate
a list of functions to be wrapped in a cmocka test. Allowing this not only
for the test file itself but also for additional "test library" source files
requires some Makefile incantations.

Moreover, no need to list globals.c in dependencies, automatic dependency
tracking takes care for this (and avoids recompilation of tests that don't
pull in global.c).

Signed-off-by: Martin Wilck <mwilck@suse.com>
15 months agolibmultipath/prio: constify simple getters
Martin Wilck [Fri, 8 Jun 2018 10:20:20 +0000 (12:20 +0200)]
libmultipath/prio: constify simple getters

One day we should also constify getprio(), but that requires
touching all prioritizers.

Signed-off-by: Martin Wilck <mwilck@suse.com>
15 months agolibmultipath: change prototypes of hwe_regmatch() and find_hwe()
Martin Wilck [Fri, 8 Jun 2018 10:20:19 +0000 (12:20 +0200)]
libmultipath: change prototypes of hwe_regmatch() and find_hwe()

hwentry structures are supposed to be initialized and destroyed
with alloc_hwe() and free_hwe(), respectively. The second
argument is of hwe_regmatch() isn't a real hwentry, just a
vendor/product/revision tuple. Clarify that by adapting the
prototype. This allows to use const arguments in find_hwe(), too.

Signed-off-by: Martin Wilck <mwilck@suse.com>
15 months agolibmultipath: some const usage in hwentry handling
Martin Wilck [Fri, 8 Jun 2018 10:20:18 +0000 (12:20 +0200)]
libmultipath: some const usage in hwentry handling

Add some const qualifiers in in the code dealing with hwentries.

Signed-off-by: Martin Wilck <mwilck@suse.com>
15 months agolibmultipath/structs.c: constify some functions
Martin Wilck [Fri, 8 Jun 2018 10:20:17 +0000 (12:20 +0200)]
libmultipath/structs.c: constify some functions

Signed-off-by: Martin Wilck <mwilck@suse.com>
15 months agolibmultipath: remove superfluous conditionals in load_config()
Martin Wilck [Fri, 8 Jun 2018 10:20:16 +0000 (12:20 +0200)]
libmultipath: remove superfluous conditionals in load_config()

In load_config(), conf is freshly allocated, there's no point in checking
previously set values.

Signed-off-by: Martin Wilck <mwilck@suse.com>
15 months agolibmultipath: fix memory leak in process_config_dir()
Martin Wilck [Fri, 8 Jun 2018 10:20:15 +0000 (12:20 +0200)]
libmultipath: fix memory leak in process_config_dir()

Signed-off-by: Martin Wilck <mwilck@suse.com>
15 months agokpartx: no need to use FREE_CONST
Martin Wilck [Fri, 8 Jun 2018 10:20:14 +0000 (12:20 +0200)]
kpartx: no need to use FREE_CONST

A function that returns a result of strdup() doesn't need to declare that
result as const char*.

Signed-off-by: Martin Wilck <mwilck@suse.com>
15 months agomultipath.conf.5: update the description of marginal_path_err_rate_threshold
Wang Ke [Fri, 8 Jun 2018 06:47:46 +0000 (14:47 +0800)]
multipath.conf.5: update the description of marginal_path_err_rate_threshold

    The path will not reinstate for \fImarginal_path_err_rate_threshold\fR
    seconds unless there is one active path, when it should be marginal_path_err_recheck_gap_time seconds
    instead of marginal_path_err_rate_threshold.

Signed-off-by: Ke Wang <wangke16@huawei.com>
15 months agomultipath: don't check timestamps without a path
Benjamin Marzinski [Tue, 5 Jun 2018 22:40:21 +0000 (17:40 -0500)]
multipath: don't check timestamps without a path

If a path was blacklisted, pathvec could exist but have no path in it.
print_cmd_valid wasn't checking this before calling
find_multipaths_check_timeout(). This was causing it to dereference a
NULL pointer in these cases.

Cc: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
15 months agompathpersist: fix aptpl support
Benjamin Marzinski [Tue, 5 Jun 2018 22:40:20 +0000 (17:40 -0500)]
mpathpersist: fix aptpl support

The "Active Persist Through Power Loss" flag must be set whenever a key
is registered. However, there is no way for multipathd to know if this
was set by mpathpersist. The result is that if a path goes down and
comes back up (or if it wasn't up when mpathpersist was first run)
multipathd will clear the aptpl flag when it reregisters the key on it.

To fix this, multipath.conf now accepts an optional ":aptpl" appended
on the reservation_key value. If this is added to the reservation_key
multipathd will set the aptpl flag when it reregisters the key. If
reservation_key is set to "file", this will automatically be tracked
in the /etc/multipath/prkeys file.

To track this flag in the prkeys file, without changing the format
I've made "0x<key>" stand for non-aptpl keys, and "0X<key>" stand
for aptpl keys. Since previously, all keys used a lower-case x, this
will default to the current behavior for existing keys. Obviously, the
next time mpathpersist is run, this will be changed if --param-aptpl
is used.  Since there are no more flags that are in sg_persist that
multipathd needs to care about in mpathpersist, there shouldn't need
to be any more flags added to the prkeys file.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
15 months agompathpersist: add all_tg_pt option
Benjamin Marzinski [Fri, 1 Jun 2018 22:22:01 +0000 (17:22 -0500)]
mpathpersist: add all_tg_pt option

Some arrays, such as the EMC VNX, don't follow the scsi persistent
reservations spec in making key registrations per I_T NEXUS. Instead,
the registration is shared by all target ports connected to a given
host.  This causes mpathpersist to fail whenever it tries to register a
key, since it will receive a registration conflict on some of the paths.

To deal with this, mpathpersist needs to track the hosts that it has
done a registration on, and only register once per host. The new
"all_tg_pt" multipath.conf option is used to set which arrays need this
feature.  I currently don't know if all EMC VNX arrays handle persistent
reservations like this, or if it is configurable. A future patch will
update the VNX built-in config, if this is indeed their default (or
only) setting.

Multipathd doesn't need to worry about this. It is often the case that
when a path device comes back, it will still have the keys registered to
it. Because of this, multipathd uses register-and-ignore, which means
that it won't cause an error if the registration has already happened
down a different target port.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
15 months agolibmultipath: remove rbd code
Benjamin Marzinski [Fri, 1 Jun 2018 22:22:02 +0000 (17:22 -0500)]
libmultipath: remove rbd code

The Ceph tean has asked to drop support for multipathed rbd, since it
was running into data corruption issues. There was never an upstream
Ceph release based on it, and because of the corruption, there should be
no users of this code. This patch simply reverts all the rbd code from
multipath.

Cc: Michael Christie <mchristi@redhat.com>
Cc: Jason Dillaman <dillaman@redhat.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
16 months agolibmultipath: fix error parsing "find_multipaths strict"
Martin Wilck [Tue, 15 May 2018 12:32:44 +0000 (14:32 +0200)]
libmultipath: fix error parsing "find_multipaths strict"

If "find_multipaths strict" is set in multipath.conf, the error message
"illegal value for find_multipaths: strict" is printed. This causes no
functional problem, as "strict" happens to be the default, fallback
value. It should be fixed nonetheless. FIND_MULTIPATHS_STRICT, having
the highest numeric value, must be last in the enum.

Fixes: c36f2f42 "libmultipath: change find_multipaths option to multi-value"
Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agomultipathd: handle errors in uxlsnr as fatal
Martin Wilck [Wed, 21 Mar 2018 09:34:19 +0000 (10:34 +0100)]
multipathd: handle errors in uxlsnr as fatal

The ppoll() calls of the uxlsnr thread are vital for proper functioning of
multipathd. If the uxlsnr thread can't open the socket or fails to call ppoll()
for other reasons, quit the daemon. If we don't do that, multipathd may
hang in a state where it can't be terminated any more, because the uxlsnr
thread is responsible for handling all signals. This happens e.g. if
systemd's multipathd.socket is running in and multipathd is started from
outside systemd.

24f2844 "multipathd: fix signal blocking logic" has made this problem more
severe. Before that patch, the signals weren't actually blocked in any thread.
That's not to say 24f2844 was wrong. I still think it's correct, we just
need this one on top.

Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agolibmultipath: don't reject maps with undefined prio
Martin Wilck [Wed, 21 Mar 2018 09:34:18 +0000 (10:34 +0100)]
libmultipath: don't reject maps with undefined prio

libmultipath's prio routines can deal with pp->priority == PRIO_UNDEF
just fine. PRIO_UNDEF is just a very low priority. So there's
no reason to reject setting up a multipath map because paths have
undefined priority.

Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agomultipath-tools: configure hitachi ams2000 and hus100 as full active arrays
Xose Vazquez Perez [Mon, 14 May 2018 15:30:17 +0000 (17:30 +0200)]
multipath-tools: configure hitachi ams2000 and hus100 as full active arrays

AMS2000 and HUS100 families are active/active arrays.

Based on https://support.hitachivantara.com/download/epcra/df818913.pdf
and internal hitachi docs.

Cc: Matthias Rudolph <Matthias.Rudolph@hitachivantara.com>
Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: DM-DEV ML <dm-devel@redhat.com>
Signed-off-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
16 months agomultipath-tools: refresh kernel-doc from kernel sources
Xose Vazquez Perez [Sat, 12 May 2018 22:39:42 +0000 (00:39 +0200)]
multipath-tools: refresh kernel-doc from kernel sources

Cc: Gris Ge <fge@redhat.com>
Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: device-mapper development <dm-devel@redhat.com>
Signed-off-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
16 months agomultipath-tools: add +x to doc-preclean.pl and split-man.pl
Xose Vazquez Perez [Sat, 12 May 2018 22:39:41 +0000 (00:39 +0200)]
multipath-tools: add +x to doc-preclean.pl and split-man.pl

It is not strictly necessary, but it helps identify bin files.

Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: DM ML <dm-devel@redhat.com>
Signed-off-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
16 months agomultipath-tools: fix compilation with musl libc
Xose Vazquez Perez [Fri, 11 May 2018 16:39:44 +0000 (18:39 +0200)]
multipath-tools: fix compilation with musl libc

In file included from alias.c:15:
file.h:9:47: error: unknown type name ‘mode_t’; did you mean ‘time_t’?
 int ensure_directories_exist(const char *str, mode_t dir_mode);
                                               ^~~~~~
                                               time_t

sysfs.c: In function ‘sysfs_is_multipathed’:
sysfs.c:304:15: error: ‘PATH_MAX’ undeclared (first use in this function); did you mean ‘PATH_UP’?
  char pathbuf[PATH_MAX];
               ^~~~~~~~
               PATH_UP

Cc: Martin Wilck <mwilck@suse.com>
Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: DM ML <dm-devel@redhat.com>
Signed-off-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
16 months agomultipath-tools: Remove trailing/leading whitespaces and reformat code
Xose Vazquez Perez [Fri, 11 May 2018 13:43:11 +0000 (15:43 +0200)]
multipath-tools: Remove trailing/leading whitespaces and reformat code

Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: device-mapper development <dm-devel@redhat.com>
Signed-off-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
16 months agomultipath-tools: replace FSF address with a www pointer
Xose Vazquez Perez [Fri, 11 May 2018 13:42:43 +0000 (15:42 +0200)]
multipath-tools: replace FSF address with a www pointer

Less prone to future modifications, new FSF licences
point exactly to this url: <http://www.gnu.org/licenses/>.
And sending a smail to FSF is outdated.

First clean up was done in 5619a39c433ac3d10a88079593cec1aa6472cbeb

Cc: Martin Wilck <mwilck@suse.com>
Cc: Benjamin Marzinski <bmarzins@redhat.com>
Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: DM ML <dm-devel@redhat.com>
Signed-off-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
16 months agomultipath-tools: remove emacs autoconfig of kpartx/gpt.h
Xose Vazquez Perez [Thu, 12 Apr 2018 16:17:13 +0000 (18:17 +0200)]
multipath-tools: remove emacs autoconfig of kpartx/gpt.h

Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: DM ML <dm-devel@redhat.com>
Signed-off-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
16 months agomultipath-tools: remove "c" from __cpluscplus, misspelled
Xose Vazquez Perez [Tue, 24 Apr 2018 13:03:40 +0000 (15:03 +0200)]
multipath-tools: remove "c" from __cpluscplus, misspelled

found by cppcheck(http://cppcheck.sf.net/):
[libmpathcmd/mpath_cmd.h:24]: (error) Invalid number of character '{' when these macros are defined: '__cpluscplus'.

Cc: Benjamin Marzinski <bmarzins@redhat.com>
Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: DM ML <dm-devel@redhat.com>
Signed-off-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
16 months agomultipath-tools: add RDAC SUN/ArrayStorage to hwtable
Xose Vazquez Perez [Wed, 11 Apr 2018 13:14:13 +0000 (15:14 +0200)]
multipath-tools: add RDAC SUN/ArrayStorage to hwtable

Already in scsi_dh: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/scsi/scsi_dh.c#n70

Cc: NetApp RDAC team <ng-eseries-upstream-maintainers@netapp.com>
Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: DM ML <dm-devel@redhat.com>
Signed-off-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
16 months agoBump version to 0.7.7 0.7.7
Christophe Varoqui [Fri, 11 May 2018 08:52:41 +0000 (10:52 +0200)]
Bump version to 0.7.7

16 months agomultipathd: fix reservation_key check
Benjamin Marzinski [Tue, 24 Apr 2018 20:15:31 +0000 (15:15 -0500)]
multipathd: fix reservation_key check

mpath_pr_event_handle should exit if the reservation key is zero, not
non-zero.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
16 months agomultipathd: add failures path format wildcard
Benjamin Marzinski [Tue, 24 Apr 2018 20:15:30 +0000 (15:15 -0500)]
multipathd: add failures path format wildcard

multipath already tracks this, so it should be able to print it out.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
16 months agomultipath.rules: find_multipaths "smart" logic
Martin Wilck [Fri, 13 Apr 2018 22:00:15 +0000 (00:00 +0200)]
multipath.rules: find_multipaths "smart" logic

When the first path to a device appears, we don't know if more paths are going
to follow. find_multipath "smart" logic attempts to solve this dilemma by
waiting for additional paths for a configurable time before giving up
and releasing single paths to upper layers.

These rules apply only if both find_multipaths is set to "smart" in
multipath.conf. In this mode, multipath -u sets DM_MULTIPATH_DEVICE_PATH=2 if
there's no clear evidence wheteher a given device should be a multipath member
(not blacklisted, not listed as "failed", not in WWIDs file, not member of an
existing map, only one path seen yet). In this case, "multipath -u" also sets the
variable FIND_MULTIPATHS_WAIT_UNIL to a relative time stamp (we need to use
relative "monotonic" time stamps because this may be triggered early during
boot, before system "calendar" time is correctly initialized).

In the DM_MULTIPATH_DEVICE_PATH=2 case, pretend that the path is multipath
member, disallow further processing by systemd (allowing multipathd some time
to grab the path), and set a systemd timer to check again after the given
timeout. If the path is still not multipathed by then, pass it on to systemd
for further processing.

Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
16 months agolibmultipath: enable find_multipaths "smart"
Martin Wilck [Fri, 13 Apr 2018 22:00:14 +0000 (00:00 +0200)]
libmultipath: enable find_multipaths "smart"

This activates "smart" path detection. This is similar to
"find_multipaths yes", but doesn't generally ignore single paths
that are not listed in the WWIDs file. Rather, such paths are
temporarily treated like multipath members. If no additional paths
are detected after a certain time, the paths are re-added to the
system as non-multipath. This needs support by the udev rules, to
be added in a follow-up patch.

If a multipath map is successfully successfully created, and paths are
in waiting state, trigger path uevents to update their status.

Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agomultipath -u: test if path is busy
Martin Wilck [Fri, 13 Apr 2018 22:00:13 +0000 (00:00 +0200)]
multipath -u: test if path is busy

For "find_multipaths smart", check if a path is already in use
before setting DM_MULTIPATH_DEVICE_PATH to 1 or 2 (and thus,
SYSTEMD_READY=0). If we don't do this, a device which has already been
mounted (e.g. during initrd processing) may be unmounted by systemd, causing
havoc to the boot process.

Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agomultipath -u: don't grab devices already passed to system
Martin Wilck [Fri, 13 Apr 2018 22:00:12 +0000 (00:00 +0200)]
multipath -u: don't grab devices already passed to system

Setting SYSTEMD_READY=0 on a device that has previously been passed to
systemd is dangerous - already mounted file systems might be unmounted by
systemd.

Avoid that by checking for previously set DM_MULTIPATH_DEVICE_PATH
environment variable.

This requires to change the exit status of multipath -u - it needs to exit
with status 0 even if the path is not a multipath device path, otherwise
udev doesn't import the printed key-value pairs. We do this only for
"multipath -u"; legacy "multipath -c", which is more likely to be run in user
scripts, still exits with 1 for non-multipath devices.

The condition ENV{DM_MULTIPATH_DEVICE_PATH}!="1" before the "multipath -u"
statement in multipath.rules needs to be removed. This condition was
pointless anyway, because until this patch, DM_MULTIPATH_DEVICE_PATH hadn't
been imported from the db and thus was never set, and "multipath -u" was
always invoked. We want to keep this behavior.

Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agomultipath -u: quick check if path is multipathed
Martin Wilck [Fri, 13 Apr 2018 22:00:11 +0000 (00:00 +0200)]
multipath -u: quick check if path is multipathed

With "find_multipaths smart", we accept paths as valid if they are
already part of a multipath map. This patch avoids doing a full path
and device-mapper map scan for this case, speeding up "multipath -u"
considerably.

Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
16 months agomultipath -u: cleanup logic
Martin Wilck [Fri, 13 Apr 2018 22:00:10 +0000 (00:00 +0200)]
multipath -u: cleanup logic

The CMD_VALID_PATH logic is complex and hard to read and understand.
This patch cleans it up a bit (preparing for folluw-up patches).
It doesn't change any logic.

Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agomultipath -u : set FIND_MULTIPATHS_WAIT_UNTIL from /dev/shm
Martin Wilck [Fri, 13 Apr 2018 22:00:09 +0000 (00:00 +0200)]
multipath -u : set FIND_MULTIPATHS_WAIT_UNTIL from /dev/shm

In "find_multipaths smart" mode, use time stamps under
/dev/shm/multipath/find_multipaths to track waiting for multipath
siblings. When a path is first encountered and is "maybe" multipath, create
a file under /dev/shm, set its modification time to the expiry time of the
timer, and set the FIND_MULTIPATHS_WAIT_UNTIL variable. On later calls,
also set FIND_MULTIPATHS_WAIT_UNTIL to the expiry time (but don't change
the time stamp) if it's not expired yet, or 0 if it is expired. Set
FIND_MULTIPATHS_WAIT_UNTIL even if enough evidence becomes available to
decide if the path needs to be multipathed - this enables the udev rules to
detect that this is a device a timer has been started for, and stop it. By
using /dev/shm, we share information about "smart" timers between initrd
and root file system, and thus only calculate the timeout once.

Because we use major:minor to identify the devices in /dev/shm, and because
a removed device might be replaced by a different one with the same
major/minor number, add a rule to multipath.rules to remove the
find_multipaths marker on remove uevents.

Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agolibmultipath: implement find_multipaths_timeout
Martin Wilck [Fri, 13 Apr 2018 22:00:08 +0000 (00:00 +0200)]
libmultipath: implement find_multipaths_timeout

This makes the timeout for "find_multipaths smart" configurable.
If the timeout has a negative value (default), it's applied only
to "known" hardware which is either in the hwtable or in a "device" section in
multipath.conf. For typical non-multipath hardware, which is not in the
hwtable, a short timeout of 1s is used, so that boot delays caused by
pointlessly waiting e.g. for SATA devices will be minimal.

It's expected that a "reasonable" timeout value depends less on the storage
hardware itself but on other properties of the data center such as network
latencies or distances. find_multipaths_timeout is therefore just a "defaults"
section setting.

Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
16 months agomultipath -u: add DM_MULTIPATH_DEVICE_PATH=2 for "maybe"
Martin Wilck [Fri, 13 Apr 2018 22:00:07 +0000 (00:00 +0200)]
multipath -u: add DM_MULTIPATH_DEVICE_PATH=2 for "maybe"

Use DM_MULTIPATH_DEVICE_PATH="2" to indicate that this might be a
valid path, but we aren't certain. This happens with find_multipaths
"smart", when the first path to a device (or a single-path
device) is encountered, and the device is neither blacklisted,
nor marked failed, nor whitelisted in the wwids file.

Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agomultipath -u: treat failed wwids as invalid
Martin Wilck [Fri, 13 Apr 2018 22:00:06 +0000 (00:00 +0200)]
multipath -u: treat failed wwids as invalid

If a WWID has been marked as "failed", don't treat it as "valid multipath
device path" in multipath -c/-u. This is key to achieve consistency between
multipathd and udev rule processing.

Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
16 months agomultipath -u: change output to environment/key format
Martin Wilck [Fri, 13 Apr 2018 22:00:05 +0000 (00:00 +0200)]
multipath -u: change output to environment/key format

... instead of free format. This provides more flexibility
for udev rule processing for the future. Adapt code in multipath.rules.
The exit status remains as usual. This affects "multipath -c", too.

The parameters "pathvec" and "conf" for print_cmd_valid are currently
unused, but will be in follow-up patches.

Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
16 months agomultipath -u: common code path for result message
Martin Wilck [Fri, 13 Apr 2018 22:00:04 +0000 (00:00 +0200)]
multipath -u: common code path for result message

Print the result message in one place only. This simplifies
future changes. multipath -c is also affected.

Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
16 months agolibmultipath: indicate wwid failure in dm_addmap_create()
Martin Wilck [Fri, 13 Apr 2018 22:00:03 +0000 (00:00 +0200)]
libmultipath: indicate wwid failure in dm_addmap_create()

dm_addmap_create() is where we actually try to set up a new
multipath map. Depending on the result, mark the wwid as
failed (or not), and re-trigger an uevent if necessary.
If a path changes from multipath to non-multipath, use an "add"
event to make sure LVM2 rules pick it up. Increase log level
of this event to 3.

Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
16 months agolibmultipath: functions to indicate mapping failure in /dev/shm
Martin Wilck [Fri, 13 Apr 2018 22:00:02 +0000 (00:00 +0200)]
libmultipath: functions to indicate mapping failure in /dev/shm

Create a simple API that indicates failure to create a map for a
certain WWID. This will allow multipathd to indicate to other tools
(in particular, "multipath -u" during udev processing) that
an attempt to create a map for a certain wwid failed.

The indicator is simply the existence of a file under
/dev/shm/multipath/failed_wwids. This has been chosen because it
"survives" during pivot-root between initrd and root file system.

The exact semantics of /dev/shm/multipath/failed_wwids/$WWID is:
"multipath or multipathd has tried to create this map from its
members with a DM_DEVICE_CREATE call, and failed on the latest,
or only, attempt to do so".

In particular, the existence of the file proves that here was at
least one unsuccessful attempt to create the map since the last
reboot. On the contrary, the non-existence of this file does not
indicate a successful attempt - perhaps multipathd never tried to
set up the map.

Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
16 months agolibmultipath: use const char* in open_file()
Martin Wilck [Fri, 13 Apr 2018 22:00:01 +0000 (00:00 +0200)]
libmultipath: use const char* in open_file()

Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agolibmultipath: change find_multipaths option to multi-value
Martin Wilck [Fri, 13 Apr 2018 22:00:00 +0000 (00:00 +0200)]
libmultipath: change find_multipaths option to multi-value

Change the "find_multipaths" option from yes/no to multi-value. This
option now covers the effects of "find_multipaths" as it used to be,
plus the -i option to multipath (ignore_wwids) and the -n option to
multipathd (ignore_new_devs), excluding such combinations of the former
options that are dangerous or inconsistent.

The possible values for "find_multipaths" are now:

 - strict: strictly stick to the WWIDs file; never add new maps automatically
   (new default; upstream behaviour with with find_multipaths "yes" and
   commit 64e27ec "multipathd: imply -n if find_multipaths is set")
 - off|no: multipath like "strict", multipathd like "greedy" (previous
   upstream default)
 - on|yes: set up multipath if >1 paths are seen (current Red Hat/Ubuntu
   behavior with find_multipaths "yes")
 - greedy: set up multipath for all non-blacklisted devices (current SUSE
   default)
 - smart: Like "yes", but try to avoid inconsistencies between udev processing
   and multipathd processing by waiting for path siblings to
   appear (fully implemented in follow-up patches)

The default has been changed to "strict", because "no" may cause inconsistent
behavior between "multipath -u" and multipathd. This is deliberately a
conservative choice.

The patch also updates the related man pages.

Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agolibmultipath: trigger path uevent only when necessary
Martin Wilck [Fri, 13 Apr 2018 21:59:59 +0000 (23:59 +0200)]
libmultipath: trigger path uevent only when necessary

Paths that are already classified as DM_MULTIPATH_DEVICE_PATH don't
need to be retriggered.

Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agolibmultipath: trigger change uevent on new device creation
Benjamin Marzinski [Fri, 13 Apr 2018 21:59:58 +0000 (23:59 +0200)]
libmultipath: trigger change uevent on new device creation

When multipath first sees a path device with find_multipaths
enabled, it can't know if the device should be multipathed. This means
that it will not claim the device in udev.  If the device is eventually
multipathed, multipath should trigger a change uevent to update the udev
database to claim the device.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agomultipath -u -i: respect entries in WWIDs file
Martin Wilck [Fri, 13 Apr 2018 21:59:57 +0000 (23:59 +0200)]
multipath -u -i: respect entries in WWIDs file

Previously, if find_multipaths was set, devices listed in the WWIDs file
weren't classified as multipath members by "multipath -u -i" unless they also
met the "find_multipaths" criteria (at least two paths, or existing map with
this WWID). Now we classify all paths in the WWIDs file as multipath members, too.

The rationale for this patch is to match the logic that multipathd applies
by default (i.e. without "-n").

Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agolibmultipath: should_multipath: keep existing maps
Martin Wilck [Fri, 13 Apr 2018 21:59:56 +0000 (23:59 +0200)]
libmultipath: should_multipath: keep existing maps

with find_multipaths "yes" and without the "-n" option to multipathd,
if a path is already multipathed, keep it. The same logic is applied by
"multipath -u -i".

To do this, we need to add a "mpvec" parameter to should_multipath().

Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agoRevert "multipathd: imply -n if find_multipaths is set"
Martin Wilck [Fri, 13 Apr 2018 21:59:55 +0000 (23:59 +0200)]
Revert "multipathd: imply -n if find_multipaths is set"

This reverts commit 64e27ec066a001012f44550f095c93443e91d845.

Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agoRevert "multipath: ignore -i if find_multipaths is set"
Martin Wilck [Fri, 13 Apr 2018 21:59:54 +0000 (23:59 +0200)]
Revert "multipath: ignore -i if find_multipaths is set"

This reverts commit ffbb886a8a16cb063d669cd76a1e656fd3ec8c4b.

Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agolibmultipath: Fix logic in should_multipath
Martin Wilck [Fri, 13 Apr 2018 17:20:42 +0000 (19:20 +0200)]
libmultipath: Fix logic in should_multipath

Commit d3b71498 missed a negation.

Fixes: d3b71498 "multipath: fix rcu thread cancellation hang"
Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agomultipath-tools: add licence info to README
Xose Vazquez Perez [Fri, 13 Apr 2018 16:17:07 +0000 (18:17 +0200)]
multipath-tools: add licence info to README

Alternative patch to [PATCH v2 2/2] multipath-tools: link LICENSES/LGPL-2.0 to LICENSE.default

Cc: Hannes Reinecke <hare@suse.de>
Cc: Benjamin Marzinski <bmarzins@redhat.com>
Cc: Martin Wilck <mwilck@suse.com>
Cc: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: Gris Ge <fge@redhat.com>
Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: DM ML <dm-devel@redhat.com>
Signed-off-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
16 months agomultipath-tools: create LICENSES dir with the text of all used licences
Xose Vazquez Perez [Tue, 10 Apr 2018 15:42:18 +0000 (17:42 +0200)]
multipath-tools: create LICENSES dir with the text of all used licences

On 04/10/2018 09:25 AM, Martin Wilck wrote:
> On Mon, 2018-04-09 at 18:51 +0200, Xose Vazquez Perez wrote:
>> Move COPYING -> LICENSES/GPL-2.0
>> Move COPYING.LESSER -> LICENSES/LGPL-2.0
>>
>> Add GPL-3.0 and LGPL-2.1 to the LICENSES dir.
>> Source directly from:
>> https://www.gnu.org/licenses/gpl-3.0.txt
>> https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
>>
>> Cc: Martin Wilck <mwilck@suse.com>
>> Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>
>> Cc: device-mapper development <dm-devel@redhat.com>
>> Signed-off-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
>> ---
>
> I like this.
> Acked-by: Martin Wilck <mwilck@suse.com>
>
> I  suggest to add my posting from yesterday ("multipath-tools 0.7.6
> fossology license assessment") as "README.licenses".
> With these changes, we'd be in a fine state for the time being.
>
> Actual license changes can be considered for the long term, but don't
> need to be - the current situation is complex but not actually
> problematic. SPDX tags can be added to source files by and by, as we
> see fit.

In the meantime, this patch should clarify the default license:

From c10b33cd2385f3726a0a47e5356b7bec20b10963 Mon Sep 17 00:00:00 2001
From: Xose Vazquez Perez <xose.vazquez@gmail.com>
Date: Tue, 10 Apr 2018 17:34:44 +0200
Subject: [PATCH] multipath-tools: link LICENSES/LGPL-2.0 to COPYING

Default licence is LGPL-2.0

Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: device-mapper development <dm-devel@redhat.com>
Signed-off-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
16 months agomultipath-tools: create LICENSES dir with the text of all used licences
Xose Vazquez Perez [Mon, 9 Apr 2018 16:51:04 +0000 (18:51 +0200)]
multipath-tools: create LICENSES dir with the text of all used licences

Move COPYING -> LICENSES/GPL-2.0
Move COPYING.LESSER -> LICENSES/LGPL-2.0

Add GPL-3.0 and LGPL-2.1 to the LICENSES dir.
Source directly from:
https://www.gnu.org/licenses/gpl-3.0.txt
https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt

Cc: Martin Wilck <mwilck@suse.com>
Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: device-mapper development <dm-devel@redhat.com>
Signed-off-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
16 months ago11-dm-mpath.rules: dont't run "multipath -U" during coldplug
Martin Wilck [Fri, 6 Apr 2018 11:45:21 +0000 (13:45 +0200)]
11-dm-mpath.rules: dont't run "multipath -U" during coldplug

When udevadm trigger is run after switching root, lots of simultaneous uevents
for both path and multipath devices arrive. In may happen that when "multipath
-U" is called on a dm device, the path's uevents haven't finished yet, thus
the paths aren't found in the udev db, and multipath -U erroneously concludes
that there are no usable paths. Avoid that by skipping "multipath -U" during
coldplug.

Fixes: "ce5ea6a 11-dm-mpath.rules: multipath -U for READY check"
Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agolibmpathpersist: decrease log level of various messages
Martin Wilck [Wed, 4 Apr 2018 16:22:00 +0000 (18:22 +0200)]
libmpathpersist: decrease log level of various messages

Silence a few libmpathpersist messages which need not be printed
at the default loglevel.

Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agomultipathd: decrease log level of waiter thread start/stop msgs
Martin Wilck [Wed, 4 Apr 2018 16:21:59 +0000 (18:21 +0200)]
multipathd: decrease log level of waiter thread start/stop msgs

These rather unimportant messages account for a large portion
of multipathd's log messages with the default verbosity level (2).

Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agolibmultipath: decrease log level of uevent filter/merge messages
Martin Wilck [Wed, 4 Apr 2018 16:21:58 +0000 (18:21 +0200)]
libmultipath: decrease log level of uevent filter/merge messages

There should be no need to log these at -v2. The messages are
informational.

Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agomultipathd: decrease log level of "spurious uevent" message
Martin Wilck [Wed, 4 Apr 2018 16:21:57 +0000 (18:21 +0200)]
multipathd: decrease log level of "spurious uevent" message

We trigger such events under various conditions, there's no point
logging them at -v2.

Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agolibmultipath: don't print undefined values
Benjamin Marzinski [Fri, 30 Mar 2018 03:37:03 +0000 (22:37 -0500)]
libmultipath: don't print undefined values

commit 48e9fd9f ("libmultipath: parser: use call-by-value for "snprint"
methods") removed some of the code that checked for undefined values to
avoid printing them.  This lead to device configurations that printed
out values for parameters that they hadn't configured. This patch adds
that code back in.

Fixes: 48e9fd9f ("libmultipath: parser: use call-by-value for "snprint" methods")
Cc: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
16 months agompathcmd: fix libmpathcmd license
Benjamin Marzinski [Fri, 30 Mar 2018 03:37:02 +0000 (22:37 -0500)]
mpathcmd: fix libmpathcmd license

There is no version 2 of the GNU Lesser General Public License, so
change the license header to version 2.1, which does exist. Also copy
the license header to mpath_cmd.c. I've CC'ed everyone who has
contributed code to libmpathcmd.

Cc: Xose Vazquez Perez <xose.vazquez@gmail.com>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Martin Wilck <mwilck@suse.com>
Cc: tang.junhui <tang.junhui@zte.com.cn>
Cc: Gris Ge <fge@redhat.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
16 months agomultipathd: remove unneeded function parameter
Benjamin Marzinski [Fri, 30 Mar 2018 03:37:01 +0000 (22:37 -0500)]
multipathd: remove unneeded function parameter

remove_map_and_stop_waiter was always called with purge_vecs = 1, so
it can simply be removed, as suggested by Martin Wilck

Cc: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
16 months agomultipathd: minor dmevents polling code cleanups
Benjamin Marzinski [Fri, 30 Mar 2018 03:37:00 +0000 (22:37 -0500)]
multipathd: minor dmevents polling code cleanups

Change strncpy to strlcpy and lock_cleanup_pop to pthread_cleanup_pop,
based on suggestions by Martin Wilck

Cc: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
16 months agomultipath: add comments
Benjamin Marzinski [Fri, 30 Mar 2018 03:36:59 +0000 (22:36 -0500)]
multipath: add comments

This commit simply adds a number of comments based on suggestions by
Martin Wilck.

Cc: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
16 months agomultipathd: remove incorrect pthread_testcancel
Benjamin Marzinski [Fri, 30 Mar 2018 03:36:58 +0000 (22:36 -0500)]
multipathd: remove incorrect pthread_testcancel

As Martin Wilck pointed out, a thread that's trying to stop the waiter
thread should not cancel itself before it gets a chance to do so

Cc: Martin Wilck <mwilck@suse.com>
Fixes: c7625f92 "multipathd: fix waiter thread cancelling"
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
16 months agolibmultipath/propsel: (re)use static const vars for origin
Martin Wilck [Tue, 27 Mar 2018 21:50:53 +0000 (23:50 +0200)]
libmultipath/propsel: (re)use static const vars for origin

Define a set of "origin" strings and reuse them throughout the code.
That avoids duplication and makes it easier to verify that we use
consistent messages.

Signed-off-by: Martin Wilck <mwilck@suse.com>
16 months agolibmultipath: hwhandler auto-detection for ALUA
Martin Wilck [Tue, 27 Mar 2018 21:50:52 +0000 (23:50 +0200)]
libmultipath: hwhandler auto-detection for ALUA

If the hardware handler isn't explicitly set, infer ALUA support
from the pp->tpgs attribute. Likewise, if ALUA is selected, but
not supported by the hardware, fall back to no hardware handler.

Signed-off-by: Martin Wilck <mwilck@suse.com>
17 months agomultipath-tools: add GPLv2 as COPYING
Xose Vazquez Perez [Tue, 27 Mar 2018 18:28:19 +0000 (20:28 +0200)]
multipath-tools: add GPLv2 as COPYING

Source directly from: https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt

Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: device-mapper development <dm-devel@redhat.com>
Signed-off-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
17 months agomultipath-tools: move COPYING to COPYING.LESSER
Xose Vazquez Perez [Tue, 27 Mar 2018 18:28:18 +0000 (20:28 +0200)]
multipath-tools: move COPYING to COPYING.LESSER

As recommended by FSF: https://www.gnu.org/licenses/gpl-howto.html

Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: device-mapper development <dm-devel@redhat.com>
Signed-off-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
17 months agomultipath: fix rcu thread cancellation hang
Benjamin Marzinski [Fri, 23 Mar 2018 20:00:46 +0000 (15:00 -0500)]
multipath: fix rcu thread cancellation hang

While the rcu code is waiting for a grace period to elapse, no threads
can register or unregister as rcu reader threads. If for some reason, a
thread never calls put_multipath_config() to exit a read side critical
section, then any threads trying to start or stop will hang. This can
happen if a thread is cancelled between calls to get_multipath_config()
and put_multipath_config(), and multipathd is reconfigured (which causes
the rcu code to wait for a grace period).

This patch fixes this issue in two ways. Where possible, it reorders the
code or saves config values into local variables to remove cancellation
points between calls to get_multipath_config() and
put_multipath_config().  In cases where this isn't possible (or where it
would cause a significant amount of extra work to be done) multipath now
pushes a cleanup handler to call put_multipath_config().

The only functions that were not modified were ones that were only
called by multipath or mpathpersist, since these are single threaded
and already disable rcu thread registration.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
17 months agomultipathd: register threads that use rcu calls
Benjamin Marzinski [Fri, 23 Mar 2018 20:00:45 +0000 (15:00 -0500)]
multipathd: register threads that use rcu calls

All calls to condlog() are rcu reader side calls, so any thread that
uses condlog() must register itself. The only threads that are exempt
are log_thread, since it never calls condlog (or any other function that
calls get_multipath_config) and mpath_pr_event_handler_fn, which is only
called by mpath_persist, which disables the rcu handling.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
17 months agolibmultipath: Fix recently introduced inconsistencies
Bart Van Assche [Mon, 19 Mar 2018 20:27:02 +0000 (21:27 +0100)]
libmultipath: Fix recently introduced inconsistencies

Commit 48e9fd9f67bb changed libmultipath such that an int is passed
as the second argument to some print_*() calls and a pointer to
other print_*() calls. Fix these inconsistencies by changing all
call-by-reference calls into call-by-value calls.

Fixes: 48e9fd9f67bb ("libmultipath: parser: use call-by-value for "snprint" methods")
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Martin Wilck <mwilck@suse.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
17 months agoAllow the compiler to verify consistency of declarations and definitions
Bart Van Assche [Mon, 19 Mar 2018 16:23:50 +0000 (09:23 -0700)]
Allow the compiler to verify consistency of declarations and definitions

Make sure that in every source file the header file is included that
declares the functions defined in that source file. This allows the
compiler to detect inconsistencies between source and header files.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
17 months agomultipathd: stop waiter in __setup_multipath
Benjamin Marzinski [Fri, 16 Mar 2018 21:31:07 +0000 (16:31 -0500)]
multipathd: stop waiter in __setup_multipath

__setup_multipath can remove a multipath device from multipathd, and it
can be called by either by the waiter thread or another thread.
Previously, it dealt with this by never stopping the waiter thread.  It
simply relied on the waiter thread to notice and stop itself.  Now, when
called by another thread, it explicitly stops the waiter thread.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
17 months agomultipathd: move __setup_multipath to multipathd
Benjamin Marzinski [Fri, 16 Mar 2018 21:31:06 +0000 (16:31 -0500)]
multipathd: move __setup_multipath to multipathd

__setup_multipath is only called from multipathd, so it shouldn't be in
libmultipath.  Move it, update_multpath (which calls it) and
set_no_path_retry (which is a helper function for it) into multipathd.
None of these functions were changed, only copied.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
17 months agomultipathd: fix waiter thread cancelling
Benjamin Marzinski [Fri, 16 Mar 2018 21:31:05 +0000 (16:31 -0500)]
multipathd: fix waiter thread cancelling

multipathd was sending a signal to the per-device waiter thread after
cancelling it.  Since these threads are detached, there is a window
where a new thread could have started with the old thread id between the
cancel and the signalling, causing the signal to be delivered to the
wrong thread. Simply reversing the order doesn't fix the issue, since
the waiter threads exit immediately if they receive a signal, again
opening a window for the cancel to be delivered to the wrong thread.

To fix this, multipathd does reverse the order, so that it signals the
thread first (it needs to signal the thread, since the dm_task_run ioctl
isn't a cancellation point) and then cancels it. However it does this
while holding a new mutex.

The waiter thread can only exit without being cancelled for two reasons.
1. When it fails in update_multipath, which removes the device while
   holding the vecs lock.
2. If it receives a SIGUSR2 signal while waiting for a dm event.

Case 1 can never race with another thread removing the device, since
removing a device always happens while holding the vecs lock.  This
means that if the device exists to be removed, then the waiter thread
can't exit this way during the removal.

Case 2 is now solved by grabbing the new mutex after failing
dm_task_run(). With the mutex held, the thread checks if it has been
cancelled. If it wasn't cancelled, the thread continues.

The reason that this uses a new mutex, instead of the vecs lock, is that
using the vecs lock would keep the thread from ending until the vecs
lock was released.  Normally, this isn't a problem. But during
reconfigure, the waiter threads for all devices are stopped, and new
ones started, all while holding the vecs lock.  For systems with a large
number of multipath devices, this will cause multipathd do have double
its already large number of waiter threads during reconfigure, all locked
into memory.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
17 months agomultipath-tools: remove DF arrays from HP
Xose Vazquez Perez [Thu, 15 Mar 2018 17:43:22 +0000 (18:43 +0100)]
multipath-tools: remove DF arrays from HP

Matthias did confirm that there are no such devices.

Cc: Matthias Rudolph <Matthias.Rudolph@hitachivantara.com>
Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: device-mapper development <dm-devel@redhat.com>
Signed-off-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
17 months agomultipath: add unit tests for dmevents code
Benjamin Marzinski [Wed, 14 Mar 2018 17:46:45 +0000 (12:46 -0500)]
multipath: add unit tests for dmevents code

These unit tests do not get complete code coverage. Also, they don't
check for memory errors. To do this through unit tests, instead of
using valgrid, would require adding unit test specific compilation
defines to the code, and compiling a seperate unit-test version.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
17 months agomultipathd: add new polling dmevents waiter thread
Benjamin Marzinski [Wed, 14 Mar 2018 17:46:44 +0000 (12:46 -0500)]
multipathd: add new polling dmevents waiter thread

The current method of waiting for dmevents on multipath devices involves
creating a seperate thread for each device. This can become very
wasteful when there are large numbers of multipath devices. Also, since
multipathd needs to grab the vecs lock to update the devices, the
additional threads don't actually provide much parallelism.

The patch adds a new method of updating multipath devices on dmevents,
which uses the new device-mapper event polling interface. This means
that there is only one dmevent waiting thread which will wait for events
on all of the multipath devices.  Currently the code to get the event
number from the list of device names and to re-arm the polling interface
is not in libdevmapper, so the patch does that work. Obviously, these
bits need to go into libdevmapper, so that multipathd can use a standard
interface.

I haven't touched any of the existing event waiting code, since event
polling was only added to device-mapper in version 4.37.0.  multipathd
checks this version, and defaults to using the polling code if
device-mapper supports it. This can be overridden by running multipathd
with "-w", to force it to use the old event waiting code.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
17 months agolibmultipath: add helper functions
Benjamin Marzinski [Wed, 14 Mar 2018 17:46:43 +0000 (12:46 -0500)]
libmultipath: add helper functions

Add the ability to reset a vector without completely freeing it, and to
check the version of the device-mapper module.  The existing version
checking code checks the version of a specific device mapper target, and
has been renamed for clarity's sake. These functions will be used in a
later patch.

Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
17 months agocall start_waiter_thread() before setup_multipath()
Benjamin Marzinski [Wed, 14 Mar 2018 17:46:42 +0000 (12:46 -0500)]
call start_waiter_thread() before setup_multipath()

If setup_multipath() is called before the waiter thread has started,
there is a window where a dm event can occur between when
setup_multipath() updates the device state and when the waiter thread
starts waiting for new events, causing the new event to be missed and
the multipath device to not get updated.

Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
17 months agomove waiter code from libmultipath to multipathd
Benjamin Marzinski [Wed, 14 Mar 2018 17:46:41 +0000 (12:46 -0500)]
move waiter code from libmultipath to multipathd

Only multipathd uses the code in waiter.[ch] and the functions that call
it directly, so they should all live in the multipathd directory.  This
patch is simply moving the waiter.[ch] files and the functions in
structs_vec that use them. None of the moved code has been changed.

Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
17 months agolibmultipath: move remove_map waiter code to multipathd
Benjamin Marzinski [Wed, 14 Mar 2018 17:46:40 +0000 (12:46 -0500)]
libmultipath: move remove_map waiter code to multipathd

Only multipathd needs to worry about the multipath waiter code. There is
no point in having remove_map_and_stop_waiter() or
remove_maps_and_stop_waiters() in libmultipath, since they should never
be use outside of multipathd.

Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
17 months agomultipathd: use nanosleep for strict timing
Benjamin Marzinski [Wed, 14 Mar 2018 17:46:39 +0000 (12:46 -0500)]
multipathd: use nanosleep for strict timing

In order to safely use SIGALRM in a multi-threaded program, only one
thread can schedule and wait on SIGALRM at a time. All other threads
must have SIGALRM blocked, and be unable to schedule an alarm. The
strict_timing code in checkerloop was unblocking SIGALRM, and calling
setitimer(), without any locking.  Instead, it should use nanosleep()
to sleep for the correct length of time, since that doesn't depend or
interfere with signals.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
17 months agolibmultipath: fix log_pthread processing
Benjamin Marzinski [Wed, 14 Mar 2018 17:46:38 +0000 (12:46 -0500)]
libmultipath: fix log_pthread processing

log_pthread() was waiting for notification on logev_cond, without
checking if it had already happened.  This means it could end up
waiting, while there is work that it should be doing.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
17 months agomultipathd: log thread cleanup
Benjamin Marzinski [Wed, 14 Mar 2018 17:46:37 +0000 (12:46 -0500)]
multipathd: log thread cleanup

The function log_thread_flush() is an exact copy of flush_lgoqueue(), so
both clearly don't need to exist. Also, There is no reason to make all
of the log thread variables global.  The only time any of them were
being used outside of log_thread.c, was to reset the log.  This code
should never be run if the log_thread isn't running, so it makes more
sense to live inside of log_thread.c

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
17 months agolibmultipath: set dm_conf_verbosity
Benjamin Marzinski [Wed, 14 Mar 2018 17:46:36 +0000 (12:46 -0500)]
libmultipath: set dm_conf_verbosity

dm_conf_verbosity was created to keep dm_write_log from needing
access to the multipath config. However it never was set.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
17 months agolibmultipath: fix basenamecpy
Benjamin Marzinski [Wed, 14 Mar 2018 17:46:35 +0000 (12:46 -0500)]
libmultipath: fix basenamecpy

basenamecpy was returning the wrong answer in multiple cases, as
shown by the unit tests for it. Now it will properly find the
basename (as defined by GNU basename, which works well for all of
multipath's uses) and return a copy, if the basename can fit in
provided buffer.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
17 months agoUnit tests for basenamecpy
Benjamin Marzinski [Wed, 14 Mar 2018 17:46:34 +0000 (12:46 -0500)]
Unit tests for basenamecpy

The current implementation of basenamecpy is broken, so some of these
tests currently fail. Fixes to follow.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
17 months agomultipath-tools: fix errors in auto generated man pages
Xose Vazquez Perez [Mon, 12 Mar 2018 20:52:43 +0000 (21:52 +0100)]
multipath-tools: fix errors in auto generated man pages

dmmp_path_blk_name_get.3:
<standard input>:14: warning: macro `nvme0n1'.' not defined

dmmp_mpath_kdev_name_get.3:
<standard input>:15: warning: macro `dm-1'.' not defined

Cc: Gris Ge <fge@redhat.com>
Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: device-mapper development <dm-devel@redhat.com>
Signed-off-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
18 months agoBump version to 0.7.6 0.7.6
Christophe Varoqui [Sat, 10 Mar 2018 07:28:38 +0000 (08:28 +0100)]
Bump version to 0.7.6

18 months agomultipath-tools: fix misspellings
Xose Vazquez Perez [Thu, 8 Mar 2018 23:08:48 +0000 (00:08 +0100)]
multipath-tools: fix misspellings

Done with https://github.com/lucasdemarchi/codespell

Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: device-mapper development <dm-devel@redhat.com>
Signed-off-by: Xose Vazquez Perez <xose.vazquez@gmail.com>