Blame SOURCES/autofs-5.1.7-add-tree_mapent_add_node.patch

beb904
autofs-5.1.7 - add tree_mapent_add_node()
beb904
beb904
From: Ian Kent <raven@themaw.net>
beb904
beb904
Add function tree_mapent_add_node() to the mapent tree handling
beb904
implementation.
beb904
beb904
Signed-off-by: Ian Kent <raven@themaw.net>
beb904
---
beb904
 CHANGELOG           |    1 +
beb904
 include/automount.h |    1 +
beb904
 include/mounts.h    |    1 +
beb904
 lib/cache.c         |    5 ++---
beb904
 lib/mounts.c        |   47 +++++++++++++++++++++++++++++++++++++++++++++++
beb904
 5 files changed, 52 insertions(+), 3 deletions(-)
beb904
beb904
--- autofs-5.1.4.orig/CHANGELOG
beb904
+++ autofs-5.1.4/CHANGELOG
beb904
@@ -33,6 +33,7 @@
beb904
 - add a len field to struct autofs_point.
beb904
 - make tree implementation data independent.
beb904
 - add mapent tree implementation.
beb904
+- add 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/automount.h
beb904
+++ autofs-5.1.4/include/automount.h
beb904
@@ -215,6 +215,7 @@ struct mapent *cache_partial_match_wild(
beb904
 int cache_add(struct mapent_cache *mc, struct map_source *ms, const char *key, const char *mapent, time_t age);
beb904
 int cache_update_offset(struct mapent_cache *mc, const char *mkey, const char *key, const char *mapent, time_t age);
beb904
 void cache_update_negative(struct mapent_cache *mc, struct map_source *ms, const char *key, time_t timeout);
beb904
+struct mapent *cache_get_offset_parent(struct mapent_cache *mc, const char *key);
beb904
 int cache_set_offset_parent(struct mapent_cache *mc, const char *offset);
beb904
 int cache_update(struct mapent_cache *mc, struct map_source *ms, const char *key, const char *mapent, time_t age);
beb904
 int cache_delete(struct mapent_cache *mc, const char *key);
beb904
--- autofs-5.1.4.orig/include/mounts.h
beb904
+++ autofs-5.1.4/include/mounts.h
beb904
@@ -169,6 +169,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 unlink_mount_tree(struct autofs_point *ap, const char *mp);
beb904
 void free_mnt_list(struct mnt_list *list);
beb904
 int is_mounted(const char *mp, unsigned int type);
beb904
--- autofs-5.1.4.orig/lib/cache.c
beb904
+++ autofs-5.1.4/lib/cache.c
beb904
@@ -719,8 +719,7 @@ void cache_update_negative(struct mapent
beb904
 }
beb904
 
beb904
 
beb904
-static struct mapent *get_offset_parent(struct mapent_cache *mc,
beb904
-					const char *key)
beb904
+struct mapent *cache_get_offset_parent(struct mapent_cache *mc, const char *key)
beb904
 {
beb904
 	struct mapent *me;
beb904
 	char *parent, *tail;
beb904
@@ -766,7 +765,7 @@ int cache_set_offset_parent(struct mapen
beb904
 	if (!IS_MM(this))
beb904
 		return 0;
beb904
 
beb904
-	parent = get_offset_parent(mc, offset);
beb904
+	parent = cache_get_offset_parent(mc, offset);
beb904
 	if (parent)
beb904
 		this->parent = parent;
beb904
 	else
beb904
--- autofs-5.1.4.orig/lib/mounts.c
beb904
+++ autofs-5.1.4/lib/mounts.c
beb904
@@ -1481,6 +1481,53 @@ static void tree_mapent_free(struct tree
beb904
 	n->right = NULL;
beb904
 }
beb904
 
beb904
+int tree_mapent_add_node(struct mapent_cache *mc,
beb904
+			 const char *root, const char *key)
beb904
+{
beb904
+	unsigned int logopt = mc->ap->logopt;
beb904
+	struct tree_node *tree, *n;
beb904
+	struct mapent *base;
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,
beb904
+		     "failed to find multi-mount root of offset tree",
beb904
+		     key);
beb904
+		return 0;
beb904
+	}
beb904
+	tree = MAPENT_ROOT(base);
beb904
+
beb904
+	me = cache_lookup_distinct(mc, key);
beb904
+	if (!me) {
beb904
+		error(logopt,
beb904
+		     "failed to find key %s of multi-mount", key);
beb904
+		return 0;
beb904
+	}
beb904
+
beb904
+	n = tree_add_node(tree, me);
beb904
+	if (!n)
beb904
+		return 0;
beb904
+
beb904
+	MAPENT_SET_ROOT(me, tree)
beb904
+
beb904
+	/* Set the subtree parent */
beb904
+	parent = cache_get_offset_parent(mc, key);
beb904
+	if (!parent)
beb904
+		MAPENT_SET_PARENT(me, tree)
beb904
+	else
beb904
+		MAPENT_SET_PARENT(me, MAPENT_NODE(parent))
beb904
+
beb904
+	return 1;
beb904
+}
beb904
+
beb904
 /* From glibc decode_name() */
beb904
 /* Since the values in a line are separated by spaces, a name cannot
beb904
  * contain a space.  Therefore some programs encode spaces in names