lkml.org 
[lkml]   [1996]   [Oct]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRFC: New kernel proc interface
I have been working on a new set of generic file operations
and helper functions for the proc filesystem. I am presenting
it here so that folks more knowledgable than I may offer their
comments and critiques. I look forward to your rave reviews. :-)

I will try let the source speak for itself, but comment on
why certain design decisions were made.

The original reason for starting on this path was that there
are a multitude of very similar, but definitely distinct proc
file operations code. I wanted eliminate most of them and make
"generic" file operations usable by most of the kernel. I
thought that a few small changes to some of the existing code
would do the trick. I was rather naive about the proc code at
the time... (There is still plenty for me to learn.)

I brought the idea up in the mailing list and a problem with the
current implementations was brought to my attention by Keith
Owens. It seems that when a user program performs mutliple reads
on proc files (large /proc/net files for example), the user
program must use great care since the kernel tables from which
the proc output is generated may change between reads. Also,
the current proc routines are only allowed to write out one
page (4K) of data at a time. Any proc routine with more than 4K
of data had to be called multiple times by the proc code. The
kernel tables could not remain locked between the seperate calls
to the proc routines and could still return inconsistent
information, even if a user program tried to swallow all the
data in one read.

The problems described above are easily solved by allowing the
proc routines to write out all their data in one shot, and
caching that data for the user programs.

After much deliberation (and some prodding), I abandoned my
original plans for a simple fix and went out and wrote some
real code. The following patch should apply cleanly to 2.1.6.
It includes the proc_generic_file_operations code (in
fs/proc/generic.c) and related patches, as well as a proc
interface, using the new code, to sbpcd.c (my original
inspiration for delving into proc) and replacement code for
net/ipv4/ip_masq.c's proc routine (Keith Owens' suggestion).
The latter two are for demonstration only, nothing more.

Rob
(rriggs@tesser.com)

begin 644 /tmp/proc_generic-2.1.6.diff
M'XL(".23>#(``W!R;V-?9V5N97)I8RTR+C$N-F(N9&EF9@#4//U7V\BN/YN_
M8LB^I0[Y(`F4TJ2T2R'TL072&V#;<[L<'\>>@(MCY]H.-'>7][=?23/CC\1.
M0K?=]QZG31Q+H]%(&HTT(]MVAD-6F[!:+>#6)`B=>P[7'G^H#1V7,]?Q)E]K
MK7JSOKME!P`,PBW+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