Blame SOURCES/autofs-5.1.8-fix-kernel-mount-status-notification.patch

96dc52
autofs-5.1.8 - fix kernel mount status notification
96dc52
96dc52
From: Ian Kent <raven@themaw.net>
96dc52
96dc52
The status return for attempted mount notification is not done
96dc52
correctly in some cases leading to a status being sent to the
96dc52
kernel multiple times or the send causing an error.
96dc52
96dc52
We must send a status to the kernel but it needs to be the correct
96dc52
one. It definitely shouldn't be sent twice for the same mount attempt
96dc52
and shouldn't be failing.
96dc52
96dc52
Signed-off-by: Ian Kent <raven@themaw.net>
96dc52
---
96dc52
 CHANGELOG         |    1 +
96dc52
 daemon/direct.c   |   19 +++++++++++--------
96dc52
 daemon/indirect.c |   19 +++++++++++--------
96dc52
 3 files changed, 23 insertions(+), 16 deletions(-)
96dc52
96dc52
--- autofs-5.1.7.orig/CHANGELOG
96dc52
+++ autofs-5.1.7/CHANGELOG
96dc52
@@ -80,6 +80,7 @@
96dc52
 - fix concat_options() error handling.
96dc52
 - eliminate some more alloca usage.
96dc52
 - use default stack size for threads.
96dc52
+- fix kernel mount status notification.
96dc52
 
96dc52
 25/01/2021 autofs-5.1.7
96dc52
 - make bind mounts propagation slave by default.
96dc52
--- autofs-5.1.7.orig/daemon/direct.c
96dc52
+++ autofs-5.1.7/daemon/direct.c
96dc52
@@ -1143,12 +1143,18 @@ int handle_packet_expire_direct(struct a
96dc52
 	return 0;
96dc52
 }
96dc52
 
96dc52
-static void mount_send_fail(void *arg)
96dc52
+static void mount_send_status(void *arg)
96dc52
 {
96dc52
 	struct ioctl_ops *ops = get_ioctl_ops();
96dc52
 	struct pending_args *mt = arg;
96dc52
 	struct autofs_point *ap = mt->ap;
96dc52
-	ops->send_fail(ap->logopt, mt->ioctlfd, mt->wait_queue_token, -ENOENT);
96dc52
+
96dc52
+	if (mt->status)
96dc52
+		ops->send_fail(ap->logopt, mt->ioctlfd,
96dc52
+			       mt->wait_queue_token, mt->status);
96dc52
+	else
96dc52
+		ops->send_ready(ap->logopt,
96dc52
+				mt->ioctlfd, mt->wait_queue_token);
96dc52
 	ops->close(ap->logopt, mt->ioctlfd);
96dc52
 }
96dc52
 
96dc52
@@ -1177,7 +1183,8 @@ static void *do_mount_direct(void *arg)
96dc52
 
96dc52
 	pending_mutex_unlock(args);
96dc52
 
96dc52
-	pthread_cleanup_push(mount_send_fail, &mt;;
96dc52
+	mt.status = 0;
96dc52
+	pthread_cleanup_push(mount_send_status, &mt;;
96dc52
 
96dc52
 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &state);
96dc52
 
96dc52
@@ -1191,9 +1198,7 @@ static void *do_mount_direct(void *arg)
96dc52
 	if (status == -1) {
96dc52
 		error(ap->logopt,
96dc52
 		      "can't stat direct mount trigger %s", mt.name);
96dc52
-		ops->send_fail(ap->logopt,
96dc52
-			       mt.ioctlfd, mt.wait_queue_token, -ENOENT);
96dc52
-		ops->close(ap->logopt, mt.ioctlfd);
96dc52
+		mt.status = -ENOENT;
96dc52
 		pthread_setcancelstate(state, NULL);
96dc52
 		pthread_exit(NULL);
96dc52
 	}
96dc52
@@ -1203,8 +1208,6 @@ static void *do_mount_direct(void *arg)
96dc52
 		error(ap->logopt,
96dc52
 		     "direct trigger not valid or already mounted %s",
96dc52
 		     mt.name);
96dc52
-		ops->send_ready(ap->logopt, mt.ioctlfd, mt.wait_queue_token);
96dc52
-		ops->close(ap->logopt, mt.ioctlfd);
96dc52
 		pthread_setcancelstate(state, NULL);
96dc52
 		pthread_exit(NULL);
96dc52
 	}
96dc52
--- autofs-5.1.7.orig/daemon/indirect.c
96dc52
+++ autofs-5.1.7/daemon/indirect.c
96dc52
@@ -674,13 +674,18 @@ int handle_packet_expire_indirect(struct
96dc52
 	return 0;
96dc52
 }
96dc52
 
96dc52
-static void mount_send_fail(void *arg)
96dc52
+static void mount_send_status(void *arg)
96dc52
 {
96dc52
 	struct ioctl_ops *ops = get_ioctl_ops();
96dc52
 	struct pending_args *mt = arg;
96dc52
 	struct autofs_point *ap = mt->ap;
96dc52
-	ops->send_fail(ap->logopt,
96dc52
-		       ap->ioctlfd, mt->wait_queue_token, -ENOENT);
96dc52
+
96dc52
+	if (mt->status)
96dc52
+		ops->send_fail(ap->logopt, ap->ioctlfd,
96dc52
+			       mt->wait_queue_token, mt->status);
96dc52
+	else
96dc52
+		ops->send_ready(ap->logopt,
96dc52
+				ap->ioctlfd, mt->wait_queue_token);
96dc52
 }
96dc52
 
96dc52
 static void *do_mount_indirect(void *arg)
96dc52
@@ -709,7 +714,8 @@ static void *do_mount_indirect(void *arg
96dc52
 
96dc52
 	pending_mutex_unlock(args);
96dc52
 
96dc52
-	pthread_cleanup_push(mount_send_fail, &mt;;
96dc52
+	mt.status = 0;
96dc52
+	pthread_cleanup_push(mount_send_status, &mt;;
96dc52
 
96dc52
 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &state);
96dc52
 
96dc52
@@ -722,9 +728,7 @@ static void *do_mount_indirect(void *arg
96dc52
 	len = ncat_path(buf, sizeof(buf), ap->path, mt.name, mt.len);
96dc52
 	if (!len) {
96dc52
 		crit(ap->logopt, "path to be mounted is to long");
96dc52
-		ops->send_fail(ap->logopt,
96dc52
-			       ap->ioctlfd, mt.wait_queue_token,
96dc52
-			      -ENAMETOOLONG);
96dc52
+		mt.status = -ENAMETOOLONG;
96dc52
 		pthread_setcancelstate(state, NULL);
96dc52
 		pthread_exit(NULL);
96dc52
 	}
96dc52
@@ -733,7 +737,6 @@ static void *do_mount_indirect(void *arg
96dc52
 	if (status != -1 && !(S_ISDIR(st.st_mode) && st.st_dev == mt.dev)) {
96dc52
 		error(ap->logopt,
96dc52
 		      "indirect trigger not valid or already mounted %s", buf);
96dc52
-		ops->send_ready(ap->logopt, ap->ioctlfd, mt.wait_queue_token);
96dc52
 		pthread_setcancelstate(state, NULL);
96dc52
 		pthread_exit(NULL);
96dc52
 	}