Make common helpers for seq_files that work with list_heads
authorPavel Emelianov <xemul@sw.ru>
Wed, 11 Jul 2007 00:22:26 +0000 (17:22 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Wed, 11 Jul 2007 00:51:13 +0000 (17:51 -0700)
Many places in kernel use seq_file API to iterate over a regular list_head.
The code for such iteration is identical in all the places, so it's worth
introducing a common helpers.

This makes code about 300 lines smaller:

The first version of this patch made the helper functions static inline
in the seq_file.h header. This patch moves them to the fs/seq_file.c as
Andrew proposed. The vmlinux .text section sizes are as follows:

2.6.22-rc1-mm1:              0x001794d5
with the previous version:   0x00179505
with this patch:             0x00179135

The config file used was make allnoconfig with the "y" inclusion of all
the possible options to make the files modified by the patch compile plus
drivers I have on the test node.

This patch:

Many places in kernel use seq_file API to iterate over a regular list_head.
The code for such iteration is identical in all the places, so it's worth
introducing a common helpers.

Signed-off-by: Pavel Emelianov <xemul@openvz.org>
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/seq_file.c
include/linux/seq_file.h

index 0ac22af7afe5f2b31ea2d289f68b5ee13e1b9040..49194a4e6b91ba9dcd22c3aa7fe81f794aca4413 100644 (file)
@@ -447,3 +447,37 @@ int seq_puts(struct seq_file *m, const char *s)
        return -1;
 }
 EXPORT_SYMBOL(seq_puts);
+
+struct list_head *seq_list_start(struct list_head *head, loff_t pos)
+{
+       struct list_head *lh;
+
+       list_for_each(lh, head)
+               if (pos-- == 0)
+                       return lh;
+
+       return NULL;
+}
+
+EXPORT_SYMBOL(seq_list_start);
+
+struct list_head *seq_list_start_head(struct list_head *head, loff_t pos)
+{
+       if (!pos)
+               return head;
+
+       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)
+{
+       struct list_head *lh;
+
+       lh = ((struct list_head *)v)->next;
+       ++*ppos;
+       return lh == head ? NULL : lh;
+}
+
+EXPORT_SYMBOL(seq_list_next);
index 3e3cccbb1cac355f385f474477f2222015e1e528..83783ab0f5524d7ad5e4e3092aa1790cdec527c9 100644 (file)
@@ -50,5 +50,16 @@ int seq_release_private(struct inode *, struct file *);
 
 #define SEQ_START_TOKEN ((void *)1)
 
+/*
+ * Helpers for iteration over list_head-s in seq_files
+ */
+
+extern struct list_head *seq_list_start(struct list_head *head,
+               loff_t pos);
+extern struct list_head *seq_list_start_head(struct list_head *head,
+               loff_t pos);
+extern struct list_head *seq_list_next(void *v, struct list_head *head,
+               loff_t *ppos);
+
 #endif
 #endif
This page took 0.058484 seconds and 5 git commands to generate.