OpenVZ Forum - RDF feed
type: channel
items: [PATCH] Make common helpers for seq_files that work with list_head-s
items: Re: [PATCH] Make common helpers for seq_files that work with list_head-s

[PATCH] Make common helpers for seq_files that work with list_head-s
type: item
description: 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 more than 300 lines smaller. Cc-ed are people, who maintain the code altered by the patch. Signed-off-by: Pavel Emelianov <xemul@openvz.org> block/genhd.c | 40 +++----- crypto/proc.c | 17 --- drivers/char/misc.c | 18 ---- drivers/input/input.c | 29 ------ drivers/isdn/capi/kcapi_proc.c | 28 ------ fs/afs/proc.c | 81 ++---------------- fs/namespace.c | 14 --- fs/nfs/client.c | 54 +----------- fs/proc/proc_tty.c | 15 --- include/linux/seq_file.h | 35 +++++++ kernel/module.c | 17 --- mm/slab.c | 28 +----- net/atm/br2684.c | 22 ---- net/core/sock.c | 39 -------- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c | 27 ------ net/netfilter/nf_conntrack_expect.c | 27 ------ net/rxrpc/ar-proc.c | 48 +--------- 17 files changed, 116 insertions(+), 423 deletions(-) --- diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h index 3e3cccb..6f394a0 100644 --- a/include/linux/seq_file.h +++ b/include/linux/seq_file.h @@ -50,5 +50,40 @@ int seq_release_private(struct inode *, #define SEQ_START_TOKEN ((void *)1) +/* + * Helpers for iteration over list_head-s in seq_files + */ + +static inline 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; +} + +static inline 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); +} + +static inline 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; +} + #endif #endif diff --git a/block/genhd.c b/block/genhd.c index 863a8c0..8813c14 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -270,22 …
creator: xemul
date: 2007-05-17T15:15:58-00:00

Re: [PATCH] Make common helpers for seq_files that work with list_head-s
type: item
description: Hi Pavel, On 5/17/07, Pavel Emelianov <xemul@sw.ru> wrote: > 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. > Makes sense, however I am working on that part of the input code so if you could split input out so I could apply it later that'd be grand. Thanks! -- Dmitry
creator: Dmitry Torokhov
date: 2007-05-17T15:35:38-00:00

Re: [PATCH] Make common helpers for seq_files that work with list_head-s
type: item
description: On Thu, 17 May 2007 19:19:40 +0400 Pavel Emelianov <xemul@sw.ru> wrote: > 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 more than 300 lines smaller. > > Cc-ed are people, who maintain the code altered by the patch. > > Signed-off-by: Pavel Emelianov <xemul@openvz.org> > > block/genhd.c | 40 +++----- > crypto/proc.c | 17 --- > drivers/char/misc.c | 18 ---- > drivers/input/input.c | 29 ------ > drivers/isdn/capi/kcapi_proc.c | 28 ------ > fs/afs/proc.c | 81 ++---------------- > fs/namespace.c | 14 --- > fs/nfs/client.c | 54 +----------- > fs/proc/proc_tty.c | 15 --- > include/linux/seq_file.h | 35 +++++++ > kernel/module.c | 17 --- > mm/slab.c | 28 +----- > net/atm/br2684.c | 22 ---- > net/core/sock.c | 39 -------- > net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c | 27 ------ > net/netfilter/nf_conntrack_expect.c | 27 ------ > net/rxrpc/ar-proc.c | 48 +--------- > 17 files changed, 116 insertions(+), 423 deletions(-) Can't complain about the diffstat. Please experiment with uninlining seq_list_start(), see if that reduces overall text size. And as Dmitry indicated, it would be less disruptive if we could have the one core patch then a stream of per-subsystem patches, please.
creator: Andrew Morton
date: 2007-05-17T17:36:55-00:00