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

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