[Libguestfs] [PATCH libnbd 0/2] Use free callback to dereference NBD.Buffer.

Eric Blake eblake at redhat.com
Wed Aug 14 21:20:32 UTC 2019


On 8/14/19 2:31 PM, Richard W.M. Jones wrote:
> In this patch series we use the newly introduced free callback
> on the completion function to dererence the OCaml NBD.Buffer.
> I will make the same kind of change for Python later in a
> separate series.
> 
> The completion function is always called at the C level, even
> if the OCaml program didn't use the optional argument.  That's
> because the free callback doesn't run otherwise.
> 
> There is a case for having the free callback run even if there is no
> registered callback:
> 
>   nbd_aio_pread (nbd, buf, sizeof buf, 0,
>                  (nbd_completion_callback) { .callback = NULL,
>                                              .free = completion_free },

Presumably you'd also want some .user_data there?

If we are going to insist on a non-NULL .callback when .free is
non-NULL, that should probably be enforced by the generator for OClosure
(we are already ensured non-NULL .callback for Closure).

>                  0);
> 
> but the semantics of that are a bit weird.  Why would you need to
> "free" a callback which doesn't exist?  Would it be correct for the
> library to free the callback immediately, rather than after the
> theoretical completion callback would have run?

I could live with 'if .free is non-NULL, free(user_data) is called after
the point that callback would be used, regardless of whether .callback
was NULL'.  Perhaps my idea of consolidating free callbacks into just
retirement code will make that easier (because then we don't have the
mess of whether .callback has to be changed to NULL on the fly to track
whether .free still needs to be called; instead we set .free to NULL
once it is done).

-- 
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/20190814/d79612b9/attachment.sig>


More information about the Libguestfs mailing list