* [Qemu-devel] [PATCH 1/2] qemu-option: Introduce default mechanism
@ 2012-01-27 18:54 Jan Kiszka
2012-01-27 18:55 ` [Qemu-devel] [PATCH 2/2] Improve default machine options usability Jan Kiszka
2012-02-01 22:11 ` [Qemu-devel] [PATCH 1/2] qemu-option: Introduce default mechanism Anthony Liguori
0 siblings, 2 replies; 3+ messages in thread
From: Jan Kiszka @ 2012-01-27 18:54 UTC (permalink / raw)
To: qemu-devel
This adds qemu_opts_set_defaults, an interface provide default values
for a QemuOpts set. Default options are parsed from a string and then
prepended to the list of existing options, or they serve as the sole
QemuOpts set.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
qemu-option.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++-------
qemu-option.h | 2 +
2 files changed, 52 insertions(+), 8 deletions(-)
diff --git a/qemu-option.c b/qemu-option.c
index a303f87..4626ccf 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -603,7 +603,8 @@ static void qemu_opt_del(QemuOpt *opt)
g_free(opt);
}
-int qemu_opt_set(QemuOpts *opts, const char *name, const char *value)
+static int opt_set(QemuOpts *opts, const char *name, const char *value,
+ bool prepend)
{
QemuOpt *opt;
const QemuOptDesc *desc = opts->list->desc;
@@ -626,7 +627,11 @@ int qemu_opt_set(QemuOpts *opts, const char *name, const char *value)
opt = g_malloc0(sizeof(*opt));
opt->name = g_strdup(name);
opt->opts = opts;
- QTAILQ_INSERT_TAIL(&opts->head, opt, next);
+ if (prepend) {
+ QTAILQ_INSERT_HEAD(&opts->head, opt, next);
+ } else {
+ QTAILQ_INSERT_TAIL(&opts->head, opt, next);
+ }
if (desc[i].name != NULL) {
opt->desc = desc+i;
}
@@ -640,6 +645,11 @@ int qemu_opt_set(QemuOpts *opts, const char *name, const char *value)
return 0;
}
+int qemu_opt_set(QemuOpts *opts, const char *name, const char *value)
+{
+ return opt_set(opts, name, value, false);
+}
+
int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val)
{
QemuOpt *opt;
@@ -691,6 +701,9 @@ QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id)
QTAILQ_FOREACH(opts, &list->head, next) {
if (!opts->id) {
+ if (!id) {
+ return opts;
+ }
continue;
}
if (strcmp(opts->id, id) != 0) {
@@ -806,7 +819,8 @@ int qemu_opts_print(QemuOpts *opts, void *dummy)
return 0;
}
-int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname)
+static int opts_do_parse(QemuOpts *opts, const char *params,
+ const char *firstname, bool prepend)
{
char option[128], value[1024];
const char *p,*pe,*pc;
@@ -841,7 +855,7 @@ int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname
}
if (strcmp(option, "id") != 0) {
/* store and parse */
- if (qemu_opt_set(opts, option, value) == -1) {
+ if (opt_set(opts, option, value, prepend) == -1) {
return -1;
}
}
@@ -852,8 +866,13 @@ int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname
return 0;
}
-QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params,
- int permit_abbrev)
+int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname)
+{
+ return opts_do_parse(opts, params, firstname, false);
+}
+
+static QemuOpts *opts_parse(QemuOptsList *list, const char *params,
+ int permit_abbrev, bool defaults)
{
const char *firstname;
char value[1024], *id = NULL;
@@ -870,11 +889,19 @@ QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params,
get_opt_value(value, sizeof(value), p+4);
id = value;
}
- opts = qemu_opts_create(list, id, 1);
+ if (defaults) {
+ if (!id && !QTAILQ_EMPTY(&list->head)) {
+ opts = qemu_opts_find(list, NULL);
+ } else {
+ opts = qemu_opts_create(list, id, 0);
+ }
+ } else {
+ opts = qemu_opts_create(list, id, 1);
+ }
if (opts == NULL)
return NULL;
- if (qemu_opts_do_parse(opts, params, firstname) != 0) {
+ if (opts_do_parse(opts, params, firstname, defaults) != 0) {
qemu_opts_del(opts);
return NULL;
}
@@ -882,6 +909,21 @@ QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params,
return opts;
}
+QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params,
+ int permit_abbrev)
+{
+ return opts_parse(list, params, permit_abbrev, false);
+}
+
+void qemu_opts_set_defaults(QemuOptsList *list, const char *params,
+ int permit_abbrev)
+{
+ QemuOpts *opts;
+
+ opts = opts_parse(list, params, permit_abbrev, true);
+ assert(opts);
+}
+
static void qemu_opts_from_qdict_1(const char *key, QObject *obj, void *opaque)
{
char buf[32];
diff --git a/qemu-option.h b/qemu-option.h
index 07958e4..e6f61e6 100644
--- a/qemu-option.h
+++ b/qemu-option.h
@@ -125,6 +125,8 @@ void qemu_opts_del(QemuOpts *opts);
int qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc);
int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname);
QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, int permit_abbrev);
+void qemu_opts_set_defaults(QemuOptsList *list, const char *params,
+ int permit_abbrev);
QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict);
QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict);
--
1.7.3.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [Qemu-devel] [PATCH 2/2] Improve default machine options usability
2012-01-27 18:54 [Qemu-devel] [PATCH 1/2] qemu-option: Introduce default mechanism Jan Kiszka
@ 2012-01-27 18:55 ` Jan Kiszka
2012-02-01 22:11 ` [Qemu-devel] [PATCH 1/2] qemu-option: Introduce default mechanism Anthony Liguori
1 sibling, 0 replies; 3+ messages in thread
From: Jan Kiszka @ 2012-01-27 18:55 UTC (permalink / raw)
To: qemu-devel
So far we overwrite the machine options completely with defaults if no
accel=value is provided. More user friendly is to fill in only
unspecified options. The new qemu_opts_set_defaults enables this.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
vl.c | 17 ++---------------
1 files changed, 2 insertions(+), 15 deletions(-)
diff --git a/vl.c b/vl.c
index 6af0f83..138f6bc 100644
--- a/vl.c
+++ b/vl.c
@@ -3153,21 +3153,8 @@ int main(int argc, char **argv, char **envp)
* specified either by the configuration file or by the command line.
*/
if (machine->default_machine_opts) {
- QemuOptsList *list = qemu_find_opts("machine");
- const char *p = NULL;
-
- if (!QTAILQ_EMPTY(&list->head)) {
- p = qemu_opt_get(QTAILQ_FIRST(&list->head), "accel");
- }
- if (p == NULL) {
- qemu_opts_reset(list);
- opts = qemu_opts_parse(list, machine->default_machine_opts, 0);
- if (!opts) {
- fprintf(stderr, "parse error for machine %s: %s\n",
- machine->name, machine->default_machine_opts);
- exit(1);
- }
- }
+ qemu_opts_set_defaults(qemu_find_opts("machine"),
+ machine->default_machine_opts, 0);
}
qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0);
--
1.7.3.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH 1/2] qemu-option: Introduce default mechanism
2012-01-27 18:54 [Qemu-devel] [PATCH 1/2] qemu-option: Introduce default mechanism Jan Kiszka
2012-01-27 18:55 ` [Qemu-devel] [PATCH 2/2] Improve default machine options usability Jan Kiszka
@ 2012-02-01 22:11 ` Anthony Liguori
1 sibling, 0 replies; 3+ messages in thread
From: Anthony Liguori @ 2012-02-01 22:11 UTC (permalink / raw)
To: Jan Kiszka; +Cc: qemu-devel
On 01/27/2012 12:54 PM, Jan Kiszka wrote:
> This adds qemu_opts_set_defaults, an interface provide default values
> for a QemuOpts set. Default options are parsed from a string and then
> prepended to the list of existing options, or they serve as the sole
> QemuOpts set.
>
> Signed-off-by: Jan Kiszka<jan.kiszka@siemens.com>
Applied. Thanks.
Regards,
Anthony Liguori
> ---
> qemu-option.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++-------
> qemu-option.h | 2 +
> 2 files changed, 52 insertions(+), 8 deletions(-)
>
> diff --git a/qemu-option.c b/qemu-option.c
> index a303f87..4626ccf 100644
> --- a/qemu-option.c
> +++ b/qemu-option.c
> @@ -603,7 +603,8 @@ static void qemu_opt_del(QemuOpt *opt)
> g_free(opt);
> }
>
> -int qemu_opt_set(QemuOpts *opts, const char *name, const char *value)
> +static int opt_set(QemuOpts *opts, const char *name, const char *value,
> + bool prepend)
> {
> QemuOpt *opt;
> const QemuOptDesc *desc = opts->list->desc;
> @@ -626,7 +627,11 @@ int qemu_opt_set(QemuOpts *opts, const char *name, const char *value)
> opt = g_malloc0(sizeof(*opt));
> opt->name = g_strdup(name);
> opt->opts = opts;
> - QTAILQ_INSERT_TAIL(&opts->head, opt, next);
> + if (prepend) {
> + QTAILQ_INSERT_HEAD(&opts->head, opt, next);
> + } else {
> + QTAILQ_INSERT_TAIL(&opts->head, opt, next);
> + }
> if (desc[i].name != NULL) {
> opt->desc = desc+i;
> }
> @@ -640,6 +645,11 @@ int qemu_opt_set(QemuOpts *opts, const char *name, const char *value)
> return 0;
> }
>
> +int qemu_opt_set(QemuOpts *opts, const char *name, const char *value)
> +{
> + return opt_set(opts, name, value, false);
> +}
> +
> int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val)
> {
> QemuOpt *opt;
> @@ -691,6 +701,9 @@ QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id)
>
> QTAILQ_FOREACH(opts,&list->head, next) {
> if (!opts->id) {
> + if (!id) {
> + return opts;
> + }
> continue;
> }
> if (strcmp(opts->id, id) != 0) {
> @@ -806,7 +819,8 @@ int qemu_opts_print(QemuOpts *opts, void *dummy)
> return 0;
> }
>
> -int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname)
> +static int opts_do_parse(QemuOpts *opts, const char *params,
> + const char *firstname, bool prepend)
> {
> char option[128], value[1024];
> const char *p,*pe,*pc;
> @@ -841,7 +855,7 @@ int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname
> }
> if (strcmp(option, "id") != 0) {
> /* store and parse */
> - if (qemu_opt_set(opts, option, value) == -1) {
> + if (opt_set(opts, option, value, prepend) == -1) {
> return -1;
> }
> }
> @@ -852,8 +866,13 @@ int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname
> return 0;
> }
>
> -QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params,
> - int permit_abbrev)
> +int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname)
> +{
> + return opts_do_parse(opts, params, firstname, false);
> +}
> +
> +static QemuOpts *opts_parse(QemuOptsList *list, const char *params,
> + int permit_abbrev, bool defaults)
> {
> const char *firstname;
> char value[1024], *id = NULL;
> @@ -870,11 +889,19 @@ QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params,
> get_opt_value(value, sizeof(value), p+4);
> id = value;
> }
> - opts = qemu_opts_create(list, id, 1);
> + if (defaults) {
> + if (!id&& !QTAILQ_EMPTY(&list->head)) {
> + opts = qemu_opts_find(list, NULL);
> + } else {
> + opts = qemu_opts_create(list, id, 0);
> + }
> + } else {
> + opts = qemu_opts_create(list, id, 1);
> + }
> if (opts == NULL)
> return NULL;
>
> - if (qemu_opts_do_parse(opts, params, firstname) != 0) {
> + if (opts_do_parse(opts, params, firstname, defaults) != 0) {
> qemu_opts_del(opts);
> return NULL;
> }
> @@ -882,6 +909,21 @@ QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params,
> return opts;
> }
>
> +QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params,
> + int permit_abbrev)
> +{
> + return opts_parse(list, params, permit_abbrev, false);
> +}
> +
> +void qemu_opts_set_defaults(QemuOptsList *list, const char *params,
> + int permit_abbrev)
> +{
> + QemuOpts *opts;
> +
> + opts = opts_parse(list, params, permit_abbrev, true);
> + assert(opts);
> +}
> +
> static void qemu_opts_from_qdict_1(const char *key, QObject *obj, void *opaque)
> {
> char buf[32];
> diff --git a/qemu-option.h b/qemu-option.h
> index 07958e4..e6f61e6 100644
> --- a/qemu-option.h
> +++ b/qemu-option.h
> @@ -125,6 +125,8 @@ void qemu_opts_del(QemuOpts *opts);
> int qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc);
> int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname);
> QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, int permit_abbrev);
> +void qemu_opts_set_defaults(QemuOptsList *list, const char *params,
> + int permit_abbrev);
> QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict);
> QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict);
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-02-01 22:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-27 18:54 [Qemu-devel] [PATCH 1/2] qemu-option: Introduce default mechanism Jan Kiszka
2012-01-27 18:55 ` [Qemu-devel] [PATCH 2/2] Improve default machine options usability Jan Kiszka
2012-02-01 22:11 ` [Qemu-devel] [PATCH 1/2] qemu-option: Introduce default mechanism Anthony Liguori
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.