Blame SOURCES/autofs-5.1.7-use-mapent-tree-root-for-tree_mapent_add_node.patch

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