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