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

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