[Cluster-devel] [PATCH 2/3] rhashtable: Add rhashtable_walk_curr
Andreas Gruenbacher
agruenba at redhat.com
Mon Dec 18 13:31:21 UTC 2017
When iterating through an rhashtable is stopped with
rhashtable_walk_stop and then resumed with rhashtable_walk_start, there
currently is no way to get back to the current object and thus revisit
the object rhashtable_walk_next has previously returned.
This functionality is useful when dumping an rhashtable via the seq file
interface: seq_read will convert one object after the other. When an
object doesn't fit in the remaining buffer space anymore, user-space
will be returned all objects that have been fully converted so far.
Upon the next read from user-space, the object that didn't fit
previously will be revisited.
Signed-off-by: Andreas Gruenbacher <agruenba at redhat.com>
---
include/linux/rhashtable.h | 1 +
lib/rhashtable.c | 17 +++++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
index 361c08e35dbc..1a1608bc5405 100644
--- a/include/linux/rhashtable.h
+++ b/include/linux/rhashtable.h
@@ -380,6 +380,7 @@ void rhashtable_walk_enter(struct rhashtable *ht,
void rhashtable_walk_exit(struct rhashtable_iter *iter);
int rhashtable_walk_start(struct rhashtable_iter *iter) __acquires(RCU);
void *rhashtable_walk_next(struct rhashtable_iter *iter);
+void *rhashtable_walk_curr(struct rhashtable_iter *iter);
void rhashtable_walk_stop(struct rhashtable_iter *iter) __releases(RCU);
void rhashtable_free_and_destroy(struct rhashtable *ht,
diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index ddd7dde87c3c..1d45a4274b7a 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -842,6 +842,23 @@ void *rhashtable_walk_next(struct rhashtable_iter *iter)
}
EXPORT_SYMBOL_GPL(rhashtable_walk_next);
+/**
+ * rhashtable_walk_next - Return the current object
+ * @iter: Hash table iterator
+ *
+ * Returns the object previously returned by rhashtable_walk_next.
+ *
+ * Returns -ENOENT if rhashtable_walk_next hasn't been called previously.
+ */
+void *rhashtable_walk_curr(struct rhashtable_iter *iter)
+{
+ if (!iter->skip)
+ return ERR_PTR(-ENOENT);
+ iter->skip--;
+ return rhashtable_walk_next(iter);
+}
+EXPORT_SYMBOL_GPL(rhashtable_walk_curr);
+
/**
* rhashtable_walk_stop - Finish a hash table walk
* @iter: Hash table iterator
--
2.14.3
More information about the Cluster-devel
mailing list