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

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