Netdev List
 help / color / mirror / Atom feed
From: Andreas Gruenbacher <agruenba@redhat.com>
To: cluster-devel@redhat.com, Thomas Graf <tgraf@suug.ch>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	netdev@vger.kernel.org
Cc: Andreas Gruenbacher <agruenba@redhat.com>
Subject: [PATCH 2/3] rhashtable: Add rhashtable_walk_curr
Date: Mon, 18 Dec 2017 14:31:21 +0100	[thread overview]
Message-ID: <20171218133122.29179-2-agruenba@redhat.com> (raw)
In-Reply-To: <20171218133122.29179-1-agruenba@redhat.com>

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@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

       reply	other threads:[~2017-12-18 13:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20171218133122.29179-1-agruenba@redhat.com>
2017-12-18 13:31 ` Andreas Gruenbacher [this message]
2017-12-18 23:38   ` [PATCH 2/3] rhashtable: Add rhashtable_walk_curr Herbert Xu
2017-12-19  8:35     ` Andreas Gruenbacher
2017-12-19 14:35       ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171218133122.29179-2-agruenba@redhat.com \
    --to=agruenba@redhat.com \
    --cc=cluster-devel@redhat.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=netdev@vger.kernel.org \
    --cc=tgraf@suug.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox