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

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