Blame SOURCES/autofs-5.1.7-add-tree_mapent_traverse_subtree.patch

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