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

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