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

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