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

49b67f
autofs-5.1.7 - add mapent tree implementation
49b67f
49b67f
From: Ian Kent <raven@themaw.net>
49b67f
49b67f
Add a struct mapent basic tree implementation.
49b67f
49b67f
Signed-off-by: Ian Kent <raven@themaw.net>
49b67f
---
49b67f
 CHANGELOG           |    1 +
49b67f
 include/automount.h |    4 ++++
49b67f
 include/mounts.h    |    8 ++++++++
49b67f
 lib/cache.c         |    9 ++++++++-
49b67f
 lib/mounts.c        |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
49b67f
 5 files changed, 71 insertions(+), 1 deletion(-)
49b67f
49b67f
--- autofs-5.1.4.orig/CHANGELOG
49b67f
+++ autofs-5.1.4/CHANGELOG
49b67f
@@ -32,6 +32,7 @@
49b67f
 - remove unused functions cache_dump_multi() and cache_dump_cache().
49b67f
 - add a len field to struct autofs_point.
49b67f
 - make tree implementation data independent.
49b67f
+- add mapent tree implementation.
49b67f
 
49b67f
 xx/xx/2018 autofs-5.1.5
49b67f
 - fix flag file permission.
49b67f
--- autofs-5.1.4.orig/include/automount.h
49b67f
+++ autofs-5.1.4/include/automount.h
49b67f
@@ -166,10 +166,14 @@ struct mapent {
49b67f
 	struct mapent_cache *mc;
49b67f
 	struct map_source *source;
49b67f
 	/* Need to know owner if we're a multi-mount */
49b67f
+	struct tree_node *mm_root;
49b67f
+	struct tree_node *mm_parent;
49b67f
+	struct tree_node node;
49b67f
 	struct mapent *multi;
49b67f
 	/* Parent nesting point within multi-mount */
49b67f
 	struct mapent *parent;
49b67f
 	char *key;
49b67f
+	size_t len;
49b67f
 	char *mapent;
49b67f
 	struct stack *stack;
49b67f
 	time_t age;
49b67f
--- autofs-5.1.4.orig/include/mounts.h
49b67f
+++ autofs-5.1.4/include/mounts.h
49b67f
@@ -66,6 +66,13 @@ struct tree_node {
49b67f
 #define MNT_LIST(n)		(container_of(n, struct mnt_list, node))
49b67f
 #define MNT_LIST_NODE(ptr)	((struct tree_node *) &((struct mnt_list *) ptr)->node)
49b67f
 
49b67f
+#define MAPENT(n)		(container_of(n, struct mapent, node))
49b67f
+#define MAPENT_NODE(p)		((struct tree_node *) &((struct mapent *) p)->node)
49b67f
+#define MAPENT_ROOT(p)		((struct tree_node *) ((struct mapent *) p)->mm_root)
49b67f
+#define MAPENT_PARENT(p)	((struct tree_node *) ((struct mapent *) p)->mm_parent)
49b67f
+#define MAPENT_SET_ROOT(p, r)	{ (((struct mapent *) p)->mm_root = (struct tree_node *) r); }
49b67f
+#define MAPENT_SET_PARENT(p, n)	{ (((struct mapent *) p)->mm_parent = (struct tree_node *) n); }
49b67f
+
49b67f
 typedef struct tree_node *(*tree_new_t) (void *ptr);
49b67f
 typedef int  (*tree_cmp_t) (struct tree_node *n, void *ptr);
49b67f
 typedef void (*tree_free_t) (struct tree_node *n);
49b67f
@@ -161,6 +168,7 @@ unsigned int mnts_has_mounted_mounts(str
49b67f
 void mnts_get_expire_list(struct list_head *mnts, struct autofs_point *ap);
49b67f
 void mnts_put_expire_list(struct list_head *mnts);
49b67f
 void mnts_set_mounted_mount(struct autofs_point *ap, const char *name, unsigned int flags);
49b67f
+struct tree_node *tree_mapent_root(struct mapent *me);
49b67f
 int unlink_mount_tree(struct autofs_point *ap, const char *mp);
49b67f
 void free_mnt_list(struct mnt_list *list);
49b67f
 int is_mounted(const char *mp, unsigned int type);
49b67f
--- autofs-5.1.4.orig/lib/cache.c
49b67f
+++ autofs-5.1.4/lib/cache.c
49b67f
@@ -546,17 +546,21 @@ int cache_add(struct mapent_cache *mc, s
49b67f
 	struct mapent *me, *existing = NULL;
49b67f
 	char *pkey, *pent;
49b67f
 	u_int32_t hashval = hash(key, mc->size);
49b67f
+	size_t len;
49b67f
 
49b67f
 	me = (struct mapent *) malloc(sizeof(struct mapent));
49b67f
 	if (!me)
49b67f
 		return CHE_FAIL;
49b67f
 
49b67f
-	pkey = malloc(strlen(key) + 1);
49b67f
+	len = strlen(key);
49b67f
+
49b67f
+	pkey = malloc(len + 1);
49b67f
 	if (!pkey) {
49b67f
 		free(me);
49b67f
 		return CHE_FAIL;
49b67f
 	}
49b67f
 	me->key = strcpy(pkey, key);
49b67f
+	me->len = len;
49b67f
 
49b67f
 	if (mapent) {
49b67f
 		pent = malloc(strlen(mapent) + 1);
49b67f
@@ -575,6 +579,9 @@ int cache_add(struct mapent_cache *mc, s
49b67f
 	me->status = 0;
49b67f
 	me->mc = mc;
49b67f
 	me->source = ms;
49b67f
+	me->mm_root = NULL;
49b67f
+	me->mm_parent = NULL;
49b67f
+	INIT_TREE_NODE(&me->node);
49b67f
 	INIT_LIST_HEAD(&me->ino_index);
49b67f
 	INIT_LIST_HEAD(&me->multi_list);
49b67f
 	me->multi = NULL;
49b67f
--- autofs-5.1.4.orig/lib/mounts.c
49b67f
+++ autofs-5.1.4/lib/mounts.c
49b67f
@@ -79,6 +79,17 @@ static struct tree_ops mnt_ops = {
49b67f
 };
49b67f
 static struct tree_ops *tree_mnt_ops = &mnt_ops;
49b67f
 
49b67f
+static struct tree_node *tree_mapent_new(void *ptr);
49b67f
+static int tree_mapent_cmp(struct tree_node *n, void *ptr);
49b67f
+static void tree_mapent_free(struct tree_node *n);
49b67f
+
49b67f
+static struct tree_ops mapent_ops = {
49b67f
+	.new = tree_mapent_new,
49b67f
+	.cmp = tree_mapent_cmp,
49b67f
+	.free = tree_mapent_free,
49b67f
+};
49b67f
+static struct tree_ops *tree_mapent_ops = &mapent_ops;
49b67f
+
49b67f
 unsigned int linux_version_code(void)
49b67f
 {
49b67f
 	struct utsname my_utsname;
49b67f
@@ -1431,6 +1442,45 @@ void mnts_put_expire_list(struct list_he
49b67f
 	mnts_hash_mutex_unlock();
49b67f
 }
49b67f
 
49b67f
+struct tree_node *tree_mapent_root(struct mapent *me)
49b67f
+{
49b67f
+	return tree_root(tree_mapent_ops, me);
49b67f
+}
49b67f
+
49b67f
+static struct tree_node *tree_mapent_new(void *ptr)
49b67f
+{
49b67f
+	struct tree_node *n = MAPENT_NODE(ptr);
49b67f
+
49b67f
+	n->ops = tree_mapent_ops;
49b67f
+	n->left = NULL;
49b67f
+	n->right = NULL;
49b67f
+
49b67f
+	return n;
49b67f
+}
49b67f
+
49b67f
+static int tree_mapent_cmp(struct tree_node *n, void *ptr)
49b67f
+{
49b67f
+	struct mapent *n_me = MAPENT(n);
49b67f
+	size_t n_me_len = n_me->len;
49b67f
+	struct mapent *me = ptr;
49b67f
+	size_t me_len = me->len;
49b67f
+
49b67f
+	if (strncmp(me->key, n_me->key, n_me_len) == 0) {
49b67f
+		if (me_len < n_me_len)
49b67f
+			return -1;
49b67f
+		else if (me_len > n_me_len)
49b67f
+			return 1;
49b67f
+	}
49b67f
+	return strcmp(me->key, n_me->key);
49b67f
+}
49b67f
+
49b67f
+static void tree_mapent_free(struct tree_node *n)
49b67f
+{
49b67f
+	n->ops = NULL;
49b67f
+	n->left = NULL;
49b67f
+	n->right = NULL;
49b67f
+}
49b67f
+
49b67f
 /* From glibc decode_name() */
49b67f
 /* Since the values in a line are separated by spaces, a name cannot
49b67f
  * contain a space.  Therefore some programs encode spaces in names