* read() called twice for /proc files
@ 2001-09-25 1:34 Tim Hockin
2001-09-25 2:16 ` Jonathan Lundell
0 siblings, 1 reply; 4+ messages in thread
From: Tim Hockin @ 2001-09-25 1:34 UTC (permalink / raw)
To: Linux Kernel Mailing List
woops! sent too early!
Is there a general solution to the case of read() being called minimum
twice for a file in /proc? I have a small file in /proc, whose data takes
a fair time to generate. My read() handler gets called once for the data,
and once so I can return 0 to terminate read().
This results in the actual read taking twice as long. Perhaps I am missing
something...
What if the proc generic stuff used file->private_data as an EOF flag. It
seems really bizarre that the read loop loops until return 0 or eof is
set. We promptly throw away the EOF information that the read() handler
set.
Would it break anything? Is there something I am not seeing in the larger
picture?
--
Tim Hockin
Systems Software Engineer
Sun Microsystems, Cobalt Server Appliances
thockin@sun.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: read() called twice for /proc files
2001-09-25 1:34 read() called twice for /proc files Tim Hockin
@ 2001-09-25 2:16 ` Jonathan Lundell
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Lundell @ 2001-09-25 2:16 UTC (permalink / raw)
To: Tim Hockin, Linux Kernel Mailing List
At 6:34 PM -0700 2001-09-24, Tim Hockin wrote:
>Is there a general solution to the case of read() being called minimum
>twice for a file in /proc? I have a small file in /proc, whose data takes
>a fair time to generate. My read() handler gets called once for the data,
>and once so I can return 0 to terminate read().
I'm guessing you mean that the user is calling read once (and not a
second time to get the 0/eof return), and that proc_file_read() is
calling your read_proc twice. If that's the case, you can just set
the eof flag on the first call (on which you return the data), and
you won't be called again unless the user reads again.
And of course, as David Miller suggests, you can check the offset
first, before generating data.
--
/Jonathan Lundell.
^ permalink raw reply [flat|nested] 4+ messages in thread
* read() called twice for /proc files
@ 2001-09-25 1:29 Tim Hockin
2001-09-25 1:35 ` David S. Miller
0 siblings, 1 reply; 4+ messages in thread
From: Tim Hockin @ 2001-09-25 1:29 UTC (permalink / raw)
To: Linux Kernel Mailing List
Is there a general solution to the case of read() being called minimum
twice for a file in /proc? I have a small file in /proc, whose data takes
a fair time to generate. My read() handler gets called once for the data,
and once so I can return 0 to terminate read().
This results in the actual read taking twice as long. Perhaps I am missing
something...
--
Tim Hockin
Systems Software Engineer
Sun Microsystems, Cobalt Server Appliances
thockin@sun.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: read() called twice for /proc files
2001-09-25 1:29 Tim Hockin
@ 2001-09-25 1:35 ` David S. Miller
0 siblings, 0 replies; 4+ messages in thread
From: David S. Miller @ 2001-09-25 1:35 UTC (permalink / raw)
To: thockin; +Cc: linux-kernel
From: Tim Hockin <thockin@sun.com>
Date: Mon, 24 Sep 2001 18:29:49 -0700
This results in the actual read taking twice as long. Perhaps I am missing
something...
EOF isn't known until you return the zero. You can watch the loff_t
arg to the read operation to see if it is at the end, and if so just
avoid retouching the device or whatever and go straight to returning
0.
Franks a lot,
David S. Miller
davem@redhat.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2001-09-25 2:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-09-25 1:34 read() called twice for /proc files Tim Hockin
2001-09-25 2:16 ` Jonathan Lundell
-- strict thread matches above, loose matches on Subject: below --
2001-09-25 1:29 Tim Hockin
2001-09-25 1:35 ` David S. Miller
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.