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

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