* [Qemu-devel] [v19 01/25] add def_value_str to QemuOptDesc
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
@ 2014-01-20 14:19 ` Chunyan Liu
2014-01-22 13:25 ` Kevin Wolf
2014-01-20 14:19 ` [Qemu-devel] [v19 02/25] qapi: output def_value_str when query command line options Chunyan Liu
` (24 subsequent siblings)
25 siblings, 1 reply; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:19 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
Add def_value_str (default value) to QemuOptDesc, to replace function of the
default value in QEMUOptionParameter. And improved related functions.
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
include/qemu/option.h | 3 +-
util/qemu-option.c | 76 ++++++++++++++++++++++++++++++++++++++++++------
2 files changed, 68 insertions(+), 11 deletions(-)
diff --git a/include/qemu/option.h b/include/qemu/option.h
index 3ea871a..2c5b03f 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -97,6 +97,7 @@ typedef struct QemuOptDesc {
const char *name;
enum QemuOptType type;
const char *help;
+ const char *def_value_str;
} QemuOptDesc;
struct QemuOptsList {
@@ -154,7 +155,7 @@ QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict);
void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp);
typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque);
-int qemu_opts_print(QemuOpts *opts, void *dummy);
+void qemu_opts_print(QemuOpts *opts);
int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
int abort_on_failure);
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 668e5d9..fd84f95 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -33,6 +33,9 @@
#include "qapi/qmp/qerror.h"
#include "qemu/option_int.h"
+static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
+ const char *name);
+
/*
* Extracts the name of an option from the parameter string (p points at the
* first byte of the option name)
@@ -507,6 +510,14 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)
const char *qemu_opt_get(QemuOpts *opts, const char *name)
{
QemuOpt *opt = qemu_opt_find(opts, name);
+ const QemuOptDesc *desc;
+
+ if (!opt) {
+ desc = find_desc_by_name(opts->list->desc, name);
+ if (desc && desc->def_value_str) {
+ return desc->def_value_str;
+ }
+ }
return opt ? opt->str : NULL;
}
@@ -525,9 +536,17 @@ bool qemu_opt_has_help_opt(QemuOpts *opts)
bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
{
QemuOpt *opt = qemu_opt_find(opts, name);
+ const QemuOptDesc *desc;
+ Error *local_err = NULL;
- if (opt == NULL)
+ if (opt == NULL) {
+ desc = find_desc_by_name(opts->list->desc, name);
+ if (desc && desc->def_value_str) {
+ parse_option_bool(name, desc->def_value_str, &defval, &local_err);
+ assert(!local_err);
+ }
return defval;
+ }
assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL);
return opt->value.boolean;
}
@@ -535,9 +554,17 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
{
QemuOpt *opt = qemu_opt_find(opts, name);
+ const QemuOptDesc *desc;
+ Error *local_err = NULL;
- if (opt == NULL)
+ if (opt == NULL) {
+ desc = find_desc_by_name(opts->list->desc, name);
+ if (desc && desc->def_value_str) {
+ parse_option_number(name, desc->def_value_str, &defval, &local_err);
+ assert(!local_err);
+ }
return defval;
+ }
assert(opt->desc && opt->desc->type == QEMU_OPT_NUMBER);
return opt->value.uint;
}
@@ -545,9 +572,17 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
{
QemuOpt *opt = qemu_opt_find(opts, name);
+ const QemuOptDesc *desc;
+ Error *local_err = NULL;
- if (opt == NULL)
+ if (opt == NULL) {
+ desc = find_desc_by_name(opts->list->desc, name);
+ if (desc && desc->def_value_str) {
+ parse_option_size(name, desc->def_value_str, &defval, &local_err);
+ assert(!local_err);
+ }
return defval;
+ }
assert(opt->desc && opt->desc->type == QEMU_OPT_SIZE);
return opt->value.uint;
}
@@ -846,17 +881,38 @@ void qemu_opts_del(QemuOpts *opts)
g_free(opts);
}
-int qemu_opts_print(QemuOpts *opts, void *dummy)
+void qemu_opts_print(QemuOpts *opts)
{
QemuOpt *opt;
+ QemuOptDesc *desc = opts->list->desc;
- fprintf(stderr, "%s: %s:", opts->list->name,
- opts->id ? opts->id : "<noid>");
- QTAILQ_FOREACH(opt, &opts->head, next) {
- fprintf(stderr, " %s=\"%s\"", opt->name, opt->str);
+ if (desc[0].name == NULL) {
+ QTAILQ_FOREACH(opt, &opts->head, next) {
+ printf("%s=\"%s\" ", opt->name, opt->str);
+ }
+ return;
+ }
+ for (; desc && desc->name; desc++) {
+ const char *value = desc->def_value_str;
+ QemuOpt *opt;
+
+ opt = qemu_opt_find(opts, desc->name);
+ if (opt) {
+ value = opt->str;
+ }
+
+ if (!value) {
+ continue;
+ }
+
+ if (desc->type == QEMU_OPT_STRING) {
+ printf("%s='%s' ", desc->name, value);
+ } else if (desc->type == QEMU_OPT_SIZE && opt) {
+ printf("%s=%" PRIu64 " ", desc->name, opt->value.uint);
+ } else {
+ printf("%s=%s ", desc->name, value);
+ }
}
- fprintf(stderr, "\n");
- return 0;
}
static int opts_do_parse(QemuOpts *opts, const char *params,
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* Re: [Qemu-devel] [v19 01/25] add def_value_str to QemuOptDesc
2014-01-20 14:19 ` [Qemu-devel] [v19 01/25] add def_value_str to QemuOptDesc Chunyan Liu
@ 2014-01-22 13:25 ` Kevin Wolf
0 siblings, 0 replies; 38+ messages in thread
From: Kevin Wolf @ 2014-01-22 13:25 UTC (permalink / raw)
To: Chunyan Liu; +Cc: Dong Xu Wang, qemu-devel, stefanha
Am 20.01.2014 um 15:19 hat Chunyan Liu geschrieben:
> Add def_value_str (default value) to QemuOptDesc, to replace function of the
> default value in QEMUOptionParameter. And improved related functions.
>
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
It would be worth mentioning that qemu_opts_print() is unused, so
changing the prototype and behaviour is fine.
> -int qemu_opts_print(QemuOpts *opts, void *dummy)
> +void qemu_opts_print(QemuOpts *opts)
> {
> QemuOpt *opt;
> + QemuOptDesc *desc = opts->list->desc;
>
> - fprintf(stderr, "%s: %s:", opts->list->name,
> - opts->id ? opts->id : "<noid>");
> - QTAILQ_FOREACH(opt, &opts->head, next) {
> - fprintf(stderr, " %s=\"%s\"", opt->name, opt->str);
> + if (desc[0].name == NULL) {
I think 'if (opts_accepts_any(opts))' would be more readable.
> + QTAILQ_FOREACH(opt, &opts->head, next) {
> + printf("%s=\"%s\" ", opt->name, opt->str);
> + }
> + return;
> + }
> + for (; desc && desc->name; desc++) {
> + const char *value = desc->def_value_str;
> + QemuOpt *opt;
> +
> + opt = qemu_opt_find(opts, desc->name);
> + if (opt) {
> + value = opt->str;
> + }
> +
> + if (!value) {
> + continue;
> + }
> +
> + if (desc->type == QEMU_OPT_STRING) {
> + printf("%s='%s' ", desc->name, value);
> + } else if (desc->type == QEMU_OPT_SIZE && opt) {
> + printf("%s=%" PRIu64 " ", desc->name, opt->value.uint);
This is so that a value like '64k' gets expanded to '65536'? Perhaps add
a comment?
> + } else {
> + printf("%s=%s ", desc->name, value);
> + }
> }
> - fprintf(stderr, "\n");
> - return 0;
> }
Kevin
^ permalink raw reply [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 02/25] qapi: output def_value_str when query command line options
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
2014-01-20 14:19 ` [Qemu-devel] [v19 01/25] add def_value_str to QemuOptDesc Chunyan Liu
@ 2014-01-20 14:19 ` Chunyan Liu
2014-01-20 15:53 ` Eric Blake
2014-01-20 14:19 ` [Qemu-devel] [v19 03/25] improve some functions in qemu-option.c Chunyan Liu
` (23 subsequent siblings)
25 siblings, 1 reply; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:19 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
Change qapi interfaces to output the newly added def_value_str when query
command line options.
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
qapi-schema.json | 8 ++++++--
qmp-commands.hx | 2 ++
util/qemu-config.c | 4 ++++
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/qapi-schema.json b/qapi-schema.json
index f27c48a..e0729ed 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3891,12 +3891,16 @@
#
# @help: #optional human readable text string, not suitable for parsing.
#
-# Since 1.5
+# @default: #optional string representation of the default used
+# if the option is omitted.
+#
+# Since 1.6
##
{ 'type': 'CommandLineParameterInfo',
'data': { 'name': 'str',
'type': 'CommandLineParameterType',
- '*help': 'str' } }
+ '*help': 'str',
+ '*default': 'str'} }
##
# @CommandLineOptionInfo:
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 02cc815..2f25256 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2742,6 +2742,8 @@ Each array entry contains the following:
or 'size')
- "help": human readable description of the parameter
(json-string, optional)
+ - "default": default value string for the parameter
+ (json-string, optional)
Example:
diff --git a/util/qemu-config.c b/util/qemu-config.c
index 7973659..c92d015 100644
--- a/util/qemu-config.c
+++ b/util/qemu-config.c
@@ -68,6 +68,10 @@ static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc)
info->has_help = true;
info->help = g_strdup(desc[i].help);
}
+ if (desc[i].def_value_str) {
+ info->has_q_default = true;
+ info->q_default = g_strdup(desc[i].def_value_str);
+ }
entry = g_malloc0(sizeof(*entry));
entry->value = info;
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* Re: [Qemu-devel] [v19 02/25] qapi: output def_value_str when query command line options
2014-01-20 14:19 ` [Qemu-devel] [v19 02/25] qapi: output def_value_str when query command line options Chunyan Liu
@ 2014-01-20 15:53 ` Eric Blake
0 siblings, 0 replies; 38+ messages in thread
From: Eric Blake @ 2014-01-20 15:53 UTC (permalink / raw)
To: Chunyan Liu, qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang
[-- Attachment #1: Type: text/plain, Size: 959 bytes --]
On 01/20/2014 07:19 AM, Chunyan Liu wrote:
> Change qapi interfaces to output the newly added def_value_str when query
> command line options.
>
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
> +++ b/qapi-schema.json
> @@ -3891,12 +3891,16 @@
> #
> # @help: #optional human readable text string, not suitable for parsing.
> #
> -# Since 1.5
> +# @default: #optional string representation of the default used
> +# if the option is omitted.
> +#
> +# Since 1.6
Not quite right. The overall type was still since 1.5, and only the new
member is since 2.0 (not 1.6). It should look more like:
# @default: #optional string representation of the default used if
# the option is omitted (since 2.0)
#
# Since 1.5
But I like the idea.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 03/25] improve some functions in qemu-option.c
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
2014-01-20 14:19 ` [Qemu-devel] [v19 01/25] add def_value_str to QemuOptDesc Chunyan Liu
2014-01-20 14:19 ` [Qemu-devel] [v19 02/25] qapi: output def_value_str when query command line options Chunyan Liu
@ 2014-01-20 14:19 ` Chunyan Liu
2014-01-22 13:33 ` Kevin Wolf
2014-01-20 14:19 ` [Qemu-devel] [v19 04/25] add some QemuOpts functions for replace work Chunyan Liu
` (22 subsequent siblings)
25 siblings, 1 reply; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:19 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
Improve opt_get and opt_set group of functions. For opt_get, check and handle
NUlL input; for opt_set, when set to an existing option, rewrite the option
with new value.
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
util/qemu-option.c | 80 ++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 66 insertions(+), 14 deletions(-)
diff --git a/util/qemu-option.c b/util/qemu-option.c
index fd84f95..8944b62 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -499,6 +499,9 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)
{
QemuOpt *opt;
+ if (!opts)
+ return NULL;
+
QTAILQ_FOREACH_REVERSE(opt, &opts->head, QemuOptHead, next) {
if (strcmp(opt->name, name) != 0)
continue;
@@ -509,9 +512,13 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)
const char *qemu_opt_get(QemuOpts *opts, const char *name)
{
- QemuOpt *opt = qemu_opt_find(opts, name);
+ QemuOpt *opt;
const QemuOptDesc *desc;
+ if (!opts)
+ return NULL;
+
+ opt = qemu_opt_find(opts, name);
if (!opt) {
desc = find_desc_by_name(opts->list->desc, name);
if (desc && desc->def_value_str) {
@@ -535,10 +542,15 @@ bool qemu_opt_has_help_opt(QemuOpts *opts)
bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
{
- QemuOpt *opt = qemu_opt_find(opts, name);
+ QemuOpt *opt;
const QemuOptDesc *desc;
Error *local_err = NULL;
+ if (!opts)
+ return defval;
+
+ opt = qemu_opt_find(opts, name);
+
if (opt == NULL) {
desc = find_desc_by_name(opts->list->desc, name);
if (desc && desc->def_value_str) {
@@ -553,10 +565,15 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
{
- QemuOpt *opt = qemu_opt_find(opts, name);
+ QemuOpt *opt;
const QemuOptDesc *desc;
Error *local_err = NULL;
+ if (!opts)
+ return defval;
+
+ opt = qemu_opt_find(opts, name);
+
if (opt == NULL) {
desc = find_desc_by_name(opts->list->desc, name);
if (desc && desc->def_value_str) {
@@ -571,10 +588,14 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
{
- QemuOpt *opt = qemu_opt_find(opts, name);
+ QemuOpt *opt;
const QemuOptDesc *desc;
Error *local_err = NULL;
+ if (!opts)
+ return defval;
+
+ opt = qemu_opt_find(opts, name);
if (opt == NULL) {
desc = find_desc_by_name(opts->list->desc, name);
if (desc && desc->def_value_str) {
@@ -612,6 +633,10 @@ static void qemu_opt_parse(QemuOpt *opt, Error **errp)
static void qemu_opt_del(QemuOpt *opt)
{
+ if (!opt) {
+ return;
+ }
+
QTAILQ_REMOVE(&opt->opts->head, opt, next);
g_free((/* !const */ char*)opt->name);
g_free((/* !const */ char*)opt->str);
@@ -664,6 +689,13 @@ static void opt_set(QemuOpts *opts, const char *name, const char *value,
return;
}
+ opt = qemu_opt_find(opts, name);
+ if (opt) {
+ g_free((char*)opt->str);
+ opt->str = g_strdup(value);
+ return;
+ }
+
opt = g_malloc0(sizeof(*opt));
opt->name = g_strdup(name);
opt->opts = opts;
@@ -704,16 +736,24 @@ void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val)
{
QemuOpt *opt;
- const QemuOptDesc *desc = opts->list->desc;
+ const QemuOptDesc *desc;
- opt = g_malloc0(sizeof(*opt));
- opt->desc = find_desc_by_name(desc, name);
- if (!opt->desc && !opts_accepts_any(opts)) {
+ desc = find_desc_by_name(opts->list->desc, name);
+ if (!desc && !opts_accepts_any(opts)) {
qerror_report(QERR_INVALID_PARAMETER, name);
- g_free(opt);
return -1;
}
+ opt = qemu_opt_find(opts, name);
+ if (opt) {
+ g_free((char*)opt->str);
+ opt->value.boolean =val;
+ opt->str = g_strdup(val ? "on" : "off");
+ return 0;
+ }
+
+ opt = g_malloc0(sizeof(*opt));
+ opt->desc = desc;
opt->name = g_strdup(name);
opt->opts = opts;
opt->value.boolean = !!val;
@@ -726,16 +766,24 @@ int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val)
int qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val)
{
QemuOpt *opt;
- const QemuOptDesc *desc = opts->list->desc;
+ const QemuOptDesc *desc;
- opt = g_malloc0(sizeof(*opt));
- opt->desc = find_desc_by_name(desc, name);
- if (!opt->desc && !opts_accepts_any(opts)) {
+ desc = find_desc_by_name(opts->list->desc, name);
+ if (!desc && !opts_accepts_any(opts)) {
qerror_report(QERR_INVALID_PARAMETER, name);
- g_free(opt);
return -1;
}
+ opt = qemu_opt_find(opts, name);
+ if (opt) {
+ g_free((char*)opt->str);
+ opt->value.uint = val;
+ opt->str = g_strdup_printf("%" PRId64, val);
+ return 0;
+ }
+
+ opt = g_malloc0(sizeof(*opt));
+ opt->desc = desc;
opt->name = g_strdup(name);
opt->opts = opts;
opt->value.uint = val;
@@ -870,6 +918,10 @@ void qemu_opts_del(QemuOpts *opts)
{
QemuOpt *opt;
+ if (!opts) {
+ return;
+ }
+
for (;;) {
opt = QTAILQ_FIRST(&opts->head);
if (opt == NULL)
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* Re: [Qemu-devel] [v19 03/25] improve some functions in qemu-option.c
2014-01-20 14:19 ` [Qemu-devel] [v19 03/25] improve some functions in qemu-option.c Chunyan Liu
@ 2014-01-22 13:33 ` Kevin Wolf
0 siblings, 0 replies; 38+ messages in thread
From: Kevin Wolf @ 2014-01-22 13:33 UTC (permalink / raw)
To: Chunyan Liu; +Cc: Dong Xu Wang, qemu-devel, stefanha
Am 20.01.2014 um 15:19 hat Chunyan Liu geschrieben:
> Improve opt_get and opt_set group of functions. For opt_get, check and handle
> NUlL input; for opt_set, when set to an existing option, rewrite the option
> with new value.
>
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
Why do we want to allow NULL opts? Silently ignoring NULL instead of
crashing leads to more subtle failure. Is there a legitimate user
passing NULL?
> util/qemu-option.c | 80 ++++++++++++++++++++++++++++++++++++++++++---------
> 1 files changed, 66 insertions(+), 14 deletions(-)
>
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index fd84f95..8944b62 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -499,6 +499,9 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)
> {
> QemuOpt *opt;
>
> + if (!opts)
> + return NULL;
The qemu coding style requires braces here (and in the following
instances).
> +
> QTAILQ_FOREACH_REVERSE(opt, &opts->head, QemuOptHead, next) {
> if (strcmp(opt->name, name) != 0)
> continue;
> @@ -509,9 +512,13 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)
>
> const char *qemu_opt_get(QemuOpts *opts, const char *name)
> {
> - QemuOpt *opt = qemu_opt_find(opts, name);
> + QemuOpt *opt;
> const QemuOptDesc *desc;
>
> + if (!opts)
> + return NULL;
> +
> + opt = qemu_opt_find(opts, name);
> if (!opt) {
> desc = find_desc_by_name(opts->list->desc, name);
> if (desc && desc->def_value_str) {
> @@ -535,10 +542,15 @@ bool qemu_opt_has_help_opt(QemuOpts *opts)
>
> bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
> {
> - QemuOpt *opt = qemu_opt_find(opts, name);
> + QemuOpt *opt;
> const QemuOptDesc *desc;
> Error *local_err = NULL;
>
> + if (!opts)
> + return defval;
> +
> + opt = qemu_opt_find(opts, name);
> +
> if (opt == NULL) {
> desc = find_desc_by_name(opts->list->desc, name);
> if (desc && desc->def_value_str) {
> @@ -553,10 +565,15 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
>
> uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
> {
> - QemuOpt *opt = qemu_opt_find(opts, name);
> + QemuOpt *opt;
> const QemuOptDesc *desc;
> Error *local_err = NULL;
>
> + if (!opts)
> + return defval;
> +
> + opt = qemu_opt_find(opts, name);
> +
> if (opt == NULL) {
> desc = find_desc_by_name(opts->list->desc, name);
> if (desc && desc->def_value_str) {
> @@ -571,10 +588,14 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
>
> uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
> {
> - QemuOpt *opt = qemu_opt_find(opts, name);
> + QemuOpt *opt;
> const QemuOptDesc *desc;
> Error *local_err = NULL;
>
> + if (!opts)
> + return defval;
> +
> + opt = qemu_opt_find(opts, name);
> if (opt == NULL) {
> desc = find_desc_by_name(opts->list->desc, name);
> if (desc && desc->def_value_str) {
> @@ -612,6 +633,10 @@ static void qemu_opt_parse(QemuOpt *opt, Error **errp)
>
> static void qemu_opt_del(QemuOpt *opt)
> {
> + if (!opt) {
> + return;
> + }
> +
> QTAILQ_REMOVE(&opt->opts->head, opt, next);
> g_free((/* !const */ char*)opt->name);
> g_free((/* !const */ char*)opt->str);
> @@ -664,6 +689,13 @@ static void opt_set(QemuOpts *opts, const char *name, const char *value,
> return;
> }
>
> + opt = qemu_opt_find(opts, name);
> + if (opt) {
> + g_free((char*)opt->str);
> + opt->str = g_strdup(value);
Why is qemu_opt_parse() not needed here?
> + return;
> + }
> +
> opt = g_malloc0(sizeof(*opt));
> opt->name = g_strdup(name);
> opt->opts = opts;
> @@ -704,16 +736,24 @@ void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
> int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val)
> {
> QemuOpt *opt;
> - const QemuOptDesc *desc = opts->list->desc;
> + const QemuOptDesc *desc;
>
> - opt = g_malloc0(sizeof(*opt));
> - opt->desc = find_desc_by_name(desc, name);
> - if (!opt->desc && !opts_accepts_any(opts)) {
> + desc = find_desc_by_name(opts->list->desc, name);
> + if (!desc && !opts_accepts_any(opts)) {
> qerror_report(QERR_INVALID_PARAMETER, name);
> - g_free(opt);
> return -1;
> }
>
> + opt = qemu_opt_find(opts, name);
> + if (opt) {
> + g_free((char*)opt->str);
> + opt->value.boolean =val;
Missing space after =
> + opt->str = g_strdup(val ? "on" : "off");
> + return 0;
> + }
> +
> + opt = g_malloc0(sizeof(*opt));
> + opt->desc = desc;
> opt->name = g_strdup(name);
> opt->opts = opts;
> opt->value.boolean = !!val;
Kevin
^ permalink raw reply [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 04/25] add some QemuOpts functions for replace work
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (2 preceding siblings ...)
2014-01-20 14:19 ` [Qemu-devel] [v19 03/25] improve some functions in qemu-option.c Chunyan Liu
@ 2014-01-20 14:19 ` Chunyan Liu
2014-01-22 13:57 ` Kevin Wolf
2014-01-20 14:19 ` [Qemu-devel] [v19 05/25] change block layer to support both QemuOpts and QEMUOptionParameter Chunyan Liu
` (21 subsequent siblings)
25 siblings, 1 reply; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:19 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
Add some qemu_opt functions to replace the same functionality of
QEMUOptionParameter handling.
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
include/qemu/option.h | 7 +++
util/qemu-option.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 138 insertions(+), 0 deletions(-)
diff --git a/include/qemu/option.h b/include/qemu/option.h
index 2c5b03f..8d77e2e 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -109,6 +109,7 @@ struct QemuOptsList {
};
const char *qemu_opt_get(QemuOpts *opts, const char *name);
+const char *qemu_opt_get_del(QemuOpts *opts, const char *name);
/**
* qemu_opt_has_help_opt:
* @opts: options to search for a help request
@@ -124,6 +125,9 @@ bool qemu_opt_has_help_opt(QemuOpts *opts);
bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval);
uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval);
uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval);
+bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval);
+uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name, uint64_t defval);
+uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name, uint64_t defval);
int qemu_opt_unset(QemuOpts *opts, const char *name);
int qemu_opt_set(QemuOpts *opts, const char *name, const char *value);
void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
@@ -159,4 +163,7 @@ void qemu_opts_print(QemuOpts *opts);
int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
int abort_on_failure);
+QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list);
+void qemu_opts_free(QemuOptsList *list);
+void qemu_opts_print_help(QemuOptsList *list);
#endif
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 8944b62..6bd5154 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -379,6 +379,72 @@ QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest,
return dest;
}
+static size_t count_opts_list(QemuOptsList *list)
+{
+ QemuOptDesc *desc = NULL;
+ size_t num_opts = 0;
+
+ if (!list)
+ return 0;
+
+ desc = list->desc;
+ while (desc && desc->name) {
+ num_opts ++;
+ desc ++;
+ }
+
+ return num_opts;
+}
+
+/* Create a new QemuOptsList with a desc of the merge of the first
+ * and second. It will allocate space for one new QemuOptsList plus
+ * enough space for QemuOptDesc in first and second QemuOptsList.
+ * First argument's QemuOptDesc members take precedence over second's.
+ * The result's name and implied_opt_name are not copied from them.
+ * Both merge_lists should not be set. Both lists can be NULL.
+ */
+QemuOptsList *qemu_opts_append(QemuOptsList *dst,
+ QemuOptsList *list)
+{
+ size_t num_opts, num_dst_opts;
+ QemuOptsList *tmp;
+ QemuOptDesc *desc;
+
+ if (!dst && !list)
+ return NULL;
+
+ num_opts = count_opts_list(dst);
+ num_opts += count_opts_list(list);
+
+ tmp = g_malloc0(sizeof(QemuOptsList) + (num_opts + 1) * sizeof(QemuOptDesc));
+ QTAILQ_INIT(&tmp->head);
+ num_dst_opts = 0;
+
+ /* copy dst->desc to new list */
+ if (dst) {
+ desc = dst->desc;
+ while (desc && desc->name) {
+ tmp->desc[num_dst_opts++] = *desc;
+ tmp->desc[num_dst_opts].name = NULL;
+ desc++;
+ }
+ }
+
+ /* add list->desc to new list */
+ if (list) {
+ desc = list->desc;
+ while (desc && desc->name) {
+ if (find_desc_by_name(tmp->desc, desc->name) == NULL) {
+ tmp->desc[num_dst_opts++] = *desc;
+ tmp->desc[num_dst_opts].name = NULL;
+ }
+ desc++;
+ }
+ }
+
+ return tmp;
+}
+
/*
* Parses a parameter string (param) into an option list (dest).
*
@@ -528,6 +594,18 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name)
return opt ? opt->str : NULL;
}
+static void qemu_opt_del(QemuOpt *opt);
+
+const char *qemu_opt_get_del(QemuOpts *opts, const char *name)
+{
+ const char *str = qemu_opt_get(opts, name);
+ QemuOpt *opt = qemu_opt_find(opts, name);
+ if (opt) {
+ qemu_opt_del(opt);
+ }
+ return str;
+}
+
bool qemu_opt_has_help_opt(QemuOpts *opts)
{
QemuOpt *opt;
@@ -563,6 +641,16 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
return opt->value.boolean;
}
+bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval)
+{
+ bool ret = qemu_opt_get_bool(opts, name, defval);
+ QemuOpt *opt = qemu_opt_find(opts, name);
+ if (opt) {
+ qemu_opt_del(opt);
+ }
+ return ret;
+}
+
uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
{
QemuOpt *opt;
@@ -586,6 +674,18 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
return opt->value.uint;
}
+uint64_t qemu_opt_get_number_del(QemuOpts *opts,
+ const char *name,
+ uint64_t defval)
+{
+ uint64_t ret = qemu_opt_get_number(opts, name, defval);
+ QemuOpt *opt = qemu_opt_find(opts, name);
+ if (opt) {
+ qemu_opt_del(opt);
+ }
+ return ret;
+}
+
uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
{
QemuOpt *opt;
@@ -608,6 +708,17 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
return opt->value.uint;
}
+uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name,
+ uint64_t defval)
+{
+ uint64_t ret = qemu_opt_get_size(opts, name, defval);
+ QemuOpt *opt = qemu_opt_find(opts, name);
+ if (opt) {
+ qemu_opt_del(opt);
+ }
+ return ret;
+}
+
static void qemu_opt_parse(QemuOpt *opt, Error **errp)
{
if (opt->desc == NULL)
@@ -1261,3 +1372,23 @@ int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
loc_pop(&loc);
return rc;
}
+
+/* free a QemuOptsList, can accept NULL as arguments */
+void qemu_opts_free(QemuOptsList *list)
+{
+ if (!list)
+ return;
+
+ g_free(list);
+}
+
+void qemu_opts_print_help(QemuOptsList *list)
+{
+ int i;
+ printf("Supported options:\n");
+ for (i = 0; list && list->desc[i].name; i++) {
+ printf("%-16s %s\n", list->desc[i].name,
+ list->desc[i].help ?
+ list->desc[i].help : "");
+ }
+}
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* Re: [Qemu-devel] [v19 04/25] add some QemuOpts functions for replace work
2014-01-20 14:19 ` [Qemu-devel] [v19 04/25] add some QemuOpts functions for replace work Chunyan Liu
@ 2014-01-22 13:57 ` Kevin Wolf
0 siblings, 0 replies; 38+ messages in thread
From: Kevin Wolf @ 2014-01-22 13:57 UTC (permalink / raw)
To: Chunyan Liu; +Cc: Dong Xu Wang, qemu-devel, stefanha
Am 20.01.2014 um 15:19 hat Chunyan Liu geschrieben:
> Add some qemu_opt functions to replace the same functionality of
> QEMUOptionParameter handling.
>
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
> include/qemu/option.h | 7 +++
> util/qemu-option.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 138 insertions(+), 0 deletions(-)
>
> diff --git a/include/qemu/option.h b/include/qemu/option.h
> index 2c5b03f..8d77e2e 100644
> --- a/include/qemu/option.h
> +++ b/include/qemu/option.h
> @@ -109,6 +109,7 @@ struct QemuOptsList {
> };
>
> const char *qemu_opt_get(QemuOpts *opts, const char *name);
> +const char *qemu_opt_get_del(QemuOpts *opts, const char *name);
> /**
> * qemu_opt_has_help_opt:
> * @opts: options to search for a help request
> @@ -124,6 +125,9 @@ bool qemu_opt_has_help_opt(QemuOpts *opts);
> bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval);
> uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval);
> uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval);
> +bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval);
> +uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name, uint64_t defval);
> +uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name, uint64_t defval);
> int qemu_opt_unset(QemuOpts *opts, const char *name);
> int qemu_opt_set(QemuOpts *opts, const char *name, const char *value);
> void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
> @@ -159,4 +163,7 @@ void qemu_opts_print(QemuOpts *opts);
> int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
> int abort_on_failure);
>
> +QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list);
> +void qemu_opts_free(QemuOptsList *list);
> +void qemu_opts_print_help(QemuOptsList *list);
> #endif
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index 8944b62..6bd5154 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -379,6 +379,72 @@ QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest,
> return dest;
> }
>
> +static size_t count_opts_list(QemuOptsList *list)
> +{
> + QemuOptDesc *desc = NULL;
> + size_t num_opts = 0;
> +
> + if (!list)
> + return 0;
Braces.
> +
> + desc = list->desc;
> + while (desc && desc->name) {
> + num_opts ++;
> + desc ++;
> + }
> +
> + return num_opts;
> +}
> +
> +/* Create a new QemuOptsList with a desc of the merge of the first
> + * and second. It will allocate space for one new QemuOptsList plus
> + * enough space for QemuOptDesc in first and second QemuOptsList.
> + * First argument's QemuOptDesc members take precedence over second's.
> + * The result's name and implied_opt_name are not copied from them.
> + * Both merge_lists should not be set. Both lists can be NULL.
> + */
> +QemuOptsList *qemu_opts_append(QemuOptsList *dst,
> + QemuOptsList *list)
You changed this function compared the qemu QEMUOptionParameter one in
that it creates a new list instead of modifying dst. I'm not objecting
to this change, but perhaps call it qemu_opts_concat() then.
> +{
> + size_t num_opts, num_dst_opts;
> + QemuOptsList *tmp;
> + QemuOptDesc *desc;
> +
> + if (!dst && !list)
> + return NULL;
Braces. Also, why is it allowed to pass NULL for list?
> +
> + num_opts = count_opts_list(dst);
> + num_opts += count_opts_list(list);
> +
> + tmp = g_malloc0(sizeof(QemuOptsList) + (num_opts + 1) * sizeof(QemuOptDesc));
This is longer than 80 characters.
> + QTAILQ_INIT(&tmp->head);
> + num_dst_opts = 0;
> +
> + /* copy dst->desc to new list */
> + if (dst) {
> + desc = dst->desc;
> + while (desc && desc->name) {
for (desc = dst->desc; desc && desc->name; desc++)
> + tmp->desc[num_dst_opts++] = *desc;
> + tmp->desc[num_dst_opts].name = NULL;
Not strictly necessary as you're using g_malloc0.
> + desc++;
> + }
> + }
> +
> + /* add list->desc to new list */
> + if (list) {
> + desc = list->desc;
> + while (desc && desc->name) {
> + if (find_desc_by_name(tmp->desc, desc->name) == NULL) {
> + tmp->desc[num_dst_opts++] = *desc;
> + tmp->desc[num_dst_opts].name = NULL;
> + }
> + desc++;
> + }
> + }
> +
> + return tmp;
> +}
> +
> /*
> * Parses a parameter string (param) into an option list (dest).
> *
> @@ -528,6 +594,18 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name)
> return opt ? opt->str : NULL;
> }
>
> +static void qemu_opt_del(QemuOpt *opt);
> +
> +const char *qemu_opt_get_del(QemuOpts *opts, const char *name)
> +{
> + const char *str = qemu_opt_get(opts, name);
> + QemuOpt *opt = qemu_opt_find(opts, name);
Somewhat inefficient to search the options list twice.
> + if (opt) {
> + qemu_opt_del(opt);
> + }
> + return str;
> +}
> +
> bool qemu_opt_has_help_opt(QemuOpts *opts)
> {
> QemuOpt *opt;
> @@ -563,6 +641,16 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
> return opt->value.boolean;
> }
>
> +bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval)
> +{
> + bool ret = qemu_opt_get_bool(opts, name, defval);
> + QemuOpt *opt = qemu_opt_find(opts, name);
> + if (opt) {
> + qemu_opt_del(opt);
> + }
> + return ret;
> +}
> +
> uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
> {
> QemuOpt *opt;
> @@ -586,6 +674,18 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
> return opt->value.uint;
> }
>
> +uint64_t qemu_opt_get_number_del(QemuOpts *opts,
> + const char *name,
> + uint64_t defval)
> +{
> + uint64_t ret = qemu_opt_get_number(opts, name, defval);
> + QemuOpt *opt = qemu_opt_find(opts, name);
> + if (opt) {
> + qemu_opt_del(opt);
> + }
> + return ret;
> +}
> +
> uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
> {
> QemuOpt *opt;
> @@ -608,6 +708,17 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
> return opt->value.uint;
> }
>
> +uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name,
> + uint64_t defval)
> +{
> + uint64_t ret = qemu_opt_get_size(opts, name, defval);
> + QemuOpt *opt = qemu_opt_find(opts, name);
> + if (opt) {
> + qemu_opt_del(opt);
> + }
> + return ret;
> +}
> +
> static void qemu_opt_parse(QemuOpt *opt, Error **errp)
> {
> if (opt->desc == NULL)
> @@ -1261,3 +1372,23 @@ int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
> loc_pop(&loc);
> return rc;
> }
> +
> +/* free a QemuOptsList, can accept NULL as arguments */
> +void qemu_opts_free(QemuOptsList *list)
> +{
> + if (!list)
> + return;
Is allowing to pass NULL useful? Also braces.
> +
> + g_free(list);
> +}
> +
> +void qemu_opts_print_help(QemuOptsList *list)
> +{
> + int i;
> + printf("Supported options:\n");
> + for (i = 0; list && list->desc[i].name; i++) {
> + printf("%-16s %s\n", list->desc[i].name,
> + list->desc[i].help ?
> + list->desc[i].help : "");
> + }
> +}
Kevin
^ permalink raw reply [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 05/25] change block layer to support both QemuOpts and QEMUOptionParameter
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (3 preceding siblings ...)
2014-01-20 14:19 ` [Qemu-devel] [v19 04/25] add some QemuOpts functions for replace work Chunyan Liu
@ 2014-01-20 14:19 ` Chunyan Liu
2014-01-22 14:19 ` Kevin Wolf
2014-01-20 14:19 ` [Qemu-devel] [v19 06/25] cow.c: replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (20 subsequent siblings)
25 siblings, 1 reply; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:19 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
Change block layer to support both QemuOpts and QEMUOptionParameter.
After this patch, it will change backend drivers one by one. At the end,
QEMUOptionParameter will be removed and only QemuOpts is kept.
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
block.c | 339 +++++++++++++++++++++++++++++++--------------
block/cow.c | 2 +-
block/qcow.c | 2 +-
block/qcow2.c | 2 +-
block/qed.c | 2 +-
block/raw_bsd.c | 2 +-
block/vhdx.c | 2 +-
block/vmdk.c | 4 +-
block/vvfat.c | 2 +-
include/block/block.h | 4 +-
include/block/block_int.h | 4 +-
qemu-img.c | 172 ++++++++++++++++-------
12 files changed, 372 insertions(+), 165 deletions(-)
diff --git a/block.c b/block.c
index 64e7d22..0dc0b09 100644
--- a/block.c
+++ b/block.c
@@ -395,6 +395,7 @@ typedef struct CreateCo {
BlockDriver *drv;
char *filename;
QEMUOptionParameter *options;
+ QemuOpts *opts;
int ret;
Error *err;
} CreateCo;
@@ -407,7 +408,10 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
CreateCo *cco = opaque;
assert(cco->drv);
- ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
+ if (cco->drv->bdrv_create2)
+ ret = cco->drv->bdrv_create2(cco->filename, cco->opts, &local_err);
+ else
+ ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
if (error_is_set(&local_err)) {
error_propagate(&cco->err, local_err);
}
@@ -415,7 +419,7 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
}
int bdrv_create(BlockDriver *drv, const char* filename,
- QEMUOptionParameter *options, Error **errp)
+ QEMUOptionParameter *options, QemuOpts *opts, Error **errp)
{
int ret;
@@ -424,11 +428,12 @@ int bdrv_create(BlockDriver *drv, const char* filename,
.drv = drv,
.filename = g_strdup(filename),
.options = options,
+ .opts = opts,
.ret = NOT_DONE,
.err = NULL,
};
- if (!drv->bdrv_create) {
+ if (!drv->bdrv_create && !drv->bdrv_create2) {
error_setg(errp, "Driver '%s' does not support image creation", drv->format_name);
ret = -ENOTSUP;
goto out;
@@ -460,7 +465,7 @@ out:
}
int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
- Error **errp)
+ QemuOpts *opts, Error **errp)
{
BlockDriver *drv;
Error *local_err = NULL;
@@ -472,7 +477,7 @@ int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
return -ENOENT;
}
- ret = bdrv_create(drv, filename, options, &local_err);
+ ret = bdrv_create(drv, filename, options, opts, &local_err);
if (error_is_set(&local_err)) {
error_propagate(errp, local_err);
}
@@ -1053,7 +1058,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
BlockDriverState *bs1;
int64_t total_size;
BlockDriver *bdrv_qcow2;
- QEMUOptionParameter *create_options;
+ QEMUOptionParameter *create_options = NULL;
+ QemuOpts *opts = NULL;
QDict *snapshot_options;
/* if snapshot, we create a temporary backing file and open it
@@ -1080,13 +1086,18 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
}
bdrv_qcow2 = bdrv_find_format("qcow2");
- create_options = parse_option_parameters("", bdrv_qcow2->create_options,
- NULL);
-
- set_option_parameter_int(create_options, BLOCK_OPT_SIZE, total_size);
+ if (bdrv_qcow2->bdrv_create2) {
+ opts = qemu_opts_create(bdrv_qcow2->create_opts, NULL, 0, &error_abort);
+ qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size);
+ } else {
+ create_options =
+ parse_option_parameters("", bdrv_qcow2->create_options, NULL);
+ set_option_parameter_int(create_options, BLOCK_OPT_SIZE, total_size);
+ }
- ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, &local_err);
+ ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, opts, &local_err);
free_option_parameters(create_options);
+ qemu_opts_del(opts);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not create temporary overlay "
"'%s': %s", tmp_filename,
@@ -4712,7 +4723,8 @@ void bdrv_img_create(const char *filename, const char *fmt,
Error **errp, bool quiet)
{
QEMUOptionParameter *param = NULL, *create_options = NULL;
- QEMUOptionParameter *backing_fmt, *backing_file, *size;
+ QemuOptsList *create_opts = NULL;
+ QemuOpts *opts = NULL;
BlockDriver *drv, *proto_drv;
BlockDriver *backing_drv = NULL;
Error *local_err = NULL;
@@ -4731,125 +4743,246 @@ void bdrv_img_create(const char *filename, const char *fmt,
return;
}
- create_options = append_option_parameters(create_options,
- drv->create_options);
- create_options = append_option_parameters(create_options,
- proto_drv->create_options);
+ if (drv->bdrv_create2) {
+ const char *backing_fmt, *backing_file;
+ int64_t size;
- /* Create parameter list with default values */
- param = parse_option_parameters("", create_options, param);
+ create_opts = qemu_opts_append(create_opts, drv->create_opts);
+ create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
+ /* Create parameter list with default values */
+ opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
- set_option_parameter_int(param, BLOCK_OPT_SIZE, img_size);
+ qemu_opt_set_number(opts, BLOCK_OPT_SIZE, img_size);
- /* Parse -o options */
- if (options) {
- param = parse_option_parameters(options, create_options, param);
- if (param == NULL) {
- error_setg(errp, "Invalid options for file format '%s'.", fmt);
- goto out;
+ /* Parse -o options */
+ if (options) {
+ if (qemu_opts_do_parse(opts, options, NULL) != 0) {
+ error_setg(errp, "Invalid options for file format '%s'.", fmt);
+ goto out;
+ }
}
- }
- if (base_filename) {
- if (set_option_parameter(param, BLOCK_OPT_BACKING_FILE,
- base_filename)) {
- error_setg(errp, "Backing file not supported for file format '%s'",
- fmt);
- goto out;
+ if (base_filename) {
+ if (qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename)) {
+ error_setg(errp, "Backing file not supported for file format '%s'",
+ fmt);
+ goto out;
+ }
}
- }
- if (base_fmt) {
- if (set_option_parameter(param, BLOCK_OPT_BACKING_FMT, base_fmt)) {
- error_setg(errp, "Backing file format not supported for file "
- "format '%s'", fmt);
- goto out;
+ if (base_fmt) {
+ if (qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt)) {
+ error_setg(errp, "Backing file format not supported for file "
+ "format '%s'", fmt);
+ goto out;
+ }
}
- }
- backing_file = get_option_parameter(param, BLOCK_OPT_BACKING_FILE);
- if (backing_file && backing_file->value.s) {
- if (!strcmp(filename, backing_file->value.s)) {
- error_setg(errp, "Error: Trying to create an image with the "
- "same filename as the backing file");
- goto out;
+ backing_file = qemu_opt_get(opts, BLOCK_OPT_BACKING_FILE);
+ if (backing_file) {
+ if (!strcmp(filename, backing_file)) {
+ error_setg(errp, "Error: Trying to create an image with the "
+ "same filename as the backing file");
+ goto out;
+ }
}
- }
- backing_fmt = get_option_parameter(param, BLOCK_OPT_BACKING_FMT);
- if (backing_fmt && backing_fmt->value.s) {
- backing_drv = bdrv_find_format(backing_fmt->value.s);
- if (!backing_drv) {
- error_setg(errp, "Unknown backing file format '%s'",
- backing_fmt->value.s);
- goto out;
+ backing_fmt = qemu_opt_get(opts, BLOCK_OPT_BACKING_FMT);
+ if (backing_fmt) {
+ backing_drv = bdrv_find_format(backing_fmt);
+ if (!backing_drv) {
+ error_setg(errp, "Unknown backing file format '%s'",
+ backing_fmt);
+ goto out;
+ }
+ }
+
+ // The size for the image must always be specified, with one exception:
+ // If we are using a backing file, we can obtain the size from there
+ size = qemu_opt_get_size(opts, BLOCK_OPT_SIZE, 0);
+ if (size == -1) {
+ if (backing_file) {
+ BlockDriverState *bs;
+ uint64_t size;
+ char buf[32];
+ int back_flags;
+
+ /* backing files always opened read-only */
+ back_flags =
+ flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
+
+ bs = bdrv_new("");
+
+ ret = bdrv_open(bs, backing_file, NULL, back_flags,
+ backing_drv, &local_err);
+ if (ret < 0) {
+ error_setg_errno(errp, -ret, "Could not open '%s': %s",
+ backing_file,
+ error_get_pretty(local_err));
+ error_free(local_err);
+ local_err = NULL;
+ bdrv_unref(bs);
+ goto out;
+ }
+ bdrv_get_geometry(bs, &size);
+ size *= 512;
+
+ snprintf(buf, sizeof(buf), "%" PRId64, size);
+ qemu_opt_set_number(opts, BLOCK_OPT_SIZE, size);
+
+ bdrv_unref(bs);
+ } else {
+ error_setg(errp, "Image creation needs a size parameter");
+ goto out;
+ }
+ }
+
+ if (!quiet) {
+ printf("Formatting '%s', fmt=%s ", filename, fmt);
+ qemu_opts_print(opts);
+ puts("");
+ }
+
+ ret = bdrv_create(drv, filename, NULL, opts, &local_err);
+ if (ret == -EFBIG) {
+ /* This is generally a better message than whatever the driver would
+ * deliver (especially because of the cluster_size_hint), since that
+ * is most probably not much different from "image too large". */
+ const char *cluster_size_hint = "";
+ if (qemu_opt_get_size(opts, BLOCK_OPT_CLUSTER_SIZE, 0)) {
+ cluster_size_hint = " (try using a larger cluster size)";
+ }
+ error_setg(errp, "The image size is too large for file format '%s'"
+ "%s", fmt, cluster_size_hint);
+ error_free(local_err);
+ local_err = NULL;
}
- }
- // The size for the image must always be specified, with one exception:
- // If we are using a backing file, we can obtain the size from there
- size = get_option_parameter(param, BLOCK_OPT_SIZE);
- if (size && size->value.n == -1) {
+ } else {
+ QEMUOptionParameter *backing_fmt, *backing_file, *size;
+
+ create_options = append_option_parameters(create_options,
+ drv->create_options);
+ create_options = append_option_parameters(create_options,
+ proto_drv->create_options);
+
+ /* Create parameter list with default values */
+ param = parse_option_parameters("", create_options, param);
+
+ set_option_parameter_int(param, BLOCK_OPT_SIZE, img_size);
+
+ /* Parse -o options */
+ if (options) {
+ param = parse_option_parameters(options, create_options, param);
+ if (param == NULL) {
+ error_setg(errp, "Invalid options for file format '%s'.", fmt);
+ goto out;
+ }
+ }
+
+ if (base_filename) {
+ if (set_option_parameter(param, BLOCK_OPT_BACKING_FILE,
+ base_filename)) {
+ error_setg(errp, "Backing file not supported for file format '%s'",
+ fmt);
+ goto out;
+ }
+ }
+
+ if (base_fmt) {
+ if (set_option_parameter(param, BLOCK_OPT_BACKING_FMT, base_fmt)) {
+ error_setg(errp, "Backing file format not supported for file "
+ "format '%s'", fmt);
+ goto out;
+ }
+ }
+
+ backing_file = get_option_parameter(param, BLOCK_OPT_BACKING_FILE);
if (backing_file && backing_file->value.s) {
- BlockDriverState *bs;
- uint64_t size;
- char buf[32];
- int back_flags;
+ if (!strcmp(filename, backing_file->value.s)) {
+ error_setg(errp, "Error: Trying to create an image with the "
+ "same filename as the backing file");
+ goto out;
+ }
+ }
- /* backing files always opened read-only */
- back_flags =
- flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
+ backing_fmt = get_option_parameter(param, BLOCK_OPT_BACKING_FMT);
+ if (backing_fmt && backing_fmt->value.s) {
+ backing_drv = bdrv_find_format(backing_fmt->value.s);
+ if (!backing_drv) {
+ error_setg(errp, "Unknown backing file format '%s'",
+ backing_fmt->value.s);
+ goto out;
+ }
+ }
- bs = bdrv_new("");
+ // The size for the image must always be specified, with one exception:
+ // If we are using a backing file, we can obtain the size from there
+ size = get_option_parameter(param, BLOCK_OPT_SIZE);
+ if (size && size->value.n == -1) {
+ if (backing_file && backing_file->value.s) {
+ BlockDriverState *bs;
+ uint64_t size;
+ char buf[32];
+ int back_flags;
+
+ /* backing files always opened read-only */
+ back_flags =
+ flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
+
+ bs = bdrv_new("");
+
+ ret = bdrv_open(bs, backing_file->value.s, NULL, back_flags,
+ backing_drv, &local_err);
+ if (ret < 0) {
+ error_setg_errno(errp, -ret, "Could not open '%s': %s",
+ backing_file->value.s,
+ error_get_pretty(local_err));
+ error_free(local_err);
+ local_err = NULL;
+ bdrv_unref(bs);
+ goto out;
+ }
+ bdrv_get_geometry(bs, &size);
+ size *= 512;
+
+ snprintf(buf, sizeof(buf), "%" PRId64, size);
+ set_option_parameter(param, BLOCK_OPT_SIZE, buf);
- ret = bdrv_open(bs, backing_file->value.s, NULL, back_flags,
- backing_drv, &local_err);
- if (ret < 0) {
- error_setg_errno(errp, -ret, "Could not open '%s': %s",
- backing_file->value.s,
- error_get_pretty(local_err));
- error_free(local_err);
- local_err = NULL;
bdrv_unref(bs);
+ } else {
+ error_setg(errp, "Image creation needs a size parameter");
goto out;
}
- bdrv_get_geometry(bs, &size);
- size *= 512;
-
- snprintf(buf, sizeof(buf), "%" PRId64, size);
- set_option_parameter(param, BLOCK_OPT_SIZE, buf);
+ }
- bdrv_unref(bs);
- } else {
- error_setg(errp, "Image creation needs a size parameter");
- goto out;
+ if (!quiet) {
+ printf("Formatting '%s', fmt=%s ", filename, fmt);
+ print_option_parameters(param);
+ puts("");
}
- }
- if (!quiet) {
- printf("Formatting '%s', fmt=%s ", filename, fmt);
- print_option_parameters(param);
- puts("");
- }
- ret = bdrv_create(drv, filename, param, &local_err);
- if (ret == -EFBIG) {
- /* This is generally a better message than whatever the driver would
- * deliver (especially because of the cluster_size_hint), since that
- * is most probably not much different from "image too large". */
- const char *cluster_size_hint = "";
- if (get_option_parameter(create_options, BLOCK_OPT_CLUSTER_SIZE)) {
- cluster_size_hint = " (try using a larger cluster size)";
+ ret = bdrv_create(drv, filename, param, NULL, &local_err);
+ if (ret == -EFBIG) {
+ /* This is generally a better message than whatever the driver would
+ * deliver (especially because of the cluster_size_hint), since that
+ * is most probably not much different from "image too large". */
+ const char *cluster_size_hint = "";
+ if (get_option_parameter(create_options, BLOCK_OPT_CLUSTER_SIZE)) {
+ cluster_size_hint = " (try using a larger cluster size)";
+ }
+ error_setg(errp, "The image size is too large for file format '%s'"
+ "%s", fmt, cluster_size_hint);
+ error_free(local_err);
+ local_err = NULL;
}
- error_setg(errp, "The image size is too large for file format '%s'"
- "%s", fmt, cluster_size_hint);
- error_free(local_err);
- local_err = NULL;
- }
+ }
out:
free_option_parameters(create_options);
free_option_parameters(param);
-
+ qemu_opts_del(opts);
+ qemu_opts_free(create_opts);
if (error_is_set(&local_err)) {
error_propagate(errp, local_err);
}
diff --git a/block/cow.c b/block/cow.c
index dc15e46..6318228 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -344,7 +344,7 @@ static int cow_create(const char *filename, QEMUOptionParameter *options,
options++;
}
- ret = bdrv_create_file(filename, options, &local_err);
+ ret = bdrv_create_file(filename, options, NULL, &local_err);
if (ret < 0) {
qerror_report_err(local_err);
error_free(local_err);
diff --git a/block/qcow.c b/block/qcow.c
index c470e05..be2a72e 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -684,7 +684,7 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options,
options++;
}
- ret = bdrv_create_file(filename, options, &local_err);
+ ret = bdrv_create_file(filename, options, NULL, &local_err);
if (ret < 0) {
qerror_report_err(local_err);
error_free(local_err);
diff --git a/block/qcow2.c b/block/qcow2.c
index 8ec9db1..e8b96cd 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1477,7 +1477,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
Error *local_err = NULL;
int ret;
- ret = bdrv_create_file(filename, options, &local_err);
+ ret = bdrv_create_file(filename, options, NULL, &local_err);
if (ret < 0) {
error_propagate(errp, local_err);
return ret;
diff --git a/block/qed.c b/block/qed.c
index 450a1fa..4221ee2 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -556,7 +556,7 @@ static int qed_create(const char *filename, uint32_t cluster_size,
int ret = 0;
BlockDriverState *bs = NULL;
- ret = bdrv_create_file(filename, NULL, &local_err);
+ ret = bdrv_create_file(filename, NULL, NULL, &local_err);
if (ret < 0) {
qerror_report_err(local_err);
error_free(local_err);
diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index 978ae7a..297e03f 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -139,7 +139,7 @@ static int raw_create(const char *filename, QEMUOptionParameter *options,
Error *local_err = NULL;
int ret;
- ret = bdrv_create_file(filename, options, &local_err);
+ ret = bdrv_create_file(filename, options, NULL, &local_err);
if (error_is_set(&local_err)) {
error_propagate(errp, local_err);
}
diff --git a/block/vhdx.c b/block/vhdx.c
index 1995778..c78675e 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -1791,7 +1791,7 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options,
block_size = block_size > VHDX_BLOCK_SIZE_MAX ? VHDX_BLOCK_SIZE_MAX :
block_size;
- ret = bdrv_create_file(filename, options, &local_err);
+ ret = bdrv_create_file(filename, options, NULL, &local_err);
if (ret < 0) {
error_propagate(errp, local_err);
goto exit;
diff --git a/block/vmdk.c b/block/vmdk.c
index c6b60b4..974eaff 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1463,7 +1463,7 @@ static int vmdk_create_extent(const char *filename, int64_t filesize,
uint32_t *gd_buf = NULL;
int gd_buf_size;
- ret = bdrv_create_file(filename, NULL, &local_err);
+ ret = bdrv_create_file(filename, NULL, NULL, &local_err);
if (ret < 0) {
error_propagate(errp, local_err);
goto exit;
@@ -1801,7 +1801,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
if (!split && !flat) {
desc_offset = 0x200;
} else {
- ret = bdrv_create_file(filename, options, &local_err);
+ ret = bdrv_create_file(filename, options, NULL, &local_err);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not create image file");
goto exit;
diff --git a/block/vvfat.c b/block/vvfat.c
index 664941c..c59cbdb 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2929,7 +2929,7 @@ static int enable_write_target(BDRVVVFATState *s)
set_option_parameter_int(options, BLOCK_OPT_SIZE, s->sector_count * 512);
set_option_parameter(options, BLOCK_OPT_BACKING_FILE, "fat:");
- ret = bdrv_create(bdrv_qcow, s->qcow_filename, options, &local_err);
+ ret = bdrv_create(bdrv_qcow, s->qcow_filename, options, NULL, &local_err);
if (ret < 0) {
qerror_report_err(local_err);
error_free(local_err);
diff --git a/include/block/block.h b/include/block/block.h
index 36efaea..687d423 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -174,9 +174,9 @@ BlockDriver *bdrv_find_format(const char *format_name);
BlockDriver *bdrv_find_whitelisted_format(const char *format_name,
bool readonly);
int bdrv_create(BlockDriver *drv, const char* filename,
- QEMUOptionParameter *options, Error **errp);
+ QEMUOptionParameter *options, QemuOpts *opts, Error **errp);
int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
- Error **errp);
+ QemuOpts *opts, Error **errp);
BlockDriverState *bdrv_new(const char *device_name);
void bdrv_make_anon(BlockDriverState *bs);
void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old);
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 2772f2f..f0043f8 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -105,6 +105,8 @@ struct BlockDriver {
void (*bdrv_rebind)(BlockDriverState *bs);
int (*bdrv_create)(const char *filename, QEMUOptionParameter *options,
Error **errp);
+ int (*bdrv_create2)(const char *filename, QemuOpts *opts,
+ Error **errp);
int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
int (*bdrv_make_empty)(BlockDriverState *bs);
/* aio */
@@ -204,7 +206,7 @@ struct BlockDriver {
/* List of options for creating images, terminated by name == NULL */
QEMUOptionParameter *create_options;
-
+ QemuOptsList *create_opts;
/*
* Returns 0 for completed check, -errno for internal errors.
diff --git a/qemu-img.c b/qemu-img.c
index c989850..05052d9 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -242,6 +242,7 @@ static int print_block_option_help(const char *filename, const char *fmt)
{
BlockDriver *drv, *proto_drv;
QEMUOptionParameter *create_options = NULL;
+ QemuOptsList *create_opts = NULL;
/* Find driver and parse its options */
drv = bdrv_find_format(fmt);
@@ -256,12 +257,19 @@ static int print_block_option_help(const char *filename, const char *fmt)
return 1;
}
- create_options = append_option_parameters(create_options,
- drv->create_options);
- create_options = append_option_parameters(create_options,
- proto_drv->create_options);
- print_option_help(create_options);
+ if (drv->bdrv_create2) {
+ create_opts = qemu_opts_append(create_opts, drv->create_opts);
+ create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
+ qemu_opts_print_help(create_opts);
+ } else {
+ create_options = append_option_parameters(create_options,
+ drv->create_options);
+ create_options = append_option_parameters(create_options,
+ proto_drv->create_options);
+ print_option_help(create_options);
+ }
free_option_parameters(create_options);
+ qemu_opts_free(create_opts);
return 0;
}
@@ -317,18 +325,21 @@ fail:
}
static int add_old_style_options(const char *fmt, QEMUOptionParameter *list,
+ QemuOpts *opts,
const char *base_filename,
const char *base_fmt)
{
if (base_filename) {
- if (set_option_parameter(list, BLOCK_OPT_BACKING_FILE, base_filename)) {
+ if ((opts && qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename)) ||
+ (list && set_option_parameter(list, BLOCK_OPT_BACKING_FILE, base_filename))) {
error_report("Backing file not supported for file format '%s'",
fmt);
return -1;
}
}
if (base_fmt) {
- if (set_option_parameter(list, BLOCK_OPT_BACKING_FMT, base_fmt)) {
+ if ((opts && qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt)) ||
+ (list && set_option_parameter(list, BLOCK_OPT_BACKING_FMT, base_fmt))) {
error_report("Backing file format not supported for file "
"format '%s'", fmt);
return -1;
@@ -1142,7 +1153,8 @@ static int img_convert(int argc, char **argv)
const uint8_t *buf1;
BlockDriverInfo bdi;
QEMUOptionParameter *param = NULL, *create_options = NULL;
- QEMUOptionParameter *out_baseimg_param;
+ QemuOpts *opts = NULL;
+ QemuOptsList *create_opts = NULL;
char *options = NULL;
const char *snapshot_name = NULL;
int min_sparse = 8; /* Need at least 4k of zeros for sparse detection */
@@ -1312,67 +1324,125 @@ static int img_convert(int argc, char **argv)
goto out;
}
- create_options = append_option_parameters(create_options,
- drv->create_options);
- create_options = append_option_parameters(create_options,
- proto_drv->create_options);
+ if (drv->bdrv_create2) {
+ const char *out_baseimg_param;
- if (options) {
- param = parse_option_parameters(options, create_options, param);
- if (param == NULL) {
+ create_opts = qemu_opts_append(create_opts, drv->create_opts);
+ create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
+ opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
+ if (options && qemu_opts_do_parse(opts, options, NULL)) {
error_report("Invalid options for file format '%s'.", out_fmt);
ret = -1;
goto out;
}
- } else {
- param = parse_option_parameters("", create_options, param);
- }
- set_option_parameter_int(param, BLOCK_OPT_SIZE, total_sectors * 512);
- ret = add_old_style_options(out_fmt, param, out_baseimg, NULL);
- if (ret < 0) {
- goto out;
- }
+ qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_sectors * 512);
+ ret = add_old_style_options(out_fmt, NULL, opts, out_baseimg, NULL);
+ if (ret < 0) {
+ goto out;
+ }
- /* Get backing file name if -o backing_file was used */
- out_baseimg_param = get_option_parameter(param, BLOCK_OPT_BACKING_FILE);
- if (out_baseimg_param) {
- out_baseimg = out_baseimg_param->value.s;
- }
+ /* Get backing file name if -o backing_file was used */
+ out_baseimg_param = qemu_opt_get(opts, BLOCK_OPT_BACKING_FILE);
+ if (out_baseimg_param) {
+ out_baseimg = out_baseimg_param;
+ }
- /* Check if compression is supported */
- if (compress) {
- QEMUOptionParameter *encryption =
- get_option_parameter(param, BLOCK_OPT_ENCRYPT);
- QEMUOptionParameter *preallocation =
- get_option_parameter(param, BLOCK_OPT_PREALLOC);
+ /* Check if compression is supported */
+ if (compress) {
+ bool encryption =
+ qemu_opt_get_bool(opts, BLOCK_OPT_ENCRYPT, false);
+ const char *preallocation =
+ qemu_opt_get(opts, BLOCK_OPT_PREALLOC);
- if (!drv->bdrv_write_compressed) {
- error_report("Compression not supported for this file format");
- ret = -1;
- goto out;
+ if (!drv->bdrv_write_compressed) {
+ error_report("Compression not supported for this file format");
+ ret = -1;
+ goto out;
+ }
+
+ if (encryption) {
+ error_report("Compression and encryption not supported at "
+ "the same time");
+ ret = -1;
+ goto out;
+ }
+
+ if (preallocation
+ && strcmp(preallocation, "off"))
+ {
+ error_report("Compression and preallocation not supported at "
+ "the same time");
+ ret = -1;
+ goto out;
+ }
}
- if (encryption && encryption->value.n) {
- error_report("Compression and encryption not supported at "
- "the same time");
- ret = -1;
- goto out;
+ } else {
+ QEMUOptionParameter *out_baseimg_param;
+
+ create_options = append_option_parameters(create_options,
+ drv->create_options);
+ create_options = append_option_parameters(create_options,
+ proto_drv->create_options);
+
+ if (options) {
+ param = parse_option_parameters(options, create_options, param);
+ if (param == NULL) {
+ error_report("Invalid options for file format '%s'.", out_fmt);
+ ret = -1;
+ goto out;
+ }
+ } else {
+ param = parse_option_parameters("", create_options, param);
}
- if (preallocation && preallocation->value.s
- && strcmp(preallocation->value.s, "off"))
- {
- error_report("Compression and preallocation not supported at "
- "the same time");
- ret = -1;
+ set_option_parameter_int(param, BLOCK_OPT_SIZE, total_sectors * 512);
+ ret = add_old_style_options(out_fmt, param, NULL, out_baseimg, NULL);
+ if (ret < 0) {
goto out;
}
+
+ /* Get backing file name if -o backing_file was used */
+ out_baseimg_param = get_option_parameter(param, BLOCK_OPT_BACKING_FILE);
+ if (out_baseimg_param) {
+ out_baseimg = out_baseimg_param->value.s;
+ }
+
+ /* Check if compression is supported */
+ if (compress) {
+ QEMUOptionParameter *encryption =
+ get_option_parameter(param, BLOCK_OPT_ENCRYPT);
+ QEMUOptionParameter *preallocation =
+ get_option_parameter(param, BLOCK_OPT_PREALLOC);
+
+ if (!drv->bdrv_write_compressed) {
+ error_report("Compression not supported for this file format");
+ ret = -1;
+ goto out;
+ }
+
+ if (encryption && encryption->value.n) {
+ error_report("Compression and encryption not supported at "
+ "the same time");
+ ret = -1;
+ goto out;
+ }
+
+ if (preallocation && preallocation->value.s
+ && strcmp(preallocation->value.s, "off"))
+ {
+ error_report("Compression and preallocation not supported at "
+ "the same time");
+ ret = -1;
+ goto out;
+ }
+ }
}
if (!skip_create) {
/* Create the new image */
- ret = bdrv_create(drv, out_filename, param, &local_err);
+ ret = bdrv_create(drv, out_filename, param, opts, &local_err);
if (ret < 0) {
error_report("%s: error while converting %s: %s",
out_filename, out_fmt, error_get_pretty(local_err));
@@ -1638,6 +1708,8 @@ out:
qemu_progress_end();
free_option_parameters(create_options);
free_option_parameters(param);
+ qemu_opts_free(create_opts);
+ qemu_opts_del(opts);
qemu_vfree(buf);
if (sn_opts) {
qemu_opts_del(sn_opts);
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* Re: [Qemu-devel] [v19 05/25] change block layer to support both QemuOpts and QEMUOptionParameter
2014-01-20 14:19 ` [Qemu-devel] [v19 05/25] change block layer to support both QemuOpts and QEMUOptionParameter Chunyan Liu
@ 2014-01-22 14:19 ` Kevin Wolf
0 siblings, 0 replies; 38+ messages in thread
From: Kevin Wolf @ 2014-01-22 14:19 UTC (permalink / raw)
To: Chunyan Liu; +Cc: Dong Xu Wang, qemu-devel, stefanha
Am 20.01.2014 um 15:19 hat Chunyan Liu geschrieben:
> Change block layer to support both QemuOpts and QEMUOptionParameter.
> After this patch, it will change backend drivers one by one. At the end,
> QEMUOptionParameter will be removed and only QemuOpts is kept.
>
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
> block.c | 339 +++++++++++++++++++++++++++++++--------------
> block/cow.c | 2 +-
> block/qcow.c | 2 +-
> block/qcow2.c | 2 +-
> block/qed.c | 2 +-
> block/raw_bsd.c | 2 +-
> block/vhdx.c | 2 +-
> block/vmdk.c | 4 +-
> block/vvfat.c | 2 +-
> include/block/block.h | 4 +-
> include/block/block_int.h | 4 +-
> qemu-img.c | 172 ++++++++++++++++-------
> 12 files changed, 372 insertions(+), 165 deletions(-)
>
> diff --git a/block.c b/block.c
> index 64e7d22..0dc0b09 100644
> --- a/block.c
> +++ b/block.c
> @@ -395,6 +395,7 @@ typedef struct CreateCo {
> BlockDriver *drv;
> char *filename;
> QEMUOptionParameter *options;
> + QemuOpts *opts;
> int ret;
> Error *err;
> } CreateCo;
> @@ -407,7 +408,10 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
> CreateCo *cco = opaque;
> assert(cco->drv);
>
> - ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
> + if (cco->drv->bdrv_create2)
> + ret = cco->drv->bdrv_create2(cco->filename, cco->opts, &local_err);
> + else
> + ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
Braces
> if (error_is_set(&local_err)) {
> error_propagate(&cco->err, local_err);
> }
> @@ -415,7 +419,7 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
> }
>
> int bdrv_create(BlockDriver *drv, const char* filename,
> - QEMUOptionParameter *options, Error **errp)
> + QEMUOptionParameter *options, QemuOpts *opts, Error **errp)
> {
> int ret;
>
> @@ -424,11 +428,12 @@ int bdrv_create(BlockDriver *drv, const char* filename,
> .drv = drv,
> .filename = g_strdup(filename),
> .options = options,
> + .opts = opts,
> .ret = NOT_DONE,
> .err = NULL,
> };
>
> - if (!drv->bdrv_create) {
> + if (!drv->bdrv_create && !drv->bdrv_create2) {
> error_setg(errp, "Driver '%s' does not support image creation", drv->format_name);
> ret = -ENOTSUP;
> goto out;
> @@ -460,7 +465,7 @@ out:
> }
>
> int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
> - Error **errp)
> + QemuOpts *opts, Error **errp)
> {
> BlockDriver *drv;
> Error *local_err = NULL;
> @@ -472,7 +477,7 @@ int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
> return -ENOENT;
> }
>
> - ret = bdrv_create(drv, filename, options, &local_err);
> + ret = bdrv_create(drv, filename, options, opts, &local_err);
> if (error_is_set(&local_err)) {
> error_propagate(errp, local_err);
> }
> @@ -1053,7 +1058,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
> BlockDriverState *bs1;
> int64_t total_size;
> BlockDriver *bdrv_qcow2;
> - QEMUOptionParameter *create_options;
> + QEMUOptionParameter *create_options = NULL;
> + QemuOpts *opts = NULL;
Trailing whitespace
> QDict *snapshot_options;
>
> /* if snapshot, we create a temporary backing file and open it
> @@ -1080,13 +1086,18 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
> }
>
> bdrv_qcow2 = bdrv_find_format("qcow2");
> - create_options = parse_option_parameters("", bdrv_qcow2->create_options,
> - NULL);
> -
> - set_option_parameter_int(create_options, BLOCK_OPT_SIZE, total_size);
> + if (bdrv_qcow2->bdrv_create2) {
> + opts = qemu_opts_create(bdrv_qcow2->create_opts, NULL, 0, &error_abort);
> + qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size);
> + } else {
> + create_options =
Here as well
> + parse_option_parameters("", bdrv_qcow2->create_options, NULL);
> + set_option_parameter_int(create_options, BLOCK_OPT_SIZE, total_size);
> + }
>
> - ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, &local_err);
> + ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, opts, &local_err);
> free_option_parameters(create_options);
> + qemu_opts_del(opts);
> if (ret < 0) {
> error_setg_errno(errp, -ret, "Could not create temporary overlay "
> "'%s': %s", tmp_filename,
> @@ -4712,7 +4723,8 @@ void bdrv_img_create(const char *filename, const char *fmt,
> Error **errp, bool quiet)
> {
> QEMUOptionParameter *param = NULL, *create_options = NULL;
> - QEMUOptionParameter *backing_fmt, *backing_file, *size;
> + QemuOptsList *create_opts = NULL;
> + QemuOpts *opts = NULL;
> BlockDriver *drv, *proto_drv;
> BlockDriver *backing_drv = NULL;
> Error *local_err = NULL;
> @@ -4731,125 +4743,246 @@ void bdrv_img_create(const char *filename, const char *fmt,
> return;
> }
>
> - create_options = append_option_parameters(create_options,
> - drv->create_options);
> - create_options = append_option_parameters(create_options,
> - proto_drv->create_options);
> + if (drv->bdrv_create2) {
> + const char *backing_fmt, *backing_file;
> + int64_t size;
>
> - /* Create parameter list with default values */
> - param = parse_option_parameters("", create_options, param);
> + create_opts = qemu_opts_append(create_opts, drv->create_opts);
> + create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
> + /* Create parameter list with default values */
> + opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
>
> - set_option_parameter_int(param, BLOCK_OPT_SIZE, img_size);
> + qemu_opt_set_number(opts, BLOCK_OPT_SIZE, img_size);
>
> - /* Parse -o options */
> - if (options) {
> - param = parse_option_parameters(options, create_options, param);
> - if (param == NULL) {
> - error_setg(errp, "Invalid options for file format '%s'.", fmt);
> - goto out;
> + /* Parse -o options */
> + if (options) {
> + if (qemu_opts_do_parse(opts, options, NULL) != 0) {
> + error_setg(errp, "Invalid options for file format '%s'.", fmt);
> + goto out;
> + }
> }
> - }
>
> - if (base_filename) {
> - if (set_option_parameter(param, BLOCK_OPT_BACKING_FILE,
> - base_filename)) {
> - error_setg(errp, "Backing file not supported for file format '%s'",
> - fmt);
> - goto out;
> + if (base_filename) {
> + if (qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename)) {
> + error_setg(errp, "Backing file not supported for file format '%s'",
> + fmt);
> + goto out;
> + }
> }
> - }
>
> - if (base_fmt) {
> - if (set_option_parameter(param, BLOCK_OPT_BACKING_FMT, base_fmt)) {
> - error_setg(errp, "Backing file format not supported for file "
> - "format '%s'", fmt);
> - goto out;
> + if (base_fmt) {
> + if (qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt)) {
> + error_setg(errp, "Backing file format not supported for file "
> + "format '%s'", fmt);
> + goto out;
> + }
> }
> - }
>
> - backing_file = get_option_parameter(param, BLOCK_OPT_BACKING_FILE);
> - if (backing_file && backing_file->value.s) {
> - if (!strcmp(filename, backing_file->value.s)) {
> - error_setg(errp, "Error: Trying to create an image with the "
> - "same filename as the backing file");
> - goto out;
> + backing_file = qemu_opt_get(opts, BLOCK_OPT_BACKING_FILE);
> + if (backing_file) {
> + if (!strcmp(filename, backing_file)) {
> + error_setg(errp, "Error: Trying to create an image with the "
> + "same filename as the backing file");
> + goto out;
> + }
> }
> - }
>
> - backing_fmt = get_option_parameter(param, BLOCK_OPT_BACKING_FMT);
> - if (backing_fmt && backing_fmt->value.s) {
> - backing_drv = bdrv_find_format(backing_fmt->value.s);
> - if (!backing_drv) {
> - error_setg(errp, "Unknown backing file format '%s'",
> - backing_fmt->value.s);
> - goto out;
> + backing_fmt = qemu_opt_get(opts, BLOCK_OPT_BACKING_FMT);
> + if (backing_fmt) {
> + backing_drv = bdrv_find_format(backing_fmt);
> + if (!backing_drv) {
> + error_setg(errp, "Unknown backing file format '%s'",
> + backing_fmt);
> + goto out;
> + }
> + }
> +
> + // The size for the image must always be specified, with one exception:
> + // If we are using a backing file, we can obtain the size from there
> + size = qemu_opt_get_size(opts, BLOCK_OPT_SIZE, 0);
> + if (size == -1) {
> + if (backing_file) {
> + BlockDriverState *bs;
> + uint64_t size;
> + char buf[32];
> + int back_flags;
> +
> + /* backing files always opened read-only */
> + back_flags =
> + flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
> +
> + bs = bdrv_new("");
> +
> + ret = bdrv_open(bs, backing_file, NULL, back_flags,
> + backing_drv, &local_err);
> + if (ret < 0) {
> + error_setg_errno(errp, -ret, "Could not open '%s': %s",
> + backing_file,
> + error_get_pretty(local_err));
> + error_free(local_err);
> + local_err = NULL;
> + bdrv_unref(bs);
> + goto out;
> + }
> + bdrv_get_geometry(bs, &size);
> + size *= 512;
> +
> + snprintf(buf, sizeof(buf), "%" PRId64, size);
> + qemu_opt_set_number(opts, BLOCK_OPT_SIZE, size);
> +
> + bdrv_unref(bs);
> + } else {
> + error_setg(errp, "Image creation needs a size parameter");
> + goto out;
> + }
> + }
> +
> + if (!quiet) {
> + printf("Formatting '%s', fmt=%s ", filename, fmt);
> + qemu_opts_print(opts);
> + puts("");
> + }
> +
> + ret = bdrv_create(drv, filename, NULL, opts, &local_err);
> + if (ret == -EFBIG) {
> + /* This is generally a better message than whatever the driver would
> + * deliver (especially because of the cluster_size_hint), since that
> + * is most probably not much different from "image too large". */
> + const char *cluster_size_hint = "";
> + if (qemu_opt_get_size(opts, BLOCK_OPT_CLUSTER_SIZE, 0)) {
> + cluster_size_hint = " (try using a larger cluster size)";
> + }
> + error_setg(errp, "The image size is too large for file format '%s'"
> + "%s", fmt, cluster_size_hint);
> + error_free(local_err);
> + local_err = NULL;
> }
> - }
>
> - // The size for the image must always be specified, with one exception:
> - // If we are using a backing file, we can obtain the size from there
> - size = get_option_parameter(param, BLOCK_OPT_SIZE);
> - if (size && size->value.n == -1) {
> + } else {
> + QEMUOptionParameter *backing_fmt, *backing_file, *size;
> +
> + create_options = append_option_parameters(create_options,
> + drv->create_options);
> + create_options = append_option_parameters(create_options,
> + proto_drv->create_options);
> +
> + /* Create parameter list with default values */
> + param = parse_option_parameters("", create_options, param);
> +
> + set_option_parameter_int(param, BLOCK_OPT_SIZE, img_size);
> +
> + /* Parse -o options */
> + if (options) {
> + param = parse_option_parameters(options, create_options, param);
> + if (param == NULL) {
> + error_setg(errp, "Invalid options for file format '%s'.", fmt);
> + goto out;
> + }
> + }
> +
> + if (base_filename) {
> + if (set_option_parameter(param, BLOCK_OPT_BACKING_FILE,
> + base_filename)) {
> + error_setg(errp, "Backing file not supported for file format '%s'",
> + fmt);
> + goto out;
> + }
> + }
> +
> + if (base_fmt) {
> + if (set_option_parameter(param, BLOCK_OPT_BACKING_FMT, base_fmt)) {
> + error_setg(errp, "Backing file format not supported for file "
> + "format '%s'", fmt);
> + goto out;
> + }
> + }
> +
> + backing_file = get_option_parameter(param, BLOCK_OPT_BACKING_FILE);
> if (backing_file && backing_file->value.s) {
> - BlockDriverState *bs;
> - uint64_t size;
> - char buf[32];
> - int back_flags;
> + if (!strcmp(filename, backing_file->value.s)) {
> + error_setg(errp, "Error: Trying to create an image with the "
> + "same filename as the backing file");
> + goto out;
> + }
> + }
>
> - /* backing files always opened read-only */
> - back_flags =
> - flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
> + backing_fmt = get_option_parameter(param, BLOCK_OPT_BACKING_FMT);
> + if (backing_fmt && backing_fmt->value.s) {
> + backing_drv = bdrv_find_format(backing_fmt->value.s);
> + if (!backing_drv) {
> + error_setg(errp, "Unknown backing file format '%s'",
> + backing_fmt->value.s);
> + goto out;
> + }
> + }
>
> - bs = bdrv_new("");
> + // The size for the image must always be specified, with one exception:
> + // If we are using a backing file, we can obtain the size from there
> + size = get_option_parameter(param, BLOCK_OPT_SIZE);
> + if (size && size->value.n == -1) {
> + if (backing_file && backing_file->value.s) {
> + BlockDriverState *bs;
> + uint64_t size;
> + char buf[32];
> + int back_flags;
> +
> + /* backing files always opened read-only */
> + back_flags =
> + flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
> +
> + bs = bdrv_new("");
> +
> + ret = bdrv_open(bs, backing_file->value.s, NULL, back_flags,
> + backing_drv, &local_err);
> + if (ret < 0) {
> + error_setg_errno(errp, -ret, "Could not open '%s': %s",
> + backing_file->value.s,
> + error_get_pretty(local_err));
> + error_free(local_err);
> + local_err = NULL;
> + bdrv_unref(bs);
> + goto out;
> + }
> + bdrv_get_geometry(bs, &size);
> + size *= 512;
> +
> + snprintf(buf, sizeof(buf), "%" PRId64, size);
> + set_option_parameter(param, BLOCK_OPT_SIZE, buf);
>
> - ret = bdrv_open(bs, backing_file->value.s, NULL, back_flags,
> - backing_drv, &local_err);
> - if (ret < 0) {
> - error_setg_errno(errp, -ret, "Could not open '%s': %s",
> - backing_file->value.s,
> - error_get_pretty(local_err));
> - error_free(local_err);
> - local_err = NULL;
> bdrv_unref(bs);
> + } else {
> + error_setg(errp, "Image creation needs a size parameter");
> goto out;
> }
> - bdrv_get_geometry(bs, &size);
> - size *= 512;
> -
> - snprintf(buf, sizeof(buf), "%" PRId64, size);
> - set_option_parameter(param, BLOCK_OPT_SIZE, buf);
> + }
>
> - bdrv_unref(bs);
> - } else {
> - error_setg(errp, "Image creation needs a size parameter");
> - goto out;
> + if (!quiet) {
> + printf("Formatting '%s', fmt=%s ", filename, fmt);
> + print_option_parameters(param);
> + puts("");
> }
> - }
>
> - if (!quiet) {
> - printf("Formatting '%s', fmt=%s ", filename, fmt);
> - print_option_parameters(param);
> - puts("");
> - }
> - ret = bdrv_create(drv, filename, param, &local_err);
> - if (ret == -EFBIG) {
> - /* This is generally a better message than whatever the driver would
> - * deliver (especially because of the cluster_size_hint), since that
> - * is most probably not much different from "image too large". */
> - const char *cluster_size_hint = "";
> - if (get_option_parameter(create_options, BLOCK_OPT_CLUSTER_SIZE)) {
> - cluster_size_hint = " (try using a larger cluster size)";
> + ret = bdrv_create(drv, filename, param, NULL, &local_err);
> + if (ret == -EFBIG) {
> + /* This is generally a better message than whatever the driver would
> + * deliver (especially because of the cluster_size_hint), since that
> + * is most probably not much different from "image too large". */
> + const char *cluster_size_hint = "";
> + if (get_option_parameter(create_options, BLOCK_OPT_CLUSTER_SIZE)) {
> + cluster_size_hint = " (try using a larger cluster size)";
> + }
> + error_setg(errp, "The image size is too large for file format '%s'"
> + "%s", fmt, cluster_size_hint);
> + error_free(local_err);
> + local_err = NULL;
> }
> - error_setg(errp, "The image size is too large for file format '%s'"
> - "%s", fmt, cluster_size_hint);
> - error_free(local_err);
> - local_err = NULL;
> - }
> + }
>
> out:
> free_option_parameters(create_options);
> free_option_parameters(param);
> -
> + qemu_opts_del(opts);
> + qemu_opts_free(create_opts);
> if (error_is_set(&local_err)) {
> error_propagate(errp, local_err);
> }
Don't you think it would be easier to support only one method in this
function, and add some conversion to bdrv_create? Just iterating over
QemuOpts and pushing all fields into QEMUOptionParameters (or the other
way round) should be easy enough.
Kevin
^ permalink raw reply [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 06/25] cow.c: replace QEMUOptionParameter with QemuOpts
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (4 preceding siblings ...)
2014-01-20 14:19 ` [Qemu-devel] [v19 05/25] change block layer to support both QemuOpts and QEMUOptionParameter Chunyan Liu
@ 2014-01-20 14:19 ` Chunyan Liu
2014-01-22 14:20 ` Kevin Wolf
2014-01-20 14:19 ` [Qemu-devel] [v19 07/25] gluster.c: " Chunyan Liu
` (19 subsequent siblings)
25 siblings, 1 reply; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:19 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
cow.c: replace QEMUOptionParameter with QemuOpts
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
block/cow.c | 46 ++++++++++++++++++++++------------------------
1 files changed, 22 insertions(+), 24 deletions(-)
diff --git a/block/cow.c b/block/cow.c
index 6318228..6688a87 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -323,7 +323,7 @@ static void cow_close(BlockDriverState *bs)
{
}
-static int cow_create(const char *filename, QEMUOptionParameter *options,
+static int cow_create(const char *filename, QemuOpts *opts,
Error **errp)
{
struct cow_header_v2 cow_header;
@@ -335,16 +335,10 @@ static int cow_create(const char *filename, QEMUOptionParameter *options,
BlockDriverState *cow_bs;
/* Read out options */
- while (options && options->name) {
- if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
- image_sectors = options->value.n / 512;
- } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
- image_filename = options->value.s;
- }
- options++;
- }
+ image_sectors = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512;
+ image_filename = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
- ret = bdrv_create_file(filename, options, NULL, &local_err);
+ ret = bdrv_create_file(filename, NULL, opts, &local_err);
if (ret < 0) {
qerror_report_err(local_err);
error_free(local_err);
@@ -392,18 +386,22 @@ exit:
return ret;
}
-static QEMUOptionParameter cow_create_options[] = {
- {
- .name = BLOCK_OPT_SIZE,
- .type = OPT_SIZE,
- .help = "Virtual disk size"
- },
- {
- .name = BLOCK_OPT_BACKING_FILE,
- .type = OPT_STRING,
- .help = "File name of a base image"
- },
- { NULL }
+static QemuOptsList cow_create_opts = {
+ .name = "cow-create-opts",
+ .head = QTAILQ_HEAD_INITIALIZER(cow_create_opts.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size"
+ },
+ {
+ .name = BLOCK_OPT_BACKING_FILE,
+ .type = QEMU_OPT_STRING,
+ .help = "File name of a base image"
+ },
+ { /* end of list */ }
+ }
};
static BlockDriver bdrv_cow = {
@@ -413,14 +411,14 @@ static BlockDriver bdrv_cow = {
.bdrv_probe = cow_probe,
.bdrv_open = cow_open,
.bdrv_close = cow_close,
- .bdrv_create = cow_create,
+ .bdrv_create2 = cow_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_read = cow_co_read,
.bdrv_write = cow_co_write,
.bdrv_co_get_block_status = cow_co_get_block_status,
- .create_options = cow_create_options,
+ .create_opts = &cow_create_opts,
};
static void bdrv_cow_init(void)
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 07/25] gluster.c: replace QEMUOptionParameter with QemuOpts
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (5 preceding siblings ...)
2014-01-20 14:19 ` [Qemu-devel] [v19 06/25] cow.c: replace QEMUOptionParameter with QemuOpts Chunyan Liu
@ 2014-01-20 14:19 ` Chunyan Liu
2014-01-22 13:10 ` Kevin Wolf
2014-01-20 14:19 ` [Qemu-devel] [v19 08/25] iscsi.c: replace QEMUOptionParamter " Chunyan Liu
` (18 subsequent siblings)
25 siblings, 1 reply; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:19 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
gluster.c: replace QEMUOptionParameter with QemuOpts
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
block/gluster.c | 44 ++++++++++++++++++++++----------------------
1 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/block/gluster.c b/block/gluster.c
index 563d497..163ca58 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -357,7 +357,7 @@ out:
}
static int qemu_gluster_create(const char *filename,
- QEMUOptionParameter *options, Error **errp)
+ QemuOpts *opts, Error **errp)
{
struct glfs *glfs;
struct glfs_fd *fd;
@@ -371,12 +371,8 @@ static int qemu_gluster_create(const char *filename,
goto out;
}
- while (options && options->name) {
- if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
- total_size = options->value.n / BDRV_SECTOR_SIZE;
- }
- options++;
- }
+ total_size =
+ qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
fd = glfs_creat(glfs, gconf->image,
O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR | S_IWUSR);
@@ -598,13 +594,17 @@ static int qemu_gluster_has_zero_init(BlockDriverState *bs)
return 0;
}
-static QEMUOptionParameter qemu_gluster_create_options[] = {
- {
- .name = BLOCK_OPT_SIZE,
- .type = OPT_SIZE,
- .help = "Virtual disk size"
- },
- { NULL }
+static QemuOptsList qemu_gluster_create_opts = {
+ .name = "qemu-gluster-create-opts",
+ .head = QTAILQ_HEAD_INITIALIZER(qemu_gluster_create_opts.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size"
+ },
+ { /* end of list */ }
+ }
};
static BlockDriver bdrv_gluster = {
@@ -614,7 +614,7 @@ static BlockDriver bdrv_gluster = {
.bdrv_needs_filename = true,
.bdrv_file_open = qemu_gluster_open,
.bdrv_close = qemu_gluster_close,
- .bdrv_create = qemu_gluster_create,
+ .bdrv_create2 = qemu_gluster_create,
.bdrv_getlength = qemu_gluster_getlength,
.bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
.bdrv_truncate = qemu_gluster_truncate,
@@ -625,7 +625,7 @@ static BlockDriver bdrv_gluster = {
#ifdef CONFIG_GLUSTERFS_DISCARD
.bdrv_aio_discard = qemu_gluster_aio_discard,
#endif
- .create_options = qemu_gluster_create_options,
+ .create_opts = &qemu_gluster_create_opts,
};
static BlockDriver bdrv_gluster_tcp = {
@@ -635,7 +635,7 @@ static BlockDriver bdrv_gluster_tcp = {
.bdrv_needs_filename = true,
.bdrv_file_open = qemu_gluster_open,
.bdrv_close = qemu_gluster_close,
- .bdrv_create = qemu_gluster_create,
+ .bdrv_create2 = qemu_gluster_create,
.bdrv_getlength = qemu_gluster_getlength,
.bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
.bdrv_truncate = qemu_gluster_truncate,
@@ -646,7 +646,7 @@ static BlockDriver bdrv_gluster_tcp = {
#ifdef CONFIG_GLUSTERFS_DISCARD
.bdrv_aio_discard = qemu_gluster_aio_discard,
#endif
- .create_options = qemu_gluster_create_options,
+ .create_opts = &qemu_gluster_create_opts,
};
static BlockDriver bdrv_gluster_unix = {
@@ -656,7 +656,7 @@ static BlockDriver bdrv_gluster_unix = {
.bdrv_needs_filename = true,
.bdrv_file_open = qemu_gluster_open,
.bdrv_close = qemu_gluster_close,
- .bdrv_create = qemu_gluster_create,
+ .bdrv_create2 = qemu_gluster_create,
.bdrv_getlength = qemu_gluster_getlength,
.bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
.bdrv_truncate = qemu_gluster_truncate,
@@ -667,7 +667,7 @@ static BlockDriver bdrv_gluster_unix = {
#ifdef CONFIG_GLUSTERFS_DISCARD
.bdrv_aio_discard = qemu_gluster_aio_discard,
#endif
- .create_options = qemu_gluster_create_options,
+ .create_opts = &qemu_gluster_create_opts,
};
static BlockDriver bdrv_gluster_rdma = {
@@ -677,7 +677,7 @@ static BlockDriver bdrv_gluster_rdma = {
.bdrv_needs_filename = true,
.bdrv_file_open = qemu_gluster_open,
.bdrv_close = qemu_gluster_close,
- .bdrv_create = qemu_gluster_create,
+ .bdrv_create2 = qemu_gluster_create,
.bdrv_getlength = qemu_gluster_getlength,
.bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
.bdrv_truncate = qemu_gluster_truncate,
@@ -688,7 +688,7 @@ static BlockDriver bdrv_gluster_rdma = {
#ifdef CONFIG_GLUSTERFS_DISCARD
.bdrv_aio_discard = qemu_gluster_aio_discard,
#endif
- .create_options = qemu_gluster_create_options,
+ .create_opts = &qemu_gluster_create_opts,
};
static void bdrv_gluster_init(void)
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* Re: [Qemu-devel] [v19 07/25] gluster.c: replace QEMUOptionParameter with QemuOpts
2014-01-20 14:19 ` [Qemu-devel] [v19 07/25] gluster.c: " Chunyan Liu
@ 2014-01-22 13:10 ` Kevin Wolf
0 siblings, 0 replies; 38+ messages in thread
From: Kevin Wolf @ 2014-01-22 13:10 UTC (permalink / raw)
To: Chunyan Liu; +Cc: Dong Xu Wang, qemu-devel, stefanha
Am 20.01.2014 um 15:19 hat Chunyan Liu geschrieben:
> gluster.c: replace QEMUOptionParameter with QemuOpts
>
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
This conflicts with the queued patch "gluster: Add support for creating
zero-filled image".
Can you please rebase on top of my block branch?
Kevin
^ permalink raw reply [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 08/25] iscsi.c: replace QEMUOptionParamter with QemuOpts
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (6 preceding siblings ...)
2014-01-20 14:19 ` [Qemu-devel] [v19 07/25] gluster.c: " Chunyan Liu
@ 2014-01-20 14:19 ` Chunyan Liu
2014-01-20 14:19 ` [Qemu-devel] [v19 09/25] qcow.c: " Chunyan Liu
` (17 subsequent siblings)
25 siblings, 0 replies; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:19 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
iscsi.c: replace QEMUOptionParamter with QemuOpts
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
block/iscsi.c | 61 ++++++++++++++++++++++++++++-----------------------------
1 files changed, 30 insertions(+), 31 deletions(-)
diff --git a/block/iscsi.c b/block/iscsi.c
index c0ea0c4..d496aff 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1346,7 +1346,22 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t offset)
return 0;
}
-static int iscsi_create(const char *filename, QEMUOptionParameter *options,
+static int iscsi_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
+{
+ IscsiLun *iscsilun = bs->opaque;
+ bdi->unallocated_blocks_are_zero = !!iscsilun->lbprz;
+ bdi->can_write_zeroes_with_unmap = iscsilun->lbprz && iscsilun->lbp.lbpws;
+ /* Guess the internal cluster (page) size of the iscsi target by the means
+ * of opt_unmap_gran. Transfer the unmap granularity only if it has a
+ * reasonable size for bdi->cluster_size */
+ if (iscsilun->bl.opt_unmap_gran * iscsilun->block_size >= 64 * 1024 &&
+ iscsilun->bl.opt_unmap_gran * iscsilun->block_size <= 16 * 1024 * 1024) {
+ bdi->cluster_size = iscsilun->bl.opt_unmap_gran * iscsilun->block_size;
+ }
+ return 0;
+}
+
+static int iscsi_create(const char *filename, QemuOpts *opts,
Error **errp)
{
int ret = 0;
@@ -1358,13 +1373,8 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options,
bs = bdrv_new("");
/* Read out options */
- while (options && options->name) {
- if (!strcmp(options->name, "size")) {
- total_size = options->value.n / BDRV_SECTOR_SIZE;
- }
- options++;
- }
-
+ total_size =
+ qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
bs->opaque = g_malloc0(sizeof(struct IscsiLun));
iscsilun = bs->opaque;
@@ -1400,28 +1410,17 @@ out:
return ret;
}
-static int iscsi_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
-{
- IscsiLun *iscsilun = bs->opaque;
- bdi->unallocated_blocks_are_zero = !!iscsilun->lbprz;
- bdi->can_write_zeroes_with_unmap = iscsilun->lbprz && iscsilun->lbp.lbpws;
- /* Guess the internal cluster (page) size of the iscsi target by the means
- * of opt_unmap_gran. Transfer the unmap granularity only if it has a
- * reasonable size for bdi->cluster_size */
- if (iscsilun->bl.opt_unmap_gran * iscsilun->block_size >= 64 * 1024 &&
- iscsilun->bl.opt_unmap_gran * iscsilun->block_size <= 16 * 1024 * 1024) {
- bdi->cluster_size = iscsilun->bl.opt_unmap_gran * iscsilun->block_size;
+static QemuOptsList iscsi_create_opts = {
+ .name = "iscsi-create-opts",
+ .head = QTAILQ_HEAD_INITIALIZER(iscsi_create_opts.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size"
+ },
+ { /* end of list */ }
}
- return 0;
-}
-
-static QEMUOptionParameter iscsi_create_options[] = {
- {
- .name = BLOCK_OPT_SIZE,
- .type = OPT_SIZE,
- .help = "Virtual disk size"
- },
- { NULL }
};
static BlockDriver bdrv_iscsi = {
@@ -1432,8 +1431,8 @@ static BlockDriver bdrv_iscsi = {
.bdrv_needs_filename = true,
.bdrv_file_open = iscsi_open,
.bdrv_close = iscsi_close,
- .bdrv_create = iscsi_create,
- .create_options = iscsi_create_options,
+ .bdrv_create2 = iscsi_create,
+ .create_opts = &iscsi_create_opts,
.bdrv_getlength = iscsi_getlength,
.bdrv_get_info = iscsi_get_info,
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 09/25] qcow.c: replace QEMUOptionParamter with QemuOpts
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (7 preceding siblings ...)
2014-01-20 14:19 ` [Qemu-devel] [v19 08/25] iscsi.c: replace QEMUOptionParamter " Chunyan Liu
@ 2014-01-20 14:19 ` Chunyan Liu
2014-01-20 14:19 ` [Qemu-devel] [v19 10/25] qcow2.c: replace QEMUOptionParameter with QemuOpts in create Chunyan Liu
` (16 subsequent siblings)
25 siblings, 0 replies; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:19 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
qcow.c: replace QEMUOptionParamter with QemuOpts
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
block/qcow.c | 61 ++++++++++++++++++++++++++++-----------------------------
1 files changed, 30 insertions(+), 31 deletions(-)
diff --git a/block/qcow.c b/block/qcow.c
index be2a72e..ac0ddff 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -659,7 +659,7 @@ static void qcow_close(BlockDriverState *bs)
error_free(s->migration_blocker);
}
-static int qcow_create(const char *filename, QEMUOptionParameter *options,
+static int qcow_create(const char *filename, QemuOpts *opts,
Error **errp)
{
int header_size, backing_filename_len, l1_size, shift, i;
@@ -673,18 +673,13 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options,
BlockDriverState *qcow_bs;
/* Read out options */
- while (options && options->name) {
- if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
- total_size = options->value.n / 512;
- } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
- backing_file = options->value.s;
- } else if (!strcmp(options->name, BLOCK_OPT_ENCRYPT)) {
- flags |= options->value.n ? BLOCK_FLAG_ENCRYPT : 0;
- }
- options++;
+ total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512;
+ backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+ if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) {
+ flags |= BLOCK_FLAG_ENCRYPT;
}
- ret = bdrv_create_file(filename, options, NULL, &local_err);
+ ret = bdrv_create_file(filename, NULL, opts, &local_err);
if (ret < 0) {
qerror_report_err(local_err);
error_free(local_err);
@@ -878,24 +873,28 @@ static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
return 0;
}
-
-static QEMUOptionParameter qcow_create_options[] = {
- {
- .name = BLOCK_OPT_SIZE,
- .type = OPT_SIZE,
- .help = "Virtual disk size"
- },
- {
- .name = BLOCK_OPT_BACKING_FILE,
- .type = OPT_STRING,
- .help = "File name of a base image"
- },
- {
- .name = BLOCK_OPT_ENCRYPT,
- .type = OPT_FLAG,
- .help = "Encrypt the image"
- },
- { NULL }
+static QemuOptsList qcow_create_opts = {
+ .name = "qcow-create-opts",
+ .head = QTAILQ_HEAD_INITIALIZER(qcow_create_opts.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size"
+ },
+ {
+ .name = BLOCK_OPT_BACKING_FILE,
+ .type = QEMU_OPT_STRING,
+ .help = "File name of a base image"
+ },
+ {
+ .name = BLOCK_OPT_ENCRYPT,
+ .type = QEMU_OPT_BOOL,
+ .help = "Encrypt the image",
+ .def_value_str = "off"
+ },
+ { /* end of list */ }
+ }
};
static BlockDriver bdrv_qcow = {
@@ -905,7 +904,7 @@ static BlockDriver bdrv_qcow = {
.bdrv_open = qcow_open,
.bdrv_close = qcow_close,
.bdrv_reopen_prepare = qcow_reopen_prepare,
- .bdrv_create = qcow_create,
+ .bdrv_create2 = qcow_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_co_readv = qcow_co_readv,
@@ -917,7 +916,7 @@ static BlockDriver bdrv_qcow = {
.bdrv_write_compressed = qcow_write_compressed,
.bdrv_get_info = qcow_get_info,
- .create_options = qcow_create_options,
+ .create_opts = &qcow_create_opts,
};
static void bdrv_qcow_init(void)
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 10/25] qcow2.c: replace QEMUOptionParameter with QemuOpts in create
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (8 preceding siblings ...)
2014-01-20 14:19 ` [Qemu-devel] [v19 09/25] qcow.c: " Chunyan Liu
@ 2014-01-20 14:19 ` Chunyan Liu
2014-01-20 14:19 ` [Qemu-devel] [v19 11/25] qcow2.c: replace QEMUOptionParameter with QemuOpts in amend options Chunyan Liu
` (15 subsequent siblings)
25 siblings, 0 replies; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:19 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
qcow2.c: replace QEMUOptionParameter with QemuOpts in 'qemu-img create'.
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
block/qcow2.c | 176 ++++++++++++++++++++++++++++----------------------------
1 files changed, 88 insertions(+), 88 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index e8b96cd..b7a2e3f 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1445,7 +1445,7 @@ static int preallocate(BlockDriverState *bs)
static int qcow2_create2(const char *filename, int64_t total_size,
const char *backing_file, const char *backing_format,
int flags, size_t cluster_size, int prealloc,
- QEMUOptionParameter *options, int version,
+ QemuOpts *opts, int version,
Error **errp)
{
/* Calculate cluster_bits */
@@ -1477,7 +1477,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
Error *local_err = NULL;
int ret;
- ret = bdrv_create_file(filename, options, NULL, &local_err);
+ ret = bdrv_create_file(filename, NULL, opts, &local_err);
if (ret < 0) {
error_propagate(errp, local_err);
return ret;
@@ -1606,11 +1606,12 @@ out:
return ret;
}
-static int qcow2_create(const char *filename, QEMUOptionParameter *options,
+static int qcow2_create(const char *filename, QemuOpts *opts,
Error **errp)
{
const char *backing_file = NULL;
const char *backing_fmt = NULL;
+ const char *buf;
uint64_t sectors = 0;
int flags = 0;
size_t cluster_size = DEFAULT_CLUSTER_SIZE;
@@ -1620,45 +1621,38 @@ static int qcow2_create(const char *filename, QEMUOptionParameter *options,
int ret;
/* Read out options */
- while (options && options->name) {
- if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
- sectors = options->value.n / 512;
- } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
- backing_file = options->value.s;
- } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FMT)) {
- backing_fmt = options->value.s;
- } else if (!strcmp(options->name, BLOCK_OPT_ENCRYPT)) {
- flags |= options->value.n ? BLOCK_FLAG_ENCRYPT : 0;
- } else if (!strcmp(options->name, BLOCK_OPT_CLUSTER_SIZE)) {
- if (options->value.n) {
- cluster_size = options->value.n;
- }
- } else if (!strcmp(options->name, BLOCK_OPT_PREALLOC)) {
- if (!options->value.s || !strcmp(options->value.s, "off")) {
- prealloc = 0;
- } else if (!strcmp(options->value.s, "metadata")) {
- prealloc = 1;
- } else {
- error_setg(errp, "Invalid preallocation mode: '%s'",
- options->value.s);
- return -EINVAL;
- }
- } else if (!strcmp(options->name, BLOCK_OPT_COMPAT_LEVEL)) {
- if (!options->value.s) {
- /* keep the default */
- } else if (!strcmp(options->value.s, "0.10")) {
- version = 2;
- } else if (!strcmp(options->value.s, "1.1")) {
- version = 3;
- } else {
- error_setg(errp, "Invalid compatibility level: '%s'",
- options->value.s);
- return -EINVAL;
- }
- } else if (!strcmp(options->name, BLOCK_OPT_LAZY_REFCOUNTS)) {
- flags |= options->value.n ? BLOCK_FLAG_LAZY_REFCOUNTS : 0;
- }
- options++;
+ sectors = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512;
+ backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+ backing_fmt = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT);
+ if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) {
+ flags |= BLOCK_FLAG_ENCRYPT;
+ }
+ cluster_size = qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE,
+ DEFAULT_CLUSTER_SIZE);
+ buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
+ if (!buf || !strcmp(buf, "off")) {
+ prealloc = 0;
+ } else if (!strcmp(buf, "metadata")) {
+ prealloc = 1;
+ } else {
+ fprintf(stderr, "Invalid preallocation mode: '%s'\n",
+ buf);
+ return -EINVAL;
+ }
+ buf = NULL;
+ buf = qemu_opt_get_del(opts, BLOCK_OPT_COMPAT_LEVEL);
+ if (!buf || !strcmp(buf, "0.10")) {
+ version = 2;
+ } else if (!strcmp(buf, "1.1")) {
+ version = 3;
+ } else {
+ fprintf(stderr, "Invalid compatibility level: '%s'\n",
+ buf);
+ return -EINVAL;
+ }
+
+ if (qemu_opt_get_bool_del(opts, BLOCK_OPT_LAZY_REFCOUNTS, false)) {
+ flags |= BLOCK_FLAG_LAZY_REFCOUNTS;
}
if (backing_file && prealloc) {
@@ -1674,7 +1668,7 @@ static int qcow2_create(const char *filename, QEMUOptionParameter *options,
}
ret = qcow2_create2(filename, sectors, backing_file, backing_fmt, flags,
- cluster_size, prealloc, options, version, &local_err);
+ cluster_size, prealloc, opts, version, &local_err);
if (error_is_set(&local_err)) {
error_propagate(errp, local_err);
}
@@ -2188,49 +2182,55 @@ static int qcow2_amend_options(BlockDriverState *bs,
return 0;
}
-static QEMUOptionParameter qcow2_create_options[] = {
- {
- .name = BLOCK_OPT_SIZE,
- .type = OPT_SIZE,
- .help = "Virtual disk size"
- },
- {
- .name = BLOCK_OPT_COMPAT_LEVEL,
- .type = OPT_STRING,
- .help = "Compatibility level (0.10 or 1.1)"
- },
- {
- .name = BLOCK_OPT_BACKING_FILE,
- .type = OPT_STRING,
- .help = "File name of a base image"
- },
- {
- .name = BLOCK_OPT_BACKING_FMT,
- .type = OPT_STRING,
- .help = "Image format of the base image"
- },
- {
- .name = BLOCK_OPT_ENCRYPT,
- .type = OPT_FLAG,
- .help = "Encrypt the image"
- },
- {
- .name = BLOCK_OPT_CLUSTER_SIZE,
- .type = OPT_SIZE,
- .help = "qcow2 cluster size",
- .value = { .n = DEFAULT_CLUSTER_SIZE },
- },
- {
- .name = BLOCK_OPT_PREALLOC,
- .type = OPT_STRING,
- .help = "Preallocation mode (allowed values: off, metadata)"
- },
- {
- .name = BLOCK_OPT_LAZY_REFCOUNTS,
- .type = OPT_FLAG,
- .help = "Postpone refcount updates",
- },
- { NULL }
+static QemuOptsList qcow2_create_opts = {
+ .name = "qcow2-create-opts",
+ .head = QTAILQ_HEAD_INITIALIZER(qcow2_create_opts.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size"
+ },
+ {
+ .name = BLOCK_OPT_COMPAT_LEVEL,
+ .type = QEMU_OPT_STRING,
+ .help = "Compatibility level (0.10 or 1.1)"
+ },
+ {
+ .name = BLOCK_OPT_BACKING_FILE,
+ .type = QEMU_OPT_STRING,
+ .help = "File name of a base image"
+ },
+ {
+ .name = BLOCK_OPT_BACKING_FMT,
+ .type = QEMU_OPT_STRING,
+ .help = "Image format of the base image"
+ },
+ {
+ .name = BLOCK_OPT_ENCRYPT,
+ .type = QEMU_OPT_BOOL,
+ .help = "Encrypt the image",
+ .def_value_str = "off"
+ },
+ {
+ .name = BLOCK_OPT_CLUSTER_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "qcow2 cluster size",
+ .def_value_str = stringify(DEFAULT_CLUSTER_SIZE)
+ },
+ {
+ .name = BLOCK_OPT_PREALLOC,
+ .type = QEMU_OPT_STRING,
+ .help = "Preallocation mode (allowed values: off, metadata)"
+ },
+ {
+ .name = BLOCK_OPT_LAZY_REFCOUNTS,
+ .type = QEMU_OPT_BOOL,
+ .help = "Postpone refcount updates",
+ .def_value_str = "off"
+ },
+ { /* end of list */ }
+ }
};
static BlockDriver bdrv_qcow2 = {
@@ -2240,7 +2240,7 @@ static BlockDriver bdrv_qcow2 = {
.bdrv_open = qcow2_open,
.bdrv_close = qcow2_close,
.bdrv_reopen_prepare = qcow2_reopen_prepare,
- .bdrv_create = qcow2_create,
+ .bdrv_create2 = qcow2_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_co_get_block_status = qcow2_co_get_block_status,
.bdrv_set_key = qcow2_set_key,
@@ -2270,7 +2270,7 @@ static BlockDriver bdrv_qcow2 = {
.bdrv_invalidate_cache = qcow2_invalidate_cache,
- .create_options = qcow2_create_options,
+ .create_opts = &qcow2_create_opts,
.bdrv_check = qcow2_check,
.bdrv_amend_options = qcow2_amend_options,
};
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 11/25] qcow2.c: replace QEMUOptionParameter with QemuOpts in amend options
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (9 preceding siblings ...)
2014-01-20 14:19 ` [Qemu-devel] [v19 10/25] qcow2.c: replace QEMUOptionParameter with QemuOpts in create Chunyan Liu
@ 2014-01-20 14:19 ` Chunyan Liu
2014-01-20 14:19 ` [Qemu-devel] [v19 12/25] qed.c: replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (14 subsequent siblings)
25 siblings, 0 replies; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:19 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
qcow2.c: replace QEMUOptionParameter with QemuOpts in 'qemu-img amend'
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
block.c | 4 +-
block/qcow2.c | 88 ++++++++++++++++++++-------------------------
include/block/block.h | 2 +-
include/block/block_int.h | 2 +-
qemu-img.c | 17 ++++-----
5 files changed, 51 insertions(+), 62 deletions(-)
diff --git a/block.c b/block.c
index 0dc0b09..8c490c6 100644
--- a/block.c
+++ b/block.c
@@ -5000,12 +5000,12 @@ void bdrv_add_before_write_notifier(BlockDriverState *bs,
notifier_with_return_list_add(&bs->before_write_notifiers, notifier);
}
-int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options)
+int bdrv_amend_options(BlockDriverState *bs, QemuOpts *opts)
{
if (bs->drv->bdrv_amend_options == NULL) {
return -ENOTSUP;
}
- return bs->drv->bdrv_amend_options(bs, options);
+ return bs->drv->bdrv_amend_options(bs, opts);
}
ExtSnapshotPerm bdrv_check_ext_snapshot(BlockDriverState *bs)
diff --git a/block/qcow2.c b/block/qcow2.c
index b7a2e3f..580bc93 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2057,64 +2057,54 @@ static int qcow2_downgrade(BlockDriverState *bs, int target_version)
}
static int qcow2_amend_options(BlockDriverState *bs,
- QEMUOptionParameter *options)
+ QemuOpts *opts)
{
BDRVQcowState *s = bs->opaque;
int old_version = s->qcow_version, new_version = old_version;
uint64_t new_size = 0;
const char *backing_file = NULL, *backing_format = NULL;
bool lazy_refcounts = s->use_lazy_refcounts;
+ const char *compat, *prealloc;
+ uint64_t cluster_size = s->cluster_size;
+ bool encrypt;
int ret;
- int i;
- for (i = 0; options[i].name; i++)
- {
- if (!options[i].assigned) {
- /* only change explicitly defined options */
- continue;
- }
+ compat = qemu_opt_get_del(opts, "compat");
+ if (!compat) {
+ } else if (!strcmp(compat, "0.10")) {
+ new_version = 2;
+ } else if (!strcmp(compat, "1.1")) {
+ new_version = 3;
+ } else {
+ fprintf(stderr, "Unknown compatibility level %s.\n", compat);
+ return -EINVAL;
+ }
+
+ prealloc = qemu_opt_get_del(opts, "preallocation");
+ if (prealloc) {
+ fprintf(stderr, "Cannot change preallocation mode.\n");
+ return -ENOTSUP;
+ }
- if (!strcmp(options[i].name, "compat")) {
- if (!options[i].value.s) {
- /* preserve default */
- } else if (!strcmp(options[i].value.s, "0.10")) {
- new_version = 2;
- } else if (!strcmp(options[i].value.s, "1.1")) {
- new_version = 3;
- } else {
- fprintf(stderr, "Unknown compatibility level %s.\n",
- options[i].value.s);
- return -EINVAL;
- }
- } else if (!strcmp(options[i].name, "preallocation")) {
- fprintf(stderr, "Cannot change preallocation mode.\n");
- return -ENOTSUP;
- } else if (!strcmp(options[i].name, "size")) {
- new_size = options[i].value.n;
- } else if (!strcmp(options[i].name, "backing_file")) {
- backing_file = options[i].value.s;
- } else if (!strcmp(options[i].name, "backing_fmt")) {
- backing_format = options[i].value.s;
- } else if (!strcmp(options[i].name, "encryption")) {
- if ((options[i].value.n != !!s->crypt_method)) {
- fprintf(stderr, "Changing the encryption flag is not "
- "supported.\n");
- return -ENOTSUP;
- }
- } else if (!strcmp(options[i].name, "cluster_size")) {
- if (options[i].value.n != s->cluster_size) {
- fprintf(stderr, "Changing the cluster size is not "
- "supported.\n");
- return -ENOTSUP;
- }
- } else if (!strcmp(options[i].name, "lazy_refcounts")) {
- lazy_refcounts = options[i].value.n;
- } else {
- /* if this assertion fails, this probably means a new option was
- * added without having it covered here */
- assert(false);
- }
+ new_size = qemu_opt_get_size_del(opts, "size", 0);
+ backing_file = qemu_opt_get_del(opts, "backing_file");
+ backing_format = qemu_opt_get_del(opts, "backing_fmt");
+
+ encrypt = qemu_opt_get_bool_del(opts, "encryption", s->crypt_method);
+ if (encrypt != !!s->crypt_method) {
+ fprintf(stderr, "Changing the encryption flag is not "
+ "supported.\n");
+ return -ENOTSUP;
+ }
+
+ cluster_size = qemu_opt_get_size_del(opts, "cluster_size", cluster_size);
+ if (cluster_size != s->cluster_size) {
+ fprintf(stderr, "Changing the cluster size is not "
+ "supported.\n");
+ return -ENOTSUP;
}
+
+ lazy_refcounts = qemu_opt_get_bool_del(opts, "lazy_refcounts", lazy_refcounts);
if (new_version != old_version) {
if (new_version > old_version) {
@@ -2240,7 +2230,7 @@ static BlockDriver bdrv_qcow2 = {
.bdrv_open = qcow2_open,
.bdrv_close = qcow2_close,
.bdrv_reopen_prepare = qcow2_reopen_prepare,
- .bdrv_create2 = qcow2_create,
+ .bdrv_create2 = qcow2_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_co_get_block_status = qcow2_co_get_block_status,
.bdrv_set_key = qcow2_set_key,
diff --git a/include/block/block.h b/include/block/block.h
index 687d423..e23a7da 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -278,7 +278,7 @@ typedef enum {
int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix);
-int bdrv_amend_options(BlockDriverState *bs_new, QEMUOptionParameter *options);
+int bdrv_amend_options(BlockDriverState *bs_new, QemuOpts *opts);
/* external snapshots */
diff --git a/include/block/block_int.h b/include/block/block_int.h
index f0043f8..f5bdd08 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -216,7 +216,7 @@ struct BlockDriver {
BdrvCheckMode fix);
int (*bdrv_amend_options)(BlockDriverState *bs,
- QEMUOptionParameter *options);
+ QemuOpts *opts);
void (*bdrv_debug_event)(BlockDriverState *bs, BlkDebugEvent event);
diff --git a/qemu-img.c b/qemu-img.c
index 05052d9..863bd03 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2692,7 +2692,8 @@ static int img_amend(int argc, char **argv)
{
int c, ret = 0;
char *options = NULL;
- QEMUOptionParameter *create_options = NULL, *options_param = NULL;
+ QemuOptsList *create_opts = NULL;
+ QemuOpts *opts = NULL;
const char *fmt = NULL, *filename;
bool quiet = false;
BlockDriverState *bs = NULL;
@@ -2744,17 +2745,15 @@ static int img_amend(int argc, char **argv)
goto out;
}
- create_options = append_option_parameters(create_options,
- bs->drv->create_options);
- options_param = parse_option_parameters(options, create_options,
- options_param);
- if (options_param == NULL) {
+ create_opts = qemu_opts_append(create_opts, bs->drv->create_opts);
+ opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
+ if (options && qemu_opts_do_parse(opts, options, NULL)) {
error_report("Invalid options for file format '%s'", fmt);
ret = -1;
goto out;
}
- ret = bdrv_amend_options(bs, options_param);
+ ret = bdrv_amend_options(bs, opts);
if (ret < 0) {
error_report("Error while amending options: %s", strerror(-ret));
goto out;
@@ -2764,8 +2763,8 @@ out:
if (bs) {
bdrv_unref(bs);
}
- free_option_parameters(create_options);
- free_option_parameters(options_param);
+ qemu_opts_del(opts);
+ qemu_opts_free(create_opts);
if (ret) {
return 1;
}
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 12/25] qed.c: replace QEMUOptionParameter with QemuOpts
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (10 preceding siblings ...)
2014-01-20 14:19 ` [Qemu-devel] [v19 11/25] qcow2.c: replace QEMUOptionParameter with QemuOpts in amend options Chunyan Liu
@ 2014-01-20 14:19 ` Chunyan Liu
2014-01-22 14:24 ` Kevin Wolf
2014-01-20 14:19 ` [Qemu-devel] [v19 13/25] raw-posix.c: " Chunyan Liu
` (13 subsequent siblings)
25 siblings, 1 reply; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:19 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
qed.c: replace QEMUOptionParameter with QemuOpts
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
block/qed.c | 89 +++++++++++++++++++++++++++++------------------------------
block/qed.h | 3 +-
2 files changed, 45 insertions(+), 47 deletions(-)
diff --git a/block/qed.c b/block/qed.c
index 4221ee2..9f819a8 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -611,7 +611,8 @@ out:
return ret;
}
-static int bdrv_qed_create(const char *filename, QEMUOptionParameter *options,
+
+static int bdrv_qed_create(const char *filename, QemuOpts *opts,
Error **errp)
{
uint64_t image_size = 0;
@@ -620,24 +621,14 @@ static int bdrv_qed_create(const char *filename, QEMUOptionParameter *options,
const char *backing_file = NULL;
const char *backing_fmt = NULL;
- while (options && options->name) {
- if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
- image_size = options->value.n;
- } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
- backing_file = options->value.s;
- } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FMT)) {
- backing_fmt = options->value.s;
- } else if (!strcmp(options->name, BLOCK_OPT_CLUSTER_SIZE)) {
- if (options->value.n) {
- cluster_size = options->value.n;
- }
- } else if (!strcmp(options->name, BLOCK_OPT_TABLE_SIZE)) {
- if (options->value.n) {
- table_size = options->value.n;
- }
- }
- options++;
- }
+ image_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+ backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+ backing_fmt = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT);
+ cluster_size = qemu_opt_get_size_del(opts,
+ BLOCK_OPT_CLUSTER_SIZE,
+ QED_DEFAULT_CLUSTER_SIZE);
+ table_size = qemu_opt_get_size_del(opts, BLOCK_OPT_TABLE_SIZE,
+ QED_DEFAULT_TABLE_SIZE);
if (!qed_is_cluster_size_valid(cluster_size)) {
fprintf(stderr, "QED cluster size must be within range [%u, %u] and power of 2\n",
@@ -1570,43 +1561,51 @@ static int bdrv_qed_check(BlockDriverState *bs, BdrvCheckResult *result,
return qed_check(s, result, !!fix);
}
-static QEMUOptionParameter qed_create_options[] = {
- {
- .name = BLOCK_OPT_SIZE,
- .type = OPT_SIZE,
- .help = "Virtual disk size (in bytes)"
- }, {
- .name = BLOCK_OPT_BACKING_FILE,
- .type = OPT_STRING,
- .help = "File name of a base image"
- }, {
- .name = BLOCK_OPT_BACKING_FMT,
- .type = OPT_STRING,
- .help = "Image format of the base image"
- }, {
- .name = BLOCK_OPT_CLUSTER_SIZE,
- .type = OPT_SIZE,
- .help = "Cluster size (in bytes)",
- .value = { .n = QED_DEFAULT_CLUSTER_SIZE },
- }, {
- .name = BLOCK_OPT_TABLE_SIZE,
- .type = OPT_SIZE,
- .help = "L1/L2 table size (in clusters)"
- },
- { /* end of list */ }
+static QemuOptsList qed_create_opts = {
+ .name = "qed-create-opts",
+ .head = QTAILQ_HEAD_INITIALIZER(qed_create_opts.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size"
+ },
+ {
+ .name = BLOCK_OPT_BACKING_FILE,
+ .type = QEMU_OPT_STRING,
+ .help = "File name of a base image"
+ },
+ {
+ .name = BLOCK_OPT_BACKING_FMT,
+ .type = QEMU_OPT_STRING,
+ .help = "Image format of the base image"
+ },
+ {
+ .name = BLOCK_OPT_CLUSTER_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Cluster size (in bytes)",
+ .def_value_str = stringify(QED_DEFAULT_CLUSTER_SIZE)
+ },
+ {
+ .name = BLOCK_OPT_TABLE_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "L1/L2 table size (in clusters)"
+ },
+ { /* end of list */ }
+ }
};
static BlockDriver bdrv_qed = {
.format_name = "qed",
.instance_size = sizeof(BDRVQEDState),
- .create_options = qed_create_options,
+ .create_opts = &qed_create_opts,
.bdrv_probe = bdrv_qed_probe,
.bdrv_rebind = bdrv_qed_rebind,
.bdrv_open = bdrv_qed_open,
.bdrv_close = bdrv_qed_close,
.bdrv_reopen_prepare = bdrv_qed_reopen_prepare,
- .bdrv_create = bdrv_qed_create,
+ .bdrv_create2 = bdrv_qed_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_co_get_block_status = bdrv_qed_co_get_block_status,
.bdrv_make_empty = bdrv_qed_make_empty,
diff --git a/block/qed.h b/block/qed.h
index 5d65bea..b024751 100644
--- a/block/qed.h
+++ b/block/qed.h
@@ -43,7 +43,7 @@
*
* All fields are little-endian on disk.
*/
-
+#define QED_DEFAULT_CLUSTER_SIZE 65536
enum {
QED_MAGIC = 'Q' | 'E' << 8 | 'D' << 16 | '\0' << 24,
@@ -69,7 +69,6 @@ enum {
*/
QED_MIN_CLUSTER_SIZE = 4 * 1024, /* in bytes */
QED_MAX_CLUSTER_SIZE = 64 * 1024 * 1024,
- QED_DEFAULT_CLUSTER_SIZE = 64 * 1024,
/* Allocated clusters are tracked using a 2-level pagetable. Table size is
* a multiple of clusters so large maximum image sizes can be supported
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* Re: [Qemu-devel] [v19 12/25] qed.c: replace QEMUOptionParameter with QemuOpts
2014-01-20 14:19 ` [Qemu-devel] [v19 12/25] qed.c: replace QEMUOptionParameter with QemuOpts Chunyan Liu
@ 2014-01-22 14:24 ` Kevin Wolf
0 siblings, 0 replies; 38+ messages in thread
From: Kevin Wolf @ 2014-01-22 14:24 UTC (permalink / raw)
To: Chunyan Liu; +Cc: Dong Xu Wang, qemu-devel, stefanha
Am 20.01.2014 um 15:19 hat Chunyan Liu geschrieben:
> qed.c: replace QEMUOptionParameter with QemuOpts
>
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
> block/qed.c | 89 +++++++++++++++++++++++++++++------------------------------
> block/qed.h | 3 +-
> 2 files changed, 45 insertions(+), 47 deletions(-)
> diff --git a/block/qed.h b/block/qed.h
> index 5d65bea..b024751 100644
> --- a/block/qed.h
> +++ b/block/qed.h
> @@ -43,7 +43,7 @@
> *
> * All fields are little-endian on disk.
> */
> -
> +#define QED_DEFAULT_CLUSTER_SIZE 65536
> enum {
> QED_MAGIC = 'Q' | 'E' << 8 | 'D' << 16 | '\0' << 24,
>
> @@ -69,7 +69,6 @@ enum {
> */
> QED_MIN_CLUSTER_SIZE = 4 * 1024, /* in bytes */
> QED_MAX_CLUSTER_SIZE = 64 * 1024 * 1024,
> - QED_DEFAULT_CLUSTER_SIZE = 64 * 1024,
>
> /* Allocated clusters are tracked using a 2-level pagetable. Table size is
> * a multiple of clusters so large maximum image sizes can be supported
What is this hunk good for?
Kevin
^ permalink raw reply [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 13/25] raw-posix.c: replace QEMUOptionParameter with QemuOpts
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (11 preceding siblings ...)
2014-01-20 14:19 ` [Qemu-devel] [v19 12/25] qed.c: replace QEMUOptionParameter with QemuOpts Chunyan Liu
@ 2014-01-20 14:19 ` Chunyan Liu
2014-01-20 14:19 ` [Qemu-devel] [v19 14/25] raw-win32.c: " Chunyan Liu
` (12 subsequent siblings)
25 siblings, 0 replies; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:19 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
raw-posix.c: replace QEMUOptionParameter with QemuOpts
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
block/raw-posix.c | 60 ++++++++++++++++++++++++----------------------------
1 files changed, 28 insertions(+), 32 deletions(-)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 0676037..0661791 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1160,7 +1160,7 @@ static int64_t raw_get_allocated_file_size(BlockDriverState *bs)
return (int64_t)st.st_blocks * 512;
}
-static int raw_create(const char *filename, QEMUOptionParameter *options,
+static int raw_create(const char *filename, QemuOpts *opts,
Error **errp)
{
int fd;
@@ -1168,13 +1168,9 @@ static int raw_create(const char *filename, QEMUOptionParameter *options,
int64_t total_size = 0;
/* Read out options */
- while (options && options->name) {
- if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
- total_size = options->value.n / BDRV_SECTOR_SIZE;
- }
- options++;
- }
-
+ total_size =
+ qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
+
fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
0644);
if (fd < 0) {
@@ -1334,13 +1330,17 @@ static int raw_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
return 0;
}
-static QEMUOptionParameter raw_create_options[] = {
- {
- .name = BLOCK_OPT_SIZE,
- .type = OPT_SIZE,
- .help = "Virtual disk size"
- },
- { NULL }
+static QemuOptsList raw_create_opts = {
+ .name = "raw-create-opts",
+ .head = QTAILQ_HEAD_INITIALIZER(raw_create_opts.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size"
+ },
+ { /* end of list */ }
+ }
};
static BlockDriver bdrv_file = {
@@ -1354,7 +1354,7 @@ static BlockDriver bdrv_file = {
.bdrv_reopen_commit = raw_reopen_commit,
.bdrv_reopen_abort = raw_reopen_abort,
.bdrv_close = raw_close,
- .bdrv_create = raw_create,
+ .bdrv_create2 = raw_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_co_get_block_status = raw_co_get_block_status,
.bdrv_co_write_zeroes = raw_co_write_zeroes,
@@ -1370,7 +1370,7 @@ static BlockDriver bdrv_file = {
.bdrv_get_allocated_file_size
= raw_get_allocated_file_size,
- .create_options = raw_create_options,
+ .create_opts = &raw_create_opts,
};
/***********************************************/
@@ -1682,7 +1682,7 @@ static coroutine_fn int hdev_co_write_zeroes(BlockDriverState *bs,
return -ENOTSUP;
}
-static int hdev_create(const char *filename, QEMUOptionParameter *options,
+static int hdev_create(const char *filename, QemuOpts *opts,
Error **errp)
{
int fd;
@@ -1691,12 +1691,8 @@ static int hdev_create(const char *filename, QEMUOptionParameter *options,
int64_t total_size = 0;
/* Read out options */
- while (options && options->name) {
- if (!strcmp(options->name, "size")) {
- total_size = options->value.n / BDRV_SECTOR_SIZE;
- }
- options++;
- }
+ total_size =
+ qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
fd = qemu_open(filename, O_WRONLY | O_BINARY);
if (fd < 0) {
@@ -1732,8 +1728,8 @@ static BlockDriver bdrv_host_device = {
.bdrv_reopen_prepare = raw_reopen_prepare,
.bdrv_reopen_commit = raw_reopen_commit,
.bdrv_reopen_abort = raw_reopen_abort,
- .bdrv_create = hdev_create,
- .create_options = raw_create_options,
+ .bdrv_create2 = hdev_create,
+ .create_opts = &raw_create_opts,
.bdrv_co_write_zeroes = hdev_co_write_zeroes,
.bdrv_aio_readv = raw_aio_readv,
@@ -1865,8 +1861,8 @@ static BlockDriver bdrv_host_floppy = {
.bdrv_reopen_prepare = raw_reopen_prepare,
.bdrv_reopen_commit = raw_reopen_commit,
.bdrv_reopen_abort = raw_reopen_abort,
- .bdrv_create = hdev_create,
- .create_options = raw_create_options,
+ .bdrv_create2 = hdev_create,
+ .create_opts = &raw_create_opts,
.bdrv_aio_readv = raw_aio_readv,
.bdrv_aio_writev = raw_aio_writev,
@@ -1975,8 +1971,8 @@ static BlockDriver bdrv_host_cdrom = {
.bdrv_reopen_prepare = raw_reopen_prepare,
.bdrv_reopen_commit = raw_reopen_commit,
.bdrv_reopen_abort = raw_reopen_abort,
- .bdrv_create = hdev_create,
- .create_options = raw_create_options,
+ .bdrv_create2 = hdev_create,
+ .create_opts = &raw_create_opts,
.bdrv_aio_readv = raw_aio_readv,
.bdrv_aio_writev = raw_aio_writev,
@@ -2104,8 +2100,8 @@ static BlockDriver bdrv_host_cdrom = {
.bdrv_reopen_prepare = raw_reopen_prepare,
.bdrv_reopen_commit = raw_reopen_commit,
.bdrv_reopen_abort = raw_reopen_abort,
- .bdrv_create = hdev_create,
- .create_options = raw_create_options,
+ .bdrv_create2 = hdev_create,
+ .create_opts = &raw_create_opts,
.bdrv_aio_readv = raw_aio_readv,
.bdrv_aio_writev = raw_aio_writev,
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 14/25] raw-win32.c: replace QEMUOptionParameter with QemuOpts
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (12 preceding siblings ...)
2014-01-20 14:19 ` [Qemu-devel] [v19 13/25] raw-posix.c: " Chunyan Liu
@ 2014-01-20 14:19 ` Chunyan Liu
2014-01-20 14:19 ` [Qemu-devel] [v19 15/25] rbd.c: " Chunyan Liu
` (11 subsequent siblings)
25 siblings, 0 replies; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:19 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
raw-win32.c: replace QEMUOptionParameter with QemuOpts
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
block/raw-win32.c | 33 +++++++++++++++++----------------
1 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/block/raw-win32.c b/block/raw-win32.c
index ce314fd..1e957d2 100644
--- a/block/raw-win32.c
+++ b/block/raw-win32.c
@@ -423,19 +423,15 @@ static int64_t raw_get_allocated_file_size(BlockDriverState *bs)
return st.st_size;
}
-static int raw_create(const char *filename, QEMUOptionParameter *options,
+static int raw_create(const char *filename, QemuOpts *opts,
Error **errp)
{
int fd;
int64_t total_size = 0;
/* Read out options */
- while (options && options->name) {
- if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
- total_size = options->value.n / 512;
- }
- options++;
- }
+ total_size =
+ qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512;
fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
0644);
@@ -449,13 +445,18 @@ static int raw_create(const char *filename, QEMUOptionParameter *options,
return 0;
}
-static QEMUOptionParameter raw_create_options[] = {
- {
- .name = BLOCK_OPT_SIZE,
- .type = OPT_SIZE,
- .help = "Virtual disk size"
- },
- { NULL }
+
+static QemuOptsList raw_create_opts = {
+ .name = "raw-create-opts",
+ .head = QTAILQ_HEAD_INITIALIZER(raw_create_opts.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size"
+ },
+ { /* end of list */ }
+ }
};
static BlockDriver bdrv_file = {
@@ -465,7 +466,7 @@ static BlockDriver bdrv_file = {
.bdrv_needs_filename = true,
.bdrv_file_open = raw_open,
.bdrv_close = raw_close,
- .bdrv_create = raw_create,
+ .bdrv_create2 = raw_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_aio_readv = raw_aio_readv,
@@ -477,7 +478,7 @@ static BlockDriver bdrv_file = {
.bdrv_get_allocated_file_size
= raw_get_allocated_file_size,
- .create_options = raw_create_options,
+ .create_opts = &raw_create_opts,
};
/***********************************************/
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 15/25] rbd.c: replace QEMUOptionParameter with QemuOpts
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (13 preceding siblings ...)
2014-01-20 14:19 ` [Qemu-devel] [v19 14/25] raw-win32.c: " Chunyan Liu
@ 2014-01-20 14:19 ` Chunyan Liu
2014-01-20 14:19 ` [Qemu-devel] [v19 16/25] sheepdog.c: " Chunyan Liu
` (10 subsequent siblings)
25 siblings, 0 replies; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:19 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
rbd.c: replace QEMUOptionParameter with QemuOpts
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
block/rbd.c | 63 +++++++++++++++++++++++++++++------------------------------
1 files changed, 31 insertions(+), 32 deletions(-)
diff --git a/block/rbd.c b/block/rbd.c
index f453f04..6e82f10 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -287,7 +287,7 @@ static int qemu_rbd_set_conf(rados_t cluster, const char *conf)
return ret;
}
-static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options,
+static int qemu_rbd_create(const char *filename, QemuOpts *opts,
Error **errp)
{
int64_t bytes = 0;
@@ -311,24 +311,18 @@ static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options,
}
/* Read out options */
- while (options && options->name) {
- if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
- bytes = options->value.n;
- } else if (!strcmp(options->name, BLOCK_OPT_CLUSTER_SIZE)) {
- if (options->value.n) {
- objsize = options->value.n;
- if ((objsize - 1) & objsize) { /* not a power of 2? */
- error_report("obj size needs to be power of 2");
- return -EINVAL;
- }
- if (objsize < 4096) {
- error_report("obj size too small");
- return -EINVAL;
- }
- obj_order = ffs(objsize) - 1;
- }
+ bytes = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+ objsize = qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE, 0);
+ if (objsize) {
+ if ((objsize - 1) & objsize) { /* not a power of 2? */
+ error_report("obj size needs to be power of 2");
+ return -EINVAL;
+ }
+ if (objsize < 4096) {
+ error_report("obj size too small");
+ return -EINVAL;
}
- options++;
+ obj_order = ffs(objsize) - 1;
}
clientname = qemu_rbd_parse_clientname(conf, clientname_buf);
@@ -986,18 +980,23 @@ static BlockDriverAIOCB* qemu_rbd_aio_discard(BlockDriverState *bs,
}
#endif
-static QEMUOptionParameter qemu_rbd_create_options[] = {
- {
- .name = BLOCK_OPT_SIZE,
- .type = OPT_SIZE,
- .help = "Virtual disk size"
- },
- {
- .name = BLOCK_OPT_CLUSTER_SIZE,
- .type = OPT_SIZE,
- .help = "RBD object size"
- },
- {NULL}
+static QemuOptsList qemu_rbd_create_opts = {
+ .name = "rbd-create-opts",
+ .head = QTAILQ_HEAD_INITIALIZER(qemu_rbd_create_opts.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size"
+ },
+ {
+ .name = BLOCK_OPT_CLUSTER_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "RBD object size",
+ .def_value_str = stringify(0),
+ },
+ { /* end of list */ }
+ }
};
static BlockDriver bdrv_rbd = {
@@ -1006,10 +1005,10 @@ static BlockDriver bdrv_rbd = {
.bdrv_needs_filename = true,
.bdrv_file_open = qemu_rbd_open,
.bdrv_close = qemu_rbd_close,
- .bdrv_create = qemu_rbd_create,
+ .bdrv_create2 = qemu_rbd_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_get_info = qemu_rbd_getinfo,
- .create_options = qemu_rbd_create_options,
+ .create_opts = qemu_rbd_create_opts,
.bdrv_getlength = qemu_rbd_getlength,
.bdrv_truncate = qemu_rbd_truncate,
.protocol_name = "rbd",
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 16/25] sheepdog.c: replace QEMUOptionParameter with QemuOpts
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (14 preceding siblings ...)
2014-01-20 14:19 ` [Qemu-devel] [v19 15/25] rbd.c: " Chunyan Liu
@ 2014-01-20 14:19 ` Chunyan Liu
2014-01-20 14:20 ` [Qemu-devel] [v19 17/25] ssh.c: " Chunyan Liu
` (9 subsequent siblings)
25 siblings, 0 replies; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:19 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
sheepdog.c: replace QEMUOptionParameter with QemuOpts
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
block/sheepdog.c | 101 +++++++++++++++++++++++++-----------------------------
1 files changed, 47 insertions(+), 54 deletions(-)
diff --git a/block/sheepdog.c b/block/sheepdog.c
index b94ab6e..13ac0d0 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1625,12 +1625,13 @@ static int parse_redundancy(BDRVSheepdogState *s, const char *opt)
return 0;
}
-static int sd_create(const char *filename, QEMUOptionParameter *options,
+static int sd_create(const char *filename, QemuOpts *opts,
Error **errp)
{
int ret = 0;
uint32_t vid = 0;
- char *backing_file = NULL;
+ const char *backing_file = NULL;
+ const char *buf = NULL;
BDRVSheepdogState *s;
char tag[SD_MAX_VDI_TAG_LEN];
uint32_t snapid;
@@ -1649,31 +1650,26 @@ static int sd_create(const char *filename, QEMUOptionParameter *options,
goto out;
}
- while (options && options->name) {
- if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
- s->inode.vdi_size = options->value.n;
- } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
- backing_file = options->value.s;
- } else if (!strcmp(options->name, BLOCK_OPT_PREALLOC)) {
- if (!options->value.s || !strcmp(options->value.s, "off")) {
- prealloc = false;
- } else if (!strcmp(options->value.s, "full")) {
- prealloc = true;
- } else {
- error_report("Invalid preallocation mode: '%s'",
- options->value.s);
- ret = -EINVAL;
- goto out;
- }
- } else if (!strcmp(options->name, BLOCK_OPT_REDUNDANCY)) {
- if (options->value.s) {
- ret = parse_redundancy(s, options->value.s);
- if (ret < 0) {
- goto out;
- }
- }
+ s->inode.vdi_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+ backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+ buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
+ if (!buf || !strcmp(buf, "off")) {
+ prealloc = false;
+ } else if (!strcmp(buf, "full")) {
+ prealloc = true;
+ } else {
+ error_report("Invalid preallocation mode: '%s'", buf);
+ ret = -EINVAL;
+ goto out;
+ }
+
+ buf = NULL;
+ buf = qemu_opt_get_del(opts, BLOCK_OPT_REDUNDANCY);
+ if (buf) {
+ ret = parse_redundancy(s, buf);
+ if (ret < 0) {
+ goto out;
}
- options++;
}
if (s->inode.vdi_size > SD_MAX_VDI_SIZE) {
@@ -2486,28 +2482,27 @@ static int64_t sd_get_allocated_file_size(BlockDriverState *bs)
return size;
}
-static QEMUOptionParameter sd_create_options[] = {
- {
- .name = BLOCK_OPT_SIZE,
- .type = OPT_SIZE,
- .help = "Virtual disk size"
- },
- {
- .name = BLOCK_OPT_BACKING_FILE,
- .type = OPT_STRING,
- .help = "File name of a base image"
- },
- {
- .name = BLOCK_OPT_PREALLOC,
- .type = OPT_STRING,
- .help = "Preallocation mode (allowed values: off, full)"
- },
- {
- .name = BLOCK_OPT_REDUNDANCY,
- .type = OPT_STRING,
- .help = "Redundancy of the image"
- },
- { NULL }
+static QemuOptsList sd_create_opts = {
+ .name = "sheepdog-create-opts",
+ .head = QTAILQ_HEAD_INITIALIZER(sd_create_opts.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size"
+ },
+ {
+ .name = BLOCK_OPT_BACKING_FILE,
+ .type = QEMU_OPT_STRING,
+ .help = "File name of a base image"
+ },
+ {
+ .name = BLOCK_OPT_PREALLOC,
+ .type = QEMU_OPT_STRING,
+ .help = "Preallocation mode (allowed values: off, full)"
+ },
+ { /* end of list */ }
+ }
};
static BlockDriver bdrv_sheepdog = {
@@ -2517,7 +2512,7 @@ static BlockDriver bdrv_sheepdog = {
.bdrv_needs_filename = true,
.bdrv_file_open = sd_open,
.bdrv_close = sd_close,
- .bdrv_create = sd_create,
+ .bdrv_create2 = sd_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_getlength = sd_getlength,
.bdrv_get_allocated_file_size = sd_get_allocated_file_size,
@@ -2537,7 +2532,7 @@ static BlockDriver bdrv_sheepdog = {
.bdrv_save_vmstate = sd_save_vmstate,
.bdrv_load_vmstate = sd_load_vmstate,
- .create_options = sd_create_options,
+ .create_opts = &sd_create_opts,
};
static BlockDriver bdrv_sheepdog_tcp = {
@@ -2547,7 +2542,7 @@ static BlockDriver bdrv_sheepdog_tcp = {
.bdrv_needs_filename = true,
.bdrv_file_open = sd_open,
.bdrv_close = sd_close,
- .bdrv_create = sd_create,
+ .bdrv_create2 = sd_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_getlength = sd_getlength,
.bdrv_get_allocated_file_size = sd_get_allocated_file_size,
@@ -2567,7 +2562,6 @@ static BlockDriver bdrv_sheepdog_tcp = {
.bdrv_save_vmstate = sd_save_vmstate,
.bdrv_load_vmstate = sd_load_vmstate,
- .create_options = sd_create_options,
};
static BlockDriver bdrv_sheepdog_unix = {
@@ -2577,7 +2571,7 @@ static BlockDriver bdrv_sheepdog_unix = {
.bdrv_needs_filename = true,
.bdrv_file_open = sd_open,
.bdrv_close = sd_close,
- .bdrv_create = sd_create,
+ .bdrv_create2 = sd_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_getlength = sd_getlength,
.bdrv_get_allocated_file_size = sd_get_allocated_file_size,
@@ -2597,7 +2591,6 @@ static BlockDriver bdrv_sheepdog_unix = {
.bdrv_save_vmstate = sd_save_vmstate,
.bdrv_load_vmstate = sd_load_vmstate,
- .create_options = sd_create_options,
};
static void bdrv_sheepdog_init(void)
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 17/25] ssh.c: replace QEMUOptionParameter with QemuOpts
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (15 preceding siblings ...)
2014-01-20 14:19 ` [Qemu-devel] [v19 16/25] sheepdog.c: " Chunyan Liu
@ 2014-01-20 14:20 ` Chunyan Liu
2014-01-20 14:20 ` [Qemu-devel] [v19 18/25] vdi.c: " Chunyan Liu
` (8 subsequent siblings)
25 siblings, 0 replies; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:20 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
ssh.c: replace QEMUOptionParameter with QemuOpts
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
block/ssh.c | 31 +++++++++++++++----------------
1 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/block/ssh.c b/block/ssh.c
index aa63c9d..8fd2175 100644
--- a/block/ssh.c
+++ b/block/ssh.c
@@ -642,16 +642,20 @@ static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags,
return ret;
}
-static QEMUOptionParameter ssh_create_options[] = {
- {
- .name = BLOCK_OPT_SIZE,
- .type = OPT_SIZE,
- .help = "Virtual disk size"
- },
- { NULL }
+static QemuOptsList ssh_create_opts = {
+ .name = "ssh-create-opts",
+ .head = QTAILQ_HEAD_INITIALIZER(ssh_create_opts.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size"
+ },
+ { /* end of list */ }
+ }
};
-static int ssh_create(const char *filename, QEMUOptionParameter *options,
+static int ssh_create(const char *filename, QemuOpts *opts,
Error **errp)
{
int r, ret;
@@ -665,12 +669,7 @@ static int ssh_create(const char *filename, QEMUOptionParameter *options,
ssh_state_init(&s);
/* Get desired file size. */
- while (options && options->name) {
- if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
- total_size = options->value.n;
- }
- options++;
- }
+ total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
DPRINTF("total_size=%" PRIi64, total_size);
uri_options = qdict_new();
@@ -1044,14 +1043,14 @@ static BlockDriver bdrv_ssh = {
.instance_size = sizeof(BDRVSSHState),
.bdrv_parse_filename = ssh_parse_filename,
.bdrv_file_open = ssh_file_open,
- .bdrv_create = ssh_create,
+ .bdrv_create2 = ssh_create,
.bdrv_close = ssh_close,
.bdrv_has_zero_init = ssh_has_zero_init,
.bdrv_co_readv = ssh_co_readv,
.bdrv_co_writev = ssh_co_writev,
.bdrv_getlength = ssh_getlength,
.bdrv_co_flush_to_disk = ssh_co_flush,
- .create_options = ssh_create_options,
+ .create_opts = &ssh_create_opts,
};
static void bdrv_ssh_init(void)
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 18/25] vdi.c: replace QEMUOptionParameter with QemuOpts
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (16 preceding siblings ...)
2014-01-20 14:20 ` [Qemu-devel] [v19 17/25] ssh.c: " Chunyan Liu
@ 2014-01-20 14:20 ` Chunyan Liu
2014-01-20 14:20 ` [Qemu-devel] [v19 19/25] vmdk.c: " Chunyan Liu
` (7 subsequent siblings)
25 siblings, 0 replies; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:20 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
vdi.c: replace QEMUOptionParameter with QemuOpts
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
block/vdi.c | 71 ++++++++++++++++++++++++++++------------------------------
1 files changed, 34 insertions(+), 37 deletions(-)
diff --git a/block/vdi.c b/block/vdi.c
index 2d7490f..e5494a0 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -646,7 +646,7 @@ static int vdi_co_write(BlockDriverState *bs,
return ret;
}
-static int vdi_create(const char *filename, QEMUOptionParameter *options,
+static int vdi_create(const char *filename, QemuOpts *opts,
Error **errp)
{
int fd;
@@ -662,25 +662,17 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options,
logout("\n");
/* Read out options. */
- while (options && options->name) {
- if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
- bytes = options->value.n;
+ bytes = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
#if defined(CONFIG_VDI_BLOCK_SIZE)
- } else if (!strcmp(options->name, BLOCK_OPT_CLUSTER_SIZE)) {
- if (options->value.n) {
- /* TODO: Additional checks (SECTOR_SIZE * 2^n, ...). */
- block_size = options->value.n;
- }
+ block_size = qemu_opt_get_size_del(opts,
+ BLOCK_OPT_CLUSTER_SIZE,
+ DEFAULT_CLUSTER_SIZE);
#endif
#if defined(CONFIG_VDI_STATIC_IMAGE)
- } else if (!strcmp(options->name, BLOCK_OPT_STATIC)) {
- if (options->value.n) {
- image_type = VDI_TYPE_STATIC;
- }
-#endif
- }
- options++;
+ if (qemu_opt_get_bool_del(opts, BLOCK_OPT_STATIC, false)) {
+ image_type = VDI_TYPE_STATIC;
}
+#endif
fd = qemu_open(filename,
O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE,
@@ -760,29 +752,34 @@ static void vdi_close(BlockDriverState *bs)
error_free(s->migration_blocker);
}
-static QEMUOptionParameter vdi_create_options[] = {
- {
- .name = BLOCK_OPT_SIZE,
- .type = OPT_SIZE,
- .help = "Virtual disk size"
- },
+static QemuOptsList vdi_create_opts = {
+ .name = "vdi-create-opts",
+ .head = QTAILQ_HEAD_INITIALIZER(vdi_create_opts.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size"
+ },
#if defined(CONFIG_VDI_BLOCK_SIZE)
- {
- .name = BLOCK_OPT_CLUSTER_SIZE,
- .type = OPT_SIZE,
- .help = "VDI cluster (block) size",
- .value = { .n = DEFAULT_CLUSTER_SIZE },
- },
+ {
+ .name = BLOCK_OPT_CLUSTER_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "VDI cluster (block) size",
+ .def_value_str = stringify(DEFAULT_CLUSTER_SIZE)
+ },
#endif
#if defined(CONFIG_VDI_STATIC_IMAGE)
- {
- .name = BLOCK_OPT_STATIC,
- .type = OPT_FLAG,
- .help = "VDI static (pre-allocated) image"
- },
+ {
+ .name = BLOCK_OPT_STATIC,
+ .type = QEMU_OPT_BOOL,
+ .help = "VDI static (pre-allocated) image",
+ .def_value_str = "off"
+ },
#endif
- /* TODO: An additional option to set UUID values might be useful. */
- { NULL }
+ /* TODO: An additional option to set UUID values might be useful. */
+ { /* end of list */ }
+ }
};
static BlockDriver bdrv_vdi = {
@@ -792,7 +789,7 @@ static BlockDriver bdrv_vdi = {
.bdrv_open = vdi_open,
.bdrv_close = vdi_close,
.bdrv_reopen_prepare = vdi_reopen_prepare,
- .bdrv_create = vdi_create,
+ .bdrv_create2 = vdi_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_co_get_block_status = vdi_co_get_block_status,
.bdrv_make_empty = vdi_make_empty,
@@ -804,7 +801,7 @@ static BlockDriver bdrv_vdi = {
.bdrv_get_info = vdi_get_info,
- .create_options = vdi_create_options,
+ .create_opts = &vdi_create_opts,
.bdrv_check = vdi_check,
};
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 19/25] vmdk.c: replace QEMUOptionParameter with QemuOpts
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (17 preceding siblings ...)
2014-01-20 14:20 ` [Qemu-devel] [v19 18/25] vdi.c: " Chunyan Liu
@ 2014-01-20 14:20 ` Chunyan Liu
2014-01-20 14:20 ` [Qemu-devel] [v19 20/25] vpc.c: " Chunyan Liu
` (6 subsequent siblings)
25 siblings, 0 replies; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:20 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
vmdk.c: replace QEMUOptionParameter with QemuOpts
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
block/vmdk.c | 109 +++++++++++++++++++++++++++++----------------------------
1 files changed, 55 insertions(+), 54 deletions(-)
diff --git a/block/vmdk.c b/block/vmdk.c
index 974eaff..c3d4328 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1617,7 +1617,7 @@ static int filename_decompose(const char *filename, char *path, char *prefix,
return VMDK_OK;
}
-static int vmdk_create(const char *filename, QEMUOptionParameter *options,
+static int vmdk_create(const char *filename, QemuOpts *opts,
Error **errp)
{
int idx = 0;
@@ -1667,22 +1667,17 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
goto exit;
}
/* Read out options */
- while (options && options->name) {
- if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
- total_size = options->value.n;
- } else if (!strcmp(options->name, BLOCK_OPT_ADAPTER_TYPE)) {
- adapter_type = options->value.s;
- } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
- backing_file = options->value.s;
- } else if (!strcmp(options->name, BLOCK_OPT_COMPAT6)) {
- flags |= options->value.n ? BLOCK_FLAG_COMPAT6 : 0;
- } else if (!strcmp(options->name, BLOCK_OPT_SUBFMT)) {
- fmt = options->value.s;
- } else if (!strcmp(options->name, BLOCK_OPT_ZEROED_GRAIN)) {
- zeroed_grain |= options->value.n;
- }
- options++;
+ total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+ adapter_type = qemu_opt_get_del(opts, BLOCK_OPT_ADAPTER_TYPE);
+ backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+ if (qemu_opt_get_bool_del(opts, BLOCK_OPT_COMPAT6, false)) {
+ flags |= BLOCK_FLAG_COMPAT6;
+ }
+ fmt = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT);
+ if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ZEROED_GRAIN, false)) {
+ zeroed_grain = true;
}
+
if (!adapter_type) {
adapter_type = "ide";
} else if (strcmp(adapter_type, "ide") &&
@@ -1801,7 +1796,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
if (!split && !flat) {
desc_offset = 0x200;
} else {
- ret = bdrv_create_file(filename, options, NULL, &local_err);
+ ret = bdrv_create_file(filename, NULL, opts, &local_err);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not create image file");
goto exit;
@@ -1949,41 +1944,47 @@ static ImageInfoSpecific *vmdk_get_specific_info(BlockDriverState *bs)
return spec_info;
}
-static QEMUOptionParameter vmdk_create_options[] = {
- {
- .name = BLOCK_OPT_SIZE,
- .type = OPT_SIZE,
- .help = "Virtual disk size"
- },
- {
- .name = BLOCK_OPT_ADAPTER_TYPE,
- .type = OPT_STRING,
- .help = "Virtual adapter type, can be one of "
- "ide (default), lsilogic, buslogic or legacyESX"
- },
- {
- .name = BLOCK_OPT_BACKING_FILE,
- .type = OPT_STRING,
- .help = "File name of a base image"
- },
- {
- .name = BLOCK_OPT_COMPAT6,
- .type = OPT_FLAG,
- .help = "VMDK version 6 image"
- },
- {
- .name = BLOCK_OPT_SUBFMT,
- .type = OPT_STRING,
- .help =
- "VMDK flat extent format, can be one of "
- "{monolithicSparse (default) | monolithicFlat | twoGbMaxExtentSparse | twoGbMaxExtentFlat | streamOptimized} "
- },
- {
- .name = BLOCK_OPT_ZEROED_GRAIN,
- .type = OPT_FLAG,
- .help = "Enable efficient zero writes using the zeroed-grain GTE feature"
- },
- { NULL }
+static QemuOptsList vmdk_create_opts = {
+ .name = "vmdk-create-opts",
+ .head = QTAILQ_HEAD_INITIALIZER(vmdk_create_opts.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size"
+ },
+ {
+ .name = BLOCK_OPT_ADAPTER_TYPE,
+ .type = QEMU_OPT_STRING,
+ .help = "Virtual adapter type, can be one of "
+ "ide (default), lsilogic, buslogic or legacyESX"
+ },
+ {
+ .name = BLOCK_OPT_BACKING_FILE,
+ .type = QEMU_OPT_STRING,
+ .help = "File name of a base image"
+ },
+ {
+ .name = BLOCK_OPT_COMPAT6,
+ .type = QEMU_OPT_BOOL,
+ .help = "VMDK version 6 image",
+ .def_value_str = "off"
+ },
+ {
+ .name = BLOCK_OPT_SUBFMT,
+ .type = QEMU_OPT_STRING,
+ .help =
+ "VMDK flat extent format, can be one of "
+ "{monolithicSparse (default) | monolithicFlat | twoGbMaxExtentSparse | twoGbMaxExtentFlat | streamOptimized} "
+ },
+ {
+ .name = BLOCK_OPT_ZEROED_GRAIN,
+ .type = QEMU_OPT_BOOL,
+ .help = "Enable efficient zero writes "
+ "using the zeroed-grain GTE feature"
+ },
+ { /* end of list */ }
+ }
};
static BlockDriver bdrv_vmdk = {
@@ -1996,14 +1997,14 @@ static BlockDriver bdrv_vmdk = {
.bdrv_write = vmdk_co_write,
.bdrv_co_write_zeroes = vmdk_co_write_zeroes,
.bdrv_close = vmdk_close,
- .bdrv_create = vmdk_create,
+ .bdrv_create2 = vmdk_create,
.bdrv_co_flush_to_disk = vmdk_co_flush,
.bdrv_co_get_block_status = vmdk_co_get_block_status,
.bdrv_get_allocated_file_size = vmdk_get_allocated_file_size,
.bdrv_has_zero_init = vmdk_has_zero_init,
.bdrv_get_specific_info = vmdk_get_specific_info,
- .create_options = vmdk_create_options,
+ .create_opts = &vmdk_create_opts,
};
static void bdrv_vmdk_init(void)
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 20/25] vpc.c: replace QEMUOptionParameter with QemuOpts
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (18 preceding siblings ...)
2014-01-20 14:20 ` [Qemu-devel] [v19 19/25] vmdk.c: " Chunyan Liu
@ 2014-01-20 14:20 ` Chunyan Liu
2014-01-20 14:20 ` [Qemu-devel] [v19 21/25] raw_bsd.c: " Chunyan Liu
` (5 subsequent siblings)
25 siblings, 0 replies; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:20 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
vpc.c: replace QEMUOptionParameter with QemuOpts
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
block/vpc.c | 52 +++++++++++++++++++++++++++-------------------------
1 files changed, 27 insertions(+), 25 deletions(-)
diff --git a/block/vpc.c b/block/vpc.c
index 1d326cb..f77f4a5 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -713,12 +713,12 @@ static int create_fixed_disk(int fd, uint8_t *buf, int64_t total_size)
return ret;
}
-static int vpc_create(const char *filename, QEMUOptionParameter *options,
+static int vpc_create(const char *filename, QemuOpts *opts,
Error **errp)
{
uint8_t buf[1024];
VHDFooter *footer = (VHDFooter *) buf;
- QEMUOptionParameter *disk_type_param;
+ const char *disk_type_param;
int fd, i;
uint16_t cyls = 0;
uint8_t heads = 0;
@@ -729,13 +729,12 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options,
int ret = -EIO;
/* Read out options */
- total_size = get_option_parameter(options, BLOCK_OPT_SIZE)->value.n;
-
- disk_type_param = get_option_parameter(options, BLOCK_OPT_SUBFMT);
- if (disk_type_param && disk_type_param->value.s) {
- if (!strcmp(disk_type_param->value.s, "dynamic")) {
+ total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+ disk_type_param = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT);
+ if (disk_type_param) {
+ if (!strcmp(disk_type_param, "dynamic")) {
disk_type = VHD_DYNAMIC;
- } else if (!strcmp(disk_type_param->value.s, "fixed")) {
+ } else if (!strcmp(disk_type_param, "fixed")) {
disk_type = VHD_FIXED;
} else {
return -EINVAL;
@@ -841,20 +840,24 @@ static void vpc_close(BlockDriverState *bs)
error_free(s->migration_blocker);
}
-static QEMUOptionParameter vpc_create_options[] = {
- {
- .name = BLOCK_OPT_SIZE,
- .type = OPT_SIZE,
- .help = "Virtual disk size"
- },
- {
- .name = BLOCK_OPT_SUBFMT,
- .type = OPT_STRING,
- .help =
- "Type of virtual hard disk format. Supported formats are "
- "{dynamic (default) | fixed} "
- },
- { NULL }
+static QemuOptsList vpc_create_opts = {
+ .name = "vpc-create-opts",
+ .head = QTAILQ_HEAD_INITIALIZER(vpc_create_opts.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size"
+ },
+ {
+ .name = BLOCK_OPT_SUBFMT,
+ .type = QEMU_OPT_STRING,
+ .help =
+ "Type of virtual hard disk format. Supported formats are "
+ "{dynamic (default) | fixed} "
+ },
+ { /* end of list */ }
+ }
};
static BlockDriver bdrv_vpc = {
@@ -865,14 +868,13 @@ static BlockDriver bdrv_vpc = {
.bdrv_open = vpc_open,
.bdrv_close = vpc_close,
.bdrv_reopen_prepare = vpc_reopen_prepare,
- .bdrv_create = vpc_create,
-
+ .bdrv_create2 = vpc_create,
.bdrv_read = vpc_co_read,
.bdrv_write = vpc_co_write,
.bdrv_get_info = vpc_get_info,
- .create_options = vpc_create_options,
+ .create_opts = &vpc_create_opts,
.bdrv_has_zero_init = vpc_has_zero_init,
};
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 21/25] raw_bsd.c: replace QEMUOptionParameter with QemuOpts
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (19 preceding siblings ...)
2014-01-20 14:20 ` [Qemu-devel] [v19 20/25] vpc.c: " Chunyan Liu
@ 2014-01-20 14:20 ` Chunyan Liu
2014-01-20 14:20 ` [Qemu-devel] [v19 22/25] vhdx.c: " Chunyan Liu
` (4 subsequent siblings)
25 siblings, 0 replies; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:20 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
raw_bsd.c: replace QEMUOptionParameter with QemuOpts
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
block/raw_bsd.c | 27 ++++++++++++++++-----------
1 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index 297e03f..4ae12dd 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -29,13 +29,17 @@
#include "block/block_int.h"
#include "qemu/option.h"
-static QEMUOptionParameter raw_create_options[] = {
- {
- .name = BLOCK_OPT_SIZE,
- .type = OPT_SIZE,
- .help = "Virtual disk size"
- },
- { 0 }
+static QemuOptsList raw_create_opts = {
+ .name = "raw-create-opts",
+ .head = QTAILQ_HEAD_INITIALIZER(raw_create_opts.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size"
+ },
+ { /* end of list */ }
+ }
};
static int raw_reopen_prepare(BDRVReopenState *reopen_state,
@@ -133,19 +137,20 @@ static int raw_has_zero_init(BlockDriverState *bs)
return bdrv_has_zero_init(bs->file);
}
-static int raw_create(const char *filename, QEMUOptionParameter *options,
+static int raw_create(const char *filename, QemuOpts *opts,
Error **errp)
{
Error *local_err = NULL;
int ret;
- ret = bdrv_create_file(filename, options, NULL, &local_err);
+ ret = bdrv_create_file(filename, NULL, opts, &local_err);
if (error_is_set(&local_err)) {
error_propagate(errp, local_err);
}
return ret;
}
+
static int raw_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{
@@ -172,7 +177,7 @@ static BlockDriver bdrv_raw = {
.bdrv_reopen_prepare = &raw_reopen_prepare,
.bdrv_open = &raw_open,
.bdrv_close = &raw_close,
- .bdrv_create = &raw_create,
+ .bdrv_create2 = &raw_create,
.bdrv_co_readv = &raw_co_readv,
.bdrv_co_writev = &raw_co_writev,
.bdrv_co_write_zeroes = &raw_co_write_zeroes,
@@ -188,7 +193,7 @@ static BlockDriver bdrv_raw = {
.bdrv_lock_medium = &raw_lock_medium,
.bdrv_ioctl = &raw_ioctl,
.bdrv_aio_ioctl = &raw_aio_ioctl,
- .create_options = &raw_create_options[0],
+ .create_opts = &raw_create_opts,
.bdrv_has_zero_init = &raw_has_zero_init
};
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 22/25] vhdx.c: replace QEMUOptionParameter with QemuOpts
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (20 preceding siblings ...)
2014-01-20 14:20 ` [Qemu-devel] [v19 21/25] raw_bsd.c: " Chunyan Liu
@ 2014-01-20 14:20 ` Chunyan Liu
2014-01-22 14:26 ` Kevin Wolf
2014-01-20 14:20 ` [Qemu-devel] [v19 23/25] vvfat.c: " Chunyan Liu
` (3 subsequent siblings)
25 siblings, 1 reply; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:20 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
vhdx.c: replace QEMUOptionParameter with QemuOpts
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
block/vhdx.c | 93 +++++++++++++++++++++++++++------------------------------
block/vhdx.h | 1 +
2 files changed, 45 insertions(+), 49 deletions(-)
diff --git a/block/vhdx.c b/block/vhdx.c
index c78675e..8021e8e 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -1711,7 +1711,7 @@ exit:
* .---- ~ ----------- ~ ------------ ~ ---------------- ~ -----------.
* 1MB
*/
-static int vhdx_create(const char *filename, QEMUOptionParameter *options,
+static int vhdx_create(const char *filename, QemuOpts *opts,
Error **errp)
{
int ret = 0;
@@ -1729,20 +1729,11 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options,
VHDXImageType image_type;
Error *local_err = NULL;
- while (options && options->name) {
- if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
- image_size = options->value.n;
- } else if (!strcmp(options->name, VHDX_BLOCK_OPT_LOG_SIZE)) {
- log_size = options->value.n;
- } else if (!strcmp(options->name, VHDX_BLOCK_OPT_BLOCK_SIZE)) {
- block_size = options->value.n;
- } else if (!strcmp(options->name, BLOCK_OPT_SUBFMT)) {
- type = options->value.s;
- } else if (!strcmp(options->name, VHDX_BLOCK_OPT_ZERO)) {
- use_zero_blocks = options->value.n != 0;
- }
- options++;
- }
+ image_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+ log_size = qemu_opt_get_size_del(opts, VHDX_BLOCK_OPT_LOG_SIZE, 0);
+ block_size = qemu_opt_get_size_del(opts, VHDX_BLOCK_OPT_BLOCK_SIZE, 0);
+ type = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT);
+ use_zero_blocks = qemu_opt_get_bool_del(opts, VHDX_BLOCK_OPT_ZERO, 0);
if (image_size > VHDX_MAX_IMAGE_SIZE) {
error_setg_errno(errp, EINVAL, "Image size too large; max of 64TB");
@@ -1791,7 +1782,7 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options,
block_size = block_size > VHDX_BLOCK_SIZE_MAX ? VHDX_BLOCK_SIZE_MAX :
block_size;
- ret = bdrv_create_file(filename, options, NULL, &local_err);
+ ret = bdrv_create_file(filename, NULL, opts, &local_err);
if (ret < 0) {
error_propagate(errp, local_err);
goto exit;
@@ -1871,37 +1862,41 @@ static int vhdx_check(BlockDriverState *bs, BdrvCheckResult *result,
return 0;
}
-static QEMUOptionParameter vhdx_create_options[] = {
- {
- .name = BLOCK_OPT_SIZE,
- .type = OPT_SIZE,
- .help = "Virtual disk size; max of 64TB."
- },
- {
- .name = VHDX_BLOCK_OPT_LOG_SIZE,
- .type = OPT_SIZE,
- .value.n = 1 * MiB,
- .help = "Log size; min 1MB."
- },
- {
- .name = VHDX_BLOCK_OPT_BLOCK_SIZE,
- .type = OPT_SIZE,
- .value.n = 0,
- .help = "Block Size; min 1MB, max 256MB. " \
- "0 means auto-calculate based on image size."
- },
- {
- .name = BLOCK_OPT_SUBFMT,
- .type = OPT_STRING,
- .help = "VHDX format type, can be either 'dynamic' or 'fixed'. "\
- "Default is 'dynamic'."
- },
- {
- .name = VHDX_BLOCK_OPT_ZERO,
- .type = OPT_FLAG,
- .help = "Force use of payload blocks of type 'ZERO'. Non-standard."
- },
- { NULL }
+static QemuOptsList vhdx_create_opts = {
+ .name = "vhdx-create-opts",
+ .head = QTAILQ_HEAD_INITIALIZER(vhdx_create_opts.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size; max of 64TB."
+ },
+ {
+ .name = VHDX_BLOCK_OPT_LOG_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .def_value_str = stringify(DEFAULT_LOG_SIZE),
+ .help = "Log size; min 1MB."
+ },
+ {
+ .name = VHDX_BLOCK_OPT_BLOCK_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .def_value_str = stringify(0),
+ .help = "Block Size; min 1MB, max 256MB. " \
+ "0 means auto-calculate based on image size."
+ },
+ {
+ .name = BLOCK_OPT_SUBFMT,
+ .type = QEMU_OPT_STRING,
+ .help = "VHDX format type, can be either 'dynamic' or 'fixed'. "\
+ "Default is 'dynamic'."
+ },
+ {
+ .name = VHDX_BLOCK_OPT_ZERO,
+ .type = QEMU_OPT_BOOL,
+ .help = "Force use of payload blocks of type 'ZERO'. Non-standard."
+ },
+ { NULL }
+ }
};
static BlockDriver bdrv_vhdx = {
@@ -1913,11 +1908,11 @@ static BlockDriver bdrv_vhdx = {
.bdrv_reopen_prepare = vhdx_reopen_prepare,
.bdrv_co_readv = vhdx_co_readv,
.bdrv_co_writev = vhdx_co_writev,
- .bdrv_create = vhdx_create,
+ .bdrv_create2 = vhdx_create,
.bdrv_get_info = vhdx_get_info,
.bdrv_check = vhdx_check,
- .create_options = vhdx_create_options,
+ .create_opts = &vhdx_create_opts,
};
static void bdrv_vhdx_init(void)
diff --git a/block/vhdx.h b/block/vhdx.h
index 2acd7c2..a5a36fc 100644
--- a/block/vhdx.h
+++ b/block/vhdx.h
@@ -23,6 +23,7 @@
#define GiB (MiB * 1024)
#define TiB ((uint64_t) GiB * 1024)
+#define DEFAULT_LOG_SIZE 1048576 /* 1MiB */
/* Structures and fields present in the VHDX file */
/* The header section has the following blocks,
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* Re: [Qemu-devel] [v19 22/25] vhdx.c: replace QEMUOptionParameter with QemuOpts
2014-01-20 14:20 ` [Qemu-devel] [v19 22/25] vhdx.c: " Chunyan Liu
@ 2014-01-22 14:26 ` Kevin Wolf
0 siblings, 0 replies; 38+ messages in thread
From: Kevin Wolf @ 2014-01-22 14:26 UTC (permalink / raw)
To: Chunyan Liu; +Cc: Dong Xu Wang, qemu-devel, stefanha
Am 20.01.2014 um 15:20 hat Chunyan Liu geschrieben:
> vhdx.c: replace QEMUOptionParameter with QemuOpts
>
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
> block/vhdx.c | 93 +++++++++++++++++++++++++++------------------------------
> block/vhdx.h | 1 +
> 2 files changed, 45 insertions(+), 49 deletions(-)
>
> diff --git a/block/vhdx.c b/block/vhdx.c
> index c78675e..8021e8e 100644
> --- a/block/vhdx.c
> +++ b/block/vhdx.c
> @@ -1711,7 +1711,7 @@ exit:
> * .---- ~ ----------- ~ ------------ ~ ---------------- ~ -----------.
> * 1MB
> */
> -static int vhdx_create(const char *filename, QEMUOptionParameter *options,
> +static int vhdx_create(const char *filename, QemuOpts *opts,
> Error **errp)
> {
> int ret = 0;
> @@ -1729,20 +1729,11 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options,
> VHDXImageType image_type;
> Error *local_err = NULL;
>
> - while (options && options->name) {
> - if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
> - image_size = options->value.n;
> - } else if (!strcmp(options->name, VHDX_BLOCK_OPT_LOG_SIZE)) {
> - log_size = options->value.n;
> - } else if (!strcmp(options->name, VHDX_BLOCK_OPT_BLOCK_SIZE)) {
> - block_size = options->value.n;
> - } else if (!strcmp(options->name, BLOCK_OPT_SUBFMT)) {
> - type = options->value.s;
> - } else if (!strcmp(options->name, VHDX_BLOCK_OPT_ZERO)) {
> - use_zero_blocks = options->value.n != 0;
> - }
> - options++;
> - }
> + image_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
> + log_size = qemu_opt_get_size_del(opts, VHDX_BLOCK_OPT_LOG_SIZE, 0);
> + block_size = qemu_opt_get_size_del(opts, VHDX_BLOCK_OPT_BLOCK_SIZE, 0);
> + type = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT);
> + use_zero_blocks = qemu_opt_get_bool_del(opts, VHDX_BLOCK_OPT_ZERO, 0);
>
> if (image_size > VHDX_MAX_IMAGE_SIZE) {
> error_setg_errno(errp, EINVAL, "Image size too large; max of 64TB");
> @@ -1791,7 +1782,7 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options,
> block_size = block_size > VHDX_BLOCK_SIZE_MAX ? VHDX_BLOCK_SIZE_MAX :
> block_size;
>
> - ret = bdrv_create_file(filename, options, NULL, &local_err);
> + ret = bdrv_create_file(filename, NULL, opts, &local_err);
> if (ret < 0) {
> error_propagate(errp, local_err);
> goto exit;
> @@ -1871,37 +1862,41 @@ static int vhdx_check(BlockDriverState *bs, BdrvCheckResult *result,
> return 0;
> }
>
> -static QEMUOptionParameter vhdx_create_options[] = {
> - {
> - .name = BLOCK_OPT_SIZE,
> - .type = OPT_SIZE,
> - .help = "Virtual disk size; max of 64TB."
> - },
> - {
> - .name = VHDX_BLOCK_OPT_LOG_SIZE,
> - .type = OPT_SIZE,
> - .value.n = 1 * MiB,
> - .help = "Log size; min 1MB."
> - },
> - {
> - .name = VHDX_BLOCK_OPT_BLOCK_SIZE,
> - .type = OPT_SIZE,
> - .value.n = 0,
> - .help = "Block Size; min 1MB, max 256MB. " \
> - "0 means auto-calculate based on image size."
> - },
> - {
> - .name = BLOCK_OPT_SUBFMT,
> - .type = OPT_STRING,
> - .help = "VHDX format type, can be either 'dynamic' or 'fixed'. "\
> - "Default is 'dynamic'."
> - },
> - {
> - .name = VHDX_BLOCK_OPT_ZERO,
> - .type = OPT_FLAG,
> - .help = "Force use of payload blocks of type 'ZERO'. Non-standard."
> - },
> - { NULL }
> +static QemuOptsList vhdx_create_opts = {
> + .name = "vhdx-create-opts",
> + .head = QTAILQ_HEAD_INITIALIZER(vhdx_create_opts.head),
> + .desc = {
> + {
> + .name = BLOCK_OPT_SIZE,
> + .type = QEMU_OPT_SIZE,
> + .help = "Virtual disk size; max of 64TB."
> + },
> + {
> + .name = VHDX_BLOCK_OPT_LOG_SIZE,
> + .type = QEMU_OPT_SIZE,
> + .def_value_str = stringify(DEFAULT_LOG_SIZE),
> + .help = "Log size; min 1MB."
> + },
> + {
> + .name = VHDX_BLOCK_OPT_BLOCK_SIZE,
> + .type = QEMU_OPT_SIZE,
> + .def_value_str = stringify(0),
> + .help = "Block Size; min 1MB, max 256MB. " \
> + "0 means auto-calculate based on image size."
> + },
> + {
> + .name = BLOCK_OPT_SUBFMT,
> + .type = QEMU_OPT_STRING,
> + .help = "VHDX format type, can be either 'dynamic' or 'fixed'. "\
> + "Default is 'dynamic'."
> + },
> + {
> + .name = VHDX_BLOCK_OPT_ZERO,
> + .type = QEMU_OPT_BOOL,
> + .help = "Force use of payload blocks of type 'ZERO'. Non-standard."
> + },
> + { NULL }
> + }
> };
>
> static BlockDriver bdrv_vhdx = {
> @@ -1913,11 +1908,11 @@ static BlockDriver bdrv_vhdx = {
> .bdrv_reopen_prepare = vhdx_reopen_prepare,
> .bdrv_co_readv = vhdx_co_readv,
> .bdrv_co_writev = vhdx_co_writev,
> - .bdrv_create = vhdx_create,
> + .bdrv_create2 = vhdx_create,
> .bdrv_get_info = vhdx_get_info,
> .bdrv_check = vhdx_check,
>
> - .create_options = vhdx_create_options,
> + .create_opts = &vhdx_create_opts,
> };
>
> static void bdrv_vhdx_init(void)
> diff --git a/block/vhdx.h b/block/vhdx.h
> index 2acd7c2..a5a36fc 100644
> --- a/block/vhdx.h
> +++ b/block/vhdx.h
> @@ -23,6 +23,7 @@
> #define GiB (MiB * 1024)
> #define TiB ((uint64_t) GiB * 1024)
>
> +#define DEFAULT_LOG_SIZE 1048576 /* 1MiB */
Why not write it as (1 * MiB) like before instead of putting a comment
there?
Kevin
^ permalink raw reply [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 23/25] vvfat.c: replace QEMUOptionParameter with QemuOpts
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (21 preceding siblings ...)
2014-01-20 14:20 ` [Qemu-devel] [v19 22/25] vhdx.c: " Chunyan Liu
@ 2014-01-20 14:20 ` Chunyan Liu
2014-01-20 14:20 ` [Qemu-devel] [v19 24/25] cleanup QEMUOptionParameter Chunyan Liu
` (2 subsequent siblings)
25 siblings, 0 replies; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:20 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
vvfat.c: replace QEMUOptionParameter with QemuOpts
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
block/vvfat.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/block/vvfat.c b/block/vvfat.c
index c59cbdb..81733bc 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2910,7 +2910,7 @@ static BlockDriver vvfat_write_target = {
static int enable_write_target(BDRVVVFATState *s)
{
BlockDriver *bdrv_qcow;
- QEMUOptionParameter *options;
+ QemuOpts *opts;
Error *local_err = NULL;
int ret;
int size = sector2cluster(s, s->sector_count);
@@ -2925,11 +2925,11 @@ static int enable_write_target(BDRVVVFATState *s)
}
bdrv_qcow = bdrv_find_format("qcow");
- options = parse_option_parameters("", bdrv_qcow->create_options, NULL);
- set_option_parameter_int(options, BLOCK_OPT_SIZE, s->sector_count * 512);
- set_option_parameter(options, BLOCK_OPT_BACKING_FILE, "fat:");
+ opts = qemu_opts_create(bdrv_qcow->create_opts, NULL, 0, &error_abort);
+ qemu_opt_set_number(opts, BLOCK_OPT_SIZE, s->sector_count * 512);
+ qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, "fat:");
- ret = bdrv_create(bdrv_qcow, s->qcow_filename, options, NULL, &local_err);
+ ret = bdrv_create(bdrv_qcow, s->qcow_filename, NULL, opts, &local_err);
if (ret < 0) {
qerror_report_err(local_err);
error_free(local_err);
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 24/25] cleanup QEMUOptionParameter
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (22 preceding siblings ...)
2014-01-20 14:20 ` [Qemu-devel] [v19 23/25] vvfat.c: " Chunyan Liu
@ 2014-01-20 14:20 ` Chunyan Liu
2014-01-22 14:33 ` Kevin Wolf
2014-01-20 14:20 ` [Qemu-devel] [v19 25/25] change back to original name from bdrv_create2 to bdrv_create Chunyan Liu
2014-01-22 14:35 ` [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Kevin Wolf
25 siblings, 1 reply; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:20 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
Now all places using QEMUOptionParameter could use QemuOpts too, remove
QEMUOptionParameter related code.
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
block.c | 147 ++---------------------
block/cow.c | 2 +-
block/qcow.c | 2 +-
block/qcow2.c | 2 +-
block/qed.c | 2 +-
block/raw_bsd.c | 2 +-
block/vhdx.c | 2 +-
block/vmdk.c | 4 +-
block/vvfat.c | 2 +-
include/block/block.h | 4 +-
include/block/block_int.h | 3 -
include/qemu/option.h | 35 ------
qemu-img.c | 93 ++-------------
util/qemu-option.c | 294 ---------------------------------------------
14 files changed, 30 insertions(+), 564 deletions(-)
diff --git a/block.c b/block.c
index 8c490c6..b33d095 100644
--- a/block.c
+++ b/block.c
@@ -394,7 +394,6 @@ BlockDriver *bdrv_find_whitelisted_format(const char *format_name,
typedef struct CreateCo {
BlockDriver *drv;
char *filename;
- QEMUOptionParameter *options;
QemuOpts *opts;
int ret;
Error *err;
@@ -403,15 +402,13 @@ typedef struct CreateCo {
static void coroutine_fn bdrv_create_co_entry(void *opaque)
{
Error *local_err = NULL;
- int ret;
+ int ret = -1;
CreateCo *cco = opaque;
assert(cco->drv);
if (cco->drv->bdrv_create2)
ret = cco->drv->bdrv_create2(cco->filename, cco->opts, &local_err);
- else
- ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
if (error_is_set(&local_err)) {
error_propagate(&cco->err, local_err);
}
@@ -419,7 +416,7 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
}
int bdrv_create(BlockDriver *drv, const char* filename,
- QEMUOptionParameter *options, QemuOpts *opts, Error **errp)
+ QemuOpts *opts, Error **errp)
{
int ret;
@@ -427,13 +424,12 @@ int bdrv_create(BlockDriver *drv, const char* filename,
CreateCo cco = {
.drv = drv,
.filename = g_strdup(filename),
- .options = options,
.opts = opts,
.ret = NOT_DONE,
.err = NULL,
};
- if (!drv->bdrv_create && !drv->bdrv_create2) {
+ if (!drv->bdrv_create2) {
error_setg(errp, "Driver '%s' does not support image creation", drv->format_name);
ret = -ENOTSUP;
goto out;
@@ -464,7 +460,7 @@ out:
return ret;
}
-int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
+int bdrv_create_file(const char* filename,
QemuOpts *opts, Error **errp)
{
BlockDriver *drv;
@@ -477,7 +473,7 @@ int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
return -ENOENT;
}
- ret = bdrv_create(drv, filename, options, opts, &local_err);
+ ret = bdrv_create(drv, filename, opts, &local_err);
if (error_is_set(&local_err)) {
error_propagate(errp, local_err);
}
@@ -1058,7 +1054,6 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
BlockDriverState *bs1;
int64_t total_size;
BlockDriver *bdrv_qcow2;
- QEMUOptionParameter *create_options = NULL;
QemuOpts *opts = NULL;
QDict *snapshot_options;
@@ -1089,14 +1084,9 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
if (bdrv_qcow2->bdrv_create2) {
opts = qemu_opts_create(bdrv_qcow2->create_opts, NULL, 0, &error_abort);
qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size);
- } else {
- create_options =
- parse_option_parameters("", bdrv_qcow2->create_options, NULL);
- set_option_parameter_int(create_options, BLOCK_OPT_SIZE, total_size);
}
- ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, opts, &local_err);
- free_option_parameters(create_options);
+ ret = bdrv_create(bdrv_qcow2, tmp_filename, opts, &local_err);
qemu_opts_del(opts);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not create temporary overlay "
@@ -4722,7 +4712,6 @@ void bdrv_img_create(const char *filename, const char *fmt,
char *options, uint64_t img_size, int flags,
Error **errp, bool quiet)
{
- QEMUOptionParameter *param = NULL, *create_options = NULL;
QemuOptsList *create_opts = NULL;
QemuOpts *opts = NULL;
BlockDriver *drv, *proto_drv;
@@ -4843,7 +4832,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
puts("");
}
- ret = bdrv_create(drv, filename, NULL, opts, &local_err);
+ ret = bdrv_create(drv, filename, opts, &local_err);
if (ret == -EFBIG) {
/* This is generally a better message than whatever the driver would
* deliver (especially because of the cluster_size_hint), since that
@@ -4859,128 +4848,10 @@ void bdrv_img_create(const char *filename, const char *fmt,
}
} else {
- QEMUOptionParameter *backing_fmt, *backing_file, *size;
-
- create_options = append_option_parameters(create_options,
- drv->create_options);
- create_options = append_option_parameters(create_options,
- proto_drv->create_options);
-
- /* Create parameter list with default values */
- param = parse_option_parameters("", create_options, param);
-
- set_option_parameter_int(param, BLOCK_OPT_SIZE, img_size);
-
- /* Parse -o options */
- if (options) {
- param = parse_option_parameters(options, create_options, param);
- if (param == NULL) {
- error_setg(errp, "Invalid options for file format '%s'.", fmt);
- goto out;
- }
- }
-
- if (base_filename) {
- if (set_option_parameter(param, BLOCK_OPT_BACKING_FILE,
- base_filename)) {
- error_setg(errp, "Backing file not supported for file format '%s'",
- fmt);
- goto out;
- }
- }
-
- if (base_fmt) {
- if (set_option_parameter(param, BLOCK_OPT_BACKING_FMT, base_fmt)) {
- error_setg(errp, "Backing file format not supported for file "
- "format '%s'", fmt);
- goto out;
- }
- }
-
- backing_file = get_option_parameter(param, BLOCK_OPT_BACKING_FILE);
- if (backing_file && backing_file->value.s) {
- if (!strcmp(filename, backing_file->value.s)) {
- error_setg(errp, "Error: Trying to create an image with the "
- "same filename as the backing file");
- goto out;
- }
- }
-
- backing_fmt = get_option_parameter(param, BLOCK_OPT_BACKING_FMT);
- if (backing_fmt && backing_fmt->value.s) {
- backing_drv = bdrv_find_format(backing_fmt->value.s);
- if (!backing_drv) {
- error_setg(errp, "Unknown backing file format '%s'",
- backing_fmt->value.s);
- goto out;
- }
- }
-
- // The size for the image must always be specified, with one exception:
- // If we are using a backing file, we can obtain the size from there
- size = get_option_parameter(param, BLOCK_OPT_SIZE);
- if (size && size->value.n == -1) {
- if (backing_file && backing_file->value.s) {
- BlockDriverState *bs;
- uint64_t size;
- char buf[32];
- int back_flags;
-
- /* backing files always opened read-only */
- back_flags =
- flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
-
- bs = bdrv_new("");
-
- ret = bdrv_open(bs, backing_file->value.s, NULL, back_flags,
- backing_drv, &local_err);
- if (ret < 0) {
- error_setg_errno(errp, -ret, "Could not open '%s': %s",
- backing_file->value.s,
- error_get_pretty(local_err));
- error_free(local_err);
- local_err = NULL;
- bdrv_unref(bs);
- goto out;
- }
- bdrv_get_geometry(bs, &size);
- size *= 512;
-
- snprintf(buf, sizeof(buf), "%" PRId64, size);
- set_option_parameter(param, BLOCK_OPT_SIZE, buf);
-
- bdrv_unref(bs);
- } else {
- error_setg(errp, "Image creation needs a size parameter");
- goto out;
- }
- }
-
- if (!quiet) {
- printf("Formatting '%s', fmt=%s ", filename, fmt);
- print_option_parameters(param);
- puts("");
- }
-
- ret = bdrv_create(drv, filename, param, NULL, &local_err);
- if (ret == -EFBIG) {
- /* This is generally a better message than whatever the driver would
- * deliver (especially because of the cluster_size_hint), since that
- * is most probably not much different from "image too large". */
- const char *cluster_size_hint = "";
- if (get_option_parameter(create_options, BLOCK_OPT_CLUSTER_SIZE)) {
- cluster_size_hint = " (try using a larger cluster size)";
- }
- error_setg(errp, "The image size is too large for file format '%s'"
- "%s", fmt, cluster_size_hint);
- error_free(local_err);
- local_err = NULL;
- }
- }
+ error_setg(errp, "Unsupported");
+ }
out:
- free_option_parameters(create_options);
- free_option_parameters(param);
qemu_opts_del(opts);
qemu_opts_free(create_opts);
if (error_is_set(&local_err)) {
diff --git a/block/cow.c b/block/cow.c
index 6688a87..61f2bab 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -338,7 +338,7 @@ static int cow_create(const char *filename, QemuOpts *opts,
image_sectors = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512;
image_filename = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
- ret = bdrv_create_file(filename, NULL, opts, &local_err);
+ ret = bdrv_create_file(filename, opts, &local_err);
if (ret < 0) {
qerror_report_err(local_err);
error_free(local_err);
diff --git a/block/qcow.c b/block/qcow.c
index ac0ddff..4f7907b 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -679,7 +679,7 @@ static int qcow_create(const char *filename, QemuOpts *opts,
flags |= BLOCK_FLAG_ENCRYPT;
}
- ret = bdrv_create_file(filename, NULL, opts, &local_err);
+ ret = bdrv_create_file(filename, opts, &local_err);
if (ret < 0) {
qerror_report_err(local_err);
error_free(local_err);
diff --git a/block/qcow2.c b/block/qcow2.c
index 580bc93..ed14195 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1477,7 +1477,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
Error *local_err = NULL;
int ret;
- ret = bdrv_create_file(filename, NULL, opts, &local_err);
+ ret = bdrv_create_file(filename, opts, &local_err);
if (ret < 0) {
error_propagate(errp, local_err);
return ret;
diff --git a/block/qed.c b/block/qed.c
index 9f819a8..e858dc5 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -556,7 +556,7 @@ static int qed_create(const char *filename, uint32_t cluster_size,
int ret = 0;
BlockDriverState *bs = NULL;
- ret = bdrv_create_file(filename, NULL, NULL, &local_err);
+ ret = bdrv_create_file(filename, NULL, &local_err);
if (ret < 0) {
qerror_report_err(local_err);
error_free(local_err);
diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index 4ae12dd..d9dd324 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -143,7 +143,7 @@ static int raw_create(const char *filename, QemuOpts *opts,
Error *local_err = NULL;
int ret;
- ret = bdrv_create_file(filename, NULL, opts, &local_err);
+ ret = bdrv_create_file(filename, opts, &local_err);
if (error_is_set(&local_err)) {
error_propagate(errp, local_err);
}
diff --git a/block/vhdx.c b/block/vhdx.c
index 8021e8e..057c409 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -1782,7 +1782,7 @@ static int vhdx_create(const char *filename, QemuOpts *opts,
block_size = block_size > VHDX_BLOCK_SIZE_MAX ? VHDX_BLOCK_SIZE_MAX :
block_size;
- ret = bdrv_create_file(filename, NULL, opts, &local_err);
+ ret = bdrv_create_file(filename, opts, &local_err);
if (ret < 0) {
error_propagate(errp, local_err);
goto exit;
diff --git a/block/vmdk.c b/block/vmdk.c
index c3d4328..9403d5d 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1463,7 +1463,7 @@ static int vmdk_create_extent(const char *filename, int64_t filesize,
uint32_t *gd_buf = NULL;
int gd_buf_size;
- ret = bdrv_create_file(filename, NULL, NULL, &local_err);
+ ret = bdrv_create_file(filename, NULL, &local_err);
if (ret < 0) {
error_propagate(errp, local_err);
goto exit;
@@ -1796,7 +1796,7 @@ static int vmdk_create(const char *filename, QemuOpts *opts,
if (!split && !flat) {
desc_offset = 0x200;
} else {
- ret = bdrv_create_file(filename, NULL, opts, &local_err);
+ ret = bdrv_create_file(filename, opts, &local_err);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not create image file");
goto exit;
diff --git a/block/vvfat.c b/block/vvfat.c
index 81733bc..b43b4b1 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2929,7 +2929,7 @@ static int enable_write_target(BDRVVVFATState *s)
qemu_opt_set_number(opts, BLOCK_OPT_SIZE, s->sector_count * 512);
qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, "fat:");
- ret = bdrv_create(bdrv_qcow, s->qcow_filename, NULL, opts, &local_err);
+ ret = bdrv_create(bdrv_qcow, s->qcow_filename, opts, &local_err);
if (ret < 0) {
qerror_report_err(local_err);
error_free(local_err);
diff --git a/include/block/block.h b/include/block/block.h
index e23a7da..feb44d2 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -174,8 +174,8 @@ BlockDriver *bdrv_find_format(const char *format_name);
BlockDriver *bdrv_find_whitelisted_format(const char *format_name,
bool readonly);
int bdrv_create(BlockDriver *drv, const char* filename,
- QEMUOptionParameter *options, QemuOpts *opts, Error **errp);
-int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
+ QemuOpts *opts, Error **errp);
+int bdrv_create_file(const char* filename,
QemuOpts *opts, Error **errp);
BlockDriverState *bdrv_new(const char *device_name);
void bdrv_make_anon(BlockDriverState *bs);
diff --git a/include/block/block_int.h b/include/block/block_int.h
index f5bdd08..b9ddbaa 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -103,8 +103,6 @@ struct BlockDriver {
const uint8_t *buf, int nb_sectors);
void (*bdrv_close)(BlockDriverState *bs);
void (*bdrv_rebind)(BlockDriverState *bs);
- int (*bdrv_create)(const char *filename, QEMUOptionParameter *options,
- Error **errp);
int (*bdrv_create2)(const char *filename, QemuOpts *opts,
Error **errp);
int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
@@ -205,7 +203,6 @@ struct BlockDriver {
BlockDriverCompletionFunc *cb, void *opaque);
/* List of options for creating images, terminated by name == NULL */
- QEMUOptionParameter *create_options;
QemuOptsList *create_opts;
/*
diff --git a/include/qemu/option.h b/include/qemu/option.h
index 8d77e2e..6051452 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -38,18 +38,6 @@ enum QEMUOptionParType {
OPT_STRING,
};
-typedef struct QEMUOptionParameter {
- const char *name;
- enum QEMUOptionParType type;
- union {
- uint64_t n;
- char* s;
- } value;
- const char *help;
- bool assigned;
-} QEMUOptionParameter;
-
-
const char *get_opt_name(char *buf, int buf_size, const char *p, char delim);
const char *get_opt_value(char *buf, int buf_size, const char *p);
int get_next_param_value(char *buf, int buf_size,
@@ -57,29 +45,6 @@ int get_next_param_value(char *buf, int buf_size,
int get_param_value(char *buf, int buf_size,
const char *tag, const char *str);
-
-/*
- * The following functions take a parameter list as input. This is a pointer to
- * the first element of a QEMUOptionParameter array which is terminated by an
- * entry with entry->name == NULL.
- */
-
-QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list,
- const char *name);
-int set_option_parameter(QEMUOptionParameter *list, const char *name,
- const char *value);
-int set_option_parameter_int(QEMUOptionParameter *list, const char *name,
- uint64_t value);
-QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest,
- QEMUOptionParameter *list);
-QEMUOptionParameter *parse_option_parameters(const char *param,
- QEMUOptionParameter *list, QEMUOptionParameter *dest);
-void parse_option_size(const char *name, const char *value,
- uint64_t *ret, Error **errp);
-void free_option_parameters(QEMUOptionParameter *list);
-void print_option_parameters(QEMUOptionParameter *list);
-void print_option_help(QEMUOptionParameter *list);
-
/* ------------------------------------------------------------------ */
typedef struct QemuOpt QemuOpt;
diff --git a/qemu-img.c b/qemu-img.c
index 863bd03..920e4bd 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -241,7 +241,6 @@ static int read_password(char *buf, int buf_size)
static int print_block_option_help(const char *filename, const char *fmt)
{
BlockDriver *drv, *proto_drv;
- QEMUOptionParameter *create_options = NULL;
QemuOptsList *create_opts = NULL;
/* Find driver and parse its options */
@@ -257,18 +256,10 @@ static int print_block_option_help(const char *filename, const char *fmt)
return 1;
}
- if (drv->bdrv_create2) {
- create_opts = qemu_opts_append(create_opts, drv->create_opts);
- create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
- qemu_opts_print_help(create_opts);
- } else {
- create_options = append_option_parameters(create_options,
- drv->create_options);
- create_options = append_option_parameters(create_options,
- proto_drv->create_options);
- print_option_help(create_options);
- }
- free_option_parameters(create_options);
+ create_opts = qemu_opts_append(create_opts, drv->create_opts);
+ create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
+ qemu_opts_print_help(create_opts);
+
qemu_opts_free(create_opts);
return 0;
}
@@ -324,22 +315,19 @@ fail:
return NULL;
}
-static int add_old_style_options(const char *fmt, QEMUOptionParameter *list,
+static int add_old_style_options(const char *fmt,
QemuOpts *opts,
const char *base_filename,
const char *base_fmt)
{
if (base_filename) {
- if ((opts && qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename)) ||
- (list && set_option_parameter(list, BLOCK_OPT_BACKING_FILE, base_filename))) {
- error_report("Backing file not supported for file format '%s'",
+ if (opts && qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename)) { error_report("Backing file not supported for file format '%s'",
fmt);
return -1;
}
}
if (base_fmt) {
- if ((opts && qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt)) ||
- (list && set_option_parameter(list, BLOCK_OPT_BACKING_FMT, base_fmt))) {
+ if (opts && qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt)) {
error_report("Backing file format not supported for file "
"format '%s'", fmt);
return -1;
@@ -1152,7 +1140,6 @@ static int img_convert(int argc, char **argv)
size_t bufsectors = IO_BUF_SIZE / BDRV_SECTOR_SIZE;
const uint8_t *buf1;
BlockDriverInfo bdi;
- QEMUOptionParameter *param = NULL, *create_options = NULL;
QemuOpts *opts = NULL;
QemuOptsList *create_opts = NULL;
char *options = NULL;
@@ -1337,7 +1324,7 @@ static int img_convert(int argc, char **argv)
}
qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_sectors * 512);
- ret = add_old_style_options(out_fmt, NULL, opts, out_baseimg, NULL);
+ ret = add_old_style_options(out_fmt, opts, out_baseimg, NULL);
if (ret < 0) {
goto out;
}
@@ -1379,70 +1366,12 @@ static int img_convert(int argc, char **argv)
}
} else {
- QEMUOptionParameter *out_baseimg_param;
-
- create_options = append_option_parameters(create_options,
- drv->create_options);
- create_options = append_option_parameters(create_options,
- proto_drv->create_options);
-
- if (options) {
- param = parse_option_parameters(options, create_options, param);
- if (param == NULL) {
- error_report("Invalid options for file format '%s'.", out_fmt);
- ret = -1;
- goto out;
- }
- } else {
- param = parse_option_parameters("", create_options, param);
- }
-
- set_option_parameter_int(param, BLOCK_OPT_SIZE, total_sectors * 512);
- ret = add_old_style_options(out_fmt, param, NULL, out_baseimg, NULL);
- if (ret < 0) {
- goto out;
- }
-
- /* Get backing file name if -o backing_file was used */
- out_baseimg_param = get_option_parameter(param, BLOCK_OPT_BACKING_FILE);
- if (out_baseimg_param) {
- out_baseimg = out_baseimg_param->value.s;
- }
-
- /* Check if compression is supported */
- if (compress) {
- QEMUOptionParameter *encryption =
- get_option_parameter(param, BLOCK_OPT_ENCRYPT);
- QEMUOptionParameter *preallocation =
- get_option_parameter(param, BLOCK_OPT_PREALLOC);
-
- if (!drv->bdrv_write_compressed) {
- error_report("Compression not supported for this file format");
- ret = -1;
- goto out;
- }
-
- if (encryption && encryption->value.n) {
- error_report("Compression and encryption not supported at "
- "the same time");
- ret = -1;
- goto out;
- }
-
- if (preallocation && preallocation->value.s
- && strcmp(preallocation->value.s, "off"))
- {
- error_report("Compression and preallocation not supported at "
- "the same time");
- ret = -1;
- goto out;
- }
- }
+ error_report("Not supported");
}
if (!skip_create) {
/* Create the new image */
- ret = bdrv_create(drv, out_filename, param, opts, &local_err);
+ ret = bdrv_create(drv, out_filename, opts, &local_err);
if (ret < 0) {
error_report("%s: error while converting %s: %s",
out_filename, out_fmt, error_get_pretty(local_err));
@@ -1706,8 +1635,6 @@ out:
qemu_progress_print(100, 0);
}
qemu_progress_end();
- free_option_parameters(create_options);
- free_option_parameters(param);
qemu_opts_free(create_opts);
qemu_opts_del(opts);
qemu_vfree(buf);
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 6bd5154..11a8a6b 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -126,22 +126,6 @@ int get_param_value(char *buf, int buf_size,
return get_next_param_value(buf, buf_size, tag, &str);
}
-/*
- * Searches an option list for an option with the given name
- */
-QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list,
- const char *name)
-{
- while (list && list->name) {
- if (!strcmp(list->name, name)) {
- return list;
- }
- list++;
- }
-
- return NULL;
-}
-
static void parse_option_bool(const char *name, const char *value, bool *ret,
Error **errp)
{
@@ -215,170 +199,6 @@ void parse_option_size(const char *name, const char *value,
}
}
-/*
- * Sets the value of a parameter in a given option list. The parsing of the
- * value depends on the type of option:
- *
- * OPT_FLAG (uses value.n):
- * If no value is given, the flag is set to 1.
- * Otherwise the value must be "on" (set to 1) or "off" (set to 0)
- *
- * OPT_STRING (uses value.s):
- * value is strdup()ed and assigned as option value
- *
- * OPT_SIZE (uses value.n):
- * The value is converted to an integer. Suffixes for kilobytes etc. are
- * allowed (powers of 1024).
- *
- * Returns 0 on succes, -1 in error cases
- */
-int set_option_parameter(QEMUOptionParameter *list, const char *name,
- const char *value)
-{
- bool flag;
- Error *local_err = NULL;
-
- // Find a matching parameter
- list = get_option_parameter(list, name);
- if (list == NULL) {
- fprintf(stderr, "Unknown option '%s'\n", name);
- return -1;
- }
-
- // Process parameter
- switch (list->type) {
- case OPT_FLAG:
- parse_option_bool(name, value, &flag, &local_err);
- if (!error_is_set(&local_err)) {
- list->value.n = flag;
- }
- break;
-
- case OPT_STRING:
- if (value != NULL) {
- list->value.s = g_strdup(value);
- } else {
- fprintf(stderr, "Option '%s' needs a parameter\n", name);
- return -1;
- }
- break;
-
- case OPT_SIZE:
- parse_option_size(name, value, &list->value.n, &local_err);
- break;
-
- default:
- fprintf(stderr, "Bug: Option '%s' has an unknown type\n", name);
- return -1;
- }
-
- if (error_is_set(&local_err)) {
- qerror_report_err(local_err);
- error_free(local_err);
- return -1;
- }
-
- list->assigned = true;
-
- return 0;
-}
-
-/*
- * Sets the given parameter to an integer instead of a string.
- * This function cannot be used to set string options.
- *
- * Returns 0 on success, -1 in error cases
- */
-int set_option_parameter_int(QEMUOptionParameter *list, const char *name,
- uint64_t value)
-{
- // Find a matching parameter
- list = get_option_parameter(list, name);
- if (list == NULL) {
- fprintf(stderr, "Unknown option '%s'\n", name);
- return -1;
- }
-
- // Process parameter
- switch (list->type) {
- case OPT_FLAG:
- case OPT_NUMBER:
- case OPT_SIZE:
- list->value.n = value;
- break;
-
- default:
- return -1;
- }
-
- list->assigned = true;
-
- return 0;
-}
-
-/*
- * Frees a option list. If it contains strings, the strings are freed as well.
- */
-void free_option_parameters(QEMUOptionParameter *list)
-{
- QEMUOptionParameter *cur = list;
-
- while (cur && cur->name) {
- if (cur->type == OPT_STRING) {
- g_free(cur->value.s);
- }
- cur++;
- }
-
- g_free(list);
-}
-
-/*
- * Count valid options in list
- */
-static size_t count_option_parameters(QEMUOptionParameter *list)
-{
- size_t num_options = 0;
-
- while (list && list->name) {
- num_options++;
- list++;
- }
-
- return num_options;
-}
-
-/*
- * Append an option list (list) to an option list (dest).
- *
- * If dest is NULL, a new copy of list is created.
- *
- * Returns a pointer to the first element of dest (or the newly allocated copy)
- */
-QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest,
- QEMUOptionParameter *list)
-{
- size_t num_options, num_dest_options;
-
- num_options = count_option_parameters(dest);
- num_dest_options = num_options;
-
- num_options += count_option_parameters(list);
-
- dest = g_realloc(dest, (num_options + 1) * sizeof(QEMUOptionParameter));
- dest[num_dest_options].name = NULL;
-
- while (list && list->name) {
- if (get_option_parameter(dest, list->name) == NULL) {
- dest[num_dest_options++] = *list;
- dest[num_dest_options].name = NULL;
- }
- list++;
- }
-
- return dest;
-}
-
static size_t count_opts_list(QemuOptsList *list)
{
QemuOptDesc *desc = NULL;
@@ -445,120 +265,6 @@ QemuOptsList *qemu_opts_append(QemuOptsList *dst,
return tmp;
}
-/*
- * Parses a parameter string (param) into an option list (dest).
- *
- * list is the template option list. If dest is NULL, a new copy of list is
- * created. If list is NULL, this function fails.
- *
- * A parameter string consists of one or more parameters, separated by commas.
- * Each parameter consists of its name and possibly of a value. In the latter
- * case, the value is delimited by an = character. To specify a value which
- * contains commas, double each comma so it won't be recognized as the end of
- * the parameter.
- *
- * For more details of the parsing see above.
- *
- * Returns a pointer to the first element of dest (or the newly allocated copy)
- * or NULL in error cases
- */
-QEMUOptionParameter *parse_option_parameters(const char *param,
- QEMUOptionParameter *list, QEMUOptionParameter *dest)
-{
- QEMUOptionParameter *allocated = NULL;
- char name[256];
- char value[256];
- char *param_delim, *value_delim;
- char next_delim;
- int i;
-
- if (list == NULL) {
- return NULL;
- }
-
- if (dest == NULL) {
- dest = allocated = append_option_parameters(NULL, list);
- }
-
- for (i = 0; dest[i].name; i++) {
- dest[i].assigned = false;
- }
-
- while (*param) {
-
- // Find parameter name and value in the string
- param_delim = strchr(param, ',');
- value_delim = strchr(param, '=');
-
- if (value_delim && (value_delim < param_delim || !param_delim)) {
- next_delim = '=';
- } else {
- next_delim = ',';
- value_delim = NULL;
- }
-
- param = get_opt_name(name, sizeof(name), param, next_delim);
- if (value_delim) {
- param = get_opt_value(value, sizeof(value), param + 1);
- }
- if (*param != '\0') {
- param++;
- }
-
- // Set the parameter
- if (set_option_parameter(dest, name, value_delim ? value : NULL)) {
- goto fail;
- }
- }
-
- return dest;
-
-fail:
- // Only free the list if it was newly allocated
- free_option_parameters(allocated);
- return NULL;
-}
-
-/*
- * Prints all options of a list that have a value to stdout
- */
-void print_option_parameters(QEMUOptionParameter *list)
-{
- while (list && list->name) {
- switch (list->type) {
- case OPT_STRING:
- if (list->value.s != NULL) {
- printf("%s='%s' ", list->name, list->value.s);
- }
- break;
- case OPT_FLAG:
- printf("%s=%s ", list->name, list->value.n ? "on" : "off");
- break;
- case OPT_SIZE:
- case OPT_NUMBER:
- printf("%s=%" PRId64 " ", list->name, list->value.n);
- break;
- default:
- printf("%s=(unknown type) ", list->name);
- break;
- }
- list++;
- }
-}
-
-/*
- * Prints an overview of all available options
- */
-void print_option_help(QEMUOptionParameter *list)
-{
- printf("Supported options:\n");
- while (list && list->name) {
- printf("%-16s %s\n", list->name,
- list->help ? list->help : "No description available");
- list++;
- }
-}
-
/* ------------------------------------------------------------------ */
static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* Re: [Qemu-devel] [v19 24/25] cleanup QEMUOptionParameter
2014-01-20 14:20 ` [Qemu-devel] [v19 24/25] cleanup QEMUOptionParameter Chunyan Liu
@ 2014-01-22 14:33 ` Kevin Wolf
0 siblings, 0 replies; 38+ messages in thread
From: Kevin Wolf @ 2014-01-22 14:33 UTC (permalink / raw)
To: Chunyan Liu; +Cc: Dong Xu Wang, qemu-devel, stefanha
Am 20.01.2014 um 15:20 hat Chunyan Liu geschrieben:
> Now all places using QEMUOptionParameter could use QemuOpts too, remove
> QEMUOptionParameter related code.
>
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
> block.c | 147 ++---------------------
> block/cow.c | 2 +-
> block/qcow.c | 2 +-
> block/qcow2.c | 2 +-
> block/qed.c | 2 +-
> block/raw_bsd.c | 2 +-
> block/vhdx.c | 2 +-
> block/vmdk.c | 4 +-
> block/vvfat.c | 2 +-
> include/block/block.h | 4 +-
> include/block/block_int.h | 3 -
> include/qemu/option.h | 35 ------
> qemu-img.c | 93 ++-------------
> util/qemu-option.c | 294 ---------------------------------------------
> 14 files changed, 30 insertions(+), 564 deletions(-)
>
> diff --git a/block.c b/block.c
> index 8c490c6..b33d095 100644
> --- a/block.c
> +++ b/block.c
> @@ -394,7 +394,6 @@ BlockDriver *bdrv_find_whitelisted_format(const char *format_name,
> typedef struct CreateCo {
> BlockDriver *drv;
> char *filename;
> - QEMUOptionParameter *options;
> QemuOpts *opts;
> int ret;
> Error *err;
> @@ -403,15 +402,13 @@ typedef struct CreateCo {
> static void coroutine_fn bdrv_create_co_entry(void *opaque)
> {
> Error *local_err = NULL;
> - int ret;
> + int ret = -1;
>
> CreateCo *cco = opaque;
> assert(cco->drv);
>
> if (cco->drv->bdrv_create2)
> ret = cco->drv->bdrv_create2(cco->filename, cco->opts, &local_err);
> - else
> - ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
The if condition isn't needed any more, it is always true.
> if (error_is_set(&local_err)) {
> error_propagate(&cco->err, local_err);
> }
> @@ -324,22 +315,19 @@ fail:
> return NULL;
> }
>
> -static int add_old_style_options(const char *fmt, QEMUOptionParameter *list,
> +static int add_old_style_options(const char *fmt,
> QemuOpts *opts,
> const char *base_filename,
> const char *base_fmt)
> {
> if (base_filename) {
> - if ((opts && qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename)) ||
> - (list && set_option_parameter(list, BLOCK_OPT_BACKING_FILE, base_filename))) {
> - error_report("Backing file not supported for file format '%s'",
> + if (opts && qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename)) { error_report("Backing file not supported for file format '%s'",
I think you lost a line break here. :-)
> fmt);
> return -1;
> }
> }
> if (base_fmt) {
> - if ((opts && qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt)) ||
> - (list && set_option_parameter(list, BLOCK_OPT_BACKING_FMT, base_fmt))) {
> + if (opts && qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt)) {
> error_report("Backing file format not supported for file "
> "format '%s'", fmt);
> return -1;
> @@ -1152,7 +1140,6 @@ static int img_convert(int argc, char **argv)
> size_t bufsectors = IO_BUF_SIZE / BDRV_SECTOR_SIZE;
> const uint8_t *buf1;
> BlockDriverInfo bdi;
> - QEMUOptionParameter *param = NULL, *create_options = NULL;
> QemuOpts *opts = NULL;
> QemuOptsList *create_opts = NULL;
> char *options = NULL;
> @@ -1337,7 +1324,7 @@ static int img_convert(int argc, char **argv)
> }
>
> qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_sectors * 512);
> - ret = add_old_style_options(out_fmt, NULL, opts, out_baseimg, NULL);
> + ret = add_old_style_options(out_fmt, opts, out_baseimg, NULL);
> if (ret < 0) {
> goto out;
> }
> @@ -1379,70 +1366,12 @@ static int img_convert(int argc, char **argv)
> }
>
> } else {
> - QEMUOptionParameter *out_baseimg_param;
> -
> - create_options = append_option_parameters(create_options,
> - drv->create_options);
> - create_options = append_option_parameters(create_options,
> - proto_drv->create_options);
> -
> - if (options) {
> - param = parse_option_parameters(options, create_options, param);
> - if (param == NULL) {
> - error_report("Invalid options for file format '%s'.", out_fmt);
> - ret = -1;
> - goto out;
> - }
> - } else {
> - param = parse_option_parameters("", create_options, param);
> - }
> -
> - set_option_parameter_int(param, BLOCK_OPT_SIZE, total_sectors * 512);
> - ret = add_old_style_options(out_fmt, param, NULL, out_baseimg, NULL);
> - if (ret < 0) {
> - goto out;
> - }
> -
> - /* Get backing file name if -o backing_file was used */
> - out_baseimg_param = get_option_parameter(param, BLOCK_OPT_BACKING_FILE);
> - if (out_baseimg_param) {
> - out_baseimg = out_baseimg_param->value.s;
> - }
> -
> - /* Check if compression is supported */
> - if (compress) {
> - QEMUOptionParameter *encryption =
> - get_option_parameter(param, BLOCK_OPT_ENCRYPT);
> - QEMUOptionParameter *preallocation =
> - get_option_parameter(param, BLOCK_OPT_PREALLOC);
> -
> - if (!drv->bdrv_write_compressed) {
> - error_report("Compression not supported for this file format");
> - ret = -1;
> - goto out;
> - }
> -
> - if (encryption && encryption->value.n) {
> - error_report("Compression and encryption not supported at "
> - "the same time");
> - ret = -1;
> - goto out;
> - }
> -
> - if (preallocation && preallocation->value.s
> - && strcmp(preallocation->value.s, "off"))
> - {
> - error_report("Compression and preallocation not supported at "
> - "the same time");
> - ret = -1;
> - goto out;
> - }
> - }
> + error_report("Not supported");
> }
Do you really need the if condition any more? I think bdrv_create()
still returns an error like it used to, and we didn't have the check
before this series.
Kevin
^ permalink raw reply [flat|nested] 38+ messages in thread
* [Qemu-devel] [v19 25/25] change back to original name from bdrv_create2 to bdrv_create
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (23 preceding siblings ...)
2014-01-20 14:20 ` [Qemu-devel] [v19 24/25] cleanup QEMUOptionParameter Chunyan Liu
@ 2014-01-20 14:20 ` Chunyan Liu
2014-01-22 14:35 ` [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Kevin Wolf
25 siblings, 0 replies; 38+ messages in thread
From: Chunyan Liu @ 2014-01-20 14:20 UTC (permalink / raw)
To: qemu-devel, stefanha, kwolf; +Cc: Dong Xu Wang, Chunyan Liu
Rename the new driver callback bdrv_create2 to the old name bdrv_create.
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
block.c | 10 +++++-----
block/cow.c | 2 +-
block/gluster.c | 8 ++++----
block/iscsi.c | 2 +-
block/qcow.c | 2 +-
block/qcow2.c | 2 +-
block/qed.c | 2 +-
block/raw-posix.c | 10 +++++-----
block/raw-win32.c | 2 +-
block/raw_bsd.c | 2 +-
block/rbd.c | 2 +-
block/sheepdog.c | 6 +++---
block/ssh.c | 2 +-
block/vdi.c | 2 +-
block/vhdx.c | 2 +-
block/vmdk.c | 2 +-
block/vpc.c | 2 +-
include/block/block_int.h | 2 +-
qemu-img.c | 2 +-
19 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/block.c b/block.c
index b33d095..d85b0f2 100644
--- a/block.c
+++ b/block.c
@@ -407,8 +407,8 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
CreateCo *cco = opaque;
assert(cco->drv);
- if (cco->drv->bdrv_create2)
- ret = cco->drv->bdrv_create2(cco->filename, cco->opts, &local_err);
+ if (cco->drv->bdrv_create)
+ ret = cco->drv->bdrv_create(cco->filename, cco->opts, &local_err);
if (error_is_set(&local_err)) {
error_propagate(&cco->err, local_err);
}
@@ -429,7 +429,7 @@ int bdrv_create(BlockDriver *drv, const char* filename,
.err = NULL,
};
- if (!drv->bdrv_create2) {
+ if (!drv->bdrv_create) {
error_setg(errp, "Driver '%s' does not support image creation", drv->format_name);
ret = -ENOTSUP;
goto out;
@@ -1081,7 +1081,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
}
bdrv_qcow2 = bdrv_find_format("qcow2");
- if (bdrv_qcow2->bdrv_create2) {
+ if (bdrv_qcow2->bdrv_create) {
opts = qemu_opts_create(bdrv_qcow2->create_opts, NULL, 0, &error_abort);
qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size);
}
@@ -4732,7 +4732,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
return;
}
- if (drv->bdrv_create2) {
+ if (drv->bdrv_create) {
const char *backing_fmt, *backing_file;
int64_t size;
diff --git a/block/cow.c b/block/cow.c
index 61f2bab..8324c09 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -411,7 +411,7 @@ static BlockDriver bdrv_cow = {
.bdrv_probe = cow_probe,
.bdrv_open = cow_open,
.bdrv_close = cow_close,
- .bdrv_create2 = cow_create,
+ .bdrv_create = cow_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_read = cow_co_read,
diff --git a/block/gluster.c b/block/gluster.c
index 163ca58..e18aef7 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -614,7 +614,7 @@ static BlockDriver bdrv_gluster = {
.bdrv_needs_filename = true,
.bdrv_file_open = qemu_gluster_open,
.bdrv_close = qemu_gluster_close,
- .bdrv_create2 = qemu_gluster_create,
+ .bdrv_create = qemu_gluster_create,
.bdrv_getlength = qemu_gluster_getlength,
.bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
.bdrv_truncate = qemu_gluster_truncate,
@@ -635,7 +635,7 @@ static BlockDriver bdrv_gluster_tcp = {
.bdrv_needs_filename = true,
.bdrv_file_open = qemu_gluster_open,
.bdrv_close = qemu_gluster_close,
- .bdrv_create2 = qemu_gluster_create,
+ .bdrv_create = qemu_gluster_create,
.bdrv_getlength = qemu_gluster_getlength,
.bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
.bdrv_truncate = qemu_gluster_truncate,
@@ -656,7 +656,7 @@ static BlockDriver bdrv_gluster_unix = {
.bdrv_needs_filename = true,
.bdrv_file_open = qemu_gluster_open,
.bdrv_close = qemu_gluster_close,
- .bdrv_create2 = qemu_gluster_create,
+ .bdrv_create = qemu_gluster_create,
.bdrv_getlength = qemu_gluster_getlength,
.bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
.bdrv_truncate = qemu_gluster_truncate,
@@ -677,7 +677,7 @@ static BlockDriver bdrv_gluster_rdma = {
.bdrv_needs_filename = true,
.bdrv_file_open = qemu_gluster_open,
.bdrv_close = qemu_gluster_close,
- .bdrv_create2 = qemu_gluster_create,
+ .bdrv_create = qemu_gluster_create,
.bdrv_getlength = qemu_gluster_getlength,
.bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
.bdrv_truncate = qemu_gluster_truncate,
diff --git a/block/iscsi.c b/block/iscsi.c
index d496aff..97d1018 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1431,7 +1431,7 @@ static BlockDriver bdrv_iscsi = {
.bdrv_needs_filename = true,
.bdrv_file_open = iscsi_open,
.bdrv_close = iscsi_close,
- .bdrv_create2 = iscsi_create,
+ .bdrv_create = iscsi_create,
.create_opts = &iscsi_create_opts,
.bdrv_getlength = iscsi_getlength,
diff --git a/block/qcow.c b/block/qcow.c
index 4f7907b..bc2d58a 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -904,7 +904,7 @@ static BlockDriver bdrv_qcow = {
.bdrv_open = qcow_open,
.bdrv_close = qcow_close,
.bdrv_reopen_prepare = qcow_reopen_prepare,
- .bdrv_create2 = qcow_create,
+ .bdrv_create = qcow_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_co_readv = qcow_co_readv,
diff --git a/block/qcow2.c b/block/qcow2.c
index ed14195..b64d590 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2230,7 +2230,7 @@ static BlockDriver bdrv_qcow2 = {
.bdrv_open = qcow2_open,
.bdrv_close = qcow2_close,
.bdrv_reopen_prepare = qcow2_reopen_prepare,
- .bdrv_create2 = qcow2_create,
+ .bdrv_create = qcow2_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_co_get_block_status = qcow2_co_get_block_status,
.bdrv_set_key = qcow2_set_key,
diff --git a/block/qed.c b/block/qed.c
index e858dc5..41c6931 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -1605,7 +1605,7 @@ static BlockDriver bdrv_qed = {
.bdrv_open = bdrv_qed_open,
.bdrv_close = bdrv_qed_close,
.bdrv_reopen_prepare = bdrv_qed_reopen_prepare,
- .bdrv_create2 = bdrv_qed_create,
+ .bdrv_create = bdrv_qed_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_co_get_block_status = bdrv_qed_co_get_block_status,
.bdrv_make_empty = bdrv_qed_make_empty,
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 0661791..fa88849 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1354,7 +1354,7 @@ static BlockDriver bdrv_file = {
.bdrv_reopen_commit = raw_reopen_commit,
.bdrv_reopen_abort = raw_reopen_abort,
.bdrv_close = raw_close,
- .bdrv_create2 = raw_create,
+ .bdrv_create = raw_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_co_get_block_status = raw_co_get_block_status,
.bdrv_co_write_zeroes = raw_co_write_zeroes,
@@ -1728,7 +1728,7 @@ static BlockDriver bdrv_host_device = {
.bdrv_reopen_prepare = raw_reopen_prepare,
.bdrv_reopen_commit = raw_reopen_commit,
.bdrv_reopen_abort = raw_reopen_abort,
- .bdrv_create2 = hdev_create,
+ .bdrv_create = hdev_create,
.create_opts = &raw_create_opts,
.bdrv_co_write_zeroes = hdev_co_write_zeroes,
@@ -1861,7 +1861,7 @@ static BlockDriver bdrv_host_floppy = {
.bdrv_reopen_prepare = raw_reopen_prepare,
.bdrv_reopen_commit = raw_reopen_commit,
.bdrv_reopen_abort = raw_reopen_abort,
- .bdrv_create2 = hdev_create,
+ .bdrv_create = hdev_create,
.create_opts = &raw_create_opts,
.bdrv_aio_readv = raw_aio_readv,
@@ -1971,7 +1971,7 @@ static BlockDriver bdrv_host_cdrom = {
.bdrv_reopen_prepare = raw_reopen_prepare,
.bdrv_reopen_commit = raw_reopen_commit,
.bdrv_reopen_abort = raw_reopen_abort,
- .bdrv_create2 = hdev_create,
+ .bdrv_create = hdev_create,
.create_opts = &raw_create_opts,
.bdrv_aio_readv = raw_aio_readv,
@@ -2100,7 +2100,7 @@ static BlockDriver bdrv_host_cdrom = {
.bdrv_reopen_prepare = raw_reopen_prepare,
.bdrv_reopen_commit = raw_reopen_commit,
.bdrv_reopen_abort = raw_reopen_abort,
- .bdrv_create2 = hdev_create,
+ .bdrv_create = hdev_create,
.create_opts = &raw_create_opts,
.bdrv_aio_readv = raw_aio_readv,
diff --git a/block/raw-win32.c b/block/raw-win32.c
index 1e957d2..3d6acfc 100644
--- a/block/raw-win32.c
+++ b/block/raw-win32.c
@@ -466,7 +466,7 @@ static BlockDriver bdrv_file = {
.bdrv_needs_filename = true,
.bdrv_file_open = raw_open,
.bdrv_close = raw_close,
- .bdrv_create2 = raw_create,
+ .bdrv_create = raw_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_aio_readv = raw_aio_readv,
diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index d9dd324..319ea2e 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -177,7 +177,7 @@ static BlockDriver bdrv_raw = {
.bdrv_reopen_prepare = &raw_reopen_prepare,
.bdrv_open = &raw_open,
.bdrv_close = &raw_close,
- .bdrv_create2 = &raw_create,
+ .bdrv_create = &raw_create,
.bdrv_co_readv = &raw_co_readv,
.bdrv_co_writev = &raw_co_writev,
.bdrv_co_write_zeroes = &raw_co_write_zeroes,
diff --git a/block/rbd.c b/block/rbd.c
index 6e82f10..43b0590 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -1005,7 +1005,7 @@ static BlockDriver bdrv_rbd = {
.bdrv_needs_filename = true,
.bdrv_file_open = qemu_rbd_open,
.bdrv_close = qemu_rbd_close,
- .bdrv_create2 = qemu_rbd_create,
+ .bdrv_create = qemu_rbd_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_get_info = qemu_rbd_getinfo,
.create_opts = qemu_rbd_create_opts,
diff --git a/block/sheepdog.c b/block/sheepdog.c
index 13ac0d0..0843a83 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -2512,7 +2512,7 @@ static BlockDriver bdrv_sheepdog = {
.bdrv_needs_filename = true,
.bdrv_file_open = sd_open,
.bdrv_close = sd_close,
- .bdrv_create2 = sd_create,
+ .bdrv_create = sd_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_getlength = sd_getlength,
.bdrv_get_allocated_file_size = sd_get_allocated_file_size,
@@ -2542,7 +2542,7 @@ static BlockDriver bdrv_sheepdog_tcp = {
.bdrv_needs_filename = true,
.bdrv_file_open = sd_open,
.bdrv_close = sd_close,
- .bdrv_create2 = sd_create,
+ .bdrv_create = sd_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_getlength = sd_getlength,
.bdrv_get_allocated_file_size = sd_get_allocated_file_size,
@@ -2571,7 +2571,7 @@ static BlockDriver bdrv_sheepdog_unix = {
.bdrv_needs_filename = true,
.bdrv_file_open = sd_open,
.bdrv_close = sd_close,
- .bdrv_create2 = sd_create,
+ .bdrv_create = sd_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_getlength = sd_getlength,
.bdrv_get_allocated_file_size = sd_get_allocated_file_size,
diff --git a/block/ssh.c b/block/ssh.c
index 8fd2175..634b376 100644
--- a/block/ssh.c
+++ b/block/ssh.c
@@ -1043,7 +1043,7 @@ static BlockDriver bdrv_ssh = {
.instance_size = sizeof(BDRVSSHState),
.bdrv_parse_filename = ssh_parse_filename,
.bdrv_file_open = ssh_file_open,
- .bdrv_create2 = ssh_create,
+ .bdrv_create = ssh_create,
.bdrv_close = ssh_close,
.bdrv_has_zero_init = ssh_has_zero_init,
.bdrv_co_readv = ssh_co_readv,
diff --git a/block/vdi.c b/block/vdi.c
index e5494a0..b4ae900 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -789,7 +789,7 @@ static BlockDriver bdrv_vdi = {
.bdrv_open = vdi_open,
.bdrv_close = vdi_close,
.bdrv_reopen_prepare = vdi_reopen_prepare,
- .bdrv_create2 = vdi_create,
+ .bdrv_create = vdi_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_co_get_block_status = vdi_co_get_block_status,
.bdrv_make_empty = vdi_make_empty,
diff --git a/block/vhdx.c b/block/vhdx.c
index 057c409..ed7d57f 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -1908,7 +1908,7 @@ static BlockDriver bdrv_vhdx = {
.bdrv_reopen_prepare = vhdx_reopen_prepare,
.bdrv_co_readv = vhdx_co_readv,
.bdrv_co_writev = vhdx_co_writev,
- .bdrv_create2 = vhdx_create,
+ .bdrv_create = vhdx_create,
.bdrv_get_info = vhdx_get_info,
.bdrv_check = vhdx_check,
diff --git a/block/vmdk.c b/block/vmdk.c
index 9403d5d..dec912b 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1997,7 +1997,7 @@ static BlockDriver bdrv_vmdk = {
.bdrv_write = vmdk_co_write,
.bdrv_co_write_zeroes = vmdk_co_write_zeroes,
.bdrv_close = vmdk_close,
- .bdrv_create2 = vmdk_create,
+ .bdrv_create = vmdk_create,
.bdrv_co_flush_to_disk = vmdk_co_flush,
.bdrv_co_get_block_status = vmdk_co_get_block_status,
.bdrv_get_allocated_file_size = vmdk_get_allocated_file_size,
diff --git a/block/vpc.c b/block/vpc.c
index f77f4a5..c97d6f6 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -868,7 +868,7 @@ static BlockDriver bdrv_vpc = {
.bdrv_open = vpc_open,
.bdrv_close = vpc_close,
.bdrv_reopen_prepare = vpc_reopen_prepare,
- .bdrv_create2 = vpc_create,
+ .bdrv_create = vpc_create,
.bdrv_read = vpc_co_read,
.bdrv_write = vpc_co_write,
diff --git a/include/block/block_int.h b/include/block/block_int.h
index b9ddbaa..1739f9b 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -103,7 +103,7 @@ struct BlockDriver {
const uint8_t *buf, int nb_sectors);
void (*bdrv_close)(BlockDriverState *bs);
void (*bdrv_rebind)(BlockDriverState *bs);
- int (*bdrv_create2)(const char *filename, QemuOpts *opts,
+ int (*bdrv_create)(const char *filename, QemuOpts *opts,
Error **errp);
int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
int (*bdrv_make_empty)(BlockDriverState *bs);
diff --git a/qemu-img.c b/qemu-img.c
index 920e4bd..b61a109 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1311,7 +1311,7 @@ static int img_convert(int argc, char **argv)
goto out;
}
- if (drv->bdrv_create2) {
+ if (drv->bdrv_create) {
const char *out_baseimg_param;
create_opts = qemu_opts_append(create_opts, drv->create_opts);
--
1.6.0.2
^ permalink raw reply related [flat|nested] 38+ messages in thread
* Re: [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
` (24 preceding siblings ...)
2014-01-20 14:20 ` [Qemu-devel] [v19 25/25] change back to original name from bdrv_create2 to bdrv_create Chunyan Liu
@ 2014-01-22 14:35 ` Kevin Wolf
2014-01-22 16:11 ` Stefan Hajnoczi
25 siblings, 1 reply; 38+ messages in thread
From: Kevin Wolf @ 2014-01-22 14:35 UTC (permalink / raw)
To: Chunyan Liu; +Cc: qemu-devel, stefanha
Am 20.01.2014 um 15:19 hat Chunyan Liu geschrieben:
> This patch series is to replace QEMUOptionParameter with QemuOpts, so that only
> one Qemu Option structure is kept in QEMU code.
>
> This version is based on Dong Xu's previous patches, to move the work forward.
> https://lists.gnu.org/archive/html/qemu-devel/2013-08/msg01695.html
Please check the coding style of all patches, especially braces and
trailing whitespace. I commented on a few occurences, but didn't do so
consistently throughout the series.
Kevin
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts
2014-01-22 14:35 ` [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Kevin Wolf
@ 2014-01-22 16:11 ` Stefan Hajnoczi
0 siblings, 0 replies; 38+ messages in thread
From: Stefan Hajnoczi @ 2014-01-22 16:11 UTC (permalink / raw)
To: Chunyan Liu; +Cc: Kevin Wolf, qemu-devel, stefanha
On Wed, Jan 22, 2014 at 03:35:15PM +0100, Kevin Wolf wrote:
> Am 20.01.2014 um 15:19 hat Chunyan Liu geschrieben:
> > This patch series is to replace QEMUOptionParameter with QemuOpts, so that only
> > one Qemu Option structure is kept in QEMU code.
> >
> > This version is based on Dong Xu's previous patches, to move the work forward.
> > https://lists.gnu.org/archive/html/qemu-devel/2013-08/msg01695.html
>
> Please check the coding style of all patches, especially braces and
> trailing whitespace. I commented on a few occurences, but didn't do so
> consistently throughout the series.
Use scripts/checkpatch.pl to scan your patches for coding style
violations.
Stefan
^ permalink raw reply [flat|nested] 38+ messages in thread