autofs-5.1.7 - use mapent tree root for tree_mapent_add_node() From: Ian Kent Since we need to create the offset tree after adding the offset entries to the mapent cache lookup the root mapent once and use it when calling tree_mapent_add_node() instread of doing a cache lookup on every node addition. Signed-off-by: Ian Kent --- CHANGELOG | 1 + include/mounts.h | 2 +- lib/mounts.c | 24 +++++------------------- modules/parse_sun.c | 11 ++++++++++- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 7b360f52..5a767360 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -72,6 +72,7 @@ - fix lookup_prune_one_cache() refactoring change. - fix amd hosts mount expire. - fix offset entries order. +- use mapent tree root for tree_mapent_add_node(). 25/01/2021 autofs-5.1.7 - make bind mounts propagation slave by default. diff --git a/include/mounts.h b/include/mounts.h index 1b376b3d..f7768ce5 100644 --- a/include/mounts.h +++ b/include/mounts.h @@ -170,7 +170,7 @@ void mnts_get_expire_list(struct list_head *mnts, struct autofs_point *ap); void mnts_put_expire_list(struct list_head *mnts); void mnts_set_mounted_mount(struct autofs_point *ap, const char *name, unsigned int flags); struct tree_node *tree_mapent_root(struct mapent *me); -int tree_mapent_add_node(struct mapent_cache *mc, const char *base, const char *key); +int tree_mapent_add_node(struct mapent_cache *mc, struct tree_node *root, const char *key); int tree_mapent_delete_offsets(struct mapent_cache *mc, const char *key); void tree_mapent_cleanup_offsets(struct mapent *oe); int tree_mapent_mount_offsets(struct mapent *oe, int nonstrict); diff --git a/lib/mounts.c b/lib/mounts.c index c24d1a88..9ec547ea 100644 --- a/lib/mounts.c +++ b/lib/mounts.c @@ -1519,27 +1519,13 @@ static void tree_mapent_free(struct tree_node *n) } int tree_mapent_add_node(struct mapent_cache *mc, - const char *root, const char *key) + struct tree_node *root, const char *key) { unsigned int logopt = mc->ap->logopt; - struct tree_node *tree, *n; - struct mapent *base; + struct tree_node *n; struct mapent *parent; struct mapent *me; - base = cache_lookup_distinct(mc, root); - if (!base) { - error(logopt, - "failed to find multi-mount root for key %s", key); - return 0; - } - - if (MAPENT_ROOT(base) != MAPENT_NODE(base)) { - error(logopt, "key %s is not multi-mount root", root); - return 0; - } - tree = MAPENT_ROOT(base); - me = cache_lookup_distinct(mc, key); if (!me) { error(logopt, @@ -1547,16 +1533,16 @@ int tree_mapent_add_node(struct mapent_cache *mc, return 0; } - n = tree_add_node(tree, me); + n = tree_add_node(root, me); if (!n) return 0; - MAPENT_SET_ROOT(me, tree) + MAPENT_SET_ROOT(me, root) /* Set the subtree parent */ parent = cache_get_offset_parent(mc, key); if (!parent) - MAPENT_SET_PARENT(me, tree) + MAPENT_SET_PARENT(me, root) else MAPENT_SET_PARENT(me, MAPENT_NODE(parent)) diff --git a/modules/parse_sun.c b/modules/parse_sun.c index b206a326..c75bcc8e 100644 --- a/modules/parse_sun.c +++ b/modules/parse_sun.c @@ -1536,8 +1536,17 @@ dont_expand: } while (*p == '/' || (*p == '"' && *(p + 1) == '/')); cache_writelock(mc); + me = cache_lookup_distinct(mc, name); + if (!me) { + cache_unlock(mc); + free(options); + free(pmapent); + cleanup_offset_entries(ap, mc, &offsets); + pthread_setcancelstate(cur_state, NULL); + return 1; + } list_for_each_entry_safe(oe, tmp, &offsets, work) { - if (!tree_mapent_add_node(mc, name, oe->key)) + if (!tree_mapent_add_node(mc, MAPENT_ROOT(me), oe->key)) error(ap->logopt, "failed to add offset %s to tree", oe->key); list_del_init(&oe->work); }