Blame SOURCES/autofs-5.1.5-use-single-unlink_umount_tree-for-both-direct-and-indirect-mounts.patch

8fa62f
autofs-5.1.5 - use single unlink_umount_tree() for both direct and indirect mounts
8fa62f
8fa62f
From: Ian Kent <raven@themaw.net>
8fa62f
8fa62f
Use the same function, unlink_umount_tree(), for forced unlink of mounts
8fa62f
for both indirect and direct mounts.
8fa62f
8fa62f
Signed-off-by: Ian Kent <raven@themaw.net>
8fa62f
---
8fa62f
 CHANGELOG           |    1 
8fa62f
 daemon/direct.c     |   96 +++++++++++++---------------------------------------
8fa62f
 daemon/indirect.c   |    2 -
8fa62f
 daemon/state.c      |   17 +--------
8fa62f
 include/automount.h |    2 -
8fa62f
 5 files changed, 30 insertions(+), 88 deletions(-)
8fa62f
8fa62f
--- autofs-5.1.4.orig/CHANGELOG
8fa62f
+++ autofs-5.1.4/CHANGELOG
8fa62f
@@ -70,6 +70,7 @@ xx/xx/2018 autofs-5.1.5
8fa62f
 - use local getmntent_r in table_is_mounted().
8fa62f
 - refactor unlink_active_mounts() in direct.c.
8fa62f
 - don't use tree_is_mounted() for mounted checks.
8fa62f
+- use single unlink_umount_tree() for both direct and indirect mounts.
8fa62f
 
8fa62f
 19/12/2017 autofs-5.1.4
8fa62f
 - fix spec file url.
8fa62f
--- autofs-5.1.4.orig/daemon/direct.c
8fa62f
+++ autofs-5.1.4/daemon/direct.c
8fa62f
@@ -49,6 +49,8 @@ pthread_key_t key_mnt_direct_params;
8fa62f
 pthread_key_t key_mnt_offset_params;
8fa62f
 pthread_once_t key_mnt_params_once = PTHREAD_ONCE_INIT;
8fa62f
 
8fa62f
+int unlink_mount_tree(struct autofs_point *ap, struct mnt_list *mnts);
8fa62f
+
8fa62f
 static void key_mnt_params_destroy(void *arg)
8fa62f
 {
8fa62f
 	struct mnt_params *mp;
8fa62f
@@ -256,64 +258,8 @@ done:
8fa62f
 	return 0;
8fa62f
 }
8fa62f
 
8fa62f
-static int unlink_mount_tree(struct autofs_point *ap, struct list_head *list)
8fa62f
-{
8fa62f
-	struct list_head *p;
8fa62f
-	int rv, ret;
8fa62f
-
8fa62f
-	ret = 1;
8fa62f
-	list_for_each(p, list) {
8fa62f
-		struct mnt_list *mnt;
8fa62f
-
8fa62f
-		mnt = list_entry(p, struct mnt_list, list);
8fa62f
-
8fa62f
-		if (mnt->flags & MNTS_AUTOFS)
8fa62f
-			rv = umount2(mnt->mp, MNT_DETACH);
8fa62f
-		else
8fa62f
-			rv = spawn_umount(ap->logopt, "-l", mnt->mp, NULL);
8fa62f
-		if (rv == -1) {
8fa62f
-			debug(ap->logopt,
8fa62f
-			      "can't unlink %s from mount tree", mnt->mp);
8fa62f
-
8fa62f
-			switch (errno) {
8fa62f
-			case EINVAL:
8fa62f
-				warn(ap->logopt,
8fa62f
-				      "bad superblock or not mounted");
8fa62f
-				break;
8fa62f
-
8fa62f
-			case ENOENT:
8fa62f
-			case EFAULT:
8fa62f
-				ret = 0;
8fa62f
-				warn(ap->logopt, "bad path for mount");
8fa62f
-				break;
8fa62f
-			}
8fa62f
-		}
8fa62f
-	}
8fa62f
-	return ret;
8fa62f
-}
8fa62f
-
8fa62f
-static int unlink_active_mounts(struct autofs_point *ap, struct mnt_list *mnts, struct mapent *me)
8fa62f
-{
8fa62f
-	struct list_head list;
8fa62f
-
8fa62f
-	INIT_LIST_HEAD(&list);
8fa62f
-
8fa62f
-	if (!tree_get_mnt_list(mnts, &list, me->key, 1))
8fa62f
-		return 1;
8fa62f
-
8fa62f
-	if (!unlink_mount_tree(ap, &list)) {
8fa62f
-		debug(ap->logopt,
8fa62f
-		      "already mounted as other than autofs "
8fa62f
-		      "or failed to unlink entry in tree");
8fa62f
-		return 0;
8fa62f
-	}
8fa62f
-
8fa62f
-	return 1;
8fa62f
-}
8fa62f
-
8fa62f
 int do_mount_autofs_direct(struct autofs_point *ap,
8fa62f
-			   struct mnt_list *mnts, struct mapent *me,
8fa62f
-			   time_t timeout)
8fa62f
+			   struct mapent *me, time_t timeout)
8fa62f
 {
8fa62f
 	const char *str_direct = mount_type_str(t_direct);
8fa62f
 	struct ioctl_ops *ops = get_ioctl_ops();
8fa62f
@@ -342,6 +288,8 @@ int do_mount_autofs_direct(struct autofs
8fa62f
 		if (ret == 0)
8fa62f
 			return -1;
8fa62f
 	} else {
8fa62f
+		struct mnt_list *mnts;
8fa62f
+
8fa62f
 		if (ap->state == ST_READMAP && is_mounted(me->key, MNTS_ALL)) {
8fa62f
 			time_t tout = get_exp_timeout(ap, me->source);
8fa62f
 			int save_ioctlfd, ioctlfd;
8fa62f
@@ -367,15 +315,23 @@ int do_mount_autofs_direct(struct autofs
8fa62f
 			return 0;
8fa62f
 		}
8fa62f
 
8fa62f
-		/*
8fa62f
-		 * A return of 1 indicates we successfully unlinked
8fa62f
-		 * the mount tree if there was one. A return of 0
8fa62f
-		 * indicates we failed to unlink the mount tree so
8fa62f
-		 * we have to return a failure.
8fa62f
-		 */
8fa62f
-		ret = unlink_active_mounts(ap, mnts, me);
8fa62f
-		if (!ret)
8fa62f
-			return -1;
8fa62f
+		mnts = get_mnt_list(me->key, 1);
8fa62f
+		if (mnts) {
8fa62f
+			/*
8fa62f
+			 * A return of 1 indicates we successfully unlinked
8fa62f
+			 * the mount tree if there was one. A return of 0
8fa62f
+			 * indicates we failed to unlink the mount tree so
8fa62f
+			 * we have to return a failure.
8fa62f
+			 */
8fa62f
+			ret = unlink_mount_tree(ap, mnts);
8fa62f
+			free_mnt_list(mnts);
8fa62f
+			if (!ret) {
8fa62f
+				error(ap->logopt,
8fa62f
+				      "already mounted as other than autofs "
8fa62f
+				      "or failed to unlink entry in tree");
8fa62f
+				return -1;
8fa62f
+			}
8fa62f
+		}
8fa62f
 
8fa62f
 		if (me->ioctlfd != -1) {
8fa62f
 			error(ap->logopt, "active direct mount %s", me->key);
8fa62f
@@ -494,7 +450,6 @@ int mount_autofs_direct(struct autofs_po
8fa62f
 	struct map_source *map;
8fa62f
 	struct mapent_cache *nc, *mc;
8fa62f
 	struct mapent *me, *ne, *nested;
8fa62f
-	struct mnt_list *mnts;
8fa62f
 	time_t now = monotonic_time(NULL);
8fa62f
 
8fa62f
 	if (strcmp(ap->path, "/-")) {
8fa62f
@@ -510,8 +465,6 @@ int mount_autofs_direct(struct autofs_po
8fa62f
 		return -1;
8fa62f
 	}
8fa62f
 
8fa62f
-	mnts = tree_make_mnt_tree("/");
8fa62f
-	pthread_cleanup_push(mnts_cleanup, mnts);
8fa62f
 	pthread_cleanup_push(master_source_lock_cleanup, ap->entry);
8fa62f
 	master_source_readlock(ap->entry);
8fa62f
 	nc = ap->entry->master->nc;
8fa62f
@@ -539,7 +492,7 @@ int mount_autofs_direct(struct autofs_po
8fa62f
 			if (ne) {
8fa62f
 				if (map->master_line < ne->age) {
8fa62f
 					/* TODO: check return, locking me */
8fa62f
-					do_mount_autofs_direct(ap, mnts, me, timeout);
8fa62f
+					do_mount_autofs_direct(ap, me, timeout);
8fa62f
 				}
8fa62f
 				me = cache_enumerate(mc, me);
8fa62f
 				continue;
8fa62f
@@ -556,7 +509,7 @@ int mount_autofs_direct(struct autofs_po
8fa62f
 			}
8fa62f
 
8fa62f
 			/* TODO: check return, locking me */
8fa62f
-			do_mount_autofs_direct(ap, mnts, me, timeout);
8fa62f
+			do_mount_autofs_direct(ap, me, timeout);
8fa62f
 
8fa62f
 			me = cache_enumerate(mc, me);
8fa62f
 		}
8fa62f
@@ -565,7 +518,6 @@ int mount_autofs_direct(struct autofs_po
8fa62f
 	}
8fa62f
 	pthread_cleanup_pop(1);
8fa62f
 	pthread_cleanup_pop(1);
8fa62f
-	pthread_cleanup_pop(1);
8fa62f
 
8fa62f
 	return 0;
8fa62f
 }
8fa62f
--- autofs-5.1.4.orig/daemon/indirect.c
8fa62f
+++ autofs-5.1.4/daemon/indirect.c
8fa62f
@@ -40,7 +40,7 @@
8fa62f
 /* Attribute to create detached thread */
8fa62f
 extern pthread_attr_t th_attr_detached;
8fa62f
 
8fa62f
-static int unlink_mount_tree(struct autofs_point *ap, struct mnt_list *mnts)
8fa62f
+int unlink_mount_tree(struct autofs_point *ap, struct mnt_list *mnts)
8fa62f
 {
8fa62f
 	struct mnt_list *this;
8fa62f
 	int rv, ret;
8fa62f
--- autofs-5.1.4.orig/daemon/state.c
8fa62f
+++ autofs-5.1.4/daemon/state.c
8fa62f
@@ -350,14 +350,7 @@ static void do_readmap_cleanup(void *arg
8fa62f
 	return;
8fa62f
 }
8fa62f
 
8fa62f
-static void tree_mnts_cleanup(void *arg)
8fa62f
-{
8fa62f
-	struct mnt_list *mnts = (struct mnt_list *) arg;
8fa62f
-	tree_free_mnt_tree(mnts);
8fa62f
-	return;
8fa62f
-}
8fa62f
-
8fa62f
-static void do_readmap_mount(struct autofs_point *ap, struct mnt_list *mnts,
8fa62f
+static void do_readmap_mount(struct autofs_point *ap,
8fa62f
 			     struct map_source *map, struct mapent *me, time_t now)
8fa62f
 {
8fa62f
 	struct mapent_cache *nc;
8fa62f
@@ -444,7 +437,7 @@ static void do_readmap_mount(struct auto
8fa62f
 			debug(ap->logopt,
8fa62f
 			      "%s is mounted", me->key);
8fa62f
 	} else
8fa62f
-		do_mount_autofs_direct(ap, mnts, me, get_exp_timeout(ap, map));
8fa62f
+		do_mount_autofs_direct(ap, me, get_exp_timeout(ap, map));
8fa62f
 
8fa62f
 	return;
8fa62f
 }
8fa62f
@@ -455,7 +448,6 @@ static void *do_readmap(void *arg)
8fa62f
 	struct map_source *map;
8fa62f
 	struct mapent_cache *nc, *mc;
8fa62f
 	struct readmap_args *ra;
8fa62f
-	struct mnt_list *mnts;
8fa62f
 	int status;
8fa62f
 	time_t now;
8fa62f
 
8fa62f
@@ -499,8 +491,6 @@ static void *do_readmap(void *arg)
8fa62f
 		struct mapent *me;
8fa62f
 		unsigned int append_alarm = !ap->exp_runfreq;
8fa62f
 
8fa62f
-		mnts = tree_make_mnt_tree("/");
8fa62f
-		pthread_cleanup_push(tree_mnts_cleanup, mnts);
8fa62f
 		nc = ap->entry->master->nc;
8fa62f
 		cache_readlock(nc);
8fa62f
 		pthread_cleanup_push(cache_lock_cleanup, nc);
8fa62f
@@ -518,7 +508,7 @@ static void *do_readmap(void *arg)
8fa62f
 			cache_readlock(mc);
8fa62f
 			me = cache_enumerate(mc, NULL);
8fa62f
 			while (me) {
8fa62f
-				do_readmap_mount(ap, mnts, map, me, now);
8fa62f
+				do_readmap_mount(ap, map, me, now);
8fa62f
 				me = cache_enumerate(mc, me);
8fa62f
 			}
8fa62f
 			lookup_prune_one_cache(ap, map->mc, now);
8fa62f
@@ -538,7 +528,6 @@ static void *do_readmap(void *arg)
8fa62f
 
8fa62f
 		pthread_cleanup_pop(1);
8fa62f
 		pthread_cleanup_pop(1);
8fa62f
-		pthread_cleanup_pop(1);
8fa62f
 	}
8fa62f
 
8fa62f
 	pthread_cleanup_pop(1);
8fa62f
--- autofs-5.1.4.orig/include/automount.h
8fa62f
+++ autofs-5.1.4/include/automount.h
8fa62f
@@ -606,7 +606,7 @@ void *expire_proc_indirect(void *);
8fa62f
 void *expire_proc_direct(void *);
8fa62f
 int expire_offsets_direct(struct autofs_point *ap, struct mapent *me, int now);
8fa62f
 int mount_autofs_indirect(struct autofs_point *ap, const char *root);
8fa62f
-int do_mount_autofs_direct(struct autofs_point *ap, struct mnt_list *mnts, struct mapent *me, time_t timeout);
8fa62f
+int do_mount_autofs_direct(struct autofs_point *ap, struct mapent *me, time_t timeout);
8fa62f
 int mount_autofs_direct(struct autofs_point *ap);
8fa62f
 int mount_autofs_offset(struct autofs_point *ap, struct mapent *me, const char *root, const char *offset);
8fa62f
 void submount_signal_parent(struct autofs_point *ap, unsigned int success);