Blob Blame History Raw
autofs-5.0.7 - add symlink pseudo option

From: Ian Kent <raven@themaw.net>

Add a "symlink" pseudo option to tell the bind mount module to symlink
instead of bind when mounting mounts other than direct mounts and
non-root indirect mount offset mounts (aka. non-root multi-mount
entries).
---
 CHANGELOG              |    1 +
 include/automount.h    |    3 +++
 lib/master_parse.y     |    8 +++++++-
 lib/master_tok.l       |    1 +
 man/auto.master.5.in   |    8 ++++++++
 modules/mount_autofs.c |    5 +++++
 modules/mount_bind.c   |   36 +++++++++++++++++++++++++++++++++++-
 7 files changed, 60 insertions(+), 2 deletions(-)

--- autofs-5.0.6.orig/CHANGELOG
+++ autofs-5.0.6/CHANGELOG
@@ -47,6 +47,7 @@
 - fix nfs4 contacts portmap.
 - add timeout option description to man page.
 - depricate nosymlink pseudo option.
+- add symlink pseudo option.
 
 28/06/2011 autofs-5.0.6
 -----------------------
--- autofs-5.0.6.orig/include/automount.h
+++ autofs-5.0.6/include/automount.h
@@ -451,6 +451,9 @@ struct kernel_mod_version {
 /* Don't use bind mounts even when system supports them */
 #define MOUNT_FLAG_NOBIND		0x0020
 
+/* Use symlinks instead of bind mounting local mounts */
+#define MOUNT_FLAG_SYMLINK		0x0040
+
 struct autofs_point {
 	pthread_t thid;
 	char *path;			/* Mount point name */
--- autofs-5.0.6.orig/lib/master_parse.y
+++ autofs-5.0.6/lib/master_parse.y
@@ -57,6 +57,7 @@ static char *type;
 static char *format;
 static long timeout;
 static long negative_timeout;
+static unsigned symlnk;
 static unsigned nobind;
 static unsigned ghost;
 extern unsigned global_selection_options;
@@ -100,7 +101,7 @@ static int master_fprintf(FILE *, char *
 %token COMMENT
 %token MAP
 %token OPT_TIMEOUT OPT_NTIMEOUT OPT_NOBIND OPT_NOGHOST OPT_GHOST OPT_VERBOSE
-%token OPT_DEBUG OPT_RANDOM OPT_USE_WEIGHT
+%token OPT_DEBUG OPT_RANDOM OPT_USE_WEIGHT OPT_SYMLINK
 %token COLON COMMA NL DDASH
 %type <strtype> map
 %type <strtype> options
@@ -186,6 +187,7 @@ line:
 	| PATH OPT_USE_WEIGHT { master_notify($1); YYABORT; }
 	| PATH OPT_DEBUG { master_notify($1); YYABORT; }
 	| PATH OPT_TIMEOUT { master_notify($1); YYABORT; }
+	| PATH OPT_SYMLINK { master_notify($1); YYABORT; }
 	| PATH OPT_NOBIND { master_notify($1); YYABORT; }
 	| PATH OPT_GHOST { master_notify($1); YYABORT; }
 	| PATH OPT_NOGHOST { master_notify($1); YYABORT; }
@@ -557,6 +559,7 @@ option: daemon_option
 
 daemon_option: OPT_TIMEOUT NUMBER { timeout = $2; }
 	| OPT_NTIMEOUT NUMBER { negative_timeout = $2; }
+	| OPT_SYMLINK	{ symlnk = 1; }
 	| OPT_NOBIND	{ nobind = 1; }
 	| OPT_NOGHOST	{ ghost = 0; }
 	| OPT_GHOST	{ ghost = 1; }
@@ -627,6 +630,7 @@ static void local_init_vars(void)
 	debug = 0;
 	timeout = -1;
 	negative_timeout = 0;
+	symlnk = 0;
 	nobind = 0;
 	ghost = defaults_get_browse_mode();
 	random_selection = global_selection_options & MOUNT_FLAG_RANDOM_SELECT;
@@ -818,6 +822,8 @@ int master_parse_entry(const char *buffe
 		entry->ap->flags |= MOUNT_FLAG_RANDOM_SELECT;
 	if (use_weight)
 		entry->ap->flags |= MOUNT_FLAG_USE_WEIGHT_ONLY;
+	if (symlnk)
+		entry->ap->flags |= MOUNT_FLAG_SYMLINK;
 	if (negative_timeout)
 		entry->ap->negative_timeout = negative_timeout;
 
--- autofs-5.0.6.orig/lib/master_tok.l
+++ autofs-5.0.6/lib/master_tok.l
@@ -359,6 +359,7 @@ OPTNTOUT	(-n{OPTWS}|-n{OPTWS}={OPTWS}|--
 		return(NUMBER);
 	}
 
+	-?symlink		{ return(OPT_SYMLINK); }
 	-?nobind		{ return(OPT_NOBIND); }
 	-?nobrowse		{ return(OPT_NOGHOST); }
 	-g|--ghost|-?browse	{ return(OPT_GHOST); }
--- autofs-5.0.6.orig/man/auto.master.5.in
+++ autofs-5.0.6/man/auto.master.5.in
@@ -155,6 +155,14 @@ entries to prevent bind mounting of loca
 of NFS file systems can also be prevented for specific map entrys by
 adding the "port=" mount option to the entries.
 .TP
+.I "symlink"
+This option makes bind mounting use a symlink instead of an actual bind
+mount. It is an autofs specific option that is a pseudo mount option and
+so is given without a leading dash. It may be used with indirect map
+entries only, either in the master map (so it effects all map entries)
+or with individual map entries. The option is ignored for direct mounts
+and non-root offest mount entries.
+.TP
 .I "\-r, \-\-random-multimount-selection"
 Enables the use of ramdom selection when choosing a host from a
 list of replicated servers. This option is applied to this mount
--- autofs-5.0.6.orig/modules/mount_autofs.c
+++ autofs-5.0.6/modules/mount_autofs.c
@@ -51,6 +51,7 @@ int mount_mount(struct autofs_point *ap,
 	int argc, status;
 	int nobind = ap->flags & MOUNT_FLAG_NOBIND;
 	int ghost = ap->flags & MOUNT_FLAG_GHOST;
+	int symlnk = ap->flags & MOUNT_FLAG_SYMLINK;
 	time_t timeout = ap->exp_timeout;
 	unsigned logopt = ap->logopt;
 	struct map_type_info *info;
@@ -120,6 +121,8 @@ int mount_mount(struct autofs_point *ap,
 				nobind = 1;
 			else if (strncmp(cp, "browse", 6) == 0)
 				ghost = 1;
+			else if (strncmp(cp, "symlink", 7) == 0)
+				symlnk = 1;
 			else if (strncmp(cp, "timeout=", 8) == 0) {
 				char *val = strchr(cp, '=');
 				unsigned tout;
@@ -158,6 +161,8 @@ int mount_mount(struct autofs_point *ap,
 	}
 	nap = entry->ap;
 	nap->parent = ap;
+	if (symlnk)
+		nap->flags |= MOUNT_FLAG_SYMLINK;
 
 	argc = 1;
 
--- autofs-5.0.6.orig/modules/mount_bind.c
+++ autofs-5.0.6/modules/mount_bind.c
@@ -73,10 +73,44 @@ int mount_mount(struct autofs_point *ap,
 	char buf[MAX_ERR_BUF];
 	int err;
 	int i, len;
+	int symlnk = (*name != '/' && (ap->flags & MOUNT_FLAG_SYMLINK));
 
 	if (ap->flags & MOUNT_FLAG_REMOUNT)
 		return 0;
 
+	/* Extract "symlink" pseudo-option which forces local filesystems
+	 * to be symlinked instead of bound.
+	 */
+	if (*name != '/' && !symlnk && options) {
+		const char *comma;
+		int o_len = strlen(options) + 1;
+
+		for (comma = options; *comma != '\0';) {
+			const char *cp;
+			const char *end;
+
+			while (*comma == ',')
+				comma++;
+
+			/* Skip leading white space */
+			while (*comma == ' ' || *comma == '\t')
+				comma++;
+
+			cp = comma;
+			while (*comma != '\0' && *comma != ',')
+				comma++;
+
+			/* Skip trailing white space */
+			end = comma - 1;
+			while (*comma == ' ' || *comma == '\t')
+				end--;
+
+			o_len = end - cp + 1;
+			if (strncmp("symlink", cp, o_len) == 0)
+				symlnk = 1;
+		}
+	}
+
 	/* Root offset of multi-mount */
 	len = strlen(root);
 	if (root[len - 1] == '/') {
@@ -100,7 +134,7 @@ int mount_mount(struct autofs_point *ap,
 	if (options == NULL || *options == '\0')
 		options = "defaults";
 
-	if (bind_works) {
+	if (!symlnk && bind_works) {
 		int status, existed = 1;
 
 		debug(ap->logopt, MODPREFIX "calling mkdir_path %s", fullpath);