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

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