[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v20 25/26] cleanup QEMUOptionParameter
From: |
Chunyan Liu |
Subject: |
[Qemu-devel] [PATCH v20 25/26] cleanup QEMUOptionParameter |
Date: |
Wed, 12 Feb 2014 14:33:25 +0800 |
Now all places using QEMUOptionParameter could use QemuOpts too, remove
QEMUOptionParameter related code.
Signed-off-by: Dong Xu Wang <address@hidden>
Signed-off-by: Chunyan Liu <address@hidden>
---
block.c | 57 ++-----
block/cow.c | 2 +-
block/qcow.c | 2 +-
block/qcow2.c | 2 +-
block/qed.c | 2 +-
block/raw_bsd.c | 2 +-
block/vhdx.c | 2 +-
block/vmdk.c | 4 +-
block/vvfat.c | 2 +-
include/block/block.h | 4 +-
include/block/block_int.h | 3 -
include/qemu/option.h | 37 ----
qemu-img.c | 39 +----
util/qemu-option.c | 405 ---------------------------------------------
14 files changed, 30 insertions(+), 533 deletions(-)
diff --git a/block.c b/block.c
index d6ddbd0..56b6d06 100644
--- a/block.c
+++ b/block.c
@@ -407,7 +407,6 @@ BlockDriver *bdrv_find_whitelisted_format(const char
*format_name,
typedef struct CreateCo {
BlockDriver *drv;
char *filename;
- QEMUOptionParameter *options;
QemuOpts *opts;
int ret;
Error *err;
@@ -421,11 +420,7 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
CreateCo *cco = opaque;
assert(cco->drv);
- if (cco->drv->bdrv_create2) {
- ret = cco->drv->bdrv_create2(cco->filename, cco->opts, &local_err);
- } else {
- ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
- }
+ ret = cco->drv->bdrv_create2(cco->filename, cco->opts, &local_err);
if (error_is_set(&local_err)) {
error_propagate(&cco->err, local_err);
}
@@ -433,7 +428,7 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
}
int bdrv_create(BlockDriver *drv, const char* filename,
- QEMUOptionParameter *options, QemuOpts *opts, Error **errp)
+ QemuOpts *opts, Error **errp)
{
int ret;
@@ -441,13 +436,12 @@ int bdrv_create(BlockDriver *drv, const char* filename,
CreateCo cco = {
.drv = drv,
.filename = g_strdup(filename),
- .options = options,
.opts = opts,
.ret = NOT_DONE,
.err = NULL,
};
- if (!drv->bdrv_create && !drv->bdrv_create2) {
+ if (!drv->bdrv_create2) {
error_setg(errp, "Driver '%s' does not support image creation",
drv->format_name);
ret = -ENOTSUP;
goto out;
@@ -478,7 +472,7 @@ out:
return ret;
}
-int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
+int bdrv_create_file(const char *filename,
QemuOpts *opts, Error **errp)
{
BlockDriver *drv;
@@ -491,7 +485,7 @@ int bdrv_create_file(const char* filename,
QEMUOptionParameter *options,
return -ENOENT;
}
- ret = bdrv_create(drv, filename, options, opts, &local_err);
+ ret = bdrv_create(drv, filename, opts, &local_err);
if (error_is_set(&local_err)) {
error_propagate(errp, local_err);
}
@@ -1252,7 +1246,6 @@ int bdrv_open(BlockDriverState *bs, const char *filename,
QDict *options,
BlockDriverState *bs1;
int64_t total_size;
BlockDriver *bdrv_qcow2;
- QEMUOptionParameter *create_options = NULL;
QemuOpts *opts = NULL;
QDict *snapshot_options;
@@ -1280,20 +1273,11 @@ int bdrv_open(BlockDriverState *bs, const char
*filename, QDict *options,
}
bdrv_qcow2 = bdrv_find_format("qcow2");
- if (bdrv_qcow2->bdrv_create2) {
- opts = qemu_opts_create(bdrv_qcow2->create_opts, NULL, 0,
- &error_abort);
- qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size);
- } else {
- create_options =
- parse_option_parameters("", bdrv_qcow2->create_options, NULL);
- set_option_parameter_int(create_options, BLOCK_OPT_SIZE,
- total_size);
- }
+ opts = qemu_opts_create(bdrv_qcow2->create_opts, NULL, 0,
+ &error_abort);
+ qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size);
- ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, opts,
- &local_err);
- free_option_parameters(create_options);
+ ret = bdrv_create(bdrv_qcow2, tmp_filename, opts, &local_err);
qemu_opts_del(opts);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not create temporary overlay "
@@ -5211,7 +5195,6 @@ void bdrv_img_create(const char *filename, const char
*fmt,
char *options, uint64_t img_size, int flags,
Error **errp, bool quiet)
{
- QEMUOptionParameter *param = NULL, *create_options = NULL;
QemuOptsList *create_opts = NULL;
QemuOpts *opts = NULL;
const char *backing_fmt, *backing_file;
@@ -5234,16 +5217,8 @@ void bdrv_img_create(const char *filename, const char
*fmt,
return;
}
- if (drv->bdrv_create2) {
- create_opts = qemu_opts_append(create_opts, drv->create_opts);
- create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
- } else {
- create_options = append_option_parameters(create_options,
- drv->create_options);
- create_options = append_option_parameters(create_options,
- proto_drv->create_options);
- create_opts = params_to_opts(create_options);
- }
+ create_opts = qemu_opts_append(create_opts, drv->create_opts);
+ create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
/* Create parameter list with default values */
opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
@@ -5338,12 +5313,7 @@ void bdrv_img_create(const char *filename, const char
*fmt,
puts("");
}
- if (drv->bdrv_create2) {
- ret = bdrv_create(drv, filename, NULL, opts, &local_err);
- } else {
- param = opts_to_params(opts);
- ret = bdrv_create(drv, filename, param, NULL, &local_err);
- }
+ ret = bdrv_create(drv, filename, opts, &local_err);
if (ret == -EFBIG) {
/* This is generally a better message than whatever the driver would
@@ -5360,9 +5330,6 @@ void bdrv_img_create(const char *filename, const char
*fmt,
}
out:
- free_option_parameters(create_options);
- free_option_parameters(param);
-
qemu_opts_del(opts);
qemu_opts_free(create_opts);
if (error_is_set(&local_err)) {
diff --git a/block/cow.c b/block/cow.c
index 0d06781..012a6b4 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -338,7 +338,7 @@ static int cow_create(const char *filename, QemuOpts *opts,
image_sectors = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512;
image_filename = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
- ret = bdrv_create_file(filename, NULL, opts, &local_err);
+ ret = bdrv_create_file(filename, opts, &local_err);
if (ret < 0) {
qerror_report_err(local_err);
error_free(local_err);
diff --git a/block/qcow.c b/block/qcow.c
index 519276e..a9a30d9 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -679,7 +679,7 @@ static int qcow_create(const char *filename, QemuOpts *opts,
flags |= BLOCK_FLAG_ENCRYPT;
}
- ret = bdrv_create_file(filename, NULL, opts, &local_err);
+ ret = bdrv_create_file(filename, opts, &local_err);
if (ret < 0) {
qerror_report_err(local_err);
error_free(local_err);
diff --git a/block/qcow2.c b/block/qcow2.c
index a3afacb..eb8f8bd 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1485,7 +1485,7 @@ static int qcow2_create2(const char *filename, int64_t
total_size,
Error *local_err = NULL;
int ret;
- ret = bdrv_create_file(filename, NULL, opts, &local_err);
+ ret = bdrv_create_file(filename, opts, &local_err);
if (ret < 0) {
error_propagate(errp, local_err);
return ret;
diff --git a/block/qed.c b/block/qed.c
index 1d37519..e5b4df4 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -564,7 +564,7 @@ static int qed_create(const char *filename, uint32_t
cluster_size,
int ret = 0;
BlockDriverState *bs = NULL;
- ret = bdrv_create_file(filename, NULL, NULL, &local_err);
+ ret = bdrv_create_file(filename, NULL, &local_err);
if (ret < 0) {
qerror_report_err(local_err);
error_free(local_err);
diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index 4ae12dd..d9dd324 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -143,7 +143,7 @@ static int raw_create(const char *filename, QemuOpts *opts,
Error *local_err = NULL;
int ret;
- ret = bdrv_create_file(filename, NULL, opts, &local_err);
+ ret = bdrv_create_file(filename, opts, &local_err);
if (error_is_set(&local_err)) {
error_propagate(errp, local_err);
}
diff --git a/block/vhdx.c b/block/vhdx.c
index 4815210..f8d032f 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -1782,7 +1782,7 @@ static int vhdx_create(const char *filename, QemuOpts
*opts,
block_size = block_size > VHDX_BLOCK_SIZE_MAX ? VHDX_BLOCK_SIZE_MAX :
block_size;
- ret = bdrv_create_file(filename, NULL, opts, &local_err);
+ ret = bdrv_create_file(filename, opts, &local_err);
if (ret < 0) {
error_propagate(errp, local_err);
goto exit;
diff --git a/block/vmdk.c b/block/vmdk.c
index 7188649..e417ec1 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1487,7 +1487,7 @@ static int vmdk_create_extent(const char *filename,
int64_t filesize,
uint32_t *gd_buf = NULL;
int gd_buf_size;
- ret = bdrv_create_file(filename, NULL, NULL, &local_err);
+ ret = bdrv_create_file(filename, NULL, &local_err);
if (ret < 0) {
error_propagate(errp, local_err);
goto exit;
@@ -1820,7 +1820,7 @@ static int vmdk_create(const char *filename, QemuOpts
*opts,
if (!split && !flat) {
desc_offset = 0x200;
} else {
- ret = bdrv_create_file(filename, NULL, opts, &local_err);
+ ret = bdrv_create_file(filename, opts, &local_err);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not create image file");
goto exit;
diff --git a/block/vvfat.c b/block/vvfat.c
index 81733bc..b43b4b1 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2929,7 +2929,7 @@ static int enable_write_target(BDRVVVFATState *s)
qemu_opt_set_number(opts, BLOCK_OPT_SIZE, s->sector_count * 512);
qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, "fat:");
- ret = bdrv_create(bdrv_qcow, s->qcow_filename, NULL, opts, &local_err);
+ ret = bdrv_create(bdrv_qcow, s->qcow_filename, opts, &local_err);
if (ret < 0) {
qerror_report_err(local_err);
error_free(local_err);
diff --git a/include/block/block.h b/include/block/block.h
index 5430057..c5a5d19 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -174,8 +174,8 @@ BlockDriver *bdrv_find_format(const char *format_name);
BlockDriver *bdrv_find_whitelisted_format(const char *format_name,
bool readonly);
int bdrv_create(BlockDriver *drv, const char* filename,
- QEMUOptionParameter *options, QemuOpts *opts, Error **errp);
-int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
+ QemuOpts *opts, Error **errp);
+int bdrv_create_file(const char *filename,
QemuOpts *opts, Error **errp);
BlockDriverState *bdrv_new(const char *device_name);
void bdrv_make_anon(BlockDriverState *bs);
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 3879d46..56b5feb 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -116,8 +116,6 @@ struct BlockDriver {
const uint8_t *buf, int nb_sectors);
void (*bdrv_close)(BlockDriverState *bs);
void (*bdrv_rebind)(BlockDriverState *bs);
- int (*bdrv_create)(const char *filename, QEMUOptionParameter *options,
- Error **errp);
int (*bdrv_create2)(const char *filename, QemuOpts *opts,
Error **errp);
int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
@@ -218,7 +216,6 @@ struct BlockDriver {
BlockDriverCompletionFunc *cb, void *opaque);
/* List of options for creating images, terminated by name == NULL */
- QEMUOptionParameter *create_options;
QemuOptsList *create_opts;
/*
diff --git a/include/qemu/option.h b/include/qemu/option.h
index de438c8..5bc6aaa 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -38,18 +38,6 @@ enum QEMUOptionParType {
OPT_STRING,
};
-typedef struct QEMUOptionParameter {
- const char *name;
- enum QEMUOptionParType type;
- union {
- uint64_t n;
- char* s;
- } value;
- const char *help;
- bool assigned;
-} QEMUOptionParameter;
-
-
const char *get_opt_name(char *buf, int buf_size, const char *p, char delim);
const char *get_opt_value(char *buf, int buf_size, const char *p);
int get_next_param_value(char *buf, int buf_size,
@@ -57,29 +45,6 @@ int get_next_param_value(char *buf, int buf_size,
int get_param_value(char *buf, int buf_size,
const char *tag, const char *str);
-
-/*
- * The following functions take a parameter list as input. This is a pointer to
- * the first element of a QEMUOptionParameter array which is terminated by an
- * entry with entry->name == NULL.
- */
-
-QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list,
- const char *name);
-int set_option_parameter(QEMUOptionParameter *list, const char *name,
- const char *value);
-int set_option_parameter_int(QEMUOptionParameter *list, const char *name,
- uint64_t value);
-QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest,
- QEMUOptionParameter *list);
-QEMUOptionParameter *parse_option_parameters(const char *param,
- QEMUOptionParameter *list, QEMUOptionParameter *dest);
-void parse_option_size(const char *name, const char *value,
- uint64_t *ret, Error **errp);
-void free_option_parameters(QEMUOptionParameter *list);
-void print_option_parameters(QEMUOptionParameter *list);
-void print_option_help(QEMUOptionParameter *list);
-
/* ------------------------------------------------------------------ */
typedef struct QemuOpt QemuOpt;
@@ -168,6 +133,4 @@ int qemu_opts_foreach(QemuOptsList *list,
qemu_opts_loopfunc func, void *opaque,
QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list);
void qemu_opts_free(QemuOptsList *list);
void qemu_opts_print_help(QemuOptsList *list);
-QEMUOptionParameter *opts_to_params(QemuOpts *opts);
-QemuOptsList *params_to_opts(QEMUOptionParameter *list);
#endif
diff --git a/qemu-img.c b/qemu-img.c
index c2a941d..3ab6bfe 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -241,7 +241,6 @@ static int read_password(char *buf, int buf_size)
static int print_block_option_help(const char *filename, const char *fmt)
{
BlockDriver *drv, *proto_drv;
- QEMUOptionParameter *create_options = NULL;
QemuOptsList *create_opts = NULL;
/* Find driver and parse its options */
@@ -257,18 +256,10 @@ static int print_block_option_help(const char *filename,
const char *fmt)
return 1;
}
- if (drv->bdrv_create2) {
- create_opts = qemu_opts_append(create_opts, drv->create_opts);
- create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
- qemu_opts_print_help(create_opts);
- } else {
- create_options = append_option_parameters(create_options,
- drv->create_options);
- create_options = append_option_parameters(create_options,
- proto_drv->create_options);
- print_option_help(create_options);
- }
- free_option_parameters(create_options);
+ create_opts = qemu_opts_append(create_opts, drv->create_opts);
+ create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
+ qemu_opts_print_help(create_opts);
+
qemu_opts_free(create_opts);
return 0;
}
@@ -1149,7 +1140,6 @@ static int img_convert(int argc, char **argv)
size_t bufsectors = IO_BUF_SIZE / BDRV_SECTOR_SIZE;
const uint8_t *buf1;
BlockDriverInfo bdi;
- QEMUOptionParameter *param = NULL, *create_options = NULL;
QemuOpts *opts = NULL;
QemuOptsList *create_opts = NULL;
const char *out_baseimg_param;
@@ -1322,16 +1312,8 @@ static int img_convert(int argc, char **argv)
goto out;
}
- if (drv->bdrv_create2) {
- create_opts = qemu_opts_append(create_opts, drv->create_opts);
- create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
- } else {
- create_options = append_option_parameters(create_options,
- drv->create_options);
- create_options = append_option_parameters(create_options,
- proto_drv->create_options);
- create_opts = params_to_opts(create_options);
- }
+ create_opts = qemu_opts_append(create_opts, drv->create_opts);
+ create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
if (options && qemu_opts_do_parse(opts, options, NULL)) {
@@ -1384,12 +1366,7 @@ static int img_convert(int argc, char **argv)
if (!skip_create) {
/* Create the new image */
- if (drv->bdrv_create2) {
- ret = bdrv_create(drv, out_filename, NULL, opts, &local_err);
- } else {
- param = opts_to_params(opts);
- ret = bdrv_create(drv, out_filename, param, NULL, &local_err);
- }
+ ret = bdrv_create(drv, out_filename, opts, &local_err);
if (ret < 0) {
error_report("%s: error while converting %s: %s",
out_filename, out_fmt, error_get_pretty(local_err));
@@ -1653,8 +1630,6 @@ out:
qemu_progress_print(100, 0);
}
qemu_progress_end();
- free_option_parameters(create_options);
- free_option_parameters(param);
qemu_opts_free(create_opts);
qemu_opts_del(opts);
qemu_vfree(buf);
diff --git a/util/qemu-option.c b/util/qemu-option.c
index be9ee13..2405db7 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -126,22 +126,6 @@ int get_param_value(char *buf, int buf_size,
return get_next_param_value(buf, buf_size, tag, &str);
}
-/*
- * Searches an option list for an option with the given name
- */
-QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list,
- const char *name)
-{
- while (list && list->name) {
- if (!strcmp(list->name, name)) {
- return list;
- }
- list++;
- }
-
- return NULL;
-}
-
static void parse_option_bool(const char *name, const char *value, bool *ret,
Error **errp)
{
@@ -215,170 +199,6 @@ void parse_option_size(const char *name, const char
*value,
}
}
-/*
- * Sets the value of a parameter in a given option list. The parsing of the
- * value depends on the type of option:
- *
- * OPT_FLAG (uses value.n):
- * If no value is given, the flag is set to 1.
- * Otherwise the value must be "on" (set to 1) or "off" (set to 0)
- *
- * OPT_STRING (uses value.s):
- * value is strdup()ed and assigned as option value
- *
- * OPT_SIZE (uses value.n):
- * The value is converted to an integer. Suffixes for kilobytes etc. are
- * allowed (powers of 1024).
- *
- * Returns 0 on succes, -1 in error cases
- */
-int set_option_parameter(QEMUOptionParameter *list, const char *name,
- const char *value)
-{
- bool flag;
- Error *local_err = NULL;
-
- // Find a matching parameter
- list = get_option_parameter(list, name);
- if (list == NULL) {
- fprintf(stderr, "Unknown option '%s'\n", name);
- return -1;
- }
-
- // Process parameter
- switch (list->type) {
- case OPT_FLAG:
- parse_option_bool(name, value, &flag, &local_err);
- if (!error_is_set(&local_err)) {
- list->value.n = flag;
- }
- break;
-
- case OPT_STRING:
- if (value != NULL) {
- list->value.s = g_strdup(value);
- } else {
- fprintf(stderr, "Option '%s' needs a parameter\n", name);
- return -1;
- }
- break;
-
- case OPT_SIZE:
- parse_option_size(name, value, &list->value.n, &local_err);
- break;
-
- default:
- fprintf(stderr, "Bug: Option '%s' has an unknown type\n", name);
- return -1;
- }
-
- if (error_is_set(&local_err)) {
- qerror_report_err(local_err);
- error_free(local_err);
- return -1;
- }
-
- list->assigned = true;
-
- return 0;
-}
-
-/*
- * Sets the given parameter to an integer instead of a string.
- * This function cannot be used to set string options.
- *
- * Returns 0 on success, -1 in error cases
- */
-int set_option_parameter_int(QEMUOptionParameter *list, const char *name,
- uint64_t value)
-{
- // Find a matching parameter
- list = get_option_parameter(list, name);
- if (list == NULL) {
- fprintf(stderr, "Unknown option '%s'\n", name);
- return -1;
- }
-
- // Process parameter
- switch (list->type) {
- case OPT_FLAG:
- case OPT_NUMBER:
- case OPT_SIZE:
- list->value.n = value;
- break;
-
- default:
- return -1;
- }
-
- list->assigned = true;
-
- return 0;
-}
-
-/*
- * Frees a option list. If it contains strings, the strings are freed as well.
- */
-void free_option_parameters(QEMUOptionParameter *list)
-{
- QEMUOptionParameter *cur = list;
-
- while (cur && cur->name) {
- if (cur->type == OPT_STRING) {
- g_free(cur->value.s);
- }
- cur++;
- }
-
- g_free(list);
-}
-
-/*
- * Count valid options in list
- */
-static size_t count_option_parameters(QEMUOptionParameter *list)
-{
- size_t num_options = 0;
-
- while (list && list->name) {
- num_options++;
- list++;
- }
-
- return num_options;
-}
-
-/*
- * Append an option list (list) to an option list (dest).
- *
- * If dest is NULL, a new copy of list is created.
- *
- * Returns a pointer to the first element of dest (or the newly allocated copy)
- */
-QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest,
- QEMUOptionParameter *list)
-{
- size_t num_options, num_dest_options;
-
- num_options = count_option_parameters(dest);
- num_dest_options = num_options;
-
- num_options += count_option_parameters(list);
-
- dest = g_realloc(dest, (num_options + 1) * sizeof(QEMUOptionParameter));
- dest[num_dest_options].name = NULL;
-
- while (list && list->name) {
- if (get_option_parameter(dest, list->name) == NULL) {
- dest[num_dest_options++] = *list;
- dest[num_dest_options].name = NULL;
- }
- list++;
- }
-
- return dest;
-}
-
static size_t count_opts_list(QemuOptsList *list)
{
QemuOptDesc *desc = NULL;
@@ -447,120 +267,6 @@ QemuOptsList *qemu_opts_append(QemuOptsList *dst,
return tmp;
}
-/*
- * Parses a parameter string (param) into an option list (dest).
- *
- * list is the template option list. If dest is NULL, a new copy of list is
- * created. If list is NULL, this function fails.
- *
- * A parameter string consists of one or more parameters, separated by commas.
- * Each parameter consists of its name and possibly of a value. In the latter
- * case, the value is delimited by an = character. To specify a value which
- * contains commas, double each comma so it won't be recognized as the end of
- * the parameter.
- *
- * For more details of the parsing see above.
- *
- * Returns a pointer to the first element of dest (or the newly allocated copy)
- * or NULL in error cases
- */
-QEMUOptionParameter *parse_option_parameters(const char *param,
- QEMUOptionParameter *list, QEMUOptionParameter *dest)
-{
- QEMUOptionParameter *allocated = NULL;
- char name[256];
- char value[256];
- char *param_delim, *value_delim;
- char next_delim;
- int i;
-
- if (list == NULL) {
- return NULL;
- }
-
- if (dest == NULL) {
- dest = allocated = append_option_parameters(NULL, list);
- }
-
- for (i = 0; dest[i].name; i++) {
- dest[i].assigned = false;
- }
-
- while (*param) {
-
- // Find parameter name and value in the string
- param_delim = strchr(param, ',');
- value_delim = strchr(param, '=');
-
- if (value_delim && (value_delim < param_delim || !param_delim)) {
- next_delim = '=';
- } else {
- next_delim = ',';
- value_delim = NULL;
- }
-
- param = get_opt_name(name, sizeof(name), param, next_delim);
- if (value_delim) {
- param = get_opt_value(value, sizeof(value), param + 1);
- }
- if (*param != '\0') {
- param++;
- }
-
- // Set the parameter
- if (set_option_parameter(dest, name, value_delim ? value : NULL)) {
- goto fail;
- }
- }
-
- return dest;
-
-fail:
- // Only free the list if it was newly allocated
- free_option_parameters(allocated);
- return NULL;
-}
-
-/*
- * Prints all options of a list that have a value to stdout
- */
-void print_option_parameters(QEMUOptionParameter *list)
-{
- while (list && list->name) {
- switch (list->type) {
- case OPT_STRING:
- if (list->value.s != NULL) {
- printf("%s='%s' ", list->name, list->value.s);
- }
- break;
- case OPT_FLAG:
- printf("%s=%s ", list->name, list->value.n ? "on" : "off");
- break;
- case OPT_SIZE:
- case OPT_NUMBER:
- printf("%s=%" PRId64 " ", list->name, list->value.n);
- break;
- default:
- printf("%s=(unknown type) ", list->name);
- break;
- }
- list++;
- }
-}
-
-/*
- * Prints an overview of all available options
- */
-void print_option_help(QEMUOptionParameter *list)
-{
- printf("Supported options:\n");
- while (list && list->name) {
- printf("%-16s %s\n", list->name,
- list->help ? list->help : "No description available");
- list++;
- }
-}
-
/* ------------------------------------------------------------------ */
static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)
@@ -1396,114 +1102,3 @@ void qemu_opts_print_help(QemuOptsList *list)
list->desc[i].help : "");
}
}
-
-/* convert QEMUOptionParameter to QemuOpts */
-QemuOptsList *params_to_opts(QEMUOptionParameter *list)
-{
- QemuOptsList *opts = NULL;
- size_t num_opts, i = 0;
-
- if (!list) {
- return NULL;
- }
-
- num_opts = count_option_parameters(list);
- opts = g_malloc0(sizeof(QemuOptsList) +
- (num_opts + 1) * sizeof(QemuOptDesc));
- QTAILQ_INIT(&opts->head);
- opts->desc[i].name = NULL;
-
- while (list && list->name) {
- opts->desc[i].name = strdup(list->name);
- opts->desc[i].help = strdup(list->help);
- switch (list->type) {
- case OPT_FLAG:
- opts->desc[i].type = QEMU_OPT_BOOL;
- opts->desc[i].def_value_str = list->value.n ? "on" : "off";
- break;
-
- case OPT_NUMBER:
- opts->desc[i].type = QEMU_OPT_NUMBER;
- if (list->value.n) {
- char tmp[100];
- sprintf(tmp, "%" PRIu64, list->value.n);
- opts->desc[i].def_value_str = strdup(tmp);
- }
- break;
-
- case OPT_SIZE:
- opts->desc[i].type = QEMU_OPT_SIZE;
- if (list->value.n) {
- char tmp[100];
- sprintf(tmp, "%" PRIu64, list->value.n);
- opts->desc[i].def_value_str = strdup(tmp);
- }
- break;
-
- case OPT_STRING:
- opts->desc[i].type = QEMU_OPT_STRING;
- if (list->value.s) {
- opts->desc[i].def_value_str = strdup(list->value.s);
- }
- break;
- }
-
- i++;
- list++;
- opts->desc[i].name = NULL;
- }
-
- return opts;
-}
-
-QEMUOptionParameter *opts_to_params(QemuOpts *opts)
-{
- QEMUOptionParameter *dest = NULL;
- QemuOptDesc *desc;
- size_t num_opts, i = 0;
- const char *tmp;
-
- if (!opts || !opts->list || !opts->list->desc) {
- return NULL;
- }
-
- num_opts = count_opts_list(opts->list);
- dest = g_malloc0((num_opts + 1) * sizeof(QEMUOptionParameter));
- dest[i].name = NULL;
-
- desc = opts->list->desc;
- while (desc && desc->name) {
- dest[i].name = strdup(desc->name);
- dest[i].help = strdup(desc->help);
- switch (desc->type) {
- case QEMU_OPT_STRING:
- dest[i].type = OPT_STRING;
- tmp = qemu_opt_get(opts, desc->name);
- if (tmp) {
- dest[i].value.s = strdup(tmp);
- }
- break;
-
- case QEMU_OPT_BOOL:
- dest[i].type = OPT_FLAG;
- dest[i].value.n = qemu_opt_get_bool(opts, desc->name, 0) ? 1 : 0;
- break;
-
- case QEMU_OPT_NUMBER:
- dest[i].type = OPT_NUMBER;
- dest[i].value.n = qemu_opt_get_number(opts, desc->name, 0);
- break;
-
- case QEMU_OPT_SIZE:
- dest[i].type = OPT_SIZE;
- dest[i].value.n = qemu_opt_get_size(opts, desc->name, 0);
- break;
- }
-
- i++;
- desc++;
- dest[i].name = NULL;
- }
-
- return dest;
-}
--
1.6.0.2
- [Qemu-devel] [PATCH v20 16/26] raw_bsd.c: replace QEMUOptionParameter with QemuOpts, (continued)
- [Qemu-devel] [PATCH v20 16/26] raw_bsd.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/02/12
- [Qemu-devel] [PATCH v20 19/26] ssh.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/02/12
- [Qemu-devel] [PATCH v20 21/26] vmdk.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/02/12
- [Qemu-devel] [PATCH v20 22/26] vpc.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/02/12
- [Qemu-devel] [PATCH v20 18/26] sheepdog.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/02/12
- [Qemu-devel] [PATCH v20 20/26] vdi.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/02/12
- [Qemu-devel] [PATCH v20 23/26] vhdx.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/02/12
- [Qemu-devel] [PATCH v20 24/26] vvfat.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/02/12
- [Qemu-devel] [PATCH v20 26/26] change back to original name from bdrv_create2 to bdrv_create, Chunyan Liu, 2014/02/12
- [Qemu-devel] [PATCH v20 25/26] cleanup QEMUOptionParameter,
Chunyan Liu <=