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

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