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

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