multipath-tools/.git
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
18 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
19 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>
20 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

20 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>
20 months agomultipath-tools: refresh kernel-doc from kernel sources
Xose Vazquez Perez [Thu, 8 Mar 2018 19:34:40 +0000 (20:34 +0100)]
multipath-tools: refresh kernel-doc from kernel sources

Bugs fixed and "get rid of unused output formats"
b05142675310d2ac80276569e151742f880e3ec3:

Since there isn't any docbook code anymore upstream,
we can get rid of several output formats:

- docbook/xml, html, html5 and list formats were used by
  the old build system;
- As ReST is text, there's not much sense on outputting
  on a different text format.

After this patch, only man and rst output formats are
supported.

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>
20 months agomultipath.conf(5): improve syntax documentation
Martin Wilck [Wed, 7 Mar 2018 23:26:20 +0000 (00:26 +0100)]
multipath.conf(5): improve syntax documentation

Describe the syntax of attribute / value pairs, comments, and quoted
strings, as well as the peculiarities of section beginnings and ends.
Also describe the newly added '""' feature.

Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agolibmultipath: config parser: fix corner case for double quotes
Martin Wilck [Wed, 7 Mar 2018 23:26:19 +0000 (00:26 +0100)]
libmultipath: config parser: fix corner case for double quotes

A corner case of the previous patch are strings starting with a double quote,
such as '"prepended to itself is false" prepended to itself is false' or
'"" is the empty string', and in particular, the string '"' ("\"" in C
notation), which is indistinguishable from the "QUOTE" token in the parsed strvec.

This patch fixes that by introducing a special token that can't occur as part
of a normal string to indicate the beginning and end of a quoted string.

'"' is admittedly not a very likely keyword value for multipath.conf, but
a) this is a matter of correctness, b) we didn't think of '2.5"' before, either, and
c) the (*str != '"') expressions would need to be patched anyway to fix the
'string starting with "' case.

Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agolibmultipath: config parser: Allow '"' in strings
Martin Wilck [Wed, 7 Mar 2018 23:26:18 +0000 (00:26 +0100)]
libmultipath: config parser: Allow '"' in strings

We have seen model strings lile '2.5" SSD' which can't be parsed
by the current config parser. This patch fixes this by allowing
'""' to represent a double quote character inside a a string.
The above model string could now be entered in the config file like this:

blacklist {
  vendor SomeCorp
  product "2.5"" SSD"
}

Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agolibmultipath: config parser: don't strip whitepace between quotes
Martin Wilck [Wed, 7 Mar 2018 23:26:17 +0000 (00:26 +0100)]
libmultipath: config parser: don't strip whitepace between quotes

Between double quotes, the parser currently strips leading (but not
trailing) whitespace. That's inconsistent and unexpected. Fix it.

Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agotests: add unit tests for config file parser
Martin Wilck [Wed, 7 Mar 2018 23:26:16 +0000 (00:26 +0100)]
tests: add unit tests for config file parser

Add test cases for parsing the config file.

Some of these tests currently fail. The patches that follow fix them.

Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agolibmultipath: uev_update_path: update path properties
Martin Wilck [Wed, 7 Mar 2018 23:21:52 +0000 (00:21 +0100)]
libmultipath: uev_update_path: update path properties

Update pp->udev and those path attributes that can be cheaply
updated from sysfs, i.e. without IO to the disk.

Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agolibmultipath: uev_update_path: always warn if WWID changed
Martin Wilck [Wed, 7 Mar 2018 23:21:51 +0000 (00:21 +0100)]
libmultipath: uev_update_path: always warn if WWID changed

Print the warning about changed WWID not only if disable_changed_wwids
is set, but always. It's actually more dangerous if that option is
not set.

Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agolibmultipath: get_uid: don't quit prematurely without udev
Martin Wilck [Wed, 7 Mar 2018 23:21:50 +0000 (00:21 +0100)]
libmultipath: get_uid: don't quit prematurely without udev

Not all the implemented methods to derive the UID rely on udev
information being present. For example getuid callout, rbd,
and the SCSI vpd code work fine without it. It's unlikely that
we don't get udev data, but we want to be as good as possible
at deriving the uid.

Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agolibmultipath: get_uid: check VPD pages for SCSI only
Martin Wilck [Wed, 7 Mar 2018 23:21:49 +0000 (00:21 +0100)]
libmultipath: get_uid: check VPD pages for SCSI only

The VPD code won't work for non-SCSI devices, anyway. For indentation
reasons, I moved the "retrigger_tries" case to a separate function,
which is also called only for SCSI devices.

Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agolibmultipath: remove FREE_CONST() again
Martin Wilck [Wed, 7 Mar 2018 23:15:51 +0000 (00:15 +0100)]
libmultipath: remove FREE_CONST() again

The FREE_CONST macro is of questionable value, as reviewers have pointed
out. The users of this macro were mostly functions that called
uevent_get_dm_xyz(). But these functions don't need to return const char*,
as they allocate the strings they return. So my change of the prototype
was wrong. This patch reverts it. The few other users of FREE_CONST can
also be reverted to use char* instead of const char* with negligible risk.

Fixes: "libmultipath: fix compiler warnings for -Wcast-qual"
Fixes: "libmultipath: const qualifier for wwid and alias"

(Note: this reverts changes not committed upstream. But as these changes are
deeply in the middle of my large-ish series of patches, it's probably easier
to simply add this patch on top than to rebase the whole series).

Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agolibmultipath: fix wrong output of "multipath -t"
Martin Wilck [Wed, 7 Mar 2018 23:15:50 +0000 (00:15 +0100)]
libmultipath: fix wrong output of "multipath -t"

The default values printed by "multipath -t" or "multipathd show config"
for "detect_prio", "detect_checker", and "retain_attached_hw_handler"
don't match the actual compiled-in defaults. Moreover, several other
options would also be displayed wrongly if the defaults were changed.

Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agoIntroduce the ibmultipath/unaligned.h header file
Bart Van Assche [Wed, 7 Mar 2018 23:15:49 +0000 (00:15 +0100)]
Introduce the ibmultipath/unaligned.h header file

This patch avoids that Coverity reports the following for the code
in libmultipath/prioritizers/alua_rtpg.c:

   CID 173256:  Integer handling issues  (SIGN_EXTENSION)
    Suspicious implicit sign extension: "buf[0]" with type "unsigned char" (8 bits, unsigned) is promoted in "((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]) + 4" to type "int" (32 bits, signed), then sign-extended to type "unsigned long" (64 bits, unsigned).  If "((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]) + 4" is greater than 0x7FFFFFFF, the upper bits of the result will all be 1.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agolibmultipath: Fix sgio_get_vpd()
Bart Van Assche [Wed, 7 Mar 2018 23:15:48 +0000 (00:15 +0100)]
libmultipath: Fix sgio_get_vpd()

Pass the VPD page number to sgio_get_vpd() such that the page needed
by the caller is queried instead of page 0x83. Fix the statement that
computes the length of the page returned by do_inq(). Fix the return
code check in the caller of sgio_get_vpd().

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agokpartx: Improve reliability of find_loop_by_file()
Bart Van Assche [Wed, 7 Mar 2018 23:15:47 +0000 (00:15 +0100)]
kpartx: Improve reliability of find_loop_by_file()

Avoid that the strchr() call in this function examines uninitialized
data on the stack. This patch avoids that Coverity reports the following:

    CID 173252:  Error handling issues  (CHECKED_RETURN)
    "read(int, void *, size_t)" returns the number of bytes read, but it is ignored.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agolibmultipath, alloc_path_with_pathinfo(): Ensure that pp->wwid is '\0'-terminated
Bart Van Assche [Wed, 7 Mar 2018 23:15:46 +0000 (00:15 +0100)]
libmultipath, alloc_path_with_pathinfo(): Ensure that pp->wwid is '\0'-terminated

Discovered by Coverity (CID 173257).

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agolibmultipath: enable feature disable changed wwid by default
Chongyun Wu [Wed, 7 Mar 2018 23:15:45 +0000 (00:15 +0100)]
libmultipath: enable feature disable changed wwid by default

enable feature disable changed wwid by default.

Signed-off-by: Chongyun Wu <wu.chongyun@h3c.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agomultipathd: add lock protection for cli_list_status
Chongyun Wu [Wed, 7 Mar 2018 23:15:44 +0000 (00:15 +0100)]
multipathd: add lock protection for cli_list_status

cli_list_status will access vecs->pathvec which should have lock
protection, otherwise might get inconsistent data or other
problem.

Signed-off-by: Chongyun Wu <wu.chongyun@h3c.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agomultipath-tools: reformat and update comments in hwtable
Xose Vazquez Perez [Wed, 7 Mar 2018 23:10:00 +0000 (00:10 +0100)]
multipath-tools: reformat and update comments in hwtable

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>
20 months agomultipath-tools: move Nimble and SGI to HPE section
Xose Vazquez Perez [Wed, 7 Mar 2018 23:09:59 +0000 (00:09 +0100)]
multipath-tools: move Nimble and SGI to HPE section

They were absorbed by HPE time ago.

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>
20 months agomultipath-tools: build: prevent intermediate file deletion
Martin Wilck [Wed, 7 Mar 2018 23:08:59 +0000 (00:08 +0100)]
multipath-tools: build: prevent intermediate file deletion

By default, "make" removes intermediate files from implicit rules
if they are the only dependency. Prevent that by using .SECONDARY.
Otherwise some files will be re-built upon second invocation of "make".

Fixes: e39283ebd79b "multipath-tools: add dependency tracking to Makefiles"
Reported-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agomultipath: fix clang warning in delegate_to_multipathd
Martin Wilck [Wed, 7 Mar 2018 23:08:58 +0000 (00:08 +0100)]
multipath: fix clang warning in delegate_to_multipathd

Fixes this warning from clang:

main.c:628:11: warning: variable 'reply' is used uninitialized
whenever 'if' condition is true [-Wsometimes-uninitialized]
...
main.c:609:32: note: initialize the variable 'reply' to silence this warning

Fixes: 506d253b7f89 "multipath: delegate dangerous commands to multipathd"
Reported-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agomultipathd: fix -Wpointer-to-int-cast warning in uxlsnr
Martin Wilck [Wed, 7 Mar 2018 23:08:57 +0000 (00:08 +0100)]
multipathd: fix -Wpointer-to-int-cast warning in uxlsnr

Fixes: "multipathd: release uxsocket and resource when cancel thread"
Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agolibmultipath: fix crash on shutdown if io_err thread isn't running
Martin Wilck [Wed, 7 Mar 2018 23:08:56 +0000 (00:08 +0100)]
libmultipath: fix crash on shutdown if io_err thread isn't running

If we've never created the io_error checker thread, we shouldn't
cancel it.

Fixes: 160da9fa4339 "multipathd: start marginal path checker thread
lazily"

Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agomultipath-tools: add info about how to get a release directly from gitweb
Xose Vazquez Perez [Fri, 12 Jan 2018 16:56:41 +0000 (17:56 +0100)]
multipath-tools: add info about how to get a release directly from gitweb

gitweb is able to extract and serve a release right away.

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>
20 months agoBump version to 0.7.5 0.7.5
Christophe Varoqui [Wed, 7 Mar 2018 09:52:25 +0000 (10:52 +0100)]
Bump version to 0.7.5

20 months agomultipathd: start marginal path checker thread lazily
Martin Wilck [Tue, 6 Mar 2018 21:18:42 +0000 (22:18 +0100)]
multipathd: start marginal path checker thread lazily

I noticed that the io_error checker thread accounts for most of the
activity of multipathd even if the marginal path checking paramters
are not set (which is still the default in most installations I assume).

Therefore, start the io_error checker thread only if there's at least
one map with marginal error path checking configured. Also, make sure
the thread is really up when start_io_err_stat_thread() returns.

This requires adding a "vecs" argument to setup_map, because vecs
needs to be passed to the io_error checking code.

Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agolibmultipath: fix race in stop_io_err_stat_thread
Martin Wilck [Tue, 6 Mar 2018 21:18:41 +0000 (22:18 +0100)]
libmultipath: fix race in stop_io_err_stat_thread

It's wrong, and unnecessary, to call pthread_kill after
pthread_cancel. I have observed cases where the io_err checker
thread hung in libpthread after receiving the USR2 signal, in particular
when multipathd is run under strace. (If multipathd is killed with
SIGINT under strace, and the io_error thread is running, it happens
almost every time). If this happens, the io_err thread
tries to obtain a mutex in the urcu code (presumably rcu_unregister_thread())
and the main thread hangs in pthread_join().

With the change from this patch, the thread is shut down cleanly. I haven't
observed the hang under strace with the patch.

Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agomultipathd: fix signal blocking logic
Martin Wilck [Mon, 5 Mar 2018 23:15:07 +0000 (00:15 +0100)]
multipathd: fix signal blocking logic

multipathd is supposed to block all signals in all threads, except
the uxlsnr thread which handles termination and reconfiguration
signals (SIGUSR1) in its ppoll() call, SIGUSR2 in the waiter thread
and the marginal path checker thread, and occasional SIGALRM. The current
logic does exactly the oppsite, it blocks termination signals in SIGPOLL and
allows multipathd to be killed e.g. by SIGALRM.

Fix that by inverting the logic. The argument to pthread_sigmask and
ppoll is the set of *blocked* signals, not vice versa.

The marginal paths code needs to unblock SIGUSR2 now explicity, as
the dm-event waiter code already does. Doing this with pselect()
avoids asynchronous cancellation.

Fixes: 810082e "libmultipath, multipathd: Rework SIGPIPE handling"
Fixes: 534ec4c "multipathd: Ensure that SIGINT, SIGTERM, SIGHUP and SIGUSR1
are delivered to the uxsock thread"

Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agomultipathd: update path group prio in check_path
Martin Wilck [Mon, 5 Mar 2018 23:15:06 +0000 (00:15 +0100)]
multipathd: update path group prio in check_path

The previous patch "libmultipath: don't update path groups when printing"
removed the call to path_group_prio_update() in the printing code path.
To compensate for that, recalculate path group prio also when it's not
strictly necessary (i.e. if failback "manual" is set).

Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agolibmultipath: foreign/nvme: implement path display
Martin Wilck [Mon, 5 Mar 2018 23:15:05 +0000 (00:15 +0100)]
libmultipath: foreign/nvme: implement path display

implement display of path information for NVMe foreign paths and maps.
With this patch, I get output like this for Linux NVMe soft targets:

nvme-submultipathd show topology
sys0:NQN:subsysname (uuid.96926ba3-b207-437c-902c-4a4df6538c3f) [nvme] nvme0n1 NVMe,Linux,4.15.0-r
size=2097152 features='n/a' hwhandler='n/a' wp=rw
`-+- policy='n/a' prio=n/a status=n/a
  |- 0:1:1 nvme0c1n1 0:0 n/a n/a live
  |- 0:2:1 nvme0c2n1 0:0 n/a n/a live
  |- 0:3:1 nvme0c3n1 0:0 n/a n/a live
  `- 0:4:1 nvme0c4n1 0:0 n/a n/a live

multipathd show paths format '%G %d %i %o %z %m %N'
foreign dev       hcil  dev_st serial           multipath host WWNN
[nvme]  nvme0c1n1 0:1:1 live   1c2c86659503a02f nvme0n1   rdma:traddr=192.168.201.101,trsvcid=4420
[nvme]  nvme0c2n1 0:2:1 live   1c2c86659503a02f nvme0n1   rdma:traddr=192.168.202.101,trsvcid=4420
[nvme]  nvme0c3n1 0:3:1 live   1c2c86659503a02f nvme0n1   rdma:traddr=192.168.203.101,trsvcid=4420
[nvme]  nvme0c4n1 0:4:1 live   1c2c86659503a02f nvme0n1   rdma:traddr=192.168.204.101,trsvcid=4420

(admittedly, I abused the 'WWNN' wildcard here a bit to display information
which is helpful for NVMe over RDMA).

Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agomultipathd: use foreign API
Martin Wilck [Mon, 5 Mar 2018 23:15:04 +0000 (00:15 +0100)]
multipathd: use foreign API

Call into the foreign library code when paths are discovered, uevents
are received, and in the checker loop. Furthermore, use the foreign
code to print information in the "multipathd show paths", "multipathd
show maps", and "multipathd show topology" client commands.

We don't support foreign data in the individual "show map" and "show path"
commands, and neither in the "json" commands. The former is a deliberate
decision, the latter could be added if desired.

Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agomultipath: use foreign API
Martin Wilck [Mon, 5 Mar 2018 23:15:03 +0000 (00:15 +0100)]
multipath: use foreign API

Use the "foreign" code to print information about multipath maps
owned by foreign libraries in print mode (multipath -ll, -l).

Signed-off-by: Martin Wilck <mwilck@suse.com>
20 months agolibmultipath: pathinfo: call into foreign library
Martin Wilck [Mon, 5 Mar 2018 23:15:02 +0000 (00:15 +0100)]
libmultipath: pathinfo: call into foreign library

This actually enables the use of foreign paths.

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