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

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