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