qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH v2 06/15] qapi: move QEMU-specific dispatch code in monitor


From: Markus Armbruster
Subject: Re: [PATCH v2 06/15] qapi: move QEMU-specific dispatch code in monitor
Date: Tue, 02 Aug 2022 14:21:53 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)

Marc-André Lureau <marcandre.lureau@gmail.com> writes:

> Hi
>
> On Tue, Aug 2, 2022 at 3:04 PM Markus Armbruster <armbru@redhat.com> wrote:
>
>> marcandre.lureau@redhat.com writes:
>>
>> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
>> >
>> > Make QMP-dispatch code free from QEMU-specific OOB dispatch/async
>> > coroutine handling. This will allow to move the base code to
>> > qemu-common, and clear other users from potential mis-ususe (QGA doesn't
>>
>
> misuse :)

Right :)

>> have OOB or coroutine).
>>
>> I trust the utilty of such a move will become clear later in this
>> series.
>>
>> >
>> > To do that, introduce an optional callback QmpDispatchRun called when a
>> > QMP command should be run, to allow QEMU to override the default
>> > behaviour.
>> >
>> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

[...]

>> A callback works, but note that each program's function is fixed (the
>> simple and common function is inlined, but that's just for convenience).
>>
>> We could use the linker instead.  We already do for
>> qmp_command_available(), and the patch doesn't change that.
>>
>
> Tbh, using the linker override trick makes me a bit uncomfortable when
> trying to make a "common" qemu library.

This linker behavior goes back to when link archives / libraries were
invented half a century ago.  All of stubs/ relies on it.

> The "trick" is not well documented (I couldn't find a good reference for
> the expected behaviour,

I'd recommend John Levine's "Linkers and Loaders".  You can find an
archive of the unedited manuscript at

    https://archive.ph/20121205032107/http://www.iecc.com/linker/

Chapter 6 applies.

>                         and my experience with it isn't great when I
> struggled with linking issues earlier). It also makes the library usage a
> bit hidden.

I think the difficulty in understanding shifts.

With link-time resolution, the *possible* resolutions are obvious (by
name), but to see the *actual* resolution, you need to understand how
the program is linked.

With run-time resolution / callbacks, you need to understand run-time
behavior.  Can range from obvious to impossible.  Your use is certainly
obvious enough.

>             And it limits the full potential of the library to static
> linking.

Unix shared libraries make this work, too (they even pay a performance
price for it).  For instance, you can override malloc() in a statically
linked .o, and all the .so use it, unless they resort to dark magic to
break this.

> Callbacks are not always meant to be dynamically changeable.

True.  See my next paragraph :)

>> Perhaps a layering argument could be made for callbacks.  Before the
>> series, monitor/qmp.c's monitor_qmp_dispatch() calls
>> qapi/qmp-dispatch.c's qmp_dispatch(), which calls a few functions from
>> monitor/.  However, consistency seems desirable.
>>
>> What do you think?
>>
>
> No strong opinion, as long as the qemu-common project is internal to qemu
> projects. If we imagine the code can be made into a shared library, it will
> need callbacks.

We'll need several more callbacks for that, I'm afraid.

I'd go with link-time resolution for now, simply because that's what we
already use for qmp_command_available() & friends.

I don't like partial replacement by callbacks.  I figure a layering
argument could be made for complete replacement.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]