On Wed, Aug 04, 2021 at 11:03:56AM +0100, Richard W.M. Jones wrote:
On Wed, Aug 04, 2021 at 10:45:36AM +0200, Martin Kletzander wrote:
On Mon, Jul 26, 2021 at 06:28:57PM +0100, Richard W.M. Jones wrote:
Although it probably cannot happen on Linux, POSIX allows pread/pwrite to return or write fewer bytes than requested. The cache and cow filters didn't handle this situation. Replace the raw pread(2)/pwrite(2) syscalls with alternate versions which can handle this.
+ssize_t +full_pwrite (int fd, const void *buf, size_t count, off_t offset) +{ + ssize_t ret = 0, r; + + while (count > 0) { + r = pwrite (fd, buf, count, offset); + if (r == -1) return -1; + ret += r; + offset += r; + count -= r; + } +
Shouldn't these continue on EINTR?
I'm not sure .. Eric?
The documentation for read(2) says this so it seems likely:
EINTR The call was interrupted by a signal before any data was read; see signal(7).
Yes, that's typical for wrapper implementations. I just checked that gnulib's full_rw() resumes on EINTR by virtue of using its safe_rw() wrapper (not that we can use gnulib's code in nbdkit, but rather to confirm that handling EINTR is common practice). -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org