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

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