[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] Add qemu_opts_validate() for post parsing validatio
From: |
Mark McLoughlin |
Subject: |
[Qemu-devel] [PATCH] Add qemu_opts_validate() for post parsing validation |
Date: |
Tue, 6 Oct 2009 12:17:03 +0100 |
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 <address@hidden>
---
qemu-option.c | 33 +++++++++++++++++++++++++++++++++
qemu-option.h | 1 +
2 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/qemu-option.c b/qemu-option.c
index 735259f..de41c06 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)
{
diff --git a/qemu-option.h b/qemu-option.h
index 525b9b6..666b666 100644
--- a/qemu-option.h
+++ b/qemu-option.h
@@ -115,6 +115,7 @@ int qemu_opts_set(QemuOptsList *list, const char *id,
const char *name, const char *value);
const char *qemu_opts_id(QemuOpts *opts);
void qemu_opts_del(QemuOpts *opts);
+int qemu_opts_validate(QemuOpts *opts, QemuOptDesc *desc);
int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char
*firstname);
QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, const char
*firstname);
--
1.6.2.5
- [Qemu-devel] [PATCH 00/19 v3] Port -net to QemuOpts, Mark McLoughlin, 2009/10/06
- [Qemu-devel] [PATCH] Don't assign a static string to NICInfo::model, Mark McLoughlin, 2009/10/06
- [Qemu-devel] [PATCH] Make NICInfo string fields non-const, Mark McLoughlin, 2009/10/06
- [Qemu-devel] [PATCH] Register rtc options for -set, Mark McLoughlin, 2009/10/06
- [Qemu-devel] [PATCH] Use qemu_strdup() for NICInfo string fields, Mark McLoughlin, 2009/10/06
- [Qemu-devel] [PATCH] Use qemu_strdup() for VLANClientState string fields, Mark McLoughlin, 2009/10/06
- [Qemu-devel] [PATCH] Make qemu_opts_parse() handle empty strings, Mark McLoughlin, 2009/10/06
- [Qemu-devel] [PATCH] Move memset() from net_client_uninit() to net_client_init(), Mark McLoughlin, 2009/10/06
- [Qemu-devel] [PATCH] Don't exit() in config_error(), Mark McLoughlin, 2009/10/06
- [Qemu-devel] [PATCH] Add qemu_opts_validate() for post parsing validation,
Mark McLoughlin <=
- [Qemu-devel] [PATCH] Make net_client_init() consume slirp_configs even on error, Mark McLoughlin, 2009/10/06
- [Qemu-devel] [PATCH] Remove bogus error message from qemu_opts_set(), Mark McLoughlin, 2009/10/06
- [Qemu-devel] [PATCH] Remove double error message in qemu_option_set(), Mark McLoughlin, 2009/10/06
- [Qemu-devel] [PATCH] Drop config_error(), use qemu_error() instead, Mark McLoughlin, 2009/10/06
- [Qemu-devel] [PATCH] Final net cleanup after conversion to QemuOpts, Mark McLoughlin, 2009/10/06
- [Qemu-devel] [PATCH] Remove double error message for -device option parsing, Mark McLoughlin, 2009/10/06
- [Qemu-devel] [PATCH] Never overwrite a QemuOpt, Mark McLoughlin, 2009/10/06
- [Qemu-devel] [PATCH] Port -net vde to QemuOpts, Mark McLoughlin, 2009/10/06
- [Qemu-devel] [PATCH] Port -net tap to QemuOpts, Mark McLoughlin, 2009/10/06
- [Qemu-devel] [PATCH] Port usb net to QemuOpts, Mark McLoughlin, 2009/10/06