All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Kent <raven@themaw.net>
To: autofs mailing list <autofs@vger.kernel.org>
Subject: [PATCH 29/37] autofs-5.1.2 - add support for amd browsable option
Date: Tue, 25 Oct 2016 09:19:59 +0800	[thread overview]
Message-ID: <20161025011959.7778.36120.stgit@pluto.themaw.net> (raw)
In-Reply-To: <20161025010014.7778.69274.stgit@pluto.themaw.net>

From: Ian Kent <ikent@redhat.com>

Add support for the "browsable_dirs" configuration option and the
pseudo mount option "browsable" of amd format maps.

Note that support for the configuration option "browsable_dirs = full"
and the pseudo mount option "fullybrowsable" of type auto map entries
cannot be implemented using  the existing kernel to user space autofs
implementation.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 CHANGELOG                      |    1 
 README.amd-maps                |    2 -
 daemon/lookup.c                |  106 ++++++++++++++++++++++++++++++++--------
 lib/master_parse.y             |   14 ++++-
 man/autofs.conf.5.in           |    7 ++-
 modules/amd_parse.y            |    3 -
 modules/mount_autofs.c         |    8 ++-
 modules/parse_amd.c            |    2 -
 redhat/autofs.conf.default.in  |    7 ++-
 samples/autofs.conf.default.in |    7 ++-
 10 files changed, 120 insertions(+), 37 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 5b3d0d1..da3b54e 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -26,6 +26,7 @@ xx/xx/2016 autofs-5.1.3
 - add sss master map wait config option.
 - fix typos in README.amd-maps.
 - add ref counting to struct map_source.
+- add support for amd browsable option.
 
 15/06/2016 autofs-5.1.2
 =======================
diff --git a/README.amd-maps b/README.amd-maps
index e79f521..4f1d58d 100644
--- a/README.amd-maps
+++ b/README.amd-maps
@@ -101,7 +101,7 @@ What hasn't been implemented
 ----------------------------
 
 The configuration options fully_qualified_hosts, unmount_on_exit and
-browsable_dirs (and a couple of others) aren't implemented.
+browsable_dirs = full (and a couple of others) aren't implemented.
 
 Map types (sources) ndbm, passwd are not implemented.
 The map source "sss" can't be used for amd format maps.
diff --git a/daemon/lookup.c b/daemon/lookup.c
index 0c2a01f..a58be30 100644
--- a/daemon/lookup.c
+++ b/daemon/lookup.c
@@ -655,6 +655,56 @@ int lookup_nss_read_map(struct autofs_point *ap, struct map_source *source, time
 	return 0;
 }
 
+static char *make_browse_path(unsigned int logopt,
+			      const char *root, const char *key,
+			      const char *prefix)
+{
+	unsigned int l_prefix;
+	unsigned int k_len, r_len;
+	char *k_start;
+	char *path;
+
+	k_start = (char *) key;
+	k_len = strlen(key);
+	l_prefix = 0;
+
+	if (prefix) {
+		l_prefix = strlen(prefix);
+
+		if (l_prefix > k_len)
+			return NULL;
+
+		/* If the prefix doesn't match the beginning
+		 * of the key this entry isn't a sub directory
+		 * at this level.
+		 */
+		if (strncmp(key, prefix, l_prefix))
+			return NULL;
+
+		/* Directory entry starts following the prefix */
+		k_start += l_prefix;
+	}
+
+	/* No remaining "/" allowed here */
+	if (strchr(k_start, '/'))
+		return NULL;
+
+	r_len = strlen(root);
+
+	if ((r_len + strlen(k_start)) > KEY_MAX_LEN)
+		return NULL;
+
+	path = malloc(r_len + k_len + 2);
+	if (!path) {
+		warn(logopt, "failed to allocate full path");
+		return NULL;
+	}
+
+	sprintf(path, "%s/%s", root, k_start);
+
+	return path;
+}
+
 int lookup_ghost(struct autofs_point *ap, const char *root)
 {
 	struct master_mapent *entry = ap->entry;
@@ -698,10 +748,19 @@ int lookup_ghost(struct autofs_point *ap, const char *root)
 			if (!me->mapent)
 				goto next;
 
-			if (!strcmp(me->key, "*"))
+			/* Wildcard cannot be a browse directory and amd map
+			 * keys may end with the wildcard.
+			 */
+			if (strchr(me->key, '*'))
 				goto next;
 
+			/* This will also take care of amd "/defaults" entry as
+			 * amd map keys are not allowd to start with "/"
+			 */
 			if (*me->key == '/') {
+				if (map->flags & MAP_FLAG_FORMAT_AMD)
+					goto next;
+
 				/* It's a busy multi-mount - leave till next time */
 				if (list_empty(&me->multi_list))
 					error(ap->logopt,
@@ -709,12 +768,10 @@ int lookup_ghost(struct autofs_point *ap, const char *root)
 				goto next;
 			}
 
-			fullpath = malloc(strlen(me->key) + strlen(root) + 3);
-			if (!fullpath) {
-				warn(ap->logopt, "failed to allocate full path");
+			fullpath = make_browse_path(ap->logopt,
+						    root, me->key, ap->pref);
+			if (!fullpath)
 				goto next;
-			}
-			sprintf(fullpath, "%s/%s", root, me->key);
 
 			ret = stat(fullpath, &st);
 			if (ret == -1 && errno != ENOENT) {
@@ -724,6 +781,17 @@ int lookup_ghost(struct autofs_point *ap, const char *root)
 				goto next;
 			}
 
+			/* Directory already exists? */
+			if (!ret) {
+				/* Shouldn't need this
+				me->dev = st.st_dev;
+				me->ino = st.st_ino;
+				*/
+				debug(ap->logopt, "me->dev %d me->ino %d", me->dev, me->ino);
+				free(fullpath);
+				goto next;
+			}
+
 			ret = mkdir_path(fullpath, 0555);
 			if (ret < 0 && errno != EEXIST) {
 				char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
@@ -1233,28 +1301,23 @@ void lookup_close_lookup(struct autofs_point *ap)
 	return;
 }
 
-static char *make_fullpath(const char *root, const char *key)
+static char *make_fullpath(struct autofs_point *ap, const char *key)
 {
+	char *path = NULL;
 	int l;
-	char *path;
 
-	if (*key == '/') {
+	if (*key != '/')
+		path = make_browse_path(ap->logopt, ap->path, key, ap->pref);
+	else {
 		l = strlen(key) + 1;
 		if (l > KEY_MAX_LEN)
-			return NULL;
+			goto out;
 		path = malloc(l);
 		if (!path)
-			return NULL;
+			goto out;
 		strcpy(path, key);
-	} else {
-		l = strlen(key) + 1 + strlen(root) + 1;
-		if (l > KEY_MAX_LEN)
-			return NULL;
-		path = malloc(l);
-		if (!path)
-			return NULL;
-		sprintf(path, "%s/%s", root, key);
 	}
+out:
 	return path;
 }
 
@@ -1285,13 +1348,14 @@ void lookup_prune_one_cache(struct autofs_point *ap, struct mapent_cache *mc, ti
 
 		key = strdup(me->key);
 		me = cache_enumerate(mc, me);
-		if (!key || !strcmp(key, "*")) {
+		/* Don't consider any entries with a wildcard */
+		if (!key || strchr(key, '*')) {
 			if (key)
 				free(key);
 			continue;
 		}
 
-		path = make_fullpath(ap->path, key);
+		path = make_fullpath(ap, key);
 		if (!path) {
 			warn(ap->logopt, "can't malloc storage for path");
 			free(key);
diff --git a/lib/master_parse.y b/lib/master_parse.y
index 0011429..7536324 100644
--- a/lib/master_parse.y
+++ b/lib/master_parse.y
@@ -811,14 +811,22 @@ int master_parse_entry(const char *buffer, unsigned int default_timeout, unsigne
 
 	if (format && !strcmp(format, "amd")) {
 		unsigned int loglevel = conf_amd_get_log_options();
+		unsigned int flags = conf_amd_get_flags(path);
+
 		if (loglevel <= LOG_DEBUG && loglevel > LOG_INFO)
 			logopt = LOGOPT_DEBUG;
 		else if (loglevel <= LOG_INFO && loglevel > LOG_ERR)
 			logopt = LOGOPT_VERBOSE;
-		/* amd mounts don't support browse mode */
-		ghost = 0;
-	}
 
+		/* It isn't possible to provide the fullybrowsable amd
+		 * browsing functionality within the autofs framework.
+		 * This flag will not be set if browsable_dirs = full
+		 * in the configuration or fullybrowsable is present as
+		 * an option.
+		 */
+		if (flags & CONF_BROWSABLE_DIRS)
+			ghost = 1;
+	}
 
 	if (timeout < 0) {
 		/*
diff --git a/man/autofs.conf.5.in b/man/autofs.conf.5.in
index 93ff7af..2bb262e 100644
--- a/man/autofs.conf.5.in
+++ b/man/autofs.conf.5.in
@@ -355,7 +355,12 @@ and that will be done.
 .TP
 .B browsable_dirs
 .br
-Not yet implemented.
+Allow map keys to be shown in directory listings. This option
+can have values of "yes" or "no". The default is "no". A variation
+of this option, "browsable", can be used as a pseudo mount option
+in type "auto" map entries to provide provide browsing funtionality
+in sub-mounts. The amd "browsable_dirs = full" option cannot be
+implemented within the current autofs framework and is not supported.
 .TP
 .B exec_map_timeout
 .br
diff --git a/modules/amd_parse.y b/modules/amd_parse.y
index bfa1d51..b33250a 100644
--- a/modules/amd_parse.y
+++ b/modules/amd_parse.y
@@ -433,8 +433,7 @@ option_assignment: MAP_OPTION OPTION_ASSIGN FS_TYPE
 
 options: OPTION
 	{
-		if (!strcmp($1, "browsable") ||
-		    !strcmp($1, "fullybrowsable") ||
+		if (!strcmp($1, "fullybrowsable") ||
 		    !strcmp($1, "nounmount") ||
 		    !strcmp($1, "unmount")) {
 			sprintf(msg_buf, "option %s is not currently "
diff --git a/modules/mount_autofs.c b/modules/mount_autofs.c
index 3ba5271..e404c83 100644
--- a/modules/mount_autofs.c
+++ b/modules/mount_autofs.c
@@ -121,11 +121,13 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name,
 			while (*comma != '\0' && *comma != ',')
 				comma++;
 
-			if (_strncmp("nobrowse", cp, 8) == 0)
+			if (_strncmp("nobrowse", cp, 8) == 0 ||
+			    _strncmp("nobrowsable", cp, 11) == 0)
 				ghost = 0;
 			else if (_strncmp("nobind", cp, 6) == 0)
 				nobind = 1;
-			else if (_strncmp("browse", cp, 6) == 0)
+			else if (_strncmp("browse", cp, 6) == 0 ||
+				 _strncmp("browsable", cp, 9) == 0)
 				ghost = 1;
 			else if (_strncmp("symlink", cp, 7) == 0)
 				symlnk = 1;
@@ -287,8 +289,6 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name,
 			nap->pref = am_entry->pref;
 			am_entry->pref = NULL;
 		}
-		/* amd mounts don't support browse mode */
-		nap->flags &= ~MOUNT_FLAG_GHOST;
 	}
 
 	if (handle_mounts_startup_cond_init(&suc)) {
diff --git a/modules/parse_amd.c b/modules/parse_amd.c
index 38d76b8..2ff43fa 100644
--- a/modules/parse_amd.c
+++ b/modules/parse_amd.c
@@ -930,7 +930,7 @@ static int do_auto_mount(struct autofs_point *ap, const char *name,
 	}
 
 	return do_mount(ap, ap->path,
-			name, strlen(name), target, "autofs", NULL);
+			name, strlen(name), target, "autofs", entry->opts);
 }
 
 static int do_link_mount(struct autofs_point *ap, const char *name,
diff --git a/redhat/autofs.conf.default.in b/redhat/autofs.conf.default.in
index 9bceab3..f7adcb5 100644
--- a/redhat/autofs.conf.default.in
+++ b/redhat/autofs.conf.default.in
@@ -274,8 +274,6 @@ mount_nfs_default_protocol = 4
 #	is a sensible option to implement and that will be
 #	done.
 #
-# browsable_dirs - not yet implemented.
-#
 # exec_map_timeout - a timeout is not currently used for
 #	for program maps, might be implemented.
 #
@@ -318,6 +316,11 @@ mount_nfs_default_protocol = 4
 #	takes its default value from the autofs internal default
 #	of 600 seconds.
 #
+# browsable_dirs - make map keys visible in directory listings.
+#	Note that support for the "fullybrowsable" option cannot
+#	be added using the existing kernel to user space autofs
+#	implementation.
+#
 # autofs_use_lofs - if set to "yes" autofs will attempt to use bind
 #	mounts for type "auto" when possible.
 #
diff --git a/samples/autofs.conf.default.in b/samples/autofs.conf.default.in
index a275e08..5311da7 100644
--- a/samples/autofs.conf.default.in
+++ b/samples/autofs.conf.default.in
@@ -273,8 +273,6 @@ browse_mode = no
 #	is a sensible option to implement and that will be
 #	done.
 #
-# browsable_dirs - not yet implemented.
-#
 # exec_map_timeout - a timeout is not currently used for
 #	for program maps, might be implemented.
 #
@@ -317,6 +315,11 @@ browse_mode = no
 #	takes its default value from the autofs internal default
 #	of 600 seconds.
 #
+# browsable_dirs - make map keys visible in directory listings.
+#	Note that support for the "fullybrowsable" option cannot
+#	be added using the existing kernel to user space autofs
+#	implementation.
+#
 # autofs_use_lofs - if set to "yes" autofs will attempt to use bind
 #	mounts for type "auto" when possible.
 #

--
To unsubscribe from this list: send the line "unsubscribe autofs" in

  parent reply	other threads:[~2016-10-25  1:19 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-25  1:17 [PATCH 00/37] Current patch queue for review Ian Kent
2016-10-25  1:17 ` [PATCH 01/37] autofs-5.1.2 - fix release date in CHANGELOG Ian Kent
2016-10-25  1:17 ` [PATCH 02/37] autofs-5.1.2 - build: check for clock_gettime in librt Ian Kent
2016-10-25  1:17 ` [PATCH 03/37] autofs-5.1.2 - Fix compiler warning in try_remount() Ian Kent
2016-10-25  1:17 ` [PATCH 04/37] autofs-5.1.2 - Drop redundant \n in logerr() Ian Kent
2016-10-25  1:17 ` [PATCH 05/37] autofs-5.1.2 - Fix size arg of fgets(3) Ian Kent
2016-10-25  1:17 ` [PATCH 06/37] autofs-5.1.2 - fix libtirpc detection with -Wl, --as-needed Ian Kent
2016-10-25  1:18 ` [PATCH 07/37] autofs-5.1.2 - Fix a typo in CREDITS Ian Kent
2016-10-25  1:18 ` [PATCH 08/37] autofs-5.1.2 - Change .requestor to .requester for consistency Ian Kent
2016-10-25  1:18 ` [PATCH 09/37] autofs-5.1.2 - fix file map changed check Ian Kent
2016-10-25  1:18 ` [PATCH 10/37] autofs-5.1.2 - Remove unused local 2KB buffer Ian Kent
2016-10-25  1:18 ` [PATCH 11/37] autofs-5.1.2 - Fix typos in error messages Ian Kent
2016-10-25  1:18 ` [PATCH 12/37] autofs-5.1.2 - Fix fgets(3) size argument (another one) Ian Kent
2016-10-25  1:18 ` [PATCH 13/37] autofs-5.1.2 - fix short memory allocation in lookup_amd_instance() Ian Kent
2016-10-25  1:18 ` [PATCH 14/37] autofs-5.1.2 - fix count_mounts() function Ian Kent
2016-10-25  1:18 ` [PATCH 15/37] autofs-5.1.2 - configure: add cache variable for Linux proc filesystem check Ian Kent
2016-10-25  1:18 ` [PATCH 16/37] autofs-5.1.2 - Avoid local variable name shadowing another Ian Kent
2016-10-25  1:18 ` [PATCH 17/37] autofs-5.1.2 - fix typo in MOUNT_FLAG_GHOST comment Ian Kent
2016-10-25  1:19 ` [PATCH 18/37] autofs-5.1.2 - fix cachefs parse message not being logged Ian Kent
2016-10-25  1:19 ` [PATCH 19/37] autofs-5.1.2 - fix argc off by one in mount_autofs.c Ian Kent
2016-10-25  1:19 ` [PATCH 20/37] autofs-5.1.2 - fix _strncmp() usage Ian Kent
2016-10-25  1:19 ` [PATCH 21/37] autofs-5.1.1 - fix create_client() RPC client handling Ian Kent
2016-10-25  1:19 ` [PATCH 22/37] autofs-5.1.2 - update and add README for old autofs schema Ian Kent
2016-10-25  1:19 ` [PATCH 23/37] autofs-5.1.2 - wait for master map available at start Ian Kent
2016-10-25  1:19 ` [PATCH 24/37] autofs-5.1.2 - add master read wait option Ian Kent
2016-10-25  1:19 ` [PATCH 25/37] autofs-5.1.2 - work around sss startup delay Ian Kent
2016-10-25  1:19 ` [PATCH 26/37] autofs-5.1.2 - add sss master map wait config option Ian Kent
2016-10-25  1:19 ` [PATCH 27/37] autofs-5.1.2 - fix typos in README.amd-maps Ian Kent
2016-10-25  1:19 ` [PATCH 28/37] autofs-5.1.2 - add ref counting to struct map_source Ian Kent
2016-10-25  1:19 ` Ian Kent [this message]
2016-10-25  1:20 ` [PATCH 30/37] autofs-5.1.2 - add function conf_amd_get_map_name() Ian Kent
2016-10-25  1:20 ` [PATCH 31/37] autofs-5.1.2 - add function conf_amd_get_mount_paths() Ian Kent
2016-10-25  1:20 ` [PATCH 32/37] autofs-5.1.2 - include amd mount section mounts in master mounts list Ian Kent
2016-10-25  1:20 ` [PATCH 33/37] autofs-5.1.2 - check for conflicting amd section mounts Ian Kent
2016-10-25  1:20 ` [PATCH 34/37] autofs-5.1.2 - add function conf_get_map_options() Ian Kent
2016-10-25  1:20 ` [PATCH 35/37] autofs-5.1.2 - capture cache option and its settings during parsing Ian Kent
2016-10-25  1:20 ` [PATCH 36/37] autofs-5.1.2 - handle map_option cache for top level mounts Ian Kent
2016-10-25  1:20 ` [PATCH 37/37] autofs-5.1.2 - handle amd cache option all in amd type auto mounts Ian Kent
2016-11-04  8:53 ` [PATCH 00/37] Current patch queue for review Ian Kent

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161025011959.7778.36120.stgit@pluto.themaw.net \
    --to=raven@themaw.net \
    --cc=autofs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.