qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] PoC: Rust binding for QAPI (qemu-ga only, for now)


From: Marc-André Lureau
Subject: Re: [PATCH] PoC: Rust binding for QAPI (qemu-ga only, for now)
Date: Tue, 29 Sep 2020 14:34:26 +0400

Hi

On Tue, Sep 29, 2020 at 2:15 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
On 29/09/20 09:45, Marc-André Lureau wrote:
> Hi
>
> On Tue, Sep 22, 2020 at 9:08 PM Paolo Bonzini <pbonzini@redhat.com
> <mailto:pbonzini@redhat.com>> wrote:
>     > So a QEMU D-Bus interface could have a name like org.qemu.Qemu51,
>     > org.qemu.Qemu52.. for example, if we can't provide better API
>     stability...
>
>     That would be a problem for backports.
>
> Yes..  Backports could expose a subset of the new version interface? Or
> the interface can be divided for each Qmp command. (unorthodox)

That seems like a workaround for an IDL that is not the right solution
for the problem.

>        qapi::qga::commands::GuestShutdown::new()
>            .mode("halt")
>            .invoke_on(qapi_channel)?;
>
>
> Or simply use the same approach as qapi-rs
> (https://github.com/arcnmx/qapi-rs) which is  simply generating data
> structures based on the schema, and not binding commands to Rust
> functions for ex.
>
> qga.execute(&qga::guest_shutdown { mode: Some(GuestShutdownMode::Halt) })


That would not be backwards compatible as you would have to set all
optional fields.  Every time the command grows a new optional argument,
all clients would have to specify it; if a command becomes optional,
you'd have to add Some() around it.  So I would say that...


Not necessarily, with ..default::Default()

> Less idiomatic, but it also works around the optional arguments and
> ordering issue.

...  the builder pattern is not a workaround: it's the best and most
common Rust idiom to achieve what QAPI expresses as optional fields.
Likewise for keyword-only arguments in Python.

Except QAPI makes all fields potentially optional (and unordered), that's not idiomatic.
 
> Yes, the python binding will have a similar issue. And if we want to add
> typing to the mix, representing everything as a dict is not going to
> help much. Fortunately, there are other options I believe. But I would
> rather aim for the obvious, having non-optional & ordered arguments, and
> interface/methods versioning.

You shouldn't just state what you want; you really should take a look at
how the ability to add optional arguments has been used in the past, and
see if an alternative RPC without optional and unordered arguments would
have been as effective.  D-Bus is probably a perfectly good API for
qemu-ga.  The experience with qemu-ga however does not necessarily
extend to QEMU.

The main issue with D-Bus is that it conflates the transport and the IDL
so that you have to resort to passing arguments as key-value pairs.  QMP

D-Bus is machine-level oriented, it's easy to bind to various languages, it can be pretty efficient too. It's not designed to be a good network RPC. QMP tries to be a bit of both, but is perhaps not good enough in either.

does the same, but the IDL is much more flexible and not QEMU-specific,
so we don't pay as high a price.  Remember that while the specific
transport of QMP ("JSON dictionaries over a socket with 'execute' and
'arguments' keys") is QEMU-specific, the concept of using JSON payloads
for RPC is very common.  For example, REST APIs almost invariably use
JSON and the resulting API even "feel" somewhat similar to QMP.

In fact, The first Google result for "openapi backwards compatible
extensions"
(https://github.com/zalando/restful-api-guidelines/blob/master/chapters/compatibility.adoc#107)
might as well be written for QMP:

* [server] Add only optional, never mandatory fields.

* [client] Be tolerant with unknown fields in the payload

* [server] Unknown input fields in payload or URL should not be ignored

* [client] API clients consuming data must not assume that objects are
closed for extension

* [server] When changing your RESTful APIs, do so in a compatible way
and avoid generating additional API versions

* [server] MUST not use URI versioning

and so on.

If you want to "reinvent" QMP, instead of focusing on D-Bus you should
take a look at alternative IDLs and protocols (D-Bus is one but there's
also Protobuf and Flexbuffers), see how QAPI declarations would map to
those protocols, see how you would deal with extensibility, and rank
them according to various criteria.  For example:

* JSON "just works" but needs a custom code generator and imposes some
extra complexity on the clients for the simplest commands

* D-Bus has a good ecosystem and would keep simple commands simpler but
has issues with upgrade paths and is uglier for complex commands

* Protobufs probably would also just work and would have better code
generators, but would require some kind of lint to ensure
backwards-compatibility



Again, the issues we are discussing are not specific to binding QMP over D-Bus. Binding QMP to various languages has similar problems. Perhaps those problems are minor, perhaps we can find decent solutions, like the one you suggest to use Rust builder pattern for commands. I think they are not great, as I tried to explain with the versioning and runtime issues that you have to take into account anyway at the client level. I would rather make those problems solved at the server level, that doesn't require any change to QMP today, just a more careful consideration when making changes (and probably some tools to help enforce some stability).



--
Marc-André Lureau

reply via email to

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