summaryrefslogtreecommitdiff
path: root/qemu-option.c
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2009-10-06 12:17:03 +0100
committerAnthony Liguori <aliguori@us.ibm.com>2009-10-06 14:36:11 -0500
commit35e438b50a6bf156c20e5d13cd6d66ca3cf645c6 (patch)
treec15b1e5c919af84f8d936f6bacb21b5b3e08aad1 /qemu-option.c
parenta5d0920fe783584e8913d77f13c1e8521454bf9f (diff)
downloadqemu-35e438b50a6bf156c20e5d13cd6d66ca3cf645c6.tar.gz
qemu-35e438b50a6bf156c20e5d13cd6d66ca3cf645c6.tar.bz2
qemu-35e438b50a6bf156c20e5d13cd6d66ca3cf645c6.zip
Add qemu_opts_validate() for post parsing validation
Several qemu command line options have a parameter whose value affects what other parameters are accepted for the option. In these cases, we can have an empty description table in the QemuOptsList and once the option has been parsed we can use a suitable description table to validate the other parameters based on the value of that parameter. Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'qemu-option.c')
-rw-r--r--qemu-option.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/qemu-option.c b/qemu-option.c
index 735259f19d..de41c06ea5 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -778,6 +778,39 @@ QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, const char *fi
return opts;
}
+/* Validate parsed opts against descriptions where no
+ * descriptions were provided in the QemuOptsList.
+ */
+int qemu_opts_validate(QemuOpts *opts, QemuOptDesc *desc)
+{
+ QemuOpt *opt;
+
+ assert(opts->list->desc[0].name == NULL);
+
+ QTAILQ_FOREACH(opt, &opts->head, next) {
+ int i;
+
+ for (i = 0; desc[i].name != NULL; i++) {
+ if (strcmp(desc[i].name, opt->name) == 0) {
+ break;
+ }
+ }
+ if (desc[i].name == NULL) {
+ fprintf(stderr, "option \"%s\" is not valid for %s\n",
+ opt->name, opts->list->name);
+ return -1;
+ }
+
+ opt->desc = &desc[i];
+
+ if (qemu_opt_parse(opt) < 0) {
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
int abort_on_failure)
{