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

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