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

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