Blame SOURCES/0133-RHBZ-1321019-wait-for-map-add.patch

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