[Top][All Lists]

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

Re: [Qemu-devel] [PATCH v2 00/25] qmp: add async command type

From: Marc-André Lureau
Subject: Re: [Qemu-devel] [PATCH v2 00/25] qmp: add async command type
Date: Mon, 23 Jan 2017 06:27:29 -0500 (EST)


----- Original Message -----
> On Wed, Jan 18, 2017 at 08:03:07PM +0400, Marc-André Lureau wrote:
> > Hi,
> CCing Jeff Cody and John Snow, who have been working on generalizing
> Block Job APIs to generic background jobs.  There is some overlap
> between async commands and background jobs.

If you say so :) Did I miss a proposal or a discussion for async qmp commands?

> > One of initial design goals of QMP was to have "asynchronous command
> > completion" (http://wiki.qemu.org/Features/QAPI). Unfortunately, that
> > goal was not fully achieved, and some broken bits left were removed
> > progressively until commit 65207c59d that removed async command
> > support.
> > 
> > Note that qmp events are asynchronous messages, and must be handled
> > appropriately by the client: dispatch both reply and events after a
> > command is sent for example.
> > 
> > The benefits of async commands that can be trade-off depending on the
> > requirements are:
> > 
> > 1) allow the command handler to re-enter the main loop if the command
> > cannot be handled synchronously, or if it is long-lasting. This is
> > currently not possible and make some bugs such as rhbz#1230527 tricky
> > (see below) to solve.  Furthermore, many QMP commands do IO and could
> > be considered 'slow' and blocking today.
> > 
> > 2) allow concurrent commands and events. This mainly implies hanlding
> > concurrency in qemu and out-of-order replies for the client. As noted
> > earlier, a good qmp client already has to handle dispatching of
> > received messages (reply and events).
> > 
> > The traditional approach to solving the above in qemu is the following
> > scheme:
> > -> { "execute": "do-foo" }
> > <- { "return": {} }
> > <- { "event": "FOO_DONE" }
> > 
> > It has several flaws:
> > - FOO_DONE event has no semantic link with do-foo in the qapi
> >   schema. It is not simple to generalize that pattern when writing
> >   qmp clients. It makes documentation and usage harder.
> > - the FOO_DONE event has no clear association with the command that
> >   triggered it: commands/events have to come up with additional
> >   specific association schemes (ids, path etc)
> > - FOO_DONE is broadcasted to all clients, but they may have no way to
> >   interprete it or interest in it, or worse it may conflict with their
> >   own commands.
> > - the arguably useless empty reply return
> > 
> > For some cases, it makes sense to use that scheme, or a more complete
> > one: to have an "handler" associated with an on-going operation, that
> > can be queried, modified, cancelled etc (block jobs etc). Also, some
> > operations have a global side-effect, in which case that cmd+event
> > scheme is right, as all clients are listening for global events.
> > 
> > However, for the simple case where a client want to perform a "local
> > context" operation (dump, query etc), QAPI can easily do better
> > without resorting to this pattern: it can send the reply when the
> > operation is done. That would make QAPI schema, usage and
> > documentation more obvious.
> > 
> > The following series implements an async solution, by introducing a
> > context associated with a command, it can:
> > - defer the return
> > - return only to the caller (no broadcasted event)
> As long as replies/events have ids then clients can discard messages for
> ids they do not own.  

There is no guarantee about id conflict between clients, the id is generated by 
the client, usually with a simple increment. Although we could check for id 
conflicts in qemu, I think it is unnecessary and costly (for both client & 

> Let's err on the side of broadcasting so that
> clients can receive events after reconnecting to the monitor.

Sorry, what do you mean?

> Is there a specific case where broadcasting causes problems?

Fortunately, it seems all events today are global state change events, and not 
command replies (otherwise we could have reply conflicts). It was suggested to 
me to use the do-foo/FOO_DONE pattern, but it is not suitable for async command 
replies (see flaws above).

reply via email to

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