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

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