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