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

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