Blame SOURCES/autofs-5.1.7-add-mapent-tree-implementation.patch

96dc52
autofs-5.1.7 - add mapent tree implementation
96dc52
96dc52
From: Ian Kent <raven@themaw.net>
96dc52
96dc52
Add a struct mapent basic tree implementation.
96dc52
96dc52
Signed-off-by: Ian Kent <raven@themaw.net>
96dc52
---
96dc52
 CHANGELOG           |    1 +
96dc52
 include/automount.h |    4 ++++
96dc52
 include/mounts.h    |    8 ++++++++
96dc52
 lib/cache.c         |    9 ++++++++-
96dc52
 lib/mounts.c        |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
96dc52
 5 files changed, 71 insertions(+), 1 deletion(-)
96dc52
96dc52
diff --git a/CHANGELOG b/CHANGELOG
96dc52
index 74571570..8841f72f 100644
96dc52
--- a/CHANGELOG
96dc52
+++ b/CHANGELOG
96dc52
@@ -32,6 +32,7 @@
96dc52
 - remove unused functions cache_dump_multi() and cache_dump_cache().
96dc52
 - add a len field to struct autofs_point.
96dc52
 - make tree implementation data independent.
96dc52
+- add mapent tree implementation.
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 34485859..ebc2007f 100644
96dc52
--- a/include/automount.h
96dc52
+++ b/include/automount.h
96dc52
@@ -166,10 +166,14 @@ struct mapent {
96dc52
 	struct mapent_cache *mc;
96dc52
 	struct map_source *source;
96dc52
 	/* Need to know owner if we're a multi-mount */
96dc52
+	struct tree_node *mm_root;
96dc52
+	struct tree_node *mm_parent;
96dc52
+	struct tree_node node;
96dc52
 	struct mapent *multi;
96dc52
 	/* Parent nesting point within multi-mount */
96dc52
 	struct mapent *parent;
96dc52
 	char *key;
96dc52
+	size_t len;
96dc52
 	char *mapent;
96dc52
 	struct stack *stack;
96dc52
 	time_t age;
96dc52
diff --git a/include/mounts.h b/include/mounts.h
96dc52
index 71d29566..fd7c6183 100644
96dc52
--- a/include/mounts.h
96dc52
+++ b/include/mounts.h
96dc52
@@ -66,6 +66,13 @@ struct tree_node {
96dc52
 #define MNT_LIST(n)		(container_of(n, struct mnt_list, node))
96dc52
 #define MNT_LIST_NODE(ptr)	((struct tree_node *) &((struct mnt_list *) ptr)->node)
96dc52
 
96dc52
+#define MAPENT(n)		(container_of(n, struct mapent, node))
96dc52
+#define MAPENT_NODE(p)		((struct tree_node *) &((struct mapent *) p)->node)
96dc52
+#define MAPENT_ROOT(p)		((struct tree_node *) ((struct mapent *) p)->mm_root)
96dc52
+#define MAPENT_PARENT(p)	((struct tree_node *) ((struct mapent *) p)->mm_parent)
96dc52
+#define MAPENT_SET_ROOT(p, r)	{ (((struct mapent *) p)->mm_root = (struct tree_node *) r); }
96dc52
+#define MAPENT_SET_PARENT(p, n)	{ (((struct mapent *) p)->mm_parent = (struct tree_node *) n); }
96dc52
+
96dc52
 typedef struct tree_node *(*tree_new_t) (void *ptr);
96dc52
 typedef int  (*tree_cmp_t) (struct tree_node *n, void *ptr);
96dc52
 typedef void (*tree_free_t) (struct tree_node *n);
96dc52
@@ -161,6 +168,7 @@ unsigned int mnts_has_mounted_mounts(struct autofs_point *ap);
96dc52
 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 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 629c4d0a..6dfaeff5 100644
96dc52
--- a/lib/cache.c
96dc52
+++ b/lib/cache.c
96dc52
@@ -546,17 +546,21 @@ int cache_add(struct mapent_cache *mc, struct map_source *ms, const char *key, c
96dc52
 	struct mapent *me, *existing = NULL;
96dc52
 	char *pkey, *pent;
96dc52
 	u_int32_t hashval = hash(key, mc->size);
96dc52
+	size_t len;
96dc52
 
96dc52
 	me = (struct mapent *) malloc(sizeof(struct mapent));
96dc52
 	if (!me)
96dc52
 		return CHE_FAIL;
96dc52
 
96dc52
-	pkey = malloc(strlen(key) + 1);
96dc52
+	len = strlen(key);
96dc52
+
96dc52
+	pkey = malloc(len + 1);
96dc52
 	if (!pkey) {
96dc52
 		free(me);
96dc52
 		return CHE_FAIL;
96dc52
 	}
96dc52
 	me->key = strcpy(pkey, key);
96dc52
+	me->len = len;
96dc52
 
96dc52
 	if (mapent) {
96dc52
 		pent = malloc(strlen(mapent) + 1);
96dc52
@@ -575,6 +579,9 @@ int cache_add(struct mapent_cache *mc, struct map_source *ms, const char *key, c
96dc52
 	me->status = 0;
96dc52
 	me->mc = mc;
96dc52
 	me->source = ms;
96dc52
+	me->mm_root = NULL;
96dc52
+	me->mm_parent = NULL;
96dc52
+	INIT_TREE_NODE(&me->node);
96dc52
 	INIT_LIST_HEAD(&me->ino_index);
96dc52
 	INIT_LIST_HEAD(&me->multi_list);
96dc52
 	me->multi = NULL;
96dc52
diff --git a/lib/mounts.c b/lib/mounts.c
96dc52
index a6d1c5a7..40ebf9cf 100644
96dc52
--- a/lib/mounts.c
96dc52
+++ b/lib/mounts.c
96dc52
@@ -79,6 +79,17 @@ static struct tree_ops mnt_ops = {
96dc52
 };
96dc52
 static struct tree_ops *tree_mnt_ops = &mnt_ops;
96dc52
 
96dc52
+static struct tree_node *tree_mapent_new(void *ptr);
96dc52
+static int tree_mapent_cmp(struct tree_node *n, void *ptr);
96dc52
+static void tree_mapent_free(struct tree_node *n);
96dc52
+
96dc52
+static struct tree_ops mapent_ops = {
96dc52
+	.new = tree_mapent_new,
96dc52
+	.cmp = tree_mapent_cmp,
96dc52
+	.free = tree_mapent_free,
96dc52
+};
96dc52
+static struct tree_ops *tree_mapent_ops = &mapent_ops;
96dc52
+
96dc52
 unsigned int linux_version_code(void)
96dc52
 {
96dc52
 	struct utsname my_utsname;
96dc52
@@ -1431,6 +1442,45 @@ void mnts_put_expire_list(struct list_head *mnts)
96dc52
 	mnts_hash_mutex_unlock();
96dc52
 }
96dc52
 
96dc52
+struct tree_node *tree_mapent_root(struct mapent *me)
96dc52
+{
96dc52
+	return tree_root(tree_mapent_ops, me);
96dc52
+}
96dc52
+
96dc52
+static struct tree_node *tree_mapent_new(void *ptr)
96dc52
+{
96dc52
+	struct tree_node *n = MAPENT_NODE(ptr);
96dc52
+
96dc52
+	n->ops = tree_mapent_ops;
96dc52
+	n->left = NULL;
96dc52
+	n->right = NULL;
96dc52
+
96dc52
+	return n;
96dc52
+}
96dc52
+
96dc52
+static int tree_mapent_cmp(struct tree_node *n, void *ptr)
96dc52
+{
96dc52
+	struct mapent *n_me = MAPENT(n);
96dc52
+	size_t n_me_len = n_me->len;
96dc52
+	struct mapent *me = ptr;
96dc52
+	size_t me_len = me->len;
96dc52
+
96dc52
+	if (strncmp(me->key, n_me->key, n_me_len) == 0) {
96dc52
+		if (me_len < n_me_len)
96dc52
+			return -1;
96dc52
+		else if (me_len > n_me_len)
96dc52
+			return 1;
96dc52
+	}
96dc52
+	return strcmp(me->key, n_me->key);
96dc52
+}
96dc52
+
96dc52
+static void tree_mapent_free(struct tree_node *n)
96dc52
+{
96dc52
+	n->ops = NULL;
96dc52
+	n->left = NULL;
96dc52
+	n->right = NULL;
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