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

96dc52
autofs-5.1.7 - add tree_mapent_add_node()
96dc52
96dc52
From: Ian Kent <raven@themaw.net>
96dc52
96dc52
Add function tree_mapent_add_node() to the mapent tree handling
96dc52
implementation.
96dc52
96dc52
Signed-off-by: Ian Kent <raven@themaw.net>
96dc52
---
96dc52
 CHANGELOG           |    1 +
96dc52
 include/automount.h |    1 +
96dc52
 include/mounts.h    |    1 +
96dc52
 lib/cache.c         |    5 ++---
96dc52
 lib/mounts.c        |   47 +++++++++++++++++++++++++++++++++++++++++++++++
96dc52
 5 files changed, 52 insertions(+), 3 deletions(-)
96dc52
96dc52
diff --git a/CHANGELOG b/CHANGELOG
96dc52
index 8841f72f..85730eda 100644
96dc52
--- a/CHANGELOG
96dc52
+++ b/CHANGELOG
96dc52
@@ -33,6 +33,7 @@
96dc52
 - add a len field to struct autofs_point.
96dc52
 - make tree implementation data independent.
96dc52
 - add mapent tree implementation.
96dc52
+- add tree_mapent_add_node().
96dc52
 
96dc52
 25/01/2021 autofs-5.1.7
96dc52
 - make bind mounts propagation slave by default.
96dc52
diff --git a/include/automount.h b/include/automount.h
96dc52
index ebc2007f..f6023e27 100644
96dc52
--- a/include/automount.h
96dc52
+++ b/include/automount.h
96dc52
@@ -216,6 +216,7 @@ int cache_add(struct mapent_cache *mc, struct map_source *ms, const char *key, c
96dc52
 int cache_update_offset(struct mapent_cache *mc, const char *mkey, const char *key, const char *mapent, time_t age);
96dc52
 int cache_lookup_negative(struct mapent *me, const char *key);
96dc52
 void cache_update_negative(struct mapent_cache *mc, struct map_source *ms, const char *key, time_t timeout);
96dc52
+struct mapent *cache_get_offset_parent(struct mapent_cache *mc, const char *key);
96dc52
 int cache_set_offset_parent(struct mapent_cache *mc, const char *offset);
96dc52
 int cache_update(struct mapent_cache *mc, struct map_source *ms, const char *key, const char *mapent, time_t age);
96dc52
 int cache_delete(struct mapent_cache *mc, const char *key);
96dc52
diff --git a/include/mounts.h b/include/mounts.h
96dc52
index fd7c6183..a0e60e24 100644
96dc52
--- a/include/mounts.h
96dc52
+++ b/include/mounts.h
96dc52
@@ -169,6 +169,7 @@ void mnts_get_expire_list(struct list_head *mnts, struct autofs_point *ap);
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 unlink_mount_tree(struct autofs_point *ap, const char *mp);
96dc52
 void free_mnt_list(struct mnt_list *list);
96dc52
 int is_mounted(const char *mp, unsigned int type);
96dc52
diff --git a/lib/cache.c b/lib/cache.c
96dc52
index 6dfaeff5..7c409a56 100644
96dc52
--- a/lib/cache.c
96dc52
+++ b/lib/cache.c
96dc52
@@ -749,8 +749,7 @@ void cache_update_negative(struct mapent_cache *mc,
96dc52
 }
96dc52
 
96dc52
 
96dc52
-static struct mapent *get_offset_parent(struct mapent_cache *mc,
96dc52
-					const char *key)
96dc52
+struct mapent *cache_get_offset_parent(struct mapent_cache *mc, const char *key)
96dc52
 {
96dc52
 	struct mapent *me;
96dc52
 	char *parent, *tail;
96dc52
@@ -796,7 +795,7 @@ int cache_set_offset_parent(struct mapent_cache *mc, const char *offset)
96dc52
 	if (!IS_MM(this))
96dc52
 		return 0;
96dc52
 
96dc52
-	parent = get_offset_parent(mc, offset);
96dc52
+	parent = cache_get_offset_parent(mc, offset);
96dc52
 	if (parent)
96dc52
 		this->parent = parent;
96dc52
 	else
96dc52
diff --git a/lib/mounts.c b/lib/mounts.c
96dc52
index 40ebf9cf..a0bf3d52 100644
96dc52
--- a/lib/mounts.c
96dc52
+++ b/lib/mounts.c
96dc52
@@ -1481,6 +1481,53 @@ static void tree_mapent_free(struct tree_node *n)
96dc52
 	n->right = NULL;
96dc52
 }
96dc52
 
96dc52
+int tree_mapent_add_node(struct mapent_cache *mc,
96dc52
+			 const char *root, const char *key)
96dc52
+{
96dc52
+	unsigned int logopt = mc->ap->logopt;
96dc52
+	struct tree_node *tree, *n;
96dc52
+	struct mapent *base;
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,
96dc52
+		     "failed to find multi-mount root of offset tree",
96dc52
+		     key);
96dc52
+		return 0;
96dc52
+	}
96dc52
+	tree = MAPENT_ROOT(base);
96dc52
+
96dc52
+	me = cache_lookup_distinct(mc, key);
96dc52
+	if (!me) {
96dc52
+		error(logopt,
96dc52
+		     "failed to find key %s of multi-mount", key);
96dc52
+		return 0;
96dc52
+	}
96dc52
+
96dc52
+	n = tree_add_node(tree, me);
96dc52
+	if (!n)
96dc52
+		return 0;
96dc52
+
96dc52
+	MAPENT_SET_ROOT(me, tree)
96dc52
+
96dc52
+	/* Set the subtree parent */
96dc52
+	parent = cache_get_offset_parent(mc, key);
96dc52
+	if (!parent)
96dc52
+		MAPENT_SET_PARENT(me, tree)
96dc52
+	else
96dc52
+		MAPENT_SET_PARENT(me, MAPENT_NODE(parent))
96dc52
+
96dc52
+	return 1;
96dc52
+}
96dc52
+
96dc52
 /* From glibc decode_name() */
96dc52
 /* Since the values in a line are separated by spaces, a name cannot
96dc52
  * contain a space.  Therefore some programs encode spaces in names