[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 23/43] qemu-option: opt_set(): split it up into more
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 23/43] qemu-option: opt_set(): split it up into more functions |
Date: |
Thu, 13 Dec 2012 16:10:30 +0100 |
From: Dong Xu Wang <address@hidden>
The new functions are opts_accepts_any() and find_desc_by_name(), which
are also going to be used by qemu_opts_validate() (see next commit).
This also makes opt_set() slightly more readable.
Signed-off-by: Luiz Capitulino <address@hidden>
Signed-off-by: Dong Xu Wang <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
qemu-option.c | 40 ++++++++++++++++++++++++----------------
1 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/qemu-option.c b/qemu-option.c
index 27891e7..375daaa 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -602,26 +602,36 @@ static void qemu_opt_del(QemuOpt *opt)
g_free(opt);
}
-static void opt_set(QemuOpts *opts, const char *name, const char *value,
- bool prepend, Error **errp)
+static bool opts_accepts_any(const QemuOpts *opts)
+{
+ return opts->list->desc[0].name == NULL;
+}
+
+static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
+ const char *name)
{
- QemuOpt *opt;
- const QemuOptDesc *desc = opts->list->desc;
- Error *local_err = NULL;
int i;
for (i = 0; desc[i].name != NULL; i++) {
if (strcmp(desc[i].name, name) == 0) {
- break;
+ return &desc[i];
}
}
- if (desc[i].name == NULL) {
- if (i == 0) {
- /* empty list -> allow any */;
- } else {
- error_set(errp, QERR_INVALID_PARAMETER, name);
- return;
- }
+
+ return NULL;
+}
+
+static void opt_set(QemuOpts *opts, const char *name, const char *value,
+ bool prepend, Error **errp)
+{
+ QemuOpt *opt;
+ const QemuOptDesc *desc;
+ Error *local_err = NULL;
+
+ desc = find_desc_by_name(opts->list->desc, name);
+ if (!desc && !opts_accepts_any(opts)) {
+ error_set(errp, QERR_INVALID_PARAMETER, name);
+ return;
}
opt = g_malloc0(sizeof(*opt));
@@ -632,9 +642,7 @@ static void opt_set(QemuOpts *opts, const char *name, const
char *value,
} else {
QTAILQ_INSERT_TAIL(&opts->head, opt, next);
}
- if (desc[i].name != NULL) {
- opt->desc = desc+i;
- }
+ opt->desc = desc;
if (value) {
opt->str = g_strdup(value);
}
--
1.7.6.5
- [Qemu-devel] [PATCH 42/43] qcow2: Execute run_dependent_requests() without lock, (continued)
- [Qemu-devel] [PATCH 42/43] qcow2: Execute run_dependent_requests() without lock, Kevin Wolf, 2012/12/13
- [Qemu-devel] [PATCH 38/43] qcow2: Allocate l2meta dynamically, Kevin Wolf, 2012/12/13
- [Qemu-devel] [PATCH 40/43] qcow2: Allocate l2meta only for cluster allocations, Kevin Wolf, 2012/12/13
- [Qemu-devel] [PATCH 36/43] qcow2: Round QCowL2Meta.offset down to cluster boundary, Kevin Wolf, 2012/12/13
- [Qemu-devel] [PATCH 34/43] qemu-iotests: Test concurrent cluster allocations, Kevin Wolf, 2012/12/13
- [Qemu-devel] [PATCH 37/43] qcow2: Introduce Qcow2COWRegion, Kevin Wolf, 2012/12/13
- [Qemu-devel] [PATCH 25/43] qemu-option: qemu_opt_set_bool(): fix code duplication, Kevin Wolf, 2012/12/13
- [Qemu-devel] [PATCH 18/43] block: bdrv_img_create(): drop unused error handling code, Kevin Wolf, 2012/12/13
- [Qemu-devel] [PATCH 32/43] qemu-io: Add AIO debugging commands, Kevin Wolf, 2012/12/13
- [Qemu-devel] [PATCH 28/43] create new function: qemu_opt_set_number, Kevin Wolf, 2012/12/13
- [Qemu-devel] [PATCH 23/43] qemu-option: opt_set(): split it up into more functions,
Kevin Wolf <=