[PATCH RFC v2 02/13] util/iova-tree: g_tree_foreach wrapper

Connor Kite <[email protected]>
Newsgroups org.nongnu.qemu-devel,dev.linux.lists.virtio-fs
Message-ID <[email protected]>
Add a wrapper to iova-tree to call g_tree_foreach.  Provides a means
to execute some function on each node of the iova-tree.

Reviewed-by: Stefan Hajnoczi <[email protected]>
Signed-off-by: Connor Kite <[email protected]>
---
 include/qemu/iova-tree.h | 21 +++++++++++++++++++++
 util/iova-tree.c         |  5 +++++
 2 files changed, 26 insertions(+)

diff --git a/include/qemu/iova-tree.h b/include/qemu/iova-tree.h
index 14e82a22d5..a1938e36a1 100644
--- a/include/qemu/iova-tree.h
+++ b/include/qemu/iova-tree.h
@@ -161,4 +161,25 @@ int iova_tree_alloc_map(IOVATree *tree, DMAMap *map, hwaddr iova_begin,
  */
 void iova_tree_destroy(IOVATree *tree);
 
+/**
+ * iova_tree_foreach:
+ *
+ * @tree: the iova tree to traverse
+ * @func: the function called at every node. A true return value ends traversal.
+ *        Arguments:
+ *            gpointer key:   key of current node
+ *            gpointer value: value of current node
+ *            gpointer data:  data passed in at g_tree_foreach call
+ *        Return: gboolean
+ * @data: an argument passed to func
+ *
+ * Wrapper to call g_tree_foreach on the underlying g_tree. g_tree_foreach will
+ * traverse through every node of the tree, barring an early return. At each
+ * node, g_tree_foreach calls func with pointers to the node key, node value,
+ * and a pointer to data passed in by the caller.
+ *
+ * Return: None
+ */
+void iova_tree_foreach(IOVATree *tree, GTraverseFunc func, gpointer data);
+
 #endif
diff --git a/util/iova-tree.c b/util/iova-tree.c
index 5b0c95ff15..2239bb6ae1 100644
--- a/util/iova-tree.c
+++ b/util/iova-tree.c
@@ -303,3 +303,8 @@ int gpa_tree_insert(IOVATree *tree, const DMAMap *map)
 
     return IOVA_OK;
 }
+
+void iova_tree_foreach(IOVATree *tree, GTraverseFunc func, gpointer data)
+{
+    g_tree_foreach(tree->tree, func, data);
+}

-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.