Blame SOURCES/autofs-5.1.7-eliminate-some-strlen-calls-in-offset-handling.patch

29d2b9
autofs-5.1.7 - eliminate some strlen calls in offset handling
29d2b9
29d2b9
From: Ian Kent <raven@themaw.net>
29d2b9
29d2b9
There are a number of places where strlen() is used to re-calculate
29d2b9
the length of a string. Eliminate some of those by calculating the
29d2b9
length once and passing it to the functions that do the re-calculation.
29d2b9
29d2b9
Signed-off-by: Ian Kent <raven@themaw.net>
29d2b9
---
29d2b9
 CHANGELOG    |    1 +
29d2b9
 lib/mounts.c |   30 +++++++++++++++++-------------
29d2b9
 2 files changed, 18 insertions(+), 13 deletions(-)
29d2b9
29d2b9
diff --git a/CHANGELOG b/CHANGELOG
29d2b9
index 0b78eb62..cb709773 100644
29d2b9
--- a/CHANGELOG
29d2b9
+++ b/CHANGELOG
29d2b9
@@ -21,6 +21,7 @@
29d2b9
 - fix inconsistent locking in parse_mount().
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
 
29d2b9
 25/01/2021 autofs-5.1.7
29d2b9
 - make bind mounts propagation slave by default.
29d2b9
diff --git a/lib/mounts.c b/lib/mounts.c
29d2b9
index 0fcd4087..04fe3d00 100644
29d2b9
--- a/lib/mounts.c
29d2b9
+++ b/lib/mounts.c
29d2b9
@@ -2540,10 +2540,12 @@ static int rmdir_path_offset(struct autofs_point *ap, struct mapent *oe)
29d2b9
 	return ret;
29d2b9
 }
29d2b9
 
29d2b9
-static int do_umount_offset(struct autofs_point *ap, struct mapent *oe, const char *root);
29d2b9
+static int do_umount_offset(struct autofs_point *ap,
29d2b9
+			    struct mapent *oe, const char *root, int start);
29d2b9
 
29d2b9
 static int do_umount_multi_triggers(struct autofs_point *ap,
29d2b9
-				    struct mapent *me, const char *root, const char *base)
29d2b9
+				    struct mapent *me, const char *root,
29d2b9
+				    int start, const char *base)
29d2b9
 {
29d2b9
 	char path[PATH_MAX + 1];
29d2b9
 	char *offset;
29d2b9
@@ -2551,12 +2553,11 @@ static int do_umount_multi_triggers(struct autofs_point *ap,
29d2b9
 	struct list_head *mm_root, *pos;
29d2b9
 	const char o_root[] = "/";
29d2b9
 	const char *mm_base;
29d2b9
-	int left, start;
29d2b9
+	int left;
29d2b9
 	unsigned int root_len;
29d2b9
 	unsigned int mm_base_len;
29d2b9
 
29d2b9
 	left = 0;
29d2b9
-	start = strlen(root);
29d2b9
 
29d2b9
 	mm_root = &me->multi->multi_list;
29d2b9
 
29d2b9
@@ -2592,13 +2593,14 @@ static int do_umount_multi_triggers(struct autofs_point *ap,
29d2b9
 		if (!oe || (strlen(oe->key) - start) == 1)
29d2b9
 			continue;
29d2b9
 
29d2b9
-		left += do_umount_offset(ap, oe, root);
29d2b9
+		left += do_umount_offset(ap, oe, root, start);
29d2b9
 	}
29d2b9
 
29d2b9
 	return left;
29d2b9
 }
29d2b9
 
29d2b9
-static int do_umount_offset(struct autofs_point *ap, struct mapent *oe, const char *root)
29d2b9
+static int do_umount_offset(struct autofs_point *ap,
29d2b9
+			    struct mapent *oe, const char *root, int start)
29d2b9
 {
29d2b9
 	char *oe_base;
29d2b9
 	int left = 0;
29d2b9
@@ -2607,8 +2609,8 @@ static int do_umount_offset(struct autofs_point *ap, struct mapent *oe, const ch
29d2b9
 	 * Check for and umount subtree offsets resulting from
29d2b9
 	 * nonstrict mount fail.
29d2b9
 	 */
29d2b9
-	oe_base = oe->key + strlen(root);
29d2b9
-	left += do_umount_multi_triggers(ap, oe, root, oe_base);
29d2b9
+	oe_base = oe->key + start;
29d2b9
+	left += do_umount_multi_triggers(ap, oe, root, start, oe_base);
29d2b9
 
29d2b9
 	/*
29d2b9
 	 * If an offset that has an active mount has been removed
29d2b9
@@ -2712,7 +2714,7 @@ int mount_multi_triggers(struct autofs_point *ap, struct mapent *me,
29d2b9
 			goto cont;
29d2b9
 		if (oe->age != me->multi->age) {
29d2b9
 			/* Best effort */
29d2b9
-			do_umount_offset(ap, oe, root);
29d2b9
+			do_umount_offset(ap, oe, root, start);
29d2b9
 			goto cont;
29d2b9
 		}
29d2b9
 
29d2b9
@@ -2726,7 +2728,7 @@ int mount_multi_triggers(struct autofs_point *ap, struct mapent *me,
29d2b9
 		if (ap->state == ST_READMAP && ap->flags & MOUNT_FLAG_REMOUNT) {
29d2b9
 			if (oe->ioctlfd != -1 ||
29d2b9
 			    is_mounted(oe->key, MNTS_REAL))
29d2b9
-				mount_multi_triggers(ap, oe, key, strlen(key), base);
29d2b9
+				mount_multi_triggers(ap, oe, key, key_len, base);
29d2b9
 		}
29d2b9
 cont:
29d2b9
 		offset = cache_get_offset(base,
29d2b9
@@ -2738,9 +2740,11 @@ cont:
29d2b9
 
29d2b9
 int umount_multi_triggers(struct autofs_point *ap, struct mapent *me, char *root, const char *base)
29d2b9
 {
29d2b9
-	int left;
29d2b9
+	int left, start;
29d2b9
+
29d2b9
+	start = strlen(root);
29d2b9
 
29d2b9
-	left = do_umount_multi_triggers(ap, me, root, base);
29d2b9
+	left = do_umount_multi_triggers(ap, me, root, start, base);
29d2b9
 
29d2b9
 	if (!left && me->multi == me) {
29d2b9
 		/*
29d2b9
@@ -2753,7 +2757,7 @@ int umount_multi_triggers(struct autofs_point *ap, struct mapent *me, char *root
29d2b9
 			info(ap->logopt, "unmounting dir = %s", root);
29d2b9
 			if (umount_ent(ap, root) &&
29d2b9
 			    is_mounted(root, MNTS_REAL)) {
29d2b9
-				if (mount_multi_triggers(ap, me, root, strlen(root), "/") < 0)
29d2b9
+				if (mount_multi_triggers(ap, me, root, start, "/") < 0)
29d2b9
 					warn(ap->logopt,
29d2b9
 					     "failed to remount offset triggers");
29d2b9
 				return ++left;