Commit c823501e authored by Marc-André Lureau's avatar Marc-André Lureau Committed by Markus Armbruster
Browse files

monitor: use qmp_find_command() (using generated qapi code)



Stop using the so-called 'middle' mode. Instead, use qmp_find_command()
from generated qapi commands registry. Update and fix the documentation
too.

Signed-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20160912091913.15831-10-marcandre.lureau@redhat.com>
Reviewed-by: default avatarMarkus Armbruster <armbru@redhat.com>
Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
parent b804dc3b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -312,7 +312,7 @@ $(qapi-modules) $(SRC_PATH)/scripts/qapi-event.py $(qapi-py)
qmp-commands.h qmp-marshal.c :\
$(qapi-modules) $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py \
		$(gen-out-type) -o "." -m $<, \
		$(gen-out-type) -o "." $<, \
		"  GEN   $@")
qmp-introspect.h qmp-introspect.c :\
$(qapi-modules) $(SRC_PATH)/scripts/qapi-introspect.py $(qapi-py)
+2 −6
Original line number Diff line number Diff line
@@ -127,7 +127,6 @@ following at the bottom:
    {
        .name       = "hello-world",
        .args_type  = "",
        .mhandler.cmd_new = qmp_marshal_hello_world,
    },

You're done. Now build qemu, run it as suggested in the "Testing" section,
@@ -179,7 +178,6 @@ The last step is to update the qmp-commands.hx file:
    {
        .name       = "hello-world",
        .args_type  = "message:s?",
        .mhandler.cmd_new = qmp_marshal_hello_world,
    },

Notice that the "args_type" member got our "message" argument. The character
@@ -454,12 +452,11 @@ There are a number of things to be noticed:
6. You have to include the "qmp-commands.h" header file in qemu-timer.c,
   otherwise qemu won't build

The last step is to add the correspoding entry in the qmp-commands.hx file:
The last step is to add the corresponding entry in the qmp-commands.hx file:

    {
        .name       = "query-alarm-clock",
        .args_type  = "",
        .mhandler.cmd_new = qmp_marshal_query_alarm_clock,
    },

Time to test the new command. Build qemu, run it as described in the "Testing"
@@ -518,7 +515,7 @@ in the monitor.c file. The entry for the "info alarmclock" follows:
        .args_type  = "",
        .params     = "",
        .help       = "show information about the alarm clock",
        .mhandler.info = hmp_info_alarm_clock,
        .mhandler.cmd = hmp_info_alarm_clock,
    },

To test this, run qemu and type "info alarmclock" in the user monitor.
@@ -605,7 +602,6 @@ To test this you have to add the corresponding qmp-commands.hx entry:
    {
        .name       = "query-alarm-methods",
        .args_type  = "",
        .mhandler.cmd_new = qmp_marshal_query_alarm_methods,
    },

Now Build qemu, run it as explained in the "Testing" section and try our new
+7 −7
Original line number Diff line number Diff line
@@ -1009,10 +1009,6 @@ static void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data,
}

/*
 * Note: right now, this function is never called.  It will be called
 * shortly when we stop using QAPI 'middle mode'.  The rest of this
 * comment is written as if that was the case already.
 *
 * We used to define commands in qmp-commands.hx in addition to the
 * QAPI schema.  This permitted defining some of them only in certain
 * configurations.  query-commands has always reflected that (good,
@@ -3976,6 +3972,7 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)
    QObject *obj, *data;
    QDict *input, *args;
    const mon_cmd_t *cmd;
    QmpCommand *qcmd;
    const char *cmd_name;
    Monitor *mon = cur_mon;

@@ -4001,7 +3998,8 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)
    cmd_name = qdict_get_str(input, "execute");
    trace_handle_qmp_command(mon, cmd_name);
    cmd = qmp_find_cmd(cmd_name);
    if (!cmd) {
    qcmd = qmp_find_command(cmd_name);
    if (!qcmd || !cmd) {
        error_set(&local_err, ERROR_CLASS_COMMAND_NOT_FOUND,
                  "The command %s has not been found", cmd_name);
        goto err_out;
@@ -4023,7 +4021,7 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)
        goto err_out;
    }

    cmd->mhandler.cmd_new(args, &data, &local_err);
    qcmd->fn(args, &data, &local_err);

err_out:
    monitor_protocol_emitter(mon, data, local_err);
@@ -4095,7 +4093,9 @@ static QObject *get_qmp_greeting(void)
    QObject *ver = NULL;

    qmp_marshal_query_version(NULL, &ver, NULL);
    return qobject_from_jsonf("{'QMP':{'version': %p,'capabilities': []}}",ver);

    return qobject_from_jsonf("{'QMP': {'version': %p, 'capabilities': []}}",
                              ver);
}

static void monitor_qmp_event(void *opaque, int event)
+0 −146

File changed.

Preview size limit exceeded, changes collapsed.

+1 −0
Original line number Diff line number Diff line
@@ -2987,6 +2987,7 @@ int main(int argc, char **argv, char **envp)
    qemu_init_exec_dir(argv[0]);

    module_call_init(MODULE_INIT_QOM);
    module_call_init(MODULE_INIT_QAPI);

    qemu_add_opts(&qemu_drive_opts);
    qemu_add_drive_opts(&qemu_legacy_drive_opts);