|
|
96dc52 |
autofs-5.1.7 - add tree_mapent_traverse_subtree()
|
|
|
96dc52 |
|
|
|
96dc52 |
From: Ian Kent <raven@themaw.net>
|
|
|
96dc52 |
|
|
|
96dc52 |
Add function tree_mapent_traverse_subtree() that enumerates offsets from
|
|
|
96dc52 |
a given base node bounded by subtree nesting points.
|
|
|
96dc52 |
|
|
|
96dc52 |
Signed-off-by: Ian Kent <raven@themaw.net>
|
|
|
96dc52 |
---
|
|
|
96dc52 |
CHANGELOG | 1 +
|
|
|
96dc52 |
lib/mounts.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
96dc52 |
2 files changed, 48 insertions(+)
|
|
|
96dc52 |
|
|
|
96dc52 |
diff --git a/CHANGELOG b/CHANGELOG
|
|
|
96dc52 |
index 488b4996..390028ac 100644
|
|
|
96dc52 |
--- a/CHANGELOG
|
|
|
96dc52 |
+++ b/CHANGELOG
|
|
|
96dc52 |
@@ -35,6 +35,7 @@
|
|
|
96dc52 |
- add mapent tree implementation.
|
|
|
96dc52 |
- add tree_mapent_add_node().
|
|
|
96dc52 |
- add tree_mapent_delete_offsets().
|
|
|
96dc52 |
+- add tree_mapent_traverse_subtree().
|
|
|
96dc52 |
|
|
|
96dc52 |
25/01/2021 autofs-5.1.7
|
|
|
96dc52 |
- make bind mounts propagation slave by default.
|
|
|
96dc52 |
diff --git a/lib/mounts.c b/lib/mounts.c
|
|
|
96dc52 |
index eb700c79..fded4c09 100644
|
|
|
96dc52 |
--- a/lib/mounts.c
|
|
|
96dc52 |
+++ b/lib/mounts.c
|
|
|
96dc52 |
@@ -1528,6 +1528,53 @@ int tree_mapent_add_node(struct mapent_cache *mc,
|
|
|
96dc52 |
return 1;
|
|
|
96dc52 |
}
|
|
|
96dc52 |
|
|
|
96dc52 |
+static inline int tree_mapent_is_root(struct mapent *oe)
|
|
|
96dc52 |
+{
|
|
|
96dc52 |
+ /* Offset "/" is a special case, it's looked up and mounted
|
|
|
96dc52 |
+ * seperately because the offset tree may or may not have a
|
|
|
96dc52 |
+ * real mount at the base and the triggers inside it need to
|
|
|
96dc52 |
+ * be mounted in either case. Also the order requires the
|
|
|
96dc52 |
+ * offset at the top of the (sub)tree to be handled after
|
|
|
96dc52 |
+ * the traversal.
|
|
|
96dc52 |
+ */
|
|
|
96dc52 |
+ return (oe->key[oe->len - 1] == '/' ||
|
|
|
96dc52 |
+ MAPENT_ROOT(oe) == MAPENT_NODE(oe));
|
|
|
96dc52 |
+}
|
|
|
96dc52 |
+
|
|
|
96dc52 |
+struct traverse_subtree_context {
|
|
|
96dc52 |
+ struct autofs_point *ap;
|
|
|
96dc52 |
+ struct tree_node *base;
|
|
|
96dc52 |
+ int strict;
|
|
|
96dc52 |
+};
|
|
|
96dc52 |
+
|
|
|
96dc52 |
+static int tree_mapent_traverse_subtree(struct tree_node *n, tree_work_fn_t work, void *ptr)
|
|
|
96dc52 |
+{
|
|
|
96dc52 |
+ struct traverse_subtree_context *ctxt = ptr;
|
|
|
96dc52 |
+ struct mapent *oe = MAPENT(n);
|
|
|
96dc52 |
+ int ret = 1;
|
|
|
96dc52 |
+
|
|
|
96dc52 |
+ if (n->left) {
|
|
|
96dc52 |
+ ret = tree_mapent_traverse_subtree(n->left, work, ctxt);
|
|
|
96dc52 |
+ if (!ret && ctxt->strict)
|
|
|
96dc52 |
+ goto done;
|
|
|
96dc52 |
+ }
|
|
|
96dc52 |
+
|
|
|
96dc52 |
+ /* Node is not multi-mount root and is part of current subtree */
|
|
|
96dc52 |
+ if (!tree_mapent_is_root(oe) && MAPENT_PARENT(oe) == ctxt->base) {
|
|
|
96dc52 |
+ ret = work(n, ctxt);
|
|
|
96dc52 |
+ if (!ret && ctxt->strict)
|
|
|
96dc52 |
+ goto done;
|
|
|
96dc52 |
+ }
|
|
|
96dc52 |
+
|
|
|
96dc52 |
+ if (n->right) {
|
|
|
96dc52 |
+ ret = tree_mapent_traverse_subtree(n->right, work, ctxt);
|
|
|
96dc52 |
+ if (!ret && ctxt->strict)
|
|
|
96dc52 |
+ goto done;
|
|
|
96dc52 |
+ }
|
|
|
96dc52 |
+done:
|
|
|
96dc52 |
+ return ret;
|
|
|
96dc52 |
+}
|
|
|
96dc52 |
+
|
|
|
96dc52 |
static int tree_mapent_delete_offset_tree(struct tree_node *root)
|
|
|
96dc52 |
{
|
|
|
96dc52 |
struct mapent *me = MAPENT(root);
|