From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com, armbru@redhat.com
Subject: [Qemu-devel] [PATCH 3/4] QMP: Enforce capability negotiation rules
Date: Thu, 4 Feb 2010 18:10:06 -0200 [thread overview]
Message-ID: <1265314207-6323-4-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1265314207-6323-1-git-send-email-lcapitulino@redhat.com>
With this commit QMP will be started in Capabilities Negotiation
mode, where the only command allowed to run is 'qmp_capabilities'.
All other commands will return CommandNotFound error. Asynchronous
messages are not delivered either.
When 'qmp_capabilities' is successfully executed QMP enters in
Command mode, where all commands (except 'qmp_capabilities') are
allowed to run and asynchronous messages are delivered.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
monitor.c | 18 +++++++++++++++++-
1 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/monitor.c b/monitor.c
index 94fc685..a0ec7fc 100644
--- a/monitor.c
+++ b/monitor.c
@@ -153,6 +153,11 @@ Monitor *cur_mon = NULL;
static void monitor_command_cb(Monitor *mon, const char *cmdline,
void *opaque);
+static inline int qmp_cmd_mode(const Monitor *mon)
+{
+ return (mon->mc ? mon->mc->command_mode : 0);
+}
+
/* Return true if in control mode, false otherwise */
static inline int monitor_ctrl_mode(const Monitor *mon)
{
@@ -403,7 +408,7 @@ void monitor_protocol_event(MonitorEvent event, QObject *data)
}
QLIST_FOREACH(mon, &mon_list, entry) {
- if (monitor_ctrl_mode(mon)) {
+ if (monitor_ctrl_mode(mon) && qmp_cmd_mode(mon)) {
monitor_json_emitter(mon, QOBJECT(qmp));
}
}
@@ -4229,6 +4234,12 @@ static int monitor_check_qmp_args(const mon_cmd_t *cmd, QDict *args)
return err;
}
+static int invalid_qmp_mode(const Monitor *mon, const char *cmd_name)
+{
+ int is_cap = compare_cmd(cmd_name, "qmp_capabilities");
+ return (qmp_cmd_mode(mon) ? is_cap : !is_cap);
+}
+
static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
{
int err;
@@ -4268,6 +4279,11 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
cmd_name = qstring_get_str(qobject_to_qstring(obj));
+ if (invalid_qmp_mode(mon, cmd_name)) {
+ qemu_error_new(QERR_COMMAND_NOT_FOUND, cmd_name);
+ goto err_input;
+ }
+
/*
* XXX: We need this special case until we get info handlers
* converted into 'query-' commands
--
1.6.6
next prev parent reply other threads:[~2010-02-04 20:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-04 20:10 [Qemu-devel] [PATCH v2 0/4]: QMP capability negotiation support Luiz Capitulino
2010-02-04 20:10 ` [Qemu-devel] [PATCH 1/4] QMP: Add QEMU's version to the greeting message Luiz Capitulino
2010-02-10 19:29 ` Anthony Liguori
2010-02-04 20:10 ` [Qemu-devel] [PATCH 2/4] QMP: Introduce the qmp_capabilities command Luiz Capitulino
2010-02-04 20:10 ` Luiz Capitulino [this message]
2010-02-04 20:10 ` [Qemu-devel] [PATCH 4/4] QMP: spec: Capability negotiation updates Luiz Capitulino
2010-02-05 9:08 ` [Qemu-devel] [PATCH v2 0/4]: QMP capability negotiation support Markus Armbruster
-- strict thread matches above, loose matches on Subject: below --
2010-02-04 14:24 [Qemu-devel] [PATCH v1 " Luiz Capitulino
2010-02-04 14:24 ` [Qemu-devel] [PATCH 3/4] QMP: Enforce capability negotiation rules Luiz Capitulino
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1265314207-6323-4-git-send-email-lcapitulino@redhat.com \
--to=lcapitulino@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=armbru@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).