[Libguestfs] [PATCH libnbd 2/7] lib: Allow retired commands to use free_callback on their buffer.

Eric Blake eblake at redhat.com
Mon Aug 12 16:37:07 UTC 2019


On 8/12/19 11:08 AM, Richard W.M. Jones wrote:
> When retiring a command test for a free_callback associated with their
> buffer.  If there is one call it.  This allows language bindings to
> use this mechanism to automatically decrement a reference to the
> persistent buffer (note: this patch does not implement this).
> 
> The vast majority of this change is simply passing around the handle
> so we have it when we call nbd_internal_free_callback in lib/aio.c.
> ---

> +++ b/lib/aio.c
> @@ -29,7 +29,8 @@
>  
>  /* Internal function which retires and frees a command. */
>  void
> -nbd_internal_retire_and_free_command (struct command *cmd)
> +nbd_internal_retire_and_free_command (struct nbd_handle *h,
> +                                      struct command *cmd)
>  {
>    /* Free the callbacks. */
>    if (cmd->type == NBD_CMD_BLOCK_STATUS && cmd->cb.fn.extent)
> @@ -42,6 +43,11 @@ nbd_internal_retire_and_free_command (struct command *cmd)
>      cmd->cb.completion (LIBNBD_CALLBACK_FREE, cmd->cb.user_data,
>                          NULL);
>  
> +  /* Free the persistent buffer if there is one and if there's an
> +   * associated free callback.
> +   */
> +  nbd_internal_free_callback (h, cmd->data);
> +

Looks reasonable.

However, I'm also wondering if the later patches to adjust the language
bindings can instead guarantee a C struct which includes both the buffer
(which needs decrementing) and the language-specific callback (or NULL),
where the language binding for both nbd.aio_pread and
nbd.aio_pread_complete call the underlying C nbd_aio_pread_complete, so
we don't need to manage an O(n) list of pointers with associated callbacks.

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20190812/30aca580/attachment.sig>


More information about the Libguestfs mailing list