Blame SOURCES/autofs-5.1.2-use-autofs_point-to-store-expire-timeout-where-possibe.patch

4d476f
autofs-5.1.2 - use autofs_point to store expire timeout where possibe
4d476f
4d476f
From: Ian Kent <raven@themaw.net>
4d476f
4d476f
For technical reasons the expire timeout is stored in the map entry source
4d476f
rather than the struct autofs_point and must be stored in the map source for
4d476f
direct (and offset) mounts.
4d476f
4d476f
But with the map source re-use needed by amd format type "auto" mounts the
4d476f
timeout can't be stored in the map source since the it may be different for
4d476f
mounts that share the map source.
4d476f
4d476f
So use the struct autofs_point where possible.
4d476f
4d476f
Signed-off-by: Ian Kent <raven@themaw.net>
4d476f
---
4d476f
 CHANGELOG              |    1 +
4d476f
 daemon/direct.c        |    6 +++---
4d476f
 daemon/indirect.c      |    2 +-
4d476f
 daemon/state.c         |   12 +++++++-----
4d476f
 include/automount.h    |    1 +
4d476f
 include/mounts.h       |    2 ++
4d476f
 lib/master.c           |    5 ++++-
4d476f
 lib/master_parse.y     |   27 +++++++++++++--------------
4d476f
 lib/mounts.c           |   27 +++++++++++++++++++++------
4d476f
 modules/mount_autofs.c |   12 ++++--------
4d476f
 10 files changed, 57 insertions(+), 38 deletions(-)
4d476f
4d476f
--- autofs-5.0.7.orig/CHANGELOG
4d476f
+++ autofs-5.0.7/CHANGELOG
4d476f
@@ -242,6 +242,7 @@
4d476f
 - add config option to use mount request log id.
4d476f
 - work around sss startup delay.
4d476f
 - add sss master map wait config option.
4d476f
+- use autofs_point to store expire timeout where possibe.
4d476f
 
4d476f
 25/07/2012 autofs-5.0.7
4d476f
 =======================
4d476f
--- autofs-5.0.7.orig/daemon/direct.c
4d476f
+++ autofs-5.0.7/daemon/direct.c
4d476f
@@ -312,7 +312,7 @@ static int unlink_active_mounts(struct a
4d476f
 
4d476f
 	if (tree_get_mnt_list(mnts, &list, me->key, 1)) {
4d476f
 		if (ap->state == ST_READMAP) {
4d476f
-			time_t tout = me->source->exp_timeout;
4d476f
+			time_t tout = get_exp_timeout(ap, me->source);
4d476f
 			int save_ioctlfd, ioctlfd;
4d476f
 
4d476f
 			save_ioctlfd = ioctlfd = me->ioctlfd;
4d476f
@@ -518,7 +518,7 @@ int mount_autofs_direct(struct autofs_po
4d476f
 		}
4d476f
 
4d476f
 		mc = map->mc;
4d476f
-		timeout = map->exp_timeout;
4d476f
+		timeout = get_exp_timeout(ap, map);
4d476f
 		cache_readlock(mc);
4d476f
 		pthread_cleanup_push(cache_lock_cleanup, mc);
4d476f
 		me = cache_enumerate(mc, NULL);
4d476f
@@ -674,7 +674,7 @@ int mount_autofs_offset(struct autofs_po
4d476f
 	struct ioctl_ops *ops = get_ioctl_ops();
4d476f
 	char buf[MAX_ERR_BUF];
4d476f
 	struct mnt_params *mp;
4d476f
-	time_t timeout = me->source->exp_timeout;
4d476f
+	time_t timeout = get_exp_timeout(ap, me->source);
4d476f
 	struct stat st;
4d476f
 	int ioctlfd, status, ret;
4d476f
 	const char *hosts_map_name = "-hosts";
4d476f
--- autofs-5.0.7.orig/daemon/indirect.c
4d476f
+++ autofs-5.0.7/daemon/indirect.c
4d476f
@@ -87,7 +87,7 @@ static int do_mount_autofs_indirect(stru
4d476f
 {
4d476f
 	const char *str_indirect = mount_type_str(t_indirect);
4d476f
 	struct ioctl_ops *ops = get_ioctl_ops();
4d476f
-	time_t timeout = ap->entry->maps->exp_timeout;
4d476f
+	time_t timeout = get_exp_timeout(ap, ap->entry->maps);
4d476f
 	char *options = NULL;
4d476f
 	const char *hosts_map_name = "-hosts";
4d476f
 	const char *map_name = hosts_map_name;
4d476f
--- autofs-5.0.7.orig/daemon/state.c
4d476f
+++ autofs-5.0.7/daemon/state.c
4d476f
@@ -407,6 +407,7 @@ static void do_readmap_mount(struct auto
4d476f
 		if (valid) {
4d476f
 			struct mapent_cache *vmc = valid->mc;
4d476f
 			struct ioctl_ops *ops = get_ioctl_ops();
4d476f
+			time_t timeout;
4d476f
 			time_t runfreq;
4d476f
 
4d476f
 			cache_unlock(vmc);
4d476f
@@ -428,9 +429,10 @@ static void do_readmap_mount(struct auto
4d476f
 			cache_set_ino_index(vmc, me->key, me->dev, me->ino);
4d476f
 			cache_unlock(vmc);
4d476f
 			/* Set timeout and calculate the expire run frequency */
4d476f
-			ops->timeout(ap->logopt, valid->ioctlfd, map->exp_timeout);
4d476f
-			if (map->exp_timeout) {
4d476f
-				runfreq = (map->exp_timeout + CHECK_RATIO - 1) / CHECK_RATIO;
4d476f
+			timeout = get_exp_timeout(ap, map);
4d476f
+			ops->timeout(ap->logopt, valid->ioctlfd, timeout);
4d476f
+			if (timeout) {
4d476f
+				runfreq = (timeout + CHECK_RATIO - 1) / CHECK_RATIO;
4d476f
 				if (ap->exp_runfreq)
4d476f
 					ap->exp_runfreq = min(ap->exp_runfreq, runfreq);
4d476f
 				else
4d476f
@@ -442,7 +444,7 @@ static void do_readmap_mount(struct auto
4d476f
 			debug(ap->logopt,
4d476f
 			      "%s is mounted", me->key);
4d476f
 	} else
4d476f
-		do_mount_autofs_direct(ap, mnts, me, map->exp_timeout);
4d476f
+		do_mount_autofs_direct(ap, mnts, me, get_exp_timeout(ap, map));
4d476f
 
4d476f
 	return;
4d476f
 }
4d476f
@@ -491,7 +493,7 @@ static void *do_readmap(void *arg)
4d476f
 
4d476f
 	if (ap->type == LKP_INDIRECT) {
4d476f
 		struct ioctl_ops *ops = get_ioctl_ops();
4d476f
-		time_t timeout = ap->entry->maps->exp_timeout;
4d476f
+		time_t timeout = get_exp_timeout(ap, ap->entry->maps);
4d476f
 		ap->exp_runfreq = (timeout + CHECK_RATIO - 1) / CHECK_RATIO;
4d476f
 		ops->timeout(ap->logopt, ap->ioctlfd, timeout);
4d476f
 		lookup_prune_cache(ap, now);
4d476f
--- autofs-5.0.7.orig/include/automount.h
4d476f
+++ autofs-5.0.7/include/automount.h
4d476f
@@ -527,6 +527,7 @@ struct autofs_point {
4d476f
 	dev_t dev;			/* "Device" number assigned by kernel */
4d476f
 	struct master_mapent *entry;	/* Master map entry for this mount */
4d476f
 	unsigned int type;		/* Type of map direct or indirect */
4d476f
+	time_t exp_timeout;		/* Indirect mount expire timeout */
4d476f
 	time_t exp_runfreq;		/* Frequency for polling for timeouts */
4d476f
 	time_t negative_timeout;	/* timeout in secs for failed mounts */
4d476f
 	unsigned int flags;		/* autofs mount flags */
4d476f
--- autofs-5.0.7.orig/include/mounts.h
4d476f
+++ autofs-5.0.7/include/mounts.h
4d476f
@@ -112,6 +112,8 @@ int tree_find_mnt_ents(struct mnt_list *
4d476f
 int tree_is_mounted(struct mnt_list *mnts, const char *path, unsigned int type);
4d476f
 void set_tsd_user_vars(unsigned int, uid_t, gid_t);
4d476f
 const char *mount_type_str(unsigned int);
4d476f
+void set_exp_timeout(struct autofs_point *ap, struct map_source *source, time_t timeout);
4d476f
+time_t get_exp_timeout(struct autofs_point *ap, struct map_source *source);
4d476f
 void notify_mount_result(struct autofs_point *, const char *, time_t, const char *);
4d476f
 int try_remount(struct autofs_point *, struct mapent *, unsigned int);
4d476f
 void set_indirect_mount_tree_catatonic(struct autofs_point *);
4d476f
--- autofs-5.0.7.orig/lib/master.c
4d476f
+++ autofs-5.0.7/lib/master.c
4d476f
@@ -99,6 +99,7 @@ int master_add_autofs_point(struct maste
4d476f
 		ap->negative_timeout = defaults_get_negative_timeout();
4d476f
 	else
4d476f
 		ap->negative_timeout = global_negative_timeout;
4d476f
+	ap->exp_timeout = defaults_get_timeout();
4d476f
 	ap->exp_runfreq = 0;
4d476f
 	ap->flags = 0;
4d476f
 	if (ghost)
4d476f
@@ -980,6 +981,7 @@ static void master_add_amd_mount_section
4d476f
 	while (paths[i]) {
4d476f
 		const char *path = paths[i];
4d476f
 		unsigned int ghost = 0;
4d476f
+		time_t timeout;
4d476f
 		char *type = NULL;
4d476f
 		char *map = NULL;
4d476f
 		char *opts;
4d476f
@@ -1065,7 +1067,8 @@ static void master_add_amd_mount_section
4d476f
 			goto next;
4d476f
 		}
4d476f
 
4d476f
-		source->exp_timeout = conf_amd_get_dismount_interval(path);
4d476f
+		timeout = conf_amd_get_dismount_interval(path);
4d476f
+		set_exp_timeout(entry->ap, source, timeout);
4d476f
 		source->master_line = 0;
4d476f
 
4d476f
 		entry->age = age;
4d476f
--- autofs-5.0.7.orig/lib/master_parse.y
4d476f
+++ autofs-5.0.7/lib/master_parse.y
4d476f
@@ -823,19 +823,6 @@ int master_parse_entry(const char *buffe
4d476f
 			ghost = 1;
4d476f
 	}
4d476f
 
4d476f
-	if (timeout < 0) {
4d476f
-		/*
4d476f
-		 * If no timeout is given get the timout from the
4d476f
-		 * first map (if it exists) or the config for amd
4d476f
-		 * maps.
4d476f
-		 */
4d476f
-		if (format && !strcmp(format, "amd"))
4d476f
-			timeout = conf_amd_get_dismount_interval(path);
4d476f
-		else if (entry->maps)
4d476f
-			timeout = entry->maps->exp_timeout;
4d476f
-		else
4d476f
-			timeout = default_timeout;
4d476f
-	}
4d476f
 
4d476f
 	if (!entry->ap) {
4d476f
 		ret = master_add_autofs_point(entry, logopt, nobind, ghost, 0);
4d476f
@@ -856,6 +843,18 @@ int master_parse_entry(const char *buffe
4d476f
 	if (negative_timeout)
4d476f
 		entry->ap->negative_timeout = negative_timeout;
4d476f
 
4d476f
+	if (timeout < 0) {
4d476f
+		/*
4d476f
+		 * If no timeout is given get the timout from the
4d476f
+		 * autofs point, or the first map, or the config
4d476f
+		 * for amd maps.
4d476f
+		 */
4d476f
+		if (format && !strcmp(format, "amd"))
4d476f
+			timeout = conf_amd_get_dismount_interval(path);
4d476f
+		else
4d476f
+			timeout = get_exp_timeout(entry->ap, entry->maps);
4d476f
+	}
4d476f
+
4d476f
 	if (format && !strcmp(format, "amd")) {
4d476f
 		char *opts = conf_amd_get_map_options(path);
4d476f
 		if (opts) {
4d476f
@@ -890,7 +889,7 @@ int master_parse_entry(const char *buffe
4d476f
 		local_free_vars();
4d476f
 		return 0;
4d476f
 	}
4d476f
-	source->exp_timeout = timeout;
4d476f
+	set_exp_timeout(entry->ap, source, timeout);
4d476f
 	source->master_line = lineno;
4d476f
 
4d476f
 	entry->age = age;
4d476f
--- autofs-5.0.7.orig/lib/mounts.c
4d476f
+++ autofs-5.0.7/lib/mounts.c
4d476f
@@ -1616,6 +1616,24 @@ const char *mount_type_str(const unsigne
4d476f
 	return (pos == type_count ? NULL : str_type[pos]);
4d476f
 }
4d476f
 
4d476f
+void set_exp_timeout(struct autofs_point *ap,
4d476f
+		     struct map_source *source, time_t timeout)
4d476f
+{
4d476f
+	ap->exp_timeout = timeout;
4d476f
+	if (source)
4d476f
+		source->exp_timeout = timeout;
4d476f
+}
4d476f
+
4d476f
+time_t get_exp_timeout(struct autofs_point *ap, struct map_source *source)
4d476f
+{
4d476f
+	time_t timeout = ap->exp_timeout;
4d476f
+
4d476f
+	if (source && ap->type == LKP_DIRECT)
4d476f
+		timeout = source->exp_timeout;
4d476f
+
4d476f
+	return timeout;
4d476f
+}
4d476f
+
4d476f
 void notify_mount_result(struct autofs_point *ap,
4d476f
 			 const char *path, time_t timeout, const char *type)
4d476f
 {
4d476f
@@ -1747,12 +1765,9 @@ static int remount_active_mount(struct a
4d476f
 	ops->open(ap->logopt, &fd, devid, path);
4d476f
 	if (fd == -1)
4d476f
 		return REMOUNT_OPEN_FAIL;
4d476f
-	else {
4d476f
-		if (type == t_indirect || type == t_offset)
4d476f
-			timeout = ap->entry->maps->exp_timeout;
4d476f
-		else
4d476f
-			timeout = me->source->exp_timeout;
4d476f
-	}
4d476f
+
4d476f
+	error(ap->logopt, "ap->type %d type %u", ap->type, type);
4d476f
+	timeout = get_exp_timeout(ap, me->source);
4d476f
 
4d476f
 	/* Re-reading the map, set timeout and return */
4d476f
 	if (ap->state == ST_READMAP) {
4d476f
--- autofs-5.0.7.orig/modules/mount_autofs.c
4d476f
+++ autofs-5.0.7/modules/mount_autofs.c
4d476f
@@ -57,7 +57,7 @@ int mount_mount(struct autofs_point *ap,
4d476f
 	int nobind = ap->flags & MOUNT_FLAG_NOBIND;
4d476f
 	int ghost = ap->flags & MOUNT_FLAG_GHOST;
4d476f
 	int symlnk = ap->flags & MOUNT_FLAG_SYMLINK;
4d476f
-	time_t timeout = ap->entry->maps->exp_timeout;
4d476f
+	time_t timeout = get_exp_timeout(ap, ap->entry->maps);
4d476f
 	unsigned logopt = ap->logopt;
4d476f
 	struct map_type_info *info;
4d476f
 	struct master *master;
4d476f
@@ -272,13 +272,9 @@ int mount_mount(struct autofs_point *ap,
4d476f
 		return 1;
4d476f
 	}
4d476f
 	free_map_type_info(info);
4d476f
-	/* The exp_timeout can't be inherited if the map is shared, so
4d476f
-	 * the autofs point exp_runfreq must be set here.
4d476f
-	 */
4d476f
-	if (source->ref <= 1)
4d476f
-		source->exp_timeout = timeout;
4d476f
-	else
4d476f
-		nap->exp_runfreq = (timeout + CHECK_RATIO - 1) / CHECK_RATIO;
4d476f
+
4d476f
+	set_exp_timeout(nap, NULL, timeout);
4d476f
+	nap->exp_runfreq = (timeout + CHECK_RATIO - 1) / CHECK_RATIO;
4d476f
 
4d476f
 	mounts_mutex_lock(ap);
4d476f