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