@@ -5382,12 +5382,12 @@ void bdrv_add_before_write_notifier(BlockDriverState *bs,
notifier_with_return_list_add(&bs->before_write_notifiers, notifier);
}
-int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options)
+int bdrv_amend_options(BlockDriverState *bs, QemuOpts *opts)
{
if (bs->drv->bdrv_amend_options == NULL) {
return -ENOTSUP;
}
- return bs->drv->bdrv_amend_options(bs, options);
+ return bs->drv->bdrv_amend_options(bs, opts);
}
/* Used to recurse on single child block filters.
@@ -2045,65 +2045,57 @@ static int qcow2_downgrade(BlockDriverState *bs, int target_version)
}
static int qcow2_amend_options(BlockDriverState *bs,
- QEMUOptionParameter *options)
+ QemuOpts *opts)
{
BDRVQcowState *s = bs->opaque;
int old_version = s->qcow_version, new_version = old_version;
uint64_t new_size = 0;
const char *backing_file = NULL, *backing_format = NULL;
bool lazy_refcounts = s->use_lazy_refcounts;
+ const char *compat, *prealloc;
+ uint64_t cluster_size = s->cluster_size;
+ bool encrypt;
int ret;
- int i;
- for (i = 0; options[i].name; i++)
- {
- if (!options[i].assigned) {
- /* only change explicitly defined options */
- continue;
- }
+ compat = qemu_opt_get_del(opts, "compat");
+ if (!compat) {
+ /* preserve default */
+ } else if (!strcmp(compat, "0.10")) {
+ new_version = 2;
+ } else if (!strcmp(compat, "1.1")) {
+ new_version = 3;
+ } else {
+ fprintf(stderr, "Unknown compatibility level %s.\n", compat);
+ return -EINVAL;
+ }
- if (!strcmp(options[i].name, "compat")) {
- if (!options[i].value.s) {
- /* preserve default */
- } else if (!strcmp(options[i].value.s, "0.10")) {
- new_version = 2;
- } else if (!strcmp(options[i].value.s, "1.1")) {
- new_version = 3;
- } else {
- fprintf(stderr, "Unknown compatibility level %s.\n",
- options[i].value.s);
- return -EINVAL;
- }
- } else if (!strcmp(options[i].name, "preallocation")) {
- fprintf(stderr, "Cannot change preallocation mode.\n");
- return -ENOTSUP;
- } else if (!strcmp(options[i].name, "size")) {
- new_size = options[i].value.n;
- } else if (!strcmp(options[i].name, "backing_file")) {
- backing_file = options[i].value.s;
- } else if (!strcmp(options[i].name, "backing_fmt")) {
- backing_format = options[i].value.s;
- } else if (!strcmp(options[i].name, "encryption")) {
- if ((options[i].value.n != !!s->crypt_method)) {
- fprintf(stderr, "Changing the encryption flag is not "
- "supported.\n");
- return -ENOTSUP;
- }
- } else if (!strcmp(options[i].name, "cluster_size")) {
- if (options[i].value.n != s->cluster_size) {
- fprintf(stderr, "Changing the cluster size is not "
- "supported.\n");
- return -ENOTSUP;
- }
- } else if (!strcmp(options[i].name, "lazy_refcounts")) {
- lazy_refcounts = options[i].value.n;
- } else {
- /* if this assertion fails, this probably means a new option was
- * added without having it covered here */
- assert(false);
- }
+ prealloc = qemu_opt_get_del(opts, "preallocation");
+ if (prealloc) {
+ fprintf(stderr, "Cannot change preallocation mode.\n");
+ return -ENOTSUP;
}
+ new_size = qemu_opt_get_size_del(opts, "size", 0);
+ backing_file = qemu_opt_get_del(opts, "backing_file");
+ backing_format = qemu_opt_get_del(opts, "backing_fmt");
+
+ encrypt = qemu_opt_get_bool_del(opts, "encryption", s->crypt_method);
+ if (encrypt != !!s->crypt_method) {
+ fprintf(stderr, "Changing the encryption flag is not "
+ "supported.\n");
+ return -ENOTSUP;
+ }
+
+ cluster_size = qemu_opt_get_size_del(opts, "cluster_size", cluster_size);
+ if (cluster_size != s->cluster_size) {
+ fprintf(stderr, "Changing the cluster size is not "
+ "supported.\n");
+ return -ENOTSUP;
+ }
+
+ lazy_refcounts = qemu_opt_get_bool_del(opts, "lazy_refcounts",
+ lazy_refcounts);
+
if (new_version != old_version) {
if (new_version > old_version) {
/* Upgrade */
@@ -2228,7 +2220,7 @@ static BlockDriver bdrv_qcow2 = {
.bdrv_open = qcow2_open,
.bdrv_close = qcow2_close,
.bdrv_reopen_prepare = qcow2_reopen_prepare,
- .bdrv_create2 = qcow2_create,
+ .bdrv_create2 = qcow2_create,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
.bdrv_co_get_block_status = qcow2_co_get_block_status,
.bdrv_set_key = qcow2_set_key,
@@ -282,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 *opts);
/* external snapshots */
@@ -229,7 +229,7 @@ struct BlockDriver {
BdrvCheckMode fix);
int (*bdrv_amend_options)(BlockDriverState *bs,
- QEMUOptionParameter *options);
+ QemuOpts *opts);
void (*bdrv_debug_event)(BlockDriverState *bs, BlkDebugEvent event);
@@ -2639,7 +2639,8 @@ static int img_amend(int argc, char **argv)
{
int c, ret = 0;
char *options = NULL;
- QEMUOptionParameter *create_options = NULL, *options_param = NULL;
+ QemuOptsList *create_opts = NULL;
+ QemuOpts *opts = NULL;
const char *fmt = NULL, *filename;
bool quiet = false;
BlockDriverState *bs = NULL;
@@ -2691,17 +2692,15 @@ static int img_amend(int argc, char **argv)
goto out;
}
- create_options = append_option_parameters(create_options,
- bs->drv->create_options);
- options_param = parse_option_parameters(options, create_options,
- options_param);
- if (options_param == NULL) {
+ create_opts = qemu_opts_append(create_opts, bs->drv->create_opts);
+ opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
+ if (options && qemu_opts_do_parse(opts, options, NULL)) {
error_report("Invalid options for file format '%s'", fmt);
ret = -1;
goto out;
}
- ret = bdrv_amend_options(bs, options_param);
+ ret = bdrv_amend_options(bs, opts);
if (ret < 0) {
error_report("Error while amending options: %s", strerror(-ret));
goto out;
@@ -2711,8 +2710,8 @@ out:
if (bs) {
bdrv_unref(bs);
}
- free_option_parameters(create_options);
- free_option_parameters(options_param);
+ qemu_opts_del(opts);
+ qemu_opts_free(create_opts);
if (ret) {
return 1;
}