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

49b67f
autofs-5.1.7 - simplify cache_get_parent()
49b67f
49b67f
From: Ian Kent <raven@themaw.net>
49b67f
49b67f
Eliminate the list traversal from get_parent() and rename it to
49b67f
get_offset_parent() to better describe it's usage.
49b67f
49b67f
Signed-off-by: Ian Kent <raven@themaw.net>
49b67f
---
49b67f
 CHANGELOG   |    1 +
49b67f
 lib/cache.c |   46 ++++++++++++++++++++++++++++------------------
49b67f
 2 files changed, 29 insertions(+), 18 deletions(-)
49b67f
49b67f
--- autofs-5.1.4.orig/CHANGELOG
49b67f
+++ autofs-5.1.4/CHANGELOG
49b67f
@@ -6,6 +6,7 @@
49b67f
 - fix mnts_remove_amdmount() uses wrong list.
49b67f
 - eliminate cache_lookup_offset() usage.
49b67f
 - fix is mounted check on non existent path.
49b67f
+- simplify cache_get_parent().
49b67f
 
49b67f
 xx/xx/2018 autofs-5.1.5
49b67f
 - fix flag file permission.
49b67f
--- autofs-5.1.4.orig/lib/cache.c
49b67f
+++ autofs-5.1.4/lib/cache.c
49b67f
@@ -797,47 +797,57 @@ void cache_update_negative(struct mapent
49b67f
 }
49b67f
 
49b67f
 
49b67f
-static struct mapent *get_parent(const char *key, struct list_head *head, struct list_head **pos)
49b67f
+static struct mapent *get_offset_parent(struct mapent_cache *mc,
49b67f
+					const char *key)
49b67f
 {
49b67f
-	struct list_head *next;
49b67f
-	struct mapent *this, *last;
49b67f
-	int eq;
49b67f
+	struct mapent *me;
49b67f
+	char *parent, *tail;
49b67f
+	int key_len;
49b67f
 
49b67f
-	last = NULL;
49b67f
-	next = *pos ? (*pos)->next : head->next;
49b67f
+	key_len = strlen(key);
49b67f
 
49b67f
-	list_for_each(next, head) {
49b67f
-		this = list_entry(next, struct mapent, multi_list);
49b67f
+	/* Check if this is the root offset */
49b67f
+	if (key[key_len - 1] == '/')
49b67f
+		return NULL;
49b67f
 
49b67f
-		if (!strcmp(this->key, key))
49b67f
+	parent = strdup(key);
49b67f
+	tail = &parent[key_len - 1];
49b67f
+
49b67f
+	while (*tail) {
49b67f
+		while (*tail != '/')
49b67f
+			tail--;
49b67f
+
49b67f
+		*tail = 0;
49b67f
+
49b67f
+		tail--;
49b67f
+		if (tail == parent)
49b67f
 			break;
49b67f
 
49b67f
-		eq = strncmp(this->key, key, strlen(this->key));
49b67f
-		if (eq == 0) {
49b67f
-			*pos = next;
49b67f
-			last = this;
49b67f
-			continue;
49b67f
+		me = cache_lookup_distinct(mc, parent);
49b67f
+		if (me) {
49b67f
+			free(parent);
49b67f
+			return me;
49b67f
 		}
49b67f
 	}
49b67f
+	free(parent);
49b67f
 
49b67f
-	return last;
49b67f
+	return NULL;
49b67f
 }
49b67f
 
49b67f
 int cache_set_parents(struct mapent *mm)
49b67f
 {
49b67f
-	struct list_head *multi_head, *p, *pos;
49b67f
+	struct list_head *multi_head, *p;
49b67f
 	struct mapent *this;
49b67f
 
49b67f
 	if (!mm->multi)
49b67f
 		return 0;
49b67f
 
49b67f
-	pos = NULL;
49b67f
 	multi_head = &mm->multi->multi_list;
49b67f
 
49b67f
 	list_for_each(p, multi_head) {
49b67f
 		struct mapent *parent;
49b67f
 		this = list_entry(p, struct mapent, multi_list);
49b67f
-		parent = get_parent(this->key, multi_head, &pos;;
49b67f
+		parent = get_offset_parent(mm->mc, this->key);
49b67f
 		if (parent)
49b67f
 			this->parent = parent;
49b67f
 		else