Blame SOURCES/autofs-5.1.7-eliminate-clean_stale_multi_triggers.patch

49b67f
autofs-5.1.7 - eliminate clean_stale_multi_triggers()
49b67f
49b67f
From: Ian Kent <raven@themaw.net>
49b67f
49b67f
Eliminate clean_stale_multi_triggers() by checking for stale offsets at
49b67f
the time mount_subtree() is called.
49b67f
49b67f
This should result in the same behaviour but eliminate an additional
49b67f
seperate traversal of the offset list.
49b67f
49b67f
Signed-off-by: Ian Kent <raven@themaw.net>
49b67f
---
49b67f
 CHANGELOG           |    1 
49b67f
 lib/mounts.c        |  209 ++++++++++------------------------------------------
49b67f
 modules/parse_sun.c |   10 --
49b67f
 3 files changed, 43 insertions(+), 177 deletions(-)
49b67f
49b67f
--- autofs-5.1.4.orig/CHANGELOG
49b67f
+++ autofs-5.1.4/CHANGELOG
49b67f
@@ -11,6 +11,7 @@
49b67f
 - remove redundant variables from mount_autofs_offset().
49b67f
 - remove unused parameter form do_mount_autofs_offset().
49b67f
 - refactor umount_multi_triggers().
49b67f
+- eliminate clean_stale_multi_triggers().
49b67f
 
49b67f
 xx/xx/2018 autofs-5.1.5
49b67f
 - fix flag file permission.
49b67f
--- autofs-5.1.4.orig/lib/mounts.c
49b67f
+++ autofs-5.1.4/lib/mounts.c
49b67f
@@ -2595,10 +2595,44 @@ static int do_umount_offset(struct autof
49b67f
 	oe_base = oe->key + strlen(root);
49b67f
 	left += do_umount_multi_triggers(ap, oe, root, oe_base);
49b67f
 
49b67f
+	/*
49b67f
+	 * If an offset that has an active mount has been removed
49b67f
+	 * from the multi-mount we don't want to attempt to trigger
49b67f
+	 * mounts for it. Obviously this is because it has been
49b67f
+	 * removed, but less obvious is the potential strange
49b67f
+	 * behaviour that can result if we do try and mount it
49b67f
+	 * again after it's been expired. For example, if an NFS
49b67f
+	 * file system is no longer exported and is later umounted
49b67f
+	 * it can be mounted again without any error message but
49b67f
+	 * shows as an empty directory. That's going to confuse
49b67f
+	 * people for sure.
49b67f
+	 *
49b67f
+	 * If the mount cannot be umounted (the process is now
49b67f
+	 * using a stale mount) the offset needs to be invalidated
49b67f
+	 * so no further mounts will be attempted but the offset
49b67f
+	 * cache entry must remain so expires can continue to
49b67f
+	 * attempt to umount it. If the mount can be umounted and
49b67f
+	 * the offset is removed, at least for NFS we will get
49b67f
+	 * ESTALE errors when attempting list the directory.
49b67f
+	 */
49b67f
 	if (oe->ioctlfd != -1 ||
49b67f
 	    is_mounted(oe->key, MNTS_REAL)) {
49b67f
-		left++;
49b67f
-		return left;
49b67f
+		if (umount_ent(ap, oe->key) &&
49b67f
+		    is_mounted(oe->key, MNTS_REAL)) {
49b67f
+			debug(ap->logopt,
49b67f
+			      "offset %s has active mount, invalidate",
49b67f
+			      oe->key);
49b67f
+			/*
49b67f
+			 * Ok, so we shouldn't modify the mapent but
49b67f
+			 * mount requests are blocked at a point above
49b67f
+			 * this and expire only uses the mapent key.
49b67f
+			 */
49b67f
+			if (oe->mapent) {
49b67f
+				free(oe->mapent);
49b67f
+				oe->mapent = NULL;
49b67f
+			}
49b67f
+			return ++left;
49b67f
+		}
49b67f
 	}
49b67f
 
49b67f
 	debug(ap->logopt, "umount offset %s", oe->key);
49b67f
@@ -2660,6 +2694,11 @@ int mount_multi_triggers(struct autofs_p
49b67f
 		oe = cache_lookup_distinct(me->mc, key);
49b67f
 		if (!oe || !oe->mapent)
49b67f
 			goto cont;
49b67f
+		if (oe->age != me->multi->age) {
49b67f
+			/* Best effort */
49b67f
+			do_umount_offset(ap, oe, root);
49b67f
+			goto cont;
49b67f
+		}
49b67f
 
49b67f
 		mounted += do_mount_autofs_offset(ap, oe, root);
49b67f
 
49b67f
@@ -2718,170 +2757,4 @@ int umount_multi_triggers(struct autofs_
49b67f
 	}
49b67f
 
49b67f
 	return left;
49b67f
-}
49b67f
-
49b67f
-int clean_stale_multi_triggers(struct autofs_point *ap,
49b67f
-			       struct mapent *me, char *top, const char *base)
49b67f
-{
49b67f
-	char *root;
49b67f
-	char mm_top[PATH_MAX + 1];
49b67f
-	char path[PATH_MAX + 1];
49b67f
-	char *offset;
49b67f
-	struct mapent *oe;
49b67f
-	struct list_head *mm_root, *pos;
49b67f
-	const char o_root[] = "/";
49b67f
-	const char *mm_base;
49b67f
-	int left, start;
49b67f
-	unsigned int root_len;
49b67f
-	unsigned int mm_base_len;
49b67f
-	time_t age;
49b67f
-
49b67f
-	if (top)
49b67f
-		root = top;
49b67f
-	else {
49b67f
-		if (!strchr(me->multi->key, '/'))
49b67f
-			/* Indirect multi-mount root */
49b67f
-			/* sprintf okay - if it's mounted, it's
49b67f
-			 * PATH_MAX or less bytes */
49b67f
-			sprintf(mm_top, "%s/%s", ap->path, me->multi->key);
49b67f
-		else
49b67f
-			strcpy(mm_top, me->multi->key);
49b67f
-		root = mm_top;
49b67f
-	}
49b67f
-
49b67f
-	left = 0;
49b67f
-	start = strlen(root);
49b67f
-
49b67f
-	mm_root = &me->multi->multi_list;
49b67f
-
49b67f
-	if (!base)
49b67f
-		mm_base = o_root;
49b67f
-	else
49b67f
-		mm_base = base;
49b67f
-
49b67f
-	pos = NULL;
49b67f
-	offset = path;
49b67f
-	root_len = start;
49b67f
-	mm_base_len = strlen(mm_base);
49b67f
-	age = me->multi->age;
49b67f
-
49b67f
-	while ((offset = cache_get_offset(mm_base, offset, start, mm_root, &pos))) {
49b67f
-		char key[PATH_MAX + 1];
49b67f
-		int key_len = root_len + strlen(offset);
49b67f
-		char *oe_base;
49b67f
-		int ret;
49b67f
-
49b67f
-		if (mm_base_len > 1)
49b67f
-			key_len += mm_base_len;
49b67f
-
49b67f
-		if (key_len > PATH_MAX) {
49b67f
-			warn(ap->logopt, "path loo long");
49b67f
-			continue;
49b67f
-		}
49b67f
-
49b67f
-		strcpy(key, root);
49b67f
-		if (mm_base_len > 1)
49b67f
-			strcat(key, mm_base);
49b67f
-		strcat(key, offset);
49b67f
-
49b67f
-		oe = cache_lookup_distinct(me->mc, key);
49b67f
-		/* root offset is a special case */
49b67f
-		if (!oe || (strlen(oe->key) - start) == 1)
49b67f
-			continue;
49b67f
-
49b67f
-		/* Check for and umount stale subtree offsets */
49b67f
-		oe_base = oe->key + strlen(root);
49b67f
-		ret = clean_stale_multi_triggers(ap, oe, root, oe_base);
49b67f
-		left += ret;
49b67f
-		if (ret)
49b67f
-			continue;
49b67f
-
49b67f
-		if (oe->age == age)
49b67f
-			continue;
49b67f
-
49b67f
-		/*
49b67f
-		 * If an offset that has an active mount has been removed
49b67f
-		 * from the multi-mount we don't want to attempt to trigger
49b67f
-		 * mounts for it. Obviously this is because it has been
49b67f
-		 * removed, but less obvious is the potential strange
49b67f
-		 * behaviour that can result if we do try and mount it
49b67f
-		 * again after it's been expired. For example, if an NFS
49b67f
-		 * file system is no longer exported and is later umounted
49b67f
-		 * it can be mounted again without any error message but
49b67f
-		 * shows as an empty directory. That's going to confuse
49b67f
-		 * people for sure.
49b67f
-		 *
49b67f
-		 * If the mount cannot be umounted (the process is now
49b67f
-		 * using a stale mount) the offset needs to be invalidated
49b67f
-		 * so no further mounts will be attempted but the offset
49b67f
-		 * cache entry must remain so expires can continue to
49b67f
-		 * attempt to umount it. If the mount can be umounted and
49b67f
-		 * the offset is removed, at least for NFS we will get
49b67f
-		 * ESTALE errors when attempting list the directory.
49b67f
-		 */
49b67f
-		if (oe->ioctlfd != -1 ||
49b67f
-		    is_mounted(oe->key, MNTS_REAL)) {
49b67f
-			if (umount_ent(ap, oe->key) &&
49b67f
-			    is_mounted(oe->key, MNTS_REAL)) {
49b67f
-				debug(ap->logopt,
49b67f
-				      "offset %s has active mount, invalidate",
49b67f
-				      oe->key);
49b67f
-				if (oe->mapent) {
49b67f
-					free(oe->mapent);
49b67f
-					oe->mapent = NULL;
49b67f
-				}
49b67f
-				left++;
49b67f
-				continue;
49b67f
-			}
49b67f
-		}
49b67f
-
49b67f
-		debug(ap->logopt, "umount offset %s", oe->key);
49b67f
-
49b67f
-		if (umount_autofs_offset(ap, oe)) {
49b67f
-			warn(ap->logopt, "failed to umount offset %s", key);
49b67f
-			left++;
49b67f
-		} else {
49b67f
-			struct stat st;
49b67f
-
49b67f
-			/* Mount point not ours to delete ? */
49b67f
-			if (!(oe->flags & MOUNT_FLAG_DIR_CREATED)) {
49b67f
-				debug(ap->logopt, "delete offset key %s", key);
49b67f
-				if (cache_delete_offset(oe->mc, key) == CHE_FAIL)
49b67f
-					error(ap->logopt,
49b67f
-					     "failed to delete offset key %s", key);
49b67f
-				continue;
49b67f
-			}
49b67f
-
49b67f
-			/*
49b67f
-			 * An error due to partial directory removal is
49b67f
-			 * ok so only try and remount the offset if the
49b67f
-			 * actual mount point still exists.
49b67f
-			 */
49b67f
-			ret = rmdir_path_offset(ap, oe);
49b67f
-			if (ret == -1 && !stat(oe->key, &st)) {
49b67f
-				ret = do_mount_autofs_offset(ap, oe, root);
49b67f
-				if (ret) {
49b67f
-					left++;
49b67f
-					/* But we did origianlly create this */
49b67f
-					oe->flags |= MOUNT_FLAG_DIR_CREATED;
49b67f
-					continue;
49b67f
-				}
49b67f
-				/*
49b67f
-				 * Fall through if the trigger can't be mounted
49b67f
-				 * again, since there is no offset there can't
49b67f
-				 * be any mount requests so remove the map
49b67f
-				 * entry from the cache. There's now a dead
49b67f
-				 * offset mount, but what else can we do ....
49b67f
-				 */
49b67f
-			}
49b67f
-
49b67f
-			debug(ap->logopt, "delete offset key %s", key);
49b67f
-
49b67f
-			if (cache_delete_offset(oe->mc, key) == CHE_FAIL)
49b67f
-				error(ap->logopt,
49b67f
-				     "failed to delete offset key %s", key);
49b67f
-		}
49b67f
-	}
49b67f
-
49b67f
-	return left;
49b67f
 }
49b67f
--- autofs-5.1.4.orig/modules/parse_sun.c
49b67f
+++ autofs-5.1.4/modules/parse_sun.c
49b67f
@@ -1178,7 +1178,7 @@ static int mount_subtree(struct autofs_p
49b67f
 
49b67f
 		/* Mount root offset if it exists */
49b67f
 		ro = cache_lookup_distinct(me->mc, key);
49b67f
-		if (ro) {
49b67f
+		if (ro && ro->age == me->multi->age) {
49b67f
 			char *myoptions, *ro_loc;
49b67f
 			int namelen = name ? strlen(name) : 0;
49b67f
 			int ro_len;
49b67f
@@ -1612,14 +1612,6 @@ dont_expand:
49b67f
 			free(myoptions);
49b67f
 		} while (*p == '/' || (*p == '"' && *(p + 1) == '/'));
49b67f
 
49b67f
-		/*
49b67f
-		 * We've got the ordered list of multi-mount entries so go
49b67f
-		 * through and remove any stale entries if this is the top
49b67f
-		 * of the multi-mount and set the parent entry of each.
49b67f
-		 */
49b67f
-		if (me == me->multi)
49b67f
-			clean_stale_multi_triggers(ap, me, NULL, NULL);
49b67f
-
49b67f
 		rv = mount_subtree(ap, me, name, NULL, options, ctxt);
49b67f
 
49b67f
 		cache_multi_unlock(me);