autofs/SOURCES/autofs-5.1.7-set-offset-parent-in-update_offset_entry.patch
2022-05-17 15:13:05 +00:00

105 lines
3.3 KiB
Diff

autofs-5.1.7 - set offset parent in update_offset_entry()
From: Ian Kent <raven@themaw.net>
Avoid the list traversal in cache_set_parents() by setting the
offset parent when updating the offset.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
include/automount.h | 2 +-
lib/cache.c | 26 +++++++++++---------------
modules/parse_sun.c | 5 ++++-
4 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
index ee746277..c4ebb52f 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -8,6 +8,7 @@
- eliminate cache_lookup_offset() usage.
- fix is mounted check on non existent path.
- simplify cache_get_parent().
+- set offset parent in update_offset_entry().
25/01/2021 autofs-5.1.7
- make bind mounts propagation slave by default.
diff --git a/include/automount.h b/include/automount.h
index 2f09e8e7..730be19a 100644
--- a/include/automount.h
+++ b/include/automount.h
@@ -208,7 +208,7 @@ int cache_add(struct mapent_cache *mc, struct map_source *ms, const char *key, c
int cache_update_offset(struct mapent_cache *mc, const char *mkey, const char *key, const char *mapent, time_t age);
int cache_lookup_negative(struct mapent *me, const char *key);
void cache_update_negative(struct mapent_cache *mc, struct map_source *ms, const char *key, time_t timeout);
-int cache_set_parents(struct mapent *mm);
+int cache_set_offset_parent(struct mapent_cache *mc, const char *offset);
int cache_update(struct mapent_cache *mc, struct map_source *ms, const char *key, const char *mapent, time_t age);
int cache_delete(struct mapent_cache *mc, const char *key);
int cache_delete_offset(struct mapent_cache *mc, const char *key);
diff --git a/lib/cache.c b/lib/cache.c
index 53f290cd..ce9e9bd2 100644
--- a/lib/cache.c
+++ b/lib/cache.c
@@ -864,25 +864,21 @@ static struct mapent *get_offset_parent(struct mapent_cache *mc,
return NULL;
}
-int cache_set_parents(struct mapent *mm)
+int cache_set_offset_parent(struct mapent_cache *mc, const char *offset)
{
- struct list_head *multi_head, *p;
- struct mapent *this;
+ struct mapent *this, *parent;
- if (!mm->multi)
+ this = cache_lookup_distinct(mc, offset);
+ if (!this)
+ return 0;
+ if (!this->multi)
return 0;
- multi_head = &mm->multi->multi_list;
-
- list_for_each(p, multi_head) {
- struct mapent *parent;
- this = list_entry(p, struct mapent, multi_list);
- parent = get_offset_parent(mm->mc, this->key);
- if (parent)
- this->parent = parent;
- else
- this->parent = mm->multi;
- }
+ parent = get_offset_parent(mc, offset);
+ if (parent)
+ this->parent = parent;
+ else
+ this->parent = this->multi;
return 1;
}
diff --git a/modules/parse_sun.c b/modules/parse_sun.c
index 819d6adc..f42af7b7 100644
--- a/modules/parse_sun.c
+++ b/modules/parse_sun.c
@@ -859,6 +859,10 @@ update_offset_entry(struct autofs_point *ap, const char *name,
}
ret = cache_update_offset(mc, name, m_key, m_mapent, age);
+
+ if (!cache_set_offset_parent(mc, m_key))
+ error(ap->logopt, "failed to set offset parent");
+
if (ret == CHE_DUPLICATE) {
warn(ap->logopt, MODPREFIX
"syntax error or duplicate offset %s -> %s", path, loc);
@@ -1613,7 +1617,6 @@ dont_expand:
*/
if (me == me->multi)
clean_stale_multi_triggers(ap, me, NULL, NULL);
- cache_set_parents(me);
rv = mount_subtree(ap, me, name, NULL, options, ctxt);