public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Li Zefan <lizf@cn•fujitsu.com>
To: David Miller <davem@davemloft•net>
Cc: Andrew Morton <akpm@linux-foundation•org>,
	LKML <linux-kernel@vger•kernel.org>,
	"netdev@vger•kernel.org" <netdev@vger•kernel.org>
Subject: [PATCH 01/13] seq_file: Add helpers for iteration over a hlist
Date: Tue, 09 Feb 2010 17:18:22 +0800	[thread overview]
Message-ID: <4B71285E.9060006@cn.fujitsu.com> (raw)
In-Reply-To: <4B712849.9040400@cn.fujitsu.com>

Some places in kernel need to iterate over a hlist in seq_file,
so provide some common helpers.

Signed-off-by: Li Zefan <lizf@cn•fujitsu.com>
---
 fs/seq_file.c            |   60 +++++++++++++++++++++++++++++++++++++++++++--
 include/linux/seq_file.h |   11 ++++++++
 2 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/fs/seq_file.c b/fs/seq_file.c
index eae7d9d..ff91aef 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -674,7 +674,6 @@ struct list_head *seq_list_start(struct list_head *head, loff_t pos)
 
 	return NULL;
 }
-
 EXPORT_SYMBOL(seq_list_start);
 
 struct list_head *seq_list_start_head(struct list_head *head, loff_t pos)
@@ -684,7 +683,6 @@ struct list_head *seq_list_start_head(struct list_head *head, loff_t pos)
 
 	return seq_list_start(head, pos - 1);
 }
-
 EXPORT_SYMBOL(seq_list_start_head);
 
 struct list_head *seq_list_next(void *v, struct list_head *head, loff_t *ppos)
@@ -695,5 +693,61 @@ struct list_head *seq_list_next(void *v, struct list_head *head, loff_t *ppos)
 	++*ppos;
 	return lh == head ? NULL : lh;
 }
-
 EXPORT_SYMBOL(seq_list_next);
+
+/**
+ * seq_hlist_start - start an iteration of a hlist
+ * @head: the head of the hlist
+ * @pos:  the start position of the sequence
+ *
+ * Called at seq_file->op->start().
+ */
+struct hlist_node *seq_hlist_start(struct hlist_head *head, loff_t pos)
+{
+	struct hlist_node *node;
+
+	hlist_for_each(node, head)
+		if (pos-- == 0)
+			return node;
+	return NULL;
+}
+EXPORT_SYMBOL(seq_hlist_start);
+
+/**
+ * seq_hlist_start_head - start an iteration of a hlist
+ * @head: the head of the hlist
+ * @pos:  the start position of the sequence
+ *
+ * Called at seq_file->op->start(). Call this function if you want to
+ * print a header at the top of the output.
+ */
+struct hlist_node *seq_hlist_start_head(struct hlist_head *head, loff_t pos)
+{
+	if (!pos)
+		return SEQ_START_TOKEN;
+
+	return seq_hlist_start(head, pos - 1);
+}
+EXPORT_SYMBOL(seq_hlist_start_head);
+
+/**
+ * seq_hlist_next - move to the next position of the hlist
+ * @v:    the current iterator
+ * @head: the head of the hlist
+ * @pos:  the current posision
+ *
+ * Called at seq_file->op->next().
+ */
+struct hlist_node *seq_hlist_next(void *v, struct hlist_head *head,
+				  loff_t *ppos)
+{
+	struct hlist_node *node = v;
+
+	++*ppos;
+	if (v == SEQ_START_TOKEN)
+		return head->first;
+	else
+		return node->next;
+}
+EXPORT_SYMBOL(seq_hlist_next);
+
diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index 8366d8f..c95bcdc 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -135,4 +135,15 @@ extern struct list_head *seq_list_start_head(struct list_head *head,
 extern struct list_head *seq_list_next(void *v, struct list_head *head,
 		loff_t *ppos);
 
+/*
+ * Helpers for iteration over hlist_head-s in seq_files
+ */
+
+extern struct hlist_node *seq_hlist_start(struct hlist_head *head,
+		loff_t pos);
+extern struct hlist_node *seq_hlist_start_head(struct hlist_head *head,
+		loff_t pos);
+extern struct hlist_node *seq_hlist_next(void *v, struct hlist_head *head,
+		loff_t *ppos);
+
 #endif
-- 
1.6.3

  reply	other threads:[~2010-02-09  9:18 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-09  9:18 [PATCH 00/13] net: simplify seq_file code, revised Li Zefan
2010-02-09  9:18 ` Li Zefan [this message]
2010-02-09  9:18 ` [PATCH 02/13] net: add a wrapper sk_entry() Li Zefan
2010-02-09  9:19 ` [PATCH 03/13] net: x25: use seq_hlist_foo() helpers Li Zefan
2010-02-09  9:19 ` [PATCH 04/13] net: rose: " Li Zefan
2010-02-09  9:19 ` [PATCH 05/13] net: packet: " Li Zefan
2010-02-09  9:19 ` [PATCH 06/13] net: netrom: " Li Zefan
2010-02-09  9:19 ` [PATCH 07/13] net: ax25: " Li Zefan
2010-02-09  9:20 ` [PATCH 08/13] net: appletalk: " Li Zefan
2010-02-09  9:20 ` [PATCH 09/13] net: af_key: " Li Zefan
2010-02-09  9:20 ` [PATCH 10/13] net: x25: use seq_list_foo() helpers Li Zefan
2010-02-09  9:21 ` [PATCH 11/13] net: irda: " Li Zefan
2010-02-09  9:21 ` [PATCH 12/13] net: ipx: " Li Zefan
2010-02-09  9:21 ` [PATCH 13/13] net: atm: " Li Zefan
2010-02-10 19:31 ` [PATCH 00/13] net: simplify seq_file code, revised David Miller
2010-02-10 20:29   ` David Miller
  -- strict thread matches above, loose matches on Subject: below --
2010-02-05  1:44 [PATCH 00/13] net: simplify seq_file code Li Zefan
2010-02-05  1:58 ` Andrew Morton
2010-02-05  2:12   ` Li Zefan
2010-02-05  4:32     ` David Miller
2010-02-05  5:04       ` [PATCH 01/13] seq_file: Add helpers for iteration over a hlist Li Zefan

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=4B71285E.9060006@cn.fujitsu.com \
    --to=lizf@cn$(echo .)fujitsu.com \
    --cc=akpm@linux-foundation$(echo .)org \
    --cc=davem@davemloft$(echo .)net \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=netdev@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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