On Thu, Aug 15, 2019 at 06:57:01AM -0500, Eric Blake wrote:
On 8/15/19 4:56 AM, Richard W.M. Jones wrote:
> Previously the .free function of a callback was not called if the
> .callback field was NULL, because the callback as a whole would be
> considered to be "null".
>
> This change allows you to register callbacks where the .callback field
> is NULL, but the .free field is != NULL, meaning that the callback is
> freed after the last time it would have been used.
>
> This is mainly convenient for language bindings where we sometimes
> want to register a free function to clean up a persistent buffer, but
> we don't need the associated completion callback to be actually
> called.
> ---
> docs/libnbd.pod | 15 +++++++++++++++
> lib/internal.h | 18 +++++++++---------
> 2 files changed, 24 insertions(+), 9 deletions(-)
>
> +++ b/lib/internal.h
> @@ -274,20 +274,20 @@ struct command {
> };
>
> /* Test if a callback is "null" or not, and set it to null. */
> -#define CALLBACK_IS_NULL(cb) ((cb).callback == NULL)
> +#define CALLBACK_IS_NULL(cb) ((cb).callback == NULL && (cb).free ==
NULL)
Semantic change. In generator, you used CALLBACK_IS_NULL() for both
Closure and OClosure. For OClosure, the new semantics are still
correct. But for Closure, we now no longer return EFAULT when the
callback itself is missing but a .free was provided. This changes
pread_structured and block_status to accept NULL for the callback; which
is probably not a good idea.
I'm unclear on this. This is the point of the patch - that you can
register a callback which has no callback action but still performs
the free action, and that's not considered a null callback. (It's
considered to be a callback that does nothing and returns 0.) Does
something bad happen to those two calls in this case?
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/