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

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