Blame SOURCES/0136-RHBZ-1304687-wait-for-map-add.patch

4ae388
---
4ae388
 libmultipath/config.c      |    1 
4ae388
 libmultipath/config.h      |    2 
4ae388
 libmultipath/configure.c   |    4 +
4ae388
 libmultipath/defaults.h    |    1 
4ae388
 libmultipath/dict.c        |   25 ++++++++
4ae388
 libmultipath/structs.h     |    2 
4ae388
 multipath.conf.defaults    |    1 
4ae388
 multipath/multipath.conf.5 |    8 ++
4ae388
 multipathd/cli_handlers.c  |   65 ++++++++++++++++++----
4ae388
 multipathd/main.c          |  132 +++++++++++++++++++++++++++++++++++++++++++--
4ae388
 multipathd/main.h          |    1 
4ae388
 11 files changed, 229 insertions(+), 13 deletions(-)
4ae388
4ae388
Index: multipath-tools-130222/libmultipath/configure.c
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/configure.c
4ae388
+++ multipath-tools-130222/libmultipath/configure.c
4ae388
@@ -701,6 +701,10 @@ domap (struct multipath * mpp, char * pa
4ae388
 			 */
4ae388
 			if (mpp->action != ACT_CREATE)
4ae388
 				mpp->action = ACT_NOTHING;
4ae388
+			else {
4ae388
+				mpp->wait_for_udev = 1;
4ae388
+				mpp->uev_wait_tick = conf->uev_wait_timeout;
4ae388
+			}
4ae388
 		}
4ae388
 		dm_setgeometry(mpp);
4ae388
 		return DOMAP_OK;
4ae388
Index: multipath-tools-130222/libmultipath/structs.h
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/structs.h
4ae388
+++ multipath-tools-130222/libmultipath/structs.h
4ae388
@@ -217,6 +217,8 @@ struct multipath {
4ae388
 	int bestpg;
4ae388
 	int queuedio;
4ae388
 	int action;
4ae388
+	int wait_for_udev;
4ae388
+	int uev_wait_tick;
4ae388
 	int pgfailback;
4ae388
 	int failback_tick;
4ae388
 	int rr_weight;
4ae388
Index: multipath-tools-130222/multipathd/cli_handlers.c
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/multipathd/cli_handlers.c
4ae388
+++ multipath-tools-130222/multipathd/cli_handlers.c
4ae388
@@ -548,6 +548,11 @@ cli_reload(void *v, char **reply, int *l
4ae388
 		condlog(0, "%s: invalid map name. cannot reload", mapname);
4ae388
 		return 1;
4ae388
 	}
4ae388
+	if (mpp->wait_for_udev) {
4ae388
+		condlog(2, "%s: device not fully created, failing reload",
4ae388
+			mpp->alias);
4ae388
+		return 1;
4ae388
+	}
4ae388
 
4ae388
 	return reload_map(vecs, mpp, 0);
4ae388
 }
4ae388
@@ -592,6 +597,12 @@ cli_resize(void *v, char **reply, int *l
4ae388
 		return 1;
4ae388
 	}
4ae388
 
4ae388
+	if (mpp->wait_for_udev) {
4ae388
+		condlog(2, "%s: device not fully created, failing resize",
4ae388
+			mpp->alias);
4ae388
+		return 1;
4ae388
+	}
4ae388
+
4ae388
 	pgp = VECTOR_SLOT(mpp->pg, 0);
4ae388
 
4ae388
 	if (!pgp){
4ae388
@@ -756,6 +767,12 @@ cli_reconfigure(void * v, char ** reply,
4ae388
 {
4ae388
 	struct vectors * vecs = (struct vectors *)data;
4ae388
 
4ae388
+	if (need_to_delay_reconfig(vecs)) {
4ae388
+		conf->delayed_reconfig = 1;
4ae388
+		condlog(2, "delaying reconfigure (operator)");
4ae388
+		return 0;
4ae388
+	}
4ae388
+
4ae388
 	condlog(2, "reconfigure (operator)");
4ae388
 
4ae388
 	return reconfigure(vecs);
4ae388
@@ -766,17 +783,25 @@ cli_suspend(void * v, char ** reply, int
4ae388
 {
4ae388
 	struct vectors * vecs = (struct vectors *)data;
4ae388
 	char * param = get_keyparam(v, MAP);
4ae388
-	int r = dm_simplecmd_noflush(DM_DEVICE_SUSPEND, param, 0);
4ae388
+	int r;
4ae388
+	struct multipath * mpp;
4ae388
 
4ae388
 	param = convert_dev(param, 0);
4ae388
-	condlog(2, "%s: suspend (operator)", param);
4ae388
+	mpp = find_mp_by_alias(vecs->mpvec, param);
4ae388
+	if (!mpp)
4ae388
+		return 1;
4ae388
 
4ae388
-	if (!r) /* error */
4ae388
+	if (mpp->wait_for_udev) {
4ae388
+		condlog(2, "%s: device not fully created, failing suspend",
4ae388
+			mpp->alias);
4ae388
 		return 1;
4ae388
+	}
4ae388
 
4ae388
-	struct multipath * mpp = find_mp_by_alias(vecs->mpvec, param);
4ae388
+	r = dm_simplecmd_noflush(DM_DEVICE_SUSPEND, param, 0);
4ae388
 
4ae388
-	if (!mpp)
4ae388
+	condlog(2, "%s: suspend (operator)", param);
4ae388
+
4ae388
+	if (!r) /* error */
4ae388
 		return 1;
4ae388
 
4ae388
 	dm_get_info(param, &mpp->dmi);
4ae388
@@ -788,17 +813,25 @@ cli_resume(void * v, char ** reply, int
4ae388
 {
4ae388
 	struct vectors * vecs = (struct vectors *)data;
4ae388
 	char * param = get_keyparam(v, MAP);
4ae388
-	int r = dm_simplecmd_noflush(DM_DEVICE_RESUME, param, 0);
4ae388
+	int r;
4ae388
+	struct multipath * mpp;
4ae388
 
4ae388
 	param = convert_dev(param, 0);
4ae388
-	condlog(2, "%s: resume (operator)", param);
4ae388
+	mpp = find_mp_by_alias(vecs->mpvec, param);
4ae388
+	if (!mpp)
4ae388
+		return 1;
4ae388
 
4ae388
-	if (!r) /* error */
4ae388
+	if (mpp->wait_for_udev) {
4ae388
+		condlog(2, "%s: device not fully created, failing resume",
4ae388
+			mpp->alias);
4ae388
 		return 1;
4ae388
+	}
4ae388
 
4ae388
-	struct multipath * mpp = find_mp_by_alias(vecs->mpvec, param);
4ae388
+	r = dm_simplecmd_noflush(DM_DEVICE_RESUME, param, 0);
4ae388
 
4ae388
-	if (!mpp)
4ae388
+	condlog(2, "%s: resume (operator)", param);
4ae388
+
4ae388
+	if (!r) /* error */
4ae388
 		return 1;
4ae388
 
4ae388
 	dm_get_info(param, &mpp->dmi);
4ae388
@@ -831,9 +864,21 @@ cli_reinstate(void * v, char ** reply, i
4ae388
 int
4ae388
 cli_reassign (void * v, char ** reply, int * len, void * data)
4ae388
 {
4ae388
+	struct vectors * vecs = (struct vectors *)data;
4ae388
 	char * param = get_keyparam(v, MAP);
4ae388
+	struct multipath *mpp;
4ae388
 
4ae388
 	param = convert_dev(param, 0);
4ae388
+	mpp = find_mp_by_alias(vecs->mpvec, param);
4ae388
+	if (!mpp)
4ae388
+		return 1;
4ae388
+
4ae388
+	if (mpp->wait_for_udev) {
4ae388
+		condlog(2, "%s: device not fully created, failing reassign",
4ae388
+			mpp->alias);
4ae388
+		return 1;
4ae388
+	}
4ae388
+
4ae388
 	condlog(3, "%s: reset devices (operator)", param);
4ae388
 
4ae388
 	dm_reassign(param);
4ae388
Index: multipath-tools-130222/libmultipath/config.h
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/config.h
4ae388
+++ multipath-tools-130222/libmultipath/config.h
4ae388
@@ -142,6 +142,8 @@ struct config {
4ae388
 	int retrigger_tries;
4ae388
 	int retrigger_delay;
4ae388
 	int new_bindings_in_boot;
4ae388
+	int delayed_reconfig;
4ae388
+	int uev_wait_timeout;
4ae388
 	unsigned int version[3];
4ae388
 
4ae388
 	char * dev;
4ae388
Index: multipath-tools-130222/multipathd/main.c
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/multipathd/main.c
4ae388
+++ multipath-tools-130222/multipathd/main.c
4ae388
@@ -251,6 +251,47 @@ flush_map(struct multipath * mpp, struct
4ae388
 	return 0;
4ae388
 }
4ae388
 
4ae388
+int
4ae388
+update_map (struct multipath *mpp, struct vectors *vecs)
4ae388
+{
4ae388
+	int retries = 3;
4ae388
+	char params[PARAMS_SIZE] = {0};
4ae388
+
4ae388
+retry:
4ae388
+	condlog(4, "%s: updating new map", mpp->alias);
4ae388
+	if (adopt_paths(vecs->pathvec, mpp, 1)) {
4ae388
+		condlog(0, "%s: failed to adopt paths for new map update",
4ae388
+			mpp->alias);
4ae388
+		retries = -1;
4ae388
+		goto fail;
4ae388
+	}
4ae388
+	verify_paths(mpp, vecs, NULL);
4ae388
+	mpp->flush_on_last_del = FLUSH_UNDEF;
4ae388
+	mpp->action = ACT_RELOAD;
4ae388
+
4ae388
+	if (setup_map(mpp, params, PARAMS_SIZE)) {
4ae388
+		condlog(0, "%s: failed to setup new map in update", mpp->alias);
4ae388
+		retries = -1;
4ae388
+		goto fail;
4ae388
+	}
4ae388
+	if (domap(mpp, params) <= 0 && retries-- > 0) {
4ae388
+		condlog(0, "%s: map_udate sleep", mpp->alias);
4ae388
+		sleep(1);
4ae388
+		goto retry;
4ae388
+	}
4ae388
+	dm_lib_release();
4ae388
+
4ae388
+fail:
4ae388
+	if (setup_multipath(vecs, mpp))
4ae388
+		return 1;
4ae388
+
4ae388
+	sync_map_state(mpp);
4ae388
+
4ae388
+	if (retries < 0)
4ae388
+		condlog(0, "%s: failed reload in new map update", mpp->alias);
4ae388
+	return 0;
4ae388
+}
4ae388
+
4ae388
 static int
4ae388
 uev_add_map (struct uevent * uev, struct vectors * vecs)
4ae388
 {
4ae388
@@ -293,6 +334,20 @@ ev_add_map (char * dev, char * alias, st
4ae388
 	mpp = find_mp_by_alias(vecs->mpvec, alias);
4ae388
 
4ae388
 	if (mpp) {
4ae388
+		if (mpp->wait_for_udev > 1) {
4ae388
+			if (update_map(mpp, vecs))
4ae388
+			/* setup multipathd removed the map */
4ae388
+				return 1;
4ae388
+		}
4ae388
+		if (mpp->wait_for_udev) {
4ae388
+			mpp->wait_for_udev = 0;
4ae388
+			if (conf->delayed_reconfig &&
4ae388
+			    !need_to_delay_reconfig(vecs)) {
4ae388
+				condlog(2, "reconfigure (delayed)");
4ae388
+				reconfigure(vecs);
4ae388
+				return 0;
4ae388
+			}
4ae388
+		}
4ae388
 		/*
4ae388
 		 * Not really an error -- we generate our own uevent
4ae388
 		 * if we create a multipath mapped device as a result
4ae388
@@ -471,7 +526,14 @@ ev_add_path (struct path * pp, struct ve
4ae388
 		condlog(0, "%s: failed to get path uid", pp->dev);
4ae388
 		goto fail; /* leave path added to pathvec */
4ae388
 	}
4ae388
-	mpp = pp->mpp = find_mp_by_wwid(vecs->mpvec, pp->wwid);
4ae388
+	mpp = find_mp_by_wwid(vecs->mpvec, pp->wwid);
4ae388
+	if (mpp && mpp->wait_for_udev) {
4ae388
+		mpp->wait_for_udev = 2;
4ae388
+		orphan_path(pp);
4ae388
+		return 0;
4ae388
+	}
4ae388
+
4ae388
+	pp->mpp = mpp;
4ae388
 rescan:
4ae388
 	if (mpp) {
4ae388
 		if ((!pp->size) || (mpp->size != pp->size)) {
4ae388
@@ -670,6 +732,12 @@ ev_remove_path (struct path *pp, struct
4ae388
 				" removal of path %s", mpp->alias, pp->dev);
4ae388
 			goto fail;
4ae388
 		}
4ae388
+
4ae388
+		if (mpp->wait_for_udev) {
4ae388
+			mpp->wait_for_udev = 2;
4ae388
+			goto out;
4ae388
+		}
4ae388
+
4ae388
 		/*
4ae388
 		 * reload the map
4ae388
 		 */
4ae388
@@ -731,6 +799,11 @@ uev_update_path (struct uevent *uev, str
4ae388
 		condlog(2, "%s: update path write_protect to '%d' (uevent)",
4ae388
 			uev->kernel, ro);
4ae388
 		if (pp->mpp) {
4ae388
+			if (pp->mpp->wait_for_udev) {
4ae388
+				pp->mpp->wait_for_udev = 2;
4ae388
+				return 0;
4ae388
+			}
4ae388
+
4ae388
 			retval = reload_map(vecs, pp->mpp, 0);
4ae388
 
4ae388
 			condlog(2, "%s: map %s reloaded (retval %d)",
4ae388
@@ -1063,6 +1136,33 @@ followover_should_failback(struct path *
4ae388
 }
4ae388
 
4ae388
 static void
4ae388
+missing_uev_wait_tick(struct vectors *vecs)
4ae388
+{
4ae388
+	struct multipath * mpp;
4ae388
+	unsigned int i;
4ae388
+	int timed_out = 0;
4ae388
+
4ae388
+	vector_foreach_slot (vecs->mpvec, mpp, i) {
4ae388
+		if (mpp->wait_for_udev && --mpp->uev_wait_tick <= 0) {
4ae388
+			timed_out = 1;
4ae388
+			condlog(0, "%s: timeout waiting on creation uevent. enabling reloads", mpp->alias);
4ae388
+			if (mpp->wait_for_udev > 1 && update_map(mpp, vecs)) {
4ae388
+				/* update_map removed map */
4ae388
+				i--;
4ae388
+				continue;
4ae388
+			}
4ae388
+			mpp->wait_for_udev = 0;
4ae388
+		}
4ae388
+	}
4ae388
+
4ae388
+	if (timed_out && conf->delayed_reconfig &&
4ae388
+	    !need_to_delay_reconfig(vecs)) {
4ae388
+		condlog(2, "reconfigure (delayed)");
4ae388
+		reconfigure(vecs);
4ae388
+	}
4ae388
+}
4ae388
+
4ae388
+static void
4ae388
 defered_failback_tick (vector mpvec)
4ae388
 {
4ae388
 	struct multipath * mpp;
4ae388
@@ -1316,6 +1416,9 @@ check_path (struct vectors * vecs, struc
4ae388
 
4ae388
 	pp->state = newstate;
4ae388
 
4ae388
+
4ae388
+	if (pp->mpp->wait_for_udev)
4ae388
+		return;
4ae388
 	/*
4ae388
 	 * path prio refreshing
4ae388
 	 */
4ae388
@@ -1369,6 +1472,7 @@ checkerloop (void *ap)
4ae388
 		if (vecs->mpvec) {
4ae388
 			defered_failback_tick(vecs->mpvec);
4ae388
 			retry_count_tick(vecs->mpvec);
4ae388
+			missing_uev_wait_tick(vecs);
4ae388
 		}
4ae388
 		if (count)
4ae388
 			count--;
4ae388
@@ -1465,6 +1569,22 @@ configure (struct vectors * vecs, int st
4ae388
 }
4ae388
 
4ae388
 int
4ae388
+need_to_delay_reconfig(struct vectors * vecs)
4ae388
+{
4ae388
+	struct multipath *mpp;
4ae388
+	int i;
4ae388
+
4ae388
+	if (!VECTOR_SIZE(vecs->mpvec))
4ae388
+		return 0;
4ae388
+
4ae388
+	vector_foreach_slot(vecs->mpvec, mpp, i) {
4ae388
+		if (mpp->wait_for_udev)
4ae388
+			return 1;
4ae388
+	}
4ae388
+	return 0;
4ae388
+}
4ae388
+
4ae388
+int
4ae388
 reconfigure (struct vectors * vecs)
4ae388
 {
4ae388
 	struct config * old = conf;
4ae388
@@ -1544,12 +1664,18 @@ void
4ae388
 handle_signals(void)
4ae388
 {
4ae388
 	if (reconfig_sig && running_state == DAEMON_RUNNING) {
4ae388
-		condlog(2, "reconfigure (signal)");
4ae388
 		pthread_cleanup_push(cleanup_lock,
4ae388
 				&gvecs->lock);
4ae388
 		lock(gvecs->lock);
4ae388
 		pthread_testcancel();
4ae388
-		reconfigure(gvecs);
4ae388
+		if (need_to_delay_reconfig(gvecs)) {
4ae388
+			conf->delayed_reconfig = 1;
4ae388
+			condlog(2, "delaying reconfigure (signal)");
4ae388
+		}
4ae388
+		else {
4ae388
+			condlog(2, "reconfigure (signal)");
4ae388
+			reconfigure(gvecs);
4ae388
+		}
4ae388
 		lock_cleanup_pop(gvecs->lock);
4ae388
 	}
4ae388
 	if (log_reset_sig) {
4ae388
Index: multipath-tools-130222/multipathd/main.h
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/multipathd/main.h
4ae388
+++ multipath-tools-130222/multipathd/main.h
4ae388
@@ -18,6 +18,7 @@ extern pid_t daemon_pid;
4ae388
 
4ae388
 void exit_daemon(void);
4ae388
 const char * daemon_status(void);
4ae388
+int need_to_delay_reconfig (struct vectors *);
4ae388
 int reconfigure (struct vectors *);
4ae388
 int ev_add_path (struct path *, struct vectors *);
4ae388
 int ev_remove_path (struct path *, struct vectors *);
4ae388
Index: multipath-tools-130222/libmultipath/config.c
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/config.c
4ae388
+++ multipath-tools-130222/libmultipath/config.c
4ae388
@@ -676,6 +676,7 @@ load_config (char * file, struct udev *u
4ae388
 	conf->retrigger_tries = DEFAULT_RETRIGGER_TRIES;
4ae388
 	conf->retrigger_delay = DEFAULT_RETRIGGER_DELAY;
4ae388
 	conf->new_bindings_in_boot = 0;
4ae388
+	conf->uev_wait_timeout = DEFAULT_UEV_WAIT_TIMEOUT;
4ae388
 
4ae388
 	/*
4ae388
 	 * preload default hwtable
4ae388
Index: multipath-tools-130222/libmultipath/defaults.h
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/defaults.h
4ae388
+++ multipath-tools-130222/libmultipath/defaults.h
4ae388
@@ -23,6 +23,7 @@
4ae388
 #define DEFAULT_DELAY_CHECKS DELAY_CHECKS_OFF
4ae388
 #define DEFAULT_RETRIGGER_DELAY 10
4ae388
 #define DEFAULT_RETRIGGER_TRIES 3
4ae388
+#define DEFAULT_UEV_WAIT_TIMEOUT 30
4ae388
 
4ae388
 #define DEFAULT_CHECKINT	5
4ae388
 #define MAX_CHECKINT(a)		(a << 2)
4ae388
Index: multipath-tools-130222/libmultipath/dict.c
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/dict.c
4ae388
+++ multipath-tools-130222/libmultipath/dict.c
4ae388
@@ -872,6 +872,24 @@ def_retrigger_delay_handler(vector strve
4ae388
 }
4ae388
 
4ae388
 static int
4ae388
+def_uev_wait_timeout_handler(vector strvec)
4ae388
+{
4ae388
+	char *buff;
4ae388
+
4ae388
+	buff = set_value(strvec);
4ae388
+
4ae388
+	if (!buff)
4ae388
+		return 1;
4ae388
+
4ae388
+	conf->uev_wait_timeout = atoi(buff);
4ae388
+	if (conf->uev_wait_timeout <= 0)
4ae388
+		conf->uev_wait_timeout = DEFAULT_UEV_WAIT_TIMEOUT;
4ae388
+	FREE(buff);
4ae388
+
4ae388
+	return 0;
4ae388
+}
4ae388
+
4ae388
+static int
4ae388
 def_new_bindings_in_boot_handler(vector strvec)
4ae388
 {
4ae388
 	char * buff;
4ae388
@@ -3261,6 +3279,12 @@ snprint_def_retrigger_delay (char * buff
4ae388
 }
4ae388
 
4ae388
 static int
4ae388
+snprint_def_uev_wait_timeout (char * buff, int len, void * data)
4ae388
+{
4ae388
+	return snprintf(buff, len, "%i", conf->uev_wait_timeout);
4ae388
+}
4ae388
+
4ae388
+static int
4ae388
 snprint_def_new_bindings_in_boot(char * buff, int len, void * data)
4ae388
 {
4ae388
 	if (conf->new_bindings_in_boot == 1)
4ae388
@@ -3345,6 +3369,7 @@ init_keywords(void)
4ae388
 	install_keyword("delay_wait_checks", &def_delay_wait_checks_handler, &snprint_def_delay_wait_checks);
4ae388
 	install_keyword("retrigger_tries", &def_retrigger_tries_handler, &snprint_def_retrigger_tries);
4ae388
 	install_keyword("retrigger_delay", &def_retrigger_delay_handler, &snprint_def_retrigger_delay);
4ae388
+	install_keyword("missing_uev_wait_timeout", &def_uev_wait_timeout_handler, &snprint_def_uev_wait_timeout);
4ae388
 	install_keyword("new_bindings_in_boot", &def_new_bindings_in_boot_handler, &snprint_def_new_bindings_in_boot);
4ae388
 	__deprecated install_keyword("default_selector", &def_selector_handler, NULL);
4ae388
 	__deprecated install_keyword("default_path_grouping_policy", &def_pgpolicy_handler, NULL);
4ae388
Index: multipath-tools-130222/multipath.conf.defaults
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/multipath.conf.defaults
4ae388
+++ multipath-tools-130222/multipath.conf.defaults
4ae388
@@ -29,6 +29,7 @@
4ae388
 #	config_dir "/etc/multipath/conf.d"
4ae388
 #	delay_watch_checks no
4ae388
 #	delay_wait_checks no
4ae388
+#	missing_uev_wait_timeout 30
4ae388
 #}
4ae388
 #blacklist {
4ae388
 #	devnode "^(ram|raw|loop|fd|md|dm-|sr|scd|st)[0-9]*"
4ae388
Index: multipath-tools-130222/multipath/multipath.conf.5
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/multipath/multipath.conf.5
4ae388
+++ multipath-tools-130222/multipath/multipath.conf.5
4ae388
@@ -478,6 +478,14 @@ used until it has passed
4ae388
 .I delay_wait_checks
4ae388
 checks. Default is
4ae388
 .I no
4ae388
+.TP
4ae388
+.B missing_uev_wait_timeout
4ae388
+Controls how many seconds multipathd will wait, after a new multipath device
4ae388
+is created, to receive a change event from udev for the device, before
4ae388
+automatically enabling device reloads. Usually multipathd will delay reloads
4ae388
+on a device until it receives a change uevent from the initial table load. The
4ae388
+default is
4ae388
+.I 30
4ae388
 .
4ae388
 .SH "blacklist section"
4ae388
 The