[Libguestfs] [nbdkit PATCH 2/3] tests: Add coverage of zero in language bindings

Eric Blake eblake at redhat.com
Thu Apr 5 19:11:53 UTC 2018


On 04/05/2018 01:54 PM, Eric Blake wrote:
> The existing test of language bindings was not covering any
> use of NBD_CMD_WRITE_ZEROES, making it harder to test changes
> to the plugin's zero callback.  Recent Linux kernels are now
> smart enough to turn fallocate(2) with FALLOC_FL_ZERO_RANGE
> into a SCSI WRITE SAME request, which qemu in turn converts
> into an NBD_CMD_WRITE_ZEROES.  Since libguestfs does not
> directly have an API for this, we have to use the backdoor
> of guestfs_debug and fallocate(1).  But inspecting logs such
> as tests/test-python.log, this change DOES prove that we
> got a client request for write zeroes, and that the fallback
> to pwrite due to test.py lacking a zero callback works.
> 
> Signed-off-by: Eric Blake <eblake at redhat.com>
> ---
>  tests/test-lang-plugins.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/tests/test-lang-plugins.c b/tests/test-lang-plugins.c
> index b695aaf..17e757b 100644
> --- a/tests/test-lang-plugins.c
> +++ b/tests/test-lang-plugins.c
> @@ -122,6 +122,13 @@ main (int argc, char *argv[])
>      exit (EXIT_FAILURE);
>  #endif
> 
> +  /* Run fallocate(1) on the device to test zero path. */
> +  if (guestfs_umount (g, "/") == 01)

That should be -1.

> +    exit (EXIT_FAILURE);
> +  const char *cmd[] = { "fallocate", "-nzl", "64k", "/dev/sda", NULL };
> +  char *s = guestfs_debug (g, "sh", (char **) cmd);
> +  free (s);
> +
>    if (guestfs_shutdown (g) == -1)
>      exit (EXIT_FAILURE);
> 

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20180405/bf3e925f/attachment.sig>


More information about the Libguestfs mailing list