Blob Blame History Raw
autofs-5.1.7 - use mapent tree root for tree_mapent_add_node()

From: Ian Kent <raven@themaw.net>

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 <raven@themaw.net>
---
 CHANGELOG           |    1 +
 include/mounts.h    |    2 +-
 lib/mounts.c        |   24 +++++-------------------
 modules/parse_sun.c |   11 ++++++++++-
 4 files changed, 17 insertions(+), 21 deletions(-)

--- autofs-5.1.4.orig/CHANGELOG
+++ autofs-5.1.4/CHANGELOG
@@ -69,6 +69,7 @@
 - fix amd section mounts map reload.
 - fix amd hosts mount expire.
 - fix offset entries order.
+- use mapent tree root for tree_mapent_add_node().
 
 xx/xx/2018 autofs-5.1.5
 - fix flag file permission.
--- autofs-5.1.4.orig/include/mounts.h
+++ autofs-5.1.4/include/mounts.h
@@ -170,7 +170,7 @@ void mnts_get_expire_list(struct list_he
 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);
--- autofs-5.1.4.orig/lib/mounts.c
+++ autofs-5.1.4/lib/mounts.c
@@ -1519,27 +1519,13 @@ static void tree_mapent_free(struct tree
 }
 
 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_c
 		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))
 
--- autofs-5.1.4.orig/modules/parse_sun.c
+++ autofs-5.1.4/modules/parse_sun.c
@@ -1538,8 +1538,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);
 		}