Eric Blake
2022-Jun-10 16:12 UTC
[Libguestfs] [nbdkit PATCH 3/3] tests: Add regression test for NBDKIT_EMULATE_CACHE fix
On Fri, Jun 10, 2022 at 10:55:27AM -0500, Eric Blake wrote:> Add testsuite coverage for the bug fixed in the previous patch (done > separately, to make it easier to prove the test fails without the > patch). > --- > tests/Makefile.am | 2 + > tests/test-eval-cache.sh | 85 ++++++++++++++++++++++++++++++++++++++++> +# This plugin requests nbdkit to emulate caching with pread. When the witness > +# file exists, cache reads; when absent, reads fail if not already cached. > +export witness="$PWD/eval-cache.witness" > +export cache="$PWD/eval-cache.cache" > +export script=' > +import os > +import errno > + > +witness = os.getenv("witness") > + > +def touch(path): > + open(path, "a").close() > + > +# Test that uncached read fails > +try: > + h.pread(1024 * 1024, 0) > +except nbd.Error as ex: > + assert ex.errnum == errno.EIO > + > +# Cache the entire image; nbdkit should break it into 64k preads64M preads> +touch(witness) > +h.cache(h.get_size(), 0) > +os.unlink(witness) > + > +# Now read should succeed > +buf = h.pread(64 * 1024 * 1024, 64 * 1024 * 1024) > +if hasattr(buf, "is_zero"): > + assert buf.is_zero() > +' > +nbdkit -U - -v eval \ > + get_size='echo 128M' can_cache='echo emulate' open='touch "$cache"' \ > + pread=' > + if test -f "$witness"; then > + echo "$3 $4" >> "$cache" > + elif ! grep -q "^$3 $4$" "$cache"; then > + echo EIO >&2; exit 1 > + fi > + dd if=/dev/zero count=$3 iflag=count_bytes > + ' --run 'nbdsh -u "$uri" -c "$script"'-- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Richard W.M. Jones
2022-Jun-10 16:21 UTC
[Libguestfs] [nbdkit PATCH 3/3] tests: Add regression test for NBDKIT_EMULATE_CACHE fix
Series looks good: Acked-by: Richard W.M. Jones <rjones at redhat.com> I think nbdkit-ext2-filter is still wrong (although at least it should no longer corrupt disk images) because it unnecessarily calls next->can_zero, so it might be worth dropping those two lines. Regression test for the LUKS case might be useful. But note that the test should not only check that zeroes work, but also that the result is still a LUKS image. The reason is that a naive fix for the earlier problem can (as I discovered) corrupt the disk image, because it will forward zeroes (eg to offset 0) straight through to the plugin. If this is too much, then I can write this test case tomorrow. Thanks! Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v