Blame SOURCES/autofs-5.1.4-add-master-map-pseudo-options-for-mount-propagation.patch

135b98
autofs-5.1.4 - add master map pseudo options for mount propagation
135b98
135b98
From: Ian Kent <raven@themaw.net>
135b98
135b98
Add master map entry pseudo mount option of "slave" or "private" to
135b98
allow mount propagation of bind mounts to be set to either "slave" or
135b98
"private".
135b98
135b98
This option may be needed when using multi-mounts that have bind mounts
135b98
that bind to a file system that is propagation shared. This is becuase
135b98
the bind mount will have the same properties as its target which causes
135b98
problems for offset mounts. When this happens an unwanted offset mount
135b98
is propagated back to the target file system resulting in a deadlock
135b98
when attempting to access the offset.
135b98
135b98
By default bind mounts will inherit the mount propagation of the target
135b98
file system.
135b98
135b98
Signed-off-by: Ian Kent <raven@themaw.net>
135b98
---
135b98
 CHANGELOG            |    1 +
135b98
 include/automount.h  |    4 ++++
135b98
 lib/master_parse.y   |   13 +++++++++++++
135b98
 lib/master_tok.l     |    2 ++
135b98
 man/auto.master.5.in |   12 ++++++++++++
135b98
 modules/mount_bind.c |   30 +++++++++++++++++++-----------
135b98
 6 files changed, 51 insertions(+), 11 deletions(-)
135b98
135b98
--- autofs-5.1.4.orig/CHANGELOG
135b98
+++ autofs-5.1.4/CHANGELOG
135b98
@@ -31,6 +31,7 @@ xx/xx/2018 autofs-5.1.5
135b98
 - fix update_negative_cache() map source usage.
135b98
 - mark removed cache entry negative.
135b98
 - set bind mount as propagation slave.
135b98
+- add master map pseudo options for mount propagation.
135b98
 
135b98
 19/12/2017 autofs-5.1.4
135b98
 - fix spec file url.
135b98
--- autofs-5.1.4.orig/include/automount.h
135b98
+++ autofs-5.1.4/include/automount.h
135b98
@@ -549,6 +549,10 @@ struct kernel_mod_version {
135b98
 /* Read amd map even if it's not to be ghosted (browsable) */
135b98
 #define MOUNT_FLAG_AMD_CACHE_ALL	0x0080
135b98
 
135b98
+/* Set mount propagation for bind mounts */
135b98
+#define MOUNT_FLAG_SLAVE		0x0100
135b98
+#define MOUNT_FLAG_PRIVATE		0x0200
135b98
+
135b98
 struct autofs_point {
135b98
 	pthread_t thid;
135b98
 	char *path;			/* Mount point name */
135b98
--- autofs-5.1.4.orig/lib/master_parse.y
135b98
+++ autofs-5.1.4/lib/master_parse.y
135b98
@@ -58,6 +58,8 @@ static char *format;
135b98
 static long timeout;
135b98
 static long negative_timeout;
135b98
 static unsigned symlnk;
135b98
+static unsigned slave;
135b98
+static unsigned private;
135b98
 static unsigned nobind;
135b98
 static unsigned ghost;
135b98
 extern unsigned global_selection_options;
135b98
@@ -103,6 +105,7 @@ static int master_fprintf(FILE *, char *
135b98
 %token MAP
135b98
 %token OPT_TIMEOUT OPT_NTIMEOUT OPT_NOBIND OPT_NOGHOST OPT_GHOST OPT_VERBOSE
135b98
 %token OPT_DEBUG OPT_RANDOM OPT_USE_WEIGHT OPT_SYMLINK OPT_MODE
135b98
+%token OPT_SLAVE OPT_PRIVATE
135b98
 %token COLON COMMA NL DDASH
135b98
 %type <strtype> map
135b98
 %type <strtype> options
135b98
@@ -196,6 +199,8 @@ line:
135b98
 	| PATH OPT_DEBUG { master_notify($1); YYABORT; }
135b98
 	| PATH OPT_TIMEOUT { master_notify($1); YYABORT; }
135b98
 	| PATH OPT_SYMLINK { master_notify($1); YYABORT; }
135b98
+	| PATH OPT_SLAVE { master_notify($1); YYABORT; }
135b98
+	| PATH OPT_PRIVATE { master_notify($1); YYABORT; }
135b98
 	| PATH OPT_NOBIND { master_notify($1); YYABORT; }
135b98
 	| PATH OPT_GHOST { master_notify($1); YYABORT; }
135b98
 	| PATH OPT_NOGHOST { master_notify($1); YYABORT; }
135b98
@@ -600,6 +605,8 @@ option: daemon_option
135b98
 daemon_option: OPT_TIMEOUT NUMBER { timeout = $2; }
135b98
 	| OPT_NTIMEOUT NUMBER { negative_timeout = $2; }
135b98
 	| OPT_SYMLINK	{ symlnk = 1; }
135b98
+	| OPT_SLAVE	{ slave = 1; }
135b98
+	| OPT_PRIVATE	{ private = 1; }
135b98
 	| OPT_NOBIND	{ nobind = 1; }
135b98
 	| OPT_NOGHOST	{ ghost = 0; }
135b98
 	| OPT_GHOST	{ ghost = 1; }
135b98
@@ -672,6 +679,8 @@ static void local_init_vars(void)
135b98
 	timeout = -1;
135b98
 	negative_timeout = 0;
135b98
 	symlnk = 0;
135b98
+	slave = 0;
135b98
+	private = 0;
135b98
 	nobind = 0;
135b98
 	ghost = defaults_get_browse_mode();
135b98
 	random_selection = global_selection_options & MOUNT_FLAG_RANDOM_SELECT;
135b98
@@ -878,6 +887,10 @@ int master_parse_entry(const char *buffe
135b98
 		entry->ap->flags |= MOUNT_FLAG_USE_WEIGHT_ONLY;
135b98
 	if (symlnk)
135b98
 		entry->ap->flags |= MOUNT_FLAG_SYMLINK;
135b98
+	if (slave)
135b98
+		entry->ap->flags |= MOUNT_FLAG_SLAVE;
135b98
+	if (private)
135b98
+		entry->ap->flags |= MOUNT_FLAG_PRIVATE;
135b98
 	if (negative_timeout)
135b98
 		entry->ap->negative_timeout = negative_timeout;
135b98
 	if (mode && mode < LONG_MAX)
135b98
--- autofs-5.1.4.orig/lib/master_tok.l
135b98
+++ autofs-5.1.4/lib/master_tok.l
135b98
@@ -389,6 +389,8 @@ MODE		(--mode{OPTWS}|--mode{OPTWS}={OPTW
135b98
 	-?symlink		{ return(OPT_SYMLINK); }
135b98
 	-?nobind		{ return(OPT_NOBIND); }
135b98
 	-?nobrowse		{ return(OPT_NOGHOST); }
135b98
+	-?slave			{ return(OPT_SLAVE); }
135b98
+	-?private		{ return(OPT_PRIVATE); }
135b98
 	-g|--ghost|-?browse	{ return(OPT_GHOST); }
135b98
 	-v|--verbose		{ return(OPT_VERBOSE); }
135b98
 	-d|--debug		{ return(OPT_DEBUG); }
135b98
--- autofs-5.1.4.orig/man/auto.master.5.in
135b98
+++ autofs-5.1.4/man/auto.master.5.in
135b98
@@ -199,6 +199,18 @@ entries only, either in the master map (
135b98
 or with individual map entries. The option is ignored for direct mounts
135b98
 and non-root offest mount entries.
135b98
 .TP
135b98
+.I slave \fPor\fI private
135b98
+This option allows mount propagation of bind mounts to be set to
135b98
+either \fIslave\fP or \fIprivate\fP. This option may be needed when using
135b98
+multi-mounts that have bind mounts that bind to a file system that is
135b98
+propagation shared. This is becuase the bind mount will have the same
135b98
+properties as its target which causes problems for offset mounts. When
135b98
+this happens an unwanted offset mount is propagated back to the target
135b98
+file system resulting in a deadlock when attempting to access the offset.
135b98
+This option is a an autofs pseudo mount option that can be used in the
135b98
+master map only. By default bind mounts will inherit the mount propagation
135b98
+of the target file system.
135b98
+.TP
135b98
 .I "\-r, \-\-random-multimount-selection"
135b98
 Enables the use of random selection when choosing a host from a
135b98
 list of replicated servers. This option is applied to this mount
135b98
--- autofs-5.1.4.orig/modules/mount_bind.c
135b98
+++ autofs-5.1.4/modules/mount_bind.c
135b98
@@ -186,17 +186,25 @@ int mount_mount(struct autofs_point *ap,
135b98
 			      what, fstype, fullpath);
135b98
 		}
135b98
 
135b98
-		/* The bind mount has succeeded but if the target
135b98
-		 * mount is propagation shared propagation of child
135b98
-		 * mounts (autofs offset mounts for example) back to
135b98
-		 * the target of the bind mount must be avoided or
135b98
-		 * autofs trigger mounts will deadlock.
135b98
-		 */
135b98
-		err = mount(NULL, fullpath, NULL, MS_SLAVE, NULL);
135b98
-		if (err)
135b98
-			warn(ap->logopt,
135b98
-			     "failed to set propagation type for %s",
135b98
-			     fullpath);
135b98
+		if (ap->flags & (MOUNT_FLAG_SLAVE | MOUNT_FLAG_PRIVATE)) {
135b98
+			int flags = MS_SLAVE;
135b98
+
135b98
+			if (ap->flags & MOUNT_FLAG_PRIVATE)
135b98
+				flags = MS_PRIVATE;
135b98
+
135b98
+			/* The bind mount has succeeded but if the target
135b98
+			 * mount is propagation shared propagation of child
135b98
+			 * mounts (autofs offset mounts for example) back to
135b98
+			 * the target of the bind mount must be avoided or
135b98
+			 * autofs trigger mounts will deadlock.
135b98
+			 */
135b98
+			err = mount(NULL, fullpath, NULL, flags, NULL);
135b98
+			if (err) {
135b98
+				warn(ap->logopt,
135b98
+				     "failed to set propagation for %s",
135b98
+				     fullpath, root);
135b98
+			}
135b98
+		}
135b98
 
135b98
 		return 0;
135b98
 	} else {