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

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