Re: [Libguestfs] [PATCH nbdkit v2 06/10] python: Implement cache.

Eric Blake
Fri, 22 Nov 2019 21:50:20 -0000

On 11/22/19 1:54 PM, Richard W.M. Jones wrote:
> However this does not implement can_cache, since that is not a simple
> boolean.
> ---
>   plugins/python/nbdkit-python-plugin.pod | 14 +++++++++-
>   plugins/python/python.c                 | 34 +++++++++++++++++++++++++
>   2 files changed, 47 insertions(+), 1 deletion(-)
>

> +static int
> +py_cache (void *handle, uint32_t count, uint64_t offset, uint32_t flags)
> +{
> +  PyObject *obj = handle;
> +  PyObject *fn;
> +  PyObject *r;
> +
> +  if (callback_defined ("cache", &fn)) {
> +    PyErr_Clear ();
> +
> +    switch (py_api_version) {
> +    case 1:
> +      nbdkit_error ("%s can only be called when using api_version
>= 2",
> +                    "cache");
> +      return -1;

Why? The signature doesn't change.  Yes, it's unusual to write an API
version 1 C plugin that provides a .cache callback, but it is not
impossible.  Instead of erroring out, we could just always support this
function in both versions of Python plugin.

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