Blob Blame History Raw
autofs-5.1.7 - don't add offset mounts to mounted mounts table

From: Ian Kent <raven@themaw.net>

Multi-mount offset mounts are added to the mounted mounts table whether
they have a real mount or not. If there are a large number of offsets
this can add unnecessary overhead to the mounted mounts table processing.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 CHANGELOG         |    1 +
 daemon/direct.c   |   14 ++++----------
 daemon/indirect.c |    4 +++-
 include/mounts.h  |    2 +-
 lib/mounts.c      |   43 +++++++++++--------------------------------
 5 files changed, 20 insertions(+), 44 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index cb709773..b144f6aa 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -22,6 +22,7 @@
 - remove unused mount offset list lock functions.
 - eliminate count_mounts() from expire_proc_indirect().
 - eliminate some strlen calls in offset handling.
+- don't add offset mounts to mounted mounts table.
 
 25/01/2021 autofs-5.1.7
 - make bind mounts propagation slave by default.
diff --git a/daemon/direct.c b/daemon/direct.c
index 311a98ba..fbfebbdd 100644
--- a/daemon/direct.c
+++ b/daemon/direct.c
@@ -605,9 +605,6 @@ force_umount:
 	} else
 		info(ap->logopt, "umounted offset mount %s", me->key);
 
-	if (!rv)
-		mnts_remove_mount(me->key, MNTS_OFFSET);
-
 	return rv;
 }
 
@@ -761,12 +758,6 @@ int mount_autofs_offset(struct autofs_point *ap, struct mapent *me)
 		notify_mount_result(ap, me->key, timeout, str_offset);
 	ops->close(ap->logopt, ioctlfd);
 
-	mnt = mnts_add_mount(ap, me->key, MNTS_OFFSET);
-	if (!mnt)
-		error(ap->logopt,
-		      "failed to add offset mount %s to mounted list",
-		      me->key);
-
 	debug(ap->logopt, "mounted trigger %s", me->key);
 
 	return MOUNT_OFFSET_OK;
@@ -1214,6 +1205,7 @@ static void *do_mount_direct(void *arg)
 		struct mapent *me;
 		struct statfs fs;
 		unsigned int close_fd = 0;
+		unsigned int flags = MNTS_DIRECT|MNTS_MOUNTED;
 
 		sbmnt = mnts_find_submount(mt.name);
 		if (statfs(mt.name, &fs) == -1 ||
@@ -1232,6 +1224,8 @@ static void *do_mount_direct(void *arg)
 				close_fd = 0;
 			if (!close_fd)
 				me->ioctlfd = mt.ioctlfd;
+			if (me->multi && me->multi != me)
+				flags |= MNTS_OFFSET;
 		}
 		ops->send_ready(ap->logopt, mt.ioctlfd, mt.wait_queue_token);
 		cache_unlock(mt.mc);
@@ -1240,7 +1234,7 @@ static void *do_mount_direct(void *arg)
 
 		info(ap->logopt, "mounted %s", mt.name);
 
-		mnts_set_mounted_mount(ap, mt.name);
+		mnts_set_mounted_mount(ap, mt.name, flags);
 
 		conditional_alarm_add(ap, ap->exp_runfreq);
 	} else {
diff --git a/daemon/indirect.c b/daemon/indirect.c
index b259ebdc..eddcfff7 100644
--- a/daemon/indirect.c
+++ b/daemon/indirect.c
@@ -747,12 +747,14 @@ static void *do_mount_indirect(void *arg)
 	status = lookup_nss_mount(ap, NULL, mt.name, mt.len);
 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &state);
 	if (status) {
+		unsigned int flags = MNTS_INDIRECT|MNTS_MOUNTED;
+
 		ops->send_ready(ap->logopt,
 				ap->ioctlfd, mt.wait_queue_token);
 
 		info(ap->logopt, "mounted %s", buf);
 
-		mnts_set_mounted_mount(ap, mt.name);
+		mnts_set_mounted_mount(ap, mt.name, flags);
 
 		conditional_alarm_add(ap, ap->exp_runfreq);
 	} else {
diff --git a/include/mounts.h b/include/mounts.h
index e3022b23..ac480c06 100644
--- a/include/mounts.h
+++ b/include/mounts.h
@@ -131,7 +131,7 @@ struct mnt_list *get_mnt_list(const char *path, int include);
 unsigned int mnts_has_mounted_mounts(struct autofs_point *ap);
 void mnts_get_expire_list(struct list_head *mnts, struct autofs_point *ap);
 void mnts_put_expire_list(struct list_head *mnts);
-void mnts_set_mounted_mount(struct autofs_point *ap, const char *name);
+void mnts_set_mounted_mount(struct autofs_point *ap, const char *name, unsigned int flags);
 int unlink_mount_tree(struct autofs_point *ap, const char *mp);
 void free_mnt_list(struct mnt_list *list);
 int is_mounted(const char *mp, unsigned int type);
diff --git a/lib/mounts.c b/lib/mounts.c
index 04fe3d00..25ae2e1d 100644
--- a/lib/mounts.c
+++ b/lib/mounts.c
@@ -1172,7 +1172,7 @@ struct mnt_list *mnts_add_mount(struct autofs_point *ap,
 	this = mnts_get_mount(mp);
 	if (this) {
 		this->flags |= flags;
-		if (list_empty(&this->mount))
+		if ((this->flags & MNTS_MOUNTED) && list_empty(&this->mount))
 			list_add(&this->mount, &ap->mounts);
 	}
 	mnts_hash_mutex_unlock();
@@ -1193,42 +1193,23 @@ void mnts_remove_mount(const char *mp, unsigned int flags)
 	this = mnts_lookup(mp);
 	if (this && this->flags & flags) {
 		this->flags &= ~flags;
-		if (!(this->flags & (MNTS_OFFSET|MNTS_MOUNTED)))
+		if (!(this->flags & MNTS_MOUNTED))
 			list_del_init(&this->mount);
 		__mnts_put_mount(this);
 	}
 	mnts_hash_mutex_unlock();
 }
 
-void mnts_set_mounted_mount(struct autofs_point *ap, const char *name)
+void mnts_set_mounted_mount(struct autofs_point *ap, const char *name, unsigned int flags)
 {
 	struct mnt_list *mnt;
 
-	mnt = mnts_add_mount(ap, name, MNTS_MOUNTED);
+	mnt = mnts_add_mount(ap, name, flags);
 	if (!mnt) {
 		error(ap->logopt,
 		      "failed to add mount %s to mounted list", name);
 		return;
 	}
-
-	/* Offset mount failed but non-strict returns success */
-	if (mnt->flags & MNTS_OFFSET &&
-	    !is_mounted(mnt->mp, MNTS_REAL)) {
-		mnt->flags &= ~MNTS_MOUNTED;
-		mnts_put_mount(mnt);
-	}
-
-	/* Housekeeping.
-	 * Set the base type of the mounted mount.
-	 * MNTS_AUTOFS and MNTS_OFFSET are set at mount time and
-	 * are used during expire.
-	 */
-	if (!(mnt->flags & (MNTS_AUTOFS|MNTS_OFFSET))) {
-		if (ap->type == LKP_INDIRECT)
-			mnt->flags |= MNTS_INDIRECT;
-		else
-			mnt->flags |= MNTS_DIRECT;
-	}
 }
 
 unsigned int mnts_has_mounted_mounts(struct autofs_point *ap)
@@ -1947,17 +1928,13 @@ static int do_remount_direct(struct autofs_point *ap,
 
 	ret = lookup_nss_mount(ap, NULL, path, strlen(path));
 	if (ret) {
-		struct mnt_list *mnt;
+		unsigned int flags = MNTS_DIRECT|MNTS_MOUNTED;
 
 		/* If it's an offset mount add a mount reference */
-		if (type == t_offset) {
-			mnt = mnts_add_mount(ap, path, MNTS_OFFSET);
-			if (!mnt)
-				error(ap->logopt,
-				      "failed to add mount %s to mounted list", path);
-		}
+		if (type == t_offset)
+			flags |= MNTS_OFFSET;
 
-		mnts_set_mounted_mount(ap, path);
+		mnts_set_mounted_mount(ap, path, flags);
 
 		info(ap->logopt, "re-connected to %s", path);
 
@@ -2032,7 +2009,9 @@ static int do_remount_indirect(struct autofs_point *ap, const unsigned int type,
 
 		ret = lookup_nss_mount(ap, NULL, de[n]->d_name, len);
 		if (ret) {
-			mnts_set_mounted_mount(ap, buf);
+			unsigned int flags = MNTS_INDIRECT|MNTS_MOUNTED;
+
+			mnts_set_mounted_mount(ap, buf, flags);
 
 			info(ap->logopt, "re-connected to %s", buf);