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

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