Linux Device Mapper development
 help / color / mirror / Atom feed
From: "Benjamin Marzinski" <bmarzins@redhat.com>
To: Martin Wilck <mwilck@suse.com>
Cc: dm-devel@redhat.com
Subject: Re: [PATCH 04/33] multipath: do not check daemon from udev rules
Date: Wed, 5 Apr 2017 16:54:46 -0500	[thread overview]
Message-ID: <20170405215446.GG19236@octiron.msp.redhat.com> (raw)
In-Reply-To: <20170228162329.14517-5-mwilck@suse.com>

On Tue, Feb 28, 2017 at 05:23:00PM +0100, Martin Wilck wrote:
> From: Hannes Reinecke <hare@suse.de>
> 
> 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.

If we are doing this, so that udev will correctly claim multipath
devices before multipathd has started up, it seems like it should be
possible to relax some of the ordering restrictions for the startup. For
instance, I assume you added the requirement that multipathd needed to
start up before lvmetad to make sure it clamined the devices first.  If
we don't need multipathd to be running to claim the devices, we can
start them up in any order.

-Ben
 
> Signed-off-by: Hannes Reinecke <hare@suse.com>
> ---
>  libmultipath/util.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  libmultipath/util.h |  1 +
>  multipath/main.c    | 13 +++++++-----
>  3 files changed, 68 insertions(+), 5 deletions(-)
> 
> diff --git a/libmultipath/util.c b/libmultipath/util.c
> index 1841f359..be454cb1 100644
> --- a/libmultipath/util.c
> +++ b/libmultipath/util.c
> @@ -6,13 +6,16 @@
>  #include <sys/stat.h>
>  #include <sys/sysmacros.h>
>  #include <sys/types.h>
> +#include <dirent.h>
>  #include <unistd.h>
> +#include <errno.h>
>  
>  #include "debug.h"
>  #include "memory.h"
>  #include "checkers.h"
>  #include "vector.h"
>  #include "structs.h"
> +#include "log.h"
>  
>  size_t
>  strchop(char *str)
> @@ -279,3 +282,59 @@ setup_thread_attr(pthread_attr_t *attr, size_t stacksize, int detached)
>  		assert(ret == 0);
>  	}
>  }
> +
> +int systemd_service_enabled_in(const char *dev, const char *prefix)
> +{
> +	char path[PATH_SIZE], file[PATH_SIZE], service[PATH_SIZE];
> +	DIR *dirfd;
> +	struct dirent *d;
> +	int found = 0;
> +
> +	snprintf(service, PATH_SIZE, "multipathd.service");
> +	snprintf(path, PATH_SIZE, "%s/systemd/system", prefix);
> +	condlog(3, "%s: checking for %s in %s", dev, service, path);
> +
> +	dirfd = opendir(path);
> +	if (dirfd == NULL)
> +		return 0;
> +
> +	while ((d = readdir(dirfd)) != NULL) {
> +		char *p;
> +		struct stat stbuf;
> +
> +		if ((strcmp(d->d_name,".") == 0) ||
> +		    (strcmp(d->d_name,"..") == 0))
> +			continue;
> +
> +		if (strlen(d->d_name) < 6)
> +			continue;
> +
> +		p = d->d_name + strlen(d->d_name) - 6;
> +		if (strcmp(p, ".wants"))
> +			continue;
> +		snprintf(file, PATH_SIZE, "%s/%s/%s",
> +			 path, d->d_name, service);
> +		if (stat(file, &stbuf) == 0) {
> +			condlog(3, "%s: found %s", dev, file);
> +			found++;
> +			break;
> +		}
> +	}
> +	closedir(dirfd);
> +
> +	return found;
> +}
> +
> +int systemd_service_enabled(const char *dev)
> +{
> +	int found = 0;
> +
> +	found = systemd_service_enabled_in(dev, "/etc");
> +	if (!found)
> +		found = systemd_service_enabled_in(dev, "/usr/lib");
> +	if (!found)
> +		found = systemd_service_enabled_in(dev, "/lib");
> +	if (!found)
> +		found = systemd_service_enabled_in(dev, "/run");
> +	return found;
> +}
> diff --git a/libmultipath/util.h b/libmultipath/util.h
> index f3b37ee9..4c1f85c3 100644
> --- a/libmultipath/util.h
> +++ b/libmultipath/util.h
> @@ -13,6 +13,7 @@ int devt2devname (char *, int, char *);
>  dev_t parse_devt(const char *dev_t);
>  char *convert_dev(char *dev, int is_path_device);
>  void setup_thread_attr(pthread_attr_t *attr, size_t stacksize, int detached);
> +int systemd_service_enabled(const char *dev);
>  
>  #define safe_sprintf(var, format, args...)	\
>  	snprintf(var, sizeof(var), format, ##args) >= sizeof(var)
> diff --git a/multipath/main.c b/multipath/main.c
> index 171c08b4..befe4c53 100644
> --- a/multipath/main.c
> +++ b/multipath/main.c
> @@ -682,11 +682,14 @@ main (int argc, char *argv[])
>  
>  		fd = mpath_connect();
>  		if (fd == -1) {
> -			printf("%s is not a valid multipath device path\n",
> -				dev);
> -			goto out;
> -		}
> -		mpath_disconnect(fd);
> +			condlog(3, "%s: daemon is not running", dev);
> +			if (!systemd_service_enabled(dev)) {
> +				printf("%s is not a valid "
> +				       "multipath device path\n", dev);
> +				goto out;
> +			}
> +		} else
> +			mpath_disconnect(fd);
>  	}
>  	if (cmd == CMD_REMOVE_WWID && !dev) {
>  		condlog(0, "the -w option requires a device");
> -- 
> 2.11.0
> 
> --
> dm-devel mailing list
> dm-devel@redhat.com
> https://www.redhat.com/mailman/listinfo/dm-devel

  reply	other threads:[~2017-04-05 21:54 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-28 16:22 [PATCH 00/33] multipath-tools fixes from SUSE Martin Wilck
2017-02-28 16:22 ` [PATCH 01/33] multipathd.service: fixup Wants= and Before= statements Martin Wilck
2017-03-13 23:06   ` Benjamin Marzinski
2017-03-14  7:36     ` Martin Wilck
2017-02-28 16:22 ` [PATCH 02/33] multipathd: start daemon after udev trigger Martin Wilck
2017-02-28 16:22 ` [PATCH 03/33] Add support for "multipath=off" and "nompath" on kernel cmdline Martin Wilck
2017-02-28 16:23 ` [PATCH 04/33] multipath: do not check daemon from udev rules Martin Wilck
2017-04-05 21:54   ` Benjamin Marzinski [this message]
2017-04-06 12:10     ` Martin Wilck
2017-02-28 16:23 ` [PATCH 05/33] Invalid error code when using multipathd CLI Martin Wilck
2017-02-28 16:23 ` [PATCH 06/33] multipathd: set timeout for CLI commands correctly Martin Wilck
2017-04-05 22:07   ` Benjamin Marzinski
2017-04-12 20:26     ` Martin Wilck
2017-04-13 13:11     ` [PATCH] Revert "multipathd: set timeout for CLI commands correctly" Martin Wilck
2017-02-28 16:23 ` [PATCH 07/33] libmultipath: fall back to search paths by devt Martin Wilck
2017-02-28 16:23 ` [PATCH 08/33] libmultipath: Do not crash on empty features Martin Wilck
2017-02-28 16:23 ` [PATCH 09/33] multipathd: Set CLI timeout correctly Martin Wilck
2017-02-28 16:23 ` [PATCH 10/33] multipath: avoid crash when using modified configuration Martin Wilck
2017-02-28 16:23 ` [PATCH 11/33] multipathd: issue systemd READY after initial configuration Martin Wilck
2017-02-28 16:23 ` [PATCH 12/33] libmultipath/discovery: do not cache 'access_state' sysfs attribute Martin Wilck
2017-02-28 16:23 ` [PATCH 13/33] libmultipath: use existing alias from bindings file Martin Wilck
2017-02-28 16:23 ` [PATCH 14/33] multipath -ll: set DI_SERIAL Martin Wilck
2017-02-28 16:23 ` [PATCH 15/33] libmultipath: move suspend logic to _dm_flush_map Martin Wilck
2017-04-05 22:44   ` Benjamin Marzinski
2017-04-12 20:54     ` Martin Wilck
2017-04-13 13:05     ` [PATCH] libmultipath: fix skip_kpartx support for removing maps Martin Wilck
2017-04-14  8:42       ` Christophe Varoqui
2017-02-28 16:23 ` [PATCH 16/33] multipath: ignore -i if find_multipaths is set Martin Wilck
2017-02-28 16:23 ` [PATCH 17/33] multipathd: imply -n " Martin Wilck
2017-04-05 23:03   ` Benjamin Marzinski
2017-04-12 21:36     ` Martin Wilck
2017-04-13 21:54       ` Benjamin Marzinski
2017-02-28 16:23 ` [PATCH 18/33] multipathd: use weaker "force_reload" at startup Martin Wilck
2017-02-28 16:23 ` [PATCH 19/33] libmultipath: setup_features: log msg if queue_if_no_path is ignored Martin Wilck
2017-02-28 16:23 ` [PATCH 20/33] libmultipath: setup_feature: print log msg if no_path_retry cant be set Martin Wilck
2017-02-28 16:23 ` [PATCH 21/33] libmultipath: setup_feature: handle "retain_attached_hw_handler" Martin Wilck
2017-02-28 16:23 ` [PATCH 22/33] libmultipath: disassemble_map: skip no_path_retry check Martin Wilck
2017-02-28 16:23 ` [PATCH 23/33] libmultipath: disassemble_map: treat minio like assemble_map does Martin Wilck
2017-02-28 16:23 ` [PATCH 24/33] libmultipath: select_action: check special features separately Martin Wilck
2017-02-28 16:23 ` [PATCH 25/33] libmultipath: sysfs_attr_set_value: use const char* Martin Wilck
2017-02-28 16:23 ` [PATCH 26/33] libmultipath: reload map if not known to udev Martin Wilck
2017-02-28 16:23 ` [PATCH 27/33] libmultipath: differentiate ACT_NOTHING and ACT_IMPOSSIBLE Martin Wilck
2017-02-28 16:23 ` [PATCH 28/33] libmultipath: coalesce_paths: trigger uevent if nothing done Martin Wilck
2017-02-28 16:23 ` [PATCH 29/33] kpartx: sanitize delete partitions Martin Wilck
2017-02-28 16:23 ` [PATCH 30/33] tur: Add pthread_testcancel() Martin Wilck
2017-02-28 16:23 ` [PATCH 31/33] multipathd: fixup check for new path states Martin Wilck
2017-02-28 16:23 ` [PATCH 32/33] libmultipath/checkers: make RADOS checker optional Martin Wilck
2017-02-28 16:23 ` [PATCH 33/33] Make libdmmp build optional Martin Wilck
2017-02-28 22:44 ` [PATCH 00/33] multipath-tools fixes from SUSE Xose Vazquez Perez
2017-03-01  8:12   ` Martin Wilck
2017-03-23 18:43     ` multipath-tools (patch): Do not select sysfs prioritizer for RDAC arrays (was Re: [PATCH 00/33] multipath-tools fixes from SUSE) Xose Vazquez Perez
2017-03-23 20:40       ` Stewart, Sean
2017-03-22 19:02 ` [PATCH 00/33] multipath-tools fixes from SUSE Xose Vazquez Perez
2017-03-22 21:29   ` Christophe Varoqui
2017-03-23  8:30     ` Christophe Varoqui
2017-03-24  7:44       ` Martin Wilck
2017-04-12  7:38         ` Christophe Varoqui

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=20170405215446.GG19236@octiron.msp.redhat.com \
    --to=bmarzins@redhat.com \
    --cc=dm-devel@redhat.com \
    --cc=mwilck@suse.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