Alexander Viro wrote:
>
> On Tue, 19 Oct 1999, Jeff Garzik wrote:
>
> > Comments on your procfs patch: I like it. :)
> >
> > It looks like many xxx_read_proc operation in fs/proc/proc_array.c
> > contains the _exact_ same code for adjusting 'len', 'start', etc.
> > Cleanup should take care of that.
> >
> > Putting that stuff into an inline or plain macro would save a lot of
> > [source] code. But I think proc_array.c can be made even smaller.
> > Maybe 80% of the functions could be condensed into something like:
> >
> > DECLARE_SIMPLE_READ_PROC(filesystems_read_proc, get_filesystem_list)
> > DECLARE_SIMPLE_READ_PROC(dma_read_proc, get_dma_list)
>
> Yes, but it's _not_ a good thing. See comment in the beginning of
> proc_misc.c - the thing you are talking about is the wrapper turning
> ->info-ish stuff into ->read_proc one. It's OK for the small things, but
> for anything large... Look into drivers/pci/proc.c - I did a proper
> conversion there and IMO the same should be done for the rest of them.
Ok, well my main complaint is that there is duplicate code no matter how
you scatter or update things. In pci_read_proc there is logic to
calculate 'count', 'eof', etc. which is duplicated many times.
My idea for solving this is to create struct proc_print, and function
proc_printk:
int proc_printk (struct proc_print *p, const char *format, ...)
'struct proc_print' would contain all the args passed to xxx_read_proc,
and proc_printk would update that information each time it is called.
proc_printk can also be set up to handle overflows of the procfs output
buffer, multiple output buffers, etc.