From 51b5cd1f3fcb8a39bd0453998b36a86b5f2d1dbd Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 31 Mar 2010 13:25:13 -0300 Subject: [PATCH 58/66] monitor: New argument type 'O' RH-Author: Markus Armbruster Message-id: <1270041921-28969-59-git-send-email-armbru@redhat.com> Patchwork-id: 8230 O-Subject: [PATCH 58/66] monitor: New argument type 'O' Bugzilla: 579470 RH-Acked-by: Kevin Wolf RH-Acked-by: Juan Quintela RH-Acked-by: Luiz Capitulino In the human monitor, it declares a single optional argument to be parsed according to the QemuOptsList given by its name. In QMP, it declares an optional argument for each member of the QemuOptsList. Restriction: only lists with empty desc are supported for now. Good enough for the job at hand. We'll lift the restriction when we need that. (cherry picked from commit 361127dfb48d7d6b6b8e2e5fa79160d92e740a44) --- monitor.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 50 insertions(+), 4 deletions(-) Signed-off-by: Eduardo Habkost --- monitor.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 50 insertions(+), 4 deletions(-) diff --git a/monitor.c b/monitor.c index 09f2211..fa21fe0 100644 --- a/monitor.c +++ b/monitor.c @@ -71,6 +71,11 @@ * 'F' filename * 'B' block device name * 's' string (accept optional quote) + * 'O' option string of the form NAME=VALUE,... + * parsed according to QemuOptsList given by its name + * Example: 'device:O' uses qemu_device_opts. + * Restriction: only lists with empty desc are supported + * TODO lift the restriction * 'i' 32 bit integer * 'l' target long (32 or 64 bit) * 'M' just like 'l', except in user mode the value is @@ -3691,6 +3696,31 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, qdict_put(qdict, key, qstring_from_str(buf)); } break; + case 'O': + { + QemuOptsList *opts_list; + QemuOpts *opts; + + opts_list = qemu_find_opts(key); + if (!opts_list || opts_list->desc->name) { + goto bad_type; + } + while (qemu_isspace(*p)) { + p++; + } + if (!*p) + break; + if (get_str(buf, sizeof(buf), &p) < 0) { + goto fail; + } + opts = qemu_opts_parse(opts_list, buf, 1); + if (!opts) { + goto fail; + } + qemu_opts_to_qdict(opts, qdict); + qemu_opts_del(opts); + } + break; case '/': { int count, format, size; @@ -4345,6 +4375,7 @@ static int check_arg(const CmdArgs *cmd_args, QDict *args) qint_from_int(qbool_get_int(qobject_to_qbool(value)))); } break; + case 'O': default: /* impossible */ abort(); @@ -4359,6 +4390,12 @@ static void cmd_args_init(CmdArgs *cmd_args) cmd_args->type = cmd_args->flag = cmd_args->optional = 0; } +static int check_opts(QemuOptsList *opts_list, QDict *args) +{ + assert(!opts_list->desc->name); + return 0; +} + /* * This is not trivial, we have to parse Monitor command's argument * type syntax to be able to check the arguments provided by clients. @@ -4371,6 +4408,7 @@ static int monitor_check_qmp_args(const mon_cmd_t *cmd, QDict *args) int err; const char *p; CmdArgs cmd_args; + QemuOptsList *opts_list; if (cmd->args_type == NULL) { return (qdict_size(args) == 0 ? 0 : -1); @@ -4378,6 +4416,7 @@ static int monitor_check_qmp_args(const mon_cmd_t *cmd, QDict *args) err = 0; cmd_args_init(&cmd_args); + opts_list = NULL; for (p = cmd->args_type;; p++) { if (*p == ':') { @@ -4386,16 +4425,23 @@ static int monitor_check_qmp_args(const mon_cmd_t *cmd, QDict *args) if (cmd_args.type == '-') { cmd_args.flag = *p++; cmd_args.optional = 1; + } else if (cmd_args.type == 'O') { + opts_list = qemu_find_opts(qstring_get_str(cmd_args.name)); + assert(opts_list); } else if (*p == '?') { cmd_args.optional = 1; p++; } assert(*p == ',' || *p == '\0'); - err = check_arg(&cmd_args, args); - - QDECREF(cmd_args.name); - cmd_args_init(&cmd_args); + if (opts_list) { + err = check_opts(opts_list, args); + opts_list = NULL; + } else { + err = check_arg(&cmd_args, args); + QDECREF(cmd_args.name); + cmd_args_init(&cmd_args); + } if (err < 0) { break; -- 1.7.0.3