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

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