From: Lennert Buytenhek
> Sent: 28 January 2021 23:07
>
> On Sun, Jan 24, 2021 at 10:21:38PM +0000, David Laight wrote:
>
> > > One open question is whether IORING_OP_GETDENTS64 should be more like
> > > pread(2) and allow passing in a starting offset to read from the
> > > directory from. (This would require some more surgery in fs/readdir.c.)
> >
> > Since directories are seekable this ought to work.
> > Modulo horrid issues with 32bit file offsets.
>
> The incremental patch below does this. (It doesn't apply cleanly on
> top of v1 of the IORING_OP_GETDENTS patch as I have other changes in
> my tree -- I'm including it just to illustrate the changes that would
> make this work.)
>
> This change seems to work, and makes IORING_OP_GETDENTS take an
> explicitly specified directory offset (instead of using the file's
> ->f_pos), making it more like pread(2), and I like the change from
> a conceptual point of view, but it's a bit ugly around
> iterate_dir_use_ctx_pos(). Any thoughts on how to do this more
> cleanly (without breaking iterate_dir() semantics)?
I had a further thought...
I presume the basic operation is:
lock(file);
do_getents(); // Updates file->offset
unlock(file);
Which means you can implement an offset by saving, updating
and restoring file->offset while the lock is held.
This is a bit like the completely broken pread() in uclibc
which uses two lseek() calls to set and restore the offset.
Whoever wrote that needs shooting - worse than useless.
Glibc is as bad:
// Don't even ask what glibc's clock_nanosleep() does, you don't want
to know.
while (syscall(SYS_clock_nanosleep, CLOCK_MONOTONIC, TIMER_ABSTIME,
&ts, NULL)
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT,
UK
Registration No: 1397386 (Wales)