multipath-tools/.git
10 days agompathpersist: fix one more crash possiblity master
Benjamin Marzinski [Sat, 13 May 2017 05:44:58 +0000 (00:44 -0500)]
mpathpersist: fix one more crash possiblity

when mpathpersist goes to rollback reservations, it doesn't do a
rollback (and thus doesn't create a pthread) on paths that didn't
successfully create a reservation in the first place. It also doesn't
do any rollbacks at all if the last path in the multipath device was down,
which is completely broken. However it still tries to join these
non-existant pthreads, causing crashes.  To fix this, set the status to
-1 (now MPATH_PR_SKIP) on threadinfos that don't get rollbacks, and
remove the broken path state checking.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
10 days agoRemove a superfluous "extern" keyword
Bart Van Assche [Wed, 17 May 2017 15:43:09 +0000 (08:43 -0700)]
Remove a superfluous "extern" keyword

Since it is not necessary to use the "extern" keyword in front of
a function definition, remove that keyword.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
10 days agoMove the declaration of mpath_mx_alloc_len to a header file
Bart Van Assche [Wed, 17 May 2017 15:43:07 +0000 (08:43 -0700)]
Move the declaration of mpath_mx_alloc_len to a header file

This allows the compiler to verify consistency of declaration and
definition.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
10 days agoRemove mpath_reverse_8bytes_order()
Bart Van Assche [Wed, 17 May 2017 15:43:06 +0000 (08:43 -0700)]
Remove mpath_reverse_8bytes_order()

Since this function is not used, remove it.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
10 days agolibmpathpersist: Add two missing #include directives
Bart Van Assche [Wed, 17 May 2017 15:43:05 +0000 (08:43 -0700)]
libmpathpersist: Add two missing #include directives

Make sure that including mpathpr.h as the first header file does not
fail. Since mpath_updatepr.c defines functions declared in mpathpr.h,
include that header file in that .c file such that the compiler can
check consistency of the .h and the .c file.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
10 days agolibmultipath/configure.h: Add a forward declaration
Bart Van Assche [Wed, 17 May 2017 15:43:04 +0000 (08:43 -0700)]
libmultipath/configure.h: Add a forward declaration

This change avoids that the "#include "configure.h"" statements that
are added by the next patch trigger a compiler warning.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
10 days agoMakefile: Remove assignments to unused variables
Bart Van Assche [Wed, 17 May 2017 15:43:03 +0000 (08:43 -0700)]
Makefile: Remove assignments to unused variables

No multipath-tools source file or Makefile imports anything directly
from the kernel source tree. Hence remove the variables that refer to
the kernel tree.

Since the $(VERSION) Makefile macro is not used, remove it. Note:
the version number is defined as a macro in libmultipath/version.h.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
10 days agomultipath-tools: document uid_attribute for NVME devices
Xose Vazquez Perez [Thu, 11 May 2017 17:29:35 +0000 (19:29 +0200)]
multipath-tools: document uid_attribute for NVME devices

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>
10 days agompath_persist: Don't join threads that don't exist
Benjamin Marzinski [Tue, 9 May 2017 16:57:05 +0000 (11:57 -0500)]
mpath_persist: Don't join threads that don't exist

There are a couple of places in the mpath_persist code that were calling
pthread join, even if the pthread_create call failed, and the thread id
was undefined. This can cause crashes, so don't do it.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
10 days agokpartx: fix device checks
Benjamin Marzinski [Tue, 9 May 2017 16:57:04 +0000 (11:57 -0500)]
kpartx: fix device checks

There are a number of issues in the the kpartx device checking code.
First, it accepts files that are neither regular files or a block device
nodes (you can run kpartx on character devices or directories, and it
will treat them as block devices). When trying to figure out the
basename of a device, the code returns garbage if the path doesn't
include a '/'. Finally, the set_delimiter code can access memory outside
of the string if an empty string is passed in.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
10 days agolibmultipath: fix suspended devs from failed reloads
Benjamin Marzinski [Tue, 9 May 2017 16:57:03 +0000 (11:57 -0500)]
libmultipath: fix suspended devs from failed reloads

When multipath reloads a device, it can either fail while loading the
new table or while resuming the device. If it fails while resuming the
device, the device can get stuck in the suspended state.  To fix this,
multipath needs to resume the device again so that it can continue using
the old table.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
10 days agolibmultipath: refactor calls to get dm device info
Benjamin Marzinski [Tue, 9 May 2017 16:57:02 +0000 (11:57 -0500)]
libmultipath: refactor calls to get dm device info

Multipath has a number of functions that all do basically the same
thing to get members of the dm_info structure. This just refactors them
to use common code to do it.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
10 days agomultipathd: force reload device on all resizes
Benjamin Marzinski [Tue, 9 May 2017 16:57:01 +0000 (11:57 -0500)]
multipathd: force reload device on all resizes

My previous patch missed setting force_udev_reload on resizes initiated
by

multipathd resize map <map>

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
10 days agolibmultipath: print alias with no_path_retry message
Benjamin Marzinski [Tue, 9 May 2017 16:57:00 +0000 (11:57 -0500)]
libmultipath: print alias with no_path_retry message

the "flush_on_last_del in progress" message in select_no_path_retry
should print the device alias.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
10 days agomultipath-tools: fix compilation with gcc < 4.9
Martin Wilck [Wed, 17 May 2017 15:24:46 +0000 (17:24 +0200)]
multipath-tools: fix compilation with gcc < 4.9

gcc supports -fstack-protector-strong since v4.9 only. Add a "poor man's
autoconf" test to check whether the option is supported on the given
build system.

Fixes: 596f51f3
"multipath-tools: Replace -fstack-protector with -fstack-protector-strong"

Signed-off-by: Martin Wilck <mwilck@suse.com>
10 days agolibmultipath: print.c: make sure lines are 0-terminated
Martin Wilck [Wed, 17 May 2017 15:24:45 +0000 (17:24 +0200)]
libmultipath: print.c: make sure lines are 0-terminated

Under certain conditions, the output of "multipath -ll" or
"multipathd show topology", or the multipathd logs, may
contain garbage characters. Fix that by making sure that
the strings are always properly zero-terminated.

While touching this code, substitute a function for the
complex ENDLINE macro.

Note 1: The way this is coded, the previously written
character is overwritten by the newline. That behavior is
unchanged by this patch. I didn't want to fuzz with the
carefully crafted print.c code more than necessary at
this point.

Note 2: The condition (c <= line + len - 1) is equivalent to
(TAIL >= 0). It should always hold the way ENDLINE is called
after PRINT and PAD in print.c, and is only added as an
additional safeguard, e.g. against future code changes.

Signed-off-by: Martin Wilck <mwilck@suse.com>
10 days agokpartx: include sys/sysmacros.h
Martin Wilck [Mon, 15 May 2017 15:37:22 +0000 (17:37 +0200)]
kpartx: include sys/sysmacros.h

Finish the work started in ea436715. Fixes a compilation warning.

Signed-off-by: Martin Wilck <mwilck@suse.com>
10 days agokpartx: find_loop_by_file: use sysfs
Martin Wilck [Mon, 15 May 2017 15:37:21 +0000 (17:37 +0200)]
kpartx: find_loop_by_file: use sysfs

Rather then searching through all of /dev, look up loop devices
in /sys/devices/virtual/block. This is cleaner and more robust
(/dev/loop$Xp$Y symlinks may confuse kpartx).

Signed-off-by: Martin Wilck <mwilck@suse.com>
10 days agokpartx: use absolute path for regular files
Martin Wilck [Mon, 15 May 2017 15:37:20 +0000 (17:37 +0200)]
kpartx: use absolute path for regular files

kpartx supports being called for a regular file, in which
case it assumes that it should set up a loop device or use
an existing one. Because the loopinfo.lo_name field contains
an absolute path, matching with existing loop devices fails
for relative paths. Matching by basename only would be unreliable.

Therefore, convert relative to absolute path for regular files.

Signed-off-by: Martin Wilck <mwilck@suse.com>
10 days agokpartx: use partition UUID for non-DM devices
Martin Wilck [Mon, 15 May 2017 15:37:19 +0000 (17:37 +0200)]
kpartx: use partition UUID for non-DM devices

For dm devices, kpartx uses an UUID check at partition removal
to make sure it only deletes partitions it previously created.
Non-DM parent devices such as loop devices don't generally have
a UUID.

Introduce a "fake" UUID for these devices to make sure kpartx
deletes only devices it had created previously. Otherwise kpartx
might e.g. delete LVM LVs that are inside a device it is trying
to delete partitions for. It seems to be wiser to make sure the
user delete these manually before running "kpartx -d".

With the fake UUID in place, we can re-introduce the UUID check
for non-DM device that was removed in the earlier patch
"kpartx: dm_remove_partmaps: support non-dm devices".

This disables also deletion of partition mappings created
by earlier versions of kpartx. If kpartx has been updated after
partition mappings were created, the "-f" flag can be used
to force delting these partitions, too.

Signed-off-by: Martin Wilck <mwilck@suse.com>
10 days agolibmultipath: don't treat multi-linear mappings as partitions
Martin Wilck [Mon, 15 May 2017 15:37:18 +0000 (17:37 +0200)]
libmultipath: don't treat multi-linear mappings as partitions

dm_type is used in libmultipath only to check whether a mapping
is "linear", with the intention to test if it represents a
"partition". This test returns TRUE also for mappings with
multiple targets, the first of which happens to be a linear
mapping into the target device. This is questionable, it's
hard to assign a "type" to such maps anyway.

Fix this by returning an error for multi-target maps.
This is analogous to the patch
"kpartx: don't treat multi-linear mappings as partitions".

Signed-off-by: Martin Wilck <mwilck@suse.com>
10 days agokpartx: don't treat multi-linear mappings as partitions
Martin Wilck [Mon, 15 May 2017 15:37:17 +0000 (17:37 +0200)]
kpartx: don't treat multi-linear mappings as partitions

kpartx -d treats any map that has a "linear" mapping into a
device as first target as a partition of this device.
This is wrong, because linear mappings may consist of
several pieces, combining multiple devices into one
(LVM logical volumes are an example of such a
mapping). Partitions have to be single-target mappings.

Fix this by returning an error in dm_type() if a map with
multiple targets is encountered. The "type" of a map with
two or more targets is a difficult concept, anyway.

test case:
truncate -s 1G test0 test1
losetup /dev/loop0 test0
losetup /dev/loop1 test1
dmsetup create <<EOF
0 1000000 linear 7:0 4096
1000000 1000000 linear 7:1 4096
EOF
kpartx -d /dev/loop0 -v

The map "join" should NOT be deleted.

Signed-off-by: Martin Wilck <mwilck@suse.com>
10 days agokpartx: dm_devn: return error for non-existent device
Martin Wilck [Mon, 15 May 2017 15:37:16 +0000 (17:37 +0200)]
kpartx: dm_devn: return error for non-existent device

For non-existent maps (ENXIO from ioctl()), dm_task_run and
dm_task_get_info return success. We need to check info.exists.

Signed-off-by: Martin Wilck <mwilck@suse.com>
10 days agokpartx: dm_remove_partmaps: support non-dm devices
Martin Wilck [Mon, 15 May 2017 15:37:15 +0000 (17:37 +0200)]
kpartx: dm_remove_partmaps: support non-dm devices

Commit  3d709241 improved partition removal, but broke support
for handling partitions of non-dm devices such as loop devices
or RAM disks.

This requires passing the dev_t of the device down to
do_foreach_partmap(). Doing so, there's little use in trying
to derive major/minor numbers from the "mapname" any more
(which actually is the device name for non-DM devices).
But we can use this to find out whether the device in question
is a dm device.

The test for UUID match doesn't work for non-DM devices (this
shall be improved in a later patch in this series).

The test for equal name of parent dev and partition is only valid
for dm devices. For non-dm devices such as loop, "/dev/mapper/loop0"
could, theoretically, be a partition of "/dev/loop0"
(and we don't want to rely on map names).

Fixes: 3d709241 "kpartx: sanitize delete partitions"
Signed-off-by: Martin Wilck <mwilck@suse.com>
10 days agokpartx: relax and improve UUID check in dm_compare_uuid
Martin Wilck [Mon, 15 May 2017 15:37:14 +0000 (17:37 +0200)]
kpartx: relax and improve UUID check in dm_compare_uuid

It is wrong to assume that UUIDs of parent devices always contain
"mpath". Fix that, and make the check for the kpartx-specific prefix
"part%d-" stricter and more explicit.

Moreover, avoid duplication of string constants and properly express
the dependencies of the various constants.

Signed-off-by: Martin Wilck <mwilck@suse.com>
10 days agokpartx: remove is_loop_device
Martin Wilck [Mon, 15 May 2017 15:37:13 +0000 (17:37 +0200)]
kpartx: remove is_loop_device

This function is not used any more.

Signed-off-by: Martin Wilck <mwilck@suse.com>
10 days agokpartx: remove "no_partitions" support
Martin Wilck [Mon, 15 May 2017 15:37:12 +0000 (17:37 +0200)]
kpartx: remove "no_partitions" support

The kernel does not support the "no_partitions" feature - remove it.
Distributions who want to keep support for this feature should
re-enable it with a distro-specific patch.

Signed-off-by: Martin Wilck <mwilck@suse.com>
10 days agokpartx: test-kpartx: new unit test program
Martin Wilck [Mon, 15 May 2017 15:37:11 +0000 (17:37 +0200)]
kpartx: test-kpartx: new unit test program

This is a unit test program for kpartx, in particular for deleting
partitions.

NOTE: This test program fails with current kpartx; full patch series
needed to make it work.

Signed-off-by: Martin Wilck <mwilck@suse.com>
4 weeks agolibmultipath: force udev reloads
Benjamin Marzinski [Mon, 24 Apr 2017 22:39:30 +0000 (17:39 -0500)]
libmultipath: force udev reloads

Now that the multipath udev rules try harder to not do lvm scans or
kpartx runs unnecessarily, multipath needs to make sure that these do
run when they are wanted.  This patch makes sure that when a device is
force reloaded, or changes size, the MPATH_UDEV_RELOAD_FLAG isn't set.
This allows lvm scanning and kpartx runs to happen on these uevents.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
4 weeks agokpartx: default to running in sync mode
Benjamin Marzinski [Mon, 24 Apr 2017 22:39:29 +0000 (17:39 -0500)]
kpartx: default to running in sync mode

When users run kpartx, they would naturally assume that when it
completes, the devices have been created. However, kpartx runs in async
mode by default.  This seems like it is likely to trip up users.  So,
switch the default to sync mode, add a -n option to enable async mode,
and set async mode when kpartx is called by the udev rules.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
4 weeks agolibmultipath: fix partition detection
Benjamin Marzinski [Mon, 24 Apr 2017 22:39:28 +0000 (17:39 -0500)]
libmultipath: fix partition detection

The do_foreach_partmaps code could incorrectly list a device as a
partition of another device, because of two issues.  First, the check to
compare the dm UUID of two devices would allow two partition devices to
match, or a partition device to match with itself, instead of only
having a partition device match with the multipath device that it
belongs to.  Second, the code to check if a multipath device's
major:minor appeared in a partition device's table only used strstr
to check of the existance of the major:minor string. This meant that
any device with a minor number that started with the same digits would
match. for instance, checking for "253:10" would also match "253:102".

This patch fixes these issues.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
4 weeks agomultipath: fix up position independent code
Benjamin Marzinski [Mon, 24 Apr 2017 22:39:27 +0000 (17:39 -0500)]
multipath: fix up position independent code

The multipath binaries were not being compiled as position independent
executables (PIE).  This code fixes that, and makes other minor code
hardening tweaks to make hardening-check happier.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
4 weeks agomultipath: Merge the DELL MD3xxx device configs
Benjamin Marzinski [Mon, 24 Apr 2017 22:39:26 +0000 (17:39 -0500)]
multipath: Merge the DELL MD3xxx device configs

All of the Dell MD3xxx configs are identical, so we can just use one
config for them.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
6 weeks agoBump version to 0.7.1 0.7.1
Christophe Varoqui [Fri, 14 Apr 2017 08:38:29 +0000 (10:38 +0200)]
Bump version to 0.7.1

6 weeks agolibmultipath: fix skip_kpartx support for removing maps
Martin Wilck [Thu, 13 Apr 2017 13:05:48 +0000 (15:05 +0200)]
libmultipath: fix skip_kpartx support for removing maps

Commit 79a05a4e inadvertently removed the code necessary
to support multipath maps without partitions, as introduced
in b73a34ea "libmultipath: add skip_kpartx option". Revert
this part of the commit, so that skip_kpartx works again.

Fixes: 79a05a4e libmultipath: move suspend logic to _dm_flush_map
Signed-off-by: Martin Wilck <mwilck@suse.com>
6 weeks agoRevert "multipathd: set timeout for CLI commands correctly"
Martin Wilck [Thu, 13 Apr 2017 13:11:21 +0000 (15:11 +0200)]
Revert "multipathd: set timeout for CLI commands correctly"

This reverts commit a002d124723cef3f2bb4fc33899d2613bdfe3924.

uxsock_timeout is in ms (argument to poll()), whereas
parse_cmd() uses the value to add to tv_sec in a struct timespec.
So the previous code was correct.

Signed-off-by: Martin Wilck <mwilck@suse.com>
6 weeks agolibmultipath/propsel: Do not select sysfs prioritizer for RDAC arrays
Hannes Reinecke [Thu, 13 Apr 2017 15:39:48 +0000 (17:39 +0200)]
libmultipath/propsel: Do not select sysfs prioritizer for RDAC arrays

Recent RDAC (NetApp E-Series) firmware implemented an internal load
balancer and switched to implicit ALUA.
Unfortunately the load balancer relies on periodic REPORT TARGET PORT
GROUPS from the host, so we cannot use the sysfs prioritizer here.

References: bsc#1004858

Signed-off-by: Hannes Reinecke <hare@suse.com>
6 weeks agomultipath-tools: replace multipath configuration output
Xose Vazquez Perez [Sat, 8 Apr 2017 13:30:42 +0000 (15:30 +0200)]
multipath-tools: replace multipath configuration output

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>
6 weeks agoBump the version code and date 0.7.0
Christophe Varoqui [Wed, 12 Apr 2017 07:33:16 +0000 (09:33 +0200)]
Bump the version code and date

The uevents merging code justifies the version second digit bump.

6 weeks agomultipath-tools: amend text from multipath/multipath.conf.5
Xose Vazquez Perez [Tue, 28 Mar 2017 21:37:12 +0000 (23:37 +0200)]
multipath-tools: amend text from multipath/multipath.conf.5

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>
6 weeks agomultipath: fix segfault with disable_changed_wwids
Benjamin Marzinski [Fri, 7 Apr 2017 06:16:38 +0000 (01:16 -0500)]
multipath: fix segfault with disable_changed_wwids

When a path wwid changes, uev_update_path was dereferencing pp->mpp
without checking if it was NULL.

Cc: Shichangkuo <shi.changkuo@h3c.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
6 weeks agoRemove a trailing tab
Christophe Varoqui [Wed, 12 Apr 2017 07:24:01 +0000 (09:24 +0200)]
Remove a trailing tab

6 weeks agolibmultipath: don't set max_sectors_kb on reloads
Benjamin Marzinski [Fri, 7 Apr 2017 06:16:37 +0000 (01:16 -0500)]
libmultipath: don't set max_sectors_kb on reloads

Multipath was setting max_sectors_kb on the multipath device and all its
path devices both when the device was created, and when it was reloaded.
The problem with this is that while this would set max_sectors_kb on all
the devices under multipath, it couldn't set this on devices on top of
multipath.  This meant that if a user lowered max_sectors_kb on an
already existing multipath device with a LV on top of it, the LV could
send down IO that was too large for the new max_sectors_kb value,
because the LV was still using the old value.  The solution to this is
to only set max_sectors_kb to the configured value when the device is
originally created, not when it is later reloaded.  Since not all paths
may be present when the device is original created, on reloads multipath
still needs to make sure that the max_sectors_kb value on all the path
devices is the same as the value of the multipath device. But if this
value doesn't match the configuration value, that's o.k.

This means that the max_sectors_kb value for a multipath device won't
change after it have been initially created. All of the devices created
on top of the multipath device will inherit that value, and all of the
devices will use it all the way down, so IOs will never be mis-sized.

I also moved sysfs_set_max_sectors_kb to configure.c, since it is only
called from there, and it it makes use of static functions from there.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
6 weeks agomultipathd: allow devices to switch from RW to RO
Benjamin Marzinski [Fri, 7 Apr 2017 06:16:36 +0000 (01:16 -0500)]
multipathd: allow devices to switch from RW to RO

Whenever multipathd tries to reload a device, even if it's because a
path switched from read/write to read-only, it tries to load the device
read/write first, and then falls back to read-only. When device-mapper
sees that multipath is using the same devices in the same state in its
new table, it simply reuses the devices from the old table, instead of
closing and re-opening them. This means that multipath can successfully
reload the multipath device read/write, even if a path device has
switched to read-only.  To deal with this, multipathd now doesn't try to
reload a device read/write when it sees that a path device has switched
to read-only.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
6 weeks agomultipathd: drop lock before calling uev_add_path
Benjamin Marzinski [Fri, 7 Apr 2017 06:16:35 +0000 (01:16 -0500)]
multipathd: drop lock before calling uev_add_path

commit c6a18f4541d0a161e2f5fed8c67d9732bf512b37 made uev_update_path
call uev_add_path while holding the vecs lock, which is deadlocks, since
uev_add_path grabs the vecs lock itself.

Cc: Alban Browaeys <prahal@yahoo.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
6 weeks agolibdmmp: move libdmmp.pc install location
Benjamin Marzinski [Fri, 7 Apr 2017 06:16:34 +0000 (01:16 -0500)]
libdmmp: move libdmmp.pc install location

/usr/share/pkgconfig is for non-architecture specific modules, and
/usr/lib/pkgconfig is for architecture specific modules. libdmmp.pc is
architecture specific, so it belongs in /usr/lib/pkgconfig

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
6 weeks agomultipathd: don't call strlen on NULL variables
Benjamin Marzinski [Fri, 7 Apr 2017 06:16:33 +0000 (01:16 -0500)]
multipathd: don't call strlen on NULL variables

strlen has undefined results when passed a NULL variable, so don't do
it.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
6 weeks agolibdmmp: don't disconnect from multipathd twice
Benjamin Marzinski [Fri, 7 Apr 2017 06:16:32 +0000 (01:16 -0500)]
libdmmp: don't disconnect from multipathd twice

libdmmp already disconnects from multipathd at the end of the
dmmp_mpath_array_get, so it doesn't need to do it earlier in the
function as well.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
6 weeks agomultipath-tools: remove incdir from Makefiles
Benjamin Marzinski [Fri, 7 Apr 2017 06:16:31 +0000 (01:16 -0500)]
multipath-tools: remove incdir from Makefiles

Makefile.in defines both incdir and includedir, and they are both the
same. This patch removes incdir, and makes all the Makefiles use
includedir.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
6 weeks agolibdmmp: minor Makefile cleanup
Benjamin Marzinski [Fri, 7 Apr 2017 06:16:30 +0000 (01:16 -0500)]
libdmmp: minor Makefile cleanup

This patch deletes the "/" after $(DESTDIR) and removes
libdmmp_speed_test on 'make clean'

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agoRevert "multipath-tools: arrange compilation options for binaries"
Christophe Varoqui [Thu, 23 Mar 2017 09:07:44 +0000 (10:07 +0100)]
Revert "multipath-tools: arrange compilation options for binaries"

This reverts commit 324c3b960f361e2433874e5ed7f8f9125cce0b97.

If object or library AA needs a symbol from library BB, then AA
should come before library BB in the command-line invocation of the linker.

2 months agoRevert "multipath-tools: arrange compilation options for shared libs/objects"
Christophe Varoqui [Thu, 23 Mar 2017 09:07:09 +0000 (10:07 +0100)]
Revert "multipath-tools: arrange compilation options for shared libs/objects"

This reverts commit 2601add472837f9d0ba93271ac84c1ec8b4b4c43.

If object or library AA needs a symbol from library BB, then AA
should come before library BB in the command-line invocation of the linker.

2 months agomultipath-tools: arrange compilation options for shared libs/objects
Xose Vazquez Perez [Sat, 18 Mar 2017 17:45:00 +0000 (18:45 +0100)]
multipath-tools: arrange compilation options for shared libs/objects

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>
2 months agomultipath-tools: arrange compilation options for binaries
Xose Vazquez Perez [Fri, 17 Mar 2017 22:40:02 +0000 (23:40 +0100)]
multipath-tools: arrange compilation options for binaries

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>
2 months agomultipath-tools: build objects for libdmmp and libmpathpersist independently
Xose Vazquez Perez [Fri, 17 Mar 2017 15:21:46 +0000 (16:21 +0100)]
multipath-tools: build objects for libdmmp and libmpathpersist independently

libdmmp:
cc -c -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int -Werror=implicit-function-declaration -Werror=format-security -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -fPIC -DLIB_STRING=\"lib64\" -DRUN_DIR=\"run\" -I../libmultipath -I../libmpathpersist -I../libmpathcmd *.c
new:
cc -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int -Werror=implicit-function-declaration -Werror=format-security -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -fPIC -DLIB_STRING=\"lib64\" -DRUN_DIR=\"run\" -I../libmultipath -I../libmpathpersist -I../libmpathcmd -c -o mpath_persist.o mpath_persist.c
cc -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int -Werror=implicit-function-declaration -Werror=format-security -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -fPIC -DLIB_STRING=\"lib64\" -DRUN_DIR=\"run\" -I../libmultipath -I../libmpathpersist -I../libmpathcmd -c -o mpath_updatepr.o mpath_updatepr.c
cc -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int -Werror=implicit-function-declaration -Werror=format-security -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -fPIC -DLIB_STRING=\"lib64\" -DRUN_DIR=\"run\" -I../libmultipath -I../libmpathpersist -I../libmpathcmd -c -o mpath_pr_ioctl.o mpath_pr_ioctl.c

libmpathpersist:
cc -c -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int -Werror=implicit-function-declaration -Werror=format-security -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -fPIC -DLIB_STRING=\"lib64\" -DRUN_DIR=\"run\" -fvisibility=hidden -I../libdmmp -I../libmpathcmd -I/usr/include/json-c -c *.c
new:
cc -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int -Werror=implicit-function-declaration -Werror=format-security -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -fPIC -DLIB_STRING=\"lib64\" -DRUN_DIR=\"run\" -fvisibility=hidden -I../libdmmp -I../libmpathcmd -I/usr/include/json-c -c -o libdmmp.o libdmmp.c
cc -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int -Werror=implicit-function-declaration -Werror=format-security -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -fPIC -DLIB_STRING=\"lib64\" -DRUN_DIR=\"run\" -fvisibility=hidden -I../libdmmp -I../libmpathcmd -I/usr/include/json-c -c -o libdmmp_mp.o libdmmp_mp.c
cc -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int -Werror=implicit-function-declaration -Werror=format-security -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -fPIC -DLIB_STRING=\"lib64\" -DRUN_DIR=\"run\" -fvisibility=hidden -I../libdmmp -I../libmpathcmd -I/usr/include/json-c -c -o libdmmp_pg.o libdmmp_pg.c
cc -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int -Werror=implicit-function-declaration -Werror=format-security -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -fPIC -DLIB_STRING=\"lib64\" -DRUN_DIR=\"run\" -fvisibility=hidden -I../libdmmp -I../libmpathcmd -I/usr/include/json-c -c -o libdmmp_path.o libdmmp_path.c
cc -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int -Werror=implicit-function-declaration -Werror=format-security -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -fPIC -DLIB_STRING=\"lib64\" -DRUN_DIR=\"run\" -fvisibility=hidden -I../libdmmp -I../libmpathcmd -I/usr/include/json-c -c -o libdmmp_misc.o libdmmp_misc.c

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>
2 months agomultipath-tools: add missing "-l" flag for pthread in libdmmp/Makefile
Xose Vazquez Perez [Fri, 17 Mar 2017 14:15:23 +0000 (15:15 +0100)]
multipath-tools: add missing "-l" flag for pthread in libdmmp/Makefile

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>
2 months agomultipath-tools: Remove trailing whitespaces
Xose Vazquez Perez [Fri, 17 Mar 2017 00:35:03 +0000 (01:35 +0100)]
multipath-tools: Remove trailing whitespaces

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>
2 months agoMake libdmmp build optional
Martin Wilck [Tue, 28 Feb 2017 16:23:29 +0000 (17:23 +0100)]
Make libdmmp build optional

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath/checkers: make RADOS checker optional
Martin Wilck [Tue, 28 Feb 2017 16:23:28 +0000 (17:23 +0100)]
libmultipath/checkers: make RADOS checker optional

Some distros lack the rados header files. Use
"make ENABLE_RADOS=0" on such distributions to build
multipath-tools in such cases. The default (to enable RADOS
support) remains unchanged.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipathd: fixup check for new path states
Hannes Reinecke [Tue, 28 Feb 2017 16:23:27 +0000 (17:23 +0100)]
multipathd: fixup check for new path states

When testing for new path states we should be making sure to
always using the same path state mask. Otherwise we'll miss
out any states.

Signed-off-by: Hannes Reinecke <hare@suse.com>
2 months agotur: Add pthread_testcancel()
Hannes Reinecke [Tue, 28 Feb 2017 16:23:26 +0000 (17:23 +0100)]
tur: Add pthread_testcancel()

When the ioctl returns we need to check if a cancellation has
been requested; otherwise we'd be re-setting the state and
overwrite any pending values.

Signed-off-by: Hannes Reinecke <hare@suse.com>
2 months agokpartx: sanitize delete partitions
Hannes Reinecke [Tue, 28 Feb 2017 16:23:25 +0000 (17:23 +0100)]
kpartx: sanitize delete partitions

kpartx has a rather braindead method for deleting partitions;
generating 'possible' partition names and trying to remove all
of them.
With this patch kpartx looks at the device-mapper devices on top
of the referenced device, and removes them if they found to be
kpartx-generated devices.

Signed-off-by: Hannes Reinecke <hare@suse.com>
2 months agolibmultipath: coalesce_paths: trigger uevent if nothing done
Martin Wilck [Tue, 28 Feb 2017 16:23:24 +0000 (17:23 +0100)]
libmultipath: coalesce_paths: trigger uevent if nothing done

The previous patches skip RELOAD actions if there's nothing
to be done. I found a corner case where this may lead to imporperly
initialized device nodes (in my case a by-label link hadn't been
reset to the partition on the multipath device by udev).
Triggering an extra "change" event on the device fixes
this situation.

Signed-off-by: Martin Wilck <mwilck@suse.de>
2 months agolibmultipath: differentiate ACT_NOTHING and ACT_IMPOSSIBLE
Martin Wilck [Tue, 28 Feb 2017 16:23:23 +0000 (17:23 +0100)]
libmultipath: differentiate ACT_NOTHING and ACT_IMPOSSIBLE

select_action uses ACT_NOTHING for two different cases,
1) if changes can't be applied for some reason, and
2) if nothing needs to be done. Introduce ACT_IMPOSSIBLE
for case 1).

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: reload map if not known to udev
Martin Wilck [Tue, 28 Feb 2017 16:23:22 +0000 (17:23 +0100)]
libmultipath: reload map if not known to udev

The previous changes skip map reload if the existing kernel
state appears correct. Sometimes, boot time race conditions
may cause a device to be correctly set up in the kernel but
not in udev. Check this condition, and reload map in this case.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: sysfs_attr_set_value: use const char*
Martin Wilck [Tue, 28 Feb 2017 16:23:21 +0000 (17:23 +0100)]
libmultipath: sysfs_attr_set_value: use const char*

The value argument in syfs_attr_set_value should be const char*.

Signed-off-by: Martin Wilck <mwilck@suse.de>
2 months agolibmultipath: select_action: check special features separately
Martin Wilck [Tue, 28 Feb 2017 16:23:20 +0000 (17:23 +0100)]
libmultipath: select_action: check special features separately

The features queue_if_no_path and retain_attached_hw_handler are
treated separately in libmultipath. Compare these features by looking
at the respective flags, and ignore them when comparing the "features"
string. assemble_map() does the ssame thing when constructing the
features string for device mapper.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: disassemble_map: treat minio like assemble_map does
Martin Wilck [Tue, 28 Feb 2017 16:23:19 +0000 (17:23 +0100)]
libmultipath: disassemble_map: treat minio like assemble_map does

Rather than using 0 for everything except round-robin, read back
the actual minio value from DM.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: disassemble_map: skip no_path_retry check
Martin Wilck [Tue, 28 Feb 2017 16:23:18 +0000 (17:23 +0100)]
libmultipath: disassemble_map: skip no_path_retry check

mpp->no_path_retry is already checked in setup_feature() itself,
no need to do it here as well. This allows using setup_feature()
for other features except queue_if_no_path.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: setup_feature: handle "retain_attached_hw_handler"
Martin Wilck [Tue, 28 Feb 2017 16:23:17 +0000 (17:23 +0100)]
libmultipath: setup_feature: handle "retain_attached_hw_handler"

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: setup_feature: print log msg if no_path_retry cant be set
Martin Wilck [Tue, 28 Feb 2017 16:23:16 +0000 (17:23 +0100)]
libmultipath: setup_feature: print log msg if no_path_retry cant be set

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: setup_features: log msg if queue_if_no_path is ignored
Martin Wilck [Tue, 28 Feb 2017 16:23:15 +0000 (17:23 +0100)]
libmultipath: setup_features: log msg if queue_if_no_path is ignored

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipathd: use weaker "force_reload" at startup
Martin Wilck [Tue, 28 Feb 2017 16:23:14 +0000 (17:23 +0100)]
multipathd: use weaker "force_reload" at startup

"force_reload" has originally been created to support multipath -r
(admin triggered reload). multipathd also uses this parameter
in DAEMON_CONFIGURE state, too. But this is causes unnecessary
device-mapper ioctls when multipathd is first started, if existing
maps have been discovered (perhaps set up by previous instance of
multipathd, e.g. in the initrd).

This patch introduces a weaker form of the force_reload parameter
to coalesce_paths(). The parameter can now take three values:
 * FORCE_RELOAD_NONE: existing maps aren't touched at all
 * FORCE_RELOAD_YES: all maps are rebuilt from scratch and (re)loaded in DM
 * FORCE_RELOAD_WEAK: existing maps are compared to the current conf and only
   reloaded in DM if there's a difference. This is useful during startup.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipathd: imply -n if find_multipaths is set
Martin Wilck [Tue, 28 Feb 2017 16:23:13 +0000 (17:23 +0100)]
multipathd: imply -n if find_multipaths is set

Automatic detection of new devices with find_multipaths
doesn't work correctly currently. Therefore, for now,
imply ignore_new_devs if find_multipaths is seen.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipath: ignore -i if find_multipaths is set
Martin Wilck [Tue, 28 Feb 2017 16:23:12 +0000 (17:23 +0100)]
multipath: ignore -i if find_multipaths is set

multipath's logic for detecing new multipath devices with find_multipaths
currently doesn't work reliably. If paths for a new device are added
sequentially, the first one will be classified as non-multpath (and passed on
to systemd for further processing) while subsequent ones will be seen as
multipath devices. If the paths are added simultaneously (such as at udev
trigger time after switching from the initrd to the rootfs, if device
detection is already finished), whether or not additional paths will be seen
when the udev rules for a given paths are processed is random.
A proper implementation of this device detection would require some sort of
information passing between multipathd and multipath, timeouts waiting for
additional paths to appear when a single one is detected, retriggering of
uevents if the status of a given paths changes, and more fine-grained
treatment of "orphaned" paths in multipathd. All of that is currently
non-existent.

Currently, our only option is to rely on the wwids file for device setup with
find_multipaths. In practice, that means that multipath maps will only be
set up for such devices that have been set up manually by the user before.
This is the behavior of multipath [-c|-u] without the "-i" option.

But "-i" is useful for the !find_multipaths case, where the expectation is
that all non-blacklisted devices are multipathed by default. Because we
can't change the multipath invocation in the udev rules file
depending on the find_multipaths setting, just ignore "-i" if find_multipaths
is set.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: move suspend logic to _dm_flush_map
Martin Wilck [Tue, 28 Feb 2017 16:23:11 +0000 (17:23 +0100)]
libmultipath: move suspend logic to _dm_flush_map

The function dm_suspend_and_flush() introduced in 9a4ff93
tries to remove child maps (partitions) after suspending
the mpath device. This may lock up if removing the partitions
requires I/O. It's better to use the following sequence
of actions: 1) clear queue_if_no_path; 2) remove partitions;
3) suspend; 4) remove (or resume and restore queue_if_no_path
in case of failure).

This patch modifies the implementation by moving the
queue_if_no_path/suspend logic into _dm_flush_map().
A call to _dm_flush_map() with need_suspend=1 replaces
the previous call to dm_suspend_and_flush().

With this change, the mpath device is only suspended after
removing partmaps, avoiding the deadlock.

Fixes: 9a4ff93 "Switch off 'queue_if_no_path' before removing maps"
Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipath -ll: set DI_SERIAL
Martin Wilck [Tue, 28 Feb 2017 16:23:10 +0000 (17:23 +0100)]
multipath -ll: set DI_SERIAL

Without DI_SERIAL, multipath -ll will not be able to obtain correct
PG priorities in certain configurations (e.g. prio "weightedpath",
prio_args "serial..."). We do not set DI_SERIAL for the multipath -l
case, where information is supposed to come from sysfs+device mapper
only.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agolibmultipath: use existing alias from bindings file
Hannes Reinecke [Tue, 28 Feb 2017 16:23:09 +0000 (17:23 +0100)]
libmultipath: use existing alias from bindings file

If the bindings file has been edited by hand not all entries conform
to the user_friendly_prefix setting. So if we don't find a matching
alias we need to check if the wwid is set to a different alias; if
so we need to use that.
Otherwise we'll end up with duplicate entries in the bindings file.

Signed-off-by: Hannes Reinecke <hare@suse.com>
2 months agolibmultipath/discovery: do not cache 'access_state' sysfs attribute
Hannes Reinecke [Tue, 28 Feb 2017 16:23:08 +0000 (17:23 +0100)]
libmultipath/discovery: do not cache 'access_state' sysfs attribute

When reading the 'access_state' sysfs attribute we should not be
using libudev as this will cache the value, causing us to lose
any update to the attribute.

Signed-off-by: Hannes Reinecke <hare@suse.com>
2 months agomultipathd: issue systemd READY after initial configuration
Hannes Reinecke [Tue, 28 Feb 2017 16:23:07 +0000 (17:23 +0100)]
multipathd: issue systemd READY after initial configuration

We should be issueing systemd READY only after the initial
configuration has been completed, otherwise systemd might
continue while the multipath devices are not setup up properly.

Signed-off-by: Hannes Reinecke <hare@suse.com>
2 months agomultipath: avoid crash when using modified configuration
Hannes Reinecke [Tue, 28 Feb 2017 16:23:06 +0000 (17:23 +0100)]
multipath: avoid crash when using modified configuration

Occasionally multipath would crash when using a modified configuration.

Signed-off-by: Hannes Reinecke <hare@suse.com>
2 months agomultipathd: Set CLI timeout correctly
Hannes Reinecke [Tue, 28 Feb 2017 16:23:05 +0000 (17:23 +0100)]
multipathd: Set CLI timeout correctly

When calling 'multipathd cmd' the CLI timeout isn't set correctly;
calling "multipathd -k'cmd'" uses the correct timeout.
And the default timeout should be increased to 4 seconds to ensure
multipath runs correctly on large installations.

Signed-off-by: Hannes Reinecke <hare@suse.com>
2 months agolibmultipath: Do not crash on empty features
Hannes Reinecke [Tue, 28 Feb 2017 16:23:04 +0000 (17:23 +0100)]
libmultipath: Do not crash on empty features

When adding to an otherwise empty feature list multipath would
crash as it doesn't check for an empty feature list.

Signed-off-by: Hannes Reinecke <hare@suse.com>
2 months agolibmultipath: fall back to search paths by devt
Hannes Reinecke [Tue, 28 Feb 2017 16:23:03 +0000 (17:23 +0100)]
libmultipath: fall back to search paths by devt

When removing path the device might already be gone from sysfs,
so we cannot lookup the device name. However, we still should
have the path vector available, so we should be trying to look
it up by using the device number.

Signed-off-by: Hannes Reinecke <hare@suse.com>
2 months agomultipathd: set timeout for CLI commands correctly
Hannes Reinecke [Tue, 28 Feb 2017 16:23:02 +0000 (17:23 +0100)]
multipathd: set timeout for CLI commands correctly

The CLI command timeout wasn't set correctly for CLI commands,
causing it to timeout prematurely before the CLI response
could be received.

Signed-off-by: Hannes Reinecke <hare@suse.com>
2 months agoInvalid error code when using multipathd CLI
Hannes Reinecke [Tue, 28 Feb 2017 16:23:01 +0000 (17:23 +0100)]
Invalid error code when using multipathd CLI

When calling the multipathd CLI we're getting the message

error -1 receiving packet

instead of the actual error number.
Problem is a confusion about the return values between
libmpathcmd and uxsock.c.
uxsock.c is assuming a negative return value to be the errno,
but libmpathcmd is returning -1 on error and setting errno.

Signed-off-by: Hannes Reinecke <hare@suse.com>
2 months agomultipath: do not check daemon from udev rules
Hannes Reinecke [Tue, 28 Feb 2017 16:23:00 +0000 (17:23 +0100)]
multipath: do not check daemon from udev rules

As stated previously, multipathd needs to start after udev trigger
has run as otherwise it won't be able to find any devices.
However, this also means that during udevadm trigger the daemon
wouldn't run, and consequently the check in the udev rules will
always be false, causing the device not to be marked as multipath
capable.

As it turns out, calling 'multipath' from udev rules has quite some
challenges. It _should_ check if a device is eligible for multipathing.
But it needs to work under all circumstances, even if the daemon isn't
running yet, as the program will be called from uevents which might
(and will) come in before the daemon is running.
To check if the daemon _should_ be run I'm checking the various
'.wants' directories from systemd, which carries links to the services
systemd will enable eventually. So if the multipathd.service is
listed in there it will be started, even if it isn't started yet.

Signed-off-by: Hannes Reinecke <hare@suse.com>
2 months agoAdd support for "multipath=off" and "nompath" on kernel cmdline
Martin Wilck [Tue, 28 Feb 2017 16:22:59 +0000 (17:22 +0100)]
Add support for "multipath=off" and "nompath" on kernel cmdline

Add support for disabling multipathd startup from the kernel command line.
This is useful for debugging purposes.

Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipathd: start daemon after udev trigger
Hannes Reinecke [Tue, 28 Feb 2017 16:22:58 +0000 (17:22 +0100)]
multipathd: start daemon after udev trigger

As multipath now relies on udev for device enumeration it needs
to be started after udev trigger has finished sending all events.
Otherwise the daemon will not find any devices during startup
(as udev trigger hasn't been called yet and the udev database is empty).
But after switchover from the initrd there will already be some
multipath device-mapper tables, for which the daemon cannot find
any device. Consequently the daemon will be removing these tables,
only to recreate them later on once udev trigger has run.
This induces a short window during which the device mapper devices
won't be present, causing systemd to umount devices or drop into
emergency mode.

Signed-off-by: Hannes Reinecke <hare@suse.com>
2 months agomultipathd.service: fixup Wants= and Before= statements
Hannes Reinecke [Tue, 28 Feb 2017 16:22:57 +0000 (17:22 +0100)]
multipathd.service: fixup Wants= and Before= statements

With the latest LVM2 update we now have the 'lvm2-lvmetad.service'.
Also we need to specify 'blk-availability.service' in the 'Before='
statement, as just adding it to 'Wants=' assumes the multipathd
service should be running after the blk-availability service.

Signed-off-by: Hannes Reinecke <hare@suse.com>
2 months agomultipath-tools: libdmmp: Fix incorrect use of __attribute__
Gris Ge [Sat, 11 Mar 2017 14:12:14 +0000 (22:12 +0800)]
multipath-tools: libdmmp: Fix incorrect use of __attribute__

According to https://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html ,
type attributes should be placed immediately after the struct, union or
enum keyword.

Signed-off-by: Gris Ge <fge@redhat.com>
2 months agomultipath-tools: clean up libdmmp/Makefile
Xose Vazquez Perez [Mon, 13 Mar 2017 16:47:31 +0000 (17:47 +0100)]
multipath-tools: clean up libdmmp/Makefile

Replace LDFLAGS with LIBDEPS, build libdmmp shared library without CFLAGS

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>
2 months agomultipathd: fix SIGUSR2 handling
tang.junhui [Thu, 29 Dec 2016 07:56:14 +0000 (15:56 +0800)]
multipathd: fix SIGUSR2 handling

SIGUSR2 is not blocked by default, it would cause bellow conflict
in removing of the last path:
-------------------------------------------------------------
uevent processing thread                 | waiter thread
-----------------------------------------|-------------------
uev_remove_path()                        |   waiteventloop()
  lock(&vecs->lock)                      |
  ev_remove_path()                       |
    dm_queue_if_no_path()----------------|----> dm_task_run()
    flush_map()                          |      |
      remove_map_and_stop_waiter()       |      -> pthread_cleanup_push(cleanup_lock, &waiter->vecs->lock);
        _remove_map()                    |         lock(&waiter->vecs->lock)//wait for the locker
          stop_waiter_thread()           |
            pthread_cancel(thread)       |
            pthread_kill(thread,SIGUSR2)-|------> sigusr2 (int sig)
                                         |          condlog()
                                         |          fprintf() //it has test cancel point
                                         |          cleanup_lock() //thread cancel, and pop, which unlock the
                                         |                           locker of uevent processing thread
--------------------------------------------------------------
Since SIGUSR2 is only needed when waiter thread running in dm_task_run(),
and it has already been unblocked before dm_task_run(), so this patch block
SIGUSR2 for other times.

Change-Id: I8c46292dc954415764ebbe054498b4f7ea53c1c6
Signed-off-by: tang.junhui <tang.junhui@zte.com.cn>
2 months agouevent_can_discard: optimize devpath check
Martin Wilck [Wed, 1 Mar 2017 17:22:19 +0000 (18:22 +0100)]
uevent_can_discard: optimize devpath check

This uses roughly 10% cycles of the sscanf-based implementation.

Improves: ee8888f0 "multipath-tools: improve processing efficiency..."
Signed-off-by: Martin Wilck <mwilck@suse.com>
2 months agomultipath-tools: improve processing efficiency for addition and deletion of multipath...
tang.junhui [Tue, 28 Feb 2017 07:05:49 +0000 (15:05 +0800)]
multipath-tools: improve processing efficiency for addition and deletion of multipath devices

This patch used to improve processing efficiency for addition and deletion
of multipath devices.

This patch is tested pass by ZTE multipath automatic testing system.
The modification reduces the system consumption(such as CPU) and shortens
the processing time obviously in scene of massive multipath devices
addition or deletion.

The main processing flow of code is:
1) add uid_attrs configuration in the defaults section:
   It is configured udev attribute which providing a unique path identifier
   for corresponding type of path devices. If this field is configured and
   matched with type of device, it would override any other methods
   providing for device unique identifier in config file, and it would
   activate merging uevents according to the identifier to promote effiecncy
   in processing uevents. Tt has no default value, so defaultly only uevents
   filtering works, and uevents merging does not works, if users want to
   identify path by udev attribute and to activate merging uevents for SCSI
   and DAS device, they can set it's value as:
   "sd:ID_SERIAL dasd:ID_UID"
2) uevents accumulation in uevents burst scene:
   wait one seconds for more uevents in uevent_listen() in uevents burst
   situations
3) uevents preparing, filtering and merging:
   discard unuse uevents and fetch path idendifier from uevents;
   filter uevents;
   merge uevents.
4) uevents proccessing:
   proccess the merged uevents in uev->merge_node list without calling
   domap();
   proccess the last uevents uev with calling domap().

Signed-off-by: tang.junhui <tang.junhui@zte.com.cn>
2 months agoAvoid that reloading a map sporadically triggers I/O errors
Bart Van Assche [Fri, 18 Nov 2016 21:33:44 +0000 (13:33 -0800)]
Avoid that reloading a map sporadically triggers I/O errors

Avoid that reloading a map while there are no paths triggers a flush
and hence unwanted I/O errors if 'queue_if_no_path' is enabled.

Fixes: commit d569988e7528 ("libmultipath: Fixup 'DM_DEVICE_RELOAD' handling")
Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: Hannes Reinecke <hare@suse.de>
2 months agofix udev rules for failed multipath devices
Benjamin Marzinski [Mon, 27 Feb 2017 18:26:43 +0000 (12:26 -0600)]
fix udev rules for failed multipath devices

11-dm-mpath.rules was only correctly dealing with the case where the
multipath device was unusable because the last path had failed.  If
instead, the last working path was removed from the device on a table
reload, it was not correctly marking the device as unusable. One problem
with fixing this is that when the device table is reloaded,
device-mapper doesn't know if the path devices are usable or not.  To
deal with this, multipath now flags reloads with no usable paths with
DM_SUBSYSTEM_UDEV_FLAG2.

11-dm-mpath.rules now checks for both PATH_FAILED events and reloads
with no valid paths. and disables the other rules.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agomultipathd: allow resetting stats
Benjamin Marzinski [Mon, 27 Feb 2017 18:26:42 +0000 (12:26 -0600)]
multipathd: allow resetting stats

This patch adds two multipathd interactive commands:

multipathd reset maps stats

and

multipathd reset map <map> stats

to reset the statistics that are shown with the "show stats" commands.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agomultipathd: add messages on delayed path addition
Benjamin Marzinski [Mon, 27 Feb 2017 18:26:41 +0000 (12:26 -0600)]
multipathd: add messages on delayed path addition

When multipath delays adding a path because the device is waiting for
udev to finish initialization, it now logs a message, so the users
know what happened to the path.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
2 months agomultipathd: don't update priority of failed paths
Benjamin Marzinski [Mon, 27 Feb 2017 18:26:40 +0000 (12:26 -0600)]
multipathd: don't update priority of failed paths

Multipathd shouldn't be updating the priority of failed paths in the
checkerloop. The current avoids this in almost all cases, but not all.
Close the loophole.

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