Patchwork [V4,04/10] introduce qemu_opts_create_nofail function

login
register
mail settings
Submitter Robert Wang
Date Oct. 25, 2012, 12:57 p.m.
Message ID <1351169848-28223-5-git-send-email-wdongxu@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/194238/
State New
Headers show

Comments

Robert Wang - Oct. 25, 2012, 12:57 p.m.
While id is NULL, qemu_opts_create can not fail, so ignore
errors is fine.

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
---
 qemu-option.c |    5 +++++
 qemu-option.h |    1 +
 2 files changed, 6 insertions(+), 0 deletions(-)
Robert Wang - Oct. 26, 2012, 2:46 a.m.
On Thu, Oct 25, 2012 at 9:06 PM, Peter Maydell <peter.maydell@linaro.org> wrote:
> On 25 October 2012 13:57, Dong Xu Wang <wdongxu@linux.vnet.ibm.com> wrote:
>> While id is NULL, qemu_opts_create can not fail, so ignore
>> errors is fine.
>>
>> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
>> ---
>>  qemu-option.c |    5 +++++
>>  qemu-option.h |    1 +
>>  2 files changed, 6 insertions(+), 0 deletions(-)
>>
>> diff --git a/qemu-option.c b/qemu-option.c
>> index e0131ce..d7d5ea9 100644
>> --- a/qemu-option.c
>> +++ b/qemu-option.c
>> @@ -780,6 +780,11 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,
>>      return opts;
>>  }
>>
>> +QemuOpts *qemu_opts_create_nofail(QemuOptsList *list)
>> +{
>> +    return qemu_opts_create(list, NULL, 0, NULL);
>> +}
>
> _nofail versions of routines generally abort() if the function
> they are wrapping returns an error (compare qemu_ram_addr_from_host_nofail
> or qdev_init_nofail). This code just ignores the error. Although
> as you say at the moment there is nothing that sets an error
> in the id==NULL case this is somewhat vulnerable to future code
> changes in the function it calls.
>
> I think this would be better as:
>
> {
>     QemuOpts *opts;
>     Error *errp = NULL;
>     opts = qemu_opts_create(list, NULL, 0, &errp);
>     assert_no_error(errp);
>     return opts;
> }

Okay, will do that in next version, thank you Peter.
>
> -- PMM
>

Patch

diff --git a/qemu-option.c b/qemu-option.c
index e0131ce..d7d5ea9 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -780,6 +780,11 @@  QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,
     return opts;
 }
 
+QemuOpts *qemu_opts_create_nofail(QemuOptsList *list)
+{
+    return qemu_opts_create(list, NULL, 0, NULL);
+}
+
 void qemu_opts_reset(QemuOptsList *list)
 {
     QemuOpts *opts, *next_opts;
diff --git a/qemu-option.h b/qemu-option.h
index ca72986..b0f8d1e 100644
--- a/qemu-option.h
+++ b/qemu-option.h
@@ -133,6 +133,7 @@  int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
 QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id);
 QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,
                            int fail_if_exists, Error **errp);
+QemuOpts *qemu_opts_create_nofail(QemuOptsList *list);
 void qemu_opts_reset(QemuOptsList *list);
 void qemu_opts_loc_restore(QemuOpts *opts);
 int qemu_opts_set(QemuOptsList *list, const char *id,