replace QEMUOptionParameter with QemuOpts parser
v14 cover replace QEMUOptionParameter with QemuOpts parser
These patches will replace QEMUOptionParameter with QemuOpts. Change logs please go to each patch's commit message.
Dong Xu Wang (6):
add def_value_str in QemuOptDesc struct and rewrite qemu_opts_print avoid duplication of default value in QemuOpts
Create four QemuOptsList related functions
Create some QemuOpts functons
Use QemuOpts support in block layer
remove QEMUOptionParameter related functions and struct
block.c | 98 ++++---- block/cow.c | 52 ++--- block/gluster.c | 37 ++- block/iscsi.c | 31 ++- block/qcow.c | 67 +++--- block/qcow2.c | 199 ++++++++-------- block/qed.c | 108 +++++---- block/qed.h | 2 +- block/raw-posix.c | 59 +++-- block/raw-win32.c | 31 +-- block/raw.c | 30 +-- block/rbd.c | 62 +++-- block/sheepdog.c | 81 ++++--- block/ssh.c | 29 ++- block/vdi.c | 70 +++--- block/vmdk.c | 128 ++++++----- block/vpc.c | 65 +++--- block/vvfat.c | 11 +- include/block/block.h | 5 +- include/block/block_int.h | 6 +- include/qemu/option.h | 49 ++-- qemu-img.c | 65 +++--- util/qemu-option.c | 571 +++++++++++++++++++++------------------------- 23 files changed, 903 insertions(+), 953 deletions(-)
Signature · 1 line
1.7.11.7
PATCH v14 1/6 add def_value_str in QemuOptDesc struct and rewrite qemu_opts_print
qemu_opts_print has no user now, so can re-write the function safely.
qemu_opts_print will be used while using "qemu-img create", it will produce the same output as previous code.
The behavior of this function has changed:
1. Print every possible option, whether a value has been set or not.
2. Option descriptors may provide a default value.
3. Print to stdout instead of stderr.
Previously the behavior was to print every option that has been set. Options that have not been set would be skipped.
---v13->v14:
1) fix memory leak.
2) make opt_set do not accpet null value argument.
v12->v13
1) re-write commit message.
v11->v12
1) make def_value_str become the real default value string in opt_set function.
v10->v11:
1) print all values that have actually been assigned while accept-any cases.
v7->v8:
1) print "elements => accept any params" while opts_accepts_any() == true.
2) since def_print_str is the default value if an option isn't set, so rename it to def_value_str.
include/qemu/option.h | 3 ++- util/qemu-option.c | 32 ++++++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 7 deletions(-)
include/qemu/option.h +2 -1
@@ -96,6 +96,7 @@ typedef struct QemuOptDesc {const char *name;enum QemuOptType type;const char *help; +const char *def_value_str; } QemuOptDesc;struct QemuOptsList {
@@ -152,7 +153,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); +int qemu_opts_print (QemuOpts *opts);int qemu_opts_foreach (QemuOptsList *list,qemu_opts_loopfunc func,void *opaque,int abort_on_failure);
util/qemu-option.c +26 -6
@@ -860,16 +860,36 @@ void qemu_opts_del(QemuOpts *opts)g_free (opts); } -int qemu_opts_print (QemuOpts *opts,void *dummy) +int qemu_opts_print (QemuOpts *opts) {QemuOpt *opt; +QemuOptDesc *desc = opts->list->desc; -fprintf (stderr,"%s: %s:" , opts->list->name, - opts->id ? opts->id :"<noid>" ); - QTAILQ_FOREACH(opt, &opts->head, next) { -fprintf (stderr," %s=\"%s\"" , opt->name, opt->str); +if (desc[0 ].name ==NULL ) { + QTAILQ_FOREACH(opt, &opts->head, next) { +printf ("%s=\"%s\" " , opt->name, opt->str); + } +return 0 ; + } +for (; desc && desc->name; desc++) { +const char *value = desc->def_value_str; +QemuOpt *opt; + + opt =qemu_opt_find (opts, desc->name); +if (opt) { + value = opt->str; + } + +if (!value) { +continue ; + } + +if (desc->type ==QEMU_OPT_STRING ) { +printf ("%s='%s' " , desc->name, value); + }else { +printf ("%s=%s " , desc->name, value); + } } -fprintf (stderr,"\n" );return 0 ; }
Signature · 1 line
1.7.11.7
PATCH v14 2/6 avoid duplication of default value in QemuOpts
In reply to Dong Xu WangThis patch will move the default value entirely to QemuOptDesc.
When getting the value of an option that hasn't been set, and QemuOptDesc has a default value, return that. Else, behave as before.
Example: qemu_opt_get_number(opts, "foo", 42)
If "foo" has been set in opts, return its value.
Else, if opt's QemuOptDesc has a default value for "foo", return that.
Else, return 42.
Note that the last argument is useless when QemuOptDesc has a default value. Ugly. If it bothers us, we could assert.
Example: qemu_opt_get(opts, "bar")
If "bar" has been set in opts, return its value.
Else, if opt's QemuOptDesc has a default value for "bar", return that.
Else, return NULL.
---v13->v14:
1) change code style.
2) assert errors.
util/qemu-option.c | 66 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 17 deletions(-)
util/qemu-option.c +49 -17
@@ -525,9 +525,31 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)return 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 ; +} +const char *qemu_opt_get (QemuOpts *opts,const char *name) {QemuOpt *opt =qemu_opt_find (opts, name); +const QemuOptDesc *desc; + +if (!opt) { + desc =find_desc_by_name (opts->list->desc, name); +if (desc && desc->def_value_str) { +return desc->def_value_str; + } + }return opt ? opt->str :NULL ; }
@@ -546,9 +568,17 @@ bool qemu_opt_has_help_opt(QemuOpts *opts)bool qemu_opt_get_bool (QemuOpts *opts,const char *name,bool defval) {QemuOpt *opt =qemu_opt_find (opts, name); +const QemuOptDesc *desc; +Error *local_err =NULL ; -if (opt ==NULL ) +if (opt ==NULL ) { + desc =find_desc_by_name (opts->list->desc, name); +if (desc && desc->def_value_str) { +parse_option_bool (name, desc->def_value_str, &defval, &local_err); +assert (!local_err); + }return defval; + }assert (opt->desc && opt->desc->type ==QEMU_OPT_BOOL );return opt->value.boolean; }
@@ -556,9 +586,17 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)uint64_t qemu_opt_get_number (QemuOpts *opts,const char *name,uint64_t defval) {QemuOpt *opt =qemu_opt_find (opts, name); +const QemuOptDesc *desc; +Error *local_err =NULL ; -if (opt ==NULL ) +if (opt ==NULL ) { + desc =find_desc_by_name (opts->list->desc, name); +if (desc && desc->def_value_str) { +parse_option_number (name, desc->def_value_str, &defval, &local_err); +assert (!local_err); + }return defval; + }assert (opt->desc && opt->desc->type ==QEMU_OPT_NUMBER );return opt->value.uint; }
@@ -566,9 +604,17 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)uint64_t qemu_opt_get_size (QemuOpts *opts,const char *name,uint64_t defval) {QemuOpt *opt =qemu_opt_find (opts, name); +const QemuOptDesc *desc; +Error *local_err =NULL ; -if (opt ==NULL ) +if (opt ==NULL ) { + desc =find_desc_by_name (opts->list->desc, name); +if (desc && desc->def_value_str) { +parse_option_size (name, desc->def_value_str, &defval, &local_err); +assert (!local_err); + }return defval; + }assert (opt->desc && opt->desc->type ==QEMU_OPT_SIZE );return opt->value.uint; }
@@ -609,20 +655,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 ; -} -static void opt_set (QemuOpts *opts,const char *name,const char *value,bool prepend,Error **errp) {
Signature · 1 line
1.7.11.7
PATCH v14 3/6 Create four QemuOptsList related functions
In reply to Dong Xu WangThis patch will create 4 functions, count_opts_list, qemu_opts_append, qemu_opts_free and qemu_opts_print_help, they will be used in following commits.
---v12->v13:
1) simply assert that neither argument has merge_lists set.
2) drop superfluous paranthesesis around p == first.
v11->v12:
1) renmae functions.
2) fix loop styles and code styles.
3) qemu_opts_apend will not return NULL now.
4) merge_lists value is from arguments in qemu_opts_append.
v6->v7:
1) Fix typo.
v5->v6:
1) allocate enough space in append_opts_list function.
include/qemu/option.h | 3 ++ util/qemu-option.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+)
include/qemu/option.h +3 -0
@@ -157,4 +157,7 @@ int qemu_opts_print(QemuOpts *opts);int qemu_opts_foreach (QemuOptsList *list,qemu_opts_loopfunc func,void *opaque,int abort_on_failure); +QemuOptsList *qemu_opts_append (QemuOptsList *first,QemuOptsList *second); +void qemu_opts_free (QemuOptsList *list); +void qemu_opts_print_help (QemuOptsList *list);#endif
util/qemu-option.c +82 -0
85 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH v14 4/6 Create some QemuOpts functons
In reply to Dong Xu WangThese functions will be used in next commit.
qemu_opt_get_(*)_del functions are used to make sure we have the same behaviors as before: in block layer, after parsing a parameter value, parameter list will delete it to avoid parsing it twice.
---v13->v14:
1) rewrite commit message.
2) use def_value_str in qemu_opt_get_FOO_del() and qemu_opt_get_del().
3) delete redundant qemu_opt_del(opt).
include/qemu/option.h | 11 ++++- util/qemu-option.c | 116 +++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 119 insertions(+), 8 deletions(-)
include/qemu/option.h +10 -1
@@ -108,6 +108,7 @@ struct QemuOptsList { };const char *qemu_opt_get (QemuOpts *opts,const char *name); +const char *qemu_opt_get_del (QemuOpts *opts,const char *name);/** * qemu_opt_has_help_opt: * @opts: options to search for a help request
@@ -121,13 +122,18 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name);*/ bool qemu_opt_has_help_opt (QemuOpts *opts);bool qemu_opt_get_bool (QemuOpts *opts,const char *name,bool defval); +bool qemu_opt_get_bool_del (QemuOpts *opts,const char *name,bool defval);uint64_t qemu_opt_get_number (QemuOpts *opts,const char *name,uint64_t defval);uint64_t qemu_opt_get_size (QemuOpts *opts,const char *name,uint64_t defval); +uint64_t qemu_opt_get_size_del (QemuOpts *opts,const char *name, +uint64_t defval);int qemu_opt_set (QemuOpts *opts,const char *name,const char *value); +int qemu_opt_replace_set (QemuOpts *opts,const char *name,const char *value);void qemu_opt_set_err (QemuOpts *opts,const char *name,const char *value,Error **errp);int qemu_opt_set_bool (QemuOpts *opts,const char *name,bool val);int qemu_opt_set_number (QemuOpts *opts,const char *name,int64_t val); +int qemu_opt_replace_set_number (QemuOpts *opts,const char *name,int64_t val);typedef int (*qemu_opt_loopfunc )(const char *name,const char *value,void *opaque);int qemu_opt_foreach (QemuOpts *opts,qemu_opt_loopfunc func,void *opaque,int abort_on_failure);
@@ -144,7 +150,10 @@ const char *qemu_opts_id(QemuOpts *opts);void qemu_opts_del (QemuOpts *opts);void qemu_opts_validate (QemuOpts *opts,const QemuOptDesc *desc,Error **errp);int qemu_opts_do_parse (QemuOpts *opts,const char *params,const char *firstname); -QemuOpts *qemu_opts_parse (QemuOptsList *list,const char *params,int permit_abbrev); +int qemu_opts_do_parse_replace (QemuOpts *opts,const char *params, +const char *firstname); +QemuOpts *qemu_opts_parse (QemuOptsList *list,const char *params, +int permit_abbrev);void qemu_opts_set_defaults (QemuOptsList *list,const char *params,int permit_abbrev); QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict,
util/qemu-option.c +109 -7
194 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH v14 5/6 Use QemuOpts support in block layer
In reply to Dong Xu WangThis patch will use QemuOpts related functions in block layer, add a member bdrv_create_opts to BlockDriver struct, it will return a QemuOptsList pointer, which includes the image format's create options.
And create options's primary consumer is block creating related functions, so modify them together.
---v13->v14:
1) add block/ssh.c support.
2) fix memory leak after using qemu_opt_get_del.
v12->v13:
1) split into 2 patches. one for block, one for QemuOpts funcitons.
2) fix leaking cco->opts.
3) other small fix.
v11->v12:
1) create functions, such as qemu_opt_get_del and qemu_opt_replace_set. These functions works like origin code.
2) use QEMU_OPT_SIZE, not QEMU_OPT_NUMBER.
3) in bdrv_create, if opts is NULL, will create an empty one, so can discard if(opts) code safely.
v10->v11:
1) qed.h move QED_DEFAULT_CLUSTER_SIZE from enum to macro, or qemu_opts_print produce un-expanded cluster_size.
2) In qcow2.c and qcow.c, bdrv_create_file(filename, NULL), NULL -> opts,
or while using protocol, there will be an error.
v8->v9:
1) add qemu_ prefix to gluster_create_opts.
2) fix bug: bdrv_gluster_unix and bdrv_gluster_rdma should also be converted.
v7->v8:
1) rebase to upstream source tree.
2) add gluster.c, raw-win32.c, and rbd.c.
v6->v7:
1) use osdep.h:stringify(), not redefining new macro.
2) preserve TODO comment.
3) fix typo. BLOCK_OPT_ENCRYPT->BLOCK_OPT_STATIC.
4) initialize disk_type even when opts is NULL.
v5->v6:
1) judge if opts == NULL in block layer create functions.
2) use bdrv_create_file(filename, NULL) in qcow_create and cow_create funtion.
3) made more readable while using qemu_opt_get_number.
block.c | 98 +++++++++++------------ block/cow.c | 52 ++++++------ block/gluster.c | 37 +++++---- block/iscsi.c | 31 ++++---- block/qcow.c | 67 ++++++++-------- block/qcow2.c | 199 +++++++++++++++++++++++++--------------------- block/qed.c | 108 +++++++++++++------------ block/qed.h | 2 +- block/raw-posix.c | 59 ++++++-------- block/raw-win32.c | 31 ++++---- block/raw.c | 30 ++++--- block/rbd.c | 62 +++++++-------- block/sheepdog.c | 81 +++++++++---------- block/ssh.c | 29 ++++--- block/vdi.c | 70 ++++++++-------- block/vmdk.c | 128 +++++++++++++++-------------- block/vpc.c | 65 ++++++++------- block/vvfat.c | 11 +-- include/block/block.h | 5 +- include/block/block_int.h | 6 +- qemu-img.c | 65 ++++++++------- 21 files changed, 627 insertions(+), 609 deletions(-)
block.c +46 -52
@@ -355,7 +355,7 @@ BlockDriver *bdrv_find_whitelisted_format(const char *format_name)typedef struct CreateCo {BlockDriver *drv;char *filename; -QEMUOptionParameter *options; +QemuOpts *opts;int ret; }CreateCo ;
@@ -364,11 +364,10 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)CreateCo *cco = opaque;assert (cco->drv); - cco->ret = cco->drv->bdrv_create (cco->filename, cco->options); + cco->ret = cco->drv->bdrv_create (cco->filename, cco->opts); } -int bdrv_create (BlockDriver *drv,const char * filename, -QEMUOptionParameter *options) +int bdrv_create (BlockDriver *drv,const char * filename,QemuOpts *opts) {int ret;
@@ -376,7 +375,7 @@ int bdrv_create(BlockDriver *drv, const char* filename,CreateCo cco = { .drv = drv, .filename =g_strdup (filename), - .options = options, + .opts = opts ?:qemu_opts_create_nofail (drv->bdrv_create_opts), .ret =NOT_DONE , };
@@ -399,11 +398,14 @@ int bdrv_create(BlockDriver *drv, const char* filename, ret = cco.ret; out: +if (!opts) { +qemu_opts_del (cco.opts); + }g_free (cco.filename);return ret; } -int bdrv_create_file (const char * filename,QEMUOptionParameter *options) +int bdrv_create_file (const char *filename,QemuOpts *opts) {BlockDriver *drv;
@@ -412,7 +414,7 @@ int bdrv_create_file(const char* filename, QEMUOptionParameter *options)return -ENOENT ; } -return bdrv_create (drv, filename, options); +return bdrv_create (drv, filename, opts); }/*
@@ -968,7 +970,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,BlockDriverState *bs1;int64_t total_size;BlockDriver *bdrv_qcow2; -QEMUOptionParameter *create_options; +QemuOpts *opts;char backing_filename[PATH_MAX ];if (qdict_size (options) !=0 ) {
@@ -1007,19 +1009,16 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, } bdrv_qcow2 =bdrv_find_format ("qcow2" ); - create_options =parse_option_parameters ("" , bdrv_qcow2->create_options, -NULL ); + opts =qemu_opts_create_nofail (bdrv_qcow2->bdrv_create_opts); -set_option_parameter_int (create_options,BLOCK_OPT_SIZE , total_size); -set_option_parameter (create_options,BLOCK_OPT_BACKING_FILE , - backing_filename); +qemu_opt_set_number (opts,BLOCK_OPT_SIZE , total_size); +qemu_opt_set (opts,BLOCK_OPT_BACKING_FILE , backing_filename);if (drv) { -set_option_parameter (create_options,BLOCK_OPT_BACKING_FMT , - drv->format_name); +qemu_opt_set (opts,BLOCK_OPT_BACKING_FMT , drv->format_name); } - ret =bdrv_create (bdrv_qcow2, tmp_filename, create_options); -free_option_parameters (create_options); + ret =bdrv_create (bdrv_qcow2, tmp_filename, opts); +qemu_opts_del (opts);if (ret <0 ) { goto fail; }
@@ -4738,8 +4737,10 @@ 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; + QemuOpts *opts = NULL; +QemuOptsList *create_opts =NULL ; +const char *backing_fmt, *backing_file; +int64_t size;BlockDriverState *bs =NULL ;BlockDriver *drv, *proto_drv;BlockDriver *backing_drv =NULL ;
@@ -4757,28 +4758,23 @@ void bdrv_img_create(const char *filename, const char *fmt,error_setg (errp,"Unknown protocol '%s'" , filename);return ; } - - create_options =append_option_parameters (create_options, - drv->create_options); - create_options =append_option_parameters (create_options, - proto_drv->create_options); - + create_opts =qemu_opts_append (drv->bdrv_create_opts, + proto_drv->bdrv_create_opts);/* Create parameter list with default values */ - param =parse_option_parameters ("" , create_options, param); + opts =qemu_opts_create_nofail (create_opts); -set_option_parameter_int (param,BLOCK_OPT_SIZE , img_size); +qemu_opt_set_number (opts,BLOCK_OPT_SIZE , img_size);/* Parse -o options */ if (options) { - param =parse_option_parameters (options, create_options, param); -if (param ==NULL ) { +if (qemu_opts_do_parse_replace (opts, options,NULL ) !=0 ) {error_setg (errp,"Invalid options for file format '%s'." , fmt); goto out; } }if (base_filename) { -if (set_option_parameter (param,BLOCK_OPT_BACKING_FILE , +if (qemu_opt_replace_set (opts,BLOCK_OPT_BACKING_FILE , base_filename)) {error_setg (errp,"Backing file not supported for file format '%s'" , fmt);
@@ -4787,39 +4783,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)) { +if (qemu_opt_replace_set (opts,BLOCK_OPT_BACKING_FMT , base_fmt)) {error_setg (errp,"Backing file format not supported for file " "format '%s'" , fmt); goto out; } } - backing_file =get_option_parameter (param,BLOCK_OPT_BACKING_FILE ); -if (backing_file && backing_file->value.s) { -if (!strcmp (filename, backing_file->value.s)) { + backing_file =qemu_opt_get (opts,BLOCK_OPT_BACKING_FILE ); +if (backing_file) { +if (!strcmp (filename, backing_file)) {error_setg (errp,"Error: Trying to create an image with the " "same filename as the backing file" ); goto out; } } - backing_fmt =get_option_parameter (param,BLOCK_OPT_BACKING_FMT ); -if (backing_fmt && backing_fmt->value.s) { - backing_drv =bdrv_find_format (backing_fmt->value.s); + backing_fmt =qemu_opt_get (opts,BLOCK_OPT_BACKING_FMT ); +if (backing_fmt) { + backing_drv =bdrv_find_format (backing_fmt);if (!backing_drv) { -error_setg (errp,"Unknown backing file format '%s'" , - backing_fmt->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 (opts,BLOCK_OPT_SIZE ,0 ); +if (size ==-1 ) { +if (backing_file) {uint64_t size; -char buf[32 ];int back_flags;/* backing files always opened read-only */
@@ -4828,18 +4822,16 @@ void bdrv_img_create(const char *filename, const char *fmt, bs =bdrv_new ("" ); - ret =bdrv_open (bs, backing_file->value.s,NULL , back_flags, - backing_drv); + ret =bdrv_open (bs, backing_file,NULL , back_flags, backing_drv);if (ret <0 ) {error_setg_errno (errp, -ret,"Could not open '%s'" , - backing_file->value.s); + backing_file); goto out; }bdrv_get_geometry (bs, &size); size *=512 ; -snprintf (buf,sizeof (buf),"%" PRId64, size); -set_option_parameter (param,BLOCK_OPT_SIZE , buf); +qemu_opt_replace_set_number (opts,BLOCK_OPT_SIZE , size); }else {error_setg (errp,"Image creation needs a size parameter" ); goto out;
@@ -4848,10 +4840,10 @@ void bdrv_img_create(const char *filename, const char *fmt,if (!quiet) {printf ("Formatting '%s', fmt=%s " , filename, fmt); -print_option_parameters (param); +qemu_opts_print (opts);puts ("" ); } - ret =bdrv_create (drv, filename, param); + ret =bdrv_create (drv, filename, opts);if (ret <0 ) {if (ret == -ENOTSUP ) { error_setg(errp,"Formatting or formatting option not supported for "
@@ -4866,8 +4858,10 @@ void bdrv_img_create(const char *filename, const char *fmt, } out: -free_option_parameters (create_options); -free_option_parameters (param); +if (opts) { +qemu_opts_del (opts); + } +qemu_opts_free (create_opts);if (bs) {bdrv_delete (bs);
block/cow.c +26 -26
85 lines not on this page · raw message
block/gluster.c +18 -19
@@ -365,8 +365,7 @@ out:return ret; } -static int qemu_gluster_create (const char *filename, -QEMUOptionParameter *options) +static int qemu_gluster_create (const char *filename,QemuOpts *opts) {struct glfs *glfs;struct glfs_fd *fd;
@@ -380,12 +379,8 @@ static int qemu_gluster_create(const char *filename, goto out; } -while (options && options->name) { -if (!strcmp (options->name,BLOCK_OPT_SIZE )) { - total_size = options->value.n /BDRV_SECTOR_SIZE ; - } - options++; - } + total_size = +qemu_opt_get_size_del (opts,BLOCK_OPT_SIZE ,0 ) /BDRV_SECTOR_SIZE ; fd =glfs_creat (glfs, gconf->image,O_WRONLY |O_CREAT |O_TRUNC |O_BINARY ,S_IRUSR |S_IWUSR );
@@ -574,13 +569,17 @@ static void qemu_gluster_close(BlockDriverState *bs)glfs_fini (s->glfs); } -static QEMUOptionParameter qemu_gluster_create_options[] = { - { - .name =BLOCK_OPT_SIZE , - .type =OPT_SIZE , - .help ="Virtual disk size" - }, - {NULL } +static QemuOptsList qemu_gluster_create_opts = { + .name ="qemu-gluster-create-opts" , + .head =QTAILQ_HEAD_INITIALIZER (qemu_gluster_create_opts.head), + .desc = { + { + .name =BLOCK_OPT_SIZE , + .type =QEMU_OPT_SIZE , + .help ="Virtual disk size" + }, + {/* end of list */ } + } };static BlockDriver bdrv_gluster = {
@@ -595,7 +594,7 @@ static BlockDriver bdrv_gluster = { .bdrv_aio_readv = qemu_gluster_aio_readv, .bdrv_aio_writev = qemu_gluster_aio_writev, .bdrv_aio_flush = qemu_gluster_aio_flush, - .create_options = qemu_gluster_create_options, + .bdrv_create_opts = &qemu_gluster_create_opts, };static BlockDriver bdrv_gluster_tcp = {
@@ -610,7 +609,7 @@ static BlockDriver bdrv_gluster_tcp = { .bdrv_aio_readv = qemu_gluster_aio_readv, .bdrv_aio_writev = qemu_gluster_aio_writev, .bdrv_aio_flush = qemu_gluster_aio_flush, - .create_options = qemu_gluster_create_options, + .bdrv_create_opts = &qemu_gluster_create_opts, };static BlockDriver bdrv_gluster_unix = {
@@ -625,7 +624,7 @@ static BlockDriver bdrv_gluster_unix = { .bdrv_aio_readv = qemu_gluster_aio_readv, .bdrv_aio_writev = qemu_gluster_aio_writev, .bdrv_aio_flush = qemu_gluster_aio_flush, - .create_options = qemu_gluster_create_options, + .bdrv_create_opts = &qemu_gluster_create_opts, };static BlockDriver bdrv_gluster_rdma = {
@@ -640,7 +639,7 @@ static BlockDriver bdrv_gluster_rdma = { .bdrv_aio_readv = qemu_gluster_aio_readv, .bdrv_aio_writev = qemu_gluster_aio_writev, .bdrv_aio_flush = qemu_gluster_aio_flush, - .create_options = qemu_gluster_create_options, + .bdrv_create_opts = &qemu_gluster_create_opts, };static void bdrv_gluster_init (void )
block/iscsi.c +15 -16
@@ -1213,7 +1213,7 @@ static int iscsi_has_zero_init(BlockDriverState *bs)return 0 ; } -static int iscsi_create (const char *filename,QEMUOptionParameter *options) +static int iscsi_create (const char *filename,QemuOpts *opts) {int ret =0 ;int64_t total_size =0 ;
@@ -1224,13 +1224,8 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options)memset (&bs,0 ,sizeof (BlockDriverState));/* Read out options */ -while (options && options->name) { -if (!strcmp (options->name,"size" )) { - total_size = options->value.n /BDRV_SECTOR_SIZE ; - } - options++; - } - + total_size = +qemu_opt_get_size_del (opts,BLOCK_OPT_SIZE ,0 ) /BDRV_SECTOR_SIZE ; bs.opaque =g_malloc0 (sizeof (struct IscsiLun )); iscsilun = bs.opaque;
@@ -1263,13 +1258,17 @@ out:return ret; } -static QEMUOptionParameter iscsi_create_options[] = { - { - .name =BLOCK_OPT_SIZE , - .type =OPT_SIZE , - .help ="Virtual disk size" - }, - {NULL } +static QemuOptsList iscsi_create_opts = { + .name ="iscsi-create-opts" , + .head =QTAILQ_HEAD_INITIALIZER (iscsi_create_opts.head), + .desc = { + { + .name =BLOCK_OPT_SIZE , + .type =QEMU_OPT_SIZE , + .help ="Virtual disk size" + }, + {/* end of list */ } + } };static BlockDriver bdrv_iscsi = {
@@ -1280,7 +1279,7 @@ static BlockDriver bdrv_iscsi = { .bdrv_file_open = iscsi_open, .bdrv_close = iscsi_close, .bdrv_create = iscsi_create, - .create_options = iscsi_create_options, + .bdrv_create_opts = &iscsi_create_opts, .bdrv_getlength = iscsi_getlength, .bdrv_truncate = iscsi_truncate,
block/qcow.c +34 -33
104 lines not on this page · raw message
block/qcow2.c +108 -91
269 lines not on this page · raw message
block/qed.c +59 -49
162 lines not on this page · raw message
block/qed.h +1 -1
@@ -43,6 +43,7 @@* * All fields are little-endian on disk. */ +#define QED_DEFAULT_CLUSTER_SIZE 65536enum {QED_MAGIC ='Q' |'E' <<8 |'D' <<16 |'\0' <<24 ,
@@ -69,7 +70,6 @@ enum {*/ QED_MIN_CLUSTER_SIZE =4 *1024 ,/* in bytes */ QED_MAX_CLUSTER_SIZE = 64 * 1024 * 1024, -QED_DEFAULT_CLUSTER_SIZE =64 *1024 ,/* Allocated clusters are tracked using a 2-level pagetable. Table size is * a multiple of clusters so large maximum image sizes can be supported
block/raw-posix.c +26 -33
150 lines not on this page · raw message
block/raw-win32.c +16 -15
@@ -420,18 +420,15 @@ static int64_t raw_get_allocated_file_size(BlockDriverState *bs)return st.st_size; } -static int raw_create (const char *filename,QEMUOptionParameter *options) +static int raw_create (const char *filename,QemuOpts *opts) {int fd;int64_t total_size =0 ;/* Read out options */ -while (options && options->name) { -if (!strcmp (options->name,BLOCK_OPT_SIZE )) { - total_size = options->value.n /512 ; - } - options++; - } + + total_size = +qemu_opt_get_size_del (opts,BLOCK_OPT_SIZE ,0 ) /512 ; fd =qemu_open (filename,O_WRONLY |O_CREAT |O_TRUNC |O_BINARY ,0644 );
@@ -443,13 +440,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" - }, - {NULL } +static QemuOptsList raw_create_opts = { + .name ="raw-create-opts" , + .head =QTAILQ_HEAD_INITIALIZER (raw_create_opts.head), + .desc = { + { + .name =BLOCK_OPT_SIZE , + .type =QEMU_OPT_SIZE , + .help ="Virtual disk size" + }, + {/* end of list */ } + } };static BlockDriver bdrv_file = {
@@ -469,7 +470,7 @@ static BlockDriver bdrv_file = { .bdrv_get_allocated_file_size = raw_get_allocated_file_size, - .create_options = raw_create_options, + .bdrv_create_opts = &raw_create_opts, };/***********************************************/
block/raw.c +17 -13
@@ -95,18 +95,22 @@ static BlockDriverAIOCB *raw_aio_ioctl(BlockDriverState *bs,return bdrv_aio_ioctl (bs->file, req, buf, cb, opaque); } -static int raw_create (const char *filename,QEMUOptionParameter *options) -{ -return bdrv_create_file (filename, options); -} - -static QEMUOptionParameter raw_create_options[] = { - { - .name =BLOCK_OPT_SIZE , - .type =OPT_SIZE , - .help ="Virtual disk size" - }, - {NULL } +static int raw_create (const char *filename,QemuOpts *opts) +{ +return bdrv_create_file (filename, opts); +} + +static QemuOptsList raw_create_opts = { + .name ="raw-create-opts" , + .head =QTAILQ_HEAD_INITIALIZER (raw_create_opts.head), + .desc = { + { + .name =BLOCK_OPT_SIZE , + .type =QEMU_OPT_SIZE , + .help ="Virtual disk size" + }, + {/* end of list */ } + } };static int raw_has_zero_init (BlockDriverState *bs)
@@ -143,8 +147,8 @@ static BlockDriver bdrv_raw = { .bdrv_aio_ioctl = raw_aio_ioctl, .bdrv_create = raw_create, - .create_options = raw_create_options, .bdrv_has_zero_init = raw_has_zero_init, + .bdrv_create_opts = &raw_create_opts, };static void bdrv_raw_init (void )
block/rbd.c +30 -32
88 lines not on this page · raw message
block/sheepdog.c +39 -42
134 lines not on this page · raw message
block/ssh.c +14 -15
@@ -641,16 +641,20 @@ static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags)return ret; } -static QEMUOptionParameter ssh_create_options[] = { - { - .name =BLOCK_OPT_SIZE , - .type =OPT_SIZE , - .help ="Virtual disk size" - }, - {NULL } +static QemuOptsList ssh_create_opts = { + .name ="ssh-create-opts" , + .head =QTAILQ_HEAD_INITIALIZER (ssh_create_opts.head), + .desc = { + { + .name =BLOCK_OPT_SIZE , + .type =QEMU_OPT_SIZE , + .help ="Virtual disk size" + }, + {/* end of list */ } + } }; -static int ssh_create (const char *filename,QEMUOptionParameter *options) +static int ssh_create (const char *filename,QemuOpts *opts) {int r, ret;Error *local_err =NULL ;
@@ -663,12 +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_del (opts,BLOCK_OPT_SIZE ,0 );DPRINTF ("total_size=%" PRIi64, total_size); uri_options =qdict_new ();
@@ -1041,7 +1040,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, + .bdrv_create_opts = &ssh_create_opts, };static void bdrv_ssh_init (void )
block/vdi.c +34 -36
102 lines not on this page · raw message
block/vmdk.c +68 -60
192 lines not on this page · raw message
block/vpc.c +35 -30
108 lines not on this page · raw message
block/vvfat.c +6 -5
@@ -2907,7 +2907,7 @@ static BlockDriver vvfat_write_target = {static int enable_write_target (BDRVVVFATState *s) {BlockDriver *bdrv_qcow; -QEMUOptionParameter *options; +QemuOpts *opts;int ret;int size =sector2cluster (s, s->sector_count); s->used_clusters =calloc (size,1 );
@@ -2923,12 +2923,13 @@ static int enable_write_target(BDRVVVFATState *s) } bdrv_qcow =bdrv_find_format ("qcow" ); - options =parse_option_parameters ("" , bdrv_qcow->create_options,NULL ); -set_option_parameter_int (options,BLOCK_OPT_SIZE , s->sector_count *512 ); -set_option_parameter (options,BLOCK_OPT_BACKING_FILE ,"fat:" ); + opts =qemu_opts_create_nofail (bdrv_qcow->bdrv_create_opts); +qemu_opt_set_number (opts,BLOCK_OPT_SIZE , s->sector_count *512 ); +qemu_opt_set (opts,BLOCK_OPT_BACKING_FILE ,"fat:" ); -if (bdrv_create (bdrv_qcow, s->qcow_filename, options) <0 ) +if (bdrv_create (bdrv_qcow, s->qcow_filename, opts) <0 ) {return -1 ; + } s->qcow =bdrv_new ("" );if (s->qcow ==NULL ) {
include/block/block.h +2 -3
@@ -125,9 +125,8 @@ void bdrv_init_with_whitelist(void);BlockDriver *bdrv_find_protocol (const char *filename);BlockDriver *bdrv_find_format (const char *format_name);BlockDriver *bdrv_find_whitelisted_format (const char *format_name); -int bdrv_create (BlockDriver *drv,const char * filename, -QEMUOptionParameter *options); -int bdrv_create_file (const char * filename,QEMUOptionParameter *options); +int bdrv_create (BlockDriver *drv,const char * filename,QemuOpts *opts); +int bdrv_create_file (const char *filename,QemuOpts *opts);BlockDriverState *bdrv_new (const char *device_name);void bdrv_make_anon (BlockDriverState *bs);void bdrv_swap (BlockDriverState *bs_new,BlockDriverState *bs_old);
include/block/block_int.h +2 -4
@@ -94,7 +94,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); +int (*bdrv_create)(const char *filename,QemuOpts *opts);int (*bdrv_set_key)(BlockDriverState *bs,const char *key);int (*bdrv_make_empty)(BlockDriverState *bs);/* aio */
@@ -183,9 +183,7 @@ struct BlockDriver { unsigned long int req, void *buf, BlockDriverCompletionFunc *cb, void *opaque); -/* List of options for creating images, terminated by name == NULL */ -QEMUOptionParameter *create_options; - +QemuOptsList *bdrv_create_opts;/* * Returns 0 for completed check, -errno for internal errors.
qemu-img.c +31 -34
147 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH v14 6/6 remove QEMUOptionParameter related functions and struct
In reply to Dong Xu Wang--- include/qemu/option.h | 32 ------ util/qemu-option.c | 285 -------------------------------------------------- 2 files changed, 317 deletions(-)
include/qemu/option.h +0 -32
@@ -38,17 +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; -}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,
@@ -58,27 +47,6 @@ int get_param_value(char *buf, int buf_size,int check_params (char *buf,int buf_size,const char *const *params,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 free_option_parameters (QEMUOptionParameter *list); -void print_option_parameters (QEMUOptionParameter *list); -void print_option_help (QEMUOptionParameter *list); -/* ------------------------------------------------------------------ */ typedef struct QemuOpt QemuOpt ;
util/qemu-option.c +0 -285
297 lines not on this page · raw message
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH V14 6/6] remove QEMUOptionParameter related functions and struct
[assuming you mis-typed your cc:, and that you meant kwolf instead of kwol at redhat]
Quoted 11 lines · Dong Xu Wang
Signed-off-by Dong Xu Wang <[email protected]>--- include/qemu/option.h | 32 ------ util/qemu-option.c | 285 ----- --------------------------------------------- 2 files changed, 317 deletions(-)include/qemu/option.h +0
-0
include/qemu/option.h enum QEMUOptionParType { · line 43
Quoted 6 lines
include/qemu/option.h +0
-3@@ -38,17 +38,6 @@ enum QEMUOptionParType { OPT_STRING, }; -typedef struct QEMUOptionParameter { - const char *name; - enum QEMUOptionParType type;
'enum QEMUOptionParType' several lines earlier is now unused; you should clean that too.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH V14 6/6] remove QEMUOptionParameter related functions and struct
Quoted 18 lines · Eric Blake
[assuming you mis-typed your cc:, and that you meant kwolf instead of kwol at redhat]
Quoted 14 lines · Dong Xu Wang
Signed-off-by Dong Xu Wang <[email protected]>--- include/qemu/option.h | 32 ------ util/qemu-option.c | 285 ----- --------------------------------------------- 2 files changed, 317 deletions(-)include/qemu/option.h +0
-0@@ -38,17 +38,6 @@ enum QEMUOptionParType { OPT_STRING, };
Quoted 7 lines
include/qemu/option.h enum QEMUOptionParType { · line 43
Quoted 3 lines
include/qemu/option.h +0
-3-typedef struct QEMUOptionParameter { - const char *name; - enum QEMUOptionParType type;'enum QEMUOptionParType' several lines earlier is now unused; you should clean that too.
Yes, will remove it after reviewing, thank you, Eric.