Blame SOURCES/autofs-5.1.4-set-bind-mount-as-propagation-slave.patch

d5dcad
autofs-5.1.4 - set bind mount as propagation slave
d5dcad
d5dcad
From: Ian Kent <raven@themaw.net>
d5dcad
d5dcad
When using a multi-mount with mount targets that are on the
d5dcad
local machine and resulting bind mounts are made to a file
d5dcad
system that is mount propagation shared (such as the root
d5dcad
file system on systemd managed systems) the autofs offset
d5dcad
mount triggers made within the bind mount will be propagated
d5dcad
back to the target file system.
d5dcad
d5dcad
When this happens the target of the offset (the unwanted
d5dcad
propagated mount) is itself an autofs trigger mount and
d5dcad
accessing the path results in a deadlock.
d5dcad
d5dcad
In order for these multi-mounts to function properly in this
d5dcad
case bind mounts that contain mount triggers must be set to
d5dcad
propagation slave or private so the backward propagation
d5dcad
doesn't occur.
d5dcad
d5dcad
Signed-off-by: Ian Kent <raven@themaw.net>
d5dcad
---
d5dcad
 CHANGELOG            |    1 +
d5dcad
 modules/mount_bind.c |   16 +++++++++++++++-
d5dcad
 2 files changed, 16 insertions(+), 1 deletion(-)
d5dcad
d5dcad
--- autofs-5.1.4.orig/CHANGELOG
d5dcad
+++ autofs-5.1.4/CHANGELOG
d5dcad
@@ -30,6 +30,7 @@ xx/xx/2018 autofs-5.1.5
d5dcad
 - fix program usage message.
d5dcad
 - fix update_negative_cache() map source usage.
d5dcad
 - mark removed cache entry negative.
d5dcad
+- set bind mount as propagation slave.
d5dcad
 
d5dcad
 19/12/2017 autofs-5.1.4
d5dcad
 - fix spec file url.
d5dcad
--- autofs-5.1.4.orig/modules/mount_bind.c
d5dcad
+++ autofs-5.1.4/modules/mount_bind.c
d5dcad
@@ -20,6 +20,7 @@
d5dcad
 #include <sys/param.h>
d5dcad
 #include <sys/types.h>
d5dcad
 #include <sys/stat.h>
d5dcad
+#include <sys/mount.h>
d5dcad
 
d5dcad
 #define MODULE_MOUNT
d5dcad
 #include "automount.h"
d5dcad
@@ -183,8 +184,21 @@ int mount_mount(struct autofs_point *ap,
d5dcad
 			debug(ap->logopt,
d5dcad
 			      MODPREFIX "mounted %s type %s on %s",
d5dcad
 			      what, fstype, fullpath);
d5dcad
-			return 0;
d5dcad
 		}
d5dcad
+
d5dcad
+		/* The bind mount has succeeded but if the target
d5dcad
+		 * mount is propagation shared propagation of child
d5dcad
+		 * mounts (autofs offset mounts for example) back to
d5dcad
+		 * the target of the bind mount must be avoided or
d5dcad
+		 * autofs trigger mounts will deadlock.
d5dcad
+		 */
d5dcad
+		err = mount(NULL, fullpath, NULL, MS_SLAVE, NULL);
d5dcad
+		if (err)
d5dcad
+			warn(ap->logopt,
d5dcad
+			     "failed to set propagation type for %s",
d5dcad
+			     fullpath);
d5dcad
+
d5dcad
+		return 0;
d5dcad
 	} else {
d5dcad
 		char *cp;
d5dcad
 		char basepath[PATH_MAX];