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

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