Martin Kletzander
2021-Aug-06 12:07 UTC
[Libguestfs] [nbdkit PATCH] tests: Check that cache-min-block-size works properly
On Wed, Aug 04, 2021 at 04:48:08PM +0100, Richard W.M. Jones wrote:>On Wed, Aug 04, 2021 at 05:08:32PM +0200, Martin Kletzander wrote: >> Signed-off-by: Martin Kletzander <mkletzan at redhat.com> >> --- >> tests/test-cache-block-size.sh | 33 ++++++++++++++++++++++----------- >> 1 file changed, 22 insertions(+), 11 deletions(-) >> >> diff --git a/tests/test-cache-block-size.sh b/tests/test-cache-block-size.sh >> index d20cc94002b6..5e83ebc1cfaa 100755 >> --- a/tests/test-cache-block-size.sh >> +++ b/tests/test-cache-block-size.sh >> @@ -47,24 +47,35 @@ truncate -s 128K cache-block-size.img >> >> # Run nbdkit with the caching filter. >> start_nbdkit -P cache-block-size.pid -U $sock --filter=cache \ >> - file cache-block-size.img cache-min-block-size=4K >> + file cache-block-size.img cache-min-block-size=64K \ > >Because of commit c1905b0a2 ("cache, cow: Use a 64K block size by >default"), 64K is the default block size. So this doesn't test that >the parameter works. Maybe choose a different block size here? >I tried that it fails with 32K, but I can double all the numbers in this test if you want.>Rest of it is fine, so ACK, but better if the block size above was >changed. > >Rich. > >> + cache-on-read=true >> >> nbdsh --connect "nbd+unix://?socket=$sock" \ >> -c ' >> -# Write some pattern data to the overlay and check it reads back OK. >> -buf = b"abcd" * 16384 >> -h.pwrite(buf, 32768) >> +# Read half of cache-min-block-size >> + >> zero = h.pread(32768, 0) >> assert zero == bytearray(32768) >> -buf2 = h.pread(65536, 32768) >> -assert buf == buf2 >> >> -# Flushing should write through to the underlying file. >> -h.flush() >> +buf = b"abcd" * 8192 >> >> +# Write past the first read >> +with open("cache-block-size.img", "wb") as file: >> + file.seek(32768) >> + file.write(buf * 2) >> + file.truncate(131072) >> + >> +# Check that it got written >> with open("cache-block-size.img", "rb") as file: >> - zero = file.read(32768) >> - assert zero == bytearray(32768) >> + file.seek(32768) >> buf2 = file.read(65536) >> - assert buf == buf2 >> + assert (buf * 2) == buf2 >> + >> +# Now read the rest of the cache-min-block-size, it should stay empty >> +zero = h.pread(32768, 32768) >> +assert zero == bytearray(32768) >> + >> +# Read past that, the pattern should be visible there >> +buf2 = h.pread(32768, 65536) >> +assert buf == buf2 >> ' >> -- >> 2.32.0 > >-- >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 >-------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://listman.redhat.com/archives/libguestfs/attachments/20210806/dcaeff7e/attachment.sig>
Richard W.M. Jones
2021-Aug-06 12:19 UTC
[Libguestfs] [nbdkit PATCH] tests: Check that cache-min-block-size works properly
On Fri, Aug 06, 2021 at 02:07:37PM +0200, Martin Kletzander wrote:> On Wed, Aug 04, 2021 at 04:48:08PM +0100, Richard W.M. Jones wrote: > >On Wed, Aug 04, 2021 at 05:08:32PM +0200, Martin Kletzander wrote: > >>Signed-off-by: Martin Kletzander <mkletzan at redhat.com> > >>--- > >> tests/test-cache-block-size.sh | 33 ++++++++++++++++++++++----------- > >> 1 file changed, 22 insertions(+), 11 deletions(-) > >> > >>diff --git a/tests/test-cache-block-size.sh b/tests/test-cache-block-size.sh > >>index d20cc94002b6..5e83ebc1cfaa 100755 > >>--- a/tests/test-cache-block-size.sh > >>+++ b/tests/test-cache-block-size.sh > >>@@ -47,24 +47,35 @@ truncate -s 128K cache-block-size.img > >> > >> # Run nbdkit with the caching filter. > >> start_nbdkit -P cache-block-size.pid -U $sock --filter=cache \ > >>- file cache-block-size.img cache-min-block-size=4K > >>+ file cache-block-size.img cache-min-block-size=64K \ > > > >Because of commit c1905b0a2 ("cache, cow: Use a 64K block size by > >default"), 64K is the default block size. So this doesn't test that > >the parameter works. Maybe choose a different block size here? > > > > I tried that it fails with 32K, but I can double all the numbers in this > test if you want.It fails even after adjusting the test to cope with the different block size? Rich.> >Rest of it is fine, so ACK, but better if the block size above was > >changed. > > > >Rich. > > > >>+ cache-on-read=true > >> > >> nbdsh --connect "nbd+unix://?socket=$sock" \ > >> -c ' > >>-# Write some pattern data to the overlay and check it reads back OK. > >>-buf = b"abcd" * 16384 > >>-h.pwrite(buf, 32768) > >>+# Read half of cache-min-block-size > >>+ > >> zero = h.pread(32768, 0) > >> assert zero == bytearray(32768) > >>-buf2 = h.pread(65536, 32768) > >>-assert buf == buf2 > >> > >>-# Flushing should write through to the underlying file. > >>-h.flush() > >>+buf = b"abcd" * 8192 > >> > >>+# Write past the first read > >>+with open("cache-block-size.img", "wb") as file: > >>+ file.seek(32768) > >>+ file.write(buf * 2) > >>+ file.truncate(131072) > >>+ > >>+# Check that it got written > >> with open("cache-block-size.img", "rb") as file: > >>- zero = file.read(32768) > >>- assert zero == bytearray(32768) > >>+ file.seek(32768) > >> buf2 = file.read(65536) > >>- assert buf == buf2 > >>+ assert (buf * 2) == buf2 > >>+ > >>+# Now read the rest of the cache-min-block-size, it should stay empty > >>+zero = h.pread(32768, 32768) > >>+assert zero == bytearray(32768) > >>+ > >>+# Read past that, the pattern should be visible there > >>+buf2 = h.pread(32768, 65536) > >>+assert buf == buf2 > >> ' > >>-- > >>2.32.0 > > > >-- > >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 > >-- 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