diff mbox

[v22,01/25] add def_value_str to QemuOptDesc

Message ID 1394436721-21812-2-git-send-email-cyliu@suse.com
State New
Headers show

Commit Message

Chunyan Liu March 10, 2014, 7:31 a.m. UTC
Add def_value_str (default value) to QemuOptDesc, to replace function of the
default value in QEMUOptionParameter. And improved related functions.

Signed-off-by: Dong Xu Wang <address@hidden>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 include/qemu/option.h |  3 ++-
 util/qemu-option.c    | 59 +++++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 52 insertions(+), 10 deletions(-)

Comments

Eric Blake March 10, 2014, 7:52 p.m. UTC | #1
On 03/10/2014 01:31 AM, Chunyan Liu wrote:
> Add def_value_str (default value) to QemuOptDesc, to replace function of the
> default value in QEMUOptionParameter. And improved related functions.
> 
> Signed-off-by: Dong Xu Wang <address@hidden>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  include/qemu/option.h |  3 ++-
>  util/qemu-option.c    | 59 +++++++++++++++++++++++++++++++++++++++++++--------
>  2 files changed, 52 insertions(+), 10 deletions(-)
> 

> +++ b/util/qemu-option.c
> @@ -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,

Reviewed-by: Eric Blake <eblake@redhat.com>
Stefan Hajnoczi March 11, 2014, 1:29 p.m. UTC | #2
On Mon, Mar 10, 2014 at 03:31:37PM +0800, Chunyan Liu wrote:
> Add def_value_str (default value) to QemuOptDesc, to replace function of the
> default value in QEMUOptionParameter. And improved related functions.
> 
> Signed-off-by: Dong Xu Wang <address@hidden>

The address should be <wdongxu@linux.vnet.ibm.com>.

Stefan
Chunyan Liu March 12, 2014, 2:45 a.m. UTC | #3
2014-03-11 21:29 GMT+08:00 Stefan Hajnoczi <stefanha@gmail.com>:

> On Mon, Mar 10, 2014 at 03:31:37PM +0800, Chunyan Liu wrote:
> > Add def_value_str (default value) to QemuOptDesc, to replace function of
> the
> > default value in QEMUOptionParameter. And improved related functions.
> >
> > Signed-off-by: Dong Xu Wang <address@hidden>
>
> The address should be <wdongxu@linux.vnet.ibm.com>.
>

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


> Stefan
>
>
Stefan Hajnoczi March 12, 2014, 8:27 a.m. UTC | #4
On Wed, Mar 12, 2014 at 10:45:57AM +0800, Chunyan Liu wrote:
> 2014-03-11 21:29 GMT+08:00 Stefan Hajnoczi <stefanha@gmail.com>:
> 
> > On Mon, Mar 10, 2014 at 03:31:37PM +0800, Chunyan Liu wrote:
> > > Add def_value_str (default value) to QemuOptDesc, to replace function of
> > the
> > > default value in QEMUOptionParameter. And improved related functions.
> > >
> > > Signed-off-by: Dong Xu Wang <address@hidden>
> >
> > The address should be <wdongxu@linux.vnet.ibm.com>.
> >
> 
> 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
wdongxu@linux.vnet.ibm.com.

Stefan
Chunyan Liu March 13, 2014, 2:46 a.m. UTC | #5
2014-03-12 16:27 GMT+08:00 Stefan Hajnoczi <stefanha@redhat.com>:

> On Wed, Mar 12, 2014 at 10:45:57AM +0800, Chunyan Liu wrote:
> > 2014-03-11 21:29 GMT+08:00 Stefan Hajnoczi <stefanha@gmail.com>:
> >
> > > On Mon, Mar 10, 2014 at 03:31:37PM +0800, Chunyan Liu wrote:
> > > > Add def_value_str (default value) to QemuOptDesc, to replace
> function of
> > > the
> > > > default value in QEMUOptionParameter. And improved related functions.
> > > >
> > > > Signed-off-by: Dong Xu Wang <address@hidden>
> > >
> > > The address should be <wdongxu@linux.vnet.ibm.com>.
> > >
> >
> > 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:
 wdongxu@linux.vnet.ibm.com


>
> 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
> wdongxu@linux.vnet.ibm.com.
>

OK.


>
> Stefan
>
>
Stefan Hajnoczi March 13, 2014, 12:13 p.m. UTC | #6
On Thu, Mar 13, 2014 at 10:46:45AM +0800, Chunyan Liu wrote:
> 2014-03-12 16:27 GMT+08:00 Stefan Hajnoczi <stefanha@redhat.com>:
> 
> > On Wed, Mar 12, 2014 at 10:45:57AM +0800, Chunyan Liu wrote:
> > > 2014-03-11 21:29 GMT+08:00 Stefan Hajnoczi <stefanha@gmail.com>:
> > >
> > > > On Mon, Mar 10, 2014 at 03:31:37PM +0800, Chunyan Liu wrote:
> > > > > Add def_value_str (default value) to QemuOptDesc, to replace
> > function of
> > > > the
> > > > > default value in QEMUOptionParameter. And improved related functions.
> > > > >
> > > > > Signed-off-by: Dong Xu Wang <address@hidden>
> > > >
> > > > The address should be <wdongxu@linux.vnet.ibm.com>.
> > > >
> > >
> > > 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:
>  wdongxu@linux.vnet.ibm.com

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
diff mbox

Patch

diff --git a/include/qemu/option.h b/include/qemu/option.h
index 8c0ac34..c3b0a91 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -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);
 
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 9d898af..65d1c22 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -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);
+
 /*
  * Extracts the name of an option from the parameter string (p points at the
  * first byte of the option name)
@@ -556,6 +559,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);
+
+    if (!opt) {
+        const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
+        if (desc && desc->def_value_str) {
+            return desc->def_value_str;
+        }
+    }
     return opt ? opt->str : NULL;
 }
 
@@ -575,8 +585,13 @@  bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
 {
     QemuOpt *opt = qemu_opt_find(opts, name);
 
-    if (opt == NULL)
+    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);
+        }
         return defval;
+    }
     assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL);
     return opt->value.boolean;
 }
@@ -585,8 +600,14 @@  uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
 {
     QemuOpt *opt = qemu_opt_find(opts, name);
 
-    if (opt == NULL)
+    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);
+        }
         return defval;
+    }
     assert(opt->desc && opt->desc->type == QEMU_OPT_NUMBER);
     return opt->value.uint;
 }
@@ -595,8 +616,13 @@  uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
 {
     QemuOpt *opt = qemu_opt_find(opts, name);
 
-    if (opt == NULL)
+    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);
+        }
         return defval;
+    }
     assert(opt->desc && opt->desc->type == QEMU_OPT_SIZE);
     return opt->value.uint;
 }
@@ -895,17 +921,32 @@  void qemu_opts_del(QemuOpts *opts)
     g_free(opts);
 }
 
-int qemu_opts_print(QemuOpts *opts, void *dummy)
+void qemu_opts_print(QemuOpts *opts)
 {
     QemuOpt *opt;
+    QemuOptDesc *desc = opts->list->desc;
 
-    fprintf(stderr, "%s: %s:", opts->list->name,
-            opts->id ? opts->id : "<noid>");
-    QTAILQ_FOREACH(opt, &opts->head, next) {
-        fprintf(stderr, " %s=\"%s\"", opt->name, opt->str);
+    if (desc[0].name == NULL) {
+        QTAILQ_FOREACH(opt, &opts->head, next) {
+            fprintf(stderr, "%s=\"%s\" ", opt->name, opt->str);
+        }
+        return;
+    }
+    for (; desc && desc->name; desc++) {
+        const char *value;
+        QemuOpt *opt = qemu_opt_find(opts, desc->name);
+
+        value = opt ? opt->str : desc->def_value_str;
+        if (!value) {
+            continue;
+        }
+        if (desc->type == QEMU_OPT_STRING) {
+            fprintf(stderr, "%s='%s' ", desc->name, value);
+        } else {
+            fprintf(stderr, "%s=%s ", desc->name, value);
+        }
     }
     fprintf(stderr, "\n");
-    return 0;
 }
 
 static int opts_do_parse(QemuOpts *opts, const char *params,