[Libguestfs] [PATCH libnbd 4/7] lib: Allow closure user_data to be associated with a free callback.
Eric Blake
eblake at redhat.com
Mon Aug 12 17:05:53 UTC 2019
On 8/12/19 11:08 AM, Richard W.M. Jones wrote:
> Mechanical change: Wherever we call any closure with the
> LIBNBD_CALLBACK_FREE function, we also call nbd_internal_free_callback
> with the closure's user_data. This allows calls to associate a free
> callback with any closure via its user_data pointer.
> ---
> +++ b/lib/aio.c
> @@ -43,6 +43,10 @@ nbd_internal_retire_and_free_command (struct nbd_handle *h,
> cmd->cb.completion (LIBNBD_CALLBACK_FREE, cmd->cb.user_data,
> NULL);
>
> + /* Free the closures if there's an associated free callback. */
> + nbd_internal_free_callback (h, cmd->cb.fn_user_data);
This calls the fn_user_data callback too many times if it was already
reached. Instead, you need:
if (cmd->type == NBD_CMD_BLOCK_STATUS && cmd->cb.fn.extent) {
cmd->cb.fn.extent (_FREE...);
nbd_internal_free_callback (h, cmd->cb.fn_user_data);
}
else if (cmd->type == NBD_CMD_BLOCK_READ && cmd->cb.fn.chunk) {
cmd->cb.fn.chunk (_FREE...);
nbd_internal_free_callback (h, cmd->cb.fn_user_data);
}
--
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/f81618e1/attachment.sig>
More information about the Libguestfs
mailing list