[Libguestfs] [PATCH nbdkit 4/7] cache, cow: Use full pread/pwrite operations

Eric Blake eblake at redhat.com
Mon Jul 26 20:51:19 UTC 2021


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.

Short reads and writes are unlikely to happen for regular files, but
are a definite possibility on named FIFOs, as well as block and char
devices.  While our local cache happens to use a regular file, it is
indeed always better practice to write robust code.

> ---
>  common/utils/Makefile.am |  1 +
>  common/utils/utils.h     |  2 +
>  common/utils/full-rw.c   | 81 ++++++++++++++++++++++++++++++++++++++++
>  filters/cache/blk.c      | 10 ++---
>  filters/cow/blk.c        |  6 +--
>  5 files changed, 92 insertions(+), 8 deletions(-)
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org




More information about the Libguestfs mailing list