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

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