Blame SOURCES/autofs-5.1.7-refactor-umount_multi_triggers.patch

29d2b9
autofs-5.1.7 - refactor umount_multi_triggers()
29d2b9
29d2b9
From: Ian Kent <raven@themaw.net>
29d2b9
29d2b9
Refactor umount_multi_triggers() to try the umount of an offset subtree
29d2b9
in a seperate function.
29d2b9
29d2b9
Signed-off-by: Ian Kent <raven@themaw.net>
29d2b9
---
29d2b9
 CHANGELOG    |    1 
29d2b9
 lib/mounts.c |  187 ++++++++++++++++++++++++++++++++--------------------------
29d2b9
 2 files changed, 104 insertions(+), 84 deletions(-)
29d2b9
29d2b9
diff --git a/CHANGELOG b/CHANGELOG
29d2b9
index 3eda995c..5a3bedc1 100644
29d2b9
--- a/CHANGELOG
29d2b9
+++ b/CHANGELOG
29d2b9
@@ -11,6 +11,7 @@
29d2b9
 - set offset parent in update_offset_entry().
29d2b9
 - remove redundant variables from mount_autofs_offset().
29d2b9
 - remove unused parameter form do_mount_autofs_offset().
29d2b9
+- refactor umount_multi_triggers().
29d2b9
 
29d2b9
 25/01/2021 autofs-5.1.7
29d2b9
 - make bind mounts propagation slave by default.
29d2b9
diff --git a/lib/mounts.c b/lib/mounts.c
29d2b9
index 8e88182f..5268ba5b 100644
29d2b9
--- a/lib/mounts.c
29d2b9
+++ b/lib/mounts.c
29d2b9
@@ -2496,57 +2496,6 @@ static int do_mount_autofs_offset(struct autofs_point *ap,
29d2b9
 	return mounted;
29d2b9
 }
29d2b9
 
29d2b9
-int mount_multi_triggers(struct autofs_point *ap, struct mapent *me,
29d2b9
-			 const char *root, unsigned int start, const char *base)
29d2b9
-{
29d2b9
-	char path[PATH_MAX + 1];
29d2b9
-	char *offset = path;
29d2b9
-	struct mapent *oe;
29d2b9
-	struct list_head *pos = NULL;
29d2b9
-	unsigned int root_len = strlen(root);
29d2b9
-	int mounted;
29d2b9
-
29d2b9
-	mounted = 0;
29d2b9
-	offset = cache_get_offset(base, offset, start, &me->multi_list, &pos;;
29d2b9
-	while (offset) {
29d2b9
-		char key[PATH_MAX + 1];
29d2b9
-		int key_len = root_len + strlen(offset);
29d2b9
-
29d2b9
-		if (key_len > PATH_MAX) {
29d2b9
-			warn(ap->logopt, "path loo long");
29d2b9
-			goto cont;
29d2b9
-		}
29d2b9
-
29d2b9
-		/* The root offset is always mounted seperately so the
29d2b9
-		 * offset path will always be root + offset.
29d2b9
-		 */
29d2b9
-		strcpy(key, root);
29d2b9
-		strcat(key, offset);
29d2b9
-
29d2b9
-		oe = cache_lookup_distinct(me->mc, key);
29d2b9
-		if (!oe || !oe->mapent)
29d2b9
-			goto cont;
29d2b9
-
29d2b9
-		mounted += do_mount_autofs_offset(ap, oe, root);
29d2b9
-
29d2b9
-		/*
29d2b9
-		 * If re-constructing a multi-mount it's necessary to walk
29d2b9
-		 * into nested mounts, unlike the usual "mount only what's
29d2b9
-		 * needed as you go" behavior.
29d2b9
-		 */
29d2b9
-		if (ap->state == ST_READMAP && ap->flags & MOUNT_FLAG_REMOUNT) {
29d2b9
-			if (oe->ioctlfd != -1 ||
29d2b9
-			    is_mounted(oe->key, MNTS_REAL))
29d2b9
-				mount_multi_triggers(ap, oe, key, strlen(key), base);
29d2b9
-		}
29d2b9
-cont:
29d2b9
-		offset = cache_get_offset(base,
29d2b9
-				offset, start, &me->multi_list, &pos;;
29d2b9
-	}
29d2b9
-
29d2b9
-	return mounted;
29d2b9
-}
29d2b9
-
29d2b9
 static int rmdir_path_offset(struct autofs_point *ap, struct mapent *oe)
29d2b9
 {
29d2b9
 	char *dir, *path;
29d2b9
@@ -2582,7 +2531,10 @@ static int rmdir_path_offset(struct autofs_point *ap, struct mapent *oe)
29d2b9
 	return ret;
29d2b9
 }
29d2b9
 
29d2b9
-int umount_multi_triggers(struct autofs_point *ap, struct mapent *me, char *root, const char *base)
29d2b9
+static int do_umount_offset(struct autofs_point *ap, struct mapent *oe, const char *root);
29d2b9
+
29d2b9
+static int do_umount_multi_triggers(struct autofs_point *ap,
29d2b9
+				    struct mapent *me, const char *root, const char *base)
29d2b9
 {
29d2b9
 	char path[PATH_MAX + 1];
29d2b9
 	char *offset;
29d2b9
@@ -2612,7 +2564,6 @@ int umount_multi_triggers(struct autofs_point *ap, struct mapent *me, char *root
29d2b9
 	while ((offset = cache_get_offset(mm_base, offset, start, mm_root, &pos))) {
29d2b9
 		char key[PATH_MAX + 1];
29d2b9
 		int key_len = root_len + strlen(offset);
29d2b9
-		char *oe_base;
29d2b9
 
29d2b9
 		if (mm_base_len > 1)
29d2b9
 			key_len += mm_base_len;
29d2b9
@@ -2632,47 +2583,116 @@ int umount_multi_triggers(struct autofs_point *ap, struct mapent *me, char *root
29d2b9
 		if (!oe || (strlen(oe->key) - start) == 1)
29d2b9
 			continue;
29d2b9
 
29d2b9
+		left += do_umount_offset(ap, oe, root);
29d2b9
+	}
29d2b9
+
29d2b9
+	return left;
29d2b9
+}
29d2b9
+
29d2b9
+static int do_umount_offset(struct autofs_point *ap, struct mapent *oe, const char *root)
29d2b9
+{
29d2b9
+	char *oe_base;
29d2b9
+	int left = 0;
29d2b9
+
29d2b9
+	/*
29d2b9
+	 * Check for and umount subtree offsets resulting from
29d2b9
+	 * nonstrict mount fail.
29d2b9
+	 */
29d2b9
+	oe_base = oe->key + strlen(root);
29d2b9
+	left += do_umount_multi_triggers(ap, oe, root, oe_base);
29d2b9
+
29d2b9
+	if (oe->ioctlfd != -1 ||
29d2b9
+	    is_mounted(oe->key, MNTS_REAL)) {
29d2b9
+		left++;
29d2b9
+		return left;
29d2b9
+	}
29d2b9
+
29d2b9
+	debug(ap->logopt, "umount offset %s", oe->key);
29d2b9
+
29d2b9
+	if (umount_autofs_offset(ap, oe)) {
29d2b9
+		warn(ap->logopt, "failed to umount offset");
29d2b9
+		left++;
29d2b9
+	} else {
29d2b9
+		struct stat st;
29d2b9
+		int ret;
29d2b9
+
29d2b9
+		if (!(oe->flags & MOUNT_FLAG_DIR_CREATED))
29d2b9
+			return left;
29d2b9
+
29d2b9
 		/*
29d2b9
-		 * Check for and umount subtree offsets resulting from
29d2b9
-		 * nonstrict mount fail.
29d2b9
+		 * An error due to partial directory removal is
29d2b9
+		 * ok so only try and remount the offset if the
29d2b9
+		 * actual mount point still exists.
29d2b9
 		 */
29d2b9
-		oe_base = oe->key + strlen(root);
29d2b9
-		left += umount_multi_triggers(ap, oe, root, oe_base);
29d2b9
+		ret = rmdir_path_offset(ap, oe);
29d2b9
+		if (ret == -1 && !stat(oe->key, &st)) {
29d2b9
+			ret = do_mount_autofs_offset(ap, oe, root);
29d2b9
+			if (ret)
29d2b9
+				left++;
29d2b9
+			/* But we did origianlly create this */
29d2b9
+			oe->flags |= MOUNT_FLAG_DIR_CREATED;
29d2b9
+		}
29d2b9
+	}
29d2b9
+	return left;
29d2b9
+}
29d2b9
 
29d2b9
-		if (oe->ioctlfd != -1 ||
29d2b9
-		    is_mounted(oe->key, MNTS_REAL)) {
29d2b9
-			left++;
29d2b9
-			continue;
29d2b9
+int mount_multi_triggers(struct autofs_point *ap, struct mapent *me,
29d2b9
+			 const char *root, unsigned int start, const char *base)
29d2b9
+{
29d2b9
+	char path[PATH_MAX + 1];
29d2b9
+	char *offset = path;
29d2b9
+	struct mapent *oe;
29d2b9
+	struct list_head *pos = NULL;
29d2b9
+	unsigned int root_len = strlen(root);
29d2b9
+	int mounted;
29d2b9
+
29d2b9
+	mounted = 0;
29d2b9
+	offset = cache_get_offset(base, offset, start, &me->multi_list, &pos;;
29d2b9
+	while (offset) {
29d2b9
+		char key[PATH_MAX + 1];
29d2b9
+		int key_len = root_len + strlen(offset);
29d2b9
+
29d2b9
+		if (key_len > PATH_MAX) {
29d2b9
+			warn(ap->logopt, "path loo long");
29d2b9
+			goto cont;
29d2b9
 		}
29d2b9
 
29d2b9
-		debug(ap->logopt, "umount offset %s", oe->key);
29d2b9
+		/* The root offset is always mounted seperately so the
29d2b9
+		 * offset path will always be root + offset.
29d2b9
+		 */
29d2b9
+		strcpy(key, root);
29d2b9
+		strcat(key, offset);
29d2b9
 
29d2b9
-		if (umount_autofs_offset(ap, oe)) {
29d2b9
-			warn(ap->logopt, "failed to umount offset");
29d2b9
-			left++;
29d2b9
-		} else {
29d2b9
-			struct stat st;
29d2b9
-			int ret;
29d2b9
+		oe = cache_lookup_distinct(me->mc, key);
29d2b9
+		if (!oe || !oe->mapent)
29d2b9
+			goto cont;
29d2b9
 
29d2b9
-			if (!(oe->flags & MOUNT_FLAG_DIR_CREATED))
29d2b9
-				continue;
29d2b9
+		mounted += do_mount_autofs_offset(ap, oe, root);
29d2b9
 
29d2b9
-			/*
29d2b9
-			 * An error due to partial directory removal is
29d2b9
-			 * ok so only try and remount the offset if the
29d2b9
-			 * actual mount point still exists.
29d2b9
-			 */
29d2b9
-			ret = rmdir_path_offset(ap, oe);
29d2b9
-			if (ret == -1 && !stat(oe->key, &st)) {
29d2b9
-				ret = do_mount_autofs_offset(ap, oe, root);
29d2b9
-				if (ret)
29d2b9
-					left++;
29d2b9
-				/* But we did origianlly create this */
29d2b9
-				oe->flags |= MOUNT_FLAG_DIR_CREATED;
29d2b9
-			}
29d2b9
+		/*
29d2b9
+		 * If re-constructing a multi-mount it's necessary to walk
29d2b9
+		 * into nested mounts, unlike the usual "mount only what's
29d2b9
+		 * needed as you go" behavior.
29d2b9
+		 */
29d2b9
+		if (ap->state == ST_READMAP && ap->flags & MOUNT_FLAG_REMOUNT) {
29d2b9
+			if (oe->ioctlfd != -1 ||
29d2b9
+			    is_mounted(oe->key, MNTS_REAL))
29d2b9
+				mount_multi_triggers(ap, oe, key, strlen(key), base);
29d2b9
 		}
29d2b9
+cont:
29d2b9
+		offset = cache_get_offset(base,
29d2b9
+				offset, start, &me->multi_list, &pos;;
29d2b9
 	}
29d2b9
 
29d2b9
+	return mounted;
29d2b9
+}
29d2b9
+
29d2b9
+int umount_multi_triggers(struct autofs_point *ap, struct mapent *me, char *root, const char *base)
29d2b9
+{
29d2b9
+	int left;
29d2b9
+
29d2b9
+	left = do_umount_multi_triggers(ap, me, root, base);
29d2b9
+
29d2b9
 	if (!left && me->multi == me) {
29d2b9
 		struct mapent_cache *mc = me->mc;
29d2b9
 		int status;
29d2b9
@@ -2871,4 +2891,3 @@ int clean_stale_multi_triggers(struct autofs_point *ap,
29d2b9
 
29d2b9
 	return left;
29d2b9
 }
29d2b9
-