Linux Device Mapper development
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: Christophe Varoqui <christophe.varoqui@gmail.com>
Cc: dm-devel@redhat.com
Subject: [PATCH 22/78] multipath: implement option '-u' for uevents
Date: Mon, 16 Mar 2015 13:36:09 +0100	[thread overview]
Message-ID: <1426509425-15978-23-git-send-email-hare@suse.de> (raw)
In-Reply-To: <1426509425-15978-1-git-send-email-hare@suse.de>

When calling 'multipath' from an uevent udev will not have
all information for that device, as it's being written into
the database _after_ the event has been processed.
This patch implements an option '-u' which uses the information
from the program environment when checking the device.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 libmultipath/config.c      |  1 +
 libmultipath/config.h      |  3 ++-
 libmultipath/configure.c   | 28 ++++++++++++++++++++++++++--
 libmultipath/log_pthread.c |  2 +-
 multipath/main.c           | 21 ++++++++++++++++++---
 multipath/multipath.8      |  6 +++++-
 multipath/multipath.rules  |  2 +-
 7 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/libmultipath/config.c b/libmultipath/config.c
index 79c6bc1..1007f32 100644
--- a/libmultipath/config.c
+++ b/libmultipath/config.c
@@ -617,6 +617,7 @@ load_config (char * file, struct udev *udev)
 	conf->partition_delim = NULL;
 	conf->processed_main_config = 0;
 	conf->find_multipaths = DEFAULT_FIND_MULTIPATHS;
+	conf->uid_attribute = set_default(DEFAULT_UID_ATTRIBUTE);
 
 	/*
 	 * preload default hwtable
diff --git a/libmultipath/config.h b/libmultipath/config.h
index a680e2b..d304a6c 100644
--- a/libmultipath/config.h
+++ b/libmultipath/config.h
@@ -19,7 +19,8 @@ enum devtypes {
 	DEV_NONE,
 	DEV_DEVT,
 	DEV_DEVNODE,
-	DEV_DEVMAP
+	DEV_DEVMAP,
+	DEV_UEVENT
 };
 
 enum mpath_cmds {
diff --git a/libmultipath/configure.c b/libmultipath/configure.c
index c9f16c7..a30ca59 100644
--- a/libmultipath/configure.c
+++ b/libmultipath/configure.c
@@ -957,8 +957,8 @@ get_refwwid (char * dev, enum devtypes dev_type, vector pathvec, char **wwid)
 			udev_device_unref(udevice);
 			if (!pp) {
 				if (ret == 1)
-					condlog(0, "%s can't store path info",
-						buff);
+					condlog(0, "%s: can't store path info",
+						dev);
 				return ret;
 			}
 		}
@@ -995,6 +995,30 @@ get_refwwid (char * dev, enum devtypes dev_type, vector pathvec, char **wwid)
 		refwwid = pp->wwid;
 		goto out;
 	}
+
+	if (dev_type == DEV_UEVENT) {
+		struct udev_device *udevice = udev_device_new_from_environment(conf->udev);
+
+		if (!udevice) {
+			condlog(2, "%s: can't get udev device", dev);
+			return 1;
+		}
+		ret = store_pathinfo(pathvec, conf->hwtable, udevice,
+				     DI_SYSFS | DI_WWID, &pp);
+		udev_device_unref(udevice);
+		if (!pp) {
+			if (ret == 1)
+				condlog(0, "%s: can't store path info",
+					dev);
+			return ret;
+		}
+		if (pp->udev && filter_property(conf, pp->udev) > 0)
+			return 2;
+
+		refwwid = pp->wwid;
+		goto out;
+	}
+
 	if (dev_type == DEV_DEVMAP) {
 
 		if (((dm_get_uuid(dev, tmpwwid)) == 0) && (strlen(tmpwwid))) {
diff --git a/libmultipath/log_pthread.c b/libmultipath/log_pthread.c
index 47d75a1..e6f4b5c 100644
--- a/libmultipath/log_pthread.c
+++ b/libmultipath/log_pthread.c
@@ -25,7 +25,7 @@ int logq_running;
 void log_safe (int prio, const char * fmt, va_list ap)
 {
 	if (log_thr == (pthread_t)0) {
-		syslog(prio, fmt, ap);
+		vsyslog(prio, fmt, ap);
 		return;
 	}
 
diff --git a/multipath/main.c b/multipath/main.c
index dadbb2a..08ba66c 100644
--- a/multipath/main.c
+++ b/multipath/main.c
@@ -28,6 +28,7 @@
 #include <unistd.h>
 #include <ctype.h>
 #include <libudev.h>
+#include <syslog.h>
 
 #include <checkers.h>
 #include <prio.h>
@@ -283,6 +284,7 @@ configure (void)
 		int failed = get_refwwid(conf->dev, conf->dev_type, pathvec,
 					 &refwwid);
 		if (!refwwid) {
+			condlog(3, "%s: failed to get wwid", conf->dev);
 			if (failed == 2 && conf->cmd == CMD_VALID_PATH)
 				printf("%s is not a valid multipath device path\n", conf->dev);
 			else
@@ -471,11 +473,11 @@ main (int argc, char *argv[])
 	int r = 1;
 
 	udev = udev_new();
-
+	logsink = 0;
 	if (load_config(DEFAULT_CONFIGFILE, udev))
 		exit(1);
 
-	while ((arg = getopt(argc, argv, ":adchl::FfM:v:p:b:BritqwW")) != EOF ) {
+	while ((arg = getopt(argc, argv, ":adchl::FfM:v:p:b:BritquwW")) != EOF ) {
 		switch(arg) {
 		case 1: printf("optarg : %s\n",optarg);
 			break;
@@ -542,6 +544,10 @@ main (int argc, char *argv[])
 		case 'h':
 			usage(argv[0]);
 			exit(0);
+		case 'u':
+			conf->cmd = CMD_VALID_PATH;
+			conf->dev_type = DEV_UEVENT;
+			break;
 		case 'w':
 			conf->cmd = CMD_REMOVE_WWID;
 			break;
@@ -581,9 +587,15 @@ main (int argc, char *argv[])
 			goto out;
 
 		strncpy(conf->dev, argv[optind], FILE_NAME_SIZE);
-		conf->dev_type = get_dev_type(conf->dev);
+		if (conf->dev_type != DEV_UEVENT)
+			conf->dev_type = get_dev_type(conf->dev);
 	}
 	conf->daemon = 0;
+	if (conf->dev_type == DEV_UEVENT) {
+		openlog("multipath", 0, LOG_DAEMON);
+		setlogmask(LOG_UPTO(conf->verbosity + 3));
+		logsink = 1;
+	}
 
 	if (conf->max_fds) {
 		struct rlimit fd_limit;
@@ -659,6 +671,9 @@ out:
 	cleanup_prio();
 	cleanup_checkers();
 
+	if (conf->dev_type == DEV_UEVENT)
+		closelog();
+
 out_free_config:
 	/*
 	 * Freeing config must be done after dm_lib_exit(), because
diff --git a/multipath/multipath.8 b/multipath/multipath.8
index 13e2e89..966139e 100644
--- a/multipath/multipath.8
+++ b/multipath/multipath.8
@@ -8,7 +8,7 @@ multipath \- Device mapper target autoconfig
 .RB [\| \-b\ \c
 .IR bindings_file \|]
 .RB [\| \-d \|]
-.RB [\| \-h | \-l | \-ll | \-f | \-t | \-F | \-B | \-c | \-q | \|-r | \|-i | \-a | \-w | \-W \|]
+.RB [\| \-h | \-l | \-ll | \-f | \-t | \-F | \-B | \-c | \-q | \|-r | \|-i | \-a | \|-u | \-w | \-W \|]
 .RB [\| \-p\ \c
 .BR failover | multibus | group_by_serial | group_by_prio | group_by_node_name \|]
 .RB [\| device \|]
@@ -74,6 +74,10 @@ allow device tables with queue_if_no_path when multipathd is not running
 .B \-a
 add the wwid for the specified device to the wwids file
 .TP
+.B \-u
+check if the device specified in the program environment should be
+a path in a multipath device.
+.TP
 .B \-w
 remove the wwid for the specified device from the wwids file
 .TP
diff --git a/multipath/multipath.rules b/multipath/multipath.rules
index 799fbb0..5bc5068 100644
--- a/multipath/multipath.rules
+++ b/multipath/multipath.rules
@@ -6,7 +6,7 @@ TEST!="$env{MPATH_SBIN_PATH}/multipath", ENV{MPATH_SBIN_PATH}="/usr/sbin"
 
 SUBSYSTEM=="block", ACTION=="add|change", KERNEL!="dm-*", \
 	ENV{DM_MULTIPATH_DEVICE_PATH}!="1", \
-	PROGRAM=="$env{MPATH_SBIN_PATH}/multipath -v 0 -c $tempnode", \
+	PROGRAM=="$env{MPATH_SBIN_PATH}/multipath -u %k", \
 	ENV{DM_MULTIPATH_DEVICE_PATH}="1" \
 	ENV{SYSTEMD_READY}="0"
 
-- 
1.8.4.5

  parent reply	other threads:[~2015-03-16 12:36 UTC|newest]

Thread overview: 98+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-16 12:35 [PATCH 00/78] SUSE SLES resync Hannes Reinecke
2015-03-16 12:35 ` [PATCH 01/78] libmultipath: remove compilation warning in devmapper.c Hannes Reinecke
2015-03-16 12:35 ` [PATCH 02/78] mpath_persist: Do not call exit() from a shared library Hannes Reinecke
2015-03-16 12:35 ` [PATCH 03/78] libmultipath: filter for missing property in get_refwwid() Hannes Reinecke
2015-03-16 12:35 ` [PATCH 04/78] Double uevent stacksize yet again Hannes Reinecke
2015-03-16 12:35 ` [PATCH 05/78] discovery: do not fail discovery on individual devices Hannes Reinecke
2015-03-16 12:35 ` [PATCH 06/78] libmultipath: Prefer deprecated 'getuid' callout Hannes Reinecke
2015-03-16 12:35 ` [PATCH 07/78] libmultipath: Skip paths with empty wwid Hannes Reinecke
2015-03-16 12:35 ` [PATCH 08/78] Make systemd installation path configurable Hannes Reinecke
2015-03-16 12:35 ` [PATCH 09/78] Add multipath rules for systemd support Hannes Reinecke
2015-03-16 12:35 ` [PATCH 10/78] Fixup multipathd.socket to resolve ordering dependeny Hannes Reinecke
2015-03-16 12:35 ` [PATCH 11/78] Fixup dependencies in multipathd.service Hannes Reinecke
2015-03-16 12:35 ` [PATCH 12/78] multipathd: set correct PID when running in debug mode Hannes Reinecke
2015-03-16 12:36 ` [PATCH 13/78] Do not print empty device strings during discovery Hannes Reinecke
2015-03-16 12:36 ` [PATCH 14/78] kpartx.rules: do not call blkid Hannes Reinecke
2015-03-16 12:36 ` [PATCH 15/78] Use 'SCSI_IDENT_.*' as the default property whitelist Hannes Reinecke
2015-03-16 12:36 ` [PATCH 16/78] Fixup wwid blacklist printing Hannes Reinecke
2015-03-16 12:36 ` [PATCH 17/78] Allow for empty path argument when printing information Hannes Reinecke
2015-03-16 12:36 ` [PATCH 18/78] Disable reassign maps per default Hannes Reinecke
2015-03-16 12:36 ` [PATCH 19/78] multipathd: implement 'list path <path>' cli command Hannes Reinecke
2015-03-16 12:36 ` [PATCH 20/78] Make checker_put() and prio_put() idempotent Hannes Reinecke
2015-03-16 12:36 ` [PATCH 21/78] Remove trailing linefeed from sysfs attributes Hannes Reinecke
2015-03-16 12:36 ` Hannes Reinecke [this message]
2015-03-16 12:36 ` [PATCH 23/78] Install multipath rule under '56-multipath.rules' Hannes Reinecke
2015-03-16 12:36 ` [PATCH 24/78] multipath.rules: Whitelist devices Hannes Reinecke
2015-03-16 12:36 ` [PATCH 25/78] multipath.rules: fixup race condition with systemd Hannes Reinecke
2015-03-16 12:36 ` [PATCH 26/78] 11-dm-mpath.rules: Import blkid values if all paths are down Hannes Reinecke
2015-03-27  3:42   ` Benjamin Marzinski
2015-03-27 16:03     ` Hannes Reinecke
2015-03-27 16:14       ` Benjamin Marzinski
2015-03-16 12:36 ` [PATCH 27/78] kpartx.rules: Skip kpartx for multipath events Hannes Reinecke
2015-03-16 12:36 ` [PATCH 28/78] multipathd: handle DOMAP_RETRY Hannes Reinecke
2015-03-16 12:36 ` [PATCH 29/78] multipathd: cleanup foreground operation Hannes Reinecke
2015-03-16 12:36 ` [PATCH 30/78] Update hwtable for EMC XtremIO Hannes Reinecke
2015-03-16 12:36 ` [PATCH 31/78] multipath: check for running daemon when called with '-u' Hannes Reinecke
2015-03-16 12:36 ` [PATCH 32/78] Revert 'return PATH_DOWN for quiesced paths' Hannes Reinecke
2015-03-16 12:36 ` [PATCH 33/78] Do not treat 'transport-offline' paths as 'offline' Hannes Reinecke
2015-03-16 12:36 ` [PATCH 34/78] Check for valid DM_DEVICE_INFO before proceeding Hannes Reinecke
2015-03-16 12:36 ` [PATCH 35/78] Separate out uevent parsing functions Hannes Reinecke
2015-03-16 12:36 ` [PATCH 36/78] Use poll() when receiving uevents Hannes Reinecke
2015-03-16 12:36 ` [PATCH 37/78] mpath_persist: cleanup Hannes Reinecke
2015-03-16 12:36 ` [PATCH 38/78] kpartx: use standard 'major' and 'minor' macros Hannes Reinecke
2015-03-16 12:36 ` [PATCH 39/78] multipath: Use standard 'major' macro Hannes Reinecke
2015-03-16 12:36 ` [PATCH 40/78] Remove sysfs_get_dev Hannes Reinecke
2015-03-16 12:36 ` [PATCH 41/78] Add paths with a size of '0' as 'ghost' paths Hannes Reinecke
2015-03-16 12:36 ` [PATCH 42/78] Remove last argument from verify_paths() Hannes Reinecke
2015-03-16 12:36 ` [PATCH 43/78] Fixup device-mapper 'cookie' handling Hannes Reinecke
2015-03-25 16:30   ` Benjamin Marzinski
2015-03-25 16:59     ` Benjamin Marzinski
2015-03-26 14:20     ` Hannes Reinecke
2015-03-16 12:36 ` [PATCH 44/78] multipath: do not print state 'orphan' for option '-l' Hannes Reinecke
2015-03-16 12:36 ` [PATCH 45/78] Return error when receiving CLI packet Hannes Reinecke
2015-03-16 12:36 ` [PATCH 46/78] Implement 'uxsock_timeout' keyword Hannes Reinecke
2015-03-16 12:36 ` [PATCH 47/78] Do not print empty multipaths section Hannes Reinecke
2015-03-16 12:36 ` [PATCH 48/78] multipathd: reload map if reinstate failed Hannes Reinecke
2015-03-16 12:36 ` [PATCH 49/78] multipathd: do not remove paths without uevents Hannes Reinecke
2015-03-16 12:36 ` [PATCH 50/78] Allow zero-sized devices during configuration Hannes Reinecke
2015-03-27  3:56   ` Benjamin Marzinski
2015-03-27  7:16     ` Hannes Reinecke
2015-03-16 12:36 ` [PATCH 51/78] Rework uev_add_path() Hannes Reinecke
2015-03-16 12:36 ` [PATCH 52/78] multipathd: Issue warning on CLI command timeout Hannes Reinecke
2015-03-16 12:36 ` [PATCH 53/78] Use strlen() when checking for valid wwid Hannes Reinecke
2015-03-16 12:36 ` [PATCH 54/78] multipathd: Use standard lists for CLI handling Hannes Reinecke
2015-03-16 12:36 ` [PATCH 55/78] uxlsnr: use typedef for trigger function Hannes Reinecke
2015-03-16 12:36 ` [PATCH 56/78] multipathd: lock cli client list Hannes Reinecke
2015-03-16 12:36 ` [PATCH 57/78] multipath: enable sync support Hannes Reinecke
2015-03-16 12:36 ` [PATCH 58/78] Remove dm_udev_XXX wrapper functions Hannes Reinecke
2015-03-16 12:36 ` [PATCH 59/78] Revert to ACT_RELOAD in domap if the map exists Hannes Reinecke
2015-03-16 12:36 ` [PATCH 60/78] multipathd: use local variable for watchdog configuration Hannes Reinecke
2015-03-16 12:36 ` [PATCH 61/78] Ignore devices when sysfs_get_tgt_nodename fails Hannes Reinecke
2015-03-16 12:36 ` [PATCH 62/78] Skip USB devices during discovery Hannes Reinecke
2015-03-16 12:36 ` [PATCH 63/78] Read wwid from sysfs vpg_pg83 attribute Hannes Reinecke
2015-03-16 12:36 ` [PATCH 64/78] Assign local priority for NAA VPD descriptor Hannes Reinecke
2015-03-16 12:36 ` [PATCH 65/78] Use sysfs attribute vpd_pg80 to read serial number Hannes Reinecke
2015-03-16 12:36 ` [PATCH 66/78] Update multipath.conf.5 to clarify wwid generation Hannes Reinecke
2015-03-16 12:36 ` [PATCH 67/78] libmultipath: Fall back to SG_IO if no UID could be assigned Hannes Reinecke
2015-03-16 12:36 ` [PATCH 68/78] libmultipath: unset 'uid_attribute' on failure Hannes Reinecke
2015-03-27  4:10   ` Benjamin Marzinski
2015-03-27  7:17     ` Hannes Reinecke
2015-03-16 12:36 ` [PATCH 69/78] Separate out vpd parsing functions Hannes Reinecke
2015-03-16 12:36 ` [PATCH 70/78] multipathd: use SG_IO as fallback to generate uid Hannes Reinecke
2015-03-16 12:36 ` [PATCH 71/78] Do not automatically fall back to vpd uid generation Hannes Reinecke
2015-03-16 12:36 ` [PATCH 72/78] libmultipath: make vpd page 0x80 optional Hannes Reinecke
2015-03-16 12:37 ` [PATCH 73/78] multipathd: push down lock in checkerloop() Hannes Reinecke
2015-03-27  4:21   ` Benjamin Marzinski
2015-03-16 12:37 ` [PATCH 74/78] Allow specific CLI commands to run unlocked Hannes Reinecke
2015-03-27  5:38   ` Benjamin Marzinski
2015-03-16 12:37 ` [PATCH 75/78] Push down vector lock during uevent processing Hannes Reinecke
2015-03-27  5:46   ` Benjamin Marzinski
2015-03-16 12:37 ` [PATCH 76/78] multipathd: timeout CLI commands when waiting for lock Hannes Reinecke
2015-03-16 12:37 ` [PATCH 77/78] multipathd: asynchronous configuration Hannes Reinecke
2015-03-27  5:58   ` Benjamin Marzinski
2015-03-27  8:09     ` Hannes Reinecke
2015-03-16 12:37 ` [PATCH 78/78] multipathd: trigger all devices on startup Hannes Reinecke
2015-03-27  5:59   ` Benjamin Marzinski
2015-03-27  7:22     ` Hannes Reinecke
2015-03-29 16:28 ` [PATCH 00/78] SUSE SLES resync Christophe Varoqui
2015-03-30  6:07   ` Hannes Reinecke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1426509425-15978-23-git-send-email-hare@suse.de \
    --to=hare@suse.de \
    --cc=christophe.varoqui@gmail.com \
    --cc=dm-devel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox