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

beb904
autofs-5.1.7 - refactor umount_multi_triggers()
beb904
beb904
From: Ian Kent <raven@themaw.net>
beb904
beb904
Refactor umount_multi_triggers() to try the umount of an offset subtree
beb904
in a seperate function.
beb904
beb904
Signed-off-by: Ian Kent <raven@themaw.net>
beb904
---
beb904
 CHANGELOG    |    1 
beb904
 lib/mounts.c |  187 ++++++++++++++++++++++++++++++++---------------------------
beb904
 2 files changed, 104 insertions(+), 84 deletions(-)
beb904
beb904
--- autofs-5.1.4.orig/CHANGELOG
beb904
+++ autofs-5.1.4/CHANGELOG
beb904
@@ -10,6 +10,7 @@
beb904
 - set offset parent in update_offset_entry().
beb904
 - remove redundant variables from mount_autofs_offset().
beb904
 - remove unused parameter form do_mount_autofs_offset().
beb904
+- refactor umount_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
@@ -2490,57 +2490,6 @@ static int do_mount_autofs_offset(struct
beb904
 	return mounted;
beb904
 }
beb904
 
beb904
-int mount_multi_triggers(struct autofs_point *ap, struct mapent *me,
beb904
-			 const char *root, unsigned int start, const char *base)
beb904
-{
beb904
-	char path[PATH_MAX + 1];
beb904
-	char *offset = path;
beb904
-	struct mapent *oe;
beb904
-	struct list_head *pos = NULL;
beb904
-	unsigned int root_len = strlen(root);
beb904
-	int mounted;
beb904
-
beb904
-	mounted = 0;
beb904
-	offset = cache_get_offset(base, offset, start, &me->multi_list, &pos;;
beb904
-	while (offset) {
beb904
-		char key[PATH_MAX + 1];
beb904
-		int key_len = root_len + strlen(offset);
beb904
-
beb904
-		if (key_len > PATH_MAX) {
beb904
-			warn(ap->logopt, "path loo long");
beb904
-			goto cont;
beb904
-		}
beb904
-
beb904
-		/* The root offset is always mounted seperately so the
beb904
-		 * offset path will always be root + offset.
beb904
-		 */
beb904
-		strcpy(key, root);
beb904
-		strcat(key, offset);
beb904
-
beb904
-		oe = cache_lookup_distinct(me->mc, key);
beb904
-		if (!oe || !oe->mapent)
beb904
-			goto cont;
beb904
-
beb904
-		mounted += do_mount_autofs_offset(ap, oe, root);
beb904
-
beb904
-		/*
beb904
-		 * If re-constructing a multi-mount it's necessary to walk
beb904
-		 * into nested mounts, unlike the usual "mount only what's
beb904
-		 * needed as you go" behavior.
beb904
-		 */
beb904
-		if (ap->state == ST_READMAP && ap->flags & MOUNT_FLAG_REMOUNT) {
beb904
-			if (oe->ioctlfd != -1 ||
beb904
-			    is_mounted(oe->key, MNTS_REAL))
beb904
-				mount_multi_triggers(ap, oe, key, strlen(key), base);
beb904
-		}
beb904
-cont:
beb904
-		offset = cache_get_offset(base,
beb904
-				offset, start, &me->multi_list, &pos;;
beb904
-	}
beb904
-
beb904
-	return mounted;
beb904
-}
beb904
-
beb904
 static int rmdir_path_offset(struct autofs_point *ap, struct mapent *oe)
beb904
 {
beb904
 	char *dir, *path;
beb904
@@ -2576,7 +2525,10 @@ static int rmdir_path_offset(struct auto
beb904
 	return ret;
beb904
 }
beb904
 
beb904
-int umount_multi_triggers(struct autofs_point *ap, struct mapent *me, char *root, const char *base)
beb904
+static int do_umount_offset(struct autofs_point *ap, struct mapent *oe, const char *root);
beb904
+
beb904
+static int do_umount_multi_triggers(struct autofs_point *ap,
beb904
+				    struct mapent *me, const char *root, const char *base)
beb904
 {
beb904
 	char path[PATH_MAX + 1];
beb904
 	char *offset;
beb904
@@ -2606,7 +2558,6 @@ int umount_multi_triggers(struct autofs_
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
 
beb904
 		if (mm_base_len > 1)
beb904
 			key_len += mm_base_len;
beb904
@@ -2626,47 +2577,116 @@ int umount_multi_triggers(struct autofs_
beb904
 		if (!oe || (strlen(oe->key) - start) == 1)
beb904
 			continue;
beb904
 
beb904
+		left += do_umount_offset(ap, oe, root);
beb904
+	}
beb904
+
beb904
+	return left;
beb904
+}
beb904
+
beb904
+static int do_umount_offset(struct autofs_point *ap, struct mapent *oe, const char *root)
beb904
+{
beb904
+	char *oe_base;
beb904
+	int left = 0;
beb904
+
beb904
+	/*
beb904
+	 * Check for and umount subtree offsets resulting from
beb904
+	 * nonstrict mount fail.
beb904
+	 */
beb904
+	oe_base = oe->key + strlen(root);
beb904
+	left += do_umount_multi_triggers(ap, oe, root, oe_base);
beb904
+
beb904
+	if (oe->ioctlfd != -1 ||
beb904
+	    is_mounted(oe->key, MNTS_REAL)) {
beb904
+		left++;
beb904
+		return left;
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");
beb904
+		left++;
beb904
+	} else {
beb904
+		struct stat st;
beb904
+		int ret;
beb904
+
beb904
+		if (!(oe->flags & MOUNT_FLAG_DIR_CREATED))
beb904
+			return left;
beb904
+
beb904
 		/*
beb904
-		 * Check for and umount subtree offsets resulting from
beb904
-		 * nonstrict mount fail.
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
-		oe_base = oe->key + strlen(root);
beb904
-		left += umount_multi_triggers(ap, oe, root, oe_base);
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
+		}
beb904
+	}
beb904
+	return left;
beb904
+}
beb904
 
beb904
-		if (oe->ioctlfd != -1 ||
beb904
-		    is_mounted(oe->key, MNTS_REAL)) {
beb904
-			left++;
beb904
-			continue;
beb904
+int mount_multi_triggers(struct autofs_point *ap, struct mapent *me,
beb904
+			 const char *root, unsigned int start, const char *base)
beb904
+{
beb904
+	char path[PATH_MAX + 1];
beb904
+	char *offset = path;
beb904
+	struct mapent *oe;
beb904
+	struct list_head *pos = NULL;
beb904
+	unsigned int root_len = strlen(root);
beb904
+	int mounted;
beb904
+
beb904
+	mounted = 0;
beb904
+	offset = cache_get_offset(base, offset, start, &me->multi_list, &pos;;
beb904
+	while (offset) {
beb904
+		char key[PATH_MAX + 1];
beb904
+		int key_len = root_len + strlen(offset);
beb904
+
beb904
+		if (key_len > PATH_MAX) {
beb904
+			warn(ap->logopt, "path loo long");
beb904
+			goto cont;
beb904
 		}
beb904
 
beb904
-		debug(ap->logopt, "umount offset %s", oe->key);
beb904
+		/* The root offset is always mounted seperately so the
beb904
+		 * offset path will always be root + offset.
beb904
+		 */
beb904
+		strcpy(key, root);
beb904
+		strcat(key, offset);
beb904
 
beb904
-		if (umount_autofs_offset(ap, oe)) {
beb904
-			warn(ap->logopt, "failed to umount offset");
beb904
-			left++;
beb904
-		} else {
beb904
-			struct stat st;
beb904
-			int ret;
beb904
+		oe = cache_lookup_distinct(me->mc, key);
beb904
+		if (!oe || !oe->mapent)
beb904
+			goto cont;
beb904
 
beb904
-			if (!(oe->flags & MOUNT_FLAG_DIR_CREATED))
beb904
-				continue;
beb904
+		mounted += do_mount_autofs_offset(ap, oe, root);
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
-			}
beb904
+		/*
beb904
+		 * If re-constructing a multi-mount it's necessary to walk
beb904
+		 * into nested mounts, unlike the usual "mount only what's
beb904
+		 * needed as you go" behavior.
beb904
+		 */
beb904
+		if (ap->state == ST_READMAP && ap->flags & MOUNT_FLAG_REMOUNT) {
beb904
+			if (oe->ioctlfd != -1 ||
beb904
+			    is_mounted(oe->key, MNTS_REAL))
beb904
+				mount_multi_triggers(ap, oe, key, strlen(key), base);
beb904
 		}
beb904
+cont:
beb904
+		offset = cache_get_offset(base,
beb904
+				offset, start, &me->multi_list, &pos;;
beb904
 	}
beb904
 
beb904
+	return mounted;
beb904
+}
beb904
+
beb904
+int umount_multi_triggers(struct autofs_point *ap, struct mapent *me, char *root, const char *base)
beb904
+{
beb904
+	int left;
beb904
+
beb904
+	left = do_umount_multi_triggers(ap, me, root, base);
beb904
+
beb904
 	if (!left && me->multi == me) {
beb904
 		struct mapent_cache *mc = me->mc;
beb904
 		int status;
beb904
@@ -2865,4 +2885,3 @@ int clean_stale_multi_triggers(struct au
beb904
 
beb904
 	return left;
beb904
 }
beb904
-