Blame SOURCES/autofs-5.0.7-add-symlink-pseudo-option.patch

306fa1
autofs-5.0.7 - add symlink pseudo option
306fa1
306fa1
From: Ian Kent <raven@themaw.net>
306fa1
306fa1
Add a "symlink" pseudo option to tell the bind mount module to symlink
306fa1
instead of bind when mounting mounts other than direct mounts and
306fa1
non-root indirect mount offset mounts (aka. non-root multi-mount
306fa1
entries).
306fa1
---
306fa1
 CHANGELOG              |    1 +
306fa1
 include/automount.h    |    3 +++
306fa1
 lib/master_parse.y     |    8 +++++++-
306fa1
 lib/master_tok.l       |    1 +
306fa1
 man/auto.master.5.in   |    8 ++++++++
306fa1
 modules/mount_autofs.c |    5 +++++
306fa1
 modules/mount_bind.c   |   36 +++++++++++++++++++++++++++++++++++-
306fa1
 7 files changed, 60 insertions(+), 2 deletions(-)
306fa1
306fa1
diff --git a/CHANGELOG b/CHANGELOG
306fa1
index c189483..247d334 100644
306fa1
--- a/CHANGELOG
306fa1
+++ b/CHANGELOG
306fa1
@@ -32,6 +32,7 @@
306fa1
 - fix wildcard multi map regression.
306fa1
 - fix file descriptor leak when reloading the daemon.
306fa1
 - depricate nosymlink pseudo option.
306fa1
+- add symlink pseudo option.
306fa1
 
306fa1
 25/07/2012 autofs-5.0.7
306fa1
 =======================
306fa1
diff --git a/include/automount.h b/include/automount.h
306fa1
index 37541f5..e72fa0d 100644
306fa1
--- a/include/automount.h
306fa1
+++ b/include/automount.h
306fa1
@@ -455,6 +455,9 @@ struct kernel_mod_version {
306fa1
 /* Don't use bind mounts even when system supports them */
306fa1
 #define MOUNT_FLAG_NOBIND		0x0020
306fa1
 
306fa1
+/* Use symlinks instead of bind mounting local mounts */
306fa1
+#define MOUNT_FLAG_SYMLINK		0x0040
306fa1
+
306fa1
 struct autofs_point {
306fa1
 	pthread_t thid;
306fa1
 	char *path;			/* Mount point name */
306fa1
diff --git a/lib/master_parse.y b/lib/master_parse.y
306fa1
index f925b5a..11caf5b 100644
306fa1
--- a/lib/master_parse.y
306fa1
+++ b/lib/master_parse.y
306fa1
@@ -57,6 +57,7 @@ static char *type;
306fa1
 static char *format;
306fa1
 static long timeout;
306fa1
 static long negative_timeout;
306fa1
+static unsigned symlnk;
306fa1
 static unsigned nobind;
306fa1
 static unsigned ghost;
306fa1
 extern unsigned global_selection_options;
306fa1
@@ -100,7 +101,7 @@ static int master_fprintf(FILE *, char *, ...);
306fa1
 %token COMMENT
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
306fa1
+%token OPT_DEBUG OPT_RANDOM OPT_USE_WEIGHT OPT_SYMLINK
306fa1
 %token COLON COMMA NL DDASH
306fa1
 %type <strtype> map
306fa1
 %type <strtype> options
306fa1
@@ -186,6 +187,7 @@ line:
306fa1
 	| PATH OPT_USE_WEIGHT { master_notify($1); YYABORT; }
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_NOBIND { master_notify($1); YYABORT; }
306fa1
 	| PATH OPT_GHOST { master_notify($1); YYABORT; }
306fa1
 	| PATH OPT_NOGHOST { master_notify($1); YYABORT; }
306fa1
@@ -557,6 +559,7 @@ option: daemon_option
306fa1
 
306fa1
 daemon_option: OPT_TIMEOUT NUMBER { timeout = $2; }
306fa1
 	| OPT_NTIMEOUT NUMBER { negative_timeout = $2; }
306fa1
+	| OPT_SYMLINK	{ symlnk = 1; }
306fa1
 	| OPT_NOBIND	{ nobind = 1; }
306fa1
 	| OPT_NOGHOST	{ ghost = 0; }
306fa1
 	| OPT_GHOST	{ ghost = 1; }
306fa1
@@ -627,6 +630,7 @@ static void local_init_vars(void)
306fa1
 	debug = 0;
306fa1
 	timeout = -1;
306fa1
 	negative_timeout = 0;
306fa1
+	symlnk = 0;
306fa1
 	nobind = 0;
306fa1
 	ghost = defaults_get_browse_mode();
306fa1
 	random_selection = global_selection_options & MOUNT_FLAG_RANDOM_SELECT;
306fa1
@@ -811,6 +815,8 @@ int master_parse_entry(const char *buffer, unsigned int default_timeout, unsigne
306fa1
 		entry->ap->flags |= MOUNT_FLAG_RANDOM_SELECT;
306fa1
 	if (use_weight)
306fa1
 		entry->ap->flags |= MOUNT_FLAG_USE_WEIGHT_ONLY;
306fa1
+	if (symlnk)
306fa1
+		entry->ap->flags |= MOUNT_FLAG_SYMLINK;
306fa1
 	if (negative_timeout)
306fa1
 		entry->ap->negative_timeout = negative_timeout;
306fa1
 
306fa1
diff --git a/lib/master_tok.l b/lib/master_tok.l
306fa1
index 30abb15..f9b4e55 100644
306fa1
--- a/lib/master_tok.l
306fa1
+++ b/lib/master_tok.l
306fa1
@@ -361,6 +361,7 @@ OPTNTOUT	(-n{OPTWS}|-n{OPTWS}={OPTWS}|--negative-timeout{OPTWS}|--negative-timeo
306fa1
 		return(NUMBER);
306fa1
 	}
306fa1
 
306fa1
+	-?symlink		{ return(OPT_SYMLINK); }
306fa1
 	-?nobind		{ return(OPT_NOBIND); }
306fa1
 	-?nobrowse		{ return(OPT_NOGHOST); }
306fa1
 	-g|--ghost|-?browse	{ return(OPT_GHOST); }
306fa1
diff --git a/man/auto.master.5.in b/man/auto.master.5.in
306fa1
index 8007542..bbea43a 100644
306fa1
--- a/man/auto.master.5.in
306fa1
+++ b/man/auto.master.5.in
306fa1
@@ -159,6 +159,14 @@ on individual map entries of both types. Bind mounting of NFS file
306fa1
 systems can also be prevented for specific map entrys by adding the
306fa1
 "port=" mount option to the entries.
306fa1
 .TP
306fa1
+.I "symlink"
306fa1
+This option makes bind mounting use a symlink instead of an actual bind
306fa1
+mount. It is an autofs specific option that is a pseudo mount option and
306fa1
+so is given without a leading dash. It may be used with indirect map
306fa1
+entries only, either in the master map (so it effects all map entries)
306fa1
+or with individual map entries. The option is ignored for direct mounts
306fa1
+and non-root offest mount entries.
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
diff --git a/modules/mount_autofs.c b/modules/mount_autofs.c
306fa1
index ef16020..8c1e600 100644
306fa1
--- a/modules/mount_autofs.c
306fa1
+++ b/modules/mount_autofs.c
306fa1
@@ -51,6 +51,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name,
306fa1
 	int argc, status;
306fa1
 	int nobind = ap->flags & MOUNT_FLAG_NOBIND;
306fa1
 	int ghost = ap->flags & MOUNT_FLAG_GHOST;
306fa1
+	int symlnk = ap->flags & MOUNT_FLAG_SYMLINK;
306fa1
 	time_t timeout = ap->entry->maps->exp_timeout;
306fa1
 	unsigned logopt = ap->logopt;
306fa1
 	struct map_type_info *info;
306fa1
@@ -120,6 +121,8 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name,
306fa1
 				nobind = 1;
306fa1
 			else if (strncmp(cp, "browse", 6) == 0)
306fa1
 				ghost = 1;
306fa1
+			else if (strncmp(cp, "symlink", 7) == 0)
306fa1
+				symlnk = 1;
306fa1
 			else if (strncmp(cp, "timeout=", 8) == 0) {
306fa1
 				char *val = strchr(cp, '=');
306fa1
 				unsigned tout;
306fa1
@@ -158,6 +161,8 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name,
306fa1
 	}
306fa1
 	nap = entry->ap;
306fa1
 	nap->parent = ap;
306fa1
+	if (symlnk)
306fa1
+		nap->flags |= MOUNT_FLAG_SYMLINK;
306fa1
 
306fa1
 	argc = 1;
306fa1
 
306fa1
diff --git a/modules/mount_bind.c b/modules/mount_bind.c
306fa1
index 9bce686..4975294 100644
306fa1
--- a/modules/mount_bind.c
306fa1
+++ b/modules/mount_bind.c
306fa1
@@ -73,10 +73,44 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
306fa1
 	char buf[MAX_ERR_BUF];
306fa1
 	int err;
306fa1
 	int i, len;
306fa1
+	int symlnk = (*name != '/' && (ap->flags & MOUNT_FLAG_SYMLINK));
306fa1
 
306fa1
 	if (ap->flags & MOUNT_FLAG_REMOUNT)
306fa1
 		return 0;
306fa1
 
306fa1
+	/* Extract "symlink" pseudo-option which forces local filesystems
306fa1
+	 * to be symlinked instead of bound.
306fa1
+	 */
306fa1
+	if (*name != '/' && !symlnk && options) {
306fa1
+		const char *comma;
306fa1
+		int o_len = strlen(options) + 1;
306fa1
+
306fa1
+		for (comma = options; *comma != '\0';) {
306fa1
+			const char *cp;
306fa1
+			const char *end;
306fa1
+
306fa1
+			while (*comma == ',')
306fa1
+				comma++;
306fa1
+
306fa1
+			/* Skip leading white space */
306fa1
+			while (*comma == ' ' || *comma == '\t')
306fa1
+				comma++;
306fa1
+
306fa1
+			cp = comma;
306fa1
+			while (*comma != '\0' && *comma != ',')
306fa1
+				comma++;
306fa1
+
306fa1
+			/* Skip trailing white space */
306fa1
+			end = comma - 1;
306fa1
+			while (*comma == ' ' || *comma == '\t')
306fa1
+				end--;
306fa1
+
306fa1
+			o_len = end - cp + 1;
306fa1
+			if (strncmp("symlink", cp, o_len) == 0)
306fa1
+				symlnk = 1;
306fa1
+		}
306fa1
+	}
306fa1
+
306fa1
 	/* Root offset of multi-mount */
306fa1
 	len = strlen(root);
306fa1
 	if (root[len - 1] == '/') {
306fa1
@@ -100,7 +134,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
306fa1
 	if (options == NULL || *options == '\0')
306fa1
 		options = "defaults";
306fa1
 
306fa1
-	if (bind_works) {
306fa1
+	if (!symlnk && bind_works) {
306fa1
 		int status, existed = 1;
306fa1
 
306fa1
 		debug(ap->logopt, MODPREFIX "calling mkdir_path %s", fullpath);