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

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