[Libguestfs] [PATCH nbdkit v2 3/4] sh: Switch nbdkit-sh-plugin to use API version 2.

Eric Blake eblake at redhat.com
Sat Dec 15 13:43:13 UTC 2018


On 12/15/18 5:01 AM, Richard W.M. Jones wrote:
> This allows us to add the following callbacks:
> 
>   - can_zero     returns boolean
>   - can_fua      should print "none", "emulate" or "native"
> 
> Furthermore the following callbacks are modified in a backwards
> compatible manner:
> 
>   - pwrite       adding flags parameter
>   - trim         adding flags parameter
> 
> This change is not backwards compatible:
> 
>   - zero         may_trim parameter replaced by flags parameter
> ---

> +=item C<can_fua>
> +
> + /path/to/script can_fua <handle>
> +
> +This controls Forced Unit Access (FUA) behaviour of the core server.
> +
> +Unlike the other C<can_*> callbacks, this one is I<not> a boolean.  It
> +must print either "none", "emulate" or "native" to stdout.  The
> +meaning of these is described in L<nbdkit-plugin(3)>.

Presumably we don't care if the user includes or omits a trailing 
newline on their output?


> +static int
> +sh_can_fua (void *handle)
> +{
> +  char *h = handle;
> +  const char *args[] = { script, "can_fua", h, NULL };
> +  char *s = NULL;
> +  size_t slen;
> +  int r;
> +
> +  switch (call_read (&s, &slen, args)) {
> +  case OK:
> +    if (slen > 0 && s[slen-1] == '\n')
> +      s[slen-1] = '\0';

Good - you do ignore trailing newline. Makes it easier for the author to 
not worry about it either way.

> +
> +  case RET_FALSE:
> +    free (s);
> +    nbdkit_error ("%s: %s method returned unexpected code (3/false)",
> +                  script, "can_fua");
> +    errno = EIO;
> +    return -1;
> +

So you decided not to take the suggestion of a false return being 
equivalent to a successful output of "none". I can live with that.

Series is looking good on my quick glance through.

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




More information about the Libguestfs mailing list