From: viro@parcelfarce.linux.theplanet.co.uk
To: Tigran Aivazian <tigran@aivazian.fsnet.co.uk>
Cc: William Lee Irwin III <wli@holomorphy.com>, linux-kernel@vger.kernel.org
Subject: Re: seq_file and exporting dynamically allocated data
Date: Mon, 17 Nov 2003 10:35:36 +0000 [thread overview]
Message-ID: <20031117103536.GW24159@parcelfarce.linux.theplanet.co.uk> (raw)
In-Reply-To: <Pine.LNX.4.44.0311171005160.1384-100000@einstein.homenet>
On Mon, Nov 17, 2003 at 10:08:45AM +0000, Tigran Aivazian wrote:
> On Mon, 17 Nov 2003 viro@parcelfarce.linux.theplanet.co.uk wrote:
> > EOF had been reached when read() returns 0. Until then read() returns
> > an arbitrary amount of bytes between 1 and 'size' argument. Since you
> > are using read(2) directly, use it correctly...
>
> I know that for read(2) in general but I thought that the whole point of
> using "sequential record" files (aka seq_file) is that they guarantee
> read(2) to return a number of fixed-size records, hence the name
> "sequential record". Especially since the ->show() function is packing
> those records into m->buf as "whole" entities, not in "halves" or such.
No. What you are guaranteed is that continuous reading from the stream
will not give you broken entries. IOW, if read() gets a part of record,
subsequent reads will get the rest of _that_ _record_.
Note that behaviour you are asking for would break a *lot* of things.
Consider the following code:
for (left = BUFSIZE; left; left -= n) {
n = read(fd, buf + BUFSIZE - left, left);
if (n <= 0)
break;
}
IOW, fill the buffer from file, until EOF/error/buffer becoming full.
With your semantics we are fscked - as soon as we have less than one
"record" left in a buffer, we are in a hopeless situation. read()
can't return an entire record (no place to put it); it can't return
0 (that would be impossible to distinguish from EOF) and there is
no acceptable error value that would indicate such situation. read(2)
is not getdents(2) - there we *do* have an error value for situation
like that ("buffer too small").
Pretty much anything that does buffered IO (e.g. stdio code) contains
equivalents of the above.
_If_ you want datagrams - implement datagrams and don't expect grep/cat/etc.
to work on them.
> I believe you of course (as you wrote seq_file) but it still seems that as
> long as the implementation (i.e. my module) is working with whole records
> it is ok to assume that read() will return them as whole, i.e. not break a
> record between two calls to read(2). Is this really not true?
It's really not true.
*NOTE*: in your case I would consider putting a cursor into task list
and moving it around on ->start() and ->stop(). That can give you
more or less accurate snapshot with multiple read(2).
However, it's not obvious that the thing is worth the effort (you'd need
to make sure that no other code scanning the list will be disturbed when
it sees your cursor).
What is *not* acceptable (regardless of the implementation, be it done via
seq_file or not): ability to get the entire list of processes in single
read(2). User-exploitable OOM is not a good thing. No matter how you
implement read(2), you would have to get sufficient amount of memory locked
in core - you need to hold a spinlock to generate the contents, to start
with, so no "copy to userland in chunks" scheme would work.
next prev parent reply other threads:[~2003-11-17 10:35 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-11-14 20:42 Harald Welte
2003-11-14 21:01 ` Tigran Aivazian
2003-11-15 9:38 ` Harald Welte
2003-11-15 17:18 ` viro
2003-11-15 17:33 ` Harald Welte
2003-11-15 19:49 ` Tigran Aivazian
2003-11-15 20:14 ` viro
2003-11-15 20:41 ` Tigran Aivazian
2003-11-15 21:30 ` viro
2003-11-15 20:50 ` Tigran Aivazian
2003-11-15 21:33 ` viro
2003-11-15 21:54 ` Tigran Aivazian
2003-11-16 7:27 ` Tigran Aivazian
2003-11-17 5:48 ` viro
2003-11-17 8:21 ` Tigran Aivazian
2003-11-17 8:30 ` William Lee Irwin III
2003-11-17 8:38 ` Tigran Aivazian
2003-11-17 8:48 ` William Lee Irwin III
2003-11-17 9:03 ` William Lee Irwin III
2003-11-17 9:42 ` Tigran Aivazian
2003-11-17 9:50 ` William Lee Irwin III
2003-11-17 9:55 ` viro
2003-11-17 10:08 ` Tigran Aivazian
2003-11-17 10:35 ` viro [this message]
2003-11-17 9:48 ` viro
2003-11-16 20:45 ` Harald Welte
2003-11-15 20:36 ` viro
2003-11-16 20:42 ` Harald Welte
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=20031117103536.GW24159@parcelfarce.linux.theplanet.co.uk \
--to=viro@parcelfarce.linux.theplanet.co.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=tigran@aivazian.fsnet.co.uk \
--cc=wli@holomorphy.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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
Powered by JetHome