[Top][All Lists]

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

Re: [Qemu-devel] RFC: Monitor high-level design

From: Anthony Liguori
Subject: Re: [Qemu-devel] RFC: Monitor high-level design
Date: Wed, 22 Sep 2010 08:18:10 -0500
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20100826 Lightning/1.0b1 Thunderbird/3.0.7

On 09/22/2010 07:32 AM, Markus Armbruster wrote:
Luiz Capitulino<address@hidden>  writes:

Hi there,

I was working on a detailed writeup about monitor's internals so that I could
get some guidance regarding monitor's internal design, but after today's call
I realized that we should discuss the general design first.

I think we have two options: the first (and better known) is to make HMP
(the human monitor) a QMP client. The other option would be to make QMP and
HMP monitor implementations.

Below I try to introduce both ideas, showing advantages and potential problems.
I've also tried drawing some nice diagrams. Please, be polite and appreciate
them whether you agree or not :-)

  1. HMP as a QMP client

     Very briefly, QMP would export a function called qmp_command(), which would
     be called by HMP handlers. This has been proposed by Anthony and a
     detailed description can be found at:


     When fully implemented, I think it would look like this:

                     | HMP |
                       /  \
                      /    \
                  |-----|   \
                  | QMP |    \
                  |-----|     \
                     |         \
                     |          \
                |---------|  |---------|
                | chardev |  | chardev |
                |---------|  |---------|

      HMP will need to handle its own chardev, so that it's able to output
      data to the user (and I guess command completion needs it too).

      However, it's important to notice that HMP won't be using QMP's chardev
      in any way. It's only there to show that QMP and HMP will handle their
      own chardevs.


        - QMP's interface is also used (and thus tested) internally
        - In theory HMP can be moved outside of QEMU


        - What to do with handlers that make no sense in QMP, like print,
          sum, etc?
I can't see why we must have a dogmatic "thou shalt not use anything but
QMP to implement HMP commands, ever" rule.

FWIW, print/sum can be easily implemented in terms of QMP commands.

It's not really necessary for every possibly HMP command to be implemented in terms of QMP. However, unless you can do everything in QMP that you can do in HMP, then people will be inclined to use HMP as a management interface.

So, the only real rule we should try to adopt is that QMP is at least as powerful as HMP. That should be our goal.
        - HMP can't be moved outside of QEMU, if we want that we'd have to
          write a new Monitor client (potentially in a different language,
          which is actually good)
I'd rather not worry about that now.

        - Not sure if HMP features like command completion will perfectly fit
Maybe I'm naive, but I figure that as long as the human monitor controls
its character device and knows enough about its own commands, it can do
completion pretty much the same way it does now.

Let's have a closer look at the human monitor:

     +---------------+   reads/writes
     | human monitor |<--------------->   character device
     +---------------+                          ^
             |                                  |
             | calls                            |
             |                                  |
             v                                  |
     +---------------+        writes            |
     | hmon handlers | -------------------------+

The "human monitor" box actually has identifiable sub-boxes:

* Command table: human monitor command description

* Several argument types: methods to parse, check, complete, ...

* Reader: read a line of input from character device

   - Readline, uses table for completion

* Parser: parse a line of input, uses table to parse arguments

* Executor: call the appropriate handler, uses table

The machine monitor (short: qmon) is pretty similar, actually.

* We read and parse JSON objects, not lines.

* We don't bother to set up completion.

* The qmon handlers don't write to the character device.  They return
   objects instead, to be written by the qmon executor.

Remember that we want qmon handlers to use proper internal interfaces to
do the real work.  In other words, qmon handlers should be fairly

I can think of three ways to write a human monitor handler:

1. Call a qmon handler, print the object it returns, suitably formatted.

2. Call the internal interfaces, just like qmon handlers do.  Print the

    This cut out the qmon handler middle-man.  Since the qmon handler is
    supposed to be trivial, this isn't a big deal.

3. Just do it.  I think that's fine for some commands that make sense
    only human monitor, like print.  Also fine for legacy commands
    scheduled for removal; we got more useful things to do than
    beautifying those.  The ones we want to keep we should convert to
    1. or 2.  Doing that early may be advisable to get the internal
    interfaces used, but it's not like "need to convert everything before
    anything works".

You see hmon doesn't use all of qmon, only qmon handlers, and even that
only with 1.  Can't see a layering issue there.

Yeah, I think what you describe makes perfect sense. As long as QMP is a thin wrapper around an API, and HMP also calls the API, then it's pretty clear that QMP is at least as powerful as HMP.

There might be a few weird commands that are just open coded in HMP. I don't think we should have a hard rule to avoid it but at the same time, it should be an exception.


Anthony Liguori

Now consider human command pass-through.  The qmon handler for the
pass-through command needs to pass a command string to a human monitor,
and capture its output to the character device.  Thus, it needs to use
hmon parser and executor, with a special character device to capture

There is no dependency cycle, because only the pass-through handler
depends on (parts of) hmon, and while hmon may depend on some qmon
handlers, the pass-through handler is not among them.

reply via email to

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