[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [v19 10/25] qcow2.c: replace QEMUOptionParameter with QemuO
From: |
Chunyan Liu |
Subject: |
[Qemu-devel] [v19 10/25] qcow2.c: replace QEMUOptionParameter with QemuOpts in create |
Date: |
Mon, 20 Jan 2014 22:19:53 +0800 |
qcow2.c: replace QEMUOptionParameter with QemuOpts in 'qemu-img create'.
Signed-off-by: Dong Xu Wang <address@hidden>
Signed-off-by: Chunyan Liu <address@hidden>
---
block/qcow2.c | 176 ++++++++++++++++++++++++++++----------------------------
1 files changed, 88 insertions(+), 88 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index e8b96cd..b7a2e3f 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1445,7 +1445,7 @@ static int preallocate(BlockDriverState *bs)
static int qcow2_create2(const char *filename, int64_t total_size,
const char *backing_file, const char *backing_format,
int flags, size_t cluster_size, int prealloc,
- QEMUOptionParameter *options, int version,
+ QemuOpts *opts, int version,
Error **errp)
{
/* Calculate cluster_bits */
@@ -1477,7 +1477,7 @@ static int qcow2_create2(const char *filename, int64_t
total_size,
Error *local_err = NULL;
int ret;
- ret = bdrv_create_file(filename, options, NULL, &local_err);
+ ret = bdrv_create_file(filename, NULL, opts, &local_err);
if (ret < 0) {
error_propagate(errp, local_err);
return ret;
@@ -1606,11 +1606,12 @@ out:
return ret;
}
-static int qcow2_create(const char *filename, QEMUOptionParameter *options,
+static int qcow2_create(const char *filename, QemuOpts *opts,
Error **errp)
{
const char *backing_file = NULL;
const char *backing_fmt = NULL;
+ const char *buf;
uint64_t sectors = 0;
int flags = 0;
size_t cluster_size = DEFAULT_CLUSTER_SIZE;
@@ -1620,45 +1621,38 @@ static int qcow2_create(const char *filename,
QEMUOptionParameter *options,
int ret;
/* Read out options */
- while (options && options->name) {
- if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
- sectors = options->value.n / 512;
- } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
- backing_file = options->value.s;
- } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FMT)) {
- backing_fmt = options->value.s;
- } else if (!strcmp(options->name, BLOCK_OPT_ENCRYPT)) {
- flags |= options->value.n ? BLOCK_FLAG_ENCRYPT : 0;
- } else if (!strcmp(options->name, BLOCK_OPT_CLUSTER_SIZE)) {
- if (options->value.n) {
- cluster_size = options->value.n;
- }
- } else if (!strcmp(options->name, BLOCK_OPT_PREALLOC)) {
- if (!options->value.s || !strcmp(options->value.s, "off")) {
- prealloc = 0;
- } else if (!strcmp(options->value.s, "metadata")) {
- prealloc = 1;
- } else {
- error_setg(errp, "Invalid preallocation mode: '%s'",
- options->value.s);
- return -EINVAL;
- }
- } else if (!strcmp(options->name, BLOCK_OPT_COMPAT_LEVEL)) {
- if (!options->value.s) {
- /* keep the default */
- } else if (!strcmp(options->value.s, "0.10")) {
- version = 2;
- } else if (!strcmp(options->value.s, "1.1")) {
- version = 3;
- } else {
- error_setg(errp, "Invalid compatibility level: '%s'",
- options->value.s);
- return -EINVAL;
- }
- } else if (!strcmp(options->name, BLOCK_OPT_LAZY_REFCOUNTS)) {
- flags |= options->value.n ? BLOCK_FLAG_LAZY_REFCOUNTS : 0;
- }
- options++;
+ sectors = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512;
+ backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+ backing_fmt = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT);
+ if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) {
+ flags |= BLOCK_FLAG_ENCRYPT;
+ }
+ cluster_size = qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE,
+ DEFAULT_CLUSTER_SIZE);
+ buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
+ if (!buf || !strcmp(buf, "off")) {
+ prealloc = 0;
+ } else if (!strcmp(buf, "metadata")) {
+ prealloc = 1;
+ } else {
+ fprintf(stderr, "Invalid preallocation mode: '%s'\n",
+ buf);
+ return -EINVAL;
+ }
+ buf = NULL;
+ buf = qemu_opt_get_del(opts, BLOCK_OPT_COMPAT_LEVEL);
+ if (!buf || !strcmp(buf, "0.10")) {
+ version = 2;
+ } else if (!strcmp(buf, "1.1")) {
+ version = 3;
+ } else {
+ fprintf(stderr, "Invalid compatibility level: '%s'\n",
+ buf);
+ return -EINVAL;
+ }
+
+ if (qemu_opt_get_bool_del(opts, BLOCK_OPT_LAZY_REFCOUNTS, false)) {
+ flags |= BLOCK_FLAG_LAZY_REFCOUNTS;
}
if (backing_file && prealloc) {
@@ -1674,7 +1668,7 @@ static int qcow2_create(const char *filename,
QEMUOptionParameter *options,
}
ret = qcow2_create2(filename, sectors, backing_file, backing_fmt, flags,
- cluster_size, prealloc, options, version, &local_err);
+ cluster_size, prealloc, opts, version, &local_err);
if (error_is_set(&local_err)) {
error_propagate(errp, local_err);
}
@@ -2188,49 +2182,55 @@ static int qcow2_amend_options(BlockDriverState *bs,
return 0;
}
-static QEMUOptionParameter qcow2_create_options[] = {
- {
- .name = BLOCK_OPT_SIZE,
- .type = OPT_SIZE,
- .help = "Virtual disk size"
- },
- {
- .name = BLOCK_OPT_COMPAT_LEVEL,
- .type = OPT_STRING,
- .help = "Compatibility level (0.10 or 1.1)"
- },
- {
- .name = BLOCK_OPT_BACKING_FILE,
- .type = OPT_STRING,
- .help = "File name of a base image"
- },
- {
- .name = BLOCK_OPT_BACKING_FMT,
- .type = OPT_STRING,
- .help = "Image format of the base image"
- },
- {
- .name = BLOCK_OPT_ENCRYPT,
- .type = OPT_FLAG,
- .help = "Encrypt the image"
- },
- {
- .name = BLOCK_OPT_CLUSTER_SIZE,
- .type = OPT_SIZE,
- .help = "qcow2 cluster size",
- .value = { .n = DEFAULT_CLUSTER_SIZE },
- },
- {
- .name = BLOCK_OPT_PREALLOC,
- .type = OPT_STRING,
- .help = "Preallocation mode (allowed values: off, metadata)"
- },
- {
- .name = BLOCK_OPT_LAZY_REFCOUNTS,
- .type = OPT_FLAG,
- .help = "Postpone refcount updates",
- },
- { NULL }
+static QemuOptsList qcow2_create_opts = {
+ .name = "qcow2-create-opts",
+ .head = QTAILQ_HEAD_INITIALIZER(qcow2_create_opts.head),
+ .desc = {
+ {
+ .name = BLOCK_OPT_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "Virtual disk size"
+ },
+ {
+ .name = BLOCK_OPT_COMPAT_LEVEL,
+ .type = QEMU_OPT_STRING,
+ .help = "Compatibility level (0.10 or 1.1)"
+ },
+ {
+ .name = BLOCK_OPT_BACKING_FILE,
+ .type = QEMU_OPT_STRING,
+ .help = "File name of a base image"
+ },
+ {
+ .name = BLOCK_OPT_BACKING_FMT,
+ .type = QEMU_OPT_STRING,
+ .help = "Image format of the base image"
+ },
+ {
+ .name = BLOCK_OPT_ENCRYPT,
+ .type = QEMU_OPT_BOOL,
+ .help = "Encrypt the image",
+ .def_value_str = "off"
+ },
+ {
+ .name = BLOCK_OPT_CLUSTER_SIZE,
+ .type = QEMU_OPT_SIZE,
+ .help = "qcow2 cluster size",
+ .def_value_str = stringify(DEFAULT_CLUSTER_SIZE)
+ },
+ {
+ .name = BLOCK_OPT_PREALLOC,
+ .type = QEMU_OPT_STRING,
+ .help = "Preallocation mode (allowed values: off, metadata)"
+ },
+ {
+ .name = BLOCK_OPT_LAZY_REFCOUNTS,
+ .type = QEMU_OPT_BOOL,
+ .help = "Postpone refcount updates",
+ .def_value_str = "off"
+ },
+ { /* end of list */ }
+ }
};
static BlockDriver bdrv_qcow2 = {
@@ -2240,7 +2240,7 @@ static BlockDriver bdrv_qcow2 = {
.bdrv_open = qcow2_open,
.bdrv_close = qcow2_close,
.bdrv_reopen_prepare = qcow2_reopen_prepare,
- .bdrv_create = qcow2_create,
+ .bdrv_create2 = qcow2_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_co_get_block_status = qcow2_co_get_block_status,
.bdrv_set_key = qcow2_set_key,
@@ -2270,7 +2270,7 @@ static BlockDriver bdrv_qcow2 = {
.bdrv_invalidate_cache = qcow2_invalidate_cache,
- .create_options = qcow2_create_options,
+ .create_opts = &qcow2_create_opts,
.bdrv_check = qcow2_check,
.bdrv_amend_options = qcow2_amend_options,
};
--
1.6.0.2
- [Qemu-devel] [v19 06/25] cow.c: replace QEMUOptionParameter with QemuOpts, (continued)
- [Qemu-devel] [v19 06/25] cow.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/01/20
- [Qemu-devel] [v19 04/25] add some QemuOpts functions for replace work, Chunyan Liu, 2014/01/20
- [Qemu-devel] [v19 05/25] change block layer to support both QemuOpts and QEMUOptionParameter, Chunyan Liu, 2014/01/20
- [Qemu-devel] [v19 07/25] gluster.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/01/20
- [Qemu-devel] [v19 08/25] iscsi.c: replace QEMUOptionParamter with QemuOpts, Chunyan Liu, 2014/01/20
- [Qemu-devel] [v19 09/25] qcow.c: replace QEMUOptionParamter with QemuOpts, Chunyan Liu, 2014/01/20
- [Qemu-devel] [v19 10/25] qcow2.c: replace QEMUOptionParameter with QemuOpts in create,
Chunyan Liu <=
- [Qemu-devel] [v19 11/25] qcow2.c: replace QEMUOptionParameter with QemuOpts in amend options, Chunyan Liu, 2014/01/20
- [Qemu-devel] [v19 15/25] rbd.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/01/20
- [Qemu-devel] [v19 12/25] qed.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/01/20
- [Qemu-devel] [v19 13/25] raw-posix.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/01/20
- [Qemu-devel] [v19 16/25] sheepdog.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/01/20
- [Qemu-devel] [v19 14/25] raw-win32.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/01/20
- [Qemu-devel] [v19 18/25] vdi.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/01/20
- [Qemu-devel] [v19 17/25] ssh.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/01/20
- [Qemu-devel] [v19 21/25] raw_bsd.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/01/20