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

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