Skip to contentSkip to conversation

replace QEMUOptionParameter with QemuOpts

PATCH Superseded Chunyan Liu 7 participants 105 messages Mar 10, 2014 – Apr 3, 2014 Block layer

v22 of 28 Superseded Latest is v28 →

lore
Share & tools
lore
#0 lore raw

v22 cover replace QEMUOptionParameter with QemuOpts

This patch series is to replace QEMUOptionParameter with QemuOpts, so that only one Qemu Option structure is kept in QEMU code.

---
Changes to v21:
* update verison info in patch 2/25
* others are not changed except for rebase

Chunyan Liu (25):
add def_value_str to QemuOptDesc
qapi: output def_value_str when query command line options improve some functions in qemu-option.c
improve assertion in qemu_opt_get functions
add some QemuOpts functions for replace work
add convert functions between QEMUOptionParameter to QemuOpts change block layer to support both QemuOpts and QEMUOptionParamter cow.c: replace QEMUOptionParameter with QemuOpts gluster.c: replace QEMUOptionParameter with QemuOpts iscsi.c: replace QEMUOptionParameter with QemuOpts qcow.c: replace QEMUOptionParameter with QemuOpts qcow2.c: replace QEMUOptionParameter with QemuOpts qed.c: replace QEMUOptionParameter with QemuOpts raw-posix.c: replace QEMUOptionParameter with QemuOpts raw-win32.c: replace QEMUOptionParameter with QemuOpts raw_bsd.c: replace QEMUOptionParameter with QemuOpts rbd.c: replace QEMUOptionParameter with QemuOpts sheepdog.c: replace QEMUOptionParameter with QemuOpts ssh.c: replace QEMUOptionParameter with QemuOpts
vdi.c: replace QEMUOptionParameter with QemuOpts vmdk.c: replace QEMUOptionParameter with QemuOpts vpc.c: replace QEMUOptionParameter with QemuOpts vhdx.c: replace QEMUOptionParameter with QemuOpts vvfat.c: replace QEMUOptionParameter with QemuOpts cleanup QEMUOptionParameter

 block.c                   |  96 ++++----
 block/cow.c               |  52 ++---
 block/gluster.c           |  73 +++---
 block/iscsi.c             |  29 ++-
 block/qcow.c              |  72 +++---
 block/qcow2.c             | 325 +++++++++++++-------------
 block/qed.c               | 112 ++++-----
 block/qed.h               |   3 +-
 block/raw-posix.c         |  55 ++---
 block/raw-win32.c         |  38 +--
 block/raw_bsd.c           |  25 +-
 block/rbd.c               |  61 +++--
 block/sheepdog.c          | 102 ++++----
 block/ssh.c               |  30 ++-
 block/vdi.c               |  70 +++---
 block/vhdx.c              |  97 ++++----
 block/vhdx.h              |   1 +
 block/vmdk.c              | 121 +++++-----
 block/vpc.c               |  60 ++---
 block/vvfat.c             |  10 +-
 include/block/block.h     |   7 +-
 include/block/block_int.h |   9 +-
 include/qemu/option.h     |  56 +----
 include/qemu/option_int.h |   4 +-
 qapi-schema.json          |   6 +-
 qemu-img.c                |  89 ++++---
 qmp-commands.hx           |   2 +
 util/qemu-config.c        |   4 +
 util/qemu-option.c        | 576 ++++++++++++++++++++++------------------------
 29 files changed, 1060 insertions(+), 1125 deletions(-)
Signature · 1 line
1.7.12.4
#1 lore raw

PATCH v22 1/25 add def_value_str to QemuOptDesc

Add def_value_str (default value) to QemuOptDesc, to replace function of the default value in QEMUOptionParameter. And improved related functions.

---
 include/qemu/option.h |  3 ++-
 util/qemu-option.c    | 59 +++++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 52 insertions(+), 10 deletions(-)
include/qemu/option.h +2 -1
index 8c0ac34..c3b0a91 100644
@@ -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);
 
util/qemu-option.c +50 -9

103 lines not on this page · raw message

Signature · 1 line
1.7.12.4
Reviewed-by on v22 1/25
#2 lore raw

Re: [Qemu-devel] [PATCH v22 01/25] add def_value_str to QemuOptDesc

Quoted 13 lines · Chunyan Liu

Add def_value_str (default value) to QemuOptDesc, to replace function of the default value in QEMUOptionParameter. And improved related functions.

---
 include/qemu/option.h |  3 ++-
 util/qemu-option.c    | 59 +++++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 52 insertions(+), 10 deletions(-)

+++ b/util/qemu-option.c

util/qemu-option.c line 37

Quoted 5 lines
util/qemu-option.c +2 -0
@@ -33,6 +33,9 @@
 #include "qapi/qmp/qerror.h"
 #include "qemu/option_int.h"
 
+static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
+                                            const char *name);

I tend to avoid forward-declaration of static functions, except when true mutual recursion is required - when I read a file, it's nicer to see the smaller building blocks up front instead of having to skip to the bottom to see what they do. Do you need a forward-declaration, or can you split this into two patches, one that does just code motion to hoist find_desc_by_name() earlier, and the second to make use of it in correct topological order?

But what you have is correct, so if you don't have a reason to respin for anything else,

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#4 lore raw

Re: [Qemu-devel] [PATCH v22 01/25] add def_value_str to QemuOptDesc

2014-03-11 21:29 GMT+08:00 Stefan Hajnoczi <[email protected]>:

Quoted 9 lines · Chunyan Liu
Quoted 1 line

Add def_value_str (default value) to QemuOptDesc, to replace function of

the

Quoted 3 lines

default value in QEMUOptionParameter. And improved related functions.

The address should be <[email protected]>.

Seems this address is not valid now, so when sending patches with git send-email, it's
changed to be <address@hidden> automatically.

Quoted 3 lines

Stefan

#5 lore raw

Re: [Qemu-devel] [PATCH v22 01/25] add def_value_str to QemuOptDesc

Quoted 7 lines · Chunyan Liu

2014-03-11 21:29 GMT+08:00 Stefan Hajnoczi <[email protected]>:

Quoted 5 lines · Chunyan Liu
Quoted 1 line

Add def_value_str (default value) to QemuOptDesc, to replace function of

the

Quoted 2 lines

default value in QEMUOptionParameter. And improved related functions.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

The address should be <[email protected]>.

Seems this address is not valid now, so when sending patches with git send-email, it's
changed to be <address@hidden> automatically.

That sounds weird. Are you sure it's not because you grabbed the patches from a web mailing list archive that hides email address to avoid spammers?

See git-send-email(1) --suppress-cc to avoid sending the patch to his old address. Since we don't have a new address, please keep [email protected].

Stefan

#6 lore raw

Re: [Qemu-devel] [PATCH v22 01/25] add def_value_str to QemuOptDesc

2014-03-12 16:27 GMT+08:00 Stefan Hajnoczi <[email protected]>:

Quoted 14 lines · Chunyan Liu
Quoted 4 lines

2014-03-11 21:29 GMT+08:00 Stefan Hajnoczi <[email protected]>:

Quoted 2 lines · Chunyan Liu
Quoted 1 line

Add def_value_str (default value) to QemuOptDesc, to replace

function of

Quoted 8 lines
Quoted 7 lines

the

Quoted 3 lines

default value in QEMUOptionParameter. And improved related functions.

The address should be <[email protected]>.

Quoted 8 lines
Quoted 3 lines

Seems this address is not valid now, so when sending patches with git send-email, it's
changed to be <address@hidden> automatically.

That sounds weird. Are you sure it's not because you grabbed the patches from a web mailing list archive that hides email address to avoid spammers?

Absolutely no. In previous version, no such problem. Only in this version, while
doing "git send-email", got the message about "email delivery failed", and the
address changed. I'll still keep this address in new version patch series:
[email protected]

Quoted 5 lines

See git-send-email(1) --suppress-cc to avoid sending the patch to his old address. Since we don't have a new address, please keep [email protected].

OK.

Quoted 4 lines

Stefan

#7 lore raw

Re: [Qemu-devel] [PATCH v22 01/25] add def_value_str to QemuOptDesc

Quoted 25 lines · Chunyan Liu

2014-03-12 16:27 GMT+08:00 Stefan Hajnoczi <[email protected]>:

Quoted 14 lines · Chunyan Liu
Quoted 4 lines

2014-03-11 21:29 GMT+08:00 Stefan Hajnoczi <[email protected]>:

Quoted 2 lines · Chunyan Liu
Quoted 1 line

Add def_value_str (default value) to QemuOptDesc, to replace

function of

Quoted 8 lines
Quoted 7 lines

the

Quoted 3 lines

default value in QEMUOptionParameter. And improved related functions.

The address should be <[email protected]>.

Quoted 8 lines
Quoted 3 lines

Seems this address is not valid now, so when sending patches with git send-email, it's
changed to be <address@hidden> automatically.

That sounds weird. Are you sure it's not because you grabbed the patches from a web mailing list archive that hides email address to avoid spammers?

Quoted 6 lines

Absolutely no. In previous version, no such problem. Only in this version, while
doing "git send-email", got the message about "email delivery failed", and the
address changed. I'll still keep this address in new version patch series:
[email protected]

I don't think the change comes from git:

$ git clone https://github.com/git/git.git
$ cd git && git grep 'address@hidden'

(Even grepping for 'hidden' doesn't show any relevant hits.)

I'm on CC list for these patches, so the emails are sent directly to my SMTP server. Since they go directly and not via the mailing list, we can eliminate the mailing list software.

The mailing list archive also shows <address@hidden> so that eliminates my SMTP server:
http://article.gmane.org/gmane.comp.emulators.qemu/260626

Do you see <address@hidden> in git-log(1)?

If yes, then maybe it's possible to track it down via git-reflog(1). If no, then it's happening while the mail is being sent.

Stefan

#8 lore raw

PATCH v22 2/25 qapi: output def_value_str when query command line options

In reply to Chunyan Liu

Change qapi interfaces to output the newly added def_value_str when querying command line options.

---
 qapi-schema.json   | 6 +++++-
 qmp-commands.hx    | 2 ++
 util/qemu-config.c | 4 ++++
 3 files changed, 11 insertions(+), 1 deletion(-)
qapi-schema.json +5 -1
index 6c381b7..f37834e 100644
@@ -4059,12 +4059,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:
qmp-commands.hx +2 -0
index d982cd6..94e8f9f 100644
@@ -2856,6 +2856,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:
 
util/qemu-config.c +4 -0
index f610101..d608b2f 100644
@@ -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;
Signature · 1 line
1.7.12.4
Reviewed-by on v22 2/25
#9 lore raw

Re: [Qemu-devel] [PATCH v22 02/25] qapi: output def_value_str when query command line options

Quoted 11 lines · Chunyan Liu

Change qapi interfaces to output the newly added def_value_str when querying command line options.

---
 qapi-schema.json   | 6 +++++-
 qmp-commands.hx    | 2 ++
 util/qemu-config.c | 4 ++++
 3 files changed, 11 insertions(+), 1 deletion(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#10 lore raw

Re: [Qemu-devel] [PATCH v22 02/25] qapi: output def_value_str when query command line options

In reply to Chunyan Liu
Quoted 4 lines · Chunyan Liu

Change qapi interfaces to output the newly added def_value_str when querying command line options.

Not a valid email address.

#11 lore raw

PATCH v22 3/25 improve some functions in qemu-option.c

In reply to Chunyan Liu

Improve opt_get and opt_set group of functions. For opt_get, check and handle NULL input; for opt_set, when set to an existing option, rewrite the option with new value.

---
 include/qemu/option_int.h |  4 +--
 util/qemu-option.c        | 81 +++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 69 insertions(+), 16 deletions(-)
include/qemu/option_int.h +2 -2
index 8212fa4..db9ed91 100644
@@ -30,8 +30,8 @@
 #include "qemu/error-report.h"
 
 struct QemuOpt {
-    const char   *name;
-    const char   *str;
+    char   *name;
+    char   *str;
 
     const QemuOptDesc *desc;
     union {
util/qemu-option.c +67 -14

147 lines not on this page · raw message

Signature · 1 line
1.7.12.4
#12 lore raw

Re: [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c

Quoted 14 lines · Chunyan Liu

Improve opt_get and opt_set group of functions. For opt_get, check and handle NULL input; for opt_set, when set to an existing option, rewrite the option with new value.

---
 include/qemu/option_int.h |  4 +--
 util/qemu-option.c        | 81 +++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 69 insertions(+), 16 deletions(-)

+++ b/include/qemu/option_int.h

include/qemu/option_int.h line 34

Quoted 7 lines
include/qemu/option_int.h +2 -2
@@ -30,8 +30,8 @@
 #include "qemu/error-report.h"
 
 struct QemuOpt {
-    const char   *name;
-    const char   *str;
+    char   *name;
+    char   *str;

You are losing the 'const' here...

util/qemu-option.c static void opt_set(QemuOpts *opts, const char *name, const char *value, · line 735

Quoted 7 lines
util/qemu-option.c +3 -0
@@ -704,6 +730,13 @@ static void opt_set(QemuOpts *opts, const char *name, const char *value,
         return;
     }
 
+    opt = qemu_opt_find(opts, name);
+    if (opt) {
+        g_free((char *)opt->str);

...which means the cast is pointless here.

Hmm. This means that you are giving opt_set() the behavior of 'last version wins', by silently overwriting earlier versions. If I'm understanding the existing code correctly, the previous behavior was that calling opt_set twice in a row on the same name would inject BOTH names into 'opts', but then subsequent lookups on opts would find the FIRST hit. Doesn't that mean this is a semantic change:

qemu -opt key=value1,key=value2

would previously set key to value1, but now sets key to value2. Is it intentional? If so, document it in the commit message. Or am I missing something, where we already reject duplicates, in which case, your new code is currently unreachable, and your commit message could do with more explanation of why you are adding something that later patches will make use of.

Also, I'd feel a LOT better if we FIRST had a testsuite that covered what QemuOpts is _supposed_ to do before we then patch it,so that we aren't getting surprised by silent changes in behavior. It's okay to write a test that shows old behavior, then tweak the test in the patch that updates the behavior along with the justification of why the new behavior is nicer.

util/qemu-option.c void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value, · line 781

Quoted 6 lines
util/qemu-option.c +3 -0
@@ -744,16 +777,24 @@ void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
 int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val)
 
+    opt = qemu_opt_find(opts, name);
+    if (opt) {
+        g_free((char *)opt->str);

Another pointless cast.

util/qemu-option.c static void opt_set(QemuOpts *opts, const char *name, const char *value, · line 735

Quoted 4 lines
util/qemu-option.c +3 -0
+    opt = qemu_opt_find(opts, name);
+    if (opt) {
+        g_free((char *)opt->str);

and another.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#13 lore raw

Re: [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c

Quoted 13 lines · Eric Blake

util/qemu-option.c static void opt_set(QemuOpts *opts, const char *name, const char *value, · line 735

Quoted 3 lines
util/qemu-option.c +3 -0
+    opt = qemu_opt_find(opts, name);
+    if (opt) {
+        g_free((char *)opt->str);

...which means the cast is pointless here.

Hmm. This means that you are giving opt_set() the behavior of 'last version wins', by silently overwriting earlier versions. If I'm understanding the existing code correctly, the previous behavior was that calling opt_set twice in a row on the same name would inject BOTH names into 'opts', but then subsequent lookups on opts would find the FIRST hit. Doesn't that mean this is a semantic change:

Quoted 3 lines

qemu -opt key=value1,key=value2

would previously set key to value1, but now sets key to value2.

I've played with this a bit more, and now am more confused. QemuOpts is a LOT to comprehend.

Pre-patch, 'qemu-system-x86_64 -nodefaults -machine type=none,type-noone' displayed a help message about unknown machine type "noone", while swapping type=noone,type=none proceeded with the 'none' type. So the last version silently won, which was not the behavior I had predicted.

Post-patch, I get a compilation error (so how did you test your patch?):

qapi/opts-visitor.c: In function ‘opts_start_struct’:
qapi/opts-visitor.c:146:31: error: assignment discards ‘const’ qualifier from pointer target type [-Werror]

         ov->fake_id_opt->name = "id";
                               ^

If I press on in spite of that warning, then I get the same behavior where the last type= still wins on behavior. So I'm not sure how it all worked, but at least behavior wise, my one test didn't uncover a regression.

Still, I'd feel a LOT better with a testsuite of what QemuOpts is supposed to be able to do. tests/test-opts-visitor.c was the only file in tests/ that even mentions QemuOpts.

Quoted 8 lines

util/qemu-option.c void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value, · line 781

Quoted 6 lines
util/qemu-option.c +3 -0
@@ -744,16 +777,24 @@ void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
 int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val)
 
+    opt = qemu_opt_find(opts, name);
+    if (opt) {
+        g_free((char *)opt->str);

Another pointless cast.

Maybe not pointless, if you end up not removing the const in the struct declaration due to the compile error; but that brings me back to my earlier question - since the compiler error proves that we have places that are assigning compile-time string constants into the name field, we must NOT call g_free on those copies - how does your code distinguish between a QemuOpt that is built up by mallocs, vs. one that is described by compile-time constants?

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#14 lore raw

Re: [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c

2014-03-11 5:21 GMT+08:00 Eric Blake <[email protected]>:

Quoted 22 lines · Eric Blake
Quoted 14 lines

util/qemu-option.c static void opt_set(QemuOpts *opts, const char *name, const char *value, · line 735

Quoted 4 lines
util/qemu-option.c +3 -0
+    opt = qemu_opt_find(opts, name);
+    if (opt) {
+        g_free((char *)opt->str);

...which means the cast is pointless here.

Hmm. This means that you are giving opt_set() the behavior of 'last version wins', by silently overwriting earlier versions. If I'm understanding the existing code correctly, the previous behavior was that calling opt_set twice in a row on the same name would inject BOTH names into 'opts', but then subsequent lookups on opts would find the FIRST hit. Doesn't that mean this is a semantic change:

Quoted 3 lines

qemu -opt key=value1,key=value2

would previously set key to value1, but now sets key to value2.

I've played with this a bit more, and now am more confused. QemuOpts is a LOT to comprehend.

Quoted 8 lines

Pre-patch, 'qemu-system-x86_64 -nodefaults -machine type=none,type-noone' displayed a help message about unknown machine type "noone", while swapping type=noone,type=none proceeded with the 'none' type. So the last version silently won, which was not the behavior I had predicted.

Post-patch, I get a compilation error (so how did you test your patch?):

Mostly tested ./qemu-img commands where QEMUOptionParameter is used. I really didn't think of test QemuOpts fully, and about the test suite, I have no full
knowledge about how many things need to be tested, how many things need to be
covered?

Quoted 6 lines

qapi/opts-visitor.c: In function ‘opts_start_struct’:
qapi/opts-visitor.c:146:31: error: assignment discards ‘const’ qualifier from pointer target type [-Werror]

         ov->fake_id_opt->name = "id";
                               ^

This is a place needed to be changed but missing, since name and str changed to be (char *), here should be g_strdup("id"). Due to my configuration,
it appears as a warning instead of error which is missed. Updated 3/25.

Quoted 35 lines

If I press on in spite of that warning, then I get the same behavior where the last type= still wins on behavior. So I'm not sure how it all worked, but at least behavior wise, my one test didn't uncover a regression.

Still, I'd feel a LOT better with a testsuite of what QemuOpts is supposed to be able to do. tests/test-opts-visitor.c was the only file in tests/ that even mentions QemuOpts.

Review void qemu_opt_set_err(QemuOpts *opts, const char

Quoted 1 line
(quoted diff) +0 -0
@@ -744,16 +777,24 @@ void qemu_opt_set_err(QemuOpts *opts, const char

*name, const char *value,

Quoted 7 lines
(quoted diff) +0 -0
 >  int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val)
 
 > +    opt = qemu_opt_find(opts, name);
 > +    if (opt) {
 > +        g_free((char *)opt->str);
 

Another pointless cast.

Maybe not pointless, if you end up not removing the const in the struct declaration due to the compile error; but that brings me back to my earlier question - since the compiler error proves that we have places that are assigning compile-time string constants into the name field, we must NOT call g_free on those copies - how does your code distinguish between a QemuOpt that is built up by mallocs, vs. one that is described by compile-time constants?

--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org

#15 lore raw

Re: [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c

Hi,

Quoted 33 lines · Chunyan Liu

2014-03-11 5:21 GMT+08:00 Eric Blake <[email protected]>:

Quoted 22 lines · Eric Blake
Quoted 14 lines

util/qemu-option.c static void opt_set(QemuOpts *opts, const char *name, const char *value, · line 735

Quoted 4 lines
util/qemu-option.c +3 -0
+    opt = qemu_opt_find(opts, name);
+    if (opt) {
+        g_free((char *)opt->str);

...which means the cast is pointless here.

Hmm. This means that you are giving opt_set() the behavior of 'last version wins', by silently overwriting earlier versions. If I'm understanding the existing code correctly, the previous behavior was that calling opt_set twice in a row on the same name would inject BOTH names into 'opts', but then subsequent lookups on opts would find the FIRST hit. Doesn't that mean this is a semantic change:

Quoted 3 lines

qemu -opt key=value1,key=value2

would previously set key to value1, but now sets key to value2.

I've played with this a bit more, and now am more confused. QemuOpts is a LOT to comprehend.

Quoted 8 lines

Pre-patch, 'qemu-system-x86_64 -nodefaults -machine type=none,type-noone' displayed a help message about unknown machine type "noone", while swapping type=noone,type=none proceeded with the 'none' type. So the last version silently won, which was not the behavior I had predicted.

Post-patch, I get a compilation error (so how did you test your patch?):

Quoted 6 lines

Mostly tested ./qemu-img commands where QEMUOptionParameter is used. I really didn't think of test QemuOpts fully, and about the test suite, I have no full
knowledge about how many things need to be tested, how many things need to be
covered?

The testsuite should test the QemuOpts implementation, not the current users.

Regards...

Signature · 1 line
Leandro Dorileo
#16 lore raw

Re: [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c

Hi Chunyan,

Quoted 36 lines · Leandro Dorileo

Hi,

Quoted 33 lines · Chunyan Liu

2014-03-11 5:21 GMT+08:00 Eric Blake <[email protected]>:

Quoted 30 lines · Eric Blake
Quoted 14 lines

util/qemu-option.c static void opt_set(QemuOpts *opts, const char *name, const char *value, · line 735

Quoted 4 lines
util/qemu-option.c +3 -0
+    opt = qemu_opt_find(opts, name);
+    if (opt) {
+        g_free((char *)opt->str);

...which means the cast is pointless here.

Hmm. This means that you are giving opt_set() the behavior of 'last version wins', by silently overwriting earlier versions. If I'm understanding the existing code correctly, the previous behavior was that calling opt_set twice in a row on the same name would inject BOTH names into 'opts', but then subsequent lookups on opts would find the FIRST hit. Doesn't that mean this is a semantic change:

Quoted 3 lines

qemu -opt key=value1,key=value2

would previously set key to value1, but now sets key to value2.

I've played with this a bit more, and now am more confused. QemuOpts is a LOT to comprehend.

Pre-patch, 'qemu-system-x86_64 -nodefaults -machine type=none,type-noone' displayed a help message about unknown machine type "noone", while swapping type=noone,type=none proceeded with the 'none' type. So the last version silently won, which was not the behavior I had predicted.

Post-patch, I get a compilation error (so how did you test your patch?):

Quoted 8 lines
Quoted 6 lines

Mostly tested ./qemu-img commands where QEMUOptionParameter is used. I really didn't think of test QemuOpts fully, and about the test suite, I have no full
knowledge about how many things need to be tested, how many things need to be
covered?

The testsuite should test the QemuOpts implementation, not the current users.

I have just posted a patch introducing a basic QemuOpt testsuite, we can use it as a start.

Regards...

Signature · 1 line
Leandro Dorileo
#17 lore raw

Re: [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c

2014-03-17 5:19 GMT+08:00 Leandro Dorileo <[email protected]>:

Quoted 54 lines

Hi Chunyan,

Quoted 14 lines · Leandro Dorileo

Hi,

Quoted 11 lines · Chunyan Liu

2014-03-11 5:21 GMT+08:00 Eric Blake <[email protected]>:

Quoted 9 lines · Eric Blake
Quoted 8 lines

util/qemu-option.c static void opt_set(QemuOpts *opts, const char *name, const char *value, · line 735

Quoted 4 lines
util/qemu-option.c +3 -0
+    opt = qemu_opt_find(opts, name);
+    if (opt) {
+        g_free((char *)opt->str);

...which means the cast is pointless here.

Hmm. This means that you are giving opt_set() the behavior of

'last

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

version wins', by silently overwriting earlier versions. If I'm understanding the existing code correctly, the previous behavior

was

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

that calling opt_set twice in a row on the same name would inject

BOTH

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

names into 'opts', but then subsequent lookups on opts would find

the

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

FIRST hit. Doesn't that mean this is a semantic change:

qemu -opt key=value1,key=value2

would previously set key to value1, but now sets key to value2.

I've played with this a bit more, and now am more confused.

QemuOpts is

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

a LOT to comprehend.

Pre-patch, 'qemu-system-x86_64 -nodefaults -machine type=none,type-noone' displayed a help message about unknown machine type "noone", while swapping type=noone,type=none proceeded with the 'none' type. So the last version silently won, which was not the behavior I had predicted.

Post-patch, I get a compilation error (so how did you test your

patch?):

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

Mostly tested ./qemu-img commands where QEMUOptionParameter is used. I really didn't think of test QemuOpts fully, and about the test

suite, I

Quoted 2 lines
Quoted 2 lines

have no full
knowledge about how many things need to be tested, how many things

need to

Quoted 3 lines
Quoted 2 lines

be
covered?

Quoted 7 lines
Quoted 1 line

The testsuite should test the QemuOpts implementation, not the current

users.

I have just posted a patch introducing a basic QemuOpt testsuite, we can use it
as a start.

Thanks a lot, I've seen that.

Quoted 7 lines

Regards...

--
Leandro Dorileo

#18 lore raw

Re: [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c

In reply to Eric Blake

2014-03-11 5:21 GMT+08:00 Eric Blake <[email protected]>:

Quoted 19 lines · Eric Blake
Quoted 14 lines

util/qemu-option.c static void opt_set(QemuOpts *opts, const char *name, const char *value, · line 735

Quoted 4 lines
util/qemu-option.c +3 -0
+    opt = qemu_opt_find(opts, name);
+    if (opt) {
+        g_free((char *)opt->str);

...which means the cast is pointless here.

Hmm. This means that you are giving opt_set() the behavior of 'last version wins', by silently overwriting earlier versions. If I'm understanding the existing code correctly, the previous behavior was that calling opt_set twice in a row on the same name would inject BOTH names into 'opts', but then subsequent lookups on opts would find the FIRST hit. Doesn't that mean this is a semantic change:

Quoted 3 lines

qemu -opt key=value1,key=value2

would previously set key to value1, but now sets key to value2.

Quoted 9 lines

I've played with this a bit more, and now am more confused. QemuOpts is a LOT to comprehend.

Pre-patch, 'qemu-system-x86_64 -nodefaults -machine type=none,type-noone' displayed a help message about unknown machine type "noone", while swapping type=noone,type=none proceeded with the 'none' type. So the last version silently won, which was not the behavior I had predicted.

In qemu_opt_find(), it uses:
QTAILQ_FOREACH_REVERSE(),
so that means find the last setting, the same result with replacement.

Quoted 44 lines

Post-patch, I get a compilation error (so how did you test your patch?):

qapi/opts-visitor.c: In function ‘opts_start_struct’:
qapi/opts-visitor.c:146:31: error: assignment discards ‘const’ qualifier from pointer target type [-Werror]

         ov->fake_id_opt->name = "id";
                               ^

If I press on in spite of that warning, then I get the same behavior where the last type= still wins on behavior. So I'm not sure how it all worked, but at least behavior wise, my one test didn't uncover a regression.

Still, I'd feel a LOT better with a testsuite of what QemuOpts is supposed to be able to do. tests/test-opts-visitor.c was the only file in tests/ that even mentions QemuOpts.

Quoted 1 line

Review void qemu_opt_set_err(QemuOpts *opts, const char

Quoted 1 line
(quoted diff) +0 -0
@@ -744,16 +777,24 @@ void qemu_opt_set_err(QemuOpts *opts, const char

*name, const char *value,

Quoted 7 lines

util/qemu-option.c void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value, · line 790

Quoted 5 lines
util/qemu-option.c +3 -0
 int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val)
 
+    opt = qemu_opt_find(opts, name);
+    if (opt) {
+        g_free((char *)opt->str);

Another pointless cast.

Maybe not pointless, if you end up not removing the const in the struct declaration due to the compile error; but that brings me back to my earlier question - since the compiler error proves that we have places that are assigning compile-time string constants into the name field, we must NOT call g_free on those copies - how does your code distinguish between a QemuOpt that is built up by mallocs, vs. one that is described by compile-time constants?

--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org

#19 lore raw

Re: [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c

In reply to Chunyan Liu

Hi,

Quoted 31 lines · Chunyan Liu

Improve opt_get and opt_set group of functions. For opt_get, check and handle NULL input; for opt_set, when set to an existing option, rewrite the option with new value.

---
 include/qemu/option_int.h |  4 +--
 util/qemu-option.c        | 81 +++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 69 insertions(+), 16 deletions(-)
include/qemu/option_int.h +2 -2
index 8212fa4..db9ed91 100644
@@ -30,8 +30,8 @@
 #include "qemu/error-report.h"
 
 struct QemuOpt {
-    const char   *name;
-    const char   *str;
+    char   *name;
+    char   *str;
 
     const QemuOptDesc *desc;
     union {
util/qemu-option.c +0 -0
index 65d1c22..c7639e8 100644

util/qemu-option.c static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name) · line 565

Quoted 9 lines
util/qemu-option.c +4 -1
@@ -558,8 +558,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);
+    QemuOpt *opt;
 
+    if (opts == NULL) {
+        return NULL;
+    }

I understand you want to prevent a segfault in qemu_opt_find(), and I'm fine with that, but these checks make me wonder why you decided to change it, aren't you hiding some broken caller?

Btw, you could change qemu_opt_find() and check if opts != NULL there and not introduce all these opts == NULL qemu_opt_find() pairs.

--
Dorileo

Quoted 150 lines
util/qemu-option.c +63 -13
+
+    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) {
@@ -583,7 +588,13 @@ 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);
+    QemuOpt *opt;
+
+    if (opts == NULL) {
+        return defval;
+    }
+
+    opt = qemu_opt_find(opts, name);
 
     if (opt == NULL) {
         const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
@@ -598,7 +609,13 @@ 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);
+    QemuOpt *opt;
+
+    if (opts == NULL) {
+        return defval;
+    }
+
+    opt = qemu_opt_find(opts, name);
 
     if (opt == NULL) {
         const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
@@ -614,8 +631,13 @@ 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);
+    QemuOpt *opt;
 
+    if (opts == NULL) {
+        return defval;
+    }
+
+    opt = qemu_opt_find(opts, name);
     if (opt == NULL) {
         const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
         if (desc && desc->def_value_str) {
@@ -652,6 +674,10 @@ static void qemu_opt_parse(QemuOpt *opt, Error **errp)
 
 static void qemu_opt_del(QemuOpt *opt)
 {
+    if (opt == NULL) {
+        return;
+    }
+
     QTAILQ_REMOVE(&opt->opts->head, opt, next);
     g_free((/* !const */ char*)opt->name);
     g_free((/* !const */ char*)opt->str);
@@ -704,6 +730,13 @@ static void opt_set(QemuOpts *opts, const char *name, const char *value,
         return;
     }
 
+    opt = qemu_opt_find(opts, name);
+    if (opt) {
+        g_free((char *)opt->str);
+        opt->str = g_strdup(value);
+        return;
+    }
+
     opt = g_malloc0(sizeof(*opt));
     opt->name = g_strdup(name);
     opt->opts = opts;
@@ -744,16 +777,24 @@ void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
 int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val)
 {
     QemuOpt *opt;
-    const QemuOptDesc *desc = opts->list->desc;
+    const QemuOptDesc *desc;
 
-    opt = g_malloc0(sizeof(*opt));
-    opt->desc = find_desc_by_name(desc, name);
-    if (!opt->desc && !opts_accepts_any(opts)) {
+    desc = find_desc_by_name(opts->list->desc, name);
+    if (!desc && !opts_accepts_any(opts)) {
         qerror_report(QERR_INVALID_PARAMETER, name);
-        g_free(opt);
         return -1;
     }
 
+    opt = qemu_opt_find(opts, name);
+    if (opt) {
+        g_free((char *)opt->str);
+        opt->value.boolean = val;
+        opt->str = g_strdup(val ? "on" : "off");
+        return 0;
+    }
+
+    opt = g_malloc0(sizeof(*opt));
+    opt->desc = desc;
     opt->name = g_strdup(name);
     opt->opts = opts;
     opt->value.boolean = !!val;
@@ -766,16 +807,24 @@ 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)
 {
     QemuOpt *opt;
-    const QemuOptDesc *desc = opts->list->desc;
+    const QemuOptDesc *desc;
 
-    opt = g_malloc0(sizeof(*opt));
-    opt->desc = find_desc_by_name(desc, name);
-    if (!opt->desc && !opts_accepts_any(opts)) {
+    desc = find_desc_by_name(opts->list->desc, name);
+    if (!desc && !opts_accepts_any(opts)) {
         qerror_report(QERR_INVALID_PARAMETER, name);
-        g_free(opt);
         return -1;
     }
 
+    opt = qemu_opt_find(opts, name);
+    if (opt) {
+        g_free((char *)opt->str);
+        opt->value.uint = val;
+        opt->str = g_strdup_printf("%" PRId64, val);
+        return 0;
+    }
+
+    opt = g_malloc0(sizeof(*opt));
+    opt->desc = desc;
     opt->name = g_strdup(name);
     opt->opts = opts;
     opt->value.uint = val;
@@ -910,6 +959,10 @@ void qemu_opts_del(QemuOpts *opts)
 {
     QemuOpt *opt;
 
+    if (opts == NULL) {
+        return;
+    }
+
     for (;;) {
         opt = QTAILQ_FIRST(&opts->head);
         if (opt == NULL)
Signature · 1 line
1.7.12.4
#20 lore raw

Re: [Qemu-devel] [PATCH v22 03/25] improve some functions in qemu-option.c

2014-03-18 3:58 GMT+08:00 Leandro Dorileo <[email protected]>:

Quoted 50 lines

Hi,

Quoted 1 line · Chunyan Liu

Improve opt_get and opt_set group of functions. For opt_get, check and

handle

Quoted 1 line

NULL input; for opt_set, when set to an existing option, rewrite the

option

Quoted 7 lines

with new value.

---
 include/qemu/option_int.h |  4 +--
 util/qemu-option.c        | 81

+++++++++++++++++++++++++++++++++++++++--------

util/qemu-option.c static QemuOpt *qemu_opt_find(QemuOpts *opts, const

Quoted 22 lines
 2 files changed, 69 insertions(+), 16 deletions(-)
include/qemu/option_int.h +2 -2
index 8212fa4..db9ed91 100644
@@ -30,8 +30,8 @@
 #include "qemu/error-report.h"
 
 struct QemuOpt {
-    const char   *name;
-    const char   *str;
+    char   *name;
+    char   *str;
 
     const QemuOptDesc *desc;
     union {
util/qemu-option.c +0 -0
index 65d1c22..c7639e8 100644
@@ -558,8 +558,13 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const

char *name)

util/qemu-option.c static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name) · line 565

Quoted 9 lines
util/qemu-option.c +4 -1
 const char *qemu_opt_get(QemuOpts *opts, const char *name)
 {
-    QemuOpt *opt = qemu_opt_find(opts, name);
+    QemuOpt *opt;
 
+    if (opts == NULL) {
+        return NULL;
+    }
Quoted 6 lines

I understand you want to prevent a segfault in qemu_opt_find(), and I'm fine with that,
but these checks make me wonder why you decided to change it, aren't you hiding some
broken caller?

It should be broken in generating patches (so I thought we should add input check), although
might not be broken at the end :) Maybe I could look at and try to exclude some changes
that's not mandatory to just make this patch series work. Like: don't need to change assertion
as in patch 4/25, don't need to replace existing setting in qemu_opt_set_* functions as in
patch 3/25.

Quoted 5 lines

Btw, you could change qemu_opt_find() and check if opts != NULL there and not introduce
all these opts == NULL qemu_opt_find() pairs.

Could do. Either change qemu_opt_find or qemu_opt_get. I can update to change qemu_opt_find :)

Quoted 168 lines

--
Dorileo

util/qemu-option.c static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)

Quoted 4 lines
util/qemu-option.c +2 -0
+
+    opt = qemu_opt_find(opts, name);
     if (!opt) {
         const QemuOptDesc *desc = find_desc_by_name(opts->list->desc,

name);

Quoted 6 lines
util/qemu-option.c +0 -1
         if (desc && desc->def_value_str) {
@@ -583,7 +588,13 @@ 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);

util/qemu-option.c bool qemu_opt_has_help_opt(QemuOpts *opts) · line 600

Quoted 10 lines
util/qemu-option.c +7 -0
+    QemuOpt *opt;
+
+    if (opts == NULL) {
+        return defval;
+    }
+
+    opt = qemu_opt_find(opts, name);
 
     if (opt == NULL) {
         const QemuOptDesc *desc = find_desc_by_name(opts->list->desc,

name);

util/qemu-option.c bool qemu_opt_get_bool(QemuOpts *opts, const char

Quoted 1 line
util/qemu-option.c +0 -0
@@ -598,7 +609,13 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char

*name, bool defval)

util/qemu-option.c bool qemu_opt_get_bool(QemuOpts *opts, const char · line 609

Quoted 2 lines
util/qemu-option.c +0 -0
 uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t

defval)

util/qemu-option.c bool qemu_opt_has_help_opt(QemuOpts *opts)

Quoted 12 lines
util/qemu-option.c +7 -1
 {
-    QemuOpt *opt = qemu_opt_find(opts, name);
+    QemuOpt *opt;
+
+    if (opts == NULL) {
+        return defval;
+    }
+
+    opt = qemu_opt_find(opts, name);
 
     if (opt == NULL) {
         const QemuOptDesc *desc = find_desc_by_name(opts->list->desc,

name);

util/qemu-option.c uint64_t qemu_opt_get_number(QemuOpts *opts, const

Quoted 1 line
util/qemu-option.c +0 -0
@@ -614,8 +631,13 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const

char *name, uint64_t defval)

util/qemu-option.c uint64_t qemu_opt_get_number(QemuOpts *opts, const · line 631

Quoted 2 lines
util/qemu-option.c +0 -0
 uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t

defval)

util/qemu-option.c uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)

Quoted 11 lines
util/qemu-option.c +6 -1
 {
-    QemuOpt *opt = qemu_opt_find(opts, name);
+    QemuOpt *opt;
 
+    if (opts == NULL) {
+        return defval;
+    }
+
+    opt = qemu_opt_find(opts, name);
     if (opt == NULL) {
         const QemuOptDesc *desc = find_desc_by_name(opts->list->desc,

name);

util/qemu-option.c static void qemu_opt_parse(QemuOpt *opt, Error

Quoted 2 lines
util/qemu-option.c +0 -0
         if (desc && desc->def_value_str) {
@@ -652,6 +674,10 @@ static void qemu_opt_parse(QemuOpt *opt, Error

**errp)

util/qemu-option.c static void opt_set(QemuOpts *opts, const char

Quoted 11 lines
util/qemu-option.c +4 -0
 static void qemu_opt_del(QemuOpt *opt)
 {
+    if (opt == NULL) {
+        return;
+    }
+
     QTAILQ_REMOVE(&opt->opts->head, opt, next);
     g_free((/* !const */ char*)opt->name);
     g_free((/* !const */ char*)opt->str);
@@ -704,6 +730,13 @@ static void opt_set(QemuOpts *opts, const char

*name, const char *value,

util/qemu-option.c void qemu_opt_set_err(QemuOpts *opts, const char

Quoted 14 lines
util/qemu-option.c +7 -0
         return;
     }
 
+    opt = qemu_opt_find(opts, name);
+    if (opt) {
+        g_free((char *)opt->str);
+        opt->str = g_strdup(value);
+        return;
+    }
+
     opt = g_malloc0(sizeof(*opt));
     opt->name = g_strdup(name);
     opt->opts = opts;
@@ -744,16 +777,24 @@ void qemu_opt_set_err(QemuOpts *opts, const char

*name, const char *value,

util/qemu-option.c int qemu_opt_set_bool(QemuOpts *opts, const char

Quoted 30 lines
util/qemu-option.c +13 -5
 int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val)
 {
     QemuOpt *opt;
-    const QemuOptDesc *desc = opts->list->desc;
+    const QemuOptDesc *desc;
 
-    opt = g_malloc0(sizeof(*opt));
-    opt->desc = find_desc_by_name(desc, name);
-    if (!opt->desc && !opts_accepts_any(opts)) {
+    desc = find_desc_by_name(opts->list->desc, name);
+    if (!desc && !opts_accepts_any(opts)) {
         qerror_report(QERR_INVALID_PARAMETER, name);
-        g_free(opt);
         return -1;
     }
 
+    opt = qemu_opt_find(opts, name);
+    if (opt) {
+        g_free((char *)opt->str);
+        opt->value.boolean = val;
+        opt->str = g_strdup(val ? "on" : "off");
+        return 0;
+    }
+
+    opt = g_malloc0(sizeof(*opt));
+    opt->desc = desc;
     opt->name = g_strdup(name);
     opt->opts = opts;
     opt->value.boolean = !!val;
@@ -766,16 +807,24 @@ int qemu_opt_set_bool(QemuOpts *opts, const char

*name, bool val)

Quoted 44 lines
util/qemu-option.c +17 -6
 int qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val)
 {
     QemuOpt *opt;
-    const QemuOptDesc *desc = opts->list->desc;
+    const QemuOptDesc *desc;
 
-    opt = g_malloc0(sizeof(*opt));
-    opt->desc = find_desc_by_name(desc, name);
-    if (!opt->desc && !opts_accepts_any(opts)) {
+    desc = find_desc_by_name(opts->list->desc, name);
+    if (!desc && !opts_accepts_any(opts)) {
         qerror_report(QERR_INVALID_PARAMETER, name);
-        g_free(opt);
         return -1;
     }
 
+    opt = qemu_opt_find(opts, name);
+    if (opt) {
+        g_free((char *)opt->str);
+        opt->value.uint = val;
+        opt->str = g_strdup_printf("%" PRId64, val);
+        return 0;
+    }
+
+    opt = g_malloc0(sizeof(*opt));
+    opt->desc = desc;
     opt->name = g_strdup(name);
     opt->opts = opts;
     opt->value.uint = val;
@@ -910,6 +959,10 @@ void qemu_opts_del(QemuOpts *opts)
 {
     QemuOpt *opt;
 
+    if (opts == NULL) {
+        return;
+    }
+
     for (;;) {
         opt = QTAILQ_FIRST(&opts->head);
         if (opt == NULL)
--

1.7.12.4

#21 lore raw

PATCH v22 4/25 improve assertion in qemu_opt_get functions

In reply to Chunyan Liu

In qemu_opt_set functions, if desc doen't exist but opts_accepts_any is true, it won't report error, but can still alloc an opt for the option and save it. However, after that, when doing qemu_opt_get, this option could be found in opts but opt->desc is NULL. This is correct, should not be treated as error.

This patch would fix vvfat issue after changing to QemuOpts.

---
 util/qemu-option.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
util/qemu-option.c +9 -3
index c7639e8..df79235 100644
@@ -603,7 +603,9 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
         }
         return defval;
     }
-    assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL);
+    if (opt->desc) {
+        assert(opt->desc->type == QEMU_OPT_BOOL);
+    }
     return opt->value.boolean;
 }
 
@@ -625,7 +627,9 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
         }
         return defval;
     }
-    assert(opt->desc && opt->desc->type == QEMU_OPT_NUMBER);
+    if (opt->desc) {
+        assert(opt->desc->type == QEMU_OPT_NUMBER);
+    }
     return opt->value.uint;
 }
 
@@ -645,7 +649,9 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
         }
         return defval;
     }
-    assert(opt->desc && opt->desc->type == QEMU_OPT_SIZE);
+    if (opt->desc) {
+        assert(opt->desc->type == QEMU_OPT_SIZE);
+    }
     return opt->value.uint;
 }
 
Signature · 1 line
1.7.12.4
#22 lore raw

Re: [Qemu-devel] [PATCH v22 04/25] improve assertion in qemu_opt_get functions

Quoted 1 line · Chunyan Liu

In qemu_opt_set functions, if desc doen't exist but opts_accepts_any is true, it

s/doen't/doesn't/

I mentioned the same problem against v20. It is very depressing when review comments are not addressed.

Quoted 16 lines

won't report error, but can still alloc an opt for the option and save it. However, after that, when doing qemu_opt_get, this option could be found in opts but opt->desc is NULL. This is correct, should not be treated as error.

This patch would fix vvfat issue after changing to QemuOpts.

---
 util/qemu-option.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
util/qemu-option.c +0 -0
index c7639e8..df79235 100644

util/qemu-option.c bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval) · line 609

Quoted 8 lines
util/qemu-option.c +3 -1
@@ -603,7 +603,9 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
         }
         return defval;
     }
-    assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL);
+    if (opt->desc) {
+        assert(opt->desc->type == QEMU_OPT_BOOL);
+    }
     return opt->value.boolean;

I'm not sure I like this. opt->value is a union, but opt_set() does NOT populate the union when opts_accepts_any() fails. Previously, we were using opt->desc->type as the discriminator for which branch of the union is valid. But with your patch, if an option was set as a string, but then queried as a boolean, we may be reading bogus contents from the union. Or even worse, if someone sets the uint member of the union to 0x100000000 via qemu_opt_set_number(), then later calls qemu_opt_get_bool, the boolean member _might_ read as true on some platforms and false on others, depending on things such as host endianness.

How is vvfat broken without this patch? That is, what specific option are you setting without specifying its type, that later triggers the assertion when you try to get the option via a specific type?

I'm wondering if the fix should look more like:

if (opt->desc) {
    assert(opt->desc->type == QEMU_OPT_BOOL);
    return opt->value.boolean;
} else {
    code to parse opt->str
}

so that you are not dereferencing an undefined state of the union.

Quoted 12 lines
util/qemu-option.c +3 -1
@@ -625,7 +627,9 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
         }
         return defval;
     }
-    assert(opt->desc && opt->desc->type == QEMU_OPT_NUMBER);
+    if (opt->desc) {
+        assert(opt->desc->type == QEMU_OPT_NUMBER);
+    }
     return opt->value.uint;
 }
 

util/qemu-option.c uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval) · line 655

Quoted 8 lines
util/qemu-option.c +3 -1
@@ -645,7 +649,9 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
         }
         return defval;
     }
-    assert(opt->desc && opt->desc->type == QEMU_OPT_SIZE);
+    if (opt->desc) {
+        assert(opt->desc->type == QEMU_OPT_SIZE);
+    }
     return opt->value.uint;

Same problem in these two spots.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#23 lore raw

Re: [Qemu-devel] [PATCH v22 04/25] improve assertion in qemu_opt_get functions

2014-03-11 5:44 GMT+08:00 Eric Blake <[email protected]>:

Quoted 47 lines · Chunyan Liu
Quoted 1 line

In qemu_opt_set functions, if desc doen't exist but opts_accepts_any is

true, it

s/doen't/doesn't/

I mentioned the same problem against v20. It is very depressing when review comments are not addressed.

Quoted 1 line

won't report error, but can still alloc an opt for the option and save

it.

Quoted 1 line

However, after that, when doing qemu_opt_get, this option could be found

in opts

util/qemu-option.c bool qemu_opt_get_bool(QemuOpts *opts, const char

Quoted 14 lines

but opt->desc is NULL. This is correct, should not be treated as error.

This patch would fix vvfat issue after changing to QemuOpts.

---
 util/qemu-option.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
util/qemu-option.c +0 -0
index c7639e8..df79235 100644
@@ -603,7 +603,9 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char

*name, bool defval)

util/qemu-option.c bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval) · line 609

Quoted 8 lines
util/qemu-option.c +3 -1
         }
         return defval;
     }
-    assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL);
+    if (opt->desc) {
+        assert(opt->desc->type == QEMU_OPT_BOOL);
+    }
     return opt->value.boolean;

I'm not sure I like this. opt->value is a union, but opt_set() does NOT populate the union when opts_accepts_any() fails. Previously, we were using opt->desc->type as the discriminator for which branch of the union is valid. But with your patch, if an option was set as a string, but then queried as a boolean, we may be reading bogus contents from the union. Or even worse, if someone sets the uint member of the union to 0x100000000 via qemu_opt_set_number(), then later calls qemu_opt_get_bool, the boolean member _might_ read as true on some platforms and false on others, depending on things such as host endianness.

Quoted 4 lines

How is vvfat broken without this patch? That is, what specific option are you setting without specifying its type, that later triggers the assertion when you try to get the option via a specific type?

Well, now I think it caused by drv (vvfat.c) and proto_drv (raw-posix.c) not consistent, one is using QemuOpts, the other is using QEMUOptionParameter. That will cause create_opts became NULL, then when passing a size option, qemu_opt_set_size is OK, but later qemu_opt_get_size will segment fault. After solving the drv/proto_drv consistent issue, this problem won't happen. So, in this patch series, this place could not be changed.

( But with opts_accept_any, I still think this place may bring problem some time
in future.)

Quoted 42 lines

I'm wondering if the fix should look more like:

if (opt->desc) {
    assert(opt->desc->type == QEMU_OPT_BOOL);
    return opt->value.boolean;
} else {
    code to parse opt->str
}

so that you are not dereferencing an undefined state of the union.

util/qemu-option.c uint64_t qemu_opt_get_number(QemuOpts *opts, const

Quoted 1 line
util/qemu-option.c +0 -0
@@ -625,7 +627,9 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const

char *name, uint64_t defval)

util/qemu-option.c uint64_t qemu_opt_get_size(QemuOpts *opts, const

Quoted 11 lines
util/qemu-option.c +3 -1
         }
         return defval;
     }
-    assert(opt->desc && opt->desc->type == QEMU_OPT_NUMBER);
+    if (opt->desc) {
+        assert(opt->desc->type == QEMU_OPT_NUMBER);
+    }
     return opt->value.uint;
 }
 
@@ -645,7 +649,9 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const

char *name, uint64_t defval)

util/qemu-option.c uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval) · line 655

Quoted 8 lines
util/qemu-option.c +3 -1
         }
         return defval;
     }
-    assert(opt->desc && opt->desc->type == QEMU_OPT_SIZE);
+    if (opt->desc) {
+        assert(opt->desc->type == QEMU_OPT_SIZE);
+    }
     return opt->value.uint;

Same problem in these two spots.

--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org

#24 lore raw

PATCH v22 5/25 add some QemuOpts functions for replace work

In reply to Chunyan Liu

Add some qemu_opt functions to replace the same functionality of QEMUOptionParameter handling.

---
 include/qemu/option.h |   9 +++
 util/qemu-option.c    | 188 ++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 184 insertions(+), 13 deletions(-)
include/qemu/option.h +9 -0
index c3b0a91..de4912a 100644
@@ -111,6 +111,7 @@ struct QemuOptsList {
 };
 
 const char *qemu_opt_get(QemuOpts *opts, const char *name);
+char *qemu_opt_get_del(QemuOpts *opts, const char *name);
 /**
  * qemu_opt_has_help_opt:
  * @opts: options to search for a help request
@@ -126,6 +127,11 @@ bool qemu_opt_has_help_opt(QemuOpts *opts);
 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);
 uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval);
+bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval);
+uint64_t qemu_opt_get_number_del(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_unset(QemuOpts *opts, const char *name);
 int qemu_opt_set(QemuOpts *opts, const char *name, const char *value);
 void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
@@ -161,4 +167,7 @@ void 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 *dst, QemuOptsList *list);
+void qemu_opts_free(QemuOptsList *list);
+void qemu_opts_print_help(QemuOptsList *list);
 #endif
util/qemu-option.c +175 -13

258 lines not on this page · raw message

Signature · 1 line
1.7.12.4
#25 lore raw

Re: [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work

Quoted 13 lines · Chunyan Liu

Add some qemu_opt functions to replace the same functionality of QEMUOptionParameter handling.

---
 include/qemu/option.h |   9 +++
 util/qemu-option.c    | 188 ++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 184 insertions(+), 13 deletions(-)

+++ b/util/qemu-option.c

util/qemu-option.c line 38

Quoted 4 lines
util/qemu-option.c +1 -0
@@ -35,6 +35,7 @@
 
 static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
                                             const char *name);
+static void qemu_opt_del(QemuOpt *opt);

Again, any reason you can't hoist the function so that it occurs in topological order, rather than needing to add a forward declaration?

Quoted 6 lines
util/qemu-option.c +4 -0
 }
 
+static size_t count_opts_list(QemuOptsList *list)
+{
+    QemuOptDesc *desc = NULL;
+    size_t num_opts = 0;

util/qemu-option.c QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest, · line 396

Quoted 10 lines
util/qemu-option.c +10 -0
+
+    if (!list) {
+        return 0;
+    }
+
+    desc = list->desc;
+    while (desc && desc->name) {
+        num_opts++;
+        desc++;
+    }

This returns 0 for option lists where opts_accepts_any() is true. Is that going to bite us? Let's see...

util/qemu-option.c QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest, · line 408

Quoted 8 lines
util/qemu-option.c +8 -0
+/* Create a new QemuOptsList with a desc of the merge of the first
+ * and second. It will allocate space for one new QemuOptsList plus
+ * enough space for QemuOptDesc in first and second QemuOptsList.
+ * First argument's QemuOptDesc members take precedence over second's.
+ * 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.
+ */
+QemuOptsList *qemu_opts_append(QemuOptsList *dst,

Naming this 'dst' is confusing, as it is not the destination. Rather, you are creating a new list, and the new list is the destination of the concatenation of first and second list arguments, where descriptions in the first list have priority over any duplicates in the second list.

Quoted 4 lines
util/qemu-option.c +4 -0
+                               QemuOptsList *list)
+{
+    size_t num_opts, num_dst_opts;
+    QemuOptsList *tmp;

util/qemu-option.c QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest, · line 422

Quoted 10 lines
util/qemu-option.c +10 -0
+    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));

...Already I can see problems if either 'dst' or 'list' passes opts_accepts_any(). If exactly one has a desc array with no name, then that QemuOptsList accepts any option spelling, but the resulting list in 'tmp' will only accept the options in the other input. Probably worth asserting that neither input passes opts_accepts_any().

util/qemu-option.c QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest, · line 424

Quoted 2 lines
util/qemu-option.c +2 -0
+    QTAILQ_INIT(&tmp->head);
+    num_dst_opts = 0;

This name is confusing - it is actually tracking how many descriptions you have copied into 'tmp', and NOT how many options are in 'dst'.

util/qemu-option.c QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest, · line 431

Quoted 7 lines
util/qemu-option.c +7 -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;

Redundant assignment; your g_malloc0() above already guaranteed this.

util/qemu-option.c QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest, · line 440

Quoted 9 lines
util/qemu-option.c +9 -0
+            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) {

So every call to qemu_opts_append() is O(n^2) behavior - I guess it's
okay: as long as we are always passing short lists, we don't need it to scale very well.

Review

Quoted 2 lines
(quoted diff) +2 -0
+                tmp->desc[num_dst_opts++] = *desc;
+                tmp->desc[num_dst_opts].name = NULL;

Again, redundant assignment to NULL.

util/qemu-option.c QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest, · line 448

Quoted 6 lines
util/qemu-option.c +6 -0
+            }
+            desc++;
+        }
+    }
+
+    return tmp;

Okay, at the end of the day, 'tmp' is a single block of malloc'd storage, where descriptions are shared with pre-existing opt lists (probably worth documenting that the lifetime of the returned value of this function is no longer than the lifetime of the two lists you concatenated, and that a simple g_free() of the list will suffice - or point to qemu_opts_free() as the recommended cleanup method).

util/qemu-option.c const char *qemu_opt_get(QemuOpts *opts, const char *name) · line 646

Quoted 10 lines
util/qemu-option.c +3 -0
+}
+
 /*
  * Parses a parameter string (param) into an option list (dest).
  *
@@ -574,6 +643,29 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name)
     return opt ? opt->str : NULL;
 }
 
+char *qemu_opt_get_del(QemuOpts *opts, const char *name)

Please, add a comment what this function does. Something like:

If 'opts' already has a value for the key 'name', remove that key from the options list and return the value. Otherwise, if 'opts' has a default value for the key, return that default. Otherwise, return NULL.

Also, I think qemu_opt_get_del and qemu_opts_append may be better as two separate commits, particularly if you are also enhancing the testsuite with each commit to prove the functionality works.

Why are your later callers using a common helper function, but qemu_opt_get_del() repeating a lot of the body of qemu_opt_get()? Shouldn't qemu_opt_get() and qemu_opt_get_del() call into a common helper?

util/qemu-option.c bool qemu_opt_has_help_opt(QemuOpts *opts) · line 681

Quoted 3 lines
util/qemu-option.c +1 -1
-bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
+static bool _qemu_opt_get_bool(QemuOpts *opts, const char *name,

Nothing else in the code base uses the '_qemu' namespace. You need to name this function something better. A comment for this method would be helpful, something like:

Determine the boolean value for key 'name' from 'opts', defaulting to 'defval' if one has not already been added to the list and if the list does not already provide a default. Additionally, if 'del', remove the value from the list.

Quoted 8 lines
util/qemu-option.c +2 -0
+                               bool defval, bool del)
 {
     QemuOpt *opt;
+    bool ret = defval;
 
     if (opts == NULL) {
         return defval;

util/qemu-option.c bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval) · line 698

Quoted 8 lines
util/qemu-option.c +2 -2
@@ -599,19 +693,35 @@ 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);
+            parse_option_bool(name, desc->def_value_str, &ret, &error_abort);
         }
-        return defval;
+        return ret;

This favors the QemuOptDesc default over the defval that the user passed in. I think that's an important detail to document that use of the def_value_str means the defval argument is never used.

util/qemu-option.c bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval) · line 703

Quoted 6 lines
util/qemu-option.c +1 -1
     }
     if (opt->desc) {
         assert(opt->desc->type == QEMU_OPT_BOOL);
     }
-    return opt->value.boolean;
+    ret = opt->value.boolean;

Same problem as in 4/25 - I don't think you can rely on opt->value.boolean being valid if you don't track the union discriminator, and right now, the union discriminator is tracked only via opt->desc.

util/qemu-option.c bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval) · line 707

Quoted 4 lines
util/qemu-option.c +4 -0
+    if (del) {
+        qemu_opt_del(opt);
+    }
+    return ret;

Couldn't this whole function be shortened to:

char *tmp;

if (del) {
    tmp = qemu_opt_get_del(opts, name);
} else {
    tmp = qemu_opt_get(opts, name);
}
if (!tmp) {
    return defval;
}

parse_option_bool(name, tmp, &defval, &error_abort); g_free(tmp);
return defval;

or even shorter, if you combine qemu_opt_get{,_del} into calling a common helper function?

util/qemu-option.c bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval) · line 718

Quoted 12 lines
util/qemu-option.c +9 -1
 }
 
-uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
+bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
+{
+    return _qemu_opt_get_bool(opts, name, defval, false);
+}
+
+bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval)
+{
+    return _qemu_opt_get_bool(opts, name, defval, true);
+}

Other than the _qemu namespace, this is a good example of how a common helper function makes it easier to implement two variants.

The _number and _size variants will need similar treatment as the _bool.

Quoted 4 lines
util/qemu-option.c +0 -0
@@ -1302,3 +1443,24 @@ int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
     loc_pop(&loc);
     return rc;
 }

util/qemu-option.c int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque, · line 1455

Quoted 10 lines
util/qemu-option.c +10 -0
+
+/* free a QemuOptsList, can accept NULL as arguments */
+void qemu_opts_free(QemuOptsList *list)
+{
+    if (!list) {
+        return;
+    }
+
+    g_free(list);
+}

g_free() is safe to call on NULL. Which means qemu_opts_free(foo) is a fancy way to spell g_free(foo). Do we need this function?

util/qemu-option.c int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque, · line 1464

Quoted 9 lines
util/qemu-option.c +9 -0
+
+void qemu_opts_print_help(QemuOptsList *list)
+{
+    int i;
+    printf("Supported options:\n");
+    for (i = 0; list && list->desc[i].name; i++) {
+        printf("%-16s %s\n", list->desc[i].name,
+               list->desc[i].help ?
+               list->desc[i].help : "");

This prints trailing spaces for any description that lacks help text. Not the end of the world, but I try to be cleaner than that.

Review int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque, · line 1466

Quoted 2 lines
(quoted diff) +2 -0
+    }
+}

Unrelated to either of the other two categories of functions - maybe this patch should be split into three parts.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#26 lore raw

Re: [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work

2014-03-11 7:28 GMT+08:00 Eric Blake <[email protected]>:

Quoted 149 lines · Chunyan Liu
Quoted 8 lines

Add some qemu_opt functions to replace the same functionality of QEMUOptionParameter handling.

---
 include/qemu/option.h |   9 +++
 util/qemu-option.c    | 188

++++++++++++++++++++++++++++++++++++++++++++++----

util/qemu-option.c line 38

Quoted 9 lines
 2 files changed, 184 insertions(+), 13 deletions(-)

+++ b/util/qemu-option.c

util/qemu-option.c +1 -0
@@ -35,6 +35,7 @@
 
 static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
                                             const char *name);
+static void qemu_opt_del(QemuOpt *opt);

Again, any reason you can't hoist the function so that it occurs in topological order, rather than needing to add a forward declaration?

Quoted 6 lines
util/qemu-option.c +4 -0
 }
 
+static size_t count_opts_list(QemuOptsList *list)
+{
+    QemuOptDesc *desc = NULL;
+    size_t num_opts = 0;

util/qemu-option.c QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest, · line 396

Quoted 10 lines
util/qemu-option.c +10 -0
+
+    if (!list) {
+        return 0;
+    }
+
+    desc = list->desc;
+    while (desc && desc->name) {
+        num_opts++;
+        desc++;
+    }

This returns 0 for option lists where opts_accepts_any() is true. Is that going to bite us? Let's see...

util/qemu-option.c QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest, · line 408

Quoted 8 lines
util/qemu-option.c +8 -0
+/* Create a new QemuOptsList with a desc of the merge of the first
+ * and second. It will allocate space for one new QemuOptsList plus
+ * enough space for QemuOptDesc in first and second QemuOptsList.
+ * First argument's QemuOptDesc members take precedence over second's.
+ * 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.
+ */
+QemuOptsList *qemu_opts_append(QemuOptsList *dst,

Naming this 'dst' is confusing, as it is not the destination. Rather, you are creating a new list, and the new list is the destination of the concatenation of first and second list arguments, where descriptions in the first list have priority over any duplicates in the second list.

Quoted 4 lines
util/qemu-option.c +4 -0
+                               QemuOptsList *list)
+{
+    size_t num_opts, num_dst_opts;
+    QemuOptsList *tmp;

util/qemu-option.c QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest, · line 422

Quoted 10 lines
util/qemu-option.c +10 -0
+    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));

...Already I can see problems if either 'dst' or 'list' passes opts_accepts_any(). If exactly one has a desc array with no name, then that QemuOptsList accepts any option spelling, but the resulting list in 'tmp' will only accept the options in the other input. Probably worth asserting that neither input passes opts_accepts_any().

util/qemu-option.c QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest, · line 424

Quoted 2 lines
util/qemu-option.c +2 -0
+    QTAILQ_INIT(&tmp->head);
+    num_dst_opts = 0;

This name is confusing - it is actually tracking how many descriptions you have copied into 'tmp', and NOT how many options are in 'dst'.

util/qemu-option.c QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest, · line 431

Quoted 7 lines
util/qemu-option.c +7 -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;

Redundant assignment; your g_malloc0() above already guaranteed this.

util/qemu-option.c QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest, · line 440

Quoted 9 lines
util/qemu-option.c +9 -0
+            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) {

So every call to qemu_opts_append() is O(n^2) behavior - I guess it's
okay: as long as we are always passing short lists, we don't need it to scale very well.

Review

Quoted 2 lines
(quoted diff) +2 -0
+                tmp->desc[num_dst_opts++] = *desc;
+                tmp->desc[num_dst_opts].name = NULL;

Again, redundant assignment to NULL.

util/qemu-option.c QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest, · line 448

Quoted 6 lines
util/qemu-option.c +6 -0
+            }
+            desc++;
+        }
+    }
+
+    return tmp;

Okay, at the end of the day, 'tmp' is a single block of malloc'd storage, where descriptions are shared with pre-existing opt lists (probably worth documenting that the lifetime of the returned value of this function is no longer than the lifetime of the two lists you concatenated, and that a simple g_free() of the list will suffice - or point to qemu_opts_free() as the recommended cleanup method).

util/qemu-option.c const char *qemu_opt_get(QemuOpts *opts, const char

Quoted 6 lines
util/qemu-option.c +2 -0
+}
+
 /*
  * Parses a parameter string (param) into an option list (dest).
  *
@@ -574,6 +643,29 @@ const char *qemu_opt_get(QemuOpts *opts, const char

*name)

util/qemu-option.c const char *qemu_opt_get(QemuOpts *opts, const char *name) · line 646

Quoted 4 lines
util/qemu-option.c +1 -0
     return opt ? opt->str : NULL;
 }
 
+char *qemu_opt_get_del(QemuOpts *opts, const char *name)

Please, add a comment what this function does. Something like:

If 'opts' already has a value for the key 'name', remove that key from the options list and return the value. Otherwise, if 'opts' has a default value for the key, return that default. Otherwise, return NULL.

Also, I think qemu_opt_get_del and qemu_opts_append may be better as two separate commits, particularly if you are also enhancing the testsuite with each commit to prove the functionality works.

Quoted 5 lines

Why are your later callers using a common helper function, but qemu_opt_get_del() repeating a lot of the body of qemu_opt_get()? Shouldn't qemu_opt_get() and qemu_opt_get_del() call into a common helper?

qemu_opt_get_del must return (char *), but the existing qemu_opt_get

returns
(const char *). Could also change qemu_opt_get return value to (char *) type,
then these two functions could use a common helper function. But there are too
many places using qemu_opt_get already, if the return value type changes, it will
affect a lot.

Quoted 45 lines

util/qemu-option.c bool qemu_opt_has_help_opt(QemuOpts *opts) · line 681

Quoted 3 lines
util/qemu-option.c +1 -1
-bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
+static bool _qemu_opt_get_bool(QemuOpts *opts, const char *name,

Nothing else in the code base uses the '_qemu' namespace. You need to name this function something better. A comment for this method would be helpful, something like:

Determine the boolean value for key 'name' from 'opts', defaulting to 'defval' if one has not already been added to the list and if the list does not already provide a default. Additionally, if 'del', remove the value from the list.

util/qemu-option.c bool qemu_opt_get_bool(QemuOpts *opts, const char

Quoted 8 lines
util/qemu-option.c +2 -0
+                               bool defval, bool del)
 {
     QemuOpt *opt;
+    bool ret = defval;
 
     if (opts == NULL) {
         return defval;
@@ -599,19 +693,35 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char

*name, bool defval)

Review bool qemu_opt_get_bool(QemuOpts *opts, const char · line 694

Quoted 2 lines
(quoted diff) +0 -0
     if (opt == NULL) {
         const QemuOptDesc *desc = find_desc_by_name(opts->list->desc,

name);

Review bool qemu_opt_get_bool(QemuOpts *opts, const char · line 602

Quoted 2 lines
(quoted diff) +0 -1
         if (desc && desc->def_value_str) {
-            parse_option_bool(name, desc->def_value_str, &defval,

&error_abort);

Review bool qemu_opt_get_bool(QemuOpts *opts, const char · line 696

Quoted 1 line
(quoted diff) +1 -0
+            parse_option_bool(name, desc->def_value_str, &ret,

&error_abort);

util/qemu-option.c bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval) · line 698

Quoted 3 lines
util/qemu-option.c +1 -1
         }
-        return defval;
+        return ret;

This favors the QemuOptDesc default over the defval that the user passed in. I think that's an important detail to document that use of the def_value_str means the defval argument is never used.

util/qemu-option.c bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval) · line 703

Quoted 6 lines
util/qemu-option.c +1 -1
     }
     if (opt->desc) {
         assert(opt->desc->type == QEMU_OPT_BOOL);
     }
-    return opt->value.boolean;
+    ret = opt->value.boolean;
Quoted 4 lines

Same problem as in 4/25 - I don't think you can rely on opt->value.boolean being valid if you don't track the union discriminator, and right now, the union discriminator is tracked only via opt->desc.

Couldn't find a reliable way if the option is passed through opts_accept_any,
just no way to check the option type.

Quoted 17 lines

util/qemu-option.c bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval) · line 707

Quoted 5 lines
util/qemu-option.c +4 -0
+    if (del) {
+        qemu_opt_del(opt);
+    }
+    return ret;

Couldn't this whole function be shortened to:

char *tmp;

if (del) {
    tmp = qemu_opt_get_del(opts, name);
} else {
    tmp = qemu_opt_get(opts, name);
}
if (!tmp) {
    return defval;
}
Quoted 8 lines

parse_option_bool(name, tmp, &defval, &error_abort); g_free(tmp);
return defval;

or even shorter, if you combine qemu_opt_get{,_del} into calling a common helper function?

Could be if changing qemu_opt_get return value type, but just as said before,
that will affect many codes.

Quoted 64 lines

Review bool qemu_opt_get_bool(QemuOpts *opts, const char · line 612

Quoted 3 lines
(quoted diff) +0 -1
 }
 
-uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t

defval)

util/qemu-option.c bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)

Quoted 6 lines
util/qemu-option.c +6 -0
+bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
+{
+    return _qemu_opt_get_bool(opts, name, defval, false);
+}
+
+bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool

defval)

util/qemu-option.c bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval) · line 718

Quoted 3 lines
util/qemu-option.c +3 -0
+{
+    return _qemu_opt_get_bool(opts, name, defval, true);
+}

Other than the _qemu namespace, this is a good example of how a common helper function makes it easier to implement two variants.

The _number and _size variants will need similar treatment as the _bool.

Review int qemu_opts_foreach(QemuOptsList *list,

Quoted 1 line
(quoted diff) +0 -0
@@ -1302,3 +1443,24 @@ int qemu_opts_foreach(QemuOptsList *list,

qemu_opts_loopfunc func, void *opaque,

util/qemu-option.c int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque, · line 1455

Quoted 13 lines
util/qemu-option.c +10 -0
     loc_pop(&loc);
     return rc;
 }
+
+/* free a QemuOptsList, can accept NULL as arguments */
+void qemu_opts_free(QemuOptsList *list)
+{
+    if (!list) {
+        return;
+    }
+
+    g_free(list);
+}

g_free() is safe to call on NULL. Which means qemu_opts_free(foo) is a fancy way to spell g_free(foo). Do we need this function?

util/qemu-option.c int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque, · line 1464

Quoted 9 lines
util/qemu-option.c +9 -0
+
+void qemu_opts_print_help(QemuOptsList *list)
+{
+    int i;
+    printf("Supported options:\n");
+    for (i = 0; list && list->desc[i].name; i++) {
+        printf("%-16s %s\n", list->desc[i].name,
+               list->desc[i].help ?
+               list->desc[i].help : "");

This prints trailing spaces for any description that lacks help text. Not the end of the world, but I try to be cleaner than that.

Review int qemu_opts_foreach(QemuOptsList *list, · line 1466

Quoted 2 lines
(quoted diff) +2 -0
+    }
+}

Unrelated to either of the other two categories of functions - maybe this patch should be split into three parts.

--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org

#27 lore raw

Re: [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work

Quoted 6 lines · Chunyan Liu
Quoted 6 lines

Why are your later callers using a common helper function, but qemu_opt_get_del() repeating a lot of the body of qemu_opt_get()? Shouldn't qemu_opt_get() and qemu_opt_get_del() call into a common helper?

qemu_opt_get_del must return (char *), but the existing qemu_opt_get

Quoted 8 lines

returns
(const char *). Could also change qemu_opt_get return value to (char *) type,
then these two functions could use a common helper function. But there are too
many places using qemu_opt_get already, if the return value type changes, it will
affect a lot.

Going from 'char *' to 'const char *' is automatic. Have your helper return 'char *', and qemu_opt_get can call it just fine and give its callers their desired const char *.

Quoted 11 lines
Quoted 5 lines

Same problem as in 4/25 - I don't think you can rely on opt->value.boolean being valid if you don't track the union discriminator, and right now, the union discriminator is tracked only via opt->desc.

Couldn't find a reliable way if the option is passed through opts_accept_any,
just no way to check the option type.

Like I said in 4/25, if the option is passed through opts_accept_any, treat it as string only; and make the opt_get_bool function either reject it outright, or to always do the string-to-bool conversion at the time of the lookup:

if (opt->desc) {
    assert(opt->desc->type == QEMU_OPT_BOOL);
    return opt->value.boolean;
} else {
    code to parse opt->str
}
Quoted 4 lines
Quoted 1 line

Could be if changing qemu_opt_get return value type, but just as said before,
that will affect many codes.

Also, changing an existing function that returns 'const char *' into now returning 'char *' will NOT break any callers if the semantics remain unchanged (what WILL break is if the semantics change where the callers must now free the result). But in general, it should still be just fine to have qemu_opt_get return 'const char *' even if the common helper returns 'char *'.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#28 lore raw

Re: [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work

2014-03-11 19:59 GMT+08:00 Eric Blake <[email protected]>:

Quoted 48 lines · Chunyan Liu
Quoted 4 lines
Quoted 4 lines

Why are your later callers using a common helper function, but qemu_opt_get_del() repeating a lot of the body of qemu_opt_get()? Shouldn't qemu_opt_get() and qemu_opt_get_del() call into a common

helper?

Quoted 6 lines
Quoted 2 lines

qemu_opt_get_del must return (char *), but the existing qemu_opt_get

returns
(const char *). Could also change qemu_opt_get return value to (char *) type,
then these two functions could use a common helper function. But there

are

Quoted 4 lines

too
many places using qemu_opt_get already, if the return value type changes, it will
affect a lot.

Going from 'char *' to 'const char *' is automatic. Have your helper return 'char *', and qemu_opt_get can call it just fine and give its callers their desired const char *.

Quoted 11 lines
Quoted 5 lines

Same problem as in 4/25 - I don't think you can rely on opt->value.boolean being valid if you don't track the union discriminator, and right now, the union discriminator is tracked only via opt->desc.

Couldn't find a reliable way if the option is passed through opts_accept_any,
just no way to check the option type.

Like I said in 4/25, if the option is passed through opts_accept_any, treat it as string only; and make the opt_get_bool function either reject it outright, or to always do the string-to-bool conversion at the time of the lookup:

if (opt->desc) {
    assert(opt->desc->type == QEMU_OPT_BOOL);
    return opt->value.boolean;
} else {
    code to parse opt->str
}
Quoted 1 line
Quoted 1 line
Quoted 8 lines
Quoted 3 lines

Could be if changing qemu_opt_get return value type, but just as said before,
that will affect many codes.

Also, changing an existing function that returns 'const char *' into now returning 'char *' will NOT break any callers if the semantics remain unchanged (what WILL break is if the semantics change where the callers must now free the result)

Yes, that's the only change, we need to free the result. There are more than 200
places using qemu_opt_get in existing code, we need to checkout the related files
and free the result one by one.

Quoted 9 lines

But in general, it should still be just fine
to have qemu_opt_get return 'const char *' even if the common helper returns 'char *'.

--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org

#29 lore raw

Re: [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work

Quoted 11 lines · Chunyan Liu
Quoted 9 lines
Quoted 4 lines
Quoted 1 line

Could be if changing qemu_opt_get return value type, but just as said before,
that will affect many codes.

Also, changing an existing function that returns 'const char *' into now returning 'char *' will NOT break any callers if the semantics remain unchanged (what WILL break is if the semantics change where the callers must now free the result)

Quoted 5 lines

Yes, that's the only change, we need to free the result. There are more than 200
places using qemu_opt_get in existing code, we need to checkout the related files
and free the result one by one.

You can still write your helper function so that if 'del' is true, you strdup, if 'del' is false, you return the in-place memory. You'll have to cast away const in the helper, but qemu_opt_get can then restore the const and you don't have to adjust any existing callers, while still sharing the underlying implementation rather than duplicating code. But I guess I'll wait for v23 to see what you actually do in response to my suggestions. If nothing else, please document design decisions in your commit message (for example, if you choose to duplicate code rather than share code in a common helper, explain that the duplication is because one function returns malloc'd memory while the other returns in-place memory).

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#30 lore raw

Re: [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work

2014-03-12 20:40 GMT+08:00 Eric Blake <[email protected]>:

Quoted 40 lines · Chunyan Liu
Quoted 12 lines
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines

Could be if changing qemu_opt_get return value type, but just as said before,
that will affect many codes.

Also, changing an existing function that returns 'const char *' into now returning 'char *' will NOT break any callers if the semantics remain unchanged (what WILL break is if the semantics change where the callers must now free the result)

Quoted 3 lines

Yes, that's the only change, we need to free the result. There are more than 200
places using qemu_opt_get in existing code, we need to checkout the

related

Quoted 2 lines

files
and free the result one by one.

You can still write your helper function so that if 'del' is true, you strdup, if 'del' is false, you return the in-place memory. You'll have to cast away const in the helper, but qemu_opt_get can then restore the const and you don't have to adjust any existing callers, while still sharing the underlying implementation rather than duplicating code. But I guess I'll wait for v23 to see what you actually do in response to my suggestions. If nothing else, please document design decisions in your commit message (for example, if you choose to duplicate code rather than share code in a common helper, explain that the duplication is because one function returns malloc'd memory while the other returns in-place memory).

Got it. Thanks.

--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org

#31 lore raw

Re: [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work

In reply to Eric Blake

2014-03-12 20:40 GMT+08:00 Eric Blake <[email protected]>:

Quoted 17 lines · Chunyan Liu
Quoted 12 lines
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines

Could be if changing qemu_opt_get return value type, but just as said before,
that will affect many codes.

Also, changing an existing function that returns 'const char *' into now returning 'char *' will NOT break any callers if the semantics remain unchanged (what WILL break is if the semantics change where the callers must now free the result)

Quoted 3 lines

Yes, that's the only change, we need to free the result. There are more than 200
places using qemu_opt_get in existing code, we need to checkout the

related

Quoted 8 lines
Quoted 2 lines

files
and free the result one by one.

You can still write your helper function so that if 'del' is true, you strdup, if 'del' is false, you return the in-place memory. You'll have to cast away const in the helper, but qemu_opt_get can then restore the const and you don't have to adjust any existing callers, while still sharing the underlying implementation rather than duplicating code.

After trying, still has blocking here. qemu_opt_get returns either opt->str (this
is char *) or desc->def_value_str (this is const char *). If not g_strdup the result,
return (const char *) is OK, but return (char *) will has build error when casting
(const char *) to (char *).

And since assert(opt->desc && opt->desc->type == xx) doesn't need change for this patch series now, qemu_opt_get_bool could still return opt->value.boolean, doesn't need to call qemu_opt_get to get opt->str and parse that to bool. Same to qemu_opt_get_size/number. So, it's not so urgent that qemu_opt_get/qemu_opt_get_del share common helper function. I'm inclined
to keep duplicating code.

Quoted 14 lines

But
I guess I'll wait for v23 to see what you actually do in response to my suggestions. If nothing else, please document design decisions in your commit message (for example, if you choose to duplicate code rather than share code in a common helper, explain that the duplication is because one function returns malloc'd memory while the other returns in-place memory).

--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org

#32 lore raw

Re: [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work

In reply to Chunyan Liu

Hi,

Quoted 23 lines · Chunyan Liu

Add some qemu_opt functions to replace the same functionality of QEMUOptionParameter handling.

---
 include/qemu/option.h |   9 +++
 util/qemu-option.c    | 188 ++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 184 insertions(+), 13 deletions(-)
include/qemu/option.h +1 -0
index c3b0a91..de4912a 100644
@@ -111,6 +111,7 @@ struct QemuOptsList {
 };
 
 const char *qemu_opt_get(QemuOpts *opts, const char *name);
+char *qemu_opt_get_del(QemuOpts *opts, const char *name);
 /**
  * qemu_opt_has_help_opt:
  * @opts: options to search for a help request

include/qemu/option.h bool qemu_opt_has_help_opt(QemuOpts *opts); · line 134

Quoted 8 lines
include/qemu/option.h +5 -0
@@ -126,6 +127,11 @@ bool qemu_opt_has_help_opt(QemuOpts *opts);
 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);
 uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval);
+bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval);
+uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name,
+                                 uint64_t defval);
+uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name,
+                               uint64_t defval);

I have initially understood you would remove these _del() suffixed functions in your final cleanup, but it seems you haven't. Am I missing something?

Neither the functions nor the callers have been cleanup, why?

Regards..

--
Dorileo

Quoted 285 lines
include/qemu/option.h +3 -0
 int qemu_opt_unset(QemuOpts *opts, const char *name);
 int qemu_opt_set(QemuOpts *opts, const char *name, const char *value);
 void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
@@ -161,4 +167,7 @@ void 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 *dst, QemuOptsList *list);
+void qemu_opts_free(QemuOptsList *list);
+void qemu_opts_print_help(QemuOptsList *list);
 #endif
util/qemu-option.c +175 -13
index df79235..2c450e0 100644
@@ -35,6 +35,7 @@
 
 static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
                                             const char *name);
+static void qemu_opt_del(QemuOpt *opt);
 
 /*
  * Extracts the name of an option from the parameter string (p points at the
@@ -379,6 +380,74 @@ QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest,
     return dest;
 }
 
+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;
+}
+
+/* Create a new QemuOptsList with a desc of the merge of the first
+ * and second. It will allocate space for one new QemuOptsList plus
+ * enough space for QemuOptDesc in first and second QemuOptsList.
+ * First argument's QemuOptDesc members take precedence over second's.
+ * 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.
+ */
+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;
+}
+
 /*
  * Parses a parameter string (param) into an option list (dest).
  *
@@ -574,6 +643,29 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name)
     return opt ? opt->str : NULL;
 }
 
+char *qemu_opt_get_del(QemuOpts *opts, const char *name)
+{
+    QemuOpt *opt;
+    const QemuOptDesc *desc;
+    char *str = NULL;
+
+    if (opts == NULL) {
+        return NULL;
+    }
+
+    opt = qemu_opt_find(opts, name);
+    if (!opt) {
+        desc = find_desc_by_name(opts->list->desc, name);
+        if (desc && desc->def_value_str) {
+            str = g_strdup(desc->def_value_str);
+        }
+        return str;
+    }
+    str = g_strdup(opt->str);
+    qemu_opt_del(opt);
+    return str;
+}
+
 bool qemu_opt_has_help_opt(QemuOpts *opts)
 {
     QemuOpt *opt;
@@ -586,9 +678,11 @@ bool qemu_opt_has_help_opt(QemuOpts *opts)
     return false;
 }
 
-bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
+static bool _qemu_opt_get_bool(QemuOpts *opts, const char *name,
+                               bool defval, bool del)
 {
     QemuOpt *opt;
+    bool ret = defval;
 
     if (opts == NULL) {
         return defval;
@@ -599,19 +693,35 @@ 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);
+            parse_option_bool(name, desc->def_value_str, &ret, &error_abort);
         }
-        return defval;
+        return ret;
     }
     if (opt->desc) {
         assert(opt->desc->type == QEMU_OPT_BOOL);
     }
-    return opt->value.boolean;
+    ret = opt->value.boolean;
+    if (del) {
+        qemu_opt_del(opt);
+    }
+    return ret;
 }
 
-uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
+bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
+{
+    return _qemu_opt_get_bool(opts, name, defval, false);
+}
+
+bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval)
+{
+    return _qemu_opt_get_bool(opts, name, defval, true);
+}
+
+static uint64_t _qemu_opt_get_number(QemuOpts *opts, const char *name,
+                                     uint64_t defval, bool del)
 {
     QemuOpt *opt;
+    uint64_t ret = defval;
 
     if (opts == NULL) {
         return defval;
@@ -622,20 +732,36 @@ 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);
+            parse_option_number(name, desc->def_value_str, &ret, &error_abort);
         }
-        return defval;
+        return ret;
     }
     if (opt->desc) {
         assert(opt->desc->type == QEMU_OPT_NUMBER);
     }
-    return opt->value.uint;
+    ret = opt->value.uint;
+    if (del) {
+        qemu_opt_del(opt);
+    }
+    return ret;
 }
 
-uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
+uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
+{
+    return _qemu_opt_get_number(opts, name, defval, false);
+}
+
+uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name,
+                                 uint64_t defval)
+{
+    return _qemu_opt_get_number(opts, name, defval, true);
+}
+
+static uint64_t _qemu_opt_get_size(QemuOpts *opts, const char *name,
+                                   uint64_t defval, bool del)
 {
     QemuOpt *opt;
+    uint64_t ret = defval;
 
     if (opts == NULL) {
         return defval;
@@ -645,14 +771,29 @@ 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);
+            parse_option_size(name, desc->def_value_str, &ret, &error_abort);
         }
-        return defval;
+        return ret;
     }
     if (opt->desc) {
         assert(opt->desc->type == QEMU_OPT_SIZE);
     }
-    return opt->value.uint;
+    ret = opt->value.uint;
+    if (del) {
+        qemu_opt_del(opt);
+    }
+    return ret;
+}
+
+uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
+{
+    return _qemu_opt_get_size(opts, name, defval, false);
+}
+
+uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name,
+                               uint64_t defval)
+{
+    return _qemu_opt_get_size(opts, name, defval, true);
 }
 
 static void qemu_opt_parse(QemuOpt *opt, Error **errp)
@@ -1302,3 +1443,24 @@ int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
     loc_pop(&loc);
     return rc;
 }
+
+/* free a QemuOptsList, can accept NULL as arguments */
+void qemu_opts_free(QemuOptsList *list)
+{
+    if (!list) {
+        return;
+    }
+
+    g_free(list);
+}
+
+void qemu_opts_print_help(QemuOptsList *list)
+{
+    int i;
+    printf("Supported options:\n");
+    for (i = 0; list && list->desc[i].name; i++) {
+        printf("%-16s %s\n", list->desc[i].name,
+               list->desc[i].help ?
+               list->desc[i].help : "");
+    }
+}
Signature · 1 line
1.7.12.4
#33 lore raw

Re: [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work

2014-03-18 3:35 GMT+08:00 Leandro Dorileo <[email protected]>:

Quoted 44 lines

Hi,

Quoted 8 lines · Chunyan Liu

Add some qemu_opt functions to replace the same functionality of QEMUOptionParameter handling.

---
 include/qemu/option.h |   9 +++
 util/qemu-option.c    | 188

++++++++++++++++++++++++++++++++++++++++++++++----

Quoted 15 lines
 2 files changed, 184 insertions(+), 13 deletions(-)
include/qemu/option.h +1 -0
index c3b0a91..de4912a 100644
@@ -111,6 +111,7 @@ struct QemuOptsList {*0*
 };
 
 const char *qemu_opt_get(QemuOpts *opts, const char *name);
+char *qemu_opt_get_del(QemuOpts *opts, const char *name);
 /**
  * qemu_opt_has_help_opt:
  * @opts: options to search for a help request

include/qemu/option.h bool qemu_opt_has_help_opt(QemuOpts *opts); · line 128

Quoted 2 lines
include/qemu/option.h +0 -0
@@ -126,6 +127,11 @@ bool qemu_opt_has_help_opt(QemuOpts *opts);
 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);

include/qemu/option.h bool qemu_opt_has_help_opt(QemuOpts *opts); · line 129

Quoted 1 line
include/qemu/option.h +0 -0
 uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t

defval);

include/qemu/option.h bool qemu_opt_has_help_opt(QemuOpts *opts); · line 130

Quoted 1 line
include/qemu/option.h +1 -0
+bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool

defval);

include/qemu/option.h bool qemu_opt_has_help_opt(QemuOpts *opts); · line 134

Quoted 4 lines
include/qemu/option.h +4 -0
+uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name,
+                                 uint64_t defval);
+uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name,
+                               uint64_t defval);

I have initially understood you would remove these _del() suffixed functions in your
final cleanup, but it seems you haven't. Am I missing something?

Quoted 2 lines

Neither the functions nor the callers have been cleanup, why?

No, it won't be removed. It replaces the existing handling of QEMUOptionParameter.
For each driver, it handles the options they are expected to handle, then remove those
options from the list; for the left options, they will be passed to proto_drv for 2nd phase
handling.

Quoted 315 lines

Regards..

--
Dorileo

include/qemu/option.h bool qemu_opt_has_help_opt(QemuOpts *opts);

Quoted 3 lines
include/qemu/option.h +0 -0
 int qemu_opt_unset(QemuOpts *opts, const char *name);
 int qemu_opt_set(QemuOpts *opts, const char *name, const char *value);
 void qemu_opt_set_err(QemuOpts *opts, const char *name, const char

*value,

include/qemu/option.h void qemu_opts_print(QemuOpts *opts); · line 167

Quoted 2 lines
include/qemu/option.h +0 -0
@@ -161,4 +167,7 @@ void qemu_opts_print(QemuOpts *opts);
 int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void

*opaque,

Quoted 11 lines
include/qemu/option.h +3 -0
                       int abort_on_failure);
 
+QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list);
+void qemu_opts_free(QemuOptsList *list);
+void qemu_opts_print_help(QemuOptsList *list);
 #endif
util/qemu-option.c +0 -0
index df79235..2c450e0 100644

util/qemu-option.c line 41

Quoted 7 lines
util/qemu-option.c +1 -0
@@ -35,6 +35,7 @@
 
 static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
                                             const char *name);
+static void qemu_opt_del(QemuOpt *opt);
 
 /*
  * Extracts the name of an option from the parameter string (p points

at the

util/qemu-option.c QEMUOptionParameter

Quoted 1 line
util/qemu-option.c +0 -0
@@ -379,6 +380,74 @@ QEMUOptionParameter

*append_option_parameters(QEMUOptionParameter *dest,

util/qemu-option.c const char *qemu_opt_get(QemuOpts *opts, const char

Quoted 75 lines
util/qemu-option.c +68 -0
     return dest;
 }
 
+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;
+}
+
+/* Create a new QemuOptsList with a desc of the merge of the first
+ * and second. It will allocate space for one new QemuOptsList plus
+ * enough space for QemuOptDesc in first and second QemuOptsList.
+ * First argument's QemuOptDesc members take precedence over second's.
+ * 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.
+ */
+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;
+}
+
 /*
  * Parses a parameter string (param) into an option list (dest).
  *
@@ -574,6 +643,29 @@ const char *qemu_opt_get(QemuOpts *opts, const char

*name)

util/qemu-option.c bool qemu_opt_get_bool(QemuOpts *opts, const char

Quoted 43 lines
util/qemu-option.c +26 -1
     return opt ? opt->str : NULL;
 }
 
+char *qemu_opt_get_del(QemuOpts *opts, const char *name)
+{
+    QemuOpt *opt;
+    const QemuOptDesc *desc;
+    char *str = NULL;
+
+    if (opts == NULL) {
+        return NULL;
+    }
+
+    opt = qemu_opt_find(opts, name);
+    if (!opt) {
+        desc = find_desc_by_name(opts->list->desc, name);
+        if (desc && desc->def_value_str) {
+            str = g_strdup(desc->def_value_str);
+        }
+        return str;
+    }
+    str = g_strdup(opt->str);
+    qemu_opt_del(opt);
+    return str;
+}
+
 bool qemu_opt_has_help_opt(QemuOpts *opts)
 {
     QemuOpt *opt;
@@ -586,9 +678,11 @@ bool qemu_opt_has_help_opt(QemuOpts *opts)
     return false;
 }
 
-bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
+static bool _qemu_opt_get_bool(QemuOpts *opts, const char *name,
+                               bool defval, bool del)
 {
     QemuOpt *opt;
+    bool ret = defval;
 
     if (opts == NULL) {
         return defval;
@@ -599,19 +693,35 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char

*name, bool defval)

util/qemu-option.c bool qemu_opt_get_bool(QemuOpts *opts, const char · line 694

Quoted 2 lines
util/qemu-option.c +0 -0
     if (opt == NULL) {
         const QemuOptDesc *desc = find_desc_by_name(opts->list->desc,

name);

util/qemu-option.c bool qemu_opt_get_bool(QemuOpts *opts, const char · line 602

Quoted 2 lines
util/qemu-option.c +0 -1
         if (desc && desc->def_value_str) {
-            parse_option_bool(name, desc->def_value_str, &defval,

&error_abort);

util/qemu-option.c bool qemu_opt_get_bool(QemuOpts *opts, const char · line 696

Quoted 1 line
util/qemu-option.c +1 -0
+            parse_option_bool(name, desc->def_value_str, &ret,

&error_abort);

Quoted 6 lines
util/qemu-option.c +1 -1
         }
-        return defval;
+        return ret;
     }
     if (opt->desc) {
         assert(opt->desc->type == QEMU_OPT_BOOL);

util/qemu-option.c bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)

Quoted 10 lines
util/qemu-option.c +5 -2
     }
-    return opt->value.boolean;
+    ret = opt->value.boolean;
+    if (del) {
+        qemu_opt_del(opt);
+    }
+    return ret;
 }
 
-uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t

defval)

util/qemu-option.c bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)

Quoted 6 lines
util/qemu-option.c +6 -0
+bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
+{
+    return _qemu_opt_get_bool(opts, name, defval, false);
+}
+
+bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool

defval)

util/qemu-option.c uint64_t qemu_opt_get_number(QemuOpts *opts, const

Quoted 13 lines
util/qemu-option.c +7 -0
+{
+    return _qemu_opt_get_bool(opts, name, defval, true);
+}
+
+static uint64_t _qemu_opt_get_number(QemuOpts *opts, const char *name,
+                                     uint64_t defval, bool del)
 {
     QemuOpt *opt;
+    uint64_t ret = defval;
 
     if (opts == NULL) {
         return defval;
@@ -622,20 +732,36 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const

char *name, uint64_t defval)

util/qemu-option.c uint64_t qemu_opt_get_number(QemuOpts *opts, const · line 733

Quoted 2 lines
util/qemu-option.c +0 -0
     if (opt == NULL) {
         const QemuOptDesc *desc = find_desc_by_name(opts->list->desc,

name);

util/qemu-option.c uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)

Quoted 4 lines
util/qemu-option.c +1 -2
         if (desc && desc->def_value_str) {
-            parse_option_number(name, desc->def_value_str, &defval,
-                                &error_abort);
+            parse_option_number(name, desc->def_value_str, &ret,

&error_abort);

Quoted 6 lines
util/qemu-option.c +1 -1
         }
-        return defval;
+        return ret;
     }
     if (opt->desc) {
         assert(opt->desc->type == QEMU_OPT_NUMBER);

util/qemu-option.c uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)

Quoted 10 lines
util/qemu-option.c +5 -2
     }
-    return opt->value.uint;
+    ret = opt->value.uint;
+    if (del) {
+        qemu_opt_del(opt);
+    }
+    return ret;
 }
 
-uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t

defval)

util/qemu-option.c uint64_t qemu_opt_get_number(QemuOpts *opts, const · line 749

Quoted 1 line
util/qemu-option.c +1 -0
+uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t

defval)

util/qemu-option.c uint64_t qemu_opt_get_size(QemuOpts *opts, const

Quoted 19 lines
util/qemu-option.c +13 -0
+{
+    return _qemu_opt_get_number(opts, name, defval, false);
+}
+
+uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name,
+                                 uint64_t defval)
+{
+    return _qemu_opt_get_number(opts, name, defval, true);
+}
+
+static uint64_t _qemu_opt_get_size(QemuOpts *opts, const char *name,
+                                   uint64_t defval, bool del)
 {
     QemuOpt *opt;
+    uint64_t ret = defval;
 
     if (opts == NULL) {
         return defval;
@@ -645,14 +771,29 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const

char *name, uint64_t defval)

util/qemu-option.c uint64_t qemu_opt_get_size(QemuOpts *opts, const · line 772

Quoted 2 lines
util/qemu-option.c +0 -0
     if (opt == NULL) {
         const QemuOptDesc *desc = find_desc_by_name(opts->list->desc,

name);

util/qemu-option.c uint64_t qemu_opt_get_size(QemuOpts *opts, const · line 648

Quoted 2 lines
util/qemu-option.c +0 -1
         if (desc && desc->def_value_str) {
-            parse_option_size(name, desc->def_value_str, &defval,

&error_abort);

util/qemu-option.c uint64_t qemu_opt_get_size(QemuOpts *opts, const · line 774

Quoted 1 line
util/qemu-option.c +1 -0
+            parse_option_size(name, desc->def_value_str, &ret,

&error_abort);

Quoted 6 lines
util/qemu-option.c +1 -1
         }
-        return defval;
+        return ret;
     }
     if (opt->desc) {
         assert(opt->desc->type == QEMU_OPT_SIZE);

util/qemu-option.c uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)

Quoted 10 lines
util/qemu-option.c +8 -1
     }
-    return opt->value.uint;
+    ret = opt->value.uint;
+    if (del) {
+        qemu_opt_del(opt);
+    }
+    return ret;
+}
+
+uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t

defval)

util/qemu-option.c int qemu_opts_foreach(QemuOptsList *list,

Quoted 12 lines
util/qemu-option.c +8 -0
+{
+    return _qemu_opt_get_size(opts, name, defval, false);
+}
+
+uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name,
+                               uint64_t defval)
+{
+    return _qemu_opt_get_size(opts, name, defval, true);
 }
 
 static void qemu_opt_parse(QemuOpt *opt, Error **errp)
@@ -1302,3 +1443,24 @@ int qemu_opts_foreach(QemuOptsList *list,

qemu_opts_loopfunc func, void *opaque,

Quoted 28 lines
util/qemu-option.c +21 -1
     loc_pop(&loc);
     return rc;
 }
+
+/* free a QemuOptsList, can accept NULL as arguments */
+void qemu_opts_free(QemuOptsList *list)
+{
+    if (!list) {
+        return;
+    }
+
+    g_free(list);
+}
+
+void qemu_opts_print_help(QemuOptsList *list)
+{
+    int i;
+    printf("Supported options:\n");
+    for (i = 0; list && list->desc[i].name; i++) {
+        printf("%-16s %s\n", list->desc[i].name,
+               list->desc[i].help ?
+               list->desc[i].help : "");
+    }
+}
--

1.7.12.4

#34 lore raw

PATCH v22 6/25 add convert functions between QEMUOptionParameter to QemuOpts

In reply to Chunyan Liu

Add two temp convert functions between QEMUOptionParameter to QemuOpts, so that next patch can use it. It will simplify next patch for easier review.

---
 include/qemu/option.h |   2 +
 util/qemu-option.c    | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 107 insertions(+)
include/qemu/option.h +2 -0
index de4912a..a6aca59 100644
@@ -170,4 +170,6 @@ 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
util/qemu-option.c +105 -0

108 lines not on this page · raw message

Signature · 1 line
1.7.12.4
#35 lore raw

Re: [Qemu-devel] [PATCH v22 06/25] add convert functions between QEMUOptionParameter to QemuOpts

Quoted 16 lines · Chunyan Liu

Add two temp convert functions between QEMUOptionParameter to QemuOpts, so that next patch can use it. It will simplify next patch for easier review.

---
 include/qemu/option.h |   2 +
 util/qemu-option.c    | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 107 insertions(+)
util/qemu-option.c +6 -0
+
+/* convert QEMUOptionParameter to QemuOpts */
+QemuOptsList *params_to_opts(QEMUOptionParameter *list)
+{
+    QemuOptsList *opts = NULL;
+    size_t num_opts, i = 0;

util/qemu-option.c void qemu_opts_print_help(QemuOptsList *list) · line 1482

Quoted 10 lines
util/qemu-option.c +10 -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;

Dead assignment to NULL, thanks to the g_malloc0 above.

util/qemu-option.c void qemu_opts_print_help(QemuOptsList *list) · line 1490

Quoted 8 lines
util/qemu-option.c +8 -0
+
+    while (list && list->name) {
+        opts->desc[i].name = g_strdup(list->name);
+        opts->desc[i].help = g_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";

Ouch. The pointer used here points to constant memory...

util/qemu-option.c void qemu_opts_print_help(QemuOptsList *list) · line 1497

Quoted 7 lines
util/qemu-option.c +7 -0
+            break;
+
+        case OPT_NUMBER:
+            opts->desc[i].type = QEMU_OPT_NUMBER;
+            if (list->value.n) {
+                opts->desc[i].def_value_str =
+                    g_strdup_printf("%" PRIu64, list->value.n);

...while the pointer used here points to heap memory. Yet I see nothing in the struct that you use to track whether to free the string or not, which means this is more likely a memory leak, but also a potential for a crash during an errant call to g_free(). You absolutely must manage the memory correctly, if you are going to conditionally heap-allocate def_value_str.

For the sake of conversions between the two types, may I suggest an idea:
in 'struct QemuOpt', add a char[24] buffer (that's large enough to hold the maximum stringized uint value). Then, instead of malloc'ing memory with g_strdup_printf, you instead format integers in place. You've already malloc'd the size for the QemuOpt, and now the string representation also fits within that space without needing a secondary malloc.

Whether or not you end up keeping the stringizing buffer permanently part of QemuOpt, or delete it after you delete QEMUOptionParameter, remains to be seen at the end of the series.

util/qemu-option.c void qemu_opts_print_help(QemuOptsList *list) · line 1511

Quoted 3 lines
util/qemu-option.c +3 -0
+        case OPT_STRING:
+            opts->desc[i].type = QEMU_OPT_STRING;
+            opts->desc[i].def_value_str = g_strdup(list->value.s);

Here, just declare that your temporary QemuOptsList result from the function has a shorter lifetime than the input QemuOptionParameter, and set the def_value_str pointer to the original list->value.s instead of duplicating it. Then, you are back to the situation where freeing the temporary QemuOptsList doesn't leak and doesn't risk double frees.

Quoted 9 lines
util/qemu-option.c +9 -0
+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;

util/qemu-option.c void qemu_opts_print_help(QemuOptsList *list) · line 1541

Quoted 10 lines
util/qemu-option.c +10 -0
+    }
+
+    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 = g_strdup(desc->name);
+        dest[i].help = g_strdup(desc->help);

I didn't research QEMUOptionParameter close enough to know if you will be causing any memory leaks on the reverse conversion - but since the end goal of the series is to delete QEMUOptionParameter, this method will eventually disappear, so I guess I could live with leaks here (although it would be nice to document it in the commit message, if you do indeed leak).

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#36 lore raw

PATCH v22 7/25 change block layer to support both QemuOpts and QEMUOptionParamter

In reply to Chunyan Liu

Change block layer to support both QemuOpts and QEMUOptionParameter. After this patch, it will change backend drivers one by one. At the end, QEMUOptionParameter will be removed and only QemuOpts is kept.

---
 block.c                   | 121 ++++++++++++++++++++++++++++++----------------
 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     |   7 +--
 include/block/block_int.h |   8 ++-
 qemu-img.c                | 120 +++++++++++++++++++++++++++++----------------
 12 files changed, 177 insertions(+), 97 deletions(-)
block.c +78 -43
index f1ef4b0..d9b1da3 100644
@@ -408,6 +408,7 @@ typedef struct CreateCo {
     BlockDriver *drv;
     char *filename;
     QEMUOptionParameter *options;
+    QemuOpts *opts;
     int ret;
     Error *err;
 } CreateCo;
@@ -420,7 +421,11 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
     CreateCo *cco = opaque;
     assert(cco->drv);
 
-    ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
+    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);
+    }
     if (local_err) {
         error_propagate(&cco->err, local_err);
     }
@@ -428,7 +433,7 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
 }
 
 int bdrv_create(BlockDriver *drv, const char* filename,
-    QEMUOptionParameter *options, Error **errp)
+    QEMUOptionParameter *options, QemuOpts *opts, Error **errp)
 {
     int ret;
 
@@ -437,11 +442,12 @@ int bdrv_create(BlockDriver *drv, const char* filename,
         .drv = drv,
         .filename = g_strdup(filename),
         .options = options,
+        .opts = opts,
         .ret = NOT_DONE,
         .err = NULL,
     };
 
-    if (!drv->bdrv_create) {
+    if (!drv->bdrv_create && !drv->bdrv_create2) {
         error_setg(errp, "Driver '%s' does not support image creation", drv->format_name);
         ret = -ENOTSUP;
         goto out;
@@ -473,7 +479,7 @@ out:
 }
 
 int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
-                     Error **errp)
+                     QemuOpts *opts, Error **errp)
 {
     BlockDriver *drv;
     Error *local_err = NULL;
@@ -485,7 +491,7 @@ int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
         return -ENOENT;
     }
 
-    ret = bdrv_create(drv, filename, options, &local_err);
+    ret = bdrv_create(drv, filename, options, opts, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
     }
@@ -1248,7 +1254,8 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
         BlockDriverState *bs1;
         int64_t total_size;
         BlockDriver *bdrv_qcow2;
-        QEMUOptionParameter *create_options;
+        QEMUOptionParameter *create_options = NULL;
+        QemuOpts *opts = NULL;
         QDict *snapshot_options;
 
         /* if snapshot, we create a temporary backing file and open it
@@ -1274,13 +1281,21 @@ 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);
+        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);
+        }
 
-        ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, &local_err);
+        ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, opts,
+                          &local_err);
         free_option_parameters(create_options);
+        qemu_opts_del(opts);
         if (ret < 0) {
             error_setg_errno(errp, -ret, "Could not create temporary overlay "
                              "'%s': %s", tmp_filename,
@@ -5229,7 +5244,10 @@ void bdrv_img_create(const char *filename, const char *fmt,
                      Error **errp, bool quiet)
 {
     QEMUOptionParameter *param = NULL, *create_options = NULL;
-    QEMUOptionParameter *backing_fmt, *backing_file, *size;
+    QemuOptsList *create_opts = NULL;
+    QemuOpts *opts = NULL;
+    const char *backing_fmt, *backing_file;
+    int64_t size;
     BlockDriver *drv, *proto_drv;
     BlockDriver *backing_drv = NULL;
     Error *local_err = NULL;
@@ -5248,28 +5266,31 @@ 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);
+    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 parameter list with default values */
-    param = parse_option_parameters("", create_options, param);
-
-    set_option_parameter_int(param, BLOCK_OPT_SIZE, img_size);
+    opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
+    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(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,
-                                 base_filename)) {
+        if (qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename)) {
             error_setg(errp, "Backing file not supported for file format '%s'",
                        fmt);
             goto out;
@@ -5277,37 +5298,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_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);
+                       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) {
             BlockDriverState *bs;
             uint64_t size;
             char buf[32];
@@ -5318,11 +5339,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,
+                                 backing_file,
                                  error_get_pretty(local_err));
                 error_free(local_err);
                 local_err = NULL;
@@ -5332,7 +5353,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
             size *= 512;
 
             snprintf(buf, sizeof(buf), "%" PRId64, size);
-            set_option_parameter(param, BLOCK_OPT_SIZE, buf);
+            qemu_opt_set_number(opts, BLOCK_OPT_SIZE, size);
 
             bdrv_unref(bs);
         } else {
@@ -5343,16 +5364,23 @@ 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, &local_err);
+
+    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);
+    }
+
     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)) {
+        if (qemu_opt_get_size(opts, BLOCK_OPT_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'"
@@ -5365,6 +5393,8 @@ out:
     free_option_parameters(create_options);
     free_option_parameters(param);
 
+    qemu_opts_del(opts);
+    qemu_opts_free(create_opts);
     if (local_err) {
         error_propagate(errp, local_err);
     }
@@ -5382,12 +5412,17 @@ 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, QEMUOptionParameter *options,
+                       QemuOpts *opts)
 {
-    if (bs->drv->bdrv_amend_options == NULL) {
+    if (!bs->drv->bdrv_amend_options && !bs->drv->bdrv_amend_options2) {
         return -ENOTSUP;
     }
-    return bs->drv->bdrv_amend_options(bs, options);
+    if (bs->drv->bdrv_amend_options2) {
+        return bs->drv->bdrv_amend_options2(bs, opts);
+    } else {
+        return bs->drv->bdrv_amend_options(bs, options);
+    }
 }
 
 /* Used to recurse on single child block filters.
block/cow.c +1 -1
index 30deb88..26cf4a5 100644
@@ -345,7 +345,7 @@ static int cow_create(const char *filename, QEMUOptionParameter *options,
         options++;
     }
 
-    ret = bdrv_create_file(filename, options, &local_err);
+    ret = bdrv_create_file(filename, options, NULL, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         return ret;
block/qcow.c +1 -1
index 1e128be..153b9bd 100644
@@ -687,7 +687,7 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options,
         options++;
     }
 
-    ret = bdrv_create_file(filename, options, &local_err);
+    ret = bdrv_create_file(filename, options, NULL, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         return ret;
block/qcow2.c +1 -1
index cfe80be..dcd43bc 100644
@@ -1487,7 +1487,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
     Error *local_err = NULL;
     int ret;
 
-    ret = bdrv_create_file(filename, options, &local_err);
+    ret = bdrv_create_file(filename, options, NULL, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         return ret;
block/qed.c +1 -1
index 8802ad3..db27f36 100644
@@ -566,7 +566,7 @@ static int qed_create(const char *filename, uint32_t cluster_size,
     int ret = 0;
     BlockDriverState *bs;
 
-    ret = bdrv_create_file(filename, NULL, &local_err);
+    ret = bdrv_create_file(filename, NULL, NULL, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         return ret;
block/raw_bsd.c +1 -1
index 01ea692..9ae5fc2 100644
@@ -145,7 +145,7 @@ static int raw_create(const char *filename, QEMUOptionParameter *options,
     Error *local_err = NULL;
     int ret;
 
-    ret = bdrv_create_file(filename, options, &local_err);
+    ret = bdrv_create_file(filename, options, NULL, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
     }
block/vhdx.c +1 -1
index 5390ba6..d8afb42 100644
@@ -1788,7 +1788,7 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options,
     block_size = block_size > VHDX_BLOCK_SIZE_MAX ? VHDX_BLOCK_SIZE_MAX :
                                                     block_size;
 
-    ret = bdrv_create_file(filename, options, &local_err);
+    ret = bdrv_create_file(filename, options, NULL, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         goto exit;
block/vmdk.c +2 -2
index b69988d..d87c8f6 100644
@@ -1525,7 +1525,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, &local_err);
+    ret = bdrv_create_file(filename, NULL, NULL, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         goto exit;
@@ -1865,7 +1865,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
     if (!split && !flat) {
         desc_offset = 0x200;
     } else {
-        ret = bdrv_create_file(filename, options, &local_err);
+        ret = bdrv_create_file(filename, options, NULL, &local_err);
         if (ret < 0) {
             error_setg_errno(errp, -ret, "Could not create image file");
             goto exit;
block/vvfat.c +1 -1
index f966ea5..ee32b3c 100644
@@ -2926,7 +2926,7 @@ static int enable_write_target(BDRVVVFATState *s)
     set_option_parameter_int(options, BLOCK_OPT_SIZE, s->sector_count * 512);
     set_option_parameter(options, BLOCK_OPT_BACKING_FILE, "fat:");
 
-    ret = bdrv_create(bdrv_qcow, s->qcow_filename, options, &local_err);
+    ret = bdrv_create(bdrv_qcow, s->qcow_filename, options, NULL, &local_err);
     if (ret < 0) {
         qerror_report_err(local_err);
         error_free(local_err);
include/block/block.h +4 -3
index 780f48b..c482204 100644
@@ -177,9 +177,9 @@ 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);
+    QEMUOptionParameter *options, QemuOpts *opts, Error **errp);
 int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
-                     Error **errp);
+                     QemuOpts *opts, 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 +283,8 @@ 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, QEMUOptionParameter *options,
+                       QemuOpts *opts);
 
 /* external snapshots */
 
include/block/block_int.h +7 -1
index 0bcf1c9..e4e832f 100644
@@ -118,6 +118,8 @@ struct BlockDriver {
     void (*bdrv_rebind)(BlockDriverState *bs);
     int (*bdrv_create)(const char *filename, QEMUOptionParameter *options,
                        Error **errp);
+    /* FIXME: will remove the duplicate and rename back to bdrv_create later */
+    int (*bdrv_create2)(const char *filename, QemuOpts *opts, Error **errp);
     int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
     int (*bdrv_make_empty)(BlockDriverState *bs);
     /* aio */
@@ -217,7 +219,7 @@ struct BlockDriver {
 
     /* List of options for creating images, terminated by name == NULL */
     QEMUOptionParameter *create_options;
-
+    QemuOptsList *create_opts;
 
     /*
      * Returns 0 for completed check, -errno for internal errors.
@@ -228,6 +230,10 @@ struct BlockDriver {
 
     int (*bdrv_amend_options)(BlockDriverState *bs,
         QEMUOptionParameter *options);
+    /* FIXME: will remove the duplicate and rename back to
+     * bdrv_amend_options later
+     */
+    int (*bdrv_amend_options2)(BlockDriverState *bs, QemuOpts *opts);
 
     void (*bdrv_debug_event)(BlockDriverState *bs, BlkDebugEvent event);
 
qemu-img.c +79 -41

229 lines not on this page · raw message

Signature · 1 line
1.7.12.4
#37 lore raw

Re: [Qemu-devel] [PATCH v22 07/25] change block layer to support both QemuOpts and QEMUOptionParamter

Quoted 9 lines · Chunyan Liu

Change block layer to support both QemuOpts and QEMUOptionParameter. After this patch, it will change backend drivers one by one. At the end, QEMUOptionParameter will be removed and only QemuOpts is kept.

---

block.c static void coroutine_fn bdrv_create_co_entry(void *opaque) · line 425

Quoted 6 lines
block.c +2 -1
@@ -420,7 +421,11 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
     CreateCo *cco = opaque;
     assert(cco->drv);
 
-    ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
+    if (cco->drv->bdrv_create2) {
+        ret = cco->drv->bdrv_create2(cco->filename, cco->opts, &local_err);

Is it worth assert(!cco->options) here,

block.c static void coroutine_fn bdrv_create_co_entry(void *opaque) · line 427

Quoted 2 lines
block.c +2 -0
+    } else {
+        ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);

and assert(!cco->opts) here, to ensure that we aren't ignoring options from the other style of create? Then again, it gets cleaned up in later patches.

block.c void bdrv_img_create(const char *filename, const char *fmt, · line 5271

Quoted 11 lines
block.c +3 -4
@@ -5248,28 +5266,31 @@ 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);
+    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);

Memory leak. As implemented earlier in the series, qemu_opts_append() creates a new object, but as you are overwriting create_opts with the second result without hanging onto the pointer returned by the first call, you have just leaked the first instance.

I ran out of time to review further today, but this series still needs more work, and I am starting to doubt that it will make 2.0.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#38 lore raw

Re: [Qemu-devel] [PATCH v22 07/25] change block layer to support both QemuOpts and QEMUOptionParamter

In reply to Chunyan Liu

block.c static void coroutine_fn bdrv_create_co_entry(void *opaque) · line 438

Quoted 13 lines · Chunyan Liu

Change block layer to support both QemuOpts and QEMUOptionParameter. After this patch, it will change backend drivers one by one. At the end, QEMUOptionParameter will be removed and only QemuOpts is kept.

---

int bdrv_create(BlockDriver *drv, const char* filename,

block.c +1 -1
-    QEMUOptionParameter *options, Error **errp)
+    QEMUOptionParameter *options, QemuOpts *opts, Error **errp)
 {
     int ret;

In addition to my remarks last night:

I wonder if you should add:

assert(!(options && opts))

to prove that all callers are passing at most one of the two supported option lists, while doing the conversion.

block.c void bdrv_img_create(const char *filename, const char *fmt, · line 5271

Quoted 11 lines
block.c +3 -4
@@ -5248,28 +5266,31 @@ 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);
+    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);

In addition to the memory leak I pointed out earlier, I see another potential problem: What if drv has been converted to QemuOpts, but proto_drv is still on QEMUOptionParameter?

block.c void bdrv_img_create(const char *filename, const char *fmt, · line 5276

Quoted 5 lines
block.c +5 -0
+    } else {
+        create_options = append_option_parameters(create_options,
+                                                  drv->create_options);
+        create_options = append_option_parameters(create_options,
+                                                  proto_drv->create_options);

Or the converse, if drv is still on QEMUOptionParameter, but proto_drv has been converted to QEMUOpts?

Either way, you will be appending NULL for the proto_drv case, when what you really wanted to be doing was merging both the QemuOpts and QEMUOptionParameters into a single list.

Review void bdrv_img_create(const char *filename, const char *fmt, · line 5278

Quoted 2 lines
(quoted diff) +2 -0
+        create_opts = params_to_opts(create_options);
+    }

I think a better path to conversion would be doing everything possible in QemuOpts, and only switching to QEMUOptionParameters at the last possible moment, rather than having two separate append code paths.

My suggestion: until the conversion is complete, add a new function, something like:

void qemu_opts_append_pair(QemuOpts *dst, QemuOpts *opts,

                           QEMUOptionParameter *options) {
    assert(!(opts && options));
    ... modify dst in-place to have it cover the entries from opts or

options
}

then in this code, you do:

    create_options = /* generate empty QemuOpts */;
    qemu_opts_append_pair(options, drv->create_opts,
                          drv->create_options);
    qemu_opts_append_pair(options, proto_drv->create_options,
                          proto_drv->create_options);

block.c void bdrv_img_create(const char *filename, const char *fmt, · line 5282

Quoted 7 lines
block.c +2 -3
     /* Create parameter list with default values */
-    param = parse_option_parameters("", create_options, param);
-
-    set_option_parameter_int(param, BLOCK_OPT_SIZE, img_size);
+    opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
+    qemu_opt_set_number(opts, BLOCK_OPT_SIZE, img_size);

This part worked nicely - once you convert both incoming styles to QemuOpts, it really is easier to have this part of the code just use QemuOpts functions for setting the size....

Quoted 7 lines

...

block.c +1 -1
@@ -5343,16 +5364,23 @@ 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);

block.c void bdrv_img_create(const char *filename, const char *fmt, · line 5376

Quoted 10 lines
block.c +7 -1
         puts("");
     }
-    ret = bdrv_create(drv, filename, param, &local_err);
+
+    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);
+    }

...and finally convert back to QEMUOptionParameters at the last moment.
But wait a minute - why are you checking for drv->bdrv_create2 here?
Isn't the last possible moment really inside bdrv_create() (that is, the actual function that decides whether to call drv->bdrv_create vs. drv->bdrv_create2)? For the code to be as clean as possible, you want to use QemuOpts everywhere until the actual point where you are calling the unconverted callback.

block.c void bdrv_add_before_write_notifier(BlockDriverState *bs, · line 5424

Quoted 13 lines
block.c +7 -3
-int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options)
+int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options,
+                       QemuOpts *opts)
 {
-    if (bs->drv->bdrv_amend_options == NULL) {
+    if (!bs->drv->bdrv_amend_options && !bs->drv->bdrv_amend_options2) {
         return -ENOTSUP;
     }
-    return bs->drv->bdrv_amend_options(bs, options);
+    if (bs->drv->bdrv_amend_options2) {
+        return bs->drv->bdrv_amend_options2(bs, opts);
+    } else {
+        return bs->drv->bdrv_amend_options(bs, options);

Similar to the create/create2 situation, _this_ function is the last possible place to make the conversions. You have a problem in that if the user passes you options but the callback expects opts, you are passing NULL to the callback. I think this should look more like:

int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options,
QemuOpts *opts)

{
    int ret;
    assert(!(opts && options));
    if (!bs->drv->bdrv_amend_options && !bs->drv->bdrv_amend_options2) {
        return -ENOTSUP;
    }
    if (bs->drv->bdrv_amend_options2) {
        if (options) {
            opts = params_to_opts(options);
        }
        ret = bs->drv->bdrv_amend_options2(bs, opts);
        if (options) {
            g_free(opts); // or whatever correct spelling to avoid leak
        }
    } else {
        if (opts) {
            options = opts_to_params(opts);
        }
        ret = bs->drv->bdrv_amend_options(bs, options);
        if (opts) {
            g_free(options); // again, with correct spelling
        }
    }
    return ret;

include/block/block_int.h struct BlockDriver { · line 122

Quoted 7 lines
include/block/block_int.h +3 -0
+++ b/include/block/block_int.h
@@ -118,6 +118,8 @@ struct BlockDriver {
     void (*bdrv_rebind)(BlockDriverState *bs);
     int (*bdrv_create)(const char *filename, QEMUOptionParameter *options,
                        Error **errp);
+    /* FIXME: will remove the duplicate and rename back to bdrv_create later */
+    int (*bdrv_create2)(const char *filename, QemuOpts *opts, Error **errp);

I like the FIXME here; maybe also mention that bdrv_create and bdrv_create2 are mutually exclusive (at most one can be non-NULL).

include/block/block_int.h struct BlockDriver { · line 222

Quoted 9 lines
include/block/block_int.h +1 -1
     int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
     int (*bdrv_make_empty)(BlockDriverState *bs);
     /* aio */
@@ -217,7 +219,7 @@ struct BlockDriver {
 
     /* List of options for creating images, terminated by name == NULL */
     QEMUOptionParameter *create_options;
-
+    QemuOptsList *create_opts;

A similar FIXME comment here might be nice, likewise mentioning that at most one of these two fields should be non-NULL.

Quoted 13 lines
qemu-img.c +6 -3
@@ -244,21 +245,34 @@ 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 (drv->create_opts) {
+        create_opts = qemu_opts_append(create_opts, drv->create_opts);
+    } else {
+        create_options = append_option_parameters(create_options,
+                                                  drv->create_options);
+    }

qemu-img.c static int print_block_option_help(const char *filename, const char *fmt) · line 261

Quoted 10 lines
qemu-img.c +2 -2
     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);
+        if (drv->create_opts) {
+            create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);

Memory leak.

qemu-img.c static int print_block_option_help(const char *filename, const char *fmt) · line 273

Quoted 13 lines
qemu-img.c +10 -1
+        } else {
+            create_options =
+                append_option_parameters(create_options,
+                                         proto_drv->create_options);
+        }
     }
 
-    print_option_help(create_options);
+    if (drv->create_opts) {
+        qemu_opts_print_help(create_opts);
+    } else {
+        print_option_help(create_options);
+    }

Another case where if you add a new helper function that absorbs either style of options into a QemuOpts, then all you have to do here is print the QemuOpts, instead of trying to switch between print methods here.

qemu-img.c static int img_convert(int argc, char **argv) · line 1361

Quoted 8 lines
qemu-img.c +3 -1
@@ -1340,40 +1356,42 @@ 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);

More memory leaks.

qemu-img.c static int img_convert(int argc, char **argv) · line 1426

Quoted 11 lines
qemu-img.c +6 -1
@@ -1400,7 +1418,12 @@ static int img_convert(int argc, char **argv)
 
     if (!skip_create) {
         /* Create the new image */
-        ret = bdrv_create(drv, out_filename, param, &local_err);
+        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);
+        }

Another case where you should just always pass opts to bdrv_create(), and let bdrv_create() do the last minute conversion to QEMUOptionParameters based on what callbacks drv supports, rather than trying to make decisions here based on contents of drv.

qemu-img.c static int img_amend(int argc, char **argv) · line 2751

Quoted 10 lines
qemu-img.c +1 -5
@@ -2721,17 +2748,26 @@ 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) {
+    if (bs->drv->bdrv_amend_options2) {

And again, you should not be making decisions on the contents of bs->drv, but just blindly setting up QemuOpts here...

Quoted 9 lines
qemu-img.c +8 -0
+        create_opts = qemu_opts_append(create_opts, bs->drv->create_opts);
+    } else {
+        create_options = append_option_parameters(create_options,
+                                                  bs->drv->create_options);
+        create_opts = params_to_opts(create_options);
+    }
+    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);

qemu-img.c static int img_amend(int argc, char **argv) · line 2769

Quoted 10 lines
qemu-img.c +5 -1
         ret = -1;
         goto out;
     }
 
-    ret = bdrv_amend_options(bs, options_param);
+    if (bs->drv->bdrv_amend_options2) {
+        ret = bdrv_amend_options(bs, NULL, opts);
+    } else {
+        options_param = opts_to_params(opts);
+        ret = bdrv_amend_options(bs, options_param, NULL);

...and blindly letting bdrv_amend_options() be the place that converts to QEMUOptionParameters as needed.

Here's hoping v23 is nicer; I'm looking forward to ditching QEMUOptionParameters.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#39 lore raw

Re: [Qemu-devel] [PATCH v22 07/25] change block layer to support both QemuOpts and QEMUOptionParamter

2014-03-12 0:54 GMT+08:00 Eric Blake <[email protected]>:

Quoted 33 lines · Chunyan Liu

block.c static void coroutine_fn bdrv_create_co_entry(void *opaque) · line 438

Quoted 13 lines

Change block layer to support both QemuOpts and QEMUOptionParameter. After this patch, it will change backend drivers one by one. At the end, QEMUOptionParameter will be removed and only QemuOpts is kept.

---

int bdrv_create(BlockDriver *drv, const char* filename,

block.c +1 -1
-    QEMUOptionParameter *options, Error **errp)
+    QEMUOptionParameter *options, QemuOpts *opts, Error **errp)
 {
     int ret;

In addition to my remarks last night:

I wonder if you should add:

assert(!(options && opts))

to prove that all callers are passing at most one of the two supported option lists, while doing the conversion.

Review void bdrv_img_create(const char *filename, const

Quoted 1 line
(quoted diff) +0 -0
@@ -5248,28 +5266,31 @@ void bdrv_img_create(const char *filename, const

char *fmt,

block.c void bdrv_img_create(const char *filename, const char *fmt, · line 5258

Quoted 7 lines
block.c +0 -4
         return;
     }
 
-    create_options = append_option_parameters(create_options,
-                                              drv->create_options);
-    create_options = append_option_parameters(create_options,
-
Quoted 7 lines

proto_drv->create_options);

block.c void bdrv_img_create(const char *filename, const char *fmt,

Quoted 3 lines
block.c +3 -0
+    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);

In addition to the memory leak I pointed out earlier,

Should use g_realloc in qemu_opts_append, realloc create_opts to the desired space and append 2nd list to it. Saving the effort to free memory while append many times.

I see another

Quoted 35 lines

potential problem: What if drv has been converted to QemuOpts, but proto_drv is still on QEMUOptionParameter?

block.c void bdrv_img_create(const char *filename, const char *fmt,

Quoted 5 lines
block.c +5 -0
+    } else {
+        create_options = append_option_parameters(create_options,
+                                                  drv->create_options);
+        create_options = append_option_parameters(create_options,
+

proto_drv->create_options);

Or the converse, if drv is still on QEMUOptionParameter, but proto_drv has been converted to QEMUOpts?

Either way, you will be appending NULL for the proto_drv case, when what you really wanted to be doing was merging both the QemuOpts and QEMUOptionParameters into a single list.

Review void bdrv_img_create(const char *filename, const · line 5278

Quoted 2 lines
(quoted diff) +2 -0
+        create_opts = params_to_opts(create_options);
+    }

I think a better path to conversion would be doing everything possible in QemuOpts, and only switching to QEMUOptionParameters at the last possible moment, rather than having two separate append code paths.

My suggestion: until the conversion is complete, add a new function, something like:

void qemu_opts_append_pair(QemuOpts *dst, QemuOpts *opts,

                           QEMUOptionParameter *options) {
    assert(!(opts && options));
    ... modify dst in-place to have it cover the entries from opts or

options
}

Quoted 8 lines

then in this code, you do:

    create_options = /* generate empty QemuOpts */;
    qemu_opts_append_pair(options, drv->create_opts,
                          drv->create_options);
    qemu_opts_append_pair(options, proto_drv->create_options,
                          proto_drv->create_options);

Good. Together with always using QemuOpts and only converting to QEMUOptionParameter until it calls .bdrv_create in specific driver, the drv/proto_drv inconsistent problem could be solved. Will update.

Thanks very much for all your suggestions!

Chunyan

Quoted 245 lines

block.c void bdrv_img_create(const char *filename, const char *fmt, · line 5282

Quoted 7 lines
block.c +2 -3
     /* Create parameter list with default values */
-    param = parse_option_parameters("", create_options, param);
-
-    set_option_parameter_int(param, BLOCK_OPT_SIZE, img_size);
+    opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
+    qemu_opt_set_number(opts, BLOCK_OPT_SIZE, img_size);

This part worked nicely - once you convert both incoming styles to QemuOpts, it really is easier to have this part of the code just use QemuOpts functions for setting the size....

Review void bdrv_img_create(const char *filename, const

Quoted 2 lines

...

(quoted diff) +0 -0
@@ -5343,16 +5364,23 @@ void bdrv_img_create(const char *filename, const

char *fmt,

Quoted 5 lines
block.c +1 -1
     if (!quiet) {
         printf("Formatting '%s', fmt=%s ", filename, fmt);
-        print_option_parameters(param);
+        qemu_opts_print(opts);

block.c void bdrv_img_create(const char *filename, const char *fmt, · line 5376

Quoted 10 lines
block.c +7 -1
         puts("");
     }
-    ret = bdrv_create(drv, filename, param, &local_err);
+
+    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);
+    }

...and finally convert back to QEMUOptionParameters at the last moment.
But wait a minute - why are you checking for drv->bdrv_create2 here?
Isn't the last possible moment really inside bdrv_create() (that is, the actual function that decides whether to call drv->bdrv_create vs. drv->bdrv_create2)? For the code to be as clean as possible, you want to use QemuOpts everywhere until the actual point where you are calling the unconverted callback.

Review void bdrv_img_create(const char *filename, const · line 5349

Quoted 1 line
(quoted diff) +0 -1
-int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter

*options)

Review void bdrv_img_create(const char *filename, const · line 5376

Quoted 1 line
(quoted diff) +1 -0
+int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter

*options,

block.c void bdrv_add_before_write_notifier(BlockDriverState *bs, · line 5424

Quoted 11 lines
block.c +6 -2
+                       QemuOpts *opts)
 {
-    if (bs->drv->bdrv_amend_options == NULL) {
+    if (!bs->drv->bdrv_amend_options && !bs->drv->bdrv_amend_options2) {
         return -ENOTSUP;
     }
-    return bs->drv->bdrv_amend_options(bs, options);
+    if (bs->drv->bdrv_amend_options2) {
+        return bs->drv->bdrv_amend_options2(bs, opts);
+    } else {
+        return bs->drv->bdrv_amend_options(bs, options);

Similar to the create/create2 situation, _this_ function is the last possible place to make the conversions. You have a problem in that if the user passes you options but the callback expects opts, you are passing NULL to the callback. I think this should look more like:

int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options,
QemuOpts *opts)

{
    int ret;
    assert(!(opts && options));
    if (!bs->drv->bdrv_amend_options && !bs->drv->bdrv_amend_options2) {
        return -ENOTSUP;
    }
    if (bs->drv->bdrv_amend_options2) {
        if (options) {
            opts = params_to_opts(options);
        }
        ret = bs->drv->bdrv_amend_options2(bs, opts);
        if (options) {
            g_free(opts); // or whatever correct spelling to avoid leak
        }
    } else {
        if (opts) {
            options = opts_to_params(opts);
        }
        ret = bs->drv->bdrv_amend_options(bs, options);
        if (opts) {
            g_free(options); // again, with correct spelling
        }
    }
    return ret;

Review struct BlockDriver { · line 119

Quoted 4 lines
(quoted diff) +1 -0
+++ b/include/block/block_int.h
@@ -118,6 +118,8 @@ struct BlockDriver {
     void (*bdrv_rebind)(BlockDriverState *bs);
     int (*bdrv_create)(const char *filename, QEMUOptionParameter

*options,

Review struct BlockDriver { · line 121

Quoted 2 lines
(quoted diff) +1 -0
                        Error **errp);
+    /* FIXME: will remove the duplicate and rename back to bdrv_create

later */

Review struct BlockDriver { · line 122

Quoted 1 line
(quoted diff) +1 -0
+    int (*bdrv_create2)(const char *filename, QemuOpts *opts, Error

**errp);

I like the FIXME here; maybe also mention that bdrv_create and bdrv_create2 are mutually exclusive (at most one can be non-NULL).

include/block/block_int.h struct BlockDriver { · line 220

Quoted 6 lines
include/block/block_int.h +0 -0
     int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
     int (*bdrv_make_empty)(BlockDriverState *bs);
     /* aio */
@@ -217,7 +219,7 @@ struct BlockDriver {
 
     /* List of options for creating images, terminated by name == NULL

*/

include/block/block_int.h struct BlockDriver { · line 222

Quoted 3 lines
include/block/block_int.h +1 -1
     QEMUOptionParameter *create_options;
-
+    QemuOptsList *create_opts;

A similar FIXME comment here might be nice, likewise mentioning that at most one of these two fields should be non-NULL.

Review static int print_block_option_help(const char

Quoted 1 line
(quoted diff) +0 -0
@@ -244,21 +245,34 @@ static int print_block_option_help(const char

*filename, const char *fmt)

Quoted 10 lines
qemu-img.c +4 -3
         return 1;
     }
 
-    create_options = append_option_parameters(create_options,
-                                              drv->create_options);
-
+    if (drv->create_opts) {
+        create_opts = qemu_opts_append(create_opts, drv->create_opts);
+    } else {
+        create_options = append_option_parameters(create_options,

qemu-img.c static int print_block_option_help(const char *filename, const char *fmt)

Quoted 10 lines
qemu-img.c +2 -2
+                                                  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);

Review static int print_block_option_help(const char · line 261

Quoted 2 lines
(quoted diff) +2 -0
+        if (drv->create_opts) {
+            create_opts = qemu_opts_append(create_opts,

proto_drv->create_opts);

Memory leak.

qemu-img.c static int print_block_option_help(const char *filename, const char *fmt) · line 273

Quoted 13 lines
qemu-img.c +10 -1
+        } else {
+            create_options =
+                append_option_parameters(create_options,
+                                         proto_drv->create_options);
+        }
     }
 
-    print_option_help(create_options);
+    if (drv->create_opts) {
+        qemu_opts_print_help(create_opts);
+    } else {
+        print_option_help(create_options);
+    }

Another case where if you add a new helper function that absorbs either style of options into a QemuOpts, then all you have to do here is print the QemuOpts, instead of trying to switch between print methods here.

qemu-img.c static int img_convert(int argc, char **argv) · line 1361

Quoted 8 lines
qemu-img.c +3 -1
@@ -1340,40 +1356,42 @@ 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);

More memory leaks.

qemu-img.c static int img_convert(int argc, char **argv) · line 1422

Quoted 7 lines
qemu-img.c +2 -1
@@ -1400,7 +1418,12 @@ static int img_convert(int argc, char **argv)
 
     if (!skip_create) {
         /* Create the new image */
-        ret = bdrv_create(drv, out_filename, param, &local_err);
+        if (drv->bdrv_create2) {
+            ret = bdrv_create(drv, out_filename, NULL, opts,

&local_err);

block.c void bdrv_img_create(const char *filename, const char *fmt,

Quoted 3 lines
block.c +3 -0
+        } else {
+            param = opts_to_params(opts);
+            ret = bdrv_create(drv, out_filename, param, NULL,

&local_err);

Review static int img_convert(int argc, char **argv) · line 1426

Quoted 1 line
(quoted diff) +1 -0
+        }

Another case where you should just always pass opts to bdrv_create(), and let bdrv_create() do the last minute conversion to QEMUOptionParameters based on what callbacks drv supports, rather than trying to make decisions here based on contents of drv.

qemu-img.c static int img_amend(int argc, char **argv) · line 2751

Quoted 10 lines
qemu-img.c +1 -5
@@ -2721,17 +2748,26 @@ 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) {
+    if (bs->drv->bdrv_amend_options2) {

And again, you should not be making decisions on the contents of bs->drv, but just blindly setting up QemuOpts here...

Review static int img_amend(int argc, char **argv) · line 2752

Quoted 1 line
(quoted diff) +1 -0
+        create_opts = qemu_opts_append(create_opts,

bs->drv->create_opts);

block.c void bdrv_img_create(const char *filename, const char *fmt, · line 5377

Quoted 3 lines
block.c +3 -0
+    } else {
+        create_options = append_option_parameters(create_options,
+

bs->drv->create_options);

Quoted 5 lines
qemu-img.c +4 -0
+        create_opts = params_to_opts(create_options);
+    }
+    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);

qemu-img.c static int img_amend(int argc, char **argv) · line 2769

Quoted 10 lines
qemu-img.c +5 -1
         ret = -1;
         goto out;
     }
 
-    ret = bdrv_amend_options(bs, options_param);
+    if (bs->drv->bdrv_amend_options2) {
+        ret = bdrv_amend_options(bs, NULL, opts);
+    } else {
+        options_param = opts_to_params(opts);
+        ret = bdrv_amend_options(bs, options_param, NULL);

...and blindly letting bdrv_amend_options() be the place that converts to QEMUOptionParameters as needed.

Here's hoping v23 is nicer; I'm looking forward to ditching QEMUOptionParameters.

--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org

#40 lore raw

PATCH v22 8/25 cow.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/cow.c | 54 ++++++++++++++++++++++++++----------------------------
 1 file changed, 26 insertions(+), 28 deletions(-)
block/cow.c +26 -28
index 26cf4a5..4085201 100644
@@ -324,31 +324,24 @@ 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 *opts, Error **errp)
 {
     struct cow_header_v2 cow_header;
     struct stat st;
     int64_t image_sectors = 0;
-    const char *image_filename = NULL;
+    char *image_filename = NULL;
     Error *local_err = NULL;
     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_del(opts, BLOCK_OPT_SIZE, 0) / 512;
+    image_filename = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
 
-    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;
+        goto exit;
     }
 
     cow_bs = NULL;
@@ -356,7 +349,7 @@ static int cow_create(const char *filename, QEMUOptionParameter *options,
                     BDRV_O_RDWR | BDRV_O_PROTOCOL, NULL, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
-        return ret;
+        goto exit;
     }
 
     memset(&cow_header, 0, sizeof(cow_header));
@@ -389,22 +382,27 @@ static int cow_create(const char *filename, QEMUOptionParameter *options,
     }
 
 exit:
+    g_free(image_filename);
     bdrv_unref(cow_bs);
     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"
-    },
-    { NULL }
+static QemuOptsList cow_create_opts = {
+    .name = "cow-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(cow_create_opts.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"
+        },
+        { /* end of list */ }
+    }
 };
 
 static BlockDriver bdrv_cow = {
@@ -414,14 +412,14 @@ static BlockDriver bdrv_cow = {
     .bdrv_probe     = cow_probe,
     .bdrv_open      = cow_open,
     .bdrv_close     = cow_close,
-    .bdrv_create    = cow_create,
+    .bdrv_create2   = cow_create,
     .bdrv_has_zero_init     = bdrv_has_zero_init_1,
 
     .bdrv_read              = cow_co_read,
     .bdrv_write             = cow_co_write,
     .bdrv_co_get_block_status   = cow_co_get_block_status,
 
-    .create_options = cow_create_options,
+    .create_opts       = &cow_create_opts,
 };
 
 static void bdrv_cow_init(void)
Signature · 1 line
1.7.12.4
Reviewed-by on v22 8/25
#42 lore raw

Re: [Qemu-devel] [PATCH v22 08/25] cow.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
Quoted 11 lines · Chunyan Liu
---
 block/cow.c | 54 ++++++++++++++++++++++++++----------------------------
 1 file changed, 26 insertions(+), 28 deletions(-)
block/cow.c +0 -0
@@ -414,14 +412,14 @@ static BlockDriver bdrv_cow = {
     .bdrv_probe     = cow_probe,
     .bdrv_open      = cow_open,
     .bdrv_close     = cow_close,

block/cow.c static BlockDriver bdrv_cow = { · line 422

Quoted 10 lines
block/cow.c +2 -2
-    .bdrv_create    = cow_create,
+    .bdrv_create2   = cow_create,
     .bdrv_has_zero_init     = bdrv_has_zero_init_1,
 
     .bdrv_read              = cow_co_read,
     .bdrv_write             = cow_co_write,
     .bdrv_co_get_block_status   = cow_co_get_block_status,
 
-    .create_options = cow_create_options,
+    .create_opts       = &cow_create_opts,

Inconsistent alignment of =, and inconsistent use of & (it is not needed here, '.create_opts = cow_create_opts' is just fine).

But those are both minor;

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#43 lore raw

Re: [Qemu-devel] [PATCH v22 08/25] cow.c: replace QEMUOptionParameter with QemuOpts

2014-03-11 23:28 GMT+08:00 Eric Blake <[email protected]>:

Quoted 20 lines · Chunyan Liu
Quoted 19 lines
---
 block/cow.c | 54 ++++++++++++++++++++++++++----------------------------
 1 file changed, 26 insertions(+), 28 deletions(-)
block/cow.c +1 -1
@@ -414,14 +412,14 @@ static BlockDriver bdrv_cow = {
     .bdrv_probe     = cow_probe,
     .bdrv_open      = cow_open,
     .bdrv_close     = cow_close,
-    .bdrv_create    = cow_create,
+    .bdrv_create2   = cow_create,
     .bdrv_has_zero_init     = bdrv_has_zero_init_1,
 
     .bdrv_read              = cow_co_read,
     .bdrv_write             = cow_co_write,
     .bdrv_co_get_block_status   = cow_co_get_block_status,
 
Quoted 6 lines

block/cow.c static BlockDriver bdrv_cow = { · line 422

Quoted 2 lines
block/cow.c +1 -1
-    .create_options = cow_create_options,
+    .create_opts       = &cow_create_opts,

Inconsistent alignment of =, and inconsistent use of & (it is not needed here, '.create_opts = cow_create_opts' is just fine).

& is needed, since cow_create_opts is a struct, but .create_opts is struct *;
It's different from cow_create_options, which is a struct array, .create_options
is struct *, so it can simply let the pointer = array name.

Quoted 10 lines

But those are both minor;

--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org

#44 lore raw

PATCH v22 9/25 gluster.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/gluster.c | 81 ++++++++++++++++++++++++++++++---------------------------
 1 file changed, 42 insertions(+), 39 deletions(-)
block/gluster.c +42 -39
index a44d612..bd72d8d 100644
@@ -471,13 +471,14 @@ 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)
+                               QemuOpts *opts, Error **errp)
 {
     struct glfs *glfs;
     struct glfs_fd *fd;
     int ret = 0;
     int prealloc = 0;
     int64_t total_size = 0;
+    char *tmp;
     GlusterConf *gconf = g_malloc0(sizeof(GlusterConf));
 
     glfs = qemu_gluster_init(gconf, filename, errp);
@@ -486,24 +487,21 @@ 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;
-            }
-        }
-        options++;
+    total_size =
+        qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
+
+    tmp = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
+    if (!tmp || !strcmp(tmp, "off")) {
+        prealloc = 0;
+    } else if (!strcmp(tmp, "full") &&
+               gluster_supports_zerofill()) {
+        prealloc = 1;
+    } else {
+        error_setg(errp, "Invalid preallocation mode: '%s'"
+            " or GlusterFS doesn't support zerofill API",
+            tmp);
+        ret = -EINVAL;
+        goto out;
     }
 
     fd = glfs_creat(glfs, gconf->image,
@@ -525,6 +523,7 @@ static int qemu_gluster_create(const char *filename,
         }
     }
 out:
+    g_free(tmp);
     qemu_gluster_gconf_free(gconf);
     if (glfs) {
         glfs_fini(glfs);
@@ -688,18 +687,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)"
-    },
-    { 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"
+        },
+        {
+            .name = BLOCK_OPT_PREALLOC,
+            .type = OPT_STRING,
+            .help = "Preallocation mode (allowed values: off, full)"
+        },
+        { /* end of list */ }
+    }
 };
 
 static BlockDriver bdrv_gluster = {
@@ -712,7 +715,7 @@ static BlockDriver bdrv_gluster = {
     .bdrv_reopen_commit           = qemu_gluster_reopen_commit,
     .bdrv_reopen_abort            = qemu_gluster_reopen_abort,
     .bdrv_close                   = qemu_gluster_close,
-    .bdrv_create                  = qemu_gluster_create,
+    .bdrv_create2                 = qemu_gluster_create,
     .bdrv_getlength               = qemu_gluster_getlength,
     .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
     .bdrv_truncate                = qemu_gluster_truncate,
@@ -726,7 +729,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_opts                  = &qemu_gluster_create_opts,
 };
 
 static BlockDriver bdrv_gluster_tcp = {
@@ -739,7 +742,7 @@ static BlockDriver bdrv_gluster_tcp = {
     .bdrv_reopen_commit           = qemu_gluster_reopen_commit,
     .bdrv_reopen_abort            = qemu_gluster_reopen_abort,
     .bdrv_close                   = qemu_gluster_close,
-    .bdrv_create                  = qemu_gluster_create,
+    .bdrv_create2                 = qemu_gluster_create,
     .bdrv_getlength               = qemu_gluster_getlength,
     .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
     .bdrv_truncate                = qemu_gluster_truncate,
@@ -753,7 +756,7 @@ static BlockDriver bdrv_gluster_tcp = {
 #ifdef CONFIG_GLUSTERFS_ZEROFILL
     .bdrv_co_write_zeroes         = qemu_gluster_co_write_zeroes,
 #endif
-    .create_options               = qemu_gluster_create_options,
+    .create_opts                  = &qemu_gluster_create_opts,
 };
 
 static BlockDriver bdrv_gluster_unix = {
@@ -766,7 +769,7 @@ static BlockDriver bdrv_gluster_unix = {
     .bdrv_reopen_commit           = qemu_gluster_reopen_commit,
     .bdrv_reopen_abort            = qemu_gluster_reopen_abort,
     .bdrv_close                   = qemu_gluster_close,
-    .bdrv_create                  = qemu_gluster_create,
+    .bdrv_create2                 = qemu_gluster_create,
     .bdrv_getlength               = qemu_gluster_getlength,
     .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
     .bdrv_truncate                = qemu_gluster_truncate,
@@ -780,7 +783,7 @@ static BlockDriver bdrv_gluster_unix = {
 #ifdef CONFIG_GLUSTERFS_ZEROFILL
     .bdrv_co_write_zeroes         = qemu_gluster_co_write_zeroes,
 #endif
-    .create_options               = qemu_gluster_create_options,
+    .create_opts                  = &qemu_gluster_create_opts,
 };
 
 static BlockDriver bdrv_gluster_rdma = {
@@ -793,7 +796,7 @@ static BlockDriver bdrv_gluster_rdma = {
     .bdrv_reopen_commit           = qemu_gluster_reopen_commit,
     .bdrv_reopen_abort            = qemu_gluster_reopen_abort,
     .bdrv_close                   = qemu_gluster_close,
-    .bdrv_create                  = qemu_gluster_create,
+    .bdrv_create2                 = qemu_gluster_create,
     .bdrv_getlength               = qemu_gluster_getlength,
     .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
     .bdrv_truncate                = qemu_gluster_truncate,
@@ -807,7 +810,7 @@ static BlockDriver bdrv_gluster_rdma = {
 #ifdef CONFIG_GLUSTERFS_ZEROFILL
     .bdrv_co_write_zeroes         = qemu_gluster_co_write_zeroes,
 #endif
-    .create_options               = qemu_gluster_create_options,
+    .create_opts                  = &qemu_gluster_create_opts,
 };
 
 static void bdrv_gluster_init(void)
Signature · 1 line
1.7.12.4
#46 lore raw

Re: [Qemu-devel] [PATCH v22 09/25] gluster.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu

block/gluster.c static BlockDriver bdrv_gluster = { · line 732

Quoted 13 lines · Chunyan Liu
---
 block/gluster.c | 81 ++++++++++++++++++++++++++++++---------------------------
 1 file changed, 42 insertions(+), 39 deletions(-)
block/gluster.c +1 -1
@@ -726,7 +729,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_opts                  = &qemu_gluster_create_opts,

Unnecessary &. Probably true in most of your patches.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#47 lore raw

PATCH v22 10/25 iscsi.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/iscsi.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)
block/iscsi.c +14 -15
index b490e98..4379d14 100644
@@ -1394,13 +1394,8 @@ 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_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
     bs->opaque = g_malloc0(sizeof(struct IscsiLun));
     iscsilun = bs->opaque;
 
@@ -1451,13 +1446,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"
-    },
-    { 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 = {
@@ -1469,7 +1468,7 @@ static BlockDriver bdrv_iscsi = {
     .bdrv_file_open  = iscsi_open,
     .bdrv_close      = iscsi_close,
     .bdrv_create     = iscsi_create,
-    .create_options  = iscsi_create_options,
+    .create_opts     = &iscsi_create_opts,
     .bdrv_reopen_prepare  = iscsi_reopen_prepare,
 
     .bdrv_getlength  = iscsi_getlength,
Signature · 1 line
1.7.12.4
#49 lore raw

PATCH v22 11/25 qcow.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/qcow.c | 72 ++++++++++++++++++++++++++++++------------------------------
 1 file changed, 36 insertions(+), 36 deletions(-)
block/qcow.c +36 -36
index 153b9bd..374e6df 100644
@@ -662,35 +662,29 @@ 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 *opts, 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;
+    char *backing_file = NULL;
     int 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_del(opts, BLOCK_OPT_SIZE, 0) / 512;
+    backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+    if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) {
+        flags |= BLOCK_FLAG_ENCRYPT;
     }
 
-    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;
+        goto cleanup;
     }
 
     qcow_bs = NULL;
@@ -698,7 +692,7 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options,
                     BDRV_O_RDWR | BDRV_O_PROTOCOL, NULL, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
-        return ret;
+        goto cleanup;
     }
 
     ret = bdrv_truncate(qcow_bs, 0);
@@ -769,6 +763,8 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options,
     ret = 0;
 exit:
     bdrv_unref(qcow_bs);
+cleanup:
+    g_free(backing_file);
     return ret;
 }
 
@@ -881,24 +877,28 @@ static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
     return 0;
 }
 
-
-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"
-    },
-    { NULL }
+static QemuOptsList qcow_create_opts = {
+    .name = "qcow-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(qcow_create_opts.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_BOOL,
+            .help = "Encrypt the image",
+            .def_value_str = "off"
+        },
+        { /* end of list */ }
+    }
 };
 
 static BlockDriver bdrv_qcow = {
@@ -907,8 +907,8 @@ static BlockDriver bdrv_qcow = {
     .bdrv_probe		= qcow_probe,
     .bdrv_open		= qcow_open,
     .bdrv_close		= qcow_close,
-    .bdrv_reopen_prepare = qcow_reopen_prepare,
-    .bdrv_create	= qcow_create,
+    .bdrv_reopen_prepare    = qcow_reopen_prepare,
+    .bdrv_create2           = qcow_create,
     .bdrv_has_zero_init     = bdrv_has_zero_init_1,
 
     .bdrv_co_readv          = qcow_co_readv,
@@ -920,7 +920,7 @@ static BlockDriver bdrv_qcow = {
     .bdrv_write_compressed  = qcow_write_compressed,
     .bdrv_get_info          = qcow_get_info,
 
-    .create_options = qcow_create_options,
+    .create_opts            = &qcow_create_opts,
 };
 
 static void bdrv_qcow_init(void)
Signature · 1 line
1.7.12.4
#51 lore raw

Re: [Qemu-devel] [PATCH v22 11/25] qcow.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
Quoted 5 lines · Chunyan Liu
---
 block/qcow.c | 72 ++++++++++++++++++++++++++++++------------------------------
 1 file changed, 36 insertions(+), 36 deletions(-)

See my comments on patch 24 - this commit temporarily breaks the vvfat driver, which is trying to reuse the qcow create_options member.

Quoted 10 lines
block/qcow.c +1 -1
@@ -920,7 +920,7 @@ static BlockDriver bdrv_qcow = {
     .bdrv_write_compressed  = qcow_write_compressed,
     .bdrv_get_info          = qcow_get_info,
 
-    .create_options = qcow_create_options,
+    .create_opts            = &qcow_create_opts,
 };
 
 static void bdrv_qcow_init(void)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#52 lore raw

PATCH v22 12/25 qcow2.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/qcow2.c | 325 ++++++++++++++++++++++++++++++----------------------------
 1 file changed, 167 insertions(+), 158 deletions(-)
block/qcow2.c +167 -158
index dcd43bc..e0f00bf 100644
@@ -1455,7 +1455,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 */
@@ -1487,7 +1487,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;
@@ -1622,11 +1622,11 @@ out:
     return ret;
 }
 
-static int qcow2_create(const char *filename, QEMUOptionParameter *options,
-                        Error **errp)
+static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp)
 {
-    const char *backing_file = NULL;
-    const char *backing_fmt = NULL;
+    char *backing_file = NULL;
+    char *backing_fmt = NULL;
+    char *buf;
     uint64_t sectors = 0;
     int flags = 0;
     size_t cluster_size = DEFAULT_CLUSTER_SIZE;
@@ -1636,64 +1636,64 @@ 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);
+        ret = -EINVAL;
+        goto finish;
+    }
+    g_free(buf);
+    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);
+        ret = -EINVAL;
+        goto finish;
+    }
+
+    if (qemu_opt_get_bool_del(opts, BLOCK_OPT_LAZY_REFCOUNTS, false)) {
+        flags |= BLOCK_FLAG_LAZY_REFCOUNTS;
     }
 
     if (backing_file && prealloc) {
         error_setg(errp, "Backing file and preallocation cannot be used at "
                    "the same time");
-        return -EINVAL;
+        ret = -EINVAL;
+        goto finish;
     }
 
     if (version < 3 && (flags & BLOCK_FLAG_LAZY_REFCOUNTS)) {
         error_setg(errp, "Lazy refcounts only supported with compatibility "
                    "level 1.1 and above (use compat=1.1 or greater)");
-        return -EINVAL;
+        ret = -EINVAL;
+        goto finish;
     }
 
     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 (local_err) {
         error_propagate(errp, local_err);
     }
+
+finish:
+    g_free(backing_file);
+    g_free(backing_fmt);
+    g_free(buf);
     return ret;
 }
 
@@ -2058,66 +2058,61 @@ 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 *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;
+    char *backing_file = NULL, *backing_format = NULL;
     bool lazy_refcounts = s->use_lazy_refcounts;
+    char *compat = NULL, *prealloc = NULL;
+    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);
+        ret = -EINVAL;
+        goto finish;
+    }
 
-        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");
+        ret = -ENOTSUP;
+        goto finish;
+    }
+
+    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");
+        ret = -ENOTSUP;
+        goto finish;
     }
 
+    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");
+        ret = -ENOTSUP;
+        goto finish;
+    }
+
+    lazy_refcounts = qemu_opt_get_bool_del(opts, "lazy_refcounts",
+                                           lazy_refcounts);
+
     if (new_version != old_version) {
         if (new_version > old_version) {
             /* Upgrade */
@@ -2125,12 +2120,12 @@ static int qcow2_amend_options(BlockDriverState *bs,
             ret = qcow2_update_header(bs);
             if (ret < 0) {
                 s->qcow_version = old_version;
-                return ret;
+                goto finish;
             }
         } else {
             ret = qcow2_downgrade(bs, new_version);
             if (ret < 0) {
-                return ret;
+                goto finish;
             }
         }
     }
@@ -2139,7 +2134,7 @@ static int qcow2_amend_options(BlockDriverState *bs,
         ret = qcow2_change_backing_file(bs, backing_file ?: bs->backing_file,
                                         backing_format ?: bs->backing_format);
         if (ret < 0) {
-            return ret;
+            goto finish;
         }
     }
 
@@ -2148,27 +2143,28 @@ static int qcow2_amend_options(BlockDriverState *bs,
             if (s->qcow_version < 3) {
                 fprintf(stderr, "Lazy refcounts only supported with compatibility "
                         "level 1.1 and above (use compat=1.1 or greater)\n");
-                return -EINVAL;
+                ret = -EINVAL;
+                goto finish;
             }
             s->compatible_features |= QCOW2_COMPAT_LAZY_REFCOUNTS;
             ret = qcow2_update_header(bs);
             if (ret < 0) {
                 s->compatible_features &= ~QCOW2_COMPAT_LAZY_REFCOUNTS;
-                return ret;
+                goto finish;
             }
             s->use_lazy_refcounts = true;
         } else {
             /* make image clean first */
             ret = qcow2_mark_clean(bs);
             if (ret < 0) {
-                return ret;
+                goto finish;
             }
             /* now disallow lazy refcounts */
             s->compatible_features &= ~QCOW2_COMPAT_LAZY_REFCOUNTS;
             ret = qcow2_update_header(bs);
             if (ret < 0) {
                 s->compatible_features |= QCOW2_COMPAT_LAZY_REFCOUNTS;
-                return ret;
+                goto finish;
             }
             s->use_lazy_refcounts = false;
         }
@@ -2177,56 +2173,69 @@ static int qcow2_amend_options(BlockDriverState *bs,
     if (new_size) {
         ret = bdrv_truncate(bs, new_size);
         if (ret < 0) {
-            return ret;
+            goto finish;
         }
     }
 
-    return 0;
+    ret = 0;
+
+finish:
+    g_free(backing_file);
+    g_free(backing_format);
+    g_free(compat);
+    g_free(prealloc);
+    return ret;
 }
 
-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 = {
@@ -2236,10 +2245,10 @@ static BlockDriver bdrv_qcow2 = {
     .bdrv_open          = qcow2_open,
     .bdrv_close         = qcow2_close,
     .bdrv_reopen_prepare  = qcow2_reopen_prepare,
-    .bdrv_create        = qcow2_create,
-    .bdrv_has_zero_init = bdrv_has_zero_init_1,
+    .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,
+    .bdrv_set_key           = qcow2_set_key,
 
     .bdrv_co_readv          = qcow2_co_readv,
     .bdrv_co_writev         = qcow2_co_writev,
@@ -2254,8 +2263,8 @@ static BlockDriver bdrv_qcow2 = {
     .bdrv_snapshot_goto     = qcow2_snapshot_goto,
     .bdrv_snapshot_delete   = qcow2_snapshot_delete,
     .bdrv_snapshot_list     = qcow2_snapshot_list,
-    .bdrv_snapshot_load_tmp     = qcow2_snapshot_load_tmp,
-    .bdrv_get_info      = qcow2_get_info,
+    .bdrv_snapshot_load_tmp = qcow2_snapshot_load_tmp,
+    .bdrv_get_info          = qcow2_get_info,
     .bdrv_get_specific_info = qcow2_get_specific_info,
 
     .bdrv_save_vmstate    = qcow2_save_vmstate,
@@ -2266,9 +2275,9 @@ static BlockDriver bdrv_qcow2 = {
     .bdrv_refresh_limits        = qcow2_refresh_limits,
     .bdrv_invalidate_cache      = qcow2_invalidate_cache,
 
-    .create_options = qcow2_create_options,
-    .bdrv_check = qcow2_check,
-    .bdrv_amend_options = qcow2_amend_options,
+    .create_opts         = &qcow2_create_opts,
+    .bdrv_check          = qcow2_check,
+    .bdrv_amend_options2 = qcow2_amend_options,
 };
 
 static void bdrv_qcow2_init(void)
Signature · 1 line
1.7.12.4
#53 lore raw

Re: [Qemu-devel] [PATCH v22 12/25] qcow2.c: replace QEMUOptionParameter with QemuOpts

Quoted 48 lines · Chunyan Liu
block/qcow2.c +5 -39
@@ -1636,64 +1636,64 @@ 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;

block/qcow2.c static int qcow2_create(const char *filename, QEMUOptionParameter *options, · line 1653

Quoted 10 lines
block/qcow2.c +10 -0
+    }
+    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);

This should be error_setg(errp, "Invalid preallocation mode: '%s'", options->value.s).

Please check the other patches too to ensure the error_setg() hasn't been turned into fprintf().

#54 lore raw

Re: [Qemu-devel] [PATCH v22 12/25] qcow2.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu

block/qcow2.c out: · line 1629

Quoted 13 lines · Chunyan Liu
block/qcow2.c +4 -4
@@ -1622,11 +1622,11 @@ out:
     return ret;
 }
 
-static int qcow2_create(const char *filename, QEMUOptionParameter *options,
-                        Error **errp)
+static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp)
 {
-    const char *backing_file = NULL;
-    const char *backing_fmt = NULL;
+    char *backing_file = NULL;
+    char *backing_fmt = NULL;
+    char *buf;

It wouldn't hurt to initialize buf to NULL. That way there is no chance of introducing a bug by jumping to the error path before buf has been initialized.

Stefan

#55 lore raw

PATCH v22 13/25 qed.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/qed.c | 114 ++++++++++++++++++++++++++++++++----------------------------
 block/qed.h |   3 +-
 2 files changed, 61 insertions(+), 56 deletions(-)
block/qed.c +60 -54
index db27f36..a22c2d9 100644
@@ -621,53 +621,51 @@ out:
     return ret;
 }
 
-static int bdrv_qed_create(const char *filename, QEMUOptionParameter *options,
-                           Error **errp)
+static int bdrv_qed_create(const char *filename, QemuOpts *opts, Error **errp)
 {
     uint64_t image_size = 0;
     uint32_t cluster_size = QED_DEFAULT_CLUSTER_SIZE;
     uint32_t table_size = QED_DEFAULT_TABLE_SIZE;
-    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++;
-    }
+    char *backing_file = NULL;
+    char *backing_fmt = NULL;
+    int ret;
+
+    image_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+    backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+    backing_fmt = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT);
+    cluster_size = qemu_opt_get_size_del(opts,
+                                         BLOCK_OPT_CLUSTER_SIZE,
+                                         QED_DEFAULT_CLUSTER_SIZE);
+    table_size = qemu_opt_get_size_del(opts, BLOCK_OPT_TABLE_SIZE,
+                                       QED_DEFAULT_TABLE_SIZE);
 
     if (!qed_is_cluster_size_valid(cluster_size)) {
         fprintf(stderr, "QED cluster size must be within range [%u, %u] and power of 2\n",
                 QED_MIN_CLUSTER_SIZE, QED_MAX_CLUSTER_SIZE);
-        return -EINVAL;
+        ret = -EINVAL;
+        goto finish;
     }
     if (!qed_is_table_size_valid(table_size)) {
         fprintf(stderr, "QED table size must be within range [%u, %u] and power of 2\n",
                 QED_MIN_TABLE_SIZE, QED_MAX_TABLE_SIZE);
-        return -EINVAL;
+        ret = -EINVAL;
+        goto finish;
     }
     if (!qed_is_image_size_valid(image_size, cluster_size, table_size)) {
         fprintf(stderr, "QED image size must be a non-zero multiple of "
                         "cluster size and less than %" PRIu64 " bytes\n",
                 qed_max_image_size(cluster_size, table_size));
-        return -EINVAL;
+        ret = -EINVAL;
+        goto finish;
     }
 
-    return qed_create(filename, cluster_size, image_size, table_size,
-                      backing_file, backing_fmt, errp);
+    ret = qed_create(filename, cluster_size, image_size, table_size,
+                     backing_file, backing_fmt, errp);
+
+finish:
+    g_free(backing_file);
+    g_free(backing_fmt);
+    return ret;
 }
 
 typedef struct {
@@ -1575,43 +1573,51 @@ 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_opts = {
+    .name = "qed-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(qed_create_opts.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_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_value_str = stringify(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_opts              = &qed_create_opts,
 
     .bdrv_probe               = bdrv_qed_probe,
     .bdrv_rebind              = bdrv_qed_rebind,
     .bdrv_open                = bdrv_qed_open,
     .bdrv_close               = bdrv_qed_close,
     .bdrv_reopen_prepare      = bdrv_qed_reopen_prepare,
-    .bdrv_create              = bdrv_qed_create,
+    .bdrv_create2             = bdrv_qed_create,
     .bdrv_has_zero_init       = bdrv_has_zero_init_1,
     .bdrv_co_get_block_status = bdrv_qed_co_get_block_status,
     .bdrv_aio_readv           = bdrv_qed_aio_readv,
block/qed.h +1 -2
index 5d65bea..b024751 100644
@@ -43,7 +43,7 @@
  *
  * All fields are little-endian on disk.
  */
-
+#define  QED_DEFAULT_CLUSTER_SIZE  65536
 enum {
     QED_MAGIC = 'Q' | 'E' << 8 | 'D' << 16 | '\0' << 24,
 
@@ -69,7 +69,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
Signature · 1 line
1.7.12.4
#56 lore raw

Re: [Qemu-devel] [PATCH v22 13/25] qed.c: replace QEMUOptionParameter with QemuOpts

Quoted 14 lines · Chunyan Liu
block/qed.h +1 -1
index 5d65bea..b024751 100644
@@ -43,7 +43,7 @@
  *
  * All fields are little-endian on disk.
  */
-
+#define  QED_DEFAULT_CLUSTER_SIZE  65536
 enum {
     QED_MAGIC = 'Q' | 'E' << 8 | 'D' << 16 | '\0' << 24,
 

block/qed.h enum { · line 72

Quoted 4 lines
block/qed.h +0 -1
@@ -69,7 +69,6 @@ enum {
      */
     QED_MIN_CLUSTER_SIZE = 4 * 1024, /* in bytes */
     QED_MAX_CLUSTER_SIZE = 64 * 1024 * 1024,
-    QED_DEFAULT_CLUSTER_SIZE = 64 * 1024,

Why is this change made for cluster size but not table size?

Stefan

#57 lore raw

Re: [Qemu-devel] [PATCH v22 13/25] qed.c: replace QEMUOptionParameter with QemuOpts

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 3/11/2014 at 10:24 PM, in message

<[email protected]>, Stefan Hajnoczi

Quoted 14 lines · <[email protected]> wrote:
Quoted 13 lines · Chunyan Liu
block/qed.h +1 -1
index 5d65bea..b024751 100644 
@@ -43,7 +43,7 @@ 
  * 
  * All fields are little-endian on disk. 
  */ 
- 
+#define  QED_DEFAULT_CLUSTER_SIZE  65536 
 enum { 
     QED_MAGIC = 'Q' | 'E' << 8 | 'D' << 16 | '\0' << 24, 
 
Quoted 7 lines

block/qed.h enum { · line 72

Quoted 5 lines
block/qed.h +0 -1
@@ -69,7 +69,6 @@ enum { 
      */ 
     QED_MIN_CLUSTER_SIZE = 4 * 1024, /* in bytes */ 
     QED_MAX_CLUSTER_SIZE = 64 * 1024 * 1024, 
-    QED_DEFAULT_CLUSTER_SIZE = 64 * 1024, 

Why is this change made for cluster size but not table size?

According to existing create_options, "cluster size" has default value = QED_DEFAULT_CLUSTER_SIZE, after switching to create_opts, this has to be stringized and set to .def_value_str. That is,
.def_value_str = stringify(QED_DEFAULT_CLUSTER_SIZE),
so the QED_DEFAULT_CLUSTER_SIZE could not be a expression, here changes. "table size" has no default value in create_options, not need such changes

Quoted 4 lines

Stefan

#58 lore raw

Re: [Qemu-devel] [PATCH v22 13/25] qed.c: replace QEMUOptionParameter with QemuOpts

Quoted 27 lines · Chun Yan Liu
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 3/11/2014 at 10:24 PM, in message

<[email protected]>, Stefan Hajnoczi

Quoted 14 lines · <[email protected]> wrote:
Quoted 13 lines · Chunyan Liu
block/qed.h +1 -1
index 5d65bea..b024751 100644 
@@ -43,7 +43,7 @@ 
  * 
  * All fields are little-endian on disk. 
  */ 
- 
+#define  QED_DEFAULT_CLUSTER_SIZE  65536 
 enum { 
     QED_MAGIC = 'Q' | 'E' << 8 | 'D' << 16 | '\0' << 24, 
 
Quoted 7 lines

block/qed.h enum { · line 72

Quoted 5 lines
block/qed.h +0 -1
@@ -69,7 +69,6 @@ enum { 
      */ 
     QED_MIN_CLUSTER_SIZE = 4 * 1024, /* in bytes */ 
     QED_MAX_CLUSTER_SIZE = 64 * 1024 * 1024, 
-    QED_DEFAULT_CLUSTER_SIZE = 64 * 1024, 

Why is this change made for cluster size but not table size?

Quoted 6 lines

According to existing create_options, "cluster size" has default value = QED_DEFAULT_CLUSTER_SIZE, after switching to create_opts, this has to be stringized and set to .def_value_str. That is,
.def_value_str = stringify(QED_DEFAULT_CLUSTER_SIZE),
so the QED_DEFAULT_CLUSTER_SIZE could not be a expression, here changes. "table size" has no default value in create_options, not need such changes

Okay, thanks!

#59 lore raw

PATCH v22 14/25 raw-posix.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/raw-posix.c | 59 +++++++++++++++++++++++++------------------------------
 1 file changed, 27 insertions(+), 32 deletions(-)
block/raw-posix.c +27 -32
index e6b4c1f..7fc4a3a 100644
@@ -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 *opts, Error **errp)
 {
     int fd;
     int result = 0;
@@ -1244,12 +1243,8 @@ 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_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
 
     fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
                    0644);
@@ -1410,13 +1405,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"
-    },
-    { 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 = {
@@ -1431,7 +1430,7 @@ static BlockDriver bdrv_file = {
     .bdrv_reopen_commit = raw_reopen_commit,
     .bdrv_reopen_abort = raw_reopen_abort,
     .bdrv_close = raw_close,
-    .bdrv_create = raw_create,
+    .bdrv_create2 = raw_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_co_get_block_status = raw_co_get_block_status,
     .bdrv_co_write_zeroes = raw_co_write_zeroes,
@@ -1448,7 +1447,7 @@ static BlockDriver bdrv_file = {
     .bdrv_get_allocated_file_size
                         = raw_get_allocated_file_size,
 
-    .create_options = raw_create_options,
+    .create_opts = &raw_create_opts,
 };
 
 /***********************************************/
@@ -1760,7 +1759,7 @@ static coroutine_fn int hdev_co_write_zeroes(BlockDriverState *bs,
     return -ENOTSUP;
 }
 
-static int hdev_create(const char *filename, QEMUOptionParameter *options,
+static int hdev_create(const char *filename, QemuOpts *opts,
                        Error **errp)
 {
     int fd;
@@ -1769,12 +1768,8 @@ static int hdev_create(const char *filename, QEMUOptionParameter *options,
     int64_t total_size = 0;
 
     /* 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;
 
     fd = qemu_open(filename, O_WRONLY | O_BINARY);
     if (fd < 0) {
@@ -1810,8 +1805,8 @@ static BlockDriver bdrv_host_device = {
     .bdrv_reopen_prepare = raw_reopen_prepare,
     .bdrv_reopen_commit  = raw_reopen_commit,
     .bdrv_reopen_abort   = raw_reopen_abort,
-    .bdrv_create        = hdev_create,
-    .create_options     = raw_create_options,
+    .bdrv_create2        = hdev_create,
+    .create_opts         = &raw_create_opts,
     .bdrv_co_write_zeroes = hdev_co_write_zeroes,
 
     .bdrv_aio_readv	= raw_aio_readv,
@@ -1944,8 +1939,8 @@ static BlockDriver bdrv_host_floppy = {
     .bdrv_reopen_prepare = raw_reopen_prepare,
     .bdrv_reopen_commit  = raw_reopen_commit,
     .bdrv_reopen_abort   = raw_reopen_abort,
-    .bdrv_create        = hdev_create,
-    .create_options     = raw_create_options,
+    .bdrv_create2        = hdev_create,
+    .create_opts         = &raw_create_opts,
 
     .bdrv_aio_readv     = raw_aio_readv,
     .bdrv_aio_writev    = raw_aio_writev,
@@ -2055,8 +2050,8 @@ static BlockDriver bdrv_host_cdrom = {
     .bdrv_reopen_prepare = raw_reopen_prepare,
     .bdrv_reopen_commit  = raw_reopen_commit,
     .bdrv_reopen_abort   = raw_reopen_abort,
-    .bdrv_create        = hdev_create,
-    .create_options     = raw_create_options,
+    .bdrv_create2        = hdev_create,
+    .create_opts         = &raw_create_opts,
 
     .bdrv_aio_readv     = raw_aio_readv,
     .bdrv_aio_writev    = raw_aio_writev,
@@ -2185,8 +2180,8 @@ static BlockDriver bdrv_host_cdrom = {
     .bdrv_reopen_prepare = raw_reopen_prepare,
     .bdrv_reopen_commit  = raw_reopen_commit,
     .bdrv_reopen_abort   = raw_reopen_abort,
-    .bdrv_create        = hdev_create,
-    .create_options     = raw_create_options,
+    .bdrv_create2        = hdev_create,
+    .create_opts        = &raw_create_opts,
 
     .bdrv_aio_readv     = raw_aio_readv,
     .bdrv_aio_writev    = raw_aio_writev,
Signature · 1 line
1.7.12.4
#61 lore raw

PATCH v22 15/25 raw-win32.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/raw-win32.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)
block/raw-win32.c +19 -19
index 9954748..29f8e54 100644
@@ -475,8 +475,7 @@ 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 *opts, Error **errp)
 {
     int fd;
     int64_t total_size = 0;
@@ -484,12 +483,8 @@ 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 / 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);
@@ -503,13 +498,18 @@ 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 = {
@@ -518,9 +518,9 @@ static BlockDriver bdrv_file = {
     .instance_size	= sizeof(BDRVRawState),
     .bdrv_needs_filename = true,
     .bdrv_parse_filename = raw_parse_filename,
-    .bdrv_file_open	= raw_open,
-    .bdrv_close		= raw_close,
-    .bdrv_create	= raw_create,
+    .bdrv_file_open     = raw_open,
+    .bdrv_close         = raw_close,
+    .bdrv_create2       = raw_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
 
     .bdrv_aio_readv     = raw_aio_readv,
@@ -532,7 +532,7 @@ static BlockDriver bdrv_file = {
     .bdrv_get_allocated_file_size
                         = raw_get_allocated_file_size,
 
-    .create_options = raw_create_options,
+    .create_opts        = &raw_create_opts,
 };
 
 /***********************************************/
Signature · 1 line
1.7.12.4
#63 lore raw

PATCH v22 16/25 raw_bsd.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/raw_bsd.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)
block/raw_bsd.c +15 -12
index 9ae5fc2..ee797fd 100644
@@ -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"
-    },
-    { 0 }
+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_reopen_prepare(BDRVReopenState *reopen_state,
@@ -139,13 +143,12 @@ 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 *opts, Error **errp)
 {
     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 (local_err) {
         error_propagate(errp, local_err);
     }
@@ -177,7 +180,7 @@ static BlockDriver bdrv_raw = {
     .bdrv_reopen_prepare  = &raw_reopen_prepare,
     .bdrv_open            = &raw_open,
     .bdrv_close           = &raw_close,
-    .bdrv_create          = &raw_create,
+    .bdrv_create2         = &raw_create,
     .bdrv_co_readv        = &raw_co_readv,
     .bdrv_co_writev       = &raw_co_writev,
     .bdrv_co_write_zeroes = &raw_co_write_zeroes,
@@ -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_opts          = &raw_create_opts,
     .bdrv_has_zero_init   = &raw_has_zero_init
 };
 
Signature · 1 line
1.7.12.4
Reviewed-by on v22 16/25
#64 lore raw

Re: [Qemu-devel] [PATCH v22 16/25] raw_bsd.c: replace QEMUOptionParameter with QemuOpts

Quoted 23 lines · Chunyan Liu
---
 block/raw_bsd.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)
block/raw_bsd.c +2 -7
index 9ae5fc2..ee797fd 100644
@@ -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"
-    },
-    { 0 }
+static QemuOptsList raw_create_opts = {
+    .name = "raw-create-opts",

block/raw_bsd.c line 43

Quoted 10 lines
block/raw_bsd.c +9 -0
+    .head = QTAILQ_HEAD_INITIALIZER(raw_create_opts.head),
+    .desc = {
+        {
+            .name = BLOCK_OPT_SIZE,
+            .type = QEMU_OPT_SIZE,
+            .help = "Virtual disk size"
+        },
+        { /* end of list */ }
+    }
 };

Hmm...I'm not sure how this works. The option isn't consumed so maybe we don't need to declare it at all. However, it's not your problem because it was like this before already.

#65 lore raw

PATCH v22 17/25 rbd.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/rbd.c | 63 +++++++++++++++++++++++++++++--------------------------------
 1 file changed, 30 insertions(+), 33 deletions(-)
block/rbd.c +30 -33
index dbc79f4..f878877 100644
@@ -282,8 +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,
-                           Error **errp)
+static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **errp)
 {
     int64_t bytes = 0;
     int64_t objsize;
@@ -306,24 +305,18 @@ static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options,
     }
 
     /* 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_del(opts, BLOCK_OPT_SIZE, 0);
+    objsize = qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE, 0);
+    if (objsize) {
+        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 +893,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"
-    },
-    {NULL}
+static QemuOptsList qemu_rbd_create_opts = {
+    .name = "rbd-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_rbd_create_opts.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"
+        },
+        { /* end of list */ }
+    }
 };
 
 static BlockDriver bdrv_rbd = {
@@ -920,10 +917,10 @@ static BlockDriver bdrv_rbd = {
     .bdrv_needs_filename = true,
     .bdrv_file_open     = qemu_rbd_open,
     .bdrv_close         = qemu_rbd_close,
-    .bdrv_create        = qemu_rbd_create,
+    .bdrv_create2       = 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_opts        = &qemu_rbd_create_opts,
     .bdrv_getlength     = qemu_rbd_getlength,
     .bdrv_truncate      = qemu_rbd_truncate,
     .protocol_name      = "rbd",
Signature · 1 line
1.7.12.4
#67 lore raw

PATCH v22 18/25 sheepdog.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/sheepdog.c | 108 ++++++++++++++++++++++++++++---------------------------
 1 file changed, 55 insertions(+), 53 deletions(-)
block/sheepdog.c +55 -53
index f7bd024..027a34e 100644
@@ -1626,12 +1626,13 @@ static int parse_redundancy(BDRVSheepdogState *s, const char *opt)
     return 0;
 }
 
-static int sd_create(const char *filename, QEMUOptionParameter *options,
+static int sd_create(const char *filename, QemuOpts *opts,
                      Error **errp)
 {
     int ret = 0;
     uint32_t vid = 0;
     char *backing_file = NULL;
+    char *buf = NULL;
     BDRVSheepdogState *s;
     char tag[SD_MAX_VDI_TAG_LEN];
     uint32_t snapid;
@@ -1650,31 +1651,26 @@ 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_del(opts, BLOCK_OPT_SIZE, 0);
+    backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+    buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
+    if (!buf || !strcmp(buf, "off")) {
+        prealloc = false;
+    } else if (!strcmp(buf, "full")) {
+        prealloc = true;
+    } else {
+        error_report("Invalid preallocation mode: '%s'", buf);
+        ret = -EINVAL;
+        goto out;
+    }
+
+    g_free(buf);
+    buf = qemu_opt_get_del(opts, BLOCK_OPT_REDUNDANCY);
+    if (buf) {
+        ret = parse_redundancy(s, buf);
+        if (ret < 0) {
+            goto out;
         }
-        options++;
     }
 
     if (s->inode.vdi_size > SD_MAX_VDI_SIZE) {
@@ -1724,6 +1720,8 @@ static int sd_create(const char *filename, QEMUOptionParameter *options,
 
     ret = sd_prealloc(filename);
 out:
+    g_free(backing_file);
+    g_free(buf);
     g_free(s);
     return ret;
 }
@@ -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"
-    },
-    { NULL }
+static QemuOptsList sd_create_opts = {
+    .name = "sheepdog-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(sd_create_opts.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"
+        },
+        { /* end of list */ }
+    }
 };
 
 static BlockDriver bdrv_sheepdog = {
@@ -2521,7 +2523,7 @@ static BlockDriver bdrv_sheepdog = {
     .bdrv_needs_filename = true,
     .bdrv_file_open = sd_open,
     .bdrv_close     = sd_close,
-    .bdrv_create    = sd_create,
+    .bdrv_create2   = sd_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_getlength = sd_getlength,
     .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
@@ -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_opts    = &sd_create_opts,
 };
 
 static BlockDriver bdrv_sheepdog_tcp = {
@@ -2551,7 +2553,7 @@ static BlockDriver bdrv_sheepdog_tcp = {
     .bdrv_needs_filename = true,
     .bdrv_file_open = sd_open,
     .bdrv_close     = sd_close,
-    .bdrv_create    = sd_create,
+    .bdrv_create2   = sd_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_getlength = sd_getlength,
     .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
@@ -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_opts    = &sd_create_opts,
 };
 
 static BlockDriver bdrv_sheepdog_unix = {
@@ -2581,7 +2583,7 @@ static BlockDriver bdrv_sheepdog_unix = {
     .bdrv_needs_filename = true,
     .bdrv_file_open = sd_open,
     .bdrv_close     = sd_close,
-    .bdrv_create    = sd_create,
+    .bdrv_create2   = sd_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_getlength = sd_getlength,
     .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
@@ -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_opts    = &sd_create_opts,
 };
 
 static void bdrv_sheepdog_init(void)
Signature · 1 line
1.7.12.4
#69 lore raw

PATCH v22 19/25 ssh.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/ssh.c | 32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)
block/ssh.c +15 -17
index aa63c9d..3a5eead 100644
@@ -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"
-    },
-    { 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,
-                      Error **errp)
+static int ssh_create(const char *filename, QemuOpts *opts, Error **errp)
 {
     int r, ret;
     Error *local_err = NULL;
@@ -665,12 +668,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();
@@ -1044,14 +1042,14 @@ static BlockDriver bdrv_ssh = {
     .instance_size                = sizeof(BDRVSSHState),
     .bdrv_parse_filename          = ssh_parse_filename,
     .bdrv_file_open               = ssh_file_open,
-    .bdrv_create                  = ssh_create,
+    .bdrv_create2                 = ssh_create,
     .bdrv_close                   = ssh_close,
     .bdrv_has_zero_init           = ssh_has_zero_init,
     .bdrv_co_readv                = ssh_co_readv,
     .bdrv_co_writev               = ssh_co_writev,
     .bdrv_getlength               = ssh_getlength,
     .bdrv_co_flush_to_disk        = ssh_co_flush,
-    .create_options               = ssh_create_options,
+    .create_opts                  = &ssh_create_opts,
 };
 
 static void bdrv_ssh_init(void)
Signature · 1 line
1.7.12.4
#71 lore raw

PATCH v22 20/25 vdi.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/vdi.c | 72 +++++++++++++++++++++++++++++--------------------------------
 1 file changed, 34 insertions(+), 38 deletions(-)
block/vdi.c +34 -38
index ae49cd8..0799467 100644
@@ -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 *opts, Error **errp)
 {
     int fd;
     int result = 0;
@@ -669,25 +668,17 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options,
     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_del(opts, 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;
-            }
+    block_size = qemu_opt_get_size_del(opts,
+                                       BLOCK_OPT_CLUSTER_SIZE,
+                                       DEFAULT_CLUSTER_SIZE);
 #endif
 #if defined(CONFIG_VDI_STATIC_IMAGE)
-        } else if (!strcmp(options->name, BLOCK_OPT_STATIC)) {
-            if (options->value.n) {
-                image_type = VDI_TYPE_STATIC;
-            }
-#endif
-        }
-        options++;
+    if (qemu_opt_get_bool_del(opts, BLOCK_OPT_STATIC, false)) {
+        image_type = VDI_TYPE_STATIC;
     }
+#endif
 
     fd = qemu_open(filename,
                    O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE,
@@ -767,29 +758,34 @@ 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_opts = {
+    .name = "vdi-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(vdi_create_opts.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_value_str = stringify(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",
+            .def_value_str = "off"
+        },
 #endif
-    /* TODO: An additional option to set UUID values might be useful. */
-    { NULL }
+        /* TODO: An additional option to set UUID values might be useful. */
+        { /* end of list */ }
+    }
 };
 
 static BlockDriver bdrv_vdi = {
@@ -799,7 +795,7 @@ static BlockDriver bdrv_vdi = {
     .bdrv_open = vdi_open,
     .bdrv_close = vdi_close,
     .bdrv_reopen_prepare = vdi_reopen_prepare,
-    .bdrv_create = vdi_create,
+    .bdrv_create2 = vdi_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_co_get_block_status = vdi_co_get_block_status,
     .bdrv_make_empty = vdi_make_empty,
@@ -811,7 +807,7 @@ static BlockDriver bdrv_vdi = {
 
     .bdrv_get_info = vdi_get_info,
 
-    .create_options = vdi_create_options,
+    .create_opts = &vdi_create_opts,
     .bdrv_check = vdi_check,
 };
 
Signature · 1 line
1.7.12.4
#72 lore raw

Re: [Qemu-devel] [PATCH v22 20/25] vdi.c: replace QEMUOptionParameter with QemuOpts

Quoted 7 lines · Chunyan Liu
block/vdi.c +0 -3
@@ -669,25 +668,17 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options,
     logout("\n");
 
     /* Read out options. */
-    while (options && options->name) {
-        if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-            bytes = options->value.n;

block/vdi.c static int vdi_create(const char *filename, QEMUOptionParameter *options, · line 675

Quoted 10 lines
block/vdi.c +4 -5
+    bytes = qemu_opt_get_size_del(opts, 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;
-            }
+    block_size = qemu_opt_get_size_del(opts,
+                                       BLOCK_OPT_CLUSTER_SIZE,
+                                       DEFAULT_CLUSTER_SIZE);

Please keep the TODO.

#73 lore raw

PATCH v22 21/25 vmdk.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/vmdk.c | 123 ++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 63 insertions(+), 60 deletions(-)
block/vmdk.c +63 -60
index d87c8f6..f9b68a0 100644
@@ -1681,17 +1681,16 @@ 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 *opts, Error **errp)
 {
     int idx = 0;
     BlockDriverState *new_bs = NULL;
     Error *local_err;
     char *desc = NULL;
     int64_t total_size = 0, filesize;
-    const char *adapter_type = NULL;
-    const char *backing_file = NULL;
-    const char *fmt = NULL;
+    char *adapter_type = NULL;
+    char *backing_file = NULL;
+    char *fmt = NULL;
     int flags = 0;
     int ret = 0;
     bool flat, split, compress;
@@ -1731,24 +1730,19 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
         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_del(opts, BLOCK_OPT_SIZE, 0);
+    adapter_type = qemu_opt_get_del(opts, BLOCK_OPT_ADAPTER_TYPE);
+    backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+    if (qemu_opt_get_bool_del(opts, BLOCK_OPT_COMPAT6, false)) {
+        flags |= BLOCK_FLAG_COMPAT6;
+    }
+    fmt = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT);
+    if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ZEROED_GRAIN, false)) {
+        zeroed_grain = true;
     }
+
     if (!adapter_type) {
-        adapter_type = "ide";
+        adapter_type = g_strdup("ide");
     } else if (strcmp(adapter_type, "ide") &&
                strcmp(adapter_type, "buslogic") &&
                strcmp(adapter_type, "lsilogic") &&
@@ -1764,7 +1758,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
     }
     if (!fmt) {
         /* Default format to monolithicSparse */
-        fmt = "monolithicSparse";
+        fmt = g_strdup("monolithicSparse");
     } else if (strcmp(fmt, "monolithicFlat") &&
                strcmp(fmt, "monolithicSparse") &&
                strcmp(fmt, "twoGbMaxExtentSparse") &&
@@ -1865,7 +1859,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
     if (!split && !flat) {
         desc_offset = 0x200;
     } else {
-        ret = bdrv_create_file(filename, options, NULL, &local_err);
+        ret = bdrv_create_file(filename, NULL, opts, &local_err);
         if (ret < 0) {
             error_setg_errno(errp, -ret, "Could not create image file");
             goto exit;
@@ -1895,6 +1889,9 @@ exit:
     if (new_bs) {
         bdrv_unref(new_bs);
     }
+    g_free(adapter_type);
+    g_free(backing_file);
+    g_free(fmt);
     g_free(desc);
     g_string_free(ext_desc_lines, true);
     return ret;
@@ -2062,41 +2059,47 @@ 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 =
-            "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 }
+static QemuOptsList vmdk_create_opts = {
+    .name = "vmdk-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(vmdk_create_opts.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",
+            .def_value_str = "off"
+        },
+        {
+            .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 = QEMU_OPT_BOOL,
+            .help = "Enable efficient zero writes "
+                    "using the zeroed-grain GTE feature"
+        },
+        { /* end of list */ }
+    }
 };
 
 static BlockDriver bdrv_vmdk = {
@@ -2110,7 +2113,7 @@ static BlockDriver bdrv_vmdk = {
     .bdrv_write                   = vmdk_co_write,
     .bdrv_co_write_zeroes         = vmdk_co_write_zeroes,
     .bdrv_close                   = vmdk_close,
-    .bdrv_create                  = vmdk_create,
+    .bdrv_create2                 = vmdk_create,
     .bdrv_co_flush_to_disk        = vmdk_co_flush,
     .bdrv_co_get_block_status     = vmdk_co_get_block_status,
     .bdrv_get_allocated_file_size = vmdk_get_allocated_file_size,
@@ -2118,7 +2121,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_opts                  = &vmdk_create_opts,
 };
 
 static void bdrv_vmdk_init(void)
Signature · 1 line
1.7.12.4
#75 lore raw

PATCH v22 22/25 vpc.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/vpc.c | 62 +++++++++++++++++++++++++++++++++----------------------------
 1 file changed, 34 insertions(+), 28 deletions(-)
block/vpc.c +34 -28
index 82bf248..ac85514 100644
@@ -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 *opts, Error **errp)
 {
     uint8_t buf[1024];
     VHDFooter *footer = (VHDFooter *) buf;
-    QEMUOptionParameter *disk_type_param;
+    char *disk_type_param;
     int fd, i;
     uint16_t cyls = 0;
     uint8_t heads = 0;
@@ -730,16 +729,16 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options,
     int ret = -EIO;
 
     /* Read out options */
-    total_size = get_option_parameter(options, BLOCK_OPT_SIZE)->value.n;
-
-    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")) {
+    total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+    disk_type_param = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT);
+    if (disk_type_param) {
+        if (!strcmp(disk_type_param, "dynamic")) {
             disk_type = VHD_DYNAMIC;
-        } else if (!strcmp(disk_type_param->value.s, "fixed")) {
+        } else if (!strcmp(disk_type_param, "fixed")) {
             disk_type = VHD_FIXED;
         } else {
-            return -EINVAL;
+            ret = -EINVAL;
+            goto out;
         }
     } else {
         disk_type = VHD_DYNAMIC;
@@ -748,7 +747,8 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options,
     /* Create the file */
     fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
     if (fd < 0) {
-        return -EIO;
+        ret = -EIO;
+        goto out;
     }
 
     /*
@@ -813,8 +813,10 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options,
         ret = create_fixed_disk(fd, buf, total_size);
     }
 
- fail:
+fail:
     qemu_close(fd);
+out:
+    g_free(disk_type_param);
     return ret;
 }
 
@@ -842,20 +844,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 =
-            "Type of virtual hard disk format. Supported formats are "
-            "{dynamic (default) | fixed} "
-    },
-    { NULL }
+static QemuOptsList vpc_create_opts = {
+    .name = "vpc-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(vpc_create_opts.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} "
+        },
+        { /* end of list */ }
+    }
 };
 
 static BlockDriver bdrv_vpc = {
@@ -866,14 +872,14 @@ static BlockDriver bdrv_vpc = {
     .bdrv_open              = vpc_open,
     .bdrv_close             = vpc_close,
     .bdrv_reopen_prepare    = vpc_reopen_prepare,
-    .bdrv_create            = vpc_create,
+    .bdrv_create2           = vpc_create,
 
     .bdrv_read              = vpc_co_read,
     .bdrv_write             = vpc_co_write,
 
     .bdrv_get_info          = vpc_get_info,
 
-    .create_options         = vpc_create_options,
+    .create_opts            = &vpc_create_opts,
     .bdrv_has_zero_init     = vpc_has_zero_init,
 };
 
Signature · 1 line
1.7.12.4
#77 lore raw

PATCH v22 23/25 vhdx.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/vhdx.c | 99 +++++++++++++++++++++++++++++-------------------------------
 block/vhdx.h |  1 +
 2 files changed, 48 insertions(+), 52 deletions(-)
block/vhdx.c +47 -52
index d8afb42..d90fe55 100644
@@ -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 *opts, Error **errp)
 {
     int ret = 0;
     uint64_t image_size = (uint64_t) 2 * GiB;
@@ -1722,24 +1721,15 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options,
     gunichar2 *creator = NULL;
     glong creator_items;
     BlockDriverState *bs;
-    const char *type = NULL;
+    char *type = NULL;
     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_del(opts, BLOCK_OPT_SIZE, 0);
+    log_size = qemu_opt_get_size_del(opts, VHDX_BLOCK_OPT_LOG_SIZE, 0);
+    block_size = qemu_opt_get_size_del(opts, VHDX_BLOCK_OPT_BLOCK_SIZE, 0);
+    type = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT);
+    use_zero_blocks = qemu_opt_get_bool_del(opts, VHDX_BLOCK_OPT_ZERO, false);
 
     if (image_size > VHDX_MAX_IMAGE_SIZE) {
         error_setg_errno(errp, EINVAL, "Image size too large; max of 64TB");
@@ -1748,7 +1738,7 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options,
     }
 
     if (type == NULL) {
-        type = "dynamic";
+        type = g_strdup("dynamic");
     }
 
     if (!strcmp(type, "dynamic")) {
@@ -1788,7 +1778,7 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options,
     block_size = block_size > VHDX_BLOCK_SIZE_MAX ? VHDX_BLOCK_SIZE_MAX :
                                                     block_size;
 
-    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);
         goto exit;
@@ -1848,6 +1838,7 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options,
 delete_and_exit:
     bdrv_unref(bs);
 exit:
+    g_free(type);
     g_free(creator);
     return ret;
 }
@@ -1870,37 +1861,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."
-    },
-    { NULL }
+static QemuOptsList vhdx_create_opts = {
+    .name = "vhdx-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(vhdx_create_opts.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_value_str = stringify(DEFAULT_LOG_SIZE),
+           .help = "Log size; min 1MB."
+       },
+       {
+           .name = VHDX_BLOCK_OPT_BLOCK_SIZE,
+           .type = QEMU_OPT_SIZE,
+           .def_value_str = stringify(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 }
+    }
 };
 
 static BlockDriver bdrv_vhdx = {
@@ -1912,11 +1907,11 @@ static BlockDriver bdrv_vhdx = {
     .bdrv_reopen_prepare    = vhdx_reopen_prepare,
     .bdrv_co_readv          = vhdx_co_readv,
     .bdrv_co_writev         = vhdx_co_writev,
-    .bdrv_create            = vhdx_create,
+    .bdrv_create2           = vhdx_create,
     .bdrv_get_info          = vhdx_get_info,
     .bdrv_check             = vhdx_check,
 
-    .create_options         = vhdx_create_options,
+    .create_opts            = &vhdx_create_opts,
 };
 
 static void bdrv_vhdx_init(void)
block/vhdx.h +1 -0
index 2acd7c2..a5a36fc 100644
@@ -23,6 +23,7 @@
 #define GiB            (MiB * 1024)
 #define TiB ((uint64_t) GiB * 1024)
 
+#define DEFAULT_LOG_SIZE 1048576 /* 1MiB */
 /* Structures and fields present in the VHDX file */
 
 /* The header section has the following blocks,
Signature · 1 line
1.7.12.4
#79 lore raw

PATCH v22 24/25 vvfat.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu
---
 block/vvfat.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
block/vvfat.c +5 -5
index ee32b3c..03be65d 100644
@@ -2907,7 +2907,7 @@ static BlockDriver vvfat_write_target = {
 static int enable_write_target(BDRVVVFATState *s)
 {
     BlockDriver *bdrv_qcow;
-    QEMUOptionParameter *options;
+    QemuOpts *opts;
     Error *local_err = NULL;
     int ret;
     int size = sector2cluster(s, s->sector_count);
@@ -2922,11 +2922,11 @@ 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(bdrv_qcow->create_opts, NULL, 0, &error_abort);
+    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, options, NULL, &local_err);
+    ret = bdrv_create(bdrv_qcow, s->qcow_filename, NULL, opts, &local_err);
     if (ret < 0) {
         qerror_report_err(local_err);
         error_free(local_err);
Signature · 1 line
1.7.12.4
#80 lore raw

Re: [Qemu-devel] [PATCH v22 24/25] vvfat.c: replace QEMUOptionParameter with QemuOpts

Quoted 9 lines · Chunyan Liu
---
 block/vvfat.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
     bdrv_qcow = bdrv_find_format("qcow");

- options = parse_option_parameters("", bdrv_qcow->create_options, NULL);

Problem. This code is broken from the time that patch 11/25 is applied until now. That's because commit 11 changed bdrv_qcow from having create_options over to having create_opts. Do any of the other drivers do cross-driver option sharing? It would be nice to fix that to quit happening, preferably earlier in the series than where you start doing per-driver conversions.

Quoted 12 lines
block/vvfat.c +4 -3
-    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(bdrv_qcow->create_opts, NULL, 0, &error_abort);
+    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, options, NULL, &local_err);
+    ret = bdrv_create(bdrv_qcow, s->qcow_filename, NULL, opts, &local_err);
     if (ret < 0) {
         qerror_report_err(local_err);
         error_free(local_err);
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#81 lore raw

Re: [Qemu-devel] [PATCH v22 24/25] vvfat.c: replace QEMUOptionParameter with QemuOpts

In reply to Chunyan Liu

block/vvfat.c static int enable_write_target(BDRVVVFATState *s) · line 2932

Quoted 5 lines · Chunyan Liu
block/vvfat.c +1 -1
-    ret = bdrv_create(bdrv_qcow, s->qcow_filename, options, NULL, &local_err);
+    ret = bdrv_create(bdrv_qcow, s->qcow_filename, NULL, opts, &local_err);
     if (ret < 0) {
         qerror_report_err(local_err);
         error_free(local_err);

Who frees opts?

#82 lore raw

PATCH v22 25/25 cleanup QEMUOptionParameter

In reply to Chunyan Liu

Now all places using QEMUOptionParameter could use QemuOpts too, remove QEMUOptionParameter related code.

---
 block.c                   |  69 ++------
 block/cow.c               |   4 +-
 block/gluster.c           |   8 +-
 block/qcow.c              |   4 +-
 block/qcow2.c             |   6 +-
 block/qed.c               |   4 +-
 block/raw-posix.c         |  10 +-
 block/raw-win32.c         |   2 +-
 block/raw_bsd.c           |   4 +-
 block/rbd.c               |   2 +-
 block/sheepdog.c          |   6 +-
 block/ssh.c               |   2 +-
 block/vdi.c               |   2 +-
 block/vhdx.c              |   4 +-
 block/vmdk.c              |   6 +-
 block/vpc.c               |   2 +-
 block/vvfat.c             |   2 +-
 include/block/block.h     |   8 +-
 include/block/block_int.h |  13 +-
 include/qemu/option.h     |  46 ------
 qemu-img.c                |  63 +-------
 util/qemu-option.c        | 401 ----------------------------------------------
 22 files changed, 62 insertions(+), 606 deletions(-)
block.c +15 -54
index d9b1da3..b6b86c5 100644
@@ -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_create(cco->filename, cco->opts, &local_err);
     if (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_create) {
         error_setg(errp, "Driver '%s' does not support image creation", drv->format_name);
         ret = -ENOTSUP;
         goto out;
@@ -478,8 +472,7 @@ out:
     return ret;
 }
 
-int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
-                     QemuOpts *opts, Error **errp)
+int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp)
 {
     BlockDriver *drv;
     Error *local_err = NULL;
@@ -491,7 +484,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 (local_err) {
         error_propagate(errp, local_err);
     }
@@ -1254,7 +1247,6 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
         BlockDriverState *bs1;
         int64_t total_size;
         BlockDriver *bdrv_qcow2;
-        QEMUOptionParameter *create_options = NULL;
         QemuOpts *opts = NULL;
         QDict *snapshot_options;
 
@@ -1281,20 +1273,11 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
         }
 
         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 "
@@ -5243,7 +5226,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;
@@ -5266,16 +5248,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);
@@ -5368,12 +5342,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
@@ -5390,9 +5359,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 (local_err) {
@@ -5412,17 +5378,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,
-                       QemuOpts *opts)
+int bdrv_amend_options(BlockDriverState *bs, QemuOpts *opts)
 {
-    if (!bs->drv->bdrv_amend_options && !bs->drv->bdrv_amend_options2) {
+    if (!bs->drv->bdrv_amend_options) {
         return -ENOTSUP;
     }
-    if (bs->drv->bdrv_amend_options2) {
-        return bs->drv->bdrv_amend_options2(bs, opts);
-    } else {
-        return bs->drv->bdrv_amend_options(bs, options);
-    }
+    return bs->drv->bdrv_amend_options(bs, opts);
 }
 
 /* Used to recurse on single child block filters.
block/cow.c +2 -2
index 4085201..55b7631 100644
@@ -338,7 +338,7 @@ static int cow_create(const char *filename, QemuOpts *opts, Error **errp)
     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) {
         error_propagate(errp, local_err);
         goto exit;
@@ -412,7 +412,7 @@ static BlockDriver bdrv_cow = {
     .bdrv_probe     = cow_probe,
     .bdrv_open      = cow_open,
     .bdrv_close     = cow_close,
-    .bdrv_create2   = cow_create,
+    .bdrv_create    = cow_create,
     .bdrv_has_zero_init     = bdrv_has_zero_init_1,
 
     .bdrv_read              = cow_co_read,
block/gluster.c +4 -4
index bd72d8d..b3cfa01 100644
@@ -715,7 +715,7 @@ static BlockDriver bdrv_gluster = {
     .bdrv_reopen_commit           = qemu_gluster_reopen_commit,
     .bdrv_reopen_abort            = qemu_gluster_reopen_abort,
     .bdrv_close                   = qemu_gluster_close,
-    .bdrv_create2                 = qemu_gluster_create,
+    .bdrv_create                  = qemu_gluster_create,
     .bdrv_getlength               = qemu_gluster_getlength,
     .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
     .bdrv_truncate                = qemu_gluster_truncate,
@@ -742,7 +742,7 @@ static BlockDriver bdrv_gluster_tcp = {
     .bdrv_reopen_commit           = qemu_gluster_reopen_commit,
     .bdrv_reopen_abort            = qemu_gluster_reopen_abort,
     .bdrv_close                   = qemu_gluster_close,
-    .bdrv_create2                 = qemu_gluster_create,
+    .bdrv_create                  = qemu_gluster_create,
     .bdrv_getlength               = qemu_gluster_getlength,
     .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
     .bdrv_truncate                = qemu_gluster_truncate,
@@ -769,7 +769,7 @@ static BlockDriver bdrv_gluster_unix = {
     .bdrv_reopen_commit           = qemu_gluster_reopen_commit,
     .bdrv_reopen_abort            = qemu_gluster_reopen_abort,
     .bdrv_close                   = qemu_gluster_close,
-    .bdrv_create2                 = qemu_gluster_create,
+    .bdrv_create                  = qemu_gluster_create,
     .bdrv_getlength               = qemu_gluster_getlength,
     .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
     .bdrv_truncate                = qemu_gluster_truncate,
@@ -796,7 +796,7 @@ static BlockDriver bdrv_gluster_rdma = {
     .bdrv_reopen_commit           = qemu_gluster_reopen_commit,
     .bdrv_reopen_abort            = qemu_gluster_reopen_abort,
     .bdrv_close                   = qemu_gluster_close,
-    .bdrv_create2                 = qemu_gluster_create,
+    .bdrv_create                  = qemu_gluster_create,
     .bdrv_getlength               = qemu_gluster_getlength,
     .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
     .bdrv_truncate                = qemu_gluster_truncate,
block/qcow.c +2 -2
index 374e6df..18ce338 100644
@@ -681,7 +681,7 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp)
         flags |= BLOCK_FLAG_ENCRYPT;
     }
 
-    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 cleanup;
@@ -908,7 +908,7 @@ static BlockDriver bdrv_qcow = {
     .bdrv_open		= qcow_open,
     .bdrv_close		= qcow_close,
     .bdrv_reopen_prepare    = qcow_reopen_prepare,
-    .bdrv_create2           = qcow_create,
+    .bdrv_create            = qcow_create,
     .bdrv_has_zero_init     = bdrv_has_zero_init_1,
 
     .bdrv_co_readv          = qcow_co_readv,
block/qcow2.c +3 -3
index e0f00bf..98d2e77 100644
@@ -1487,7 +1487,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;
@@ -2245,7 +2245,7 @@ static BlockDriver bdrv_qcow2 = {
     .bdrv_open          = qcow2_open,
     .bdrv_close         = qcow2_close,
     .bdrv_reopen_prepare  = qcow2_reopen_prepare,
-    .bdrv_create2         = qcow2_create,
+    .bdrv_create          = 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,
@@ -2277,7 +2277,7 @@ static BlockDriver bdrv_qcow2 = {
 
     .create_opts         = &qcow2_create_opts,
     .bdrv_check          = qcow2_check,
-    .bdrv_amend_options2 = qcow2_amend_options,
+    .bdrv_amend_options  = qcow2_amend_options,
 };
 
 static void bdrv_qcow2_init(void)
block/qed.c +2 -2
index a22c2d9..12d86bb 100644
@@ -566,7 +566,7 @@ static int qed_create(const char *filename, uint32_t cluster_size,
     int ret = 0;
     BlockDriverState *bs;
 
-    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);
         return ret;
@@ -1617,7 +1617,7 @@ static BlockDriver bdrv_qed = {
     .bdrv_open                = bdrv_qed_open,
     .bdrv_close               = bdrv_qed_close,
     .bdrv_reopen_prepare      = bdrv_qed_reopen_prepare,
-    .bdrv_create2             = bdrv_qed_create,
+    .bdrv_create              = bdrv_qed_create,
     .bdrv_has_zero_init       = bdrv_has_zero_init_1,
     .bdrv_co_get_block_status = bdrv_qed_co_get_block_status,
     .bdrv_aio_readv           = bdrv_qed_aio_readv,
block/raw-posix.c +5 -5
index 7fc4a3a..7dac3e1 100644
@@ -1430,7 +1430,7 @@ static BlockDriver bdrv_file = {
     .bdrv_reopen_commit = raw_reopen_commit,
     .bdrv_reopen_abort = raw_reopen_abort,
     .bdrv_close = raw_close,
-    .bdrv_create2 = raw_create,
+    .bdrv_create = raw_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_co_get_block_status = raw_co_get_block_status,
     .bdrv_co_write_zeroes = raw_co_write_zeroes,
@@ -1805,7 +1805,7 @@ static BlockDriver bdrv_host_device = {
     .bdrv_reopen_prepare = raw_reopen_prepare,
     .bdrv_reopen_commit  = raw_reopen_commit,
     .bdrv_reopen_abort   = raw_reopen_abort,
-    .bdrv_create2        = hdev_create,
+    .bdrv_create         = hdev_create,
     .create_opts         = &raw_create_opts,
     .bdrv_co_write_zeroes = hdev_co_write_zeroes,
 
@@ -1939,7 +1939,7 @@ static BlockDriver bdrv_host_floppy = {
     .bdrv_reopen_prepare = raw_reopen_prepare,
     .bdrv_reopen_commit  = raw_reopen_commit,
     .bdrv_reopen_abort   = raw_reopen_abort,
-    .bdrv_create2        = hdev_create,
+    .bdrv_create         = hdev_create,
     .create_opts         = &raw_create_opts,
 
     .bdrv_aio_readv     = raw_aio_readv,
@@ -2050,7 +2050,7 @@ static BlockDriver bdrv_host_cdrom = {
     .bdrv_reopen_prepare = raw_reopen_prepare,
     .bdrv_reopen_commit  = raw_reopen_commit,
     .bdrv_reopen_abort   = raw_reopen_abort,
-    .bdrv_create2        = hdev_create,
+    .bdrv_create         = hdev_create,
     .create_opts         = &raw_create_opts,
 
     .bdrv_aio_readv     = raw_aio_readv,
@@ -2180,7 +2180,7 @@ static BlockDriver bdrv_host_cdrom = {
     .bdrv_reopen_prepare = raw_reopen_prepare,
     .bdrv_reopen_commit  = raw_reopen_commit,
     .bdrv_reopen_abort   = raw_reopen_abort,
-    .bdrv_create2        = hdev_create,
+    .bdrv_create        = hdev_create,
     .create_opts        = &raw_create_opts,
 
     .bdrv_aio_readv     = raw_aio_readv,
block/raw-win32.c +1 -1
index 29f8e54..8cc8e61 100644
@@ -520,7 +520,7 @@ static BlockDriver bdrv_file = {
     .bdrv_parse_filename = raw_parse_filename,
     .bdrv_file_open     = raw_open,
     .bdrv_close         = raw_close,
-    .bdrv_create2       = raw_create,
+    .bdrv_create        = raw_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
 
     .bdrv_aio_readv     = raw_aio_readv,
block/raw_bsd.c +2 -2
index ee797fd..492f58d 100644
@@ -148,7 +148,7 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp)
     Error *local_err = NULL;
     int ret;
 
-    ret = bdrv_create_file(filename, NULL, opts, &local_err);
+    ret = bdrv_create_file(filename, opts, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
     }
@@ -180,7 +180,7 @@ static BlockDriver bdrv_raw = {
     .bdrv_reopen_prepare  = &raw_reopen_prepare,
     .bdrv_open            = &raw_open,
     .bdrv_close           = &raw_close,
-    .bdrv_create2         = &raw_create,
+    .bdrv_create          = &raw_create,
     .bdrv_co_readv        = &raw_co_readv,
     .bdrv_co_writev       = &raw_co_writev,
     .bdrv_co_write_zeroes = &raw_co_write_zeroes,
block/rbd.c +1 -1
index f878877..f189900 100644
@@ -917,7 +917,7 @@ static BlockDriver bdrv_rbd = {
     .bdrv_needs_filename = true,
     .bdrv_file_open     = qemu_rbd_open,
     .bdrv_close         = qemu_rbd_close,
-    .bdrv_create2       = qemu_rbd_create,
+    .bdrv_create        = qemu_rbd_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_get_info      = qemu_rbd_getinfo,
     .create_opts        = &qemu_rbd_create_opts,
block/sheepdog.c +3 -3
index 027a34e..c688b0f 100644
@@ -2523,7 +2523,7 @@ static BlockDriver bdrv_sheepdog = {
     .bdrv_needs_filename = true,
     .bdrv_file_open = sd_open,
     .bdrv_close     = sd_close,
-    .bdrv_create2   = sd_create,
+    .bdrv_create    = sd_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_getlength = sd_getlength,
     .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
@@ -2553,7 +2553,7 @@ static BlockDriver bdrv_sheepdog_tcp = {
     .bdrv_needs_filename = true,
     .bdrv_file_open = sd_open,
     .bdrv_close     = sd_close,
-    .bdrv_create2   = sd_create,
+    .bdrv_create    = sd_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_getlength = sd_getlength,
     .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
@@ -2583,7 +2583,7 @@ static BlockDriver bdrv_sheepdog_unix = {
     .bdrv_needs_filename = true,
     .bdrv_file_open = sd_open,
     .bdrv_close     = sd_close,
-    .bdrv_create2   = sd_create,
+    .bdrv_create    = sd_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_getlength = sd_getlength,
     .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
block/ssh.c +1 -1
index 3a5eead..a4c7f06 100644
@@ -1042,7 +1042,7 @@ static BlockDriver bdrv_ssh = {
     .instance_size                = sizeof(BDRVSSHState),
     .bdrv_parse_filename          = ssh_parse_filename,
     .bdrv_file_open               = ssh_file_open,
-    .bdrv_create2                 = ssh_create,
+    .bdrv_create                  = ssh_create,
     .bdrv_close                   = ssh_close,
     .bdrv_has_zero_init           = ssh_has_zero_init,
     .bdrv_co_readv                = ssh_co_readv,
block/vdi.c +1 -1
index 0799467..3680e1a 100644
@@ -795,7 +795,7 @@ static BlockDriver bdrv_vdi = {
     .bdrv_open = vdi_open,
     .bdrv_close = vdi_close,
     .bdrv_reopen_prepare = vdi_reopen_prepare,
-    .bdrv_create2 = vdi_create,
+    .bdrv_create = vdi_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_co_get_block_status = vdi_co_get_block_status,
     .bdrv_make_empty = vdi_make_empty,
block/vhdx.c +2 -2
index d90fe55..26ac780 100644
@@ -1778,7 +1778,7 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp)
     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;
@@ -1907,7 +1907,7 @@ static BlockDriver bdrv_vhdx = {
     .bdrv_reopen_prepare    = vhdx_reopen_prepare,
     .bdrv_co_readv          = vhdx_co_readv,
     .bdrv_co_writev         = vhdx_co_writev,
-    .bdrv_create2           = vhdx_create,
+    .bdrv_create            = vhdx_create,
     .bdrv_get_info          = vhdx_get_info,
     .bdrv_check             = vhdx_check,
 
block/vmdk.c +3 -3
index f9b68a0..97e0432 100644
@@ -1525,7 +1525,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;
@@ -1859,7 +1859,7 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)
     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;
@@ -2113,7 +2113,7 @@ static BlockDriver bdrv_vmdk = {
     .bdrv_write                   = vmdk_co_write,
     .bdrv_co_write_zeroes         = vmdk_co_write_zeroes,
     .bdrv_close                   = vmdk_close,
-    .bdrv_create2                 = vmdk_create,
+    .bdrv_create                  = vmdk_create,
     .bdrv_co_flush_to_disk        = vmdk_co_flush,
     .bdrv_co_get_block_status     = vmdk_co_get_block_status,
     .bdrv_get_allocated_file_size = vmdk_get_allocated_file_size,
block/vpc.c +1 -1
index ac85514..111c3c6 100644
@@ -872,7 +872,7 @@ static BlockDriver bdrv_vpc = {
     .bdrv_open              = vpc_open,
     .bdrv_close             = vpc_close,
     .bdrv_reopen_prepare    = vpc_reopen_prepare,
-    .bdrv_create2           = vpc_create,
+    .bdrv_create            = vpc_create,
 
     .bdrv_read              = vpc_co_read,
     .bdrv_write             = vpc_co_write,
block/vvfat.c +1 -1
index 03be65d..de00f69 100644
@@ -2926,7 +2926,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);
include/block/block.h +3 -5
index c482204..33a984e 100644
@@ -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, QemuOpts *opts, Error **errp);
-int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
-                     QemuOpts *opts, Error **errp);
+                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);
 void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old);
@@ -283,8 +282,7 @@ typedef enum {
 
 int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix);
 
-int bdrv_amend_options(BlockDriverState *bs_new, QEMUOptionParameter *options,
-                       QemuOpts *opts);
+int bdrv_amend_options(BlockDriverState *bs_new, QemuOpts *opts);
 
 /* external snapshots */
 
include/block/block_int.h +2 -11
index e4e832f..12684ef 100644
@@ -116,10 +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);
-    /* FIXME: will remove the duplicate and rename back to bdrv_create later */
-    int (*bdrv_create2)(const char *filename, QemuOpts *opts, Error **errp);
+    int (*bdrv_create)(const char *filename, QemuOpts *opts, Error **errp);
     int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
     int (*bdrv_make_empty)(BlockDriverState *bs);
     /* aio */
@@ -218,7 +215,6 @@ struct BlockDriver {
         BlockDriverCompletionFunc *cb, void *opaque);
 
     /* List of options for creating images, terminated by name == NULL */
-    QEMUOptionParameter *create_options;
     QemuOptsList *create_opts;
 
     /*
@@ -228,12 +224,7 @@ struct BlockDriver {
     int (*bdrv_check)(BlockDriverState* bs, BdrvCheckResult *result,
         BdrvCheckMode fix);
 
-    int (*bdrv_amend_options)(BlockDriverState *bs,
-        QEMUOptionParameter *options);
-    /* FIXME: will remove the duplicate and rename back to
-     * bdrv_amend_options later
-     */
-    int (*bdrv_amend_options2)(BlockDriverState *bs, QemuOpts *opts);
+    int (*bdrv_amend_options)(BlockDriverState *bs, QemuOpts *opts);
 
     void (*bdrv_debug_event)(BlockDriverState *bs, BlkDebugEvent event);
 
include/qemu/option.h +0 -46

65 lines not on this page · raw message

qemu-img.c +8 -55

131 lines not on this page · raw message

util/qemu-option.c +0 -401

428 lines not on this page · raw message

Signature · 1 line
1.7.12.4
Reviewed-by on v22 25/25
#83 lore raw

Re: [Qemu-devel] [PATCH v22 25/25] cleanup QEMUOptionParameter

Quoted 21 lines · Chunyan Liu

Now all places using QEMUOptionParameter could use QemuOpts too, remove QEMUOptionParameter related code.

---
 block.c                   |  69 ++------
 block/cow.c               |   4 +-
 block/gluster.c           |   8 +-
 block/qcow.c              |   4 +-
 block/qcow2.c             |   6 +-
 block/qed.c               |   4 +-
 block/raw-posix.c         |  10 +-
 block/raw-win32.c         |   2 +-
 block/raw_bsd.c           |   4 +-
 block/rbd.c               |   2 +-
 block/sheepdog.c          |   6 +-
 block/ssh.c               |   2 +-
 block/vdi.c               |   2 +-
 block/vhdx.c              |   4 +-
 block/vmdk.c              |   6 +-
Quoted 8 lines
 block/vpc.c               |   2 +-
 block/vvfat.c             |   2 +-
 include/block/block.h     |   8 +-
 include/block/block_int.h |  13 +-
 include/qemu/option.h     |  46 ------
 qemu-img.c                |  63 +-------
 util/qemu-option.c        | 401 ----------------------------------------------
 22 files changed, 62 insertions(+), 606 deletions(-)

Please change the commit message to "qemu-option: remove QEMUOptionParameter". Commit messages should have a prefix that indicates which part of the codebase is affected. And "remove" is more specific than "cleanup".

#84 lore raw

Re: [Qemu-devel] [PATCH v22 25/25] cleanup QEMUOptionParameter

In reply to Chunyan Liu

Hi,

Quoted 21 lines · Chunyan Liu

Now all places using QEMUOptionParameter could use QemuOpts too, remove QEMUOptionParameter related code.

---
 block.c                   |  69 ++------
 block/cow.c               |   4 +-
 block/gluster.c           |   8 +-
 block/qcow.c              |   4 +-
 block/qcow2.c             |   6 +-
 block/qed.c               |   4 +-
 block/raw-posix.c         |  10 +-
 block/raw-win32.c         |   2 +-
 block/raw_bsd.c           |   4 +-
 block/rbd.c               |   2 +-
 block/sheepdog.c          |   6 +-
 block/ssh.c               |   2 +-
 block/vdi.c               |   2 +-
 block/vhdx.c              |   4 +-
 block/vmdk.c              |   6 +-
Quoted 8 lines
 block/vpc.c               |   2 +-
 block/vvfat.c             |   2 +-
 include/block/block.h     |   8 +-
 include/block/block_int.h |  13 +-
 include/qemu/option.h     |  46 ------
 qemu-img.c                |  63 +-------
 util/qemu-option.c        | 401 ----------------------------------------------
 22 files changed, 62 insertions(+), 606 deletions(-)

It seems you've missed block/iscsi.c in the final cleanup.

I got the following:

block/iscsi.c:1385:47: error: unknown type name ‘QEMUOptionParameter’
static int iscsi_create(const char *filename, QEMUOptionParameter *options,

                                               ^

block/iscsi.c:1470:24: error: ‘iscsi_create’ undeclared here (not in a function)
.bdrv_create = iscsi_create,

I did a s/QemuOptionParameter/QemuOption/ and got the following:

block/iscsi.c: In function ‘iscsi_create’:
block/iscsi.c:1398:31: error: ‘opts’ undeclared (first use in this function)

         qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
                               ^

block/iscsi.c:1398:31: note: each undeclared identifier is reported only once for each function it appears in /home/dorileo/work/sources/foss/qemu/rules.mak:33: recipe for target 'block/iscsi.o' failed

iscsi_create() is expecting an argument opts not options, then a s/options/opts/ here fixed the issue.

I ran my QemuOpts testsuite on top of your patches and got a few problems (initially 2 wrong assertions). I'll dig it a little deeper - when I find some time to - and comment in the proper patches.

Regards...

Signature · 1 line
Leandro Dorileo
#85 lore raw

Re: [Qemu-devel] [PATCH v22 25/25] cleanup QEMUOptionParameter

Hi,

Quoted 50 lines · Leandro Dorileo

Hi,

Quoted 21 lines · Chunyan Liu

Now all places using QEMUOptionParameter could use QemuOpts too, remove QEMUOptionParameter related code.

---
 block.c                   |  69 ++------
 block/cow.c               |   4 +-
 block/gluster.c           |   8 +-
 block/qcow.c              |   4 +-
 block/qcow2.c             |   6 +-
 block/qed.c               |   4 +-
 block/raw-posix.c         |  10 +-
 block/raw-win32.c         |   2 +-
 block/raw_bsd.c           |   4 +-
 block/rbd.c               |   2 +-
 block/sheepdog.c          |   6 +-
 block/ssh.c               |   2 +-
 block/vdi.c               |   2 +-
 block/vhdx.c              |   4 +-
 block/vmdk.c              |   6 +-
Quoted 8 lines
 block/vpc.c               |   2 +-
 block/vvfat.c             |   2 +-
 include/block/block.h     |   8 +-
 include/block/block_int.h |  13 +-
 include/qemu/option.h     |  46 ------
 qemu-img.c                |  63 +-------
 util/qemu-option.c        | 401 ----------------------------------------------
 22 files changed, 62 insertions(+), 606 deletions(-)

It seems you've missed block/iscsi.c in the final cleanup.

I got the following:

block/iscsi.c:1385:47: error: unknown type name ‘QEMUOptionParameter’
static int iscsi_create(const char *filename, QEMUOptionParameter *options,

                                               ^

block/iscsi.c:1470:24: error: ‘iscsi_create’ undeclared here (not in a function)
.bdrv_create = iscsi_create,

I did a s/QemuOptionParameter/QemuOption/ and got the following:

block/iscsi.c: In function ‘iscsi_create’:
block/iscsi.c:1398:31: error: ‘opts’ undeclared (first use in this function)

         qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
                               ^
Quoted 8 lines

block/iscsi.c:1398:31: note: each undeclared identifier is reported only once for each function it appears in /home/dorileo/work/sources/foss/qemu/rules.mak:33: recipe for target 'block/iscsi.o' failed

iscsi_create() is expecting an argument opts not options, then a s/options/opts/ here fixed the issue.

I ran my QemuOpts testsuite on top of your patches and got a few problems (initially 2 wrong assertions). I'll dig it a little deeper - when I find some time to - and comment in the proper patches.

It's also broken test-opts-visitor.c

ERROR:tests/test-opts-visitor.c:119:test_value: assertion failed: (magic == 0xDEADBEEF)

Signature · 1 line
Leandro Dorileo
#86 lore raw
In reply to Chunyan Liu

The whole patch series could also be get from here:
https://github.com/chunyanliu/qemu/commits/QemuOpts

-Chunyan

Quoted 1 line
Quoted 1 line
Quoted 1 line

On 3/10/2014 at 03:31 PM, in message

<[email protected]>, Chunyan Liu

Quoted 66 lines · <[email protected]> wrote:

This patch series is to replace QEMUOptionParameter with QemuOpts, so that only
one Qemu Option structure is kept in QEMU code.

---
Changes to v21:
* update verison info in patch 2/25
* others are not changed except for rebase

Chunyan Liu (25):
add def_value_str to QemuOptDesc
qapi: output def_value_str when query command line options improve some functions in qemu-option.c
improve assertion in qemu_opt_get functions
add some QemuOpts functions for replace work
add convert functions between QEMUOptionParameter to QemuOpts change block layer to support both QemuOpts and QEMUOptionParamter cow.c: replace QEMUOptionParameter with QemuOpts gluster.c: replace QEMUOptionParameter with QemuOpts iscsi.c: replace QEMUOptionParameter with QemuOpts qcow.c: replace QEMUOptionParameter with QemuOpts qcow2.c: replace QEMUOptionParameter with QemuOpts qed.c: replace QEMUOptionParameter with QemuOpts raw-posix.c: replace QEMUOptionParameter with QemuOpts raw-win32.c: replace QEMUOptionParameter with QemuOpts raw_bsd.c: replace QEMUOptionParameter with QemuOpts rbd.c: replace QEMUOptionParameter with QemuOpts sheepdog.c: replace QEMUOptionParameter with QemuOpts ssh.c: replace QEMUOptionParameter with QemuOpts
vdi.c: replace QEMUOptionParameter with QemuOpts vmdk.c: replace QEMUOptionParameter with QemuOpts vpc.c: replace QEMUOptionParameter with QemuOpts vhdx.c: replace QEMUOptionParameter with QemuOpts vvfat.c: replace QEMUOptionParameter with QemuOpts cleanup QEMUOptionParameter

 block.c                   |  96 ++++---- 
 block/cow.c               |  52 ++--- 
 block/gluster.c           |  73 +++--- 
 block/iscsi.c             |  29 ++- 
 block/qcow.c              |  72 +++--- 
 block/qcow2.c             | 325 +++++++++++++------------- 
 block/qed.c               | 112 ++++----- 
 block/qed.h               |   3 +- 
 block/raw-posix.c         |  55 ++--- 
 block/raw-win32.c         |  38 +-- 
 block/raw_bsd.c           |  25 +- 
 block/rbd.c               |  61 +++-- 
 block/sheepdog.c          | 102 ++++---- 
 block/ssh.c               |  30 ++- 
 block/vdi.c               |  70 +++--- 
 block/vhdx.c              |  97 ++++---- 
 block/vhdx.h              |   1 + 
 block/vmdk.c              | 121 +++++----- 
 block/vpc.c               |  60 ++--- 
 block/vvfat.c             |  10 +- 
 include/block/block.h     |   7 +- 
 include/block/block_int.h |   9 +- 
 include/qemu/option.h     |  56 +---- 
 include/qemu/option_int.h |   4 +- 
 qapi-schema.json          |   6 +- 
 qemu-img.c                |  89 ++++--- 
 qmp-commands.hx           |   2 + 
 util/qemu-config.c        |   4 + 
 util/qemu-option.c        | 576 ++++++++++++++++++++++------------------------ 
 29 files changed, 1060 insertions(+), 1125 deletions(-) 
#87 lore raw
In reply to Chunyan Liu

The whole patch series could also be get from here:
https://github.com/chunyanliu/qemu/commits/QemuOpts

-Chunyan

Quoted 1 line
Quoted 1 line
Quoted 1 line

On 3/10/2014 at 03:31 PM, in message

<[email protected]>, Chunyan Liu

Quoted 66 lines · <[email protected]> wrote:

This patch series is to replace QEMUOptionParameter with QemuOpts, so that only
one Qemu Option structure is kept in QEMU code.

---
Changes to v21:
* update verison info in patch 2/25
* others are not changed except for rebase

Chunyan Liu (25):
add def_value_str to QemuOptDesc
qapi: output def_value_str when query command line options improve some functions in qemu-option.c
improve assertion in qemu_opt_get functions
add some QemuOpts functions for replace work
add convert functions between QEMUOptionParameter to QemuOpts change block layer to support both QemuOpts and QEMUOptionParamter cow.c: replace QEMUOptionParameter with QemuOpts gluster.c: replace QEMUOptionParameter with QemuOpts iscsi.c: replace QEMUOptionParameter with QemuOpts qcow.c: replace QEMUOptionParameter with QemuOpts qcow2.c: replace QEMUOptionParameter with QemuOpts qed.c: replace QEMUOptionParameter with QemuOpts raw-posix.c: replace QEMUOptionParameter with QemuOpts raw-win32.c: replace QEMUOptionParameter with QemuOpts raw_bsd.c: replace QEMUOptionParameter with QemuOpts rbd.c: replace QEMUOptionParameter with QemuOpts sheepdog.c: replace QEMUOptionParameter with QemuOpts ssh.c: replace QEMUOptionParameter with QemuOpts
vdi.c: replace QEMUOptionParameter with QemuOpts vmdk.c: replace QEMUOptionParameter with QemuOpts vpc.c: replace QEMUOptionParameter with QemuOpts vhdx.c: replace QEMUOptionParameter with QemuOpts vvfat.c: replace QEMUOptionParameter with QemuOpts cleanup QEMUOptionParameter

 block.c                   |  96 ++++---- 
 block/cow.c               |  52 ++--- 
 block/gluster.c           |  73 +++--- 
 block/iscsi.c             |  29 ++- 
 block/qcow.c              |  72 +++--- 
 block/qcow2.c             | 325 +++++++++++++------------- 
 block/qed.c               | 112 ++++----- 
 block/qed.h               |   3 +- 
 block/raw-posix.c         |  55 ++--- 
 block/raw-win32.c         |  38 +-- 
 block/raw_bsd.c           |  25 +- 
 block/rbd.c               |  61 +++-- 
 block/sheepdog.c          | 102 ++++---- 
 block/ssh.c               |  30 ++- 
 block/vdi.c               |  70 +++--- 
 block/vhdx.c              |  97 ++++---- 
 block/vhdx.h              |   1 + 
 block/vmdk.c              | 121 +++++----- 
 block/vpc.c               |  60 ++--- 
 block/vvfat.c             |  10 +- 
 include/block/block.h     |   7 +- 
 include/block/block_int.h |   9 +- 
 include/qemu/option.h     |  56 +---- 
 include/qemu/option_int.h |   4 +- 
 qapi-schema.json          |   6 +- 
 qemu-img.c                |  89 ++++--- 
 qmp-commands.hx           |   2 + 
 util/qemu-config.c        |   4 + 
 util/qemu-option.c        | 576 ++++++++++++++++++++++------------------------ 
 29 files changed, 1060 insertions(+), 1125 deletions(-) 
#88 lore raw
In reply to Chunyan Liu

The whole patch series could also be get from here:
https://github.com/chunyanliu/qemu/commits/QemuOpts

-Chunyan

Quoted 1 line
Quoted 1 line
Quoted 1 line

On 3/10/2014 at 03:31 PM, in message

<[email protected]>, Chunyan Liu

Quoted 66 lines · <[email protected]> wrote:

This patch series is to replace QEMUOptionParameter with QemuOpts, so that only
one Qemu Option structure is kept in QEMU code.

---
Changes to v21:
* update verison info in patch 2/25
* others are not changed except for rebase

Chunyan Liu (25):
add def_value_str to QemuOptDesc
qapi: output def_value_str when query command line options improve some functions in qemu-option.c
improve assertion in qemu_opt_get functions
add some QemuOpts functions for replace work
add convert functions between QEMUOptionParameter to QemuOpts change block layer to support both QemuOpts and QEMUOptionParamter cow.c: replace QEMUOptionParameter with QemuOpts gluster.c: replace QEMUOptionParameter with QemuOpts iscsi.c: replace QEMUOptionParameter with QemuOpts qcow.c: replace QEMUOptionParameter with QemuOpts qcow2.c: replace QEMUOptionParameter with QemuOpts qed.c: replace QEMUOptionParameter with QemuOpts raw-posix.c: replace QEMUOptionParameter with QemuOpts raw-win32.c: replace QEMUOptionParameter with QemuOpts raw_bsd.c: replace QEMUOptionParameter with QemuOpts rbd.c: replace QEMUOptionParameter with QemuOpts sheepdog.c: replace QEMUOptionParameter with QemuOpts ssh.c: replace QEMUOptionParameter with QemuOpts
vdi.c: replace QEMUOptionParameter with QemuOpts vmdk.c: replace QEMUOptionParameter with QemuOpts vpc.c: replace QEMUOptionParameter with QemuOpts vhdx.c: replace QEMUOptionParameter with QemuOpts vvfat.c: replace QEMUOptionParameter with QemuOpts cleanup QEMUOptionParameter

 block.c                   |  96 ++++---- 
 block/cow.c               |  52 ++--- 
 block/gluster.c           |  73 +++--- 
 block/iscsi.c             |  29 ++- 
 block/qcow.c              |  72 +++--- 
 block/qcow2.c             | 325 +++++++++++++------------- 
 block/qed.c               | 112 ++++----- 
 block/qed.h               |   3 +- 
 block/raw-posix.c         |  55 ++--- 
 block/raw-win32.c         |  38 +-- 
 block/raw_bsd.c           |  25 +- 
 block/rbd.c               |  61 +++-- 
 block/sheepdog.c          | 102 ++++---- 
 block/ssh.c               |  30 ++- 
 block/vdi.c               |  70 +++--- 
 block/vhdx.c              |  97 ++++---- 
 block/vhdx.h              |   1 + 
 block/vmdk.c              | 121 +++++----- 
 block/vpc.c               |  60 ++--- 
 block/vvfat.c             |  10 +- 
 include/block/block.h     |   7 +- 
 include/block/block_int.h |   9 +- 
 include/qemu/option.h     |  56 +---- 
 include/qemu/option_int.h |   4 +- 
 qapi-schema.json          |   6 +- 
 qemu-img.c                |  89 ++++--- 
 qmp-commands.hx           |   2 + 
 util/qemu-config.c        |   4 + 
 util/qemu-option.c        | 576 ++++++++++++++++++++++------------------------ 
 29 files changed, 1060 insertions(+), 1125 deletions(-) 
#89 lore raw
In reply to Chunyan Liu

The whole patch series could also be get from here:
https://github.com/chunyanliu/qemu/commits/QemuOpts

-Chunyan

Quoted 1 line
Quoted 1 line
Quoted 1 line

On 3/10/2014 at 03:31 PM, in message

<[email protected]>, Chunyan Liu

Quoted 66 lines · <[email protected]> wrote:

This patch series is to replace QEMUOptionParameter with QemuOpts, so that only
one Qemu Option structure is kept in QEMU code.

---
Changes to v21:
* update verison info in patch 2/25
* others are not changed except for rebase

Chunyan Liu (25):
add def_value_str to QemuOptDesc
qapi: output def_value_str when query command line options improve some functions in qemu-option.c
improve assertion in qemu_opt_get functions
add some QemuOpts functions for replace work
add convert functions between QEMUOptionParameter to QemuOpts change block layer to support both QemuOpts and QEMUOptionParamter cow.c: replace QEMUOptionParameter with QemuOpts gluster.c: replace QEMUOptionParameter with QemuOpts iscsi.c: replace QEMUOptionParameter with QemuOpts qcow.c: replace QEMUOptionParameter with QemuOpts qcow2.c: replace QEMUOptionParameter with QemuOpts qed.c: replace QEMUOptionParameter with QemuOpts raw-posix.c: replace QEMUOptionParameter with QemuOpts raw-win32.c: replace QEMUOptionParameter with QemuOpts raw_bsd.c: replace QEMUOptionParameter with QemuOpts rbd.c: replace QEMUOptionParameter with QemuOpts sheepdog.c: replace QEMUOptionParameter with QemuOpts ssh.c: replace QEMUOptionParameter with QemuOpts
vdi.c: replace QEMUOptionParameter with QemuOpts vmdk.c: replace QEMUOptionParameter with QemuOpts vpc.c: replace QEMUOptionParameter with QemuOpts vhdx.c: replace QEMUOptionParameter with QemuOpts vvfat.c: replace QEMUOptionParameter with QemuOpts cleanup QEMUOptionParameter

 block.c                   |  96 ++++---- 
 block/cow.c               |  52 ++--- 
 block/gluster.c           |  73 +++--- 
 block/iscsi.c             |  29 ++- 
 block/qcow.c              |  72 +++--- 
 block/qcow2.c             | 325 +++++++++++++------------- 
 block/qed.c               | 112 ++++----- 
 block/qed.h               |   3 +- 
 block/raw-posix.c         |  55 ++--- 
 block/raw-win32.c         |  38 +-- 
 block/raw_bsd.c           |  25 +- 
 block/rbd.c               |  61 +++-- 
 block/sheepdog.c          | 102 ++++---- 
 block/ssh.c               |  30 ++- 
 block/vdi.c               |  70 +++--- 
 block/vhdx.c              |  97 ++++---- 
 block/vhdx.h              |   1 + 
 block/vmdk.c              | 121 +++++----- 
 block/vpc.c               |  60 ++--- 
 block/vvfat.c             |  10 +- 
 include/block/block.h     |   7 +- 
 include/block/block_int.h |   9 +- 
 include/qemu/option.h     |  56 +---- 
 include/qemu/option_int.h |   4 +- 
 qapi-schema.json          |   6 +- 
 qemu-img.c                |  89 ++++--- 
 qmp-commands.hx           |   2 + 
 util/qemu-config.c        |   4 + 
 util/qemu-option.c        | 576 ++++++++++++++++++++++------------------------ 
 29 files changed, 1060 insertions(+), 1125 deletions(-) 
#90 lore raw
In reply to Chunyan Liu

The whole patch series could also be get from here:
https://github.com/chunyanliu/qemu/commits/QemuOpts

-Chunyan

Quoted 1 line
Quoted 1 line
Quoted 1 line

On 3/10/2014 at 03:31 PM, in message

<[email protected]>, Chunyan Liu

Quoted 66 lines · <[email protected]> wrote:

This patch series is to replace QEMUOptionParameter with QemuOpts, so that only
one Qemu Option structure is kept in QEMU code.

---
Changes to v21:
* update verison info in patch 2/25
* others are not changed except for rebase

Chunyan Liu (25):
add def_value_str to QemuOptDesc
qapi: output def_value_str when query command line options improve some functions in qemu-option.c
improve assertion in qemu_opt_get functions
add some QemuOpts functions for replace work
add convert functions between QEMUOptionParameter to QemuOpts change block layer to support both QemuOpts and QEMUOptionParamter cow.c: replace QEMUOptionParameter with QemuOpts gluster.c: replace QEMUOptionParameter with QemuOpts iscsi.c: replace QEMUOptionParameter with QemuOpts qcow.c: replace QEMUOptionParameter with QemuOpts qcow2.c: replace QEMUOptionParameter with QemuOpts qed.c: replace QEMUOptionParameter with QemuOpts raw-posix.c: replace QEMUOptionParameter with QemuOpts raw-win32.c: replace QEMUOptionParameter with QemuOpts raw_bsd.c: replace QEMUOptionParameter with QemuOpts rbd.c: replace QEMUOptionParameter with QemuOpts sheepdog.c: replace QEMUOptionParameter with QemuOpts ssh.c: replace QEMUOptionParameter with QemuOpts
vdi.c: replace QEMUOptionParameter with QemuOpts vmdk.c: replace QEMUOptionParameter with QemuOpts vpc.c: replace QEMUOptionParameter with QemuOpts vhdx.c: replace QEMUOptionParameter with QemuOpts vvfat.c: replace QEMUOptionParameter with QemuOpts cleanup QEMUOptionParameter

 block.c                   |  96 ++++---- 
 block/cow.c               |  52 ++--- 
 block/gluster.c           |  73 +++--- 
 block/iscsi.c             |  29 ++- 
 block/qcow.c              |  72 +++--- 
 block/qcow2.c             | 325 +++++++++++++------------- 
 block/qed.c               | 112 ++++----- 
 block/qed.h               |   3 +- 
 block/raw-posix.c         |  55 ++--- 
 block/raw-win32.c         |  38 +-- 
 block/raw_bsd.c           |  25 +- 
 block/rbd.c               |  61 +++-- 
 block/sheepdog.c          | 102 ++++---- 
 block/ssh.c               |  30 ++- 
 block/vdi.c               |  70 +++--- 
 block/vhdx.c              |  97 ++++---- 
 block/vhdx.h              |   1 + 
 block/vmdk.c              | 121 +++++----- 
 block/vpc.c               |  60 ++--- 
 block/vvfat.c             |  10 +- 
 include/block/block.h     |   7 +- 
 include/block/block_int.h |   9 +- 
 include/qemu/option.h     |  56 +---- 
 include/qemu/option_int.h |   4 +- 
 qapi-schema.json          |   6 +- 
 qemu-img.c                |  89 ++++--- 
 qmp-commands.hx           |   2 + 
 util/qemu-config.c        |   4 + 
 util/qemu-option.c        | 576 ++++++++++++++++++++++------------------------ 
 29 files changed, 1060 insertions(+), 1125 deletions(-) 
#91 lore raw
In reply to Chunyan Liu

The whole patch series could also be get from here:
https://github.com/chunyanliu/qemu/commits/QemuOpts

-Chunyan

Quoted 1 line
Quoted 1 line
Quoted 1 line

On 3/10/2014 at 03:31 PM, in message

<[email protected]>, Chunyan Liu

Quoted 66 lines · <[email protected]> wrote:

This patch series is to replace QEMUOptionParameter with QemuOpts, so that only
one Qemu Option structure is kept in QEMU code.

---
Changes to v21:
* update verison info in patch 2/25
* others are not changed except for rebase

Chunyan Liu (25):
add def_value_str to QemuOptDesc
qapi: output def_value_str when query command line options improve some functions in qemu-option.c
improve assertion in qemu_opt_get functions
add some QemuOpts functions for replace work
add convert functions between QEMUOptionParameter to QemuOpts change block layer to support both QemuOpts and QEMUOptionParamter cow.c: replace QEMUOptionParameter with QemuOpts gluster.c: replace QEMUOptionParameter with QemuOpts iscsi.c: replace QEMUOptionParameter with QemuOpts qcow.c: replace QEMUOptionParameter with QemuOpts qcow2.c: replace QEMUOptionParameter with QemuOpts qed.c: replace QEMUOptionParameter with QemuOpts raw-posix.c: replace QEMUOptionParameter with QemuOpts raw-win32.c: replace QEMUOptionParameter with QemuOpts raw_bsd.c: replace QEMUOptionParameter with QemuOpts rbd.c: replace QEMUOptionParameter with QemuOpts sheepdog.c: replace QEMUOptionParameter with QemuOpts ssh.c: replace QEMUOptionParameter with QemuOpts
vdi.c: replace QEMUOptionParameter with QemuOpts vmdk.c: replace QEMUOptionParameter with QemuOpts vpc.c: replace QEMUOptionParameter with QemuOpts vhdx.c: replace QEMUOptionParameter with QemuOpts vvfat.c: replace QEMUOptionParameter with QemuOpts cleanup QEMUOptionParameter

 block.c                   |  96 ++++---- 
 block/cow.c               |  52 ++--- 
 block/gluster.c           |  73 +++--- 
 block/iscsi.c             |  29 ++- 
 block/qcow.c              |  72 +++--- 
 block/qcow2.c             | 325 +++++++++++++------------- 
 block/qed.c               | 112 ++++----- 
 block/qed.h               |   3 +- 
 block/raw-posix.c         |  55 ++--- 
 block/raw-win32.c         |  38 +-- 
 block/raw_bsd.c           |  25 +- 
 block/rbd.c               |  61 +++-- 
 block/sheepdog.c          | 102 ++++---- 
 block/ssh.c               |  30 ++- 
 block/vdi.c               |  70 +++--- 
 block/vhdx.c              |  97 ++++---- 
 block/vhdx.h              |   1 + 
 block/vmdk.c              | 121 +++++----- 
 block/vpc.c               |  60 ++--- 
 block/vvfat.c             |  10 +- 
 include/block/block.h     |   7 +- 
 include/block/block_int.h |   9 +- 
 include/qemu/option.h     |  56 +---- 
 include/qemu/option_int.h |   4 +- 
 qapi-schema.json          |   6 +- 
 qemu-img.c                |  89 ++++--- 
 qmp-commands.hx           |   2 + 
 util/qemu-config.c        |   4 + 
 util/qemu-option.c        | 576 ++++++++++++++++++++++------------------------ 
 29 files changed, 1060 insertions(+), 1125 deletions(-) 
#92 lore raw
In reply to Chunyan Liu
Quoted 57 lines · Chunyan Liu

This patch series is to replace QEMUOptionParameter with QemuOpts, so that only one Qemu Option structure is kept in QEMU code.

---
Changes to v21:
* update verison info in patch 2/25
* others are not changed except for rebase

Chunyan Liu (25):
add def_value_str to QemuOptDesc
qapi: output def_value_str when query command line options improve some functions in qemu-option.c
improve assertion in qemu_opt_get functions
add some QemuOpts functions for replace work
add convert functions between QEMUOptionParameter to QemuOpts change block layer to support both QemuOpts and QEMUOptionParamter cow.c: replace QEMUOptionParameter with QemuOpts gluster.c: replace QEMUOptionParameter with QemuOpts iscsi.c: replace QEMUOptionParameter with QemuOpts qcow.c: replace QEMUOptionParameter with QemuOpts qcow2.c: replace QEMUOptionParameter with QemuOpts qed.c: replace QEMUOptionParameter with QemuOpts raw-posix.c: replace QEMUOptionParameter with QemuOpts raw-win32.c: replace QEMUOptionParameter with QemuOpts raw_bsd.c: replace QEMUOptionParameter with QemuOpts rbd.c: replace QEMUOptionParameter with QemuOpts sheepdog.c: replace QEMUOptionParameter with QemuOpts ssh.c: replace QEMUOptionParameter with QemuOpts
vdi.c: replace QEMUOptionParameter with QemuOpts vmdk.c: replace QEMUOptionParameter with QemuOpts vpc.c: replace QEMUOptionParameter with QemuOpts vhdx.c: replace QEMUOptionParameter with QemuOpts vvfat.c: replace QEMUOptionParameter with QemuOpts cleanup QEMUOptionParameter

 block.c                   |  96 ++++----
 block/cow.c               |  52 ++---
 block/gluster.c           |  73 +++---
 block/iscsi.c             |  29 ++-
 block/qcow.c              |  72 +++---
 block/qcow2.c             | 325 +++++++++++++-------------
 block/qed.c               | 112 ++++-----
 block/qed.h               |   3 +-
 block/raw-posix.c         |  55 ++---
 block/raw-win32.c         |  38 +--
 block/raw_bsd.c           |  25 +-
 block/rbd.c               |  61 +++--
 block/sheepdog.c          | 102 ++++----
 block/ssh.c               |  30 ++-
 block/vdi.c               |  70 +++---
 block/vhdx.c              |  97 ++++----
 block/vhdx.h              |   1 +
 block/vmdk.c              | 121 +++++-----
 block/vpc.c               |  60 ++---
 block/vvfat.c             |  10 +-
 include/block/block.h     |   7 +-
 include/block/block_int.h |   9 +-
Quoted 8 lines
 include/qemu/option.h     |  56 +----
 include/qemu/option_int.h |   4 +-
 qapi-schema.json          |   6 +-
 qemu-img.c                |  89 ++++---
 qmp-commands.hx           |   2 +
 util/qemu-config.c        |   4 +
 util/qemu-option.c        | 576 ++++++++++++++++++++++------------------------
 29 files changed, 1060 insertions(+), 1125 deletions(-)

Looks like this needs to be rebased onto qemu.git/master:

qapi/string-input-visitor.c: In function ‘parse_type_size’:
qapi/string-input-visitor.c:53:9: error: implicit declaration of function ‘parse_option_size’ [-Werror=implicit-function-declaration]

         parse_option_size(name, siv->string, &val, &err);
         ^

qapi/string-input-visitor.c:53:9: error: nested extern declaration of ‘parse_option_size’ [-Werror=nested-externs]
cc1: all warnings being treated as errors
make: *** [qapi/string-input-visitor.o] Error 1
make: *** Waiting for unfinished jobs....
qapi/opts-visitor.c: In function ‘opts_start_struct’:
qapi/opts-visitor.c:146:31: error: assignment discards ‘const’ qualifier from pointer target type [-Werror]

         ov->fake_id_opt->name = "id";
                               ^
#93 lore raw

2014-03-11 4:22 GMT+08:00 Stefan Hajnoczi <[email protected]>:

Quoted 69 lines · Chunyan Liu
Quoted 1 line

This patch series is to replace QEMUOptionParameter with QemuOpts, so

that only

Quoted 55 lines

one Qemu Option structure is kept in QEMU code.

---
Changes to v21:
* update verison info in patch 2/25
* others are not changed except for rebase

Chunyan Liu (25):
add def_value_str to QemuOptDesc
qapi: output def_value_str when query command line options improve some functions in qemu-option.c
improve assertion in qemu_opt_get functions
add some QemuOpts functions for replace work
add convert functions between QEMUOptionParameter to QemuOpts change block layer to support both QemuOpts and QEMUOptionParamter cow.c: replace QEMUOptionParameter with QemuOpts gluster.c: replace QEMUOptionParameter with QemuOpts iscsi.c: replace QEMUOptionParameter with QemuOpts qcow.c: replace QEMUOptionParameter with QemuOpts qcow2.c: replace QEMUOptionParameter with QemuOpts qed.c: replace QEMUOptionParameter with QemuOpts raw-posix.c: replace QEMUOptionParameter with QemuOpts raw-win32.c: replace QEMUOptionParameter with QemuOpts raw_bsd.c: replace QEMUOptionParameter with QemuOpts rbd.c: replace QEMUOptionParameter with QemuOpts sheepdog.c: replace QEMUOptionParameter with QemuOpts ssh.c: replace QEMUOptionParameter with QemuOpts
vdi.c: replace QEMUOptionParameter with QemuOpts vmdk.c: replace QEMUOptionParameter with QemuOpts vpc.c: replace QEMUOptionParameter with QemuOpts vhdx.c: replace QEMUOptionParameter with QemuOpts vvfat.c: replace QEMUOptionParameter with QemuOpts cleanup QEMUOptionParameter

 block.c                   |  96 ++++----
 block/cow.c               |  52 ++---
 block/gluster.c           |  73 +++---
 block/iscsi.c             |  29 ++-
 block/qcow.c              |  72 +++---
 block/qcow2.c             | 325 +++++++++++++-------------
 block/qed.c               | 112 ++++-----
 block/qed.h               |   3 +-
 block/raw-posix.c         |  55 ++---
 block/raw-win32.c         |  38 +--
 block/raw_bsd.c           |  25 +-
 block/rbd.c               |  61 +++--
 block/sheepdog.c          | 102 ++++----
 block/ssh.c               |  30 ++-
 block/vdi.c               |  70 +++---
 block/vhdx.c              |  97 ++++----
 block/vhdx.h              |   1 +
 block/vmdk.c              | 121 +++++-----
 block/vpc.c               |  60 ++---
 block/vvfat.c             |  10 +-
 include/block/block.h     |   7 +-
Quoted 8 lines
 include/block/block_int.h |   9 +-
 include/qemu/option.h     |  56 +----
 include/qemu/option_int.h |   4 +-
 qapi-schema.json          |   6 +-
 qemu-img.c                |  89 ++++---
 qmp-commands.hx           |   2 +
 util/qemu-config.c        |   4 +
 util/qemu-option.c        | 576

++++++++++++++++++++++------------------------

Quoted 1 line
 29 files changed, 1060 insertions(+), 1125 deletions(-)
Quoted 8 lines

Looks like this needs to be rebased onto qemu.git/master:

qapi/string-input-visitor.c: In function ‘parse_type_size’:
qapi/string-input-visitor.c:53:9: error: implicit declaration of function ‘parse_option_size’ [-Werror=implicit-function-declaration]

         parse_option_size(name, siv->string, &val, &err);
         ^

I've updated the patch series in github:
https://github.com/chunyanliu/qemu/commits/QemuOpts

updated 25/25.

Quoted 11 lines

qapi/string-input-visitor.c:53:9: error: nested extern declaration of ‘parse_option_size’ [-Werror=nested-externs]
cc1: all warnings being treated as errors
make: *** [qapi/string-input-visitor.o] Error 1
make: *** Waiting for unfinished jobs.... qapi/opts-visitor.c: In function ‘opts_start_struct’:
qapi/opts-visitor.c:146:31: error: assignment discards ‘const’ qualifier from pointer target type [-Werror]

         ov->fake_id_opt->name = "id";
                               ^

following patch squashed to 03/25:

---
 qapi/opts-visitor.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
qapi/opts-visitor.c +0 -0
index 5d830a2..e6a295a 100644
@@ -143,8 +143,8 @@ opts_start_struct(Visitor *v, void **obj, const char

*kind,

     if (ov->opts_root->id != NULL) {
         ov->fake_id_opt = g_malloc0(sizeof *ov->fake_id_opt);
-        ov->fake_id_opt->name = "id";
-        ov->fake_id_opt->str = ov->opts_root->id;
+        ov->fake_id_opt->name = g_strdup("id");
+        ov->fake_id_opt->str = g_strdup(ov->opts_root->id);
         opts_visitor_insert(ov->unprocessed_opts, ov->fake_id_opt);
     }
 }
@@ -177,6 +177,8 @@ opts_end_struct(Visitor *v, Error **errp)
     }
     g_hash_table_destroy(ov->unprocessed_opts);
     ov->unprocessed_opts = NULL;
+    g_free(ov->fake_id_opt->name);
+    g_free(ov->fake_id_opt->str);
     g_free(ov->fake_id_opt);
     ov->fake_id_opt = NULL;

}

Signature · 1 line
1.7.12.4
#94 lore raw
In reply to Chunyan Liu
Quoted 2 lines · Chunyan Liu

This patch series is to replace QEMUOptionParameter with QemuOpts, so that only one Qemu Option structure is kept in QEMU code.

Uggh. The more I learn about QemuOpts while reviewing this patch, the more I KNOW it has lurking bugs waiting to bite us.

Case in point:

$ touch oddname,id=1
$ qemu-system-x86_64 -drive id=a,file=oddname,,id=1    # starts
$ # now, swap the two arguments:
$ qemu-system-x86_64 -drive file=oddname,,id=1,id=a
qemu-system-x86_64: -drive file=oddname,,id=1,id=a: Parameter 'id'
expects an identifier
$

Gross. opts_parse uses strncmp() for checking for a leading 'id=', but strstr() for checking for an intermediate ',id='. And strstr() can have false positives, including in the middle of my filename that was properly escaped.

This is a long-standing bug - as a bug, you can fix it after freeze, but as it is long-standing, it's not the end of the world if it misses 2.0.
But it underscores my plea that this series is not fully baked until
you add a testsuite.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#95 lore raw
In reply to Chunyan Liu
Quoted 2 lines · Chunyan Liu

This patch series is to replace QEMUOptionParameter with QemuOpts, so that only one Qemu Option structure is kept in QEMU code.

Hi Chunyan,
Please add my Reviewed-by: tags to the commits so future revisions will already have them. If you change the code in a patch then please remove the Reviewed-by: again.

This will help reviewers narrow down the scope of patches to review and hopefully we'll soon be able to merge this series.

Thanks,
Stefan

#96 lore raw
In reply to Chunyan Liu

Hi Chunyan,

Quoted 3 lines · Chunyan Liu

This patch series is to replace QEMUOptionParameter with QemuOpts, so that only one Qemu Option structure is kept in QEMU code.

Last night I took some time do take a deeper look at you series and the required effort to do the QemuOptionParameter -> QemuOpts migration.

I think you've over complicated the things, I understand you tried to keep your serie's bisectability (?), but the final result was something really hard to review and to integrate as well. The overall approach wasn't even resolving the bisectability problem since it breaks the tree until the last commit. Moreover, in the path of getting things ready you created new problems and their respective fixes, what we really don't need to.

In this regards you could have kept things as simple as possible and submitted the patches in a "natural way", even if they were breaking the build between each patch, you could get all the required maintainer's Reviewed-by + Tested-by + Signed-off-by and so on for each individual patch and when it was time to integrate get squashed the needed patches.

I mean, add N patches introducing new required QemuOpts API's, 1 patch migrating the block upper layer (block.c, block.h, etc), one patch for each block driver (i.e ssh.c, qcow.c, qcow2.c, etc), one patch for qemu-img.c and finally a last patch removing the QEMUOptionParamer itself. When time comes to integrate your series the patches changing the block layer + patches changing the block drivers + patches changing qemu-img.c could be squashed adding all the collected Reviewed-by to this single squashed patch.

As I said, last night I took a deeper look at the problem and, understood most of changes weren't required to do the job. We don't need an adaptation layer between QemuOptionParameter and QemuOpts, we don't need to add new opts accessors (like those qemu_opt_*_del() functions), all we need is 1) that qemu_opts_append() function so we can merge the protocol and drivers options in a single QemuOptList and
2) the default value support. All we need is already present in the QemuOpts APIs.

With that simpler approach in mind I ended up putting my hands in the source code trying to see how feasible it is, and turns out I came up with a full solution. I'm sending the job's resulting series to the mailing list so I can show you what I mean and have some more room for discussion. It doesn't mean I want to overlap you work, I just needed to have a little more input on that.

Regards....

Signature · 1 line
Leandro Dorileo
#97 lore raw

2014-03-21 8:07 GMT+08:00 Leandro Dorileo <[email protected]>:

Quoted 25 lines

Hi Chunyan,

Quoted 1 line · Chunyan Liu

This patch series is to replace QEMUOptionParameter with QemuOpts, so

that only

Quoted 2 lines

one Qemu Option structure is kept in QEMU code.

Last night I took some time do take a deeper look at you series and the required
effort to do the QemuOptionParameter -> QemuOpts migration.

I think you've over complicated the things, I understand you tried to keep your
serie's bisectability (?), but the final result was something really hard to
review and to integrate as well. The overall approach wasn't even resolving the
bisectability problem since it breaks the tree until the last commit. Moreover,
in the path of getting things ready you created new problems and their respective
fixes, what we really don't need to.

Quoted 9 lines

In this regards you could have kept things as simple as possible and submitted
the patches in a "natural way", even if they were breaking the build between each
patch, you could get all the required maintainer's Reviewed-by + Tested-by +
Signed-off-by and so on for each individual patch and when it was time to integrate get squashed the needed patches.

Well, if breaking the build could be allowed between each patch, then it could be
much cleaner. Indeed there are lots of code just for build and function unbroken
between each patch. I'm inclined to listen to more voice. If all agree to this method,
it's OK to me.

Quoted 28 lines

I mean, add N patches introducing new required QemuOpts API's, 1 patch migrating
the block upper layer (block.c, block.h, etc), one patch for each block driver
(i.e ssh.c, qcow.c, qcow2.c, etc), one patch for qemu-img.c and finally a last
patch removing the QEMUOptionParamer itself. When time comes to integrate your
series the patches changing the block layer + patches changing the block drivers +
patches changing qemu-img.c could be squashed adding all the collected Reviewed-by
to this single squashed patch.

As I said, last night I took a deeper look at the problem and, understood most
of changes weren't required to do the job. We don't need an adaptation layer between
QemuOptionParameter and QemuOpts, we don't need to add new opts accessors (like
those qemu_opt_*_del() functions), all we need is 1) that qemu_opts_append() function
so we can merge the protocol and drivers options in a single QemuOptList and
2) the default value support. All we need is already present in the QemuOpts APIs.

Quoted 1 line

qemu_opt_*_del functions are needed. Each driver handles options they

expected then
delete, left options passed to 2nd driver and let it handle. Like qcow2 create, first, qcow2
driver handle, then raw driver handle.

But as you point, some changes are not required for this job, I've omitted in my new patch
series, like: qemu_opt_set, NULL check in qemu_opt_get and qemu_opt_find, assert()
update in qemu_opt_get.

Quoted 10 lines

With that simpler approach in mind I ended up putting my hands in the source code
trying to see how feasible it is, and turns out I came up with a full solution. I'm
sending the job's resulting series to the mailing list so I can show you what
I mean and have some more room for discussion. It doesn't mean I want to overlap
you work, I just needed to have a little more input on that.

No matter. I'm OK to follow a more acceptable way :)

Quoted 7 lines

Regards....

--
Leandro Dorileo

#98 lore raw
Quoted 37 lines · Chunyan Liu

2014-03-21 8:07 GMT+08:00 Leandro Dorileo <[email protected]>:

Quoted 25 lines

Hi Chunyan,

Quoted 1 line · Chunyan Liu

This patch series is to replace QEMUOptionParameter with QemuOpts, so

that only

Quoted 2 lines

one Qemu Option structure is kept in QEMU code.

Last night I took some time do take a deeper look at you series and the required
effort to do the QemuOptionParameter -> QemuOpts migration.

I think you've over complicated the things, I understand you tried to keep your
serie's bisectability (?), but the final result was something really hard to
review and to integrate as well. The overall approach wasn't even resolving the
bisectability problem since it breaks the tree until the last commit. Moreover,
in the path of getting things ready you created new problems and their respective
fixes, what we really don't need to.

Quoted 9 lines

In this regards you could have kept things as simple as possible and submitted
the patches in a "natural way", even if they were breaking the build between each
patch, you could get all the required maintainer's Reviewed-by + Tested-by +
Signed-off-by and so on for each individual patch and when it was time to integrate get squashed the needed patches.

Quoted 7 lines

Well, if breaking the build could be allowed between each patch, then it could be
much cleaner. Indeed there are lots of code just for build and function unbroken
between each patch. I'm inclined to listen to more voice. If all agree to this method,
it's OK to me.

The thing is the balance between complexity and the change size. Do we really want to avoid a small patch - doing all the change - and increase the whole thing complexity? I don't see a great benefit on that :)

Quoted 30 lines
Quoted 30 lines

I mean, add N patches introducing new required QemuOpts API's, 1 patch migrating
the block upper layer (block.c, block.h, etc), one patch for each block driver
(i.e ssh.c, qcow.c, qcow2.c, etc), one patch for qemu-img.c and finally a last
patch removing the QEMUOptionParamer itself. When time comes to integrate your
series the patches changing the block layer + patches changing the block drivers +
patches changing qemu-img.c could be squashed adding all the collected Reviewed-by
to this single squashed patch.

As I said, last night I took a deeper look at the problem and, understood most
of changes weren't required to do the job. We don't need an adaptation layer between
QemuOptionParameter and QemuOpts, we don't need to add new opts accessors (like
those qemu_opt_*_del() functions), all we need is 1) that qemu_opts_append() function
so we can merge the protocol and drivers options in a single QemuOptList and
2) the default value support. All we need is already present in the QemuOpts APIs.

Quoted 5 lines
Quoted 1 line

qemu_opt_*_del functions are needed. Each driver handles options they

expected then
delete, left options passed to 2nd driver and let it handle. Like qcow2 create, first, qcow2
driver handle, then raw driver handle.

Not true, the only place you need to allocate QemuOpts or QemuOptsList is on qemu-img.c and block.c, if they're doing so they should free it, not the lower lavels. The block drivers should just use it, unless they do allocate anything themselves.

Quoted 7 lines

But as you point, some changes are not required for this job, I've omitted in my new patch
series, like: qemu_opt_set, NULL check in qemu_opt_get and qemu_opt_find, assert()
update in qemu_opt_get.

Ok.

Signature · 1 line
Leandro Dorileo
Quoted 22 lines
Quoted 11 lines

With that simpler approach in mind I ended up putting my hands in the source code
trying to see how feasible it is, and turns out I came up with a full solution. I'm
sending the job's resulting series to the mailing list so I can show you what
I mean and have some more room for discussion. It doesn't mean I want to overlap
you work, I just needed to have a little more input on that.

No matter. I'm OK to follow a more acceptable way :)

Quoted 7 lines

Regards....

--
Leandro Dorileo

#99 lore raw

2014-03-21 20:31 GMT+08:00 Leandro Dorileo <[email protected]>:

Quoted 100 lines · Chunyan Liu
Quoted 16 lines

2014-03-21 8:07 GMT+08:00 Leandro Dorileo <[email protected]>:

Quoted 14 lines

Hi Chunyan,

Quoted 1 line · Chunyan Liu

This patch series is to replace QEMUOptionParameter with QemuOpts, so

that only

Quoted 2 lines

one Qemu Option structure is kept in QEMU code.

Last night I took some time do take a deeper look at you series and the required
effort to do the QemuOptionParameter -> QemuOpts migration.

I think you've over complicated the things, I understand you tried to

keep

Quoted 2 lines
Quoted 2 lines

your
serie's bisectability (?), but the final result was something really

hard

Quoted 9 lines
Quoted 9 lines

to
review and to integrate as well. The overall approach wasn't even resolving the
bisectability problem since it breaks the tree until the last commit. Moreover,
in the path of getting things ready you created new problems and their respective
fixes, what we really don't need to.

Quoted 5 lines
Quoted 5 lines

In this regards you could have kept things as simple as possible and submitted
the patches in a "natural way", even if they were breaking the build between each
patch, you could get all the required maintainer's Reviewed-by +

Tested-by

Quoted 2 lines
Quoted 2 lines

+
Signed-off-by and so on for each individual patch and when it was time

to

Quoted 10 lines
Quoted 2 lines

integrate get squashed the needed patches.

Well, if breaking the build could be allowed between each patch, then it could be
much cleaner. Indeed there are lots of code just for build and function unbroken
between each patch. I'm inclined to listen to more voice. If all agree to this method,
it's OK to me.

The thing is the balance between complexity and the change size. Do we really
want to avoid a small patch - doing all the change - and increase the whole thing complexity? I don't see a great benefit on that :)

Quoted 8 lines
Quoted 8 lines

I mean, add N patches introducing new required QemuOpts API's, 1 patch migrating
the block upper layer (block.c, block.h, etc), one patch for each block driver
(i.e ssh.c, qcow.c, qcow2.c, etc), one patch for qemu-img.c and

finally a

Quoted 2 lines
Quoted 2 lines

last
patch removing the QEMUOptionParamer itself. When time comes to

integrate

Quoted 2 lines
Quoted 2 lines

your
series the patches changing the block layer + patches changing the

block

Quoted 6 lines
Quoted 6 lines

drivers +
patches changing qemu-img.c could be squashed adding all the collected Reviewed-by
to this single squashed patch.

As I said, last night I took a deeper look at the problem and,

understood

Quoted 4 lines
Quoted 4 lines

most
of changes weren't required to do the job. We don't need an adaptation layer between
QemuOptionParameter and QemuOpts, we don't need to add new opts

accessors

Quoted 4 lines
Quoted 4 lines

(like
those qemu_opt_*_del() functions), all we need is 1) that qemu_opts_append() function
so we can merge the protocol and drivers options in a single

QemuOptList

Quoted 9 lines
Quoted 5 lines

and
2) the default value support. All we need is already present in the QemuOpts APIs.

qemu_opt_*_del functions are needed. Each driver handles options they

expected then
delete, left options passed to 2nd driver and let it handle. Like qcow2 create, first, qcow2
driver handle, then raw driver handle.

Quoted 6 lines

Not true, the only place you need to allocate QemuOpts or QemuOptsList is on qemu-img.c and block.c, if they're doing so they should free it, not the lower lavels. The block drivers should just use it, unless they do allocate anything themselves.

The reason qemu_opt_get_*_del functions should be used in backend drivers, is to
keep same behavior as how previous QEMUOptionParameter handles. At least, in one
case: create a qcow2 img. "size" option is handled by qcow2 driver, then delete; in 2nd raw
driver, there is no "size" option any more, it will create a 0 size file. If qemu_opt_get but
not delete, then all options will be passed to 2nd raw driver, it will create a full sized file.
That is not expected.

Quoted 41 lines
Quoted 3 lines

But as you point, some changes are not required for this job, I've

omitted

Quoted 5 lines

in my new patch
series, like: qemu_opt_set, NULL check in qemu_opt_get and qemu_opt_find, assert()
update in qemu_opt_get.

Ok.

--
Leandro Dorileo

Quoted 6 lines
Quoted 6 lines

With that simpler approach in mind I ended up putting my hands in the source code
trying to see how feasible it is, and turns out I came up with a full solution. I'm
sending the job's resulting series to the mailing list so I can show

you

Quoted 2 lines
Quoted 2 lines

what
I mean and have some more room for discussion. It doesn't mean I want

to

Quoted 14 lines
Quoted 3 lines

overlap
you work, I just needed to have a little more input on that.

No matter. I'm OK to follow a more acceptable way :)

Quoted 7 lines

Regards....

--
Leandro Dorileo

#100 lore raw

Hi Chunyan,

Quoted 108 lines · Chunyan Liu

2014-03-21 20:31 GMT+08:00 Leandro Dorileo <[email protected]>:

Quoted 100 lines · Chunyan Liu
Quoted 16 lines

2014-03-21 8:07 GMT+08:00 Leandro Dorileo <[email protected]>:

Quoted 14 lines

Hi Chunyan,

Quoted 1 line · Chunyan Liu

This patch series is to replace QEMUOptionParameter with QemuOpts, so

that only

Quoted 2 lines

one Qemu Option structure is kept in QEMU code.

Last night I took some time do take a deeper look at you series and the required
effort to do the QemuOptionParameter -> QemuOpts migration.

I think you've over complicated the things, I understand you tried to

keep

Quoted 2 lines
Quoted 2 lines

your
serie's bisectability (?), but the final result was something really

hard

Quoted 9 lines
Quoted 9 lines

to
review and to integrate as well. The overall approach wasn't even resolving the
bisectability problem since it breaks the tree until the last commit. Moreover,
in the path of getting things ready you created new problems and their respective
fixes, what we really don't need to.

Quoted 5 lines
Quoted 5 lines

In this regards you could have kept things as simple as possible and submitted
the patches in a "natural way", even if they were breaking the build between each
patch, you could get all the required maintainer's Reviewed-by +

Tested-by

Quoted 2 lines
Quoted 2 lines

+
Signed-off-by and so on for each individual patch and when it was time

to

Quoted 10 lines
Quoted 2 lines

integrate get squashed the needed patches.

Well, if breaking the build could be allowed between each patch, then it could be
much cleaner. Indeed there are lots of code just for build and function unbroken
between each patch. I'm inclined to listen to more voice. If all agree to this method,
it's OK to me.

The thing is the balance between complexity and the change size. Do we really
want to avoid a small patch - doing all the change - and increase the whole thing complexity? I don't see a great benefit on that :)

Quoted 8 lines
Quoted 8 lines

I mean, add N patches introducing new required QemuOpts API's, 1 patch migrating
the block upper layer (block.c, block.h, etc), one patch for each block driver
(i.e ssh.c, qcow.c, qcow2.c, etc), one patch for qemu-img.c and

finally a

Quoted 2 lines
Quoted 2 lines

last
patch removing the QEMUOptionParamer itself. When time comes to

integrate

Quoted 2 lines
Quoted 2 lines

your
series the patches changing the block layer + patches changing the

block

Quoted 6 lines
Quoted 6 lines

drivers +
patches changing qemu-img.c could be squashed adding all the collected Reviewed-by
to this single squashed patch.

As I said, last night I took a deeper look at the problem and,

understood

Quoted 4 lines
Quoted 4 lines

most
of changes weren't required to do the job. We don't need an adaptation layer between
QemuOptionParameter and QemuOpts, we don't need to add new opts

accessors

Quoted 4 lines
Quoted 4 lines

(like
those qemu_opt_*_del() functions), all we need is 1) that qemu_opts_append() function
so we can merge the protocol and drivers options in a single

QemuOptList

Quoted 9 lines
Quoted 5 lines

and
2) the default value support. All we need is already present in the QemuOpts APIs.

qemu_opt_*_del functions are needed. Each driver handles options they

expected then
delete, left options passed to 2nd driver and let it handle. Like qcow2 create, first, qcow2
driver handle, then raw driver handle.

Quoted 6 lines

Not true, the only place you need to allocate QemuOpts or QemuOptsList is on qemu-img.c and block.c, if they're doing so they should free it, not the lower lavels. The block drivers should just use it, unless they do allocate anything themselves.

Quoted 11 lines

The reason qemu_opt_get_*_del functions should be used in backend drivers, is to
keep same behavior as how previous QEMUOptionParameter handles. At least, in one
case: create a qcow2 img. "size" option is handled by qcow2 driver, then delete; in 2nd raw
driver, there is no "size" option any more, it will create a 0 size file. If qemu_opt_get but
not delete, then all options will be passed to 2nd raw driver, it will create a full sized file.
That is not expected.

I couldn't find the described use case - I still think you don't need to unset it, but if that's the case what about using for example:

uint64_t sectos = qemu_opt_get_size(options, BLOCK_OPT_SIZE) / 512; ret = qemu_opt_unset(options, BLOCK_OPT_SIZE);

You don't need to introduce a new API for this.

Regards..

Signature · 1 line
Leandro Dorileo
Quoted 43 lines
Quoted 43 lines
Quoted 5 lines

But as you point, some changes are not required for this job, I've

omitted

Quoted 5 lines

in my new patch
series, like: qemu_opt_set, NULL check in qemu_opt_get and qemu_opt_find, assert()
update in qemu_opt_get.

Ok.

--
Leandro Dorileo

Quoted 6 lines
Quoted 6 lines

With that simpler approach in mind I ended up putting my hands in the source code
trying to see how feasible it is, and turns out I came up with a full solution. I'm
sending the job's resulting series to the mailing list so I can show

you

Quoted 2 lines
Quoted 2 lines

what
I mean and have some more room for discussion. It doesn't mean I want

to

Quoted 14 lines
Quoted 3 lines

overlap
you work, I just needed to have a little more input on that.

No matter. I'm OK to follow a more acceptable way :)

Quoted 7 lines

Regards....

--
Leandro Dorileo

#101 lore raw

2014-03-24 23:00 GMT+08:00 Leandro Dorileo <[email protected]>:

Quoted 145 lines

Hi Chunyan,

Quoted 9 lines · Chunyan Liu

2014-03-21 20:31 GMT+08:00 Leandro Dorileo <[email protected]>:

Quoted 7 lines · Chunyan Liu
Quoted 6 lines

2014-03-21 8:07 GMT+08:00 Leandro Dorileo <[email protected]>:

Quoted 4 lines

Hi Chunyan,

Quoted 1 line · Chunyan Liu

This patch series is to replace QEMUOptionParameter with

QemuOpts, so

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

that only

Quoted 2 lines

one Qemu Option structure is kept in QEMU code.

Last night I took some time do take a deeper look at you series

and the

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

required
effort to do the QemuOptionParameter -> QemuOpts migration.

I think you've over complicated the things, I understand you tried

to

Quoted 3 lines
Quoted 3 lines

keep

Quoted 2 lines
Quoted 2 lines

your
serie's bisectability (?), but the final result was something

really

Quoted 5 lines
Quoted 5 lines

hard

Quoted 4 lines
Quoted 4 lines

to
review and to integrate as well. The overall approach wasn't even resolving the
bisectability problem since it breaks the tree until the last

commit.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Moreover,
in the path of getting things ready you created new problems and

their

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

respective
fixes, what we really don't need to.

In this regards you could have kept things as simple as possible

and

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

submitted
the patches in a "natural way", even if they were breaking the

build

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

between each
patch, you could get all the required maintainer's Reviewed-by +

Tested-by

Quoted 2 lines
Quoted 2 lines

+
Signed-off-by and so on for each individual patch and when it was

time

Quoted 5 lines
Quoted 5 lines

to

Quoted 4 lines
Quoted 2 lines

integrate get squashed the needed patches.

Well, if breaking the build could be allowed between each patch,

then it

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

could be
much cleaner. Indeed there are lots of code just for build and

function

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

unbroken
between each patch. I'm inclined to listen to more voice. If all

agree to

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

this method,
it's OK to me.

The thing is the balance between complexity and the change size. Do we really
want to avoid a small patch - doing all the change - and increase the

whole

Quoted 7 lines
Quoted 7 lines

thing complexity? I don't see a great benefit on that :)

Quoted 4 lines
Quoted 4 lines

I mean, add N patches introducing new required QemuOpts API's, 1

patch

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

migrating
the block upper layer (block.c, block.h, etc), one patch for each

block

Quoted 11 lines
Quoted 11 lines
Quoted 2 lines
Quoted 2 lines

driver
(i.e ssh.c, qcow.c, qcow2.c, etc), one patch for qemu-img.c and

finally a

Quoted 2 lines
Quoted 2 lines

last
patch removing the QEMUOptionParamer itself. When time comes to

integrate

Quoted 2 lines
Quoted 2 lines

your
series the patches changing the block layer + patches changing the

block

Quoted 2 lines
Quoted 2 lines

drivers +
patches changing qemu-img.c could be squashed adding all the

collected

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

Reviewed-by
to this single squashed patch.

As I said, last night I took a deeper look at the problem and,

understood

Quoted 2 lines
Quoted 2 lines

most
of changes weren't required to do the job. We don't need an

adaptation

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

layer between
QemuOptionParameter and QemuOpts, we don't need to add new opts

accessors

Quoted 4 lines
Quoted 4 lines

(like
those qemu_opt_*_del() functions), all we need is 1) that qemu_opts_append() function
so we can merge the protocol and drivers options in a single

Quoted 6 lines
Quoted 6 lines

QemuOptList

Quoted 5 lines
Quoted 5 lines

and
2) the default value support. All we need is already present in the QemuOpts APIs.

qemu_opt_*_del functions are needed. Each driver handles options

they

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

expected then
delete, left options passed to 2nd driver and let it handle. Like

qcow2

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

create, first, qcow2
driver handle, then raw driver handle.

Not true, the only place you need to allocate QemuOpts or QemuOptsList

is

Quoted 6 lines
Quoted 5 lines

on qemu-img.c and block.c, if they're doing so they should free it, not the lower lavels. The block drivers should just use it, unless they do allocate anything themselves.

The reason qemu_opt_get_*_del functions should be used in backend

drivers,

Quoted 10 lines

is to
keep same behavior as how previous QEMUOptionParameter handles. At least, in one
case: create a qcow2 img. "size" option is handled by qcow2 driver, then delete; in 2nd raw
driver, there is no "size" option any more, it will create a 0 size file. If qemu_opt_get but
not delete, then all options will be passed to 2nd raw driver, it will create a full sized file.
That is not expected.

Quoted 1 line

I couldn't find the described use case -

In block drivers that calls bdrv_create_file in its bdrv_create (like:
qcow.c qcow2.c vhdx.c vpc.c, etc), current code, will see, it get options from QEMUOptionParameter one by one with options++, after that passes 'options' to bdrv_create_file (at this time, 'options' actually points to left options
that's not be handled yet).

Quoted 8 lines

I still think you don't need to
unset it, but if that's the case what about using for example:

uint64_t sectos = qemu_opt_get_size(options, BLOCK_OPT_SIZE) / 512; ret = qemu_opt_unset(options, BLOCK_OPT_SIZE);

You don't need to introduce a new API for this.

OK. I checked and it seems only those call bdrv_create_file or bdrv_create() in
their .bdrv_create functions should take care. Currently, only need to take care of
options that's parsed in raw-posix.c: raw_create(). That is, currently, only BLOCK_OPT_SIZE should be taken care. Base on this, we can unset after parsing
BLOCK_OPT_SIZE as you point in related drivers.

I'll adjust the patches for this, after feedback of other patches and after there is a
consensus about in which way doing patches:
a. keep changes simple in 'natural way' (allowing break between patch) or
b. keep current way (make each patch build and work successfully)

Regards,
Chunyan

Quoted 56 lines

Regards..

--
Leandro Dorileo

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

But as you point, some changes are not required for this job, I've

omitted

Quoted 2 lines

in my new patch
series, like: qemu_opt_set, NULL check in qemu_opt_get and

qemu_opt_find,

Quoted 11 lines
Quoted 11 lines
Quoted 3 lines

assert()
update in qemu_opt_get.

Ok.

--
Leandro Dorileo

Quoted 2 lines
Quoted 2 lines

With that simpler approach in mind I ended up putting my hands in

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

source code
trying to see how feasible it is, and turns out I came up with a

full

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

solution. I'm
sending the job's resulting series to the mailing list so I can

show

Quoted 3 lines
Quoted 3 lines

you

Quoted 2 lines
Quoted 2 lines

what
I mean and have some more room for discussion. It doesn't mean I

want

Quoted 17 lines
Quoted 17 lines

to

Quoted 14 lines
Quoted 3 lines

overlap
you work, I just needed to have a little more input on that.

No matter. I'm OK to follow a more acceptable way :)

Quoted 7 lines

Regards....

--
Leandro Dorileo

#102 lore raw

2014-03-25 15:15 GMT+08:00 Chunyan Liu <[email protected]>:

Quoted 157 lines

2014-03-24 23:00 GMT+08:00 Leandro Dorileo <[email protected]>:

Hi Chunyan,

Quoted 141 lines · Chunyan Liu
Quoted 9 lines

2014-03-21 20:31 GMT+08:00 Leandro Dorileo <[email protected]>:

Quoted 7 lines · Chunyan Liu
Quoted 6 lines

2014-03-21 8:07 GMT+08:00 Leandro Dorileo <[email protected]>:

Quoted 4 lines

Hi Chunyan,

Quoted 1 line · Chunyan Liu

This patch series is to replace QEMUOptionParameter with

QemuOpts, so

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

that only

Quoted 2 lines

one Qemu Option structure is kept in QEMU code.

Last night I took some time do take a deeper look at you series

and the

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

required
effort to do the QemuOptionParameter -> QemuOpts migration.

I think you've over complicated the things, I understand you

tried to

Quoted 3 lines
Quoted 3 lines

keep

Quoted 2 lines
Quoted 2 lines

your
serie's bisectability (?), but the final result was something

really

Quoted 5 lines
Quoted 5 lines

hard

Quoted 4 lines
Quoted 4 lines

to
review and to integrate as well. The overall approach wasn't even resolving the
bisectability problem since it breaks the tree until the last

commit.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Moreover,
in the path of getting things ready you created new problems and

their

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

respective
fixes, what we really don't need to.

In this regards you could have kept things as simple as possible

and

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

submitted
the patches in a "natural way", even if they were breaking the

build

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

between each
patch, you could get all the required maintainer's Reviewed-by +

Tested-by

Quoted 2 lines
Quoted 2 lines

+
Signed-off-by and so on for each individual patch and when it was

time

Quoted 5 lines
Quoted 5 lines

to

Quoted 4 lines
Quoted 2 lines

integrate get squashed the needed patches.

Well, if breaking the build could be allowed between each patch,

then it

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

could be
much cleaner. Indeed there are lots of code just for build and

function

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

unbroken
between each patch. I'm inclined to listen to more voice. If all

agree to

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

this method,
it's OK to me.

The thing is the balance between complexity and the change size. Do we really
want to avoid a small patch - doing all the change - and increase the

whole

Quoted 7 lines
Quoted 7 lines

thing complexity? I don't see a great benefit on that :)

Quoted 4 lines
Quoted 4 lines

I mean, add N patches introducing new required QemuOpts API's, 1

patch

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

migrating
the block upper layer (block.c, block.h, etc), one patch for each

block

Quoted 11 lines
Quoted 11 lines
Quoted 2 lines
Quoted 2 lines

driver
(i.e ssh.c, qcow.c, qcow2.c, etc), one patch for qemu-img.c and

finally a

Quoted 2 lines
Quoted 2 lines

last
patch removing the QEMUOptionParamer itself. When time comes to

integrate

Quoted 2 lines
Quoted 2 lines

your
series the patches changing the block layer + patches changing the

block

Quoted 2 lines
Quoted 2 lines

drivers +
patches changing qemu-img.c could be squashed adding all the

collected

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

Reviewed-by
to this single squashed patch.

As I said, last night I took a deeper look at the problem and,

understood

Quoted 2 lines
Quoted 2 lines

most
of changes weren't required to do the job. We don't need an

adaptation

Quoted 10 lines
Quoted 10 lines
Quoted 2 lines
Quoted 2 lines

layer between
QemuOptionParameter and QemuOpts, we don't need to add new opts

accessors

Quoted 4 lines
Quoted 4 lines

(like
those qemu_opt_*_del() functions), all we need is 1) that qemu_opts_append() function
so we can merge the protocol and drivers options in a single

QemuOptList

Quoted 2 lines
Quoted 2 lines

and
2) the default value support. All we need is already present in

the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

QemuOpts APIs.

qemu_opt_*_del functions are needed. Each driver handles options

they

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

expected then
delete, left options passed to 2nd driver and let it handle. Like

qcow2

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

create, first, qcow2
driver handle, then raw driver handle.

Not true, the only place you need to allocate QemuOpts or

QemuOptsList is

Quoted 1 line
Quoted 1 line

on qemu-img.c and block.c, if they're doing so they should free it,

not

Quoted 5 lines
Quoted 4 lines

the lower lavels. The block drivers should just use it, unless they do allocate anything themselves.

The reason qemu_opt_get_*_del functions should be used in backend

drivers,

Quoted 2 lines

is to
keep same behavior as how previous QEMUOptionParameter handles. At

least,

Quoted 4 lines

in one
case: create a qcow2 img. "size" option is handled by qcow2 driver, then delete; in 2nd raw
driver, there is no "size" option any more, it will create a 0 size

Quoted 8 lines

file.

Quoted 4 lines

If qemu_opt_get but
not delete, then all options will be passed to 2nd raw driver, it will create a full sized file.
That is not expected.

I couldn't find the described use case -

Quoted 8 lines

In block drivers that calls bdrv_create_file in its bdrv_create (like:
qcow.c qcow2.c vhdx.c vpc.c, etc), current code, will see, it get options from QEMUOptionParameter one by one with options++, after that passes 'options' to bdrv_create_file (at this time, 'options' actually points to left options
that's not be handled yet).

Hi, Leandro,

I found some comment very long before:
http://lists.gnu.org/archive/html/qemu-devel/2013-01/msg02446.html
I think maybe keep qemu_opt_get_del is better than optionally doing qemu_opt_unset.
Using qemu_opt_get_del will keep same logic with previous options++, we don't need
to take care which option should be unset, which need effort to know who will use it later
and easy to cause problem.

So I'll still keep qemu_opt_get_del in next version. Will post soon.

Regards,
Chunyan

Quoted 87 lines

I still think you don't need to

Quoted 7 lines

unset it, but if that's the case what about using for example:

uint64_t sectos = qemu_opt_get_size(options, BLOCK_OPT_SIZE) / 512; ret = qemu_opt_unset(options, BLOCK_OPT_SIZE);

You don't need to introduce a new API for this.

OK. I checked and it seems only those call bdrv_create_file or bdrv_create() in
their .bdrv_create functions should take care. Currently, only need to take care of
options that's parsed in raw-posix.c: raw_create(). That is, currently, only
BLOCK_OPT_SIZE should be taken care. Base on this, we can unset after parsing
BLOCK_OPT_SIZE as you point in related drivers.

I'll adjust the patches for this, after feedback of other patches and after there is a
consensus about in which way doing patches:
a. keep changes simple in 'natural way' (allowing break between patch) or
b. keep current way (make each patch build and work successfully)

Regards,
Chunyan

Quoted 56 lines

Regards..

--
Leandro Dorileo

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

But as you point, some changes are not required for this job, I've

omitted

Quoted 2 lines

in my new patch
series, like: qemu_opt_set, NULL check in qemu_opt_get and

qemu_opt_find,

Quoted 11 lines
Quoted 11 lines
Quoted 3 lines

assert()
update in qemu_opt_get.

Ok.

--
Leandro Dorileo

Quoted 2 lines
Quoted 2 lines

With that simpler approach in mind I ended up putting my hands in

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

source code
trying to see how feasible it is, and turns out I came up with a

full

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

solution. I'm
sending the job's resulting series to the mailing list so I can

show

Quoted 3 lines
Quoted 3 lines

you

Quoted 2 lines
Quoted 2 lines

what
I mean and have some more room for discussion. It doesn't mean I

want

Quoted 17 lines
Quoted 17 lines

to

Quoted 14 lines
Quoted 3 lines

overlap
you work, I just needed to have a little more input on that.

No matter. I'm OK to follow a more acceptable way :)

Quoted 7 lines

Regards....

--
Leandro Dorileo

#103 lore raw
In reply to Leandro Dorileo

Am 21.03.2014 um 01:07 hat Leandro Dorileo geschrieben:

Quoted 18 lines

Hi Chunyan,

Quoted 3 lines · Chunyan Liu

This patch series is to replace QEMUOptionParameter with QemuOpts, so that only one Qemu Option structure is kept in QEMU code.

Last night I took some time do take a deeper look at you series and the required effort to do the QemuOptionParameter -> QemuOpts migration.

I think you've over complicated the things, I understand you tried to keep your serie's bisectability (?), but the final result was something really hard to review and to integrate as well. The overall approach wasn't even resolving the bisectability problem since it breaks the tree until the last commit. Moreover, in the path of getting things ready you created new problems and their respective fixes, what we really don't need to.

Quoted 5 lines

In this regards you could have kept things as simple as possible and submitted the patches in a "natural way", even if they were breaking the build between each patch, you could get all the required maintainer's Reviewed-by + Tested-by + Signed-off-by and so on for each individual patch and when it was time to integrate get squashed the needed patches.

No, please not. If you have bisectability on the surface, but the bisect ends in a monster patch with several thousand lines of code, nothing is won.

Kevin

#104 lore raw

Hi Kevin,

Quoted 25 lines · Kevin Wolf

Am 21.03.2014 um 01:07 hat Leandro Dorileo geschrieben:

Quoted 18 lines

Hi Chunyan,

Quoted 3 lines · Chunyan Liu

This patch series is to replace QEMUOptionParameter with QemuOpts, so that only one Qemu Option structure is kept in QEMU code.

Last night I took some time do take a deeper look at you series and the required effort to do the QemuOptionParameter -> QemuOpts migration.

I think you've over complicated the things, I understand you tried to keep your serie's bisectability (?), but the final result was something really hard to review and to integrate as well. The overall approach wasn't even resolving the bisectability problem since it breaks the tree until the last commit. Moreover, in the path of getting things ready you created new problems and their respective fixes, what we really don't need to.

Quoted 5 lines

In this regards you could have kept things as simple as possible and submitted the patches in a "natural way", even if they were breaking the build between each patch, you could get all the required maintainer's Reviewed-by + Tested-by + Signed-off-by and so on for each individual patch and when it was time to integrate get squashed the needed patches.

Quoted 3 lines

No, please not. If you have bisectability on the surface, but the bisect ends in a monster patch with several thousand lines of code, nothing is won.

I don't think that is the case (several thousand lines), with the experiment I did the "squashable" patches are 769 insertions(+), 1076 deletions(-), of course, the patch series is bigger than that - not that bigger, but bigger - but I'm mentioning only the patches I think need to be squashed.

These patches represent the changes across the block layer. I see no gain on increasing the patches complexity just to avoid a patch with that statistic. More over, the changes are very simple and easily reviewable.

Regards...

Signature · 1 line
Leandro Dorileo