[Libguestfs] [PATCH nbdkit 3/3] server: filters: Remove struct b_h.

Eric Blake eblake at redhat.com
Wed Feb 12 13:56:38 UTC 2020


On 2/12/20 7:40 AM, Richard W.M. Jones wrote:
> This was previously used as ‘nxdata’ and stored a tuple of ’b->next’
> and the real filter handle.  However after recent changes we don't
> need it.  We can use ‘b->next’ as nxdata, and the handle is passed to
> us by the calling functions.
> 
> Inspired by Eric Blakes observations in this email:

Blake's

> https://www.redhat.com/archives/libguestfs/2020-February/msg00092.html
> ---
>   server/filters.c | 217 ++++++++++++++++-------------------------------
>   1 file changed, 73 insertions(+), 144 deletions(-)
> 

> @@ -216,201 +205,181 @@ plugin_magic_config_key (struct backend *b)
>   static int
>   next_open (void *nxdata, int readonly)
>   {
> -  struct b_h *b_h = nxdata;
> +  struct backend *b_next = nxdata;
>   
> -  return backend_open (b_h->b, readonly);
> +  return backend_open (b_next, readonly);
>   }

With this change, 'next_open' and '(int (*)(void *, int))backend_open' 
now have identical semantics.  I'm trying to see if there are further 
changes we could make that would alleviate the need for function casts. 
I don't know if it is worth changing nbdkit-filter.h to use 'struct 
backend *' instead of 'void *' (while leaving struct backend an 
incomplete type in the public header) - it would be ABI compatible, and 
although it would require recompilation, we already state that filter 
recompilation is par for the course (since only plugins promise API 
compatibility).

But one step at a time; your patch is fine as-is.
ACK


>   /* The next_functions structure contains pointers to backend
> - * functions.  However because these functions are all expecting a
> - * backend and a handle, we cannot call them directly, but must
> - * write some next_* functions that unpack the two parameters from a
> - * single ‘void *nxdata’ struct pointer (‘b_h’).
> + * functions.  These are only needed for type safety (nxdata is void
> + * pointer, backend_* functions expect a struct backend * parameter).
> + * nxdata is a pointer to the next backend in the linked list.
>    */
>   

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




More information about the Libguestfs mailing list