On 29/09/20 09:45, Marc-André Lureau wrote: > Hi > > On Tue, Sep 22, 2020 at 9:08 PM Paolo Bonzini <pbonz...@redhat.com > <mailto:pbonz...@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... > 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. > 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 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 * etc. > Well, I wouldn't say it's not a problem. It makes working with QMP as a > client quite an unpleasant experience overall imho... With automatically-generated bindings, the experience writing a QMP client is as pleasant as the code generator makes it. Paolo