Blame SOURCES/autofs-5.1.7-simplify-get_parent.patch

29d2b9
autofs-5.1.7 - simplify cache_get_parent()
29d2b9
29d2b9
From: Ian Kent <raven@themaw.net>
29d2b9
29d2b9
Eliminate the list traversal from get_parent() and rename it to
29d2b9
get_offset_parent() to better describe it's usage.
29d2b9
29d2b9
Signed-off-by: Ian Kent <raven@themaw.net>
29d2b9
---
29d2b9
 CHANGELOG   |    1 +
29d2b9
 lib/cache.c |   46 ++++++++++++++++++++++++++++------------------
29d2b9
 2 files changed, 29 insertions(+), 18 deletions(-)
29d2b9
29d2b9
diff --git a/CHANGELOG b/CHANGELOG
29d2b9
index e55fd66a..ee746277 100644
29d2b9
--- a/CHANGELOG
29d2b9
+++ b/CHANGELOG
29d2b9
@@ -7,6 +7,7 @@
29d2b9
 - Fix option for master read wait.
29d2b9
 - eliminate cache_lookup_offset() usage.
29d2b9
 - fix is mounted check on non existent path.
29d2b9
+- simplify cache_get_parent().
29d2b9
 
29d2b9
 25/01/2021 autofs-5.1.7
29d2b9
 - make bind mounts propagation slave by default.
29d2b9
diff --git a/lib/cache.c b/lib/cache.c
29d2b9
index d3b6642b..53f290cd 100644
29d2b9
--- a/lib/cache.c
29d2b9
+++ b/lib/cache.c
29d2b9
@@ -827,47 +827,57 @@ void cache_update_negative(struct mapent_cache *mc,
29d2b9
 }
29d2b9
 
29d2b9
 
29d2b9
-static struct mapent *get_parent(const char *key, struct list_head *head, struct list_head **pos)
29d2b9
+static struct mapent *get_offset_parent(struct mapent_cache *mc,
29d2b9
+					const char *key)
29d2b9
 {
29d2b9
-	struct list_head *next;
29d2b9
-	struct mapent *this, *last;
29d2b9
-	int eq;
29d2b9
+	struct mapent *me;
29d2b9
+	char *parent, *tail;
29d2b9
+	int key_len;
29d2b9
 
29d2b9
-	last = NULL;
29d2b9
-	next = *pos ? (*pos)->next : head->next;
29d2b9
+	key_len = strlen(key);
29d2b9
 
29d2b9
-	list_for_each(next, head) {
29d2b9
-		this = list_entry(next, struct mapent, multi_list);
29d2b9
+	/* Check if this is the root offset */
29d2b9
+	if (key[key_len - 1] == '/')
29d2b9
+		return NULL;
29d2b9
+
29d2b9
+	parent = strdup(key);
29d2b9
+	tail = &parent[key_len - 1];
29d2b9
 
29d2b9
-		if (!strcmp(this->key, key))
29d2b9
+	while (*tail) {
29d2b9
+		while (*tail != '/')
29d2b9
+			tail--;
29d2b9
+
29d2b9
+		*tail = 0;
29d2b9
+
29d2b9
+		tail--;
29d2b9
+		if (tail == parent)
29d2b9
 			break;
29d2b9
 
29d2b9
-		eq = strncmp(this->key, key, strlen(this->key));
29d2b9
-		if (eq == 0) {
29d2b9
-			*pos = next;
29d2b9
-			last = this;
29d2b9
-			continue;
29d2b9
+		me = cache_lookup_distinct(mc, parent);
29d2b9
+		if (me) {
29d2b9
+			free(parent);
29d2b9
+			return me;
29d2b9
 		}
29d2b9
 	}
29d2b9
+	free(parent);
29d2b9
 
29d2b9
-	return last;
29d2b9
+	return NULL;
29d2b9
 }
29d2b9
 
29d2b9
 int cache_set_parents(struct mapent *mm)
29d2b9
 {
29d2b9
-	struct list_head *multi_head, *p, *pos;
29d2b9
+	struct list_head *multi_head, *p;
29d2b9
 	struct mapent *this;
29d2b9
 
29d2b9
 	if (!mm->multi)
29d2b9
 		return 0;
29d2b9
 
29d2b9
-	pos = NULL;
29d2b9
 	multi_head = &mm->multi->multi_list;
29d2b9
 
29d2b9
 	list_for_each(p, multi_head) {
29d2b9
 		struct mapent *parent;
29d2b9
 		this = list_entry(p, struct mapent, multi_list);
29d2b9
-		parent = get_parent(this->key, multi_head, &pos;;
29d2b9
+		parent = get_offset_parent(mm->mc, this->key);
29d2b9
 		if (parent)
29d2b9
 			this->parent = parent;
29d2b9
 		else