On 8/12/19 9:08 AM, Eric Blake wrote:
Is the existing idea of a VALID|FREE parameter not sufficient? If
we
can convince the C bindings for python nbd.aio_pread to increase the
refcount of buf, and then install a C completion handler (whether the
python user called nbd.aio_pread with no python completer, or whether
they called nbd.aio_pread_complete) that does the decref when called
with FREE, then that would do the same job, even without the need for
nbd_add_free_callback, wouldn't it? And there's no issue of scanning
through a list of pointers with a free callback associated with them
(storing registered pointers with some sort of hash may eventually get
to amortized O(1) lookup, but that seems like a lot of overhead compared
to the fact that we already have O(1) access to when to call the
completion callback with the FREE flag).
Maybe we could add an OClosure optional argument to optargs, and pass
the callback closure as an optional argument (making it legal to pass
NULL instead of a closure in C, and making it so that other language
bindings can have a closure argument present or absent).
Thus, in Python, we'd allow any of:
h.aio_pread(buf, offset)
h.aio_pread(buf, offset, cb=callback)
h.aio_pread(buf, offset, flags=nbd.flag)
while the C API would always have to pass enough parameters:
nbd_aio_pread(h, buf, count, offset, callback, user_data, flags)
but maybe we could add a convenience macro:
#define nbd_aio_pread_easy(h, buf, count, offset) \
nbd_aio_pread(h, buf, count, offset, NULL, NULL, 0)
but it becomes easier to write the Python bindings, because whether or
not the python code passed in a Python callback, we still always use a C
completion callback to do proper inc/dec of the buf refcounts.
On the other hand, the above ideas are a rather large API change,
affecting fio and other existing clients. We'll have to think carefully
on how many variants the generator actually produces per language, and
whether or not we want Python bindings to use a simple name for all
cases, while the C API reserves the simple name for the least parameters
and uses a longer name when optional parameters are present.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization:
qemu.org |
libvirt.org