Re: sys_write() racy for multi-threaded append?
From: Alan Cox
Date: Mon Mar 12 2007 - 21:22:29 EST
> Writing to a file from multiple processes is not usually the problem.
> Writing to a common "struct file" from multiple threads is.
Not normally because POSIX sensibly invented pread/pwrite. Forgot
preadv/pwritev but they did the basics and end of problem
> So what? My products are shipping _now_.
That doesn't inspire confidence.
> even funny. If POSIX mandates stupid shit, and application
> programmers don't read that part of the manual anyway (and don't code
> on that assumption in practice), to hell with POSIX. On many file
Thats funny, you were talking about quality a moment ago.
> descriptors, short writes simply can't happen -- and code that
There is almost no descriptor this is true for. Any file I/O can and will
end up short on disk full or resource limit exceeded or quota exceeded or
NFS server exploded or ...
And on the device side about the only thing with the vaguest guarantees
is pipe().
> purports to handle short writes but has never been exercised is
> arguably worse than code that simply bombs on short write. So if I
> can't shim in an induce-short-writes-randomly-on-purpose mechanism
> during development, I don't want short writes in production, period.
Easy enough to do and gcov plus dejagnu or similar tools will let you
coverage analyse the resulting test set and replay it.
> Sure -- until the one code path in a hundred that handles the "short
> write" case incorrectly gets traversed in production, after having
> gone untested in a development environment that used a different
> filesystem that never happened to trigger it.
Competent QA and testing people test all the returns in the manual as
well as all the returns they can find in the code. See ptrace(2) if you
don't want to do a lot of relinking and strace for some useful worked
examples of syscall hooking.
Alan
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/