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

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