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 77/78] multipathd: asynchronous configuration
Date: Mon, 16 Mar 2015 13:37:04 +0100	[thread overview]
Message-ID: <1426509425-15978-78-git-send-email-hare@suse.de> (raw)
In-Reply-To: <1426509425-15978-1-git-send-email-hare@suse.de>

For initial configuration multipathd waits it has synchronized
with the existing setup. On larger systems this takes up quite
some time (I've measured 80 seconds on a system with 1024 paths)
causing systemd to stall and the system to fail booting.
This patch makes the initial configuration asynchronous, and
using the same codepath as the existing 'reconfigure' CLI
command.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 multipathd/cli_handlers.c |  5 ++-
 multipathd/main.c         | 79 ++++++++++++++++++++++++++++-------------------
 multipathd/main.h         |  1 +
 3 files changed, 51 insertions(+), 34 deletions(-)

diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c
index dc96c45..e51537e 100644
--- a/multipathd/cli_handlers.c
+++ b/multipathd/cli_handlers.c
@@ -830,11 +830,10 @@ cli_switch_group(void * v, char ** reply, int * len, void * data)
 int
 cli_reconfigure(void * v, char ** reply, int * len, void * data)
 {
-	struct vectors * vecs = (struct vectors *)data;
-
 	condlog(2, "reconfigure (operator)");
 
-	return reconfigure(vecs);
+	post_config_state(DAEMON_CONFIGURE);
+	return 0;
 }
 
 int
diff --git a/multipathd/main.c b/multipathd/main.c
index 6c98686..d9f2435 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -93,10 +93,11 @@ struct mpath_event_param
 unsigned int mpath_mx_alloc_len;
 
 int logsink;
-enum daemon_status running_state;
+enum daemon_status running_state = DAEMON_INIT;
 pid_t daemon_pid;
+pthread_mutex_t config_lock = PTHREAD_MUTEX_INITIALIZER;
+pthread_cond_t config_cond = PTHREAD_COND_INITIALIZER;
 
-static sem_t exit_sem;
 /*
  * global copy of vecs for use in sig handlers
  */
@@ -104,6 +105,21 @@ struct vectors * gvecs;
 
 struct udev * udev;
 
+static void config_cleanup(void *arg)
+{
+	pthread_mutex_unlock(&config_lock);
+}
+
+void post_config_state(enum daemon_status state)
+{
+	pthread_mutex_lock(&config_lock);
+	if (state != running_state) {
+		running_state = state;
+		pthread_cond_broadcast(&config_cond);
+	}
+	pthread_mutex_unlock(&config_lock);
+}
+
 static int
 need_switch_pathgroup (struct multipath * mpp, int refresh)
 {
@@ -860,6 +876,15 @@ uev_trigger (struct uevent * uev, void * trigger_data)
 	if (uev_discard(uev->devpath))
 		return 0;
 
+	pthread_cleanup_push(config_cleanup, NULL);
+	pthread_mutex_lock(&config_lock);
+	if (running_state != DAEMON_RUNNING)
+		pthread_cond_wait(&config_cond, &config_lock);
+	pthread_cleanup_pop(1);
+
+	if (running_state == DAEMON_SHUTDOWN)
+		return 0;
+
 	/*
 	 * device map event
 	 * Add events are ignored here as the tables
@@ -948,7 +973,7 @@ uxlsnrloop (void * ap)
 	set_handler_callback(ADD+MAP, cli_add_map);
 	set_handler_callback(DEL+MAP, cli_del_map);
 	set_handler_callback(SWITCH+MAP+GROUP, cli_switch_group);
-	set_handler_callback(RECONFIGURE, cli_reconfigure);
+	set_unlocked_handler_callback(RECONFIGURE, cli_reconfigure);
 	set_handler_callback(SUSPEND+MAP, cli_suspend);
 	set_handler_callback(RESUME+MAP, cli_resume);
 	set_handler_callback(RESIZE+MAP, cli_resize);
@@ -977,7 +1002,7 @@ uxlsnrloop (void * ap)
 void
 exit_daemon (void)
 {
-	sem_post(&exit_sem);
+	post_config_state(DAEMON_SHUTDOWN);
 }
 
 const char *
@@ -1561,8 +1586,6 @@ reconfigure (struct vectors * vecs)
 	struct config * old = conf;
 	int retval = 1;
 
-	running_state = DAEMON_CONFIGURE;
-
 	/*
 	 * free old map and path vectors ... they use old conf state
 	 */
@@ -1587,7 +1610,7 @@ reconfigure (struct vectors * vecs)
 		retval = 0;
 	}
 
-	running_state = DAEMON_RUNNING;
+	post_config_state(DAEMON_RUNNING);
 
 	return retval;
 }
@@ -1643,12 +1666,7 @@ handle_signals(void)
 {
 	if (reconfig_sig && running_state == DAEMON_RUNNING) {
 		condlog(2, "reconfigure (signal)");
-		pthread_cleanup_push(cleanup_lock,
-				&gvecs->lock);
-		lock(gvecs->lock);
-		pthread_testcancel();
-		reconfigure(gvecs);
-		lock_cleanup_pop(gvecs->lock);
+		post_config_state(DAEMON_CONFIGURE);
 	}
 	if (log_reset_sig) {
 		condlog(2, "reset log (signal)");
@@ -1781,7 +1799,6 @@ child (void * param)
 	char *envp;
 
 	mlockall(MCL_CURRENT | MCL_FUTURE);
-	sem_init(&exit_sem, 0, 0);
 	signal_init();
 
 	udev = udev_new();
@@ -1796,7 +1813,7 @@ child (void * param)
 		pthread_attr_destroy(&log_attr);
 	}
 
-	running_state = DAEMON_START;
+	post_config_state(DAEMON_START);
 
 #ifdef USE_SYSTEMD
 	sd_notify(0, "STATUS=startup");
@@ -1891,15 +1908,7 @@ child (void * param)
 #ifdef USE_SYSTEMD
 	sd_notify(0, "STATUS=configure");
 #endif
-	running_state = DAEMON_CONFIGURE;
-
-	lock(vecs->lock);
-	if (configure(vecs, 1)) {
-		unlock(vecs->lock);
-		condlog(0, "failure during configuration");
-		goto failed;
-	}
-	unlock(vecs->lock);
+	post_config_state(DAEMON_CONFIGURE);
 
 	/*
 	 * start threads
@@ -1918,20 +1927,29 @@ child (void * param)
 	pid_rc = pidfile_create(DEFAULT_PIDFILE, daemon_pid);
 	/* Ignore errors, we can live without */
 
-	running_state = DAEMON_RUNNING;
 #ifdef USE_SYSTEMD
 	sd_notify(0, "READY=1\nSTATUS=running");
 #endif
 
-	/*
-	 * exit path
-	 */
-	while(sem_wait(&exit_sem) != 0); /* Do nothing */
+	while (running_state != DAEMON_SHUTDOWN) {
+		pthread_cleanup_push(config_cleanup, NULL);
+		pthread_mutex_lock(&config_lock);
+		if (running_state == DAEMON_RUNNING) {
+			pthread_cond_wait(&config_cond, &config_lock);
+		}
+		pthread_cleanup_pop(1);
+		if (running_state == DAEMON_CONFIGURE) {
+			pthread_cleanup_push(cleanup_lock, &vecs->lock);
+			lock(vecs->lock);
+			pthread_testcancel();
+			reconfigure(vecs);
+			lock_cleanup_pop(vecs->lock);
+		}
+	}
 
 #ifdef USE_SYSTEMD
 	sd_notify(0, "STATUS=shutdown");
 #endif
-	running_state = DAEMON_SHUTDOWN;
 	lock(vecs->lock);
 	if (conf->queue_without_daemon == QUE_NO_DAEMON_OFF)
 		vector_foreach_slot(vecs->mpvec, mpp, i)
@@ -2066,7 +2084,6 @@ main (int argc, char *argv[])
 	int foreground = 0;
 
 	logsink = 1;
-	running_state = DAEMON_INIT;
 	dm_init();
 
 	if (getuid() != 0) {
diff --git a/multipathd/main.h b/multipathd/main.h
index 1813633..6edf4ab 100644
--- a/multipathd/main.h
+++ b/multipathd/main.h
@@ -25,6 +25,7 @@ int ev_remove_path (struct path *, struct vectors *);
 int ev_add_map (char *, char *, struct vectors *);
 int ev_remove_map (char *, char *, int, struct vectors *);
 void sync_map_state (struct multipath *);
+void post_config_state(enum daemon_status);
 void * mpath_alloc_prin_response(int prin_sa);
 int prin_do_scsi_ioctl(char *, int rq_servact, struct prin_resp * resp,
        int noisy);
-- 
1.8.4.5

  parent reply	other threads:[~2015-03-16 12:37 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 ` [PATCH 22/78] multipath: implement option '-u' for uevents Hannes Reinecke
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 ` Hannes Reinecke [this message]
2015-03-27  5:58   ` [PATCH 77/78] multipathd: asynchronous configuration 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-78-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