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

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