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

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