* [Qemu-devel] [PATCH 01/26] qapi: output def_value_str when query command line options
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 23:15 ` Eric Blake
2014-03-21 0:13 ` [Qemu-devel] [PATCH 02/26] add def_value_str to QemuOptDesc Leandro Dorileo
` (24 subsequent siblings)
25 siblings, 1 reply; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones, Dong Xu Wang,
Luiz Capitulino, Chunyan Liu, Leandro Dorileo, Ronnie Sahlberg,
Josh Durgin, Anthony Liguori, Paolo Bonzini, Stefan Weil,
Max Reitz, MORITA Kazutaka, Benoit Canet
From: Chunyan Liu <cyliu@suse.com>
Change qapi interfaces to output the newly added def_value_str when querying
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 | 6 +++++-
qmp-commands.hx | 2 ++
util/qemu-config.c | 4 ++++
3 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/qapi-schema.json b/qapi-schema.json
index b68cd44..cf9174e 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4088,12 +4088,16 @@
#
# @help: #optional human readable text string, not suitable for parsing.
#
+# @default: #optional string representation of the default used
+# if the option is omitted. (since 2.0)
+#
# Since 1.5
##
{ '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 a22621f..178aadd 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2895,6 +2895,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 f610101..d608b2f 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.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* Re: [Qemu-devel] [PATCH 01/26] qapi: output def_value_str when query command line options
2014-03-21 0:13 ` [Qemu-devel] [PATCH 01/26] qapi: output def_value_str when query command line options Leandro Dorileo
@ 2014-03-21 23:15 ` Eric Blake
0 siblings, 0 replies; 34+ messages in thread
From: Eric Blake @ 2014-03-21 23:15 UTC (permalink / raw)
To: Leandro Dorileo, qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Peter Lieven, Richard W.M. Jones, Dong Xu Wang, Luiz Capitulino,
Chunyan Liu, Ronnie Sahlberg, Josh Durgin, Anthony Liguori,
Paolo Bonzini, Stefan Weil, Max Reitz, Markus Armbruster,
MORITA Kazutaka, Benoit Canet
[-- Attachment #1: Type: text/plain, Size: 1000 bytes --]
On 03/20/2014 06:13 PM, Leandro Dorileo wrote:
> From: Chunyan Liu <cyliu@suse.com>
>
> Change qapi interfaces to output the newly added def_value_str when querying
> 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 | 6 +++++-
> qmp-commands.hx | 2 ++
> util/qemu-config.c | 4 ++++
> 3 files changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/qapi-schema.json b/qapi-schema.json
> index b68cd44..cf9174e 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -4088,12 +4088,16 @@
> #
> # @help: #optional human readable text string, not suitable for parsing.
> #
> +# @default: #optional string representation of the default used
> +# if the option is omitted. (since 2.0)
We've missed 2.0; this needs to mention 2.1.
--
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] 34+ messages in thread
* [Qemu-devel] [PATCH 02/26] add def_value_str to QemuOptDesc
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 01/26] qapi: output def_value_str when query command line options Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 03/26] QemuOpt: improve default value Leandro Dorileo
` (23 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones, Dong Xu Wang,
Luiz Capitulino, Chunyan Liu, Leandro Dorileo, Ronnie Sahlberg,
Josh Durgin, Anthony Liguori, Paolo Bonzini, Stefan Weil,
Max Reitz, MORITA Kazutaka, Benoit Canet
From: Chunyan Liu <cyliu@suse.com>
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 | 84 +++++++++++++++++++++++++++++++++++++--------------
2 files changed, 63 insertions(+), 24 deletions(-)
diff --git a/include/qemu/option.h b/include/qemu/option.h
index 8c0ac34..c3b0a91 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -99,6 +99,7 @@ typedef struct QemuOptDesc {
const char *name;
enum QemuOptType type;
const char *help;
+ const char *def_value_str;
} QemuOptDesc;
struct QemuOptsList {
@@ -156,7 +157,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 9d898af..8c0756d 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -33,6 +33,20 @@
#include "qapi/qmp/qerror.h"
#include "qemu/option_int.h"
+static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
+ const char *name)
+{
+ int i;
+
+ for (i = 0; desc[i].name != NULL; i++) {
+ if (strcmp(desc[i].name, name) == 0) {
+ return &desc[i];
+ }
+ }
+
+ return NULL;
+}
+
/*
* Extracts the name of an option from the parameter string (p points at the
* first byte of the option name)
@@ -556,6 +570,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);
+
+ if (!opt) {
+ const QemuOptDesc *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;
}
@@ -575,8 +596,13 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
{
QemuOpt *opt = qemu_opt_find(opts, name);
- if (opt == NULL)
+ if (opt == NULL) {
+ const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
+ if (desc && desc->def_value_str) {
+ parse_option_bool(name, desc->def_value_str, &defval, &error_abort);
+ }
return defval;
+ }
assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL);
return opt->value.boolean;
}
@@ -585,8 +611,14 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
{
QemuOpt *opt = qemu_opt_find(opts, name);
- if (opt == NULL)
+ if (opt == NULL) {
+ const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
+ if (desc && desc->def_value_str) {
+ parse_option_number(name, desc->def_value_str, &defval,
+ &error_abort);
+ }
return defval;
+ }
assert(opt->desc && opt->desc->type == QEMU_OPT_NUMBER);
return opt->value.uint;
}
@@ -595,8 +627,13 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
{
QemuOpt *opt = qemu_opt_find(opts, name);
- if (opt == NULL)
+ if (opt == NULL) {
+ const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
+ if (desc && desc->def_value_str) {
+ parse_option_size(name, desc->def_value_str, &defval, &error_abort);
+ }
return defval;
+ }
assert(opt->desc && opt->desc->type == QEMU_OPT_SIZE);
return opt->value.uint;
}
@@ -637,20 +674,6 @@ static bool opts_accepts_any(const QemuOpts *opts)
return opts->list->desc[0].name == NULL;
}
-static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
- const char *name)
-{
- int i;
-
- for (i = 0; desc[i].name != NULL; i++) {
- if (strcmp(desc[i].name, name) == 0) {
- return &desc[i];
- }
- }
-
- return NULL;
-}
-
int qemu_opt_unset(QemuOpts *opts, const char *name)
{
QemuOpt *opt = qemu_opt_find(opts, name);
@@ -895,17 +918,32 @@ 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) {
+ fprintf(stderr, "%s=\"%s\" ", opt->name, opt->str);
+ }
+ return;
+ }
+ for (; desc && desc->name; desc++) {
+ const char *value;
+ QemuOpt *opt = qemu_opt_find(opts, desc->name);
+
+ value = opt ? opt->str : desc->def_value_str;
+ if (!value) {
+ continue;
+ }
+ if (desc->type == QEMU_OPT_STRING) {
+ fprintf(stderr, "%s='%s' ", desc->name, value);
+ } else {
+ fprintf(stderr, "%s=%s ", desc->name, value);
+ }
}
fprintf(stderr, "\n");
- return 0;
}
static int opts_do_parse(QemuOpts *opts, const char *params,
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 03/26] QemuOpt: improve default value
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 01/26] qapi: output def_value_str when query command line options Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 02/26] add def_value_str to QemuOptDesc Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 04/26] QemuOpt: introduce qemu_opts_append() Leandro Dorileo
` (22 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Use a pointer to a structure holding the primitive types and avoid
parsing the default value representation.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
include/qemu/option.h | 20 +++++++++++++++++++-
util/qemu-config.c | 4 ++--
util/qemu-option.c | 45 ++++++++++++++++++++++++++-------------------
3 files changed, 47 insertions(+), 22 deletions(-)
diff --git a/include/qemu/option.h b/include/qemu/option.h
index c3b0a91..f0d4798 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -95,11 +95,29 @@ enum QemuOptType {
QEMU_OPT_SIZE, /* size, accepts (K)ilo, (M)ega, (G)iga, (T)era postfix */
};
+#define QEMU_OPT_VAL_STR(_val) \
+ &(QemuOptValue) {.s = _val} \
+
+#define QEMU_OPT_VAL_NUMBER(_val) \
+ &(QemuOptValue) {.n = _val} \
+
+#define QEMU_OPT_VAL_SIZE(_val) \
+ &(QemuOptValue) {.n = _val} \
+
+#define QEMU_OPT_VAL_BOOL(_val) \
+ &(QemuOptValue) {.b = _val} \
+
+typedef struct QemuOptValue {
+ bool b;
+ uint64_t n;
+ const char *s;
+} QemuOptValue;
+
typedef struct QemuOptDesc {
const char *name;
enum QemuOptType type;
const char *help;
- const char *def_value_str;
+ QemuOptValue *def_val;
} QemuOptDesc;
struct QemuOptsList {
diff --git a/util/qemu-config.c b/util/qemu-config.c
index d608b2f..a40711b 100644
--- a/util/qemu-config.c
+++ b/util/qemu-config.c
@@ -68,9 +68,9 @@ 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) {
+ if (desc[i].def_val) {
info->has_q_default = true;
- info->q_default = g_strdup(desc[i].def_value_str);
+ info->q_default = g_strdup(desc[i].def_val->s);
}
entry = g_malloc0(sizeof(*entry));
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 8c0756d..612a966 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -573,8 +573,8 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name)
if (!opt) {
const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
- if (desc && desc->def_value_str) {
- return desc->def_value_str;
+ if (desc && desc->def_val) {
+ return desc->def_val->s;
}
}
return opt ? opt->str : NULL;
@@ -598,11 +598,12 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
if (opt == NULL) {
const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
- if (desc && desc->def_value_str) {
- parse_option_bool(name, desc->def_value_str, &defval, &error_abort);
+ if (desc && desc->def_val) {
+ return desc->def_val->b;
}
return defval;
}
+
assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL);
return opt->value.boolean;
}
@@ -613,9 +614,8 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
if (opt == NULL) {
const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
- if (desc && desc->def_value_str) {
- parse_option_number(name, desc->def_value_str, &defval,
- &error_abort);
+ if (desc && desc->def_val) {
+ return desc->def_val->n;
}
return defval;
}
@@ -629,8 +629,8 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
if (opt == NULL) {
const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
- if (desc && desc->def_value_str) {
- parse_option_size(name, desc->def_value_str, &defval, &error_abort);
+ if (desc && desc->def_val) {
+ return desc->def_val->n;
}
return defval;
}
@@ -929,21 +929,28 @@ void qemu_opts_print(QemuOpts *opts)
}
return;
}
+
for (; desc && desc->name; desc++) {
- const char *value;
- QemuOpt *opt = qemu_opt_find(opts, desc->name);
+ const char *str;
+ uint64_t number;
+ bool bol;
- value = opt ? opt->str : desc->def_value_str;
- if (!value) {
- continue;
- }
if (desc->type == QEMU_OPT_STRING) {
- fprintf(stderr, "%s='%s' ", desc->name, value);
- } else {
- fprintf(stderr, "%s=%s ", desc->name, value);
+ str = qemu_opt_get(opts, desc->name);
+ if (str) {
+ fprintf(stderr, "%s='%s' ", desc->name, str);
+ }
+ } else if (desc->type == QEMU_OPT_BOOL) {
+ bol = qemu_opt_get_bool(opts, desc->name, false);
+ fprintf(stderr, "%s=%s ", desc->name, bol ? "true" : "false");
+ } else if (desc->type == QEMU_OPT_SIZE) {
+ number = qemu_opt_get_size(opts, desc->name, 0);
+ fprintf(stderr, "%s=%"PRId64" ", desc->name, number);
+ } else if (desc->type == QEMU_OPT_NUMBER) {
+ number = qemu_opt_get_number(opts, desc->name, 0);
+ fprintf(stderr, "%s=%"PRId64" ", desc->name, number);
}
}
- fprintf(stderr, "\n");
}
static int opts_do_parse(QemuOpts *opts, const char *params,
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 04/26] QemuOpt: introduce qemu_opts_append()
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (2 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 03/26] QemuOpt: improve default value Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 05/26] QemuOpt: add qemu_opt_print_help() Leandro Dorileo
` (21 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Chunyan Liu, Leandro Dorileo, Ronnie Sahlberg,
Josh Durgin, Anthony Liguori, Paolo Bonzini, Stefan Weil,
Max Reitz, MORITA Kazutaka, Benoit Canet
From: Chunyan Liu <cyliu@suse.com>
The qemu_opts_append() function is intended to merge to different
QemuOptsList's. The resulting list must be freed by its user.
Signed-off-by: Chunyan Liu <cyliu@suse.com>
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
include/qemu/option.h | 1 +
util/qemu-option.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 70 insertions(+)
diff --git a/include/qemu/option.h b/include/qemu/option.h
index f0d4798..3f4976d 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -157,6 +157,7 @@ int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id);
QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,
int fail_if_exists, Error **errp);
+QemuOptsList *qemu_opts_append(QemuOptsList *head, QemuOptsList *tail);
void qemu_opts_reset(QemuOptsList *list);
void qemu_opts_loc_restore(QemuOpts *opts);
int qemu_opts_set(QemuOptsList *list, const char *id,
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 612a966..026d2ff 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -863,6 +863,75 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,
return opts;
}
+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;
+}
+
+/**
+ * Merge two QEMUOptsList. First argument's QemuOptDesc members take precedence
+ * over second's.
+ *
+ * @note 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.
+ *
+ * The resulting QemuOptsList should be freed by this functions caller.
+ */
+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;
+}
+
void qemu_opts_reset(QemuOptsList *list)
{
QemuOpts *opts, *next_opts;
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 05/26] QemuOpt: add qemu_opt_print_help()
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (3 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 04/26] QemuOpt: introduce qemu_opts_append() Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 06/26] block: migrate block later QemuOptionParameter Leandro Dorileo
` (20 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Analogous to print_option_help(QEMUOptionParameter *list) this function
displays the available key and help for each described QemuOptDesc in
QemuOptList.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
include/qemu/option.h | 1 +
util/qemu-option.c | 12 ++++++++++++
2 files changed, 13 insertions(+)
diff --git a/include/qemu/option.h b/include/qemu/option.h
index 3f4976d..62eacf3 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -177,6 +177,7 @@ void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp);
typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque);
void qemu_opts_print(QemuOpts *opts);
+void qemu_opts_print_help(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 026d2ff..6fac370 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -1022,6 +1022,18 @@ void qemu_opts_print(QemuOpts *opts)
}
}
+void qemu_opts_print_help(QemuOpts *opts)
+{
+ QemuOptDesc *desc = opts->list->desc;
+
+ printf("Supported options:\n");
+
+ for (; desc && desc->name; desc++) {
+ printf("%-16s %s\n", desc->name, desc->help ?
+ desc->help : "No description available");
+ }
+}
+
static int opts_do_parse(QemuOpts *opts, const char *params,
const char *firstname, bool prepend)
{
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 06/26] block: migrate block later QemuOptionParameter
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (4 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 05/26] QemuOpt: add qemu_opt_print_help() Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 07/26] cow: migrate cow driver QemuOptionParameter usage Leandro Dorileo
` (19 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Do the directly migration from QemuOptionParameter to QemuOpts on
block layer.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
block.c | 133 ++++++++++++++++++++++++++++------------------
include/block/block.h | 7 ++-
include/block/block_int.h | 8 ++-
3 files changed, 86 insertions(+), 62 deletions(-)
diff --git a/block.c b/block.c
index acb70fd..e70f360 100644
--- a/block.c
+++ b/block.c
@@ -407,7 +407,7 @@ BlockDriver *bdrv_find_whitelisted_format(const char *format_name,
typedef struct CreateCo {
BlockDriver *drv;
char *filename;
- QEMUOptionParameter *options;
+ QemuOpts *options;
int ret;
Error *err;
} CreateCo;
@@ -427,8 +427,8 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
cco->ret = ret;
}
-int bdrv_create(BlockDriver *drv, const char* filename,
- QEMUOptionParameter *options, Error **errp)
+int bdrv_create(BlockDriver *drv, const char* filename, QemuOpts *options,
+ Error **errp)
{
int ret;
@@ -472,8 +472,7 @@ out:
return ret;
}
-int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
- Error **errp)
+int bdrv_create_file(const char *filename, QemuOpts *options, Error **errp)
{
BlockDriver *drv;
Error *local_err = NULL;
@@ -1248,7 +1247,7 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
BlockDriverState *bs1;
int64_t total_size;
BlockDriver *bdrv_qcow2;
- QEMUOptionParameter *create_options;
+ QemuOpts *create_options;
QDict *snapshot_options;
/* if snapshot, we create a temporary backing file and open it
@@ -1274,13 +1273,27 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
}
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);
+ create_options = qemu_opts_create(bdrv_qcow2->create_options, NULL, 0,
+ &local_err);
+
+ if (create_options == NULL) {
+ error_setg(errp, "Could not create internal option %s",
+ error_get_pretty(local_err));
+ error_free(local_err);
+ local_err = NULL;
+ goto fail;
+ }
+
+ ret = qemu_opt_set_number(create_options, BLOCK_OPT_SIZE, total_size);
+ if (ret < 0) {
+ qemu_opts_del(create_options);
+ goto fail;
+ }
ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, &local_err);
- free_option_parameters(create_options);
+ qemu_opts_del(create_options);
+
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not create temporary overlay "
"'%s': %s", tmp_filename,
@@ -5259,12 +5272,14 @@ 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;
- QEMUOptionParameter *backing_fmt, *backing_file, *size;
+ QemuOptsList *list;
+ QemuOpts *create_options;
+ const char *backing_file, *backing_fmt;
BlockDriver *drv, *proto_drv;
BlockDriver *backing_drv = NULL;
Error *local_err = NULL;
int ret = 0;
+ uint64_t size;
/* Find driver and parse its options */
drv = bdrv_find_format(fmt);
@@ -5279,28 +5294,39 @@ 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);
+ list = qemu_opts_append(drv->create_options, proto_drv->create_options);
+ if (!list) {
+ error_setg(errp, "Could not allocate option list");
+ return;
+ }
- /* Create parameter list with default values */
- param = parse_option_parameters("", create_options, param);
+ create_options = qemu_opts_create(list, NULL, 0, &local_err);
+ if (create_options == NULL) {
+ error_setg(errp, "Could not create internal option %s",
+ error_get_pretty(local_err));
+ error_free(local_err);
+ g_free(list);
+ local_err = NULL;
+ return;
+ }
- set_option_parameter_int(param, BLOCK_OPT_SIZE, img_size);
+ ret = qemu_opt_set_number(create_options, BLOCK_OPT_SIZE, img_size);
+ if (ret < 0) {
+ goto out;
+ }
/* 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);
+ ret = qemu_opts_do_parse(create_options, options, NULL);
+ if (ret < 0) {
goto out;
}
}
if (base_filename) {
- if (set_option_parameter(param, BLOCK_OPT_BACKING_FILE,
- base_filename)) {
+ ret = qemu_opt_set(create_options, BLOCK_OPT_BACKING_FILE,
+ base_filename);
+ if (ret < 0) {
error_setg(errp, "Backing file not supported for file format '%s'",
fmt);
goto out;
@@ -5308,40 +5334,37 @@ void bdrv_img_create(const char *filename, const char *fmt,
}
if (base_fmt) {
- if (set_option_parameter(param, BLOCK_OPT_BACKING_FMT, base_fmt)) {
+ ret = qemu_opt_set(create_options, BLOCK_OPT_BACKING_FMT, base_fmt);
+ if (ret < 0) {
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(create_options, BLOCK_OPT_BACKING_FILE);
+ if (backing_file && !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);
+ backing_fmt = qemu_opt_get(create_options, 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->value.s);
+ 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 = get_option_parameter(param, BLOCK_OPT_SIZE);
- if (size && size->value.n == -1) {
- if (backing_file && backing_file->value.s) {
+ size = qemu_opt_get_size(create_options, 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 */
@@ -5349,12 +5372,11 @@ void bdrv_img_create(const char *filename, const char *fmt,
flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
bs = NULL;
- ret = bdrv_open(&bs, backing_file->value.s, NULL, NULL, back_flags,
+ ret = bdrv_open(&bs, backing_file, NULL, 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));
+ backing_file, error_get_pretty(local_err));
error_free(local_err);
local_err = NULL;
goto out;
@@ -5362,8 +5384,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
bdrv_get_geometry(bs, &size);
size *= 512;
- snprintf(buf, sizeof(buf), "%" PRId64, size);
- set_option_parameter(param, BLOCK_OPT_SIZE, buf);
+ qemu_opt_set_number(create_options, BLOCK_OPT_SIZE, size);
bdrv_unref(bs);
} else {
@@ -5373,19 +5394,25 @@ void bdrv_img_create(const char *filename, const char *fmt,
}
if (!quiet) {
- printf("Formatting '%s', fmt=%s ", filename, fmt);
- print_option_parameters(param);
+ fprintf(stderr, "Formatting '%s', fmt=%s ", filename, fmt);
+ qemu_opts_print(create_options);
puts("");
}
- ret = bdrv_create(drv, filename, param, &local_err);
+ ret = bdrv_create(drv, filename, create_options, &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)) {
+ uint32_t cluster_size;
+
+ cluster_size = qemu_opt_get_size(create_options,
+ BLOCK_OPT_CLUSTER_SIZE, 0);
+
+ if (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);
@@ -5393,8 +5420,8 @@ void bdrv_img_create(const char *filename, const char *fmt,
}
out:
- free_option_parameters(create_options);
- free_option_parameters(param);
+ qemu_opts_del(create_options);
+ g_free(list);
if (local_err) {
error_propagate(errp, local_err);
@@ -5413,7 +5440,7 @@ 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 *options)
{
if (bs->drv->bdrv_amend_options == NULL) {
return -ENOTSUP;
diff --git a/include/block/block.h b/include/block/block.h
index 1ed55d8..ec3fc34 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -177,9 +177,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, Error **errp);
-int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
- Error **errp);
+ QemuOpts *options, Error **errp);
+int bdrv_create_file(const char *filename, QemuOpts *options, Error **errp);
BlockDriverState *bdrv_new(const char *device_name);
void bdrv_make_anon(BlockDriverState *bs);
void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old);
@@ -283,7 +282,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 *options);
/* external snapshots */
bool bdrv_recurse_is_first_non_filter(BlockDriverState *bs,
diff --git a/include/block/block_int.h b/include/block/block_int.h
index cd5bc73..365686f 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -116,8 +116,7 @@ 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_create)(const char *filename, QemuOpts *options, Error **errp);
int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
int (*bdrv_make_empty)(BlockDriverState *bs);
/* aio */
@@ -216,7 +215,7 @@ struct BlockDriver {
BlockDriverCompletionFunc *cb, void *opaque);
/* List of options for creating images, terminated by name == NULL */
- QEMUOptionParameter *create_options;
+ QemuOptsList *create_options;
/*
@@ -226,8 +225,7 @@ struct BlockDriver {
int (*bdrv_check)(BlockDriverState* bs, BdrvCheckResult *result,
BdrvCheckMode fix);
- int (*bdrv_amend_options)(BlockDriverState *bs,
- QEMUOptionParameter *options);
+ int (*bdrv_amend_options)(BlockDriverState *bs, QemuOpts *options);
void (*bdrv_debug_event)(BlockDriverState *bs, BlkDebugEvent event);
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 07/26] cow: migrate cow driver QemuOptionParameter usage
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (5 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 06/26] block: migrate block later QemuOptionParameter Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 08/26] gluster: migrate gluster " Leandro Dorileo
` (18 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Do the directly migration from QemuOptionParameter to QemuOpts on
cow block driver.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
block/cow.c | 44 ++++++++++++++++++++++----------------------
1 file changed, 22 insertions(+), 22 deletions(-)
diff --git a/block/cow.c b/block/cow.c
index 30deb88..811f7f7 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -324,8 +324,7 @@ static void cow_close(BlockDriverState *bs)
{
}
-static int cow_create(const char *filename, QEMUOptionParameter *options,
- Error **errp)
+static int cow_create(const char *filename, QemuOpts *options, Error **errp)
{
struct cow_header_v2 cow_header;
struct stat st;
@@ -335,16 +334,13 @@ static int cow_create(const char *filename, QEMUOptionParameter *options,
int ret;
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(options, BLOCK_OPT_SIZE, 0);
+ if (image_sectors) {
+ image_sectors = image_sectors / 512;
}
+ image_filename = qemu_opt_get(options, BLOCK_OPT_BACKING_FILE);
+
ret = bdrv_create_file(filename, options, &local_err);
if (ret < 0) {
error_propagate(errp, local_err);
@@ -393,18 +389,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"
+static QemuOptsList cow_create_options = {
+ .name = "cow_create_options",
+ .head = QTAILQ_HEAD_INITIALIZER(cow_create_options.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"
+ },
+ { NULL }
},
- { NULL }
};
static BlockDriver bdrv_cow = {
@@ -421,7 +421,7 @@ static BlockDriver bdrv_cow = {
.bdrv_write = cow_co_write,
.bdrv_co_get_block_status = cow_co_get_block_status,
- .create_options = cow_create_options,
+ .create_options = &cow_create_options,
};
static void bdrv_cow_init(void)
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 08/26] gluster: migrate gluster driver QemuOptionParameter usage
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (6 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 07/26] cow: migrate cow driver QemuOptionParameter usage Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 09/26] iscsi: migrate iscsi " Leandro Dorileo
` (17 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Do the directly migration from QemuOptionParameter to QemuOpts on
gluster block driver.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
block/gluster.c | 68 +++++++++++++++++++++++++++++++--------------------------
1 file changed, 37 insertions(+), 31 deletions(-)
diff --git a/block/gluster.c b/block/gluster.c
index a44d612..e8d966e 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -470,14 +470,15 @@ static inline int qemu_gluster_zerofill(struct glfs_fd *fd, int64_t offset,
}
#endif
-static int qemu_gluster_create(const char *filename,
- QEMUOptionParameter *options, Error **errp)
+static int qemu_gluster_create(const char *filename, QemuOpts *options,
+ Error **errp)
{
struct glfs *glfs;
struct glfs_fd *fd;
int ret = 0;
int prealloc = 0;
int64_t total_size = 0;
+ const char *prealloc_opt;
GlusterConf *gconf = g_malloc0(sizeof(GlusterConf));
glfs = qemu_gluster_init(gconf, filename, errp);
@@ -486,24 +487,25 @@ 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;
- } 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, "full") &&
- gluster_supports_zerofill()) {
- prealloc = 1;
- } else {
- error_setg(errp, "Invalid preallocation mode: '%s'"
- " or GlusterFS doesn't support zerofill API",
- options->value.s);
- ret = -EINVAL;
- goto out;
- }
+ total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+ if (total_size) {
+ total_size = total_size / BDRV_SECTOR_SIZE;
+ }
+
+ prealloc_opt = qemu_opt_get(options, BLOCK_OPT_PREALLOC);
+ if (prealloc_opt) {
+ if (!strcmp(prealloc_opt, "off")) {
+ prealloc = 0;
+ } else if (!strcmp(prealloc_opt, "full") &&
+ gluster_supports_zerofill()) {
+ prealloc = 1;
+ } else {
+ error_setg(errp, "Invalid preallocation mode: '%s'"
+ " or GlusterFS doesn't support zerofill API",
+ prealloc_opt);
+ ret = -EINVAL;
+ goto out;
}
- options++;
}
fd = glfs_creat(glfs, gconf->image,
@@ -688,18 +690,22 @@ 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"
- },
- {
- .name = BLOCK_OPT_PREALLOC,
- .type = OPT_STRING,
- .help = "Preallocation mode (allowed values: off, full)"
+static QemuOptsList qemu_gluster_create_options = {
+ .name = "qemu_gluster_create_options",
+ .head = QTAILQ_HEAD_INITIALIZER(qemu_gluster_create_options.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size"
+ },
+ {
+ .name = BLOCK_OPT_PREALLOC,
+ .type = QEMU_OPT_STRING,
+ .help = "Preallocation mode (allowed values: off, full)"
+ },
+ { NULL }
},
- { NULL }
};
static BlockDriver bdrv_gluster = {
@@ -726,7 +732,7 @@ static BlockDriver bdrv_gluster = {
#ifdef CONFIG_GLUSTERFS_ZEROFILL
.bdrv_co_write_zeroes = qemu_gluster_co_write_zeroes,
#endif
- .create_options = qemu_gluster_create_options,
+ .create_options = &qemu_gluster_create_options,
};
static BlockDriver bdrv_gluster_tcp = {
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 09/26] iscsi: migrate iscsi driver QemuOptionParameter usage
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (7 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 08/26] gluster: migrate gluster " Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 6:43 ` Peter Lieven
2014-03-21 0:13 ` [Qemu-devel] [PATCH 10/26] nfs: migrate nfs " Leandro Dorileo
` (16 subsequent siblings)
25 siblings, 1 reply; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Do the directly migration from QemuOptionParameter to QemuOpts on
iscsi block driver.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
block/iscsi.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/block/iscsi.c b/block/iscsi.c
index b490e98..85252e7 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1125,7 +1125,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
QemuOpts *opts;
Error *local_err = NULL;
const char *filename;
- int i, ret;
+ int i, ret = 0;
if ((BDRV_SECTOR_SIZE % 512) != 0) {
error_setg(errp, "iSCSI: Invalid BDRV_SECTOR_SIZE. "
@@ -1382,8 +1382,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t offset)
return 0;
}
-static int iscsi_create(const char *filename, QEMUOptionParameter *options,
- Error **errp)
+static int iscsi_create(const char *filename, QemuOpts *options, Error **errp)
{
int ret = 0;
int64_t total_size = 0;
@@ -1393,12 +1392,9 @@ 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(options, BLOCK_OPT_SIZE, 0);
+ if (total_size) {
+ total_size = total_size / BDRV_SECTOR_SIZE;
}
bs->opaque = g_malloc0(sizeof(struct IscsiLun));
@@ -1451,13 +1447,17 @@ static int iscsi_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
return 0;
}
-static QEMUOptionParameter iscsi_create_options[] = {
- {
- .name = BLOCK_OPT_SIZE,
- .type = OPT_SIZE,
- .help = "Virtual disk size"
+static QemuOptsList iscsi_create_options = {
+ .name = "iscsi_create_options",
+ .head = QTAILQ_HEAD_INITIALIZER(iscsi_create_options.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size"
+ },
+ { NULL }
},
- { NULL }
};
static BlockDriver bdrv_iscsi = {
@@ -1469,7 +1469,7 @@ static BlockDriver bdrv_iscsi = {
.bdrv_file_open = iscsi_open,
.bdrv_close = iscsi_close,
.bdrv_create = iscsi_create,
- .create_options = iscsi_create_options,
+ .create_options = &iscsi_create_options,
.bdrv_reopen_prepare = iscsi_reopen_prepare,
.bdrv_getlength = iscsi_getlength,
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* Re: [Qemu-devel] [PATCH 09/26] iscsi: migrate iscsi driver QemuOptionParameter usage
2014-03-21 0:13 ` [Qemu-devel] [PATCH 09/26] iscsi: migrate iscsi " Leandro Dorileo
@ 2014-03-21 6:43 ` Peter Lieven
2014-03-21 13:31 ` Leandro Dorileo
0 siblings, 1 reply; 34+ messages in thread
From: Peter Lieven @ 2014-03-21 6:43 UTC (permalink / raw)
To: Leandro Dorileo, qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Richard W.M. Jones, Luiz Capitulino,
Ronnie Sahlberg, Josh Durgin, Anthony Liguori, Paolo Bonzini,
Stefan Weil, Max Reitz, MORITA Kazutaka, Benoit Canet
On 21.03.2014 01:13, Leandro Dorileo wrote:
> Do the directly migration from QemuOptionParameter to QemuOpts on
> iscsi block driver.
>
> Signed-off-by: Leandro Dorileo <l@dorileo.org>
> ---
> block/iscsi.c | 32 ++++++++++++++++----------------
> 1 file changed, 16 insertions(+), 16 deletions(-)
>
> diff --git a/block/iscsi.c b/block/iscsi.c
> index b490e98..85252e7 100644
> --- a/block/iscsi.c
> +++ b/block/iscsi.c
> @@ -1125,7 +1125,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
> QemuOpts *opts;
> Error *local_err = NULL;
> const char *filename;
> - int i, ret;
> + int i, ret = 0;
why? is there a chance that ret remains uninitialized?
>
> if ((BDRV_SECTOR_SIZE % 512) != 0) {
> error_setg(errp, "iSCSI: Invalid BDRV_SECTOR_SIZE. "
> @@ -1382,8 +1382,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t offset)
> return 0;
> }
>
> -static int iscsi_create(const char *filename, QEMUOptionParameter *options,
> - Error **errp)
> +static int iscsi_create(const char *filename, QemuOpts *options, Error **errp)
> {
> int ret = 0;
> int64_t total_size = 0;
> @@ -1393,12 +1392,9 @@ 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(options, BLOCK_OPT_SIZE, 0);
> + if (total_size) {
> + total_size = total_size / BDRV_SECTOR_SIZE;
> }
you don't need the if condition. 0 / BDRV_SECTOR_SIZE = 0.
Peter
>
> bs->opaque = g_malloc0(sizeof(struct IscsiLun));
> @@ -1451,13 +1447,17 @@ static int iscsi_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
> return 0;
> }
>
> -static QEMUOptionParameter iscsi_create_options[] = {
> - {
> - .name = BLOCK_OPT_SIZE,
> - .type = OPT_SIZE,
> - .help = "Virtual disk size"
> +static QemuOptsList iscsi_create_options = {
> + .name = "iscsi_create_options",
> + .head = QTAILQ_HEAD_INITIALIZER(iscsi_create_options.head),
> + .desc = {
> + {
> + .name = BLOCK_OPT_SIZE,
> + .type = QEMU_OPT_SIZE,
> + .help = "Virtual disk size"
> + },
> + { NULL }
> },
> - { NULL }
> };
>
> static BlockDriver bdrv_iscsi = {
> @@ -1469,7 +1469,7 @@ static BlockDriver bdrv_iscsi = {
> .bdrv_file_open = iscsi_open,
> .bdrv_close = iscsi_close,
> .bdrv_create = iscsi_create,
> - .create_options = iscsi_create_options,
> + .create_options = &iscsi_create_options,
> .bdrv_reopen_prepare = iscsi_reopen_prepare,
>
> .bdrv_getlength = iscsi_getlength,
--
Mit freundlichen Grüßen
Peter Lieven
...........................................................
KAMP Netzwerkdienste GmbH
Vestische Str. 89-91 | 46117 Oberhausen
Tel: +49 (0) 208.89 402-50 | Fax: +49 (0) 208.89 402-40
pl@kamp.de | http://www.kamp.de
Geschäftsführer: Heiner Lante | Michael Lante
Amtsgericht Duisburg | HRB Nr. 12154
USt-Id-Nr.: DE 120607556
...........................................................
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [Qemu-devel] [PATCH 09/26] iscsi: migrate iscsi driver QemuOptionParameter usage
2014-03-21 6:43 ` Peter Lieven
@ 2014-03-21 13:31 ` Leandro Dorileo
2014-03-21 13:34 ` Leandro Dorileo
2014-03-21 13:42 ` Peter Lieven
0 siblings, 2 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 13:31 UTC (permalink / raw)
To: Peter Lieven
Cc: Kevin Wolf, Fam Zheng, Ronnie Sahlberg, Richard W.M. Jones,
Stefan Weil, Jeff Cody, qemu-devel, Markus Armbruster,
Paolo Bonzini, Stefan Hajnoczi, Josh Durgin, Anthony Liguori,
Liu Yuan, Luiz Capitulino, Max Reitz, MORITA Kazutaka,
Benoit Canet
On Fri, Mar 21, 2014 at 07:43:44AM +0100, Peter Lieven wrote:
> On 21.03.2014 01:13, Leandro Dorileo wrote:
> >Do the directly migration from QemuOptionParameter to QemuOpts on
> >iscsi block driver.
> >
> >Signed-off-by: Leandro Dorileo <l@dorileo.org>
> >---
> > block/iscsi.c | 32 ++++++++++++++++----------------
> > 1 file changed, 16 insertions(+), 16 deletions(-)
> >
> >diff --git a/block/iscsi.c b/block/iscsi.c
> >index b490e98..85252e7 100644
> >--- a/block/iscsi.c
> >+++ b/block/iscsi.c
> >@@ -1125,7 +1125,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
> > QemuOpts *opts;
> > Error *local_err = NULL;
> > const char *filename;
> >- int i, ret;
> >+ int i, ret = 0;
>
> why? is there a chance that ret remains uninitialized?
Yep, my compiler tells me so:
block/iscsi.c:1128:12: error: ‘ret’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
>
> > if ((BDRV_SECTOR_SIZE % 512) != 0) {
> > error_setg(errp, "iSCSI: Invalid BDRV_SECTOR_SIZE. "
> >@@ -1382,8 +1382,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t offset)
> > return 0;
> > }
> >-static int iscsi_create(const char *filename, QEMUOptionParameter *options,
> >- Error **errp)
> >+static int iscsi_create(const char *filename, QemuOpts *options, Error **errp)
> > {
> > int ret = 0;
> > int64_t total_size = 0;
> >@@ -1393,12 +1392,9 @@ 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(options, BLOCK_OPT_SIZE, 0);
> >+ if (total_size) {
> >+ total_size = total_size / BDRV_SECTOR_SIZE;
> > }
> you don't need the if condition. 0 / BDRV_SECTOR_SIZE = 0.
>
I'm not sure, bdrv_img_create() will set BLOCK_OPT_SIZE with img_size, we have no guarantee on the
value passed to bdrv_img_create(), we don't check img_size value there, having said that can't
we run on division by zero here? The previous code wasn't checking it but I wonder if the problem
wasn't there already.
> Peter
> > bs->opaque = g_malloc0(sizeof(struct IscsiLun));
> >@@ -1451,13 +1447,17 @@ static int iscsi_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
> > return 0;
> > }
> >-static QEMUOptionParameter iscsi_create_options[] = {
> >- {
> >- .name = BLOCK_OPT_SIZE,
> >- .type = OPT_SIZE,
> >- .help = "Virtual disk size"
> >+static QemuOptsList iscsi_create_options = {
> >+ .name = "iscsi_create_options",
> >+ .head = QTAILQ_HEAD_INITIALIZER(iscsi_create_options.head),
> >+ .desc = {
> >+ {
> >+ .name = BLOCK_OPT_SIZE,
> >+ .type = QEMU_OPT_SIZE,
> >+ .help = "Virtual disk size"
> >+ },
> >+ { NULL }
> > },
> >- { NULL }
> > };
> > static BlockDriver bdrv_iscsi = {
> >@@ -1469,7 +1469,7 @@ static BlockDriver bdrv_iscsi = {
> > .bdrv_file_open = iscsi_open,
> > .bdrv_close = iscsi_close,
> > .bdrv_create = iscsi_create,
> >- .create_options = iscsi_create_options,
> >+ .create_options = &iscsi_create_options,
> > .bdrv_reopen_prepare = iscsi_reopen_prepare,
> > .bdrv_getlength = iscsi_getlength,
>
>
> --
>
> Mit freundlichen Grüßen
>
> Peter Lieven
>
> ...........................................................
>
> KAMP Netzwerkdienste GmbH
> Vestische Str. 89-91 | 46117 Oberhausen
> Tel: +49 (0) 208.89 402-50 | Fax: +49 (0) 208.89 402-40
> pl@kamp.de | http://www.kamp.de
>
> Geschäftsführer: Heiner Lante | Michael Lante
> Amtsgericht Duisburg | HRB Nr. 12154
> USt-Id-Nr.: DE 120607556
>
> ...........................................................
>
>
--
Leandro Dorileo
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [Qemu-devel] [PATCH 09/26] iscsi: migrate iscsi driver QemuOptionParameter usage
2014-03-21 13:31 ` Leandro Dorileo
@ 2014-03-21 13:34 ` Leandro Dorileo
2014-03-21 13:42 ` Peter Lieven
1 sibling, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 13:34 UTC (permalink / raw)
To: Peter Lieven
Cc: Kevin Wolf, Fam Zheng, Ronnie Sahlberg, Richard W.M. Jones,
Stefan Weil, Jeff Cody, qemu-devel, Markus Armbruster,
Paolo Bonzini, Stefan Hajnoczi, Josh Durgin, Anthony Liguori,
Liu Yuan, Luiz Capitulino, Max Reitz, MORITA Kazutaka,
Benoit Canet
On Fri, Mar 21, 2014 at 01:31:42PM +0000, Leandro Dorileo wrote:
> On Fri, Mar 21, 2014 at 07:43:44AM +0100, Peter Lieven wrote:
> > On 21.03.2014 01:13, Leandro Dorileo wrote:
> > >Do the directly migration from QemuOptionParameter to QemuOpts on
> > >iscsi block driver.
> > >
> > >Signed-off-by: Leandro Dorileo <l@dorileo.org>
> > >---
> > > block/iscsi.c | 32 ++++++++++++++++----------------
> > > 1 file changed, 16 insertions(+), 16 deletions(-)
> > >
> > >diff --git a/block/iscsi.c b/block/iscsi.c
> > >index b490e98..85252e7 100644
> > >--- a/block/iscsi.c
> > >+++ b/block/iscsi.c
> > >@@ -1125,7 +1125,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
> > > QemuOpts *opts;
> > > Error *local_err = NULL;
> > > const char *filename;
> > >- int i, ret;
> > >+ int i, ret = 0;
> >
> > why? is there a chance that ret remains uninitialized?
>
> Yep, my compiler tells me so:
>
> block/iscsi.c:1128:12: error: ‘ret’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
>
>
> >
> > > if ((BDRV_SECTOR_SIZE % 512) != 0) {
> > > error_setg(errp, "iSCSI: Invalid BDRV_SECTOR_SIZE. "
> > >@@ -1382,8 +1382,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t offset)
> > > return 0;
> > > }
> > >-static int iscsi_create(const char *filename, QEMUOptionParameter *options,
> > >- Error **errp)
> > >+static int iscsi_create(const char *filename, QemuOpts *options, Error **errp)
> > > {
> > > int ret = 0;
> > > int64_t total_size = 0;
> > >@@ -1393,12 +1392,9 @@ 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(options, BLOCK_OPT_SIZE, 0);
> > >+ if (total_size) {
> > >+ total_size = total_size / BDRV_SECTOR_SIZE;
> > > }
> > you don't need the if condition. 0 / BDRV_SECTOR_SIZE = 0.
> >
>
> I'm not sure, bdrv_img_create() will set BLOCK_OPT_SIZE with img_size, we have no guarantee on the
> value passed to bdrv_img_create(), we don't check img_size value there, having said that can't
> we run on division by zero here? The previous code wasn't checking it but I wonder if the problem
> wasn't there already.
Ok, qemu-img does guarantee the img_size value...
>
>
> > Peter
> > > bs->opaque = g_malloc0(sizeof(struct IscsiLun));
> > >@@ -1451,13 +1447,17 @@ static int iscsi_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
> > > return 0;
> > > }
> > >-static QEMUOptionParameter iscsi_create_options[] = {
> > >- {
> > >- .name = BLOCK_OPT_SIZE,
> > >- .type = OPT_SIZE,
> > >- .help = "Virtual disk size"
> > >+static QemuOptsList iscsi_create_options = {
> > >+ .name = "iscsi_create_options",
> > >+ .head = QTAILQ_HEAD_INITIALIZER(iscsi_create_options.head),
> > >+ .desc = {
> > >+ {
> > >+ .name = BLOCK_OPT_SIZE,
> > >+ .type = QEMU_OPT_SIZE,
> > >+ .help = "Virtual disk size"
> > >+ },
> > >+ { NULL }
> > > },
> > >- { NULL }
> > > };
> > > static BlockDriver bdrv_iscsi = {
> > >@@ -1469,7 +1469,7 @@ static BlockDriver bdrv_iscsi = {
> > > .bdrv_file_open = iscsi_open,
> > > .bdrv_close = iscsi_close,
> > > .bdrv_create = iscsi_create,
> > >- .create_options = iscsi_create_options,
> > >+ .create_options = &iscsi_create_options,
> > > .bdrv_reopen_prepare = iscsi_reopen_prepare,
> > > .bdrv_getlength = iscsi_getlength,
> >
> >
> > --
> >
> > Mit freundlichen Grüßen
> >
> > Peter Lieven
> >
> > ...........................................................
> >
> > KAMP Netzwerkdienste GmbH
> > Vestische Str. 89-91 | 46117 Oberhausen
> > Tel: +49 (0) 208.89 402-50 | Fax: +49 (0) 208.89 402-40
> > pl@kamp.de | http://www.kamp.de
> >
> > Geschäftsführer: Heiner Lante | Michael Lante
> > Amtsgericht Duisburg | HRB Nr. 12154
> > USt-Id-Nr.: DE 120607556
> >
> > ...........................................................
> >
> >
>
> --
> Leandro Dorileo
--
Leandro Dorileo
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [Qemu-devel] [PATCH 09/26] iscsi: migrate iscsi driver QemuOptionParameter usage
2014-03-21 13:31 ` Leandro Dorileo
2014-03-21 13:34 ` Leandro Dorileo
@ 2014-03-21 13:42 ` Peter Lieven
2014-03-21 13:54 ` Leandro Dorileo
1 sibling, 1 reply; 34+ messages in thread
From: Peter Lieven @ 2014-03-21 13:42 UTC (permalink / raw)
To: Leandro Dorileo
Cc: Kevin Wolf, Fam Zheng, Ronnie Sahlberg, Richard W.M. Jones,
Stefan Weil, Jeff Cody, qemu-devel, Markus Armbruster,
Paolo Bonzini, Stefan Hajnoczi, Josh Durgin, Anthony Liguori,
Liu Yuan, Luiz Capitulino, Max Reitz, MORITA Kazutaka,
Benoit Canet
On 21.03.2014 14:31, Leandro Dorileo wrote:
> On Fri, Mar 21, 2014 at 07:43:44AM +0100, Peter Lieven wrote:
>> On 21.03.2014 01:13, Leandro Dorileo wrote:
>>> Do the directly migration from QemuOptionParameter to QemuOpts on
>>> iscsi block driver.
>>>
>>> Signed-off-by: Leandro Dorileo <l@dorileo.org>
>>> ---
>>> block/iscsi.c | 32 ++++++++++++++++----------------
>>> 1 file changed, 16 insertions(+), 16 deletions(-)
>>>
>>> diff --git a/block/iscsi.c b/block/iscsi.c
>>> index b490e98..85252e7 100644
>>> --- a/block/iscsi.c
>>> +++ b/block/iscsi.c
>>> @@ -1125,7 +1125,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
>>> QemuOpts *opts;
>>> Error *local_err = NULL;
>>> const char *filename;
>>> - int i, ret;
>>> + int i, ret = 0;
>> why? is there a chance that ret remains uninitialized?
> Yep, my compiler tells me so:
>
> block/iscsi.c:1128:12: error: ‘ret’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
>
>
>>> if ((BDRV_SECTOR_SIZE % 512) != 0) {
>>> error_setg(errp, "iSCSI: Invalid BDRV_SECTOR_SIZE. "
>>> @@ -1382,8 +1382,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t offset)
>>> return 0;
>>> }
>>> -static int iscsi_create(const char *filename, QEMUOptionParameter *options,
>>> - Error **errp)
>>> +static int iscsi_create(const char *filename, QemuOpts *options, Error **errp)
>>> {
>>> int ret = 0;
>>> int64_t total_size = 0;
>>> @@ -1393,12 +1392,9 @@ 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(options, BLOCK_OPT_SIZE, 0);
>>> + if (total_size) {
>>> + total_size = total_size / BDRV_SECTOR_SIZE;
>>> }
>> you don't need the if condition. 0 / BDRV_SECTOR_SIZE = 0.
>>
> I'm not sure, bdrv_img_create() will set BLOCK_OPT_SIZE with img_size, we have no guarantee on the
> value passed to bdrv_img_create(), we don't check img_size value there, having said that can't
> we run on division by zero here? The previous code wasn't checking it but I wonder if the problem
> wasn't there already.
division by zero is x / 0 not 0 / x.
0 / x = 0
x / 0 = undef
Peter
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [Qemu-devel] [PATCH 09/26] iscsi: migrate iscsi driver QemuOptionParameter usage
2014-03-21 13:42 ` Peter Lieven
@ 2014-03-21 13:54 ` Leandro Dorileo
0 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 13:54 UTC (permalink / raw)
To: Peter Lieven
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Stefan Weil, Jeff Cody,
Richard W.M. Jones, qemu-devel, Max Reitz, MORITA Kazutaka,
Ronnie Sahlberg, Josh Durgin, Anthony Liguori, Paolo Bonzini,
Liu Yuan, Luiz Capitulino, Markus Armbruster, Benoit Canet
On Fri, Mar 21, 2014 at 02:42:35PM +0100, Peter Lieven wrote:
> On 21.03.2014 14:31, Leandro Dorileo wrote:
> >On Fri, Mar 21, 2014 at 07:43:44AM +0100, Peter Lieven wrote:
> >>On 21.03.2014 01:13, Leandro Dorileo wrote:
> >>>Do the directly migration from QemuOptionParameter to QemuOpts on
> >>>iscsi block driver.
> >>>
> >>>Signed-off-by: Leandro Dorileo <l@dorileo.org>
> >>>---
> >>> block/iscsi.c | 32 ++++++++++++++++----------------
> >>> 1 file changed, 16 insertions(+), 16 deletions(-)
> >>>
> >>>diff --git a/block/iscsi.c b/block/iscsi.c
> >>>index b490e98..85252e7 100644
> >>>--- a/block/iscsi.c
> >>>+++ b/block/iscsi.c
> >>>@@ -1125,7 +1125,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
> >>> QemuOpts *opts;
> >>> Error *local_err = NULL;
> >>> const char *filename;
> >>>- int i, ret;
> >>>+ int i, ret = 0;
> >>why? is there a chance that ret remains uninitialized?
> >Yep, my compiler tells me so:
> >
> >block/iscsi.c:1128:12: error: ‘ret’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
> >
> >
> >>> if ((BDRV_SECTOR_SIZE % 512) != 0) {
> >>> error_setg(errp, "iSCSI: Invalid BDRV_SECTOR_SIZE. "
> >>>@@ -1382,8 +1382,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t offset)
> >>> return 0;
> >>> }
> >>>-static int iscsi_create(const char *filename, QEMUOptionParameter *options,
> >>>- Error **errp)
> >>>+static int iscsi_create(const char *filename, QemuOpts *options, Error **errp)
> >>> {
> >>> int ret = 0;
> >>> int64_t total_size = 0;
> >>>@@ -1393,12 +1392,9 @@ 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(options, BLOCK_OPT_SIZE, 0);
> >>>+ if (total_size) {
> >>>+ total_size = total_size / BDRV_SECTOR_SIZE;
> >>> }
> >>you don't need the if condition. 0 / BDRV_SECTOR_SIZE = 0.
> >>
> >I'm not sure, bdrv_img_create() will set BLOCK_OPT_SIZE with img_size, we have no guarantee on the
> >value passed to bdrv_img_create(), we don't check img_size value there, having said that can't
> >we run on division by zero here? The previous code wasn't checking it but I wonder if the problem
> >wasn't there already.
>
> division by zero is x / 0 not 0 / x.
>
> 0 / x = 0
> x / 0 = undef
>
Yep, true.
--
Leandro Dorileo
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 10/26] nfs: migrate nfs driver QemuOptionParameter usage
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (8 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 09/26] iscsi: migrate iscsi " Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 11/26] qcow: migrate qcow " Leandro Dorileo
` (15 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Do the directly migration from QemuOptionParameter to QemuOpts on
nfs block driver.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
block/nfs.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/block/nfs.c b/block/nfs.c
index 98aa363..c01f109 100644
--- a/block/nfs.c
+++ b/block/nfs.c
@@ -357,20 +357,13 @@ static int nfs_file_open(BlockDriverState *bs, QDict *options, int flags,
return 0;
}
-static int nfs_file_create(const char *url, QEMUOptionParameter *options,
- Error **errp)
+static int nfs_file_create(const char *url, QemuOpts *options, Error **errp)
{
int ret = 0;
int64_t total_size = 0;
NFSClient *client = g_malloc0(sizeof(NFSClient));
- /* Read out options */
- while (options && options->name) {
- if (!strcmp(options->name, "size")) {
- total_size = options->value.n;
- }
- options++;
- }
+ total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
ret = nfs_client_open(client, url, O_CREAT, errp);
if (ret < 0) {
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 11/26] qcow: migrate qcow driver QemuOptionParameter usage
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (9 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 10/26] nfs: migrate nfs " Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 12/26] qcow2: migrate qcow2 " Leandro Dorileo
` (14 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Do the directly migration from QemuOptionParameter to QemuOpts on
qcow block driver.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
block/qcow.c | 59 +++++++++++++++++++++++++++++------------------------------
1 file changed, 29 insertions(+), 30 deletions(-)
diff --git a/block/qcow.c b/block/qcow.c
index 1e128be..65c7486 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -662,31 +662,26 @@ static void qcow_close(BlockDriverState *bs)
error_free(s->migration_blocker);
}
-static int qcow_create(const char *filename, QEMUOptionParameter *options,
- Error **errp)
+static int qcow_create(const char *filename, QemuOpts *options, Error **errp)
{
int header_size, backing_filename_len, l1_size, shift, i;
QCowHeader header;
uint8_t *tmp;
int64_t total_size = 0;
const char *backing_file = NULL;
- int flags = 0;
+ uint64_t flags = 0;
Error *local_err = NULL;
int ret;
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(options, BLOCK_OPT_SIZE, 0);
+ if (total_size) {
+ total_size = total_size / 512;
}
+ backing_file = qemu_opt_get(options, BLOCK_OPT_BACKING_FILE);
+ flags |= qemu_opt_get_number(options, BLOCK_OPT_ENCRYPT, 0);
+
ret = bdrv_create_file(filename, options, &local_err);
if (ret < 0) {
error_propagate(errp, local_err);
@@ -882,23 +877,27 @@ static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
}
-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"
+static QemuOptsList qcow_create_options = {
+ .name = "qcow_create_options",
+ .head = QTAILQ_HEAD_INITIALIZER(qcow_create_options.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_NUMBER,
+ .help = "Encrypt the image"
+ },
+ { NULL }
},
- { NULL }
};
static BlockDriver bdrv_qcow = {
@@ -920,7 +919,7 @@ static BlockDriver bdrv_qcow = {
.bdrv_write_compressed = qcow_write_compressed,
.bdrv_get_info = qcow_get_info,
- .create_options = qcow_create_options,
+ .create_options = &qcow_create_options,
};
static void bdrv_qcow_init(void)
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 12/26] qcow2: migrate qcow2 driver QemuOptionParameter usage
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (10 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 11/26] qcow: migrate qcow " Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 13/26] qed: migrate qed " Leandro Dorileo
` (13 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Do the directly migration from QemuOptionParameter to QemuOpts on
qcow2 block driver.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
block/qcow2.c | 263 ++++++++++++++++++++++++++++------------------------------
1 file changed, 128 insertions(+), 135 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index b9dc960..a69438f 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1472,7 +1472,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 *options, int version,
Error **errp)
{
/* Calculate cluster_bits */
@@ -1639,9 +1639,10 @@ out:
return ret;
}
-static int qcow2_create(const char *filename, QEMUOptionParameter *options,
- Error **errp)
+static int qcow2_create(const char *filename, QemuOpts *options, Error **errp)
{
+ const char *compat_level_opt = NULL;
+ const char *prealloc_opt = NULL;
const char *backing_file = NULL;
const char *backing_fmt = NULL;
uint64_t sectors = 0;
@@ -1652,46 +1653,47 @@ static int qcow2_create(const char *filename, QEMUOptionParameter *options,
Error *local_err = NULL;
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;
+ sectors = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+ if (sectors) {
+ sectors = sectors / 512;
+ }
+
+ backing_file = qemu_opt_get(options, BLOCK_OPT_BACKING_FILE);
+ backing_fmt = qemu_opt_get(options, BLOCK_OPT_BACKING_FMT);
+
+ if (qemu_opt_get_bool(options, BLOCK_OPT_ENCRYPT, false)) {
+ flags |= BLOCK_FLAG_ENCRYPT;
+ }
+
+ cluster_size = qemu_opt_get_size(options, BLOCK_OPT_CLUSTER_SIZE, 0);
+
+ prealloc_opt = qemu_opt_get(options, BLOCK_OPT_PREALLOC);
+ if (prealloc_opt) {
+ if (!strcmp(prealloc_opt, "off")) {
+ prealloc = 0;
+ } else if (!strcmp(prealloc_opt, "metadata")) {
+ prealloc = 1;
+ } else {
+ error_setg(errp, "Invalid preallocation mode: '%s'", prealloc_opt);
+ return -EINVAL;
+ }
+ }
+
+ compat_level_opt = qemu_opt_get(options, BLOCK_OPT_COMPAT_LEVEL);
+ if (compat_level_opt) {
+ if (!strcmp(compat_level_opt, "0.10")) {
+ version = 2;
+ } else if (!strcmp(compat_level_opt, "1.1")) {
+ version = 3;
+ } else {
+ error_setg(errp, "Invalid compatibility level: '%s'",
+ compat_level_opt);
+ return -EINVAL;
}
- options++;
+ }
+
+ if (qemu_opt_get_bool(options, BLOCK_OPT_LAZY_REFCOUNTS, false)) {
+ flags |= BLOCK_FLAG_LAZY_REFCOUNTS;
}
if (backing_file && prealloc) {
@@ -2075,66 +2077,53 @@ static int qcow2_downgrade(BlockDriverState *bs, int target_version)
return 0;
}
-static int qcow2_amend_options(BlockDriverState *bs,
- QEMUOptionParameter *options)
+static int qcow2_amend_options(BlockDriverState *bs, QemuOpts *options)
{
BDRVQcowState *s = bs->opaque;
int old_version = s->qcow_version, new_version = old_version;
- uint64_t new_size = 0;
+ uint64_t cluster_size, new_size = 0;
const char *backing_file = NULL, *backing_format = NULL;
- bool lazy_refcounts = s->use_lazy_refcounts;
+ const char *compat_level_opt = NULL;
+ bool crypt_opt, lazy_refcounts;
int ret;
- int i;
- for (i = 0; options[i].name; i++)
- {
- if (!options[i].assigned) {
- /* only change explicitly defined options */
- continue;
- }
-
- 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;
+ compat_level_opt = qemu_opt_get(options, BLOCK_OPT_COMPAT_LEVEL);
+ if (compat_level_opt) {
+ if (!strcmp(compat_level_opt, "0.10")) {
+ new_version = 2;
+ } else if (!strcmp(compat_level_opt, "1.1")) {
+ new_version = 3;
} else {
- /* if this assertion fails, this probably means a new option was
- * added without having it covered here */
- assert(false);
+ fprintf(stderr, "Invalid compatibility level: '%s'",
+ compat_level_opt);
+ return -EINVAL;
}
}
+ if (qemu_opt_get_bool(options, BLOCK_OPT_PREALLOC, false)) {
+ fprintf(stderr, "Cannot change preallocation mode.\n");
+ return -ENOTSUP;
+ }
+
+ new_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+ backing_file = qemu_opt_get(options, BLOCK_OPT_BACKING_FILE);
+ backing_format = qemu_opt_get(options, BLOCK_OPT_BACKING_FMT);
+
+ crypt_opt = qemu_opt_get_bool(options, BLOCK_OPT_ENCRYPT, false);
+ if (crypt_opt != !!s->crypt_method) {
+ fprintf(stderr, "Changing the encryption flag is not supported.\n");
+ return -ENOTSUP;
+ }
+
+ cluster_size = qemu_opt_get_size(options, BLOCK_OPT_CLUSTER_SIZE, 0);
+ if (cluster_size != s->cluster_size) {
+ fprintf(stderr, "Changing the cluster size is not supported.\n");
+ return -ENOTSUP;
+ }
+
+ lazy_refcounts = qemu_opt_get_bool(options, BLOCK_OPT_LAZY_REFCOUNTS,
+ s->use_lazy_refcounts);
+
if (new_version != old_version) {
if (new_version > old_version) {
/* Upgrade */
@@ -2201,49 +2190,53 @@ 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",
+static QemuOptsList qcow2_create_options = {
+ .name = "qcow2_create_options",
+ .head = QTAILQ_HEAD_INITIALIZER(qcow2_create_options.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"
+ },
+ {
+ .name = BLOCK_OPT_CLUSTER_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "qcow2 cluster size",
+ .def_val = QEMU_OPT_VAL_SIZE(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",
+ },
+ { NULL }
},
- { NULL }
};
static BlockDriver bdrv_qcow2 = {
@@ -2283,7 +2276,7 @@ static BlockDriver bdrv_qcow2 = {
.bdrv_refresh_limits = qcow2_refresh_limits,
.bdrv_invalidate_cache = qcow2_invalidate_cache,
- .create_options = qcow2_create_options,
+ .create_options = &qcow2_create_options,
.bdrv_check = qcow2_check,
.bdrv_amend_options = qcow2_amend_options,
};
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 13/26] qed: migrate qed driver QemuOptionParameter usage
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (11 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 12/26] qcow2: migrate qcow2 " Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 14/26] raw-posix: migrate raw-posix " Leandro Dorileo
` (12 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Do the directly migration from QemuOptionParameter to QemuOpts on
qed block driver.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
block/qed.c | 79 +++++++++++++++++++++++++++----------------------------------
1 file changed, 35 insertions(+), 44 deletions(-)
diff --git a/block/qed.c b/block/qed.c
index 3bd9db9..c082ba3 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -621,7 +621,7 @@ out:
return ret;
}
-static int bdrv_qed_create(const char *filename, QEMUOptionParameter *options,
+static int bdrv_qed_create(const char *filename, QemuOpts *options,
Error **errp)
{
uint64_t image_size = 0;
@@ -630,24 +630,11 @@ 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(options, BLOCK_OPT_SIZE, 0);
+ backing_file = qemu_opt_get(options, BLOCK_OPT_BACKING_FILE);
+ backing_fmt = qemu_opt_get(options, BLOCK_OPT_BACKING_FMT);
+ cluster_size = qemu_opt_get_size(options, BLOCK_OPT_CLUSTER_SIZE, 0);
+ table_size = qemu_opt_get_size(options, BLOCK_OPT_TABLE_SIZE, 0);
if (!qed_is_cluster_size_valid(cluster_size)) {
fprintf(stderr, "QED cluster size must be within range [%u, %u] and power of 2\n",
@@ -1593,36 +1580,40 @@ 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_options = {
+ .name = "qed_create_options",
+ .head = QTAILQ_HEAD_INITIALIZER(qed_create_options.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size (in bytes)"
+ }, {
+ .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_val = QEMU_OPT_VAL_SIZE(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_options = &qed_create_options,
.bdrv_probe = bdrv_qed_probe,
.bdrv_rebind = bdrv_qed_rebind,
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 14/26] raw-posix: migrate raw-posix driver QemuOptionParameter usage
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (12 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 13/26] qed: migrate qed " Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 15/26] raw-win32: migrate cow " Leandro Dorileo
` (11 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Do the directly migration from QemuOptionParameter to QemuOpts on
raw-posix block driver.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
block/raw-posix.c | 50 +++++++++++++++++++++++---------------------------
1 file changed, 23 insertions(+), 27 deletions(-)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 1688e16..ddeafa7 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1234,8 +1234,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,
- Error **errp)
+static int raw_create(const char *filename, QemuOpts *options, Error **errp)
{
int fd;
int result = 0;
@@ -1243,12 +1242,9 @@ static int raw_create(const char *filename, QEMUOptionParameter *options,
strstart(filename, "file:", &filename);
- /* 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(options, BLOCK_OPT_SIZE, 0);
+ if (total_size) {
+ total_size = total_size / BDRV_SECTOR_SIZE;
}
fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
@@ -1410,13 +1406,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"
+static QemuOptsList raw_create_options = {
+ .name = "raw_create_options",
+ .head = QTAILQ_HEAD_INITIALIZER(raw_create_options.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size"
+ },
+ { NULL }
},
- { NULL }
};
static BlockDriver bdrv_file = {
@@ -1448,7 +1448,7 @@ static BlockDriver bdrv_file = {
.bdrv_get_allocated_file_size
= raw_get_allocated_file_size,
- .create_options = raw_create_options,
+ .create_options = &raw_create_options,
};
/***********************************************/
@@ -1769,8 +1769,7 @@ static coroutine_fn int hdev_co_write_zeroes(BlockDriverState *bs,
return -ENOTSUP;
}
-static int hdev_create(const char *filename, QEMUOptionParameter *options,
- Error **errp)
+static int hdev_create(const char *filename, QemuOpts *options, Error **errp)
{
int fd;
int ret = 0;
@@ -1789,12 +1788,9 @@ static int hdev_create(const char *filename, QEMUOptionParameter *options,
(void)has_prefix;
- /* 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(options, BLOCK_OPT_SIZE, 0);
+ if (total_size) {
+ total_size = total_size / BDRV_SECTOR_SIZE;
}
fd = qemu_open(filename, O_WRONLY | O_BINARY);
@@ -1833,7 +1829,7 @@ static BlockDriver bdrv_host_device = {
.bdrv_reopen_commit = raw_reopen_commit,
.bdrv_reopen_abort = raw_reopen_abort,
.bdrv_create = hdev_create,
- .create_options = raw_create_options,
+ .create_options = &raw_create_options,
.bdrv_co_write_zeroes = hdev_co_write_zeroes,
.bdrv_aio_readv = raw_aio_readv,
@@ -1977,7 +1973,7 @@ static BlockDriver bdrv_host_floppy = {
.bdrv_reopen_commit = raw_reopen_commit,
.bdrv_reopen_abort = raw_reopen_abort,
.bdrv_create = hdev_create,
- .create_options = raw_create_options,
+ .create_options = &raw_create_options,
.bdrv_aio_readv = raw_aio_readv,
.bdrv_aio_writev = raw_aio_writev,
@@ -2102,7 +2098,7 @@ static BlockDriver bdrv_host_cdrom = {
.bdrv_reopen_commit = raw_reopen_commit,
.bdrv_reopen_abort = raw_reopen_abort,
.bdrv_create = hdev_create,
- .create_options = raw_create_options,
+ .create_options = &raw_create_options,
.bdrv_aio_readv = raw_aio_readv,
.bdrv_aio_writev = raw_aio_writev,
@@ -2233,7 +2229,7 @@ static BlockDriver bdrv_host_cdrom = {
.bdrv_reopen_commit = raw_reopen_commit,
.bdrv_reopen_abort = raw_reopen_abort,
.bdrv_create = hdev_create,
- .create_options = raw_create_options,
+ .create_options = &raw_create_options,
.bdrv_aio_readv = raw_aio_readv,
.bdrv_aio_writev = raw_aio_writev,
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 15/26] raw-win32: migrate cow driver QemuOptionParameter usage
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (13 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 14/26] raw-posix: migrate raw-posix " Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 16/26] raw_bsd: migrate raw_bsd " Leandro Dorileo
` (10 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Do the directly migration from QemuOptionParameter to QemuOpts on
raw-win32 block driver.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
block/raw-win32.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/block/raw-win32.c b/block/raw-win32.c
index 48cb2c2..4cca514 100644
--- a/block/raw-win32.c
+++ b/block/raw-win32.c
@@ -475,21 +475,14 @@ static int64_t raw_get_allocated_file_size(BlockDriverState *bs)
return st.st_size;
}
-static int raw_create(const char *filename, QEMUOptionParameter *options,
- Error **errp)
+static int raw_create(const char *filename, QemuOpts *options, Error **errp)
{
int fd;
int64_t total_size = 0;
strstart(filename, "file:", &filename);
- /* 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(options, BLOCK_OPT_SIZE, 0);
fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
0644);
@@ -503,13 +496,17 @@ 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"
+static QemuOptsList raw_create_options = {
+ .name = "raw_create_options",
+ .head = QTAILQ_HEAD_INITIALIZER(raw_create_options.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size"
+ },
+ { NULL }
},
- { NULL }
};
static BlockDriver bdrv_file = {
@@ -532,7 +529,7 @@ static BlockDriver bdrv_file = {
.bdrv_get_allocated_file_size
= raw_get_allocated_file_size,
- .create_options = raw_create_options,
+ .create_options = &raw_create_options,
};
/***********************************************/
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 16/26] raw_bsd: migrate raw_bsd driver QemuOptionParameter usage
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (14 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 15/26] raw-win32: migrate cow " Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 17/26] rbd: migrate rbd " Leandro Dorileo
` (9 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Do the directly migration from QemuOptionParameter to QemuOpts on
raw_bsd block driver.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
block/raw_bsd.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index 01ea692..5090b4e 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"
+static QemuOptsList raw_create_options = {
+ .name = "raw_create_options",
+ .head = QTAILQ_HEAD_INITIALIZER(raw_create_options.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size"
+ },
+ { 0 }
},
- { 0 }
};
static int raw_reopen_prepare(BDRVReopenState *reopen_state,
@@ -139,8 +143,7 @@ static int raw_has_zero_init(BlockDriverState *bs)
return bdrv_has_zero_init(bs->file);
}
-static int raw_create(const char *filename, QEMUOptionParameter *options,
- Error **errp)
+static int raw_create(const char *filename, QemuOpts *options, Error **errp)
{
Error *local_err = NULL;
int ret;
@@ -194,7 +197,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_options = &raw_create_options,
.bdrv_has_zero_init = &raw_has_zero_init
};
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 17/26] rbd: migrate rbd driver QemuOptionParameter usage
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (15 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 16/26] raw_bsd: migrate raw_bsd " Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 18/26] sheepdog: migrate sheepdog " Leandro Dorileo
` (8 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Do the directly migration from QemuOptionParameter to QemuOpts on
rbd block driver.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
block/rbd.c | 60 +++++++++++++++++++++++++++++-------------------------------
1 file changed, 29 insertions(+), 31 deletions(-)
diff --git a/block/rbd.c b/block/rbd.c
index dbc79f4..ae8c471 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -282,7 +282,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 *options,
Error **errp)
{
int64_t bytes = 0;
@@ -305,25 +305,19 @@ static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options,
return -EINVAL;
}
- /* 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(options, BLOCK_OPT_SIZE, 0);
+ objsize = qemu_opt_get_size(options, BLOCK_OPT_CLUSTER_SIZE, 0);
+
+ if (objsize != 0) {
+ 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);
@@ -900,18 +894,22 @@ 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"
+static QemuOptsList qemu_rbd_create_options = {
+ .name = "qemu_rbd_create_options",
+ .head = QTAILQ_HEAD_INITIALIZER(qemu_rbd_create_options.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"
+ },
+ {NULL}
},
- {NULL}
};
static BlockDriver bdrv_rbd = {
@@ -923,7 +921,7 @@ static BlockDriver bdrv_rbd = {
.bdrv_create = 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_options = &qemu_rbd_create_options,
.bdrv_getlength = qemu_rbd_getlength,
.bdrv_truncate = qemu_rbd_truncate,
.protocol_name = "rbd",
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 18/26] sheepdog: migrate sheepdog driver QemuOptionParameter usage
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (16 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 17/26] rbd: migrate rbd " Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 19/26] ssh: migrate ssh " Leandro Dorileo
` (7 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Do the directly migration from QemuOptionParameter to QemuOpts on
sheepdog block driver.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
block/sheepdog.c | 104 ++++++++++++++++++++++++++++---------------------------
1 file changed, 53 insertions(+), 51 deletions(-)
diff --git a/block/sheepdog.c b/block/sheepdog.c
index f7bd024..4f4945f 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1626,17 +1626,18 @@ static int parse_redundancy(BDRVSheepdogState *s, const char *opt)
return 0;
}
-static int sd_create(const char *filename, QEMUOptionParameter *options,
- Error **errp)
+static int sd_create(const char *filename, QemuOpts *options, Error **errp)
{
int ret = 0;
uint32_t vid = 0;
- char *backing_file = NULL;
+ const char *backing_file = NULL;
BDRVSheepdogState *s;
char tag[SD_MAX_VDI_TAG_LEN];
uint32_t snapid;
bool prealloc = false;
Error *local_err = NULL;
+ const char *prealloc_opt;
+ char *redundancy_opt;
s = g_malloc0(sizeof(BDRVSheepdogState));
@@ -1650,31 +1651,28 @@ 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(options, BLOCK_OPT_SIZE, 0);
+ backing_file = qemu_opt_get(options, BLOCK_OPT_BACKING_FILE);
+
+ prealloc_opt = qemu_opt_get(options, BLOCK_OPT_PREALLOC);
+ if (prealloc_opt) {
+ if (!strcmp(prealloc_opt, "off")) {
+ prealloc = false;
+ } else if (!strcmp(prealloc_opt, "full")) {
+ prealloc = true;
+ } else {
+ error_report("Invalid preallocation mode: '%s'", prealloc_opt);
+ ret = -EINVAL;
+ goto out;
+ }
+ }
+
+ redundancy_opt = (char *)qemu_opt_get(options, BLOCK_OPT_REDUNDANCY);
+ if (redundancy_opt) {
+ ret = parse_redundancy(s, redundancy_opt);
+ if (ret < 0) {
+ goto out;
}
- options++;
}
if (s->inode.vdi_size > SD_MAX_VDI_SIZE) {
@@ -2490,28 +2488,32 @@ 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"
+static QemuOptsList sd_create_options = {
+ .name = "sd_create_options",
+ .head = QTAILQ_HEAD_INITIALIZER(sd_create_options.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)"
+ },
+ {
+ .name = BLOCK_OPT_REDUNDANCY,
+ .type = QEMU_OPT_STRING,
+ .help = "Redundancy of the image"
+ },
+ { NULL }
},
- { NULL }
};
static BlockDriver bdrv_sheepdog = {
@@ -2541,7 +2543,7 @@ static BlockDriver bdrv_sheepdog = {
.bdrv_save_vmstate = sd_save_vmstate,
.bdrv_load_vmstate = sd_load_vmstate,
- .create_options = sd_create_options,
+ .create_options = &sd_create_options,
};
static BlockDriver bdrv_sheepdog_tcp = {
@@ -2571,7 +2573,7 @@ static BlockDriver bdrv_sheepdog_tcp = {
.bdrv_save_vmstate = sd_save_vmstate,
.bdrv_load_vmstate = sd_load_vmstate,
- .create_options = sd_create_options,
+ .create_options = &sd_create_options,
};
static BlockDriver bdrv_sheepdog_unix = {
@@ -2601,7 +2603,7 @@ static BlockDriver bdrv_sheepdog_unix = {
.bdrv_save_vmstate = sd_save_vmstate,
.bdrv_load_vmstate = sd_load_vmstate,
- .create_options = sd_create_options,
+ .create_options = &sd_create_options,
};
static void bdrv_sheepdog_init(void)
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 19/26] ssh: migrate ssh driver QemuOptionParameter usage
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (17 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 18/26] sheepdog: migrate sheepdog " Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 8:32 ` Richard W.M. Jones
2014-03-21 0:13 ` [Qemu-devel] [PATCH 20/26] vdi: migrate vdi " Leandro Dorileo
` (6 subsequent siblings)
25 siblings, 1 reply; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Do the directly migration from QemuOptionParameter to QemuOpts on
ssh block driver.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
block/ssh.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/block/ssh.c b/block/ssh.c
index aa63c9d..b55c518 100644
--- a/block/ssh.c
+++ b/block/ssh.c
@@ -642,17 +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"
+static QemuOptsList ssh_create_options = {
+ .name = "ssh_create_options",
+ .head = QTAILQ_HEAD_INITIALIZER(ssh_create_options.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size"
+ },
+ { NULL }
},
- { NULL }
};
-static int ssh_create(const char *filename, QEMUOptionParameter *options,
- Error **errp)
+static int ssh_create(const char *filename, QemuOpts *options, Error **errp)
{
int r, ret;
Error *local_err = NULL;
@@ -664,13 +667,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(options, BLOCK_OPT_SIZE, 0);
DPRINTF("total_size=%" PRIi64, total_size);
uri_options = qdict_new();
@@ -1051,7 +1048,7 @@ static BlockDriver bdrv_ssh = {
.bdrv_co_writev = ssh_co_writev,
.bdrv_getlength = ssh_getlength,
.bdrv_co_flush_to_disk = ssh_co_flush,
- .create_options = ssh_create_options,
+ .create_options = &ssh_create_options,
};
static void bdrv_ssh_init(void)
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* Re: [Qemu-devel] [PATCH 19/26] ssh: migrate ssh driver QemuOptionParameter usage
2014-03-21 0:13 ` [Qemu-devel] [PATCH 19/26] ssh: migrate ssh " Leandro Dorileo
@ 2014-03-21 8:32 ` Richard W.M. Jones
0 siblings, 0 replies; 34+ messages in thread
From: Richard W.M. Jones @ 2014-03-21 8:32 UTC (permalink / raw)
To: Leandro Dorileo
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, qemu-devel, Luiz Capitulino,
Ronnie Sahlberg, Josh Durgin, Anthony Liguori, Paolo Bonzini,
Stefan Weil, Max Reitz, MORITA Kazutaka, Benoit Canet
On Thu, Mar 20, 2014 at 09:13:26PM -0300, Leandro Dorileo wrote:
> Do the directly migration from QemuOptionParameter to QemuOpts on
> ssh block driver.
>
> Signed-off-by: Leandro Dorileo <l@dorileo.org>
> ---
> block/ssh.c | 29 +++++++++++++----------------
> 1 file changed, 13 insertions(+), 16 deletions(-)
>
> diff --git a/block/ssh.c b/block/ssh.c
> index aa63c9d..b55c518 100644
> --- a/block/ssh.c
> +++ b/block/ssh.c
> @@ -642,17 +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"
> +static QemuOptsList ssh_create_options = {
> + .name = "ssh_create_options",
> + .head = QTAILQ_HEAD_INITIALIZER(ssh_create_options.head),
> + .desc = {
> + {
> + .name = BLOCK_OPT_SIZE,
> + .type = QEMU_OPT_SIZE,
> + .help = "Virtual disk size"
> + },
> + { NULL }
> },
> - { NULL }
> };
>
> -static int ssh_create(const char *filename, QEMUOptionParameter *options,
> - Error **errp)
> +static int ssh_create(const char *filename, QemuOpts *options, Error **errp)
> {
> int r, ret;
> Error *local_err = NULL;
> @@ -664,13 +667,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(options, BLOCK_OPT_SIZE, 0);
> DPRINTF("total_size=%" PRIi64, total_size);
>
> uri_options = qdict_new();
> @@ -1051,7 +1048,7 @@ static BlockDriver bdrv_ssh = {
> .bdrv_co_writev = ssh_co_writev,
> .bdrv_getlength = ssh_getlength,
> .bdrv_co_flush_to_disk = ssh_co_flush,
> - .create_options = ssh_create_options,
> + .create_options = &ssh_create_options,
> };
>
> static void bdrv_ssh_init(void)
> --
> 1.9.0
Looks good to me, ACK.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 20/26] vdi: migrate vdi driver QemuOptionParameter usage
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (18 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 19/26] ssh: migrate ssh " Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 21/26] vhdx: migrate vhdx " Leandro Dorileo
` (5 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Do the directly migration from QemuOptionParameter to QemuOpts on
vdi block driver.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
block/vdi.c | 73 ++++++++++++++++++++++++++++---------------------------------
1 file changed, 34 insertions(+), 39 deletions(-)
diff --git a/block/vdi.c b/block/vdi.c
index ae49cd8..4f8a143 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -653,8 +653,7 @@ static int vdi_co_write(BlockDriverState *bs,
return ret;
}
-static int vdi_create(const char *filename, QEMUOptionParameter *options,
- Error **errp)
+static int vdi_create(const char *filename, QemuOpts *options, Error **errp)
{
int fd;
int result = 0;
@@ -662,31 +661,23 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options,
uint32_t blocks;
size_t block_size = DEFAULT_CLUSTER_SIZE;
uint32_t image_type = VDI_TYPE_DYNAMIC;
+ bool stat;
VdiHeader header;
size_t i;
size_t bmap_size;
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(options, 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;
- }
-#endif
-#if defined(CONFIG_VDI_STATIC_IMAGE)
- } else if (!strcmp(options->name, BLOCK_OPT_STATIC)) {
- if (options->value.n) {
- image_type = VDI_TYPE_STATIC;
- }
+ /* TODO: Additional checks (SECTOR_SIZE * 2^n, ...). */
+ block_size = qemu_opt_get_size(options, BLOCK_OPT_CLUSTER_SIZE, 0);
#endif
- }
- options++;
+
+ stat = qemu_opt_get_bool(options, BLOCK_OPT_STATIC, false);
+ if (stat) {
+ image_type = VDI_TYPE_STATIC;
}
fd = qemu_open(filename,
@@ -767,29 +758,33 @@ 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_options = {
+ .name = "vdi_create_options",
+ .head = QTAILQ_HEAD_INITIALIZER(vdi_create_options.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_val = QEMU_OPT_VAL_SIZE(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"
+ },
#endif
- /* TODO: An additional option to set UUID values might be useful. */
- { NULL }
+ /* TODO: An additional option to set UUID values might be useful. */
+ { NULL }
+ },
};
static BlockDriver bdrv_vdi = {
@@ -811,7 +806,7 @@ static BlockDriver bdrv_vdi = {
.bdrv_get_info = vdi_get_info,
- .create_options = vdi_create_options,
+ .create_options = &vdi_create_options,
.bdrv_check = vdi_check,
};
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 21/26] vhdx: migrate vhdx driver QemuOptionParameter usage
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (19 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 20/26] vdi: migrate vdi " Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 22/26] vmdk: migrate vmdk " Leandro Dorileo
` (4 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Do the directly migration from QemuOptionParameter to QemuOpts on
vhdx block driver.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
block/vhdx.c | 88 ++++++++++++++++++++++++++++--------------------------------
1 file changed, 41 insertions(+), 47 deletions(-)
diff --git a/block/vhdx.c b/block/vhdx.c
index 5390ba6..106ea7a 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -1708,8 +1708,7 @@ exit:
* .---- ~ ----------- ~ ------------ ~ ---------------- ~ -----------.
* 1MB
*/
-static int vhdx_create(const char *filename, QEMUOptionParameter *options,
- Error **errp)
+static int vhdx_create(const char *filename, QemuOpts *options, Error **errp)
{
int ret = 0;
uint64_t image_size = (uint64_t) 2 * GiB;
@@ -1726,20 +1725,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(options, BLOCK_OPT_SIZE, 0);
+ log_size = qemu_opt_get_size(options, VHDX_BLOCK_OPT_LOG_SIZE, 0);
+ block_size = qemu_opt_get_size(options, VHDX_BLOCK_OPT_BLOCK_SIZE, 0);
+ type = qemu_opt_get(options, BLOCK_OPT_SUBFMT);
+ use_zero_blocks = qemu_opt_get_bool(options, VHDX_BLOCK_OPT_ZERO, false);
if (image_size > VHDX_MAX_IMAGE_SIZE) {
error_setg_errno(errp, EINVAL, "Image size too large; max of 64TB");
@@ -1870,37 +1860,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."
+static QemuOptsList vhdx_create_options = {
+ .name = "vhdx_create_options",
+ .head = QTAILQ_HEAD_INITIALIZER(vhdx_create_options.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_val = QEMU_OPT_VAL_SIZE(1 * MiB),
+ .help = "Log size; min 1MB."
+ },
+ {
+ .name = VHDX_BLOCK_OPT_BLOCK_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .def_val = QEMU_OPT_VAL_SIZE(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 }
},
- { NULL }
};
static BlockDriver bdrv_vhdx = {
@@ -1916,7 +1910,7 @@ static BlockDriver bdrv_vhdx = {
.bdrv_get_info = vhdx_get_info,
.bdrv_check = vhdx_check,
- .create_options = vhdx_create_options,
+ .create_options = &vhdx_create_options,
};
static void bdrv_vhdx_init(void)
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 22/26] vmdk: migrate vmdk driver QemuOptionParameter usage
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (20 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 21/26] vhdx: migrate vhdx " Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 23/26] vpc: migrate vpc " Leandro Dorileo
` (3 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Do the directly migration from QemuOptionParameter to QemuOpts on
vmdk block driver.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
block/vmdk.c | 105 ++++++++++++++++++++++++++++++-----------------------------
1 file changed, 53 insertions(+), 52 deletions(-)
diff --git a/block/vmdk.c b/block/vmdk.c
index b69988d..1974c30 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1681,8 +1681,7 @@ static int filename_decompose(const char *filename, char *path, char *prefix,
return VMDK_OK;
}
-static int vmdk_create(const char *filename, QEMUOptionParameter *options,
- Error **errp)
+static int vmdk_create(const char *filename, QemuOpts *options, Error **errp)
{
int idx = 0;
BlockDriverState *new_bs = NULL;
@@ -1704,6 +1703,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
uint32_t number_heads = 16;
bool zeroed_grain = false;
uint32_t desc_offset = 0, desc_len;
+ bool compat6;
const char desc_template[] =
"# Disk DescriptorFile\n"
"version=1\n"
@@ -1730,23 +1730,19 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
ret = -EINVAL;
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(options, BLOCK_OPT_SIZE, 0);
+ adapter_type = qemu_opt_get(options, BLOCK_OPT_ADAPTER_TYPE);
+ backing_file = qemu_opt_get(options, BLOCK_OPT_BACKING_FILE);
+
+ compat6 = qemu_opt_get_bool(options, BLOCK_OPT_COMPAT6, false);
+ if (compat6) {
+ flags |= BLOCK_FLAG_COMPAT6;
}
+
+ fmt = qemu_opt_get(options, BLOCK_OPT_SUBFMT);
+ zeroed_grain = qemu_opt_get_bool(options, BLOCK_OPT_ZEROED_GRAIN, false);
+
if (!adapter_type) {
adapter_type = "ide";
} else if (strcmp(adapter_type, "ide") &&
@@ -2062,41 +2058,46 @@ 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 =
+static QemuOptsList vmdk_create_options = {
+ .name = "vmdk_create_options",
+ .head = QTAILQ_HEAD_INITIALIZER(vmdk_create_options.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"
+ },
+ {
+ .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 = OPT_FLAG,
- .help = "Enable efficient zero writes using the zeroed-grain GTE feature"
- },
- { NULL }
+ },
+ {
+ .name = BLOCK_OPT_ZEROED_GRAIN,
+ .type = QEMU_OPT_BOOL,
+ .help = "Enable efficient zero writes using the zeroed-grain "
+ "GTE feature"
+ },
+ { NULL }
+ }
};
static BlockDriver bdrv_vmdk = {
@@ -2118,7 +2119,7 @@ static BlockDriver bdrv_vmdk = {
.bdrv_get_specific_info = vmdk_get_specific_info,
.bdrv_refresh_limits = vmdk_refresh_limits,
- .create_options = vmdk_create_options,
+ .create_options = &vmdk_create_options,
};
static void bdrv_vmdk_init(void)
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 23/26] vpc: migrate vpc driver QemuOptionParameter usage
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (21 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 22/26] vmdk: migrate vmdk " Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 24/26] vvfat: migrate vvfat " Leandro Dorileo
` (2 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Do the directly migration from QemuOptionParameter to QemuOpts on
vpc block driver.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
block/vpc.c | 54 +++++++++++++++++++++++++++---------------------------
1 file changed, 27 insertions(+), 27 deletions(-)
diff --git a/block/vpc.c b/block/vpc.c
index 82bf248..421b820 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -714,12 +714,11 @@ 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,
- Error **errp)
+static int vpc_create(const char *filename, QemuOpts *options, 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,20 +728,17 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options,
int disk_type;
int ret = -EIO;
- /* Read out options */
- total_size = get_option_parameter(options, BLOCK_OPT_SIZE)->value.n;
+ total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+ disk_type_param = qemu_opt_get(options, BLOCK_OPT_SUBFMT);
- 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")) {
- disk_type = VHD_DYNAMIC;
- } else if (!strcmp(disk_type_param->value.s, "fixed")) {
- disk_type = VHD_FIXED;
- } else {
- return -EINVAL;
- }
- } else {
+ if (!disk_type_param) {
disk_type = VHD_DYNAMIC;
+ } else if (!strcmp(disk_type_param, "dynamic")) {
+ disk_type = VHD_DYNAMIC;
+ } else if (!strcmp(disk_type_param, "fixed")) {
+ disk_type = VHD_FIXED;
+ } else {
+ return -EINVAL;
}
/* Create the file */
@@ -842,20 +838,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 =
+static QemuOptsList vpc_create_options = {
+ .name = "vpc_create_options",
+ .head = QTAILQ_HEAD_INITIALIZER(vpc_create_options.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} "
+ },
+ { NULL }
},
- { NULL }
};
static BlockDriver bdrv_vpc = {
@@ -873,7 +873,7 @@ static BlockDriver bdrv_vpc = {
.bdrv_get_info = vpc_get_info,
- .create_options = vpc_create_options,
+ .create_options = &vpc_create_options,
.bdrv_has_zero_init = vpc_has_zero_init,
};
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 24/26] vvfat: migrate vvfat driver QemuOptionParameter usage
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (22 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 23/26] vpc: migrate vpc " Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 25/26] QemuOpt: get rid of QEMUOptionParameter Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 26/26] qemu-img: migrate QemuOptionParameter usage Leandro Dorileo
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Do the directly migration from QemuOptionParameter to QemuOpts on
vvfat block driver.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
block/vvfat.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/block/vvfat.c b/block/vvfat.c
index f966ea5..7aefba3 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2907,7 +2907,7 @@ static BlockDriver vvfat_write_target = {
static int enable_write_target(BDRVVVFATState *s)
{
BlockDriver *bdrv_qcow;
- QEMUOptionParameter *options;
+ QemuOpts *options;
Error *local_err = NULL;
int ret;
int size = sector2cluster(s, s->sector_count);
@@ -2918,13 +2918,26 @@ static int enable_write_target(BDRVVVFATState *s)
s->qcow_filename = g_malloc(1024);
ret = get_tmp_filename(s->qcow_filename, 1024);
if (ret < 0) {
- goto err;
+ goto err_opt;
}
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:");
+
+ options = qemu_opts_create(bdrv_qcow->create_options, NULL, 0,
+ &error_abort);
+ if (!options) {
+ goto err_opt;
+ }
+
+ ret = qemu_opt_set_number(options, BLOCK_OPT_SIZE, s->sector_count * 512);
+ if (ret < 0) {
+ goto err;
+ }
+
+ ret = qemu_opt_set(options, BLOCK_OPT_BACKING_FILE, "fat:");
+ if (ret < 0) {
+ goto err;
+ }
ret = bdrv_create(bdrv_qcow, s->qcow_filename, options, &local_err);
if (ret < 0) {
@@ -2951,10 +2964,13 @@ static int enable_write_target(BDRVVVFATState *s)
s->bs->backing_hd->drv = &vvfat_write_target;
s->bs->backing_hd->opaque = g_malloc(sizeof(void*));
*(void**)s->bs->backing_hd->opaque = s;
+ qemu_opts_del(options);
return 0;
err:
+ qemu_opts_del(options);
+err_opt:
g_free(s->qcow_filename);
s->qcow_filename = NULL;
return ret;
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 25/26] QemuOpt: get rid of QEMUOptionParameter
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (23 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 24/26] vvfat: migrate vvfat " Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
2014-03-21 0:13 ` [Qemu-devel] [PATCH 26/26] qemu-img: migrate QemuOptionParameter usage Leandro Dorileo
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Finally remove all the remaining QEMUOptionParameter bits.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
include/qemu/option.h | 40 -------
util/qemu-option.c | 296 --------------------------------------------------
2 files changed, 336 deletions(-)
diff --git a/include/qemu/option.h b/include/qemu/option.h
index 62eacf3..4a7c148 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -31,24 +31,6 @@
#include "qapi/error.h"
#include "qapi/qmp/qdict.h"
-enum QEMUOptionParType {
- OPT_FLAG,
- OPT_NUMBER,
- OPT_SIZE,
- 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);
@@ -57,33 +39,11 @@ 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);
bool has_help_option(const char *param);
bool is_valid_option_list(const char *param);
-/* ------------------------------------------------------------------ */
-
typedef struct QemuOpt QemuOpt;
typedef struct QemuOpts QemuOpts;
typedef struct QemuOptsList QemuOptsList;
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 6fac370..e08ed74 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -137,22 +137,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)
{
@@ -226,244 +210,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 (!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 (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;
-}
-
-/*
- * 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;
-}
-
bool has_help_option(const char *param)
{
size_t buflen = strlen(param) + 1;
@@ -513,48 +259,6 @@ out:
return result;
}
-/*
- * 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)
{
QemuOpt *opt;
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [Qemu-devel] [PATCH 26/26] qemu-img: migrate QemuOptionParameter usage
2014-03-21 0:13 [Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration Leandro Dorileo
` (24 preceding siblings ...)
2014-03-21 0:13 ` [Qemu-devel] [PATCH 25/26] QemuOpt: get rid of QEMUOptionParameter Leandro Dorileo
@ 2014-03-21 0:13 ` Leandro Dorileo
25 siblings, 0 replies; 34+ messages in thread
From: Leandro Dorileo @ 2014-03-21 0:13 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Fam Zheng, Stefan Hajnoczi, Liu Yuan, Jeff Cody,
Markus Armbruster, Peter Lieven, Richard W.M. Jones,
Luiz Capitulino, Leandro Dorileo, Ronnie Sahlberg, Josh Durgin,
Anthony Liguori, Paolo Bonzini, Stefan Weil, Max Reitz,
MORITA Kazutaka, Benoit Canet
Do the directly migration from QemuOptionParameter to QemuOpts on
qemu-img.
Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
qemu-img.c | 166 +++++++++++++++++++++++++++++++++++--------------------------
1 file changed, 95 insertions(+), 71 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index 2e40cc1..1a8ce3c 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -235,7 +235,9 @@ 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 *proto_opts = NULL;
+ QemuOpts *opts;
+ QemuOptsList *list;
/* Find driver and parse its options */
drv = bdrv_find_format(fmt);
@@ -244,21 +246,32 @@ static int print_block_option_help(const char *filename, const char *fmt)
return 1;
}
- create_options = append_option_parameters(create_options,
- drv->create_options);
-
if (filename) {
proto_drv = bdrv_find_protocol(filename, true);
if (!proto_drv) {
error_report("Unknown protocol '%s'", filename);
return 1;
}
- create_options = append_option_parameters(create_options,
- proto_drv->create_options);
+ proto_opts = proto_drv->create_options;
+ }
+
+ list = qemu_opts_append(drv->create_options, proto_opts);
+ if (!list) {
+ error_report("Could not allocate option descriptors structure");
+ return 1;
+ }
+
+ opts = qemu_opts_create(list, NULL, 0, &error_abort);
+ if (!list) {
+ error_report("Could not allocate options structure");
+ g_free(list);
+ return 1;
}
- print_option_help(create_options);
- free_option_parameters(create_options);
+ qemu_opts_print_help(opts);
+
+ qemu_opts_del(opts);
+ g_free(list);
return 0;
}
@@ -311,22 +324,26 @@ 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)
{
+ int ret;
+
if (base_filename) {
- if (set_option_parameter(list, BLOCK_OPT_BACKING_FILE, base_filename)) {
+ ret = qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename);
+ if (ret < 0) {
error_report("Backing file not supported for file format '%s'",
fmt);
- return -1;
+ return ret;
}
}
if (base_fmt) {
- if (set_option_parameter(list, BLOCK_OPT_BACKING_FMT, base_fmt)) {
+ ret = qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt);
+ if (ret < 0) {
error_report("Backing file format not supported for file "
"format '%s'", fmt);
- return -1;
+ return ret;
}
}
return 0;
@@ -1153,8 +1170,8 @@ 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;
- QEMUOptionParameter *out_baseimg_param;
+ QemuOpts *create_options;
+ QemuOptsList *opts_list = NULL;
char *options = NULL;
const char *snapshot_name = NULL;
int min_sparse = 8; /* Need at least 4k of zeros for sparse detection */
@@ -1340,72 +1357,73 @@ 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);
+ opts_list = qemu_opts_append(drv->create_options,
+ proto_drv->create_options);
+ if (!opts_list) {
+ error_report("Could not allocate option descriptors structure");
+ ret = -1;
+ goto out;
+ }
+
+ create_options = qemu_opts_create(opts_list, NULL, 0, &error_abort);
+ if (!create_options) {
+ error_report("Could not allocate options structure");
+ ret = -1;
+ goto err_opts;
+ }
if (options) {
- param = parse_option_parameters(options, create_options, param);
- if (param == NULL) {
+ ret = qemu_opts_do_parse(create_options, options, NULL);
+ if (ret < 0) {
error_report("Invalid options for file format '%s'.", out_fmt);
- ret = -1;
- goto out;
+ goto err;
}
- } 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);
+ ret = qemu_opt_set_number(create_options, BLOCK_OPT_SIZE,
+ total_sectors * 512);
if (ret < 0) {
- goto out;
+ goto err;
}
- /* 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;
+ ret = add_old_style_options(out_fmt, create_options, out_baseimg, NULL);
+ if (ret < 0) {
+ goto err;
}
+ /* Get backing file name if -o backing_file was used */
+ out_baseimg = qemu_opt_get(create_options, BLOCK_OPT_BACKING_FILE);
+
/* 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);
+ const char *encryption, *preallocation;
+
+ encryption = qemu_opt_get(create_options, BLOCK_OPT_ENCRYPT);
+ preallocation = qemu_opt_get(create_options, 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;
+ goto err;
}
- if (preallocation && preallocation->value.s
- && strcmp(preallocation->value.s, "off"))
+ if (encryption && preallocation && strcmp(preallocation, "off"))
{
error_report("Compression and preallocation not supported at "
"the same time");
ret = -1;
- goto out;
+ goto err;
}
}
if (!skip_create) {
/* Create the new image */
- ret = bdrv_create(drv, out_filename, param, &local_err);
+ ret = bdrv_create(drv, out_filename, create_options, &local_err);
if (ret < 0) {
error_report("%s: error while converting %s: %s",
out_filename, out_fmt, error_get_pretty(local_err));
error_free(local_err);
- goto out;
+ goto err;
}
}
@@ -1419,7 +1437,7 @@ static int img_convert(int argc, char **argv)
out_bs = bdrv_new_open(out_filename, out_fmt, flags, true, quiet);
if (!out_bs) {
ret = -1;
- goto out;
+ goto err;
}
bs_i = 0;
@@ -1442,11 +1460,11 @@ static int img_convert(int argc, char **argv)
error_report("unable to get output image length: %s\n",
strerror(-output_length));
ret = -1;
- goto out;
+ goto err;
} else if (output_length < total_sectors << BDRV_SECTOR_BITS) {
error_report("output file is smaller than input file");
ret = -1;
- goto out;
+ goto err;
}
}
@@ -1455,7 +1473,7 @@ static int img_convert(int argc, char **argv)
if (ret < 0) {
if (compress) {
error_report("could not get block driver info");
- goto out;
+ goto err;
}
} else {
cluster_sectors = bdi.cluster_size / BDRV_SECTOR_SIZE;
@@ -1465,7 +1483,7 @@ static int img_convert(int argc, char **argv)
if (cluster_sectors <= 0 || cluster_sectors > bufsectors) {
error_report("invalid cluster size");
ret = -1;
- goto out;
+ goto err;
}
sector_num = 0;
@@ -1508,7 +1526,7 @@ static int img_convert(int argc, char **argv)
if (ret < 0) {
error_report("error while reading sector %" PRId64 ": %s",
bs_num, strerror(-ret));
- goto out;
+ goto err;
}
buf2 += nlow * 512;
@@ -1523,7 +1541,7 @@ static int img_convert(int argc, char **argv)
if (ret != 0) {
error_report("error while compressing sector %" PRId64
": %s", sector_num, strerror(-ret));
- goto out;
+ goto err;
}
}
sector_num += n;
@@ -1539,7 +1557,7 @@ static int img_convert(int argc, char **argv)
if (!has_zero_init && bdrv_can_write_zeroes_with_unmap(out_bs)) {
ret = bdrv_make_zero(out_bs, BDRV_REQ_MAY_UNMAP);
if (ret < 0) {
- goto out;
+ goto err;
}
has_zero_init = 1;
}
@@ -1582,7 +1600,7 @@ restart:
error_report("error while reading block status of sector %"
PRId64 ": %s", sector_num - bs_offset,
strerror(-ret));
- goto out;
+ goto err;
}
/* If the output image is zero initialized, we are not working
* on a shared base and the input is zero we can skip the next
@@ -1636,7 +1654,7 @@ restart:
if (ret < 0) {
error_report("error while reading sector %" PRId64 ": %s",
sector_num - bs_offset, strerror(-ret));
- goto out;
+ goto err;
}
/* NOTE: at the same time we convert, we do not write zero
sectors to have a chance to compress the image. Ideally, we
@@ -1649,7 +1667,7 @@ restart:
if (ret < 0) {
error_report("error while writing sector %" PRId64
": %s", sector_num, strerror(-ret));
- goto out;
+ goto err;
}
}
sector_num += n1;
@@ -1659,13 +1677,16 @@ restart:
qemu_progress_print(100.0 * sectors_read / sectors_to_read, 0);
}
}
+
+err:
+ qemu_opts_del(create_options);
+err_opts:
+ g_free(opts_list);
out:
if (!ret) {
qemu_progress_print(100, 0);
}
qemu_progress_end();
- free_option_parameters(create_options);
- free_option_parameters(param);
qemu_vfree(buf);
if (sn_opts) {
qemu_opts_del(sn_opts);
@@ -2651,7 +2672,7 @@ static int img_amend(int argc, char **argv)
{
int c, ret = 0;
char *options = NULL;
- QEMUOptionParameter *create_options = NULL, *options_param = NULL;
+ QemuOpts *opts = NULL;
const char *fmt = NULL, *filename;
bool quiet = false;
BlockDriverState *bs = NULL;
@@ -2721,17 +2742,21 @@ 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) {
+ opts = qemu_opts_create(bs->drv->create_options, NULL, 0, &error_abort);
+ if (!opts) {
+ error_report("Could not create the options structure");
+ ret = -1;
+ goto out;
+ }
+
+ ret = qemu_opts_do_parse(opts, options, NULL);
+ if (ret < 0) {
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;
@@ -2741,8 +2766,7 @@ out:
if (bs) {
bdrv_unref(bs);
}
- free_option_parameters(create_options);
- free_option_parameters(options_param);
+ qemu_opts_del(opts);
g_free(options);
if (ret) {
--
1.9.0
^ permalink raw reply related [flat|nested] 34+ messages in thread