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 <[email protected]>
> ---
>  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

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Libguestfs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/libguestfs

Reply via email to