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

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