[Libguestfs] [nbdkit PATCH 1/3] server: Fix NBDKIT_ZERO_EMULATE from filters

Eric Blake eblake at redhat.com
Fri Jun 10 16:11:31 UTC 2022


On Fri, Jun 10, 2022 at 10:55:25AM -0500, Eric Blake wrote:
> When we turned the result of .can_zero into a tri-state for filters
> back in v1.16, the intention was that the backend would emulate by
> calling into .pwrite instead of .zero.  The nozero filter already had
> an implementation of that algorithm, but it needs to live in backend.c
> to be used by all filters, rather than repeatedly recoded in each
> filter that wants .zero support by .pwrite emulation.
> 
> Discovered because the luks filter asked for .pwrite emulation in
> .can_zero without providing a .zero override, resulting in:
> 
> $ qemu-img create -f luks --object secret,data=LETMEPASS,id=sec0 -o key-secret=sec0 encrypted.img 100M
> Formatting 'encrypted.img', fmt=luks size=104857600 key-secret=sec0
> $ rm -f data.img
> $ truncate -s 100M data.img
> $ nbdkit file encrypted.img --filter=luks passphrase=LETMEPASS --run 'nbdcopy data.img $nbd'
> nbdkit: backend.c:718: backend_zero: Assertion `c->can_zero > NBDKIT_ZERO_NONE' failed.
> write at offset 0 failed: Transport endpoint is not connected
> nbdkit: nbdkit command was killed by signal 6

Do you want me to add this into 'make check' as test-luks-copy.sh or similar?

> 
> As a result of moving it into the backend, the nozero filter is
> simplified, but the corresponding test has to change.  Since
> --filter=log does not alter .can_zero, the emulation actually occurs
> earlier in the stack (prior to calling into any filter, regardless of
> whether log is placed before or after nozero, rather than at the point
> of the nozero filter), so there is now no discernable difference
> between sock3 and sock4 (we can eliminate the duplicate), and the old
> sock5a no longer shows a Zero request.  [Historically, when the nozero
> filter was first written, we were relying on qemu to send packets, and
> the use of the log filter was essential to ensure that we were getting
> the desired NBD_CMD_WRITE_ZEROES across various versions of qemu; but
> now that the test uses nbdkit, we know that h.zero() is doing exactly

nbdsh

> that, so the reduced length of the testsuite is no longer risky.]
> 
> Reported-by: Richard W.M. Jones <rjones at redhat.com>
> Fixes: fd361554 ("filters: Cache and change semantics of can_zero", v1.15.1)
> ---

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


More information about the Libguestfs mailing list