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

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