Blame SOURCES/autofs-5.1.2-set-autofs-mounts-catatonic-at-exit.patch

304803
autofs-5.1.2 - set autofs mounts catatonic at exit
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
Setting direct mounts catatonic at exit doesn't go far enough.
304803
304803
To avoid possible hang on access of automount managed paths when
304803
the daemon has exited all mounted autofs file systems must be set
304803
catatonic when the daemon exits.
304803
304803
Signed-off-by: Ian Kent <raven@themaw.net>
304803
---
304803
 CHANGELOG          |    1 
304803
 daemon/automount.c |    1 
304803
 daemon/direct.c    |   17 ++++---------
304803
 daemon/indirect.c  |    3 --
304803
 include/mounts.h   |    3 +-
304803
 lib/mounts.c       |   69 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
304803
 6 files changed, 78 insertions(+), 16 deletions(-)
304803
304803
--- autofs-5.0.7.orig/CHANGELOG
304803
+++ autofs-5.0.7/CHANGELOG
304803
@@ -214,6 +214,7 @@
304803
 - don't return until after master map retry read.
304803
 - make lookup_nss_read_master() return nss status.
304803
 - make set_direct_mount_catatonic() more general.
304803
+- set autofs mounts catatonic at exit.
304803
 
304803
 25/07/2012 autofs-5.0.7
304803
 =======================
304803
--- autofs-5.0.7.orig/daemon/automount.c
304803
+++ autofs-5.0.7/daemon/automount.c
304803
@@ -1732,6 +1732,7 @@ int handle_mounts_exit(struct autofs_poi
304803
 	 */
304803
 	ret = umount_autofs(ap, NULL, 1);
304803
 	if (!ret) {
304803
+		set_indirect_mount_tree_catatonic(ap);
304803
 		handle_mounts_cleanup(ap);
304803
 		return 1;
304803
 	}
304803
--- autofs-5.0.7.orig/daemon/direct.c
304803
+++ autofs-5.0.7/daemon/direct.c
304803
@@ -130,20 +130,16 @@ int do_umount_autofs_direct(struct autof
304803
 				error(ap->logopt,
304803
 				      "ask umount returned busy for %s",
304803
 				      me->key);
304803
-				if (ap->state != ST_READMAP)
304803
-					set_mount_catatonic(ap, me, ioctlfd);
304803
 				if (opened)
304803
 					ops->close(ap->logopt, ioctlfd);
304803
 				return 1;
304803
 			} else {
304803
 				me->ioctlfd = -1;
304803
-				set_mount_catatonic(ap, me, ioctlfd);
304803
 				ops->close(ap->logopt, ioctlfd);
304803
 				goto force_umount;
304803
 			}
304803
 		}
304803
 		me->ioctlfd = -1;
304803
-		set_mount_catatonic(ap, me, ioctlfd);
304803
 		ops->close(ap->logopt, ioctlfd);
304803
 	} else {
304803
 		error(ap->logopt,
304803
@@ -173,8 +169,11 @@ int do_umount_autofs_direct(struct autof
304803
 			warn(ap->logopt, "mount point %s is in use", me->key);
304803
 			if (ap->state == ST_SHUTDOWN_FORCE)
304803
 				goto force_umount;
304803
-			else
304803
+			else {
304803
+				if (ap->state != ST_READMAP)
304803
+					set_direct_mount_tree_catatonic(ap, me);
304803
 				return 0;
304803
+			}
304803
 			break;
304803
 		case ENOTDIR:
304803
 			error(ap->logopt, "mount point is not a directory");
304803
@@ -238,12 +237,8 @@ int umount_autofs_direct(struct autofs_p
304803
 			if (!error)
304803
 				goto done;
304803
 
304803
-			error = set_mount_catatonic(ap, me, me->ioctlfd);
304803
-			if (!error)
304803
-				goto done;
304803
-
304803
-			/* We really need to set this, last ditch attempt */
304803
-			set_mount_catatonic(ap, me, -1);
304803
+			if (ap->state != ST_READMAP)
304803
+				set_direct_mount_tree_catatonic(ap, me);
304803
 done:
304803
 			me = cache_enumerate(mc, me);
304803
 		}
304803
--- autofs-5.0.7.orig/daemon/indirect.c
304803
+++ autofs-5.0.7/daemon/indirect.c
304803
@@ -286,9 +286,6 @@ int umount_autofs_indirect(struct autofs
304803
 #endif
304803
 	}
304803
 
304803
-	if (ap->shutdown)
304803
-		ops->catatonic(ap->logopt, ap->ioctlfd);
304803
-
304803
 	ops->close(ap->logopt, ap->ioctlfd);
304803
 	ap->ioctlfd = -1;
304803
 	sched_yield();
304803
--- autofs-5.0.7.orig/include/mounts.h
304803
+++ autofs-5.0.7/include/mounts.h
304803
@@ -114,7 +114,8 @@ void set_tsd_user_vars(unsigned int, uid
304803
 const char *mount_type_str(unsigned int);
304803
 void notify_mount_result(struct autofs_point *, const char *, time_t, const char *);
304803
 int try_remount(struct autofs_point *, struct mapent *, unsigned int);
304803
-int set_mount_catatonic(struct autofs_point *, struct mapent *, int);
304803
+void set_indirect_mount_tree_catatonic(struct autofs_point *);
304803
+void set_direct_mount_tree_catatonic(struct autofs_point *, struct mapent *);
304803
 int umount_ent(struct autofs_point *, const char *);
304803
 int mount_multi_triggers(struct autofs_point *, struct mapent *, const char *, unsigned int, const char *);
304803
 int umount_multi_triggers(struct autofs_point *, struct mapent *, char *, const char *);
304803
--- autofs-5.0.7.orig/lib/mounts.c
304803
+++ autofs-5.0.7/lib/mounts.c
304803
@@ -1899,7 +1899,7 @@ int try_remount(struct autofs_point *ap,
304803
  * are busy on not, to avoid a hang on access once the daemon has gone
304803
  * away.
304803
  */
304803
-int set_mount_catatonic(struct autofs_point *ap, struct mapent *me, int ioctlfd)
304803
+static int set_mount_catatonic(struct autofs_point *ap, struct mapent *me, int ioctlfd)
304803
 {
304803
 	struct ioctl_ops *ops = get_ioctl_ops();
304803
 	unsigned int opened = 0;
304803
@@ -1926,6 +1926,9 @@ int set_mount_catatonic(struct autofs_po
304803
 			int err = errno;
304803
 			char *estr;
304803
 
304803
+			if (errno == ENOENT)
304803
+				return 0;
304803
+
304803
 			estr = strerror_r(errno, buf, MAX_ERR_BUF);
304803
 			error(ap->logopt,
304803
 			      "failed to open ioctlfd for %s, error: %s",
304803
@@ -1958,6 +1961,70 @@ int set_mount_catatonic(struct autofs_po
304803
 	return 0;
304803
 }
304803
 
304803
+static void set_multi_mount_tree_catatonic(struct autofs_point *ap, struct mapent *me)
304803
+{
304803
+	if (!list_empty(&me->multi_list)) {
304803
+		struct list_head *head = &me->multi_list;
304803
+		struct list_head *p;
304803
+
304803
+		list_for_each(p, head) {
304803
+			struct mapent *this;
304803
+
304803
+			this = list_entry(p, struct mapent, multi_list);
304803
+			set_mount_catatonic(ap, this, this->ioctlfd);
304803
+		}
304803
+	}
304803
+}
304803
+
304803
+void set_indirect_mount_tree_catatonic(struct autofs_point *ap)
304803
+{
304803
+	struct master_mapent *entry = ap->entry;
304803
+	struct map_source *map;
304803
+	struct mapent_cache *mc;
304803
+	struct mapent *me;
304803
+
304803
+	if (!is_mounted(_PROC_MOUNTS, ap->path, MNTS_AUTOFS))
304803
+		return;
304803
+
304803
+	map = entry->maps;
304803
+	while (map) {
304803
+		mc = map->mc;
304803
+		cache_readlock(mc);
304803
+		me = cache_enumerate(mc, NULL);
304803
+		while (me) {
304803
+			/* Skip negative map entries and wildcard entries */
304803
+			if (!me->mapent)
304803
+				goto next;
304803
+
304803
+			if (!strcmp(me->key, "*"))
304803
+				goto next;
304803
+
304803
+			/* Only need to set offset mounts catatonic */
304803
+			if (me->multi && me->multi == me)
304803
+				set_multi_mount_tree_catatonic(ap, me);
304803
+next:
304803
+			me = cache_enumerate(mc, me);
304803
+		}
304803
+		cache_unlock(mc);
304803
+		map = map->next;
304803
+	}
304803
+
304803
+	/* By the time this function is called ap->ioctlfd will have
304803
+	 * been closed so don't try and use it.
304803
+	 */
304803
+	set_mount_catatonic(ap, NULL, -1);
304803
+
304803
+	return;
304803
+}
304803
+
304803
+void set_direct_mount_tree_catatonic(struct autofs_point *ap, struct mapent *me)
304803
+{
304803
+	/* Set offset mounts catatonic for this mapent */
304803
+	if (me->multi && me->multi == me)
304803
+		set_multi_mount_tree_catatonic(ap, me);
304803
+	set_mount_catatonic(ap, me, me->ioctlfd);
304803
+}
304803
+
304803
 int umount_ent(struct autofs_point *ap, const char *path)
304803
 {
304803
 	int rv;