Blame SOURCES/autofs-5.1.2-make-set_direct_mount_catatonic-more-general.patch

304803
autofs-5.1.2 - make set_direct_mount_catatonic() more general
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
Start by making set_direct_mount_catatonic() able to handle the
304803
different types of autofs mounts and move it to the mounts function
304803
library.
304803
---
304803
 CHANGELOG        |    1 
304803
 daemon/direct.c  |   69 +++----------------------------------------------------
304803
 include/mounts.h |    1 
304803
 lib/mounts.c     |   64 +++++++++++++++++++++++++++++++++++++++++++++++++++
304803
 4 files changed, 71 insertions(+), 64 deletions(-)
304803
304803
--- autofs-5.0.7.orig/CHANGELOG
304803
+++ autofs-5.0.7/CHANGELOG
304803
@@ -213,6 +213,7 @@
304803
 - set sane default master read wait timeout.
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
 
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
@@ -82,65 +82,6 @@ static void mnts_cleanup(void *arg)
304803
 	return;
304803
 }
304803
 
304803
-/* When exiting direct mount triggers must be set catatonic, regardless
304803
- * of whether they are busy on not, to avoid a hang on access once the
304803
- * daemon has gone away.
304803
- */
304803
-static int set_direct_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
-	char buf[MAX_ERR_BUF];
304803
-	int fd = -1;
304803
-	int error;
304803
-
304803
-	/* In case the miscellaneous device isn't being used try
304803
-	 * and use an existing ioctl control fd. In this case if
304803
-	 * we don't already have an ioctl fd the mount can't be
304803
-	 * set catatonic if it's covered.
304803
-	 */
304803
-	if (ioctlfd >= 0)
304803
-		fd = ioctlfd;
304803
-	else if (me->ioctlfd >= 0)
304803
-		fd = me->ioctlfd;
304803
-	else {
304803
-		error = ops->open(ap->logopt, &fd, me->dev, me->key);
304803
-		if (error == -1) {
304803
-			int err = errno;
304803
-			char *estr;
304803
-
304803
-			estr = strerror_r(errno, buf, MAX_ERR_BUF);
304803
-			error(ap->logopt,
304803
-			      "failed to open ioctlfd for %s, error: %s",
304803
-			      me->key, estr);
304803
-			return err;
304803
-		}
304803
-		opened = 1;
304803
-	}
304803
-
304803
-	if (fd >= 0) {
304803
-		error = ops->catatonic(ap->logopt, fd);
304803
-		if (error == -1) {
304803
-			int err = errno;
304803
-			char *estr;
304803
-
304803
-			estr = strerror_r(errno, buf, MAX_ERR_BUF);
304803
-			error(ap->logopt,
304803
-			      "failed to set %s catatonic, error: %s",
304803
-			      me->key, estr);
304803
-			if (opened)
304803
-				ops->close(ap->logopt, fd);
304803
-			return err;
304803
-		}
304803
-		if (opened)
304803
-			ops->close(ap->logopt, fd);
304803
-	}
304803
-
304803
-	debug(ap->logopt, "set %s catatonic", me->key);
304803
-
304803
-	return 0;
304803
-}
304803
-
304803
 int do_umount_autofs_direct(struct autofs_point *ap, struct mnt_list *mnts, struct mapent *me)
304803
 {
304803
 	struct ioctl_ops *ops = get_ioctl_ops();
304803
@@ -190,19 +131,19 @@ int do_umount_autofs_direct(struct autof
304803
 				      "ask umount returned busy for %s",
304803
 				      me->key);
304803
 				if (ap->state != ST_READMAP)
304803
-					set_direct_mount_catatonic(ap, me, ioctlfd);
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_direct_mount_catatonic(ap, me, ioctlfd);
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_direct_mount_catatonic(ap, me, ioctlfd);
304803
+		set_mount_catatonic(ap, me, ioctlfd);
304803
 		ops->close(ap->logopt, ioctlfd);
304803
 	} else {
304803
 		error(ap->logopt,
304803
@@ -297,12 +238,12 @@ int umount_autofs_direct(struct autofs_p
304803
 			if (!error)
304803
 				goto done;
304803
 
304803
-			error = set_direct_mount_catatonic(ap, me, me->ioctlfd);
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_direct_mount_catatonic(ap, me, -1);
304803
+			set_mount_catatonic(ap, me, -1);
304803
 done:
304803
 			me = cache_enumerate(mc, me);
304803
 		}
304803
--- autofs-5.0.7.orig/include/mounts.h
304803
+++ autofs-5.0.7/include/mounts.h
304803
@@ -114,6 +114,7 @@ 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
 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
@@ -1894,6 +1894,70 @@ int try_remount(struct autofs_point *ap,
304803
 	return 0;
304803
 }
304803
 
304803
+/*
304803
+ * When exiting mounts need be set catatonic, regardless of whether they
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
+{
304803
+	struct ioctl_ops *ops = get_ioctl_ops();
304803
+	unsigned int opened = 0;
304803
+	char buf[MAX_ERR_BUF];
304803
+	char *path;
304803
+	int fd = -1;
304803
+	int error;
304803
+	dev_t dev;
304803
+
304803
+	path = ap->path;
304803
+	dev = ap->dev;
304803
+	if (me && (ap->type == LKP_DIRECT || *me->key == '/')) {
304803
+		path = me->key;
304803
+		dev = me->dev;
304803
+	}
304803
+
304803
+	if (ioctlfd >= 0)
304803
+		fd = ioctlfd;
304803
+	else if (me && me->ioctlfd >= 0)
304803
+		fd = me->ioctlfd;
304803
+	else {
304803
+		error = ops->open(ap->logopt, &fd, dev, path);
304803
+		if (error == -1) {
304803
+			int err = errno;
304803
+			char *estr;
304803
+
304803
+			estr = strerror_r(errno, buf, MAX_ERR_BUF);
304803
+			error(ap->logopt,
304803
+			      "failed to open ioctlfd for %s, error: %s",
304803
+			      path, estr);
304803
+			return err;
304803
+		}
304803
+		opened = 1;
304803
+	}
304803
+
304803
+	if (fd >= 0) {
304803
+		error = ops->catatonic(ap->logopt, fd);
304803
+		if (error == -1) {
304803
+			int err = errno;
304803
+			char *estr;
304803
+
304803
+			estr = strerror_r(errno, buf, MAX_ERR_BUF);
304803
+			error(ap->logopt,
304803
+			      "failed to set %s catatonic, error: %s",
304803
+			      path, estr);
304803
+			if (opened)
304803
+				ops->close(ap->logopt, fd);
304803
+			return err;
304803
+		}
304803
+		if (opened)
304803
+			ops->close(ap->logopt, fd);
304803
+	}
304803
+
304803
+	debug(ap->logopt, "set %s catatonic", path);
304803
+
304803
+	return 0;
304803
+}
304803
+
304803
 int umount_ent(struct autofs_point *ap, const char *path)
304803
 {
304803
 	int rv;