Blame SOURCES/autofs-5.0.9-amd-lookup-fix-host-mount-naming.patch

304803
autofs-5.0.9 - amd lookup fix host mount naming
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
Currently the amd host mount type assumes the lookup name is
304803
the host name for the host mount but amd uses ${rhost} for
304803
this.
304803
304803
This introduces the possibility of multiple concurrent mount
304803
requests since constructing a mount tree that isn't under the
304803
lookup name can't take advantage of the kernel queuing other
304803
concurrent lookups while the mount tree is constructed.
304803
---
304803
 daemon/lookup.c     |   20 +++++++++++++----
304803
 modules/parse_amd.c |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++--
304803
 modules/parse_sun.c |   22 +++++++++++-------
304803
 3 files changed, 89 insertions(+), 14 deletions(-)
304803
304803
--- autofs-5.0.7.orig/daemon/lookup.c
304803
+++ autofs-5.0.7/daemon/lookup.c
304803
@@ -815,7 +815,8 @@ static int lookup_amd_instance(struct au
304803
 
304803
 	m_key = malloc(strlen(ap->path) + strlen(me->multi->key) + 1);
304803
 	if (!m_key) {
304803
-		error(ap->logopt, "failed to allocate storage for search key");
304803
+		error(ap->logopt,
304803
+		     "failed to allocate storage for search key");
304803
 		return NSS_STATUS_UNKNOWN;
304803
 	}
304803
 
304803
@@ -823,12 +824,12 @@ static int lookup_amd_instance(struct au
304803
 	strcat(m_key, "/");
304803
 	strcat(m_key, me->multi->key);
304803
 	entry = master_find_amdmount(ap, m_key);
304803
+	free(m_key);
304803
+
304803
 	if (!entry) {
304803
 		error(ap->logopt, "expected amd mount entry not found");
304803
-		free(m_key);
304803
 		return NSS_STATUS_UNKNOWN;
304803
 	}
304803
-	free(m_key);
304803
 
304803
 	if (strcmp(entry->type, "host")) {
304803
 		error(ap->logopt, "unexpected map type %s", entry->type);
304803
@@ -843,6 +844,17 @@ static int lookup_amd_instance(struct au
304803
 	}
304803
 
304803
 	instance = master_find_source_instance(map, "hosts", "sun", argc, pargv);
304803
+	/* If this is an nss map instance it may have an amd host map sub instance */
304803
+	if (!instance && map->instance) {
304803
+		struct map_source *next = map->instance;
304803
+		while (next) {
304803
+			instance = master_find_source_instance(next,
304803
+						"hosts", "sun", argc, pargv);
304803
+			if (instance)
304803
+				break;
304803
+			next = next->next;
304803
+		}
304803
+	}
304803
 	if (!instance) {
304803
 		error(ap->logopt, "expected hosts map instance not found");
304803
 		return NSS_STATUS_UNKNOWN;
304803
@@ -1174,7 +1186,6 @@ int lookup_nss_mount(struct autofs_point
304803
 	}
304803
 	if (ap->state != ST_INIT)
304803
 		send_map_update_request(ap);
304803
-	pthread_cleanup_pop(1);
304803
 
304803
 	/*
304803
 	 * The last source lookup will return NSS_STATUS_NOTFOUND if the
304803
@@ -1183,6 +1194,7 @@ int lookup_nss_mount(struct autofs_point
304803
 	 */
304803
 	if (result == NSS_STATUS_NOTFOUND || result == NSS_STATUS_UNAVAIL)
304803
 		update_negative_cache(ap, source, name);
304803
+	pthread_cleanup_pop(1);
304803
 
304803
 	return !result;
304803
 }
304803
--- autofs-5.0.7.orig/modules/parse_amd.c
304803
+++ autofs-5.0.7/modules/parse_amd.c
304803
@@ -1068,6 +1068,23 @@ static int do_nfsl_mount(struct autofs_p
304803
 	return do_link_mount(ap, name, entry, flags);
304803
 }
304803
 
304803
+static int wait_for_expire(struct autofs_point *ap)
304803
+{
304803
+	int ret = 1;
304803
+
304803
+	st_wait_task(ap, ST_EXPIRE, 0);
304803
+
304803
+	st_mutex_lock();
304803
+	if (ap->state != ST_SHUTDOWN &&
304803
+	    ap->state != ST_SHUTDOWN_PENDING &&
304803
+	    ap->state != ST_SHUTDOWN_FORCE) {
304803
+		ret = 0;
304803
+	}
304803
+	st_mutex_unlock();
304803
+
304803
+	return ret;
304803
+}
304803
+
304803
 static int do_host_mount(struct autofs_point *ap, const char *name,
304803
 			 struct amd_entry *entry, struct map_source *source,
304803
 			 unsigned int flags)
304803
@@ -1080,6 +1097,36 @@ static int do_host_mount(struct autofs_p
304803
 	int argc = 0;
304803
 	int ret = 1;
304803
 
304803
+	/*
304803
+	 * If the mount point name isn't the same as the host name
304803
+	 * then we need to symlink to it after the mount. Attempt
304803
+	 * the allocation and set entry->path to the base location
304803
+	 * of the hosts mount tree so we can find it in
304803
+	 * lookup_nss_mount() later.
304803
+	 */
304803
+	if (strcmp(name, entry->rhost)) {
304803
+		char *target;
304803
+		size_t len = strlen(ap->path) + strlen(entry->rhost) + 2;
304803
+		target = malloc(len);
304803
+		if (!target) {
304803
+			warn(ap->logopt, MODPREFIX
304803
+			     "failed to alloc target to hosts mount base");
304803
+			goto out;
304803
+		}
304803
+		strcpy(target, ap->path);
304803
+		strcat(target, "/");
304803
+		strcat(target, entry->rhost);
304803
+		if (entry->path)
304803
+			free(entry->path);
304803
+		entry->path = target;
304803
+		/*
304803
+		 * Wait for any expire before racing to mount the
304803
+		 * export tree or bail out if we're shutting down.
304803
+		*/
304803
+		if (!wait_for_expire(ap))
304803
+			goto out;
304803
+	}
304803
+
304803
 	if (entry->opts) {
304803
 		argv[0] = entry->opts;
304803
 		argv[1] = NULL;
304803
@@ -1095,7 +1142,8 @@ static int do_host_mount(struct autofs_p
304803
 		goto out;
304803
 	}
304803
 
304803
-	instance = master_find_source_instance(source, "hosts", "sun", argc, pargv);
304803
+	instance = master_find_source_instance(source,
304803
+					 "hosts", "sun", argc, pargv);
304803
 	if (!instance) {
304803
 		instance = master_add_source_instance(source,
304803
 				 "hosts", "sun", time(NULL), argc, pargv);
304803
@@ -1119,7 +1167,16 @@ static int do_host_mount(struct autofs_p
304803
 	master_source_current_wait(ap->entry);
304803
 	ap->entry->current = source;
304803
 
304803
-	ret = lookup->lookup_mount(ap, name, strlen(name), lookup->context);
304803
+	ret = lookup->lookup_mount(ap, entry->rhost,
304803
+				   strlen(entry->rhost), lookup->context);
304803
+
304803
+	if (!strcmp(name, entry->rhost))
304803
+		goto out;
304803
+
304803
+	if (do_mount(ap, ap->path,
304803
+		     name, strlen(name), entry->path, "bind", "symlink"))
304803
+		warn(ap->logopt, MODPREFIX
304803
+		     "failed to create symlink to hosts mount base");
304803
 out:
304803
 	return ret;
304803
 }
304803
--- autofs-5.0.7.orig/modules/parse_sun.c
304803
+++ autofs-5.0.7/modules/parse_sun.c
304803
@@ -1343,26 +1343,32 @@ int parse_mount(struct autofs_point *ap,
304803
 			strcat(m_root, name);
304803
 		}
304803
 
304803
+		pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
304803
 		cache_readlock(mc);
304803
 		me = cache_lookup_distinct(mc, name);
304803
-		if (me) {
304803
-			/* So we know we're the multi-mount root */
304803
-			if (!me->multi)
304803
-				me->multi = me;
304803
-		}
304803
-
304803
 		if (!me) {
304803
 			free(options);
304803
 			cache_unlock(mc);
304803
+			pthread_setcancelstate(cur_state, NULL);
304803
 			error(ap->logopt,
304803
 			      MODPREFIX "can't find multi root %s", name);
304803
 			return 1;
304803
 		}
304803
 
304803
+		cache_multi_writelock(me);
304803
+		/* Someone beat us to it, return success */
304803
+		if (me->multi) {
304803
+			free(options);
304803
+			cache_multi_unlock(me);
304803
+			cache_unlock(mc);
304803
+			pthread_setcancelstate(cur_state, NULL);
304803
+			return 0;
304803
+		}
304803
+		/* So we know we're the multi-mount root */
304803
+		me->multi = me;
304803
+
304803
 		age = me->age;
304803
 
304803
-		pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
304803
-		cache_multi_writelock(me);
304803
 		/* It's a multi-mount; deal with it */
304803
 		do {
304803
 			char *path, *myoptions, *loc;