lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20171218133122.29179-2-agruenba@redhat.com>
Date:   Mon, 18 Dec 2017 14:31:21 +0100
From:   Andreas Gruenbacher <agruenba@...hat.com>
To:     cluster-devel@...hat.com, Thomas Graf <tgraf@...g.ch>,
        Herbert Xu <herbert@...dor.apana.org.au>,
        netdev@...r.kernel.org
Cc:     Andreas Gruenbacher <agruenba@...hat.com>
Subject: [PATCH 2/3] rhashtable: Add rhashtable_walk_curr

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ