[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [libnbd] More thoughts on callbacks and more

More thoughts on callbacks, etc. following on from:

Closure lifetimes

Closures could have a lifetime if we had a little bit of support from
the C library.  We would generate (from C only):

  nbd_set_free_<fn>_<closure> (nbd, free_closure);

which calls free_closure (user_data) as soon as the closure will no
longer be called by the library.  This function would be used to
decrement the refcount from Python or remove the global root from

Note this is a family of functions, eg:


corresponding to the debug_fn arg of nbd_set_debug_callback.  Luckily
they can all be generated along with the internal machinery to call

Buffer lifetimes

Similar to the above, persistent buffers (BytesPersist*) can
have lifetimes.

Remove nbd_add_close_callback

The above changes (actually, just the closure change) lets us remove

Fixing callback / cookie problem

I think an easier way to fix this would be to simply detect the
problematic situation and queue up the callback to be call the next
time the library is entered.  Detecting the situation is fairly easy -
we know the current cookie number, so can check it before we call the
completion function.  And calling the deferred callback(s) is easy
from the generated code.

The only questions in my mind are: (1) If this could cause a deadlock
because the caller is waiting for the completion signal before
reentering the library.  (2) If there's some implicit guarantee that
we should call the callback as easy as possible after the command

I think (1) is not possible in ordinary code since callers must always
enter the main loop after calling one of the nbd_aio_* functions.


Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]