Blame SOURCES/autofs-5.1.5-add-strictexpire-mount-option.patch

304803
autofs-5.1.5 - support strictexpire mount option
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
Kernel commit 092a53452b (("autofs: take more care to not update
304803
last_used on path walk") helped to (partially) resolve a problem
304803
where automounts were not expiring due to aggressive accesses from
304803
user space.
304803
304803
This patch was later reverted because, for very large environments,
304803
it meant more mount requests from clients and when there are a lot
304803
of clients this caused a fairly significant increase in server load.
304803
304803
But there is a need for both types of expire check, depending on use
304803
case, so a mount option to allow for strict update of last use of
304803
autofs dentrys has been added ito the autofs file system (which just
304803
means not updating the last use on path walk accesses).
304803
304803
So add support for this master map mount entry option in the user
304803
space code.
304803
304803
Signed-off-by: Ian Kent <raven@themaw.net>
304803
---
304803
 CHANGELOG              |    1 +
304803
 daemon/direct.c        |   10 ++++++++++
304803
 daemon/indirect.c      |   10 ++++++++++
304803
 include/automount.h    |    3 +++
304803
 lib/master_parse.y     |    8 +++++++-
304803
 lib/master_tok.l       |    1 +
304803
 man/auto.master.5.in   |    8 ++++++++
304803
 modules/mount_autofs.c |    5 +++++
304803
 8 files changed, 45 insertions(+), 1 deletion(-)
304803
304803
--- autofs-5.0.7.orig/CHANGELOG
304803
+++ autofs-5.0.7/CHANGELOG
304803
@@ -316,6 +316,7 @@
304803
 - use flags for startup boolean options.
304803
 - move close stdio descriptors to become_daemon().
304803
 - add systemd service command line option.
304803
+- support strictexpire mount option.
304803
 
304803
 25/07/2012 autofs-5.0.7
304803
 =======================
304803
--- autofs-5.0.7.orig/daemon/direct.c
304803
+++ autofs-5.0.7/daemon/direct.c
304803
@@ -420,6 +420,16 @@ int do_mount_autofs_direct(struct autofs
304803
 		mp->options = make_options_string(ap->path, ap->kpipefd, str_direct);
304803
 		if (!mp->options)
304803
 			return 0;
304803
+
304803
+		if ((ap->flags & MOUNT_FLAG_STRICTEXPIRE) &&
304803
+		    ((get_kver_major() == 5 && get_kver_minor() > 3) ||
304803
+		     (get_kver_major() > 5))) {
304803
+			char *tmp = realloc(mp->options, strlen(mp->options) + 12);
304803
+			if (tmp) {
304803
+				strcat(tmp, ",strictexpire");
304803
+				mp->options = tmp;
304803
+			}
304803
+		}
304803
 	}
304803
 
304803
 	/* In case the directory doesn't exist, try to mkdir it */
304803
--- autofs-5.0.7.orig/daemon/indirect.c
304803
+++ autofs-5.0.7/daemon/indirect.c
304803
@@ -131,6 +131,16 @@ static int do_mount_autofs_indirect(stru
304803
 		goto out_err;
304803
 	}
304803
 
304803
+	if ((ap->flags & MOUNT_FLAG_STRICTEXPIRE) &&
304803
+	    ((get_kver_major() == 5 && get_kver_minor() > 3) ||
304803
+	     (get_kver_major() > 5))) {
304803
+		char *tmp = realloc(options, strlen(options) + 12);
304803
+		if (tmp) {
304803
+			strcat(tmp, ",strictexpire");
304803
+			options = tmp;
304803
+		}
304803
+	}
304803
+
304803
 	/* In case the directory doesn't exist, try to mkdir it */
304803
 	if (mkdir_path(root, 0555) < 0) {
304803
 		if (errno != EEXIST && errno != EROFS) {
304803
--- autofs-5.0.7.orig/include/automount.h
304803
+++ autofs-5.0.7/include/automount.h
304803
@@ -538,6 +538,9 @@ struct kernel_mod_version {
304803
 #define MOUNT_FLAG_SLAVE		0x0100
304803
 #define MOUNT_FLAG_PRIVATE		0x0200
304803
 
304803
+/* Use strict expire semantics if requested and kernel supports it */
304803
+#define MOUNT_FLAG_STRICTEXPIRE		0x0400
304803
+
304803
 struct autofs_point {
304803
 	pthread_t thid;
304803
 	char *path;			/* Mount point name */
304803
--- autofs-5.0.7.orig/lib/master_parse.y
304803
+++ autofs-5.0.7/lib/master_parse.y
304803
@@ -58,6 +58,7 @@ static char *format;
304803
 static long timeout;
304803
 static long negative_timeout;
304803
 static unsigned symlnk;
304803
+static unsigned strictexpire;
304803
 static unsigned slave;
304803
 static unsigned private;
304803
 static unsigned nobind;
304803
@@ -104,7 +105,7 @@ static int master_fprintf(FILE *, char *
304803
 %token MAP
304803
 %token OPT_TIMEOUT OPT_NTIMEOUT OPT_NOBIND OPT_NOGHOST OPT_GHOST OPT_VERBOSE
304803
 %token OPT_DEBUG OPT_RANDOM OPT_USE_WEIGHT OPT_SYMLINK
304803
-%token OPT_SLAVE OPT_PRIVATE
304803
+%token OPT_STRICTEXPIRE OPT_SLAVE OPT_PRIVATE
304803
 %token COLON COMMA NL DDASH
304803
 %type <strtype> map
304803
 %type <strtype> options
304803
@@ -191,6 +192,7 @@ line:
304803
 	| PATH OPT_DEBUG { master_notify($1); YYABORT; }
304803
 	| PATH OPT_TIMEOUT { master_notify($1); YYABORT; }
304803
 	| PATH OPT_SYMLINK { master_notify($1); YYABORT; }
304803
+	| PATH OPT_STRICTEXPIRE { master_notify($1); YYABORT; }
304803
 	| PATH OPT_SLAVE { master_notify($1); YYABORT; }
304803
 	| PATH OPT_PRIVATE { master_notify($1); YYABORT; }
304803
 	| PATH OPT_NOBIND { master_notify($1); YYABORT; }
304803
@@ -574,6 +576,7 @@ option: daemon_option
304803
 daemon_option: OPT_TIMEOUT NUMBER { timeout = $2; }
304803
 	| OPT_NTIMEOUT NUMBER { negative_timeout = $2; }
304803
 	| OPT_SYMLINK	{ symlnk = 1; }
304803
+	| OPT_STRICTEXPIRE { strictexpire = 1; }
304803
 	| OPT_SLAVE	{ slave = 1; }
304803
 	| OPT_PRIVATE	{ private = 1; }
304803
 	| OPT_NOBIND	{ nobind = 1; }
304803
@@ -647,6 +650,7 @@ static void local_init_vars(void)
304803
 	timeout = -1;
304803
 	negative_timeout = 0;
304803
 	symlnk = 0;
304803
+	strictexpire = 0;
304803
 	slave = 0;
304803
 	private = 0;
304803
 	nobind = 0;
304803
@@ -854,6 +858,8 @@ int master_parse_entry(const char *buffe
304803
 		entry->ap->flags |= MOUNT_FLAG_USE_WEIGHT_ONLY;
304803
 	if (symlnk)
304803
 		entry->ap->flags |= MOUNT_FLAG_SYMLINK;
304803
+	if (strictexpire)
304803
+		entry->ap->flags |= MOUNT_FLAG_STRICTEXPIRE;
304803
 	if (slave)
304803
 		entry->ap->flags |= MOUNT_FLAG_SLAVE;
304803
 	if (private)
304803
--- autofs-5.0.7.orig/lib/master_tok.l
304803
+++ autofs-5.0.7/lib/master_tok.l
304803
@@ -388,6 +388,7 @@ OPTNTOUT	(-n{OPTWS}|-n{OPTWS}={OPTWS}|--
304803
 	-?nobrowse		{ return(OPT_NOGHOST); }
304803
 	-?slave			{ return(OPT_SLAVE); }
304803
 	-?private		{ return(OPT_PRIVATE); }
304803
+	-?strictexpire		{ return(OPT_STRICTEXPIRE); }
304803
 	-g|--ghost|-?browse	{ return(OPT_GHOST); }
304803
 	-v|--verbose		{ return(OPT_VERBOSE); }
304803
 	-d|--debug		{ return(OPT_DEBUG); }
304803
--- autofs-5.0.7.orig/man/auto.master.5.in
304803
+++ autofs-5.0.7/man/auto.master.5.in
304803
@@ -198,6 +198,14 @@ entries only, either in the master map (
304803
 or with individual map entries. The option is ignored for direct mounts
304803
 and non-root offest mount entries.
304803
 .TP
304803
+.I "strictexpire"
304803
+Use a strict expire policy for this automount. Using this option means
304803
+that last use of autofs directory entries will not be updated during
304803
+path walks so that mounts in an automount won't be kept mounted by
304803
+applications scanning the mount tree. Note that this doesn't completely
304803
+resolve the problem of expired automounts being immediately re-mounted
304803
+due to application accesses triggered by the expire itself.
304803
+.TP
304803
 .I slave \fPor\fI private
304803
 This option allows mount propagation of bind mounts to be set to
304803
 either \fIslave\fP or \fIprivate\fP. This option may be needed when using
304803
--- autofs-5.0.7.orig/modules/mount_autofs.c
304803
+++ autofs-5.0.7/modules/mount_autofs.c
304803
@@ -57,6 +57,7 @@ int mount_mount(struct autofs_point *ap,
304803
 	int nobind = ap->flags & MOUNT_FLAG_NOBIND;
304803
 	int ghost = ap->flags & MOUNT_FLAG_GHOST;
304803
 	int symlnk = ap->flags & MOUNT_FLAG_SYMLINK;
304803
+	int strictexpire = ap->flags & MOUNT_FLAG_STRICTEXPIRE;
304803
 	time_t timeout = get_exp_timeout(ap, ap->entry->maps);
304803
 	unsigned logopt = ap->logopt;
304803
 	struct map_type_info *info;
304803
@@ -131,6 +132,8 @@ int mount_mount(struct autofs_point *ap,
304803
 				ghost = 1;
304803
 			else if (_strncmp("symlink", cp, 7) == 0)
304803
 				symlnk = 1;
304803
+			else if (_strncmp("strictexpire", cp, 12) == 0)
304803
+				strictexpire = 1;
304803
 			else if (_strncmp("hosts", cp, 5) == 0)
304803
 				hosts = 1;
304803
 			else if (_strncmp("timeout=", cp, 8) == 0) {
304803
@@ -173,6 +176,8 @@ int mount_mount(struct autofs_point *ap,
304803
 	nap->parent = ap;
304803
 	if (symlnk)
304803
 		nap->flags |= MOUNT_FLAG_SYMLINK;
304803
+	if (strictexpire)
304803
+		nap->flags |= MOUNT_FLAG_STRICTEXPIRE;
304803
 
304803
 	if (hosts)
304803
 		argc = 0;