Re: [Libguestfs] [PATCH nbdkit v2 05/10] python: Share common code in boolean callbacks.

Eric Blake
Fri, 22 Nov 2019 21:46:56 -0000

On 11/22/19 1:54 PM, Richard W.M. Jones wrote:
> This change is pure refactoring and should have no effect.
> ---
>   plugins/python/nbdkit-python-plugin.pod | 12 ++--
>   plugins/python/python.c                 | 90 +++++--------------------
>   2 files changed, 24 insertions(+), 78 deletions(-)
>
> diff --git a/plugins/python/nbdkit-python-plugin.pod
b/plugins/python/nbdkit-python-plugin.pod
> index 51e0f57..0fd4dcb 100644
> --- a/plugins/python/nbdkit-python-plugin.pod
> +++ b/plugins/python/nbdkit-python-plugin.pod
> @@ -184,25 +184,25 @@ contents will be garbage collected.
>    def get_size(h):
>      # return the size of the disk
>
> -=item C<can_write>
> +=item C<is_rotational>
>
>   (Optional)
>
> - def can_write(h):
> + def is_rotational(h):
>      # return a boolean
>
> -=item C<can_flush>
> +=item C<can_write>
>
>   (Optional)
>
> - def can_flush(h):
> + def can_write(h):
>      # return a boolean
>
> -=item C<is_rotational>
> +=item C<can_flush>
>
>   (Optional)
>
> - def is_rotational(h):
> + def can_flush(h):
>      # return a boolean

Why the shuffle? To match ordering in other docs?  But not the end of
the world.

Otherwise, nice reduction in lines of code (it may get trickier with
can_FOO that return tristate, but for this patch you really did simplify
true bool/error return functions).

> @@ -812,9 +758,9 @@ static struct nbdkit_plugin plugin = {
>     .close             = py_close,
>
>     .get_size          = py_get_size,
> +  .is_rotational     = py_is_rotational,
>     .can_write         = py_can_write,
>     .can_flush         = py_can_flush,
> -  .is_rotational     = py_is_rotational,
>     .can_trim          = py_can_trim,
>
>     .pread             = py_pread,
>

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