Blame SOURCES/autofs-5.1.7-dont-add-offset-mounts-to-mounted-mounts-table.patch

49b67f
autofs-5.1.7 - don't add offset mounts to mounted mounts table
49b67f
49b67f
From: Ian Kent <raven@themaw.net>
49b67f
49b67f
Multi-mount offset mounts are added to the mounted mounts table whether
49b67f
they have a real mount or not. If there are a large number of offsets
49b67f
this can add unnecessary overhead to the mounted mounts table processing.
49b67f
49b67f
Signed-off-by: Ian Kent <raven@themaw.net>
49b67f
---
49b67f
 CHANGELOG         |    1 +
49b67f
 daemon/direct.c   |   14 ++++----------
49b67f
 daemon/indirect.c |    4 +++-
49b67f
 include/mounts.h  |    2 +-
49b67f
 lib/mounts.c      |   43 +++++++++++--------------------------------
49b67f
 5 files changed, 20 insertions(+), 44 deletions(-)
49b67f
49b67f
--- autofs-5.1.4.orig/CHANGELOG
49b67f
+++ autofs-5.1.4/CHANGELOG
49b67f
@@ -21,6 +21,7 @@
49b67f
 - remove unused mount offset list lock functions.
49b67f
 - eliminate count_mounts() from expire_proc_indirect().
49b67f
 - eliminate some strlen calls in offset handling.
49b67f
+- don't add offset mounts to mounted mounts table.
49b67f
 
49b67f
 xx/xx/2018 autofs-5.1.5
49b67f
 - fix flag file permission.
49b67f
--- autofs-5.1.4.orig/daemon/direct.c
49b67f
+++ autofs-5.1.4/daemon/direct.c
49b67f
@@ -605,9 +605,6 @@ force_umount:
49b67f
 	} else
49b67f
 		info(ap->logopt, "umounted offset mount %s", me->key);
49b67f
 
49b67f
-	if (!rv)
49b67f
-		mnts_remove_mount(me->key, MNTS_OFFSET);
49b67f
-
49b67f
 	return rv;
49b67f
 }
49b67f
 
49b67f
@@ -761,12 +758,6 @@ int mount_autofs_offset(struct autofs_po
49b67f
 		notify_mount_result(ap, me->key, timeout, str_offset);
49b67f
 	ops->close(ap->logopt, ioctlfd);
49b67f
 
49b67f
-	mnt = mnts_add_mount(ap, me->key, MNTS_OFFSET);
49b67f
-	if (!mnt)
49b67f
-		error(ap->logopt,
49b67f
-		      "failed to add offset mount %s to mounted list",
49b67f
-		      me->key);
49b67f
-
49b67f
 	debug(ap->logopt, "mounted trigger %s", me->key);
49b67f
 
49b67f
 	return MOUNT_OFFSET_OK;
49b67f
@@ -1214,6 +1205,7 @@ static void *do_mount_direct(void *arg)
49b67f
 		struct mapent *me;
49b67f
 		struct statfs fs;
49b67f
 		unsigned int close_fd = 0;
49b67f
+		unsigned int flags = MNTS_DIRECT|MNTS_MOUNTED;
49b67f
 
49b67f
 		sbmnt = mnts_find_submount(mt.name);
49b67f
 		if (statfs(mt.name, &fs) == -1 ||
49b67f
@@ -1232,6 +1224,8 @@ static void *do_mount_direct(void *arg)
49b67f
 				close_fd = 0;
49b67f
 			if (!close_fd)
49b67f
 				me->ioctlfd = mt.ioctlfd;
49b67f
+			if (me->multi && me->multi != me)
49b67f
+				flags |= MNTS_OFFSET;
49b67f
 		}
49b67f
 		ops->send_ready(ap->logopt, mt.ioctlfd, mt.wait_queue_token);
49b67f
 		cache_unlock(mt.mc);
49b67f
@@ -1240,7 +1234,7 @@ static void *do_mount_direct(void *arg)
49b67f
 
49b67f
 		info(ap->logopt, "mounted %s", mt.name);
49b67f
 
49b67f
-		mnts_set_mounted_mount(ap, mt.name);
49b67f
+		mnts_set_mounted_mount(ap, mt.name, flags);
49b67f
 
49b67f
 		conditional_alarm_add(ap, ap->exp_runfreq);
49b67f
 	} else {
49b67f
--- autofs-5.1.4.orig/daemon/indirect.c
49b67f
+++ autofs-5.1.4/daemon/indirect.c
49b67f
@@ -747,12 +747,14 @@ static void *do_mount_indirect(void *arg
49b67f
 	status = lookup_nss_mount(ap, NULL, mt.name, mt.len);
49b67f
 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &state);
49b67f
 	if (status) {
49b67f
+		unsigned int flags = MNTS_INDIRECT|MNTS_MOUNTED;
49b67f
+
49b67f
 		ops->send_ready(ap->logopt,
49b67f
 				ap->ioctlfd, mt.wait_queue_token);
49b67f
 
49b67f
 		info(ap->logopt, "mounted %s", buf);
49b67f
 
49b67f
-		mnts_set_mounted_mount(ap, mt.name);
49b67f
+		mnts_set_mounted_mount(ap, mt.name, flags);
49b67f
 
49b67f
 		conditional_alarm_add(ap, ap->exp_runfreq);
49b67f
 	} else {
49b67f
--- autofs-5.1.4.orig/include/mounts.h
49b67f
+++ autofs-5.1.4/include/mounts.h
49b67f
@@ -131,7 +131,7 @@ struct mnt_list *get_mnt_list(const char
49b67f
 unsigned int mnts_has_mounted_mounts(struct autofs_point *ap);
49b67f
 void mnts_get_expire_list(struct list_head *mnts, struct autofs_point *ap);
49b67f
 void mnts_put_expire_list(struct list_head *mnts);
49b67f
-void mnts_set_mounted_mount(struct autofs_point *ap, const char *name);
49b67f
+void mnts_set_mounted_mount(struct autofs_point *ap, const char *name, unsigned int flags);
49b67f
 int unlink_mount_tree(struct autofs_point *ap, const char *mp);
49b67f
 void free_mnt_list(struct mnt_list *list);
49b67f
 int is_mounted(const char *mp, unsigned int type);
49b67f
--- autofs-5.1.4.orig/lib/mounts.c
49b67f
+++ autofs-5.1.4/lib/mounts.c
49b67f
@@ -1172,7 +1172,7 @@ struct mnt_list *mnts_add_mount(struct a
49b67f
 	this = mnts_get_mount(mp);
49b67f
 	if (this) {
49b67f
 		this->flags |= flags;
49b67f
-		if (list_empty(&this->mount))
49b67f
+		if ((this->flags & MNTS_MOUNTED) && list_empty(&this->mount))
49b67f
 			list_add(&this->mount, &ap->mounts);
49b67f
 	}
49b67f
 	mnts_hash_mutex_unlock();
49b67f
@@ -1193,42 +1193,23 @@ void mnts_remove_mount(const char *mp, u
49b67f
 	this = mnts_lookup(mp);
49b67f
 	if (this && this->flags & flags) {
49b67f
 		this->flags &= ~flags;
49b67f
-		if (!(this->flags & (MNTS_OFFSET|MNTS_MOUNTED)))
49b67f
+		if (!(this->flags & MNTS_MOUNTED))
49b67f
 			list_del_init(&this->mount);
49b67f
 		__mnts_put_mount(this);
49b67f
 	}
49b67f
 	mnts_hash_mutex_unlock();
49b67f
 }
49b67f
 
49b67f
-void mnts_set_mounted_mount(struct autofs_point *ap, const char *name)
49b67f
+void mnts_set_mounted_mount(struct autofs_point *ap, const char *name, unsigned int flags)
49b67f
 {
49b67f
 	struct mnt_list *mnt;
49b67f
 
49b67f
-	mnt = mnts_add_mount(ap, name, MNTS_MOUNTED);
49b67f
+	mnt = mnts_add_mount(ap, name, flags);
49b67f
 	if (!mnt) {
49b67f
 		error(ap->logopt,
49b67f
 		      "failed to add mount %s to mounted list", name);
49b67f
 		return;
49b67f
 	}
49b67f
-
49b67f
-	/* Offset mount failed but non-strict returns success */
49b67f
-	if (mnt->flags & MNTS_OFFSET &&
49b67f
-	    !is_mounted(mnt->mp, MNTS_REAL)) {
49b67f
-		mnt->flags &= ~MNTS_MOUNTED;
49b67f
-		mnts_put_mount(mnt);
49b67f
-	}
49b67f
-
49b67f
-	/* Housekeeping.
49b67f
-	 * Set the base type of the mounted mount.
49b67f
-	 * MNTS_AUTOFS and MNTS_OFFSET are set at mount time and
49b67f
-	 * are used during expire.
49b67f
-	 */
49b67f
-	if (!(mnt->flags & (MNTS_AUTOFS|MNTS_OFFSET))) {
49b67f
-		if (ap->type == LKP_INDIRECT)
49b67f
-			mnt->flags |= MNTS_INDIRECT;
49b67f
-		else
49b67f
-			mnt->flags |= MNTS_DIRECT;
49b67f
-	}
49b67f
 }
49b67f
 
49b67f
 unsigned int mnts_has_mounted_mounts(struct autofs_point *ap)
49b67f
@@ -1943,17 +1924,13 @@ static int do_remount_direct(struct auto
49b67f
 
49b67f
 	ret = lookup_nss_mount(ap, NULL, path, strlen(path));
49b67f
 	if (ret) {
49b67f
-		struct mnt_list *mnt;
49b67f
+		unsigned int flags = MNTS_DIRECT|MNTS_MOUNTED;
49b67f
 
49b67f
 		/* If it's an offset mount add a mount reference */
49b67f
-		if (type == t_offset) {
49b67f
-			mnt = mnts_add_mount(ap, path, MNTS_OFFSET);
49b67f
-			if (!mnt)
49b67f
-				error(ap->logopt,
49b67f
-				      "failed to add mount %s to mounted list", path);
49b67f
-		}
49b67f
+		if (type == t_offset)
49b67f
+			flags |= MNTS_OFFSET;
49b67f
 
49b67f
-		mnts_set_mounted_mount(ap, path);
49b67f
+		mnts_set_mounted_mount(ap, path, flags);
49b67f
 
49b67f
 		info(ap->logopt, "re-connected to %s", path);
49b67f
 
49b67f
@@ -2028,7 +2005,9 @@ static int do_remount_indirect(struct au
49b67f
 
49b67f
 		ret = lookup_nss_mount(ap, NULL, de[n]->d_name, len);
49b67f
 		if (ret) {
49b67f
-			mnts_set_mounted_mount(ap, buf);
49b67f
+			unsigned int flags = MNTS_INDIRECT|MNTS_MOUNTED;
49b67f
+
49b67f
+			mnts_set_mounted_mount(ap, buf, flags);
49b67f
 
49b67f
 			info(ap->logopt, "re-connected to %s", buf);
49b67f