Re: [GIT PULL] 9p update for 5.7
From: Linus Torvalds
Date: Tue Apr 07 2020 - 13:59:25 EST
On Mon, Apr 6, 2020 at 7:16 PM L29Ah <l29ah@xxxxxxx> wrote:
>
> In fact i would prefer disabling the full reads unconditionally, but AFAIR some userspace programs might interpret a short read as EOF (and also would need to check the logic that motivated the kernel-side looping).
Oh, it's even worse than "might interpret a short read as EOF".
Lots of ad-hoc small tools will basically do something like
fd = open(name, O_RDONLY);
fstat(fd, &st);
buf = malloc(st.st_size);
read(fd, buf, st.st_size);
and be done with it. Obviously they may have some error handling (ie
imagine the above being written with proper tests for buf beign NULL
and 'fstat()' returning an error), but if they check the return value
of "read()" at all, it might be just to verify that it matches
st.st_size.
I've written stuff like that myself.
Sure, the "real" programs I write would have loops with EAGAIN and
partial reads, and maybe I'd have a helper function called "xread()"
that does that. And most major applications will do things like that,
exactly because they've seen years of development, they're trying to
be portable, and they might even have hit other network filesystems
that do partial reads or return EAGAIN - or they might have more
complex functionality anyway which allows you to pipe things in from a
buffer etc.
But the above kind of "assume read() gets the whole thing" is not
unusual for quick hacks.
After all, it's a _valid_ assumption for a proper POSIX filesystem,
although it obviously _also_ assumes that nobody else is writing to
that file at the same time.
And some of those quick hacks may end up existing for years in major
code-bases, who knows..
[ Honesty in advertising: the Linux VFS layer itself says "screw
POSIX" for some things.
Particularly, if somebody tries to do a read larger than 2GB in
size, the VFS layer will just say "POSIX is garbage in this situation,
we _will_ truncate this read".
So if you deal with huge files, you _have_ to do the proper "loop
until EOF" even for regular files, and POSIX be damned.
The kernel refuses to do crazy things, and no amount of standard
paperwork matters. ]
But basically honoring full reads for any _reasonable_ situation is
pretty much required for a lot of reasons. Yes, lots of apps will deal
gracefully with partial reads - maybe even most. But "lots" is not
"all".
Linus