Blame SOURCES/autofs-5.1.7-eliminate-count_mounts-from-expire_proc_indirect.patch

96dc52
autofs-5.1.7 - eliminate count_mounts() from expire_proc_indirect()
96dc52
96dc52
From: Ian Kent <raven@themaw.net>
96dc52
96dc52
The count_mounts() function traverses the directory tree under a given
96dc52
automount in order to count the number of mounts.
96dc52
96dc52
If there are many directories (such as when there is a very large
96dc52
number of offset trigger mounts) this can take a long time.
96dc52
96dc52
Eliminate the call in expire_proc_indirect() by changing the expire
96dc52
ioctl function to better use the expire return from the kernel.
96dc52
96dc52
Signed-off-by: Ian Kent <raven@themaw.net>
96dc52
---
96dc52
 CHANGELOG           |    1 +
96dc52
 daemon/direct.c     |    4 ++--
96dc52
 daemon/indirect.c   |   10 +++++-----
96dc52
 lib/dev-ioctl-lib.c |   21 +++++++++++++--------
96dc52
 4 files changed, 21 insertions(+), 15 deletions(-)
96dc52
96dc52
diff --git a/CHANGELOG b/CHANGELOG
96dc52
index c5619d2e..0b78eb62 100644
96dc52
--- a/CHANGELOG
96dc52
+++ b/CHANGELOG
96dc52
@@ -20,6 +20,7 @@
96dc52
 - pass mapent_cache to update_offset_entry().
96dc52
 - fix inconsistent locking in parse_mount().
96dc52
 - remove unused mount offset list lock functions.
96dc52
+- eliminate count_mounts() from expire_proc_indirect().
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 c41c680f..311a98ba 100644
96dc52
--- a/daemon/direct.c
96dc52
+++ b/daemon/direct.c
96dc52
@@ -884,7 +884,7 @@ cont:
96dc52
 			ioctlfd = me->ioctlfd;
96dc52
 
96dc52
 			ret = ops->expire(ap->logopt, ioctlfd, mnt->mp, how);
96dc52
-			if (ret) {
96dc52
+			if (ret == 1) {
96dc52
 				left++;
96dc52
 				pthread_setcancelstate(cur_state, NULL);
96dc52
 				continue;
96dc52
@@ -910,7 +910,7 @@ cont:
96dc52
 
96dc52
 		pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
96dc52
 		ret = ops->expire(ap->logopt, ioctlfd, mnt->mp, how);
96dc52
-		if (ret)
96dc52
+		if (ret == 1)
96dc52
 			left++;
96dc52
 		pthread_setcancelstate(cur_state, NULL);
96dc52
 	}
96dc52
diff --git a/daemon/indirect.c b/daemon/indirect.c
96dc52
index 65cfe4e3..b259ebdc 100644
96dc52
--- a/daemon/indirect.c
96dc52
+++ b/daemon/indirect.c
96dc52
@@ -358,7 +358,6 @@ void *expire_proc_indirect(void *arg)
96dc52
 	struct expire_args ec;
96dc52
 	unsigned int how;
96dc52
 	int offsets, submnts, count;
96dc52
-	int retries;
96dc52
 	int ioctlfd, cur_state;
96dc52
 	int status, ret, left;
96dc52
 
96dc52
@@ -496,7 +495,7 @@ void *expire_proc_indirect(void *arg)
96dc52
 
96dc52
 		pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
96dc52
 		ret = ops->expire(ap->logopt, ioctlfd, mnt->mp, how);
96dc52
-		if (ret)
96dc52
+		if (ret == 1)
96dc52
 			left++;
96dc52
 		pthread_setcancelstate(cur_state, NULL);
96dc52
 	}
96dc52
@@ -507,10 +506,11 @@ void *expire_proc_indirect(void *arg)
96dc52
 	 * so we need to umount or unlink them here.
96dc52
 	 */
96dc52
 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
96dc52
-	retries = (count_mounts(ap, ap->path, ap->dev) + 1);
96dc52
-	while (retries--) {
96dc52
+	while (1) {
96dc52
 		ret = ops->expire(ap->logopt, ap->ioctlfd, ap->path, how);
96dc52
-		if (ret)
96dc52
+		if (ret != 0 && errno == EAGAIN)
96dc52
+			break;
96dc52
+		if (ret == 1)
96dc52
 			left++;
96dc52
 	}
96dc52
 	pthread_setcancelstate(cur_state, NULL);
96dc52
diff --git a/lib/dev-ioctl-lib.c b/lib/dev-ioctl-lib.c
96dc52
index 7040c3da..e7a1b42a 100644
96dc52
--- a/lib/dev-ioctl-lib.c
96dc52
+++ b/lib/dev-ioctl-lib.c
96dc52
@@ -650,6 +650,7 @@ static int expire(unsigned int logopt,
96dc52
 {
96dc52
 	int ret, retries = EXPIRE_RETRIES;
96dc52
 	unsigned int may_umount;
96dc52
+	int save_errno = 0;
96dc52
 
96dc52
 	while (retries--) {
96dc52
 		struct timespec tm = {0, 100000000};
96dc52
@@ -657,9 +658,11 @@ static int expire(unsigned int logopt,
96dc52
 		/* Ggenerate expire message for the mount. */
96dc52
 		ret = ioctl(fd, cmd, arg);
96dc52
 		if (ret == -1) {
96dc52
+			save_errno = errno;
96dc52
+
96dc52
 			/* Mount has gone away */
96dc52
 			if (errno == EBADF || errno == EINVAL)
96dc52
-				return 0;
96dc52
+				break;
96dc52
 
96dc52
 			/*
96dc52
 			 * Other than EAGAIN is an expire error so continue.
96dc52
@@ -673,14 +676,16 @@ static int expire(unsigned int logopt,
96dc52
 		nanosleep(&tm, NULL);
96dc52
 	}
96dc52
 
96dc52
-	may_umount = 0;
96dc52
-	if (ctl.ops->askumount(logopt, ioctlfd, &may_umount))
96dc52
-		return -1;
96dc52
-
96dc52
-	if (!may_umount)
96dc52
-		return 1;
96dc52
+	if (!ret || save_errno == EAGAIN) {
96dc52
+		may_umount = 0;
96dc52
+		if (!ctl.ops->askumount(logopt, ioctlfd, &may_umount)) {
96dc52
+			if (!may_umount)
96dc52
+				ret = 1;
96dc52
+		}
96dc52
+	}
96dc52
+	errno = save_errno;
96dc52
 
96dc52
-	return 0;
96dc52
+	return ret;
96dc52
 }
96dc52
 
96dc52
 static int dev_ioctl_expire(unsigned int logopt,