qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
To: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Cc: Kevin Wolf <kwolf@redhat.com>, Jeff Cody <jcody@redhat.com>,
	"qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	mreitz@redhat.com
Subject: Re: [Qemu-devel] [PATCH V8 3/8] util: add error_append()
Date: Mon, 06 Jan 2014 09:58:00 +0800	[thread overview]
Message-ID: <52CA0DA8.3030209@linux.vnet.ibm.com> (raw)
In-Reply-To: <CAEgOgz6vzb63fE=SoDjFNHWDieasZrNVBms9JtX+zoGxVy7cKQ@mail.gmail.com>

于 2014/1/3 23:32, Peter Crosthwaite 写道:
> On Fri, Jan 3, 2014 at 1:08 PM, Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>> Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
>> ---
>>   include/qapi/error.h |    6 ++++++
>>   util/error.c         |   21 +++++++++++++++++++++
>>   2 files changed, 27 insertions(+), 0 deletions(-)
>>
>> diff --git a/include/qapi/error.h b/include/qapi/error.h
>> index 7d4c696..bcfb724 100644
>> --- a/include/qapi/error.h
>> +++ b/include/qapi/error.h
>> @@ -30,6 +30,12 @@ typedef struct Error Error;
>>   void error_set(Error **err, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(3, 4);
>>
>>   /**
>> + * Append message to err if err != NULL && *err != NULL. "\n" will be inserted
>> + * after old message.
>> + */
>> +void error_append(Error **err, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
>> +
>> +/**
>>    * Set an indirect pointer to an error given a ErrorClass value and a
>>    * printf-style human message, followed by a strerror() string if
>>    * @os_error is not zero.
>> diff --git a/util/error.c b/util/error.c
>> index 3ee362a..64bbb2d 100644
>> --- a/util/error.c
>> +++ b/util/error.c
>> @@ -46,6 +46,27 @@ void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...)
>>       errno = saved_errno;
>>   }
>>
>> +void error_append(Error **err, const char *fmt, ...)
>
> errp
>
>> +{
>> +    va_list ap;
>> +    gchar *msg, *msg_old;
>> +
>> +    if (!err || !*err) {
>
> Should appending to an unset error really be a nop? You should just
> set the error as normal in this case (error_set()?).
>
> This avoids callers having to:
>
> if (error_is_set(&err)) {
>     error_append(&err);
> } else {
>     error_set(&err);
> }
>
> so they can just append if they want appending.
>
> Generally speaking, appending to nothing should give you something.
>
> Regards,
> Peter
>

   Make sense, will fix as above, thanks for review.

>> +        return;
>> +    }
>> +
>> +    va_start(ap, fmt);
>> +    msg = g_strdup_vprintf(fmt, ap);
>> +    va_end(ap);
>> +
>> +    msg_old = (*err)->msg;
>> +    (*err)->msg = g_strdup_printf("%s\n%s", msg_old, msg);
>> +
>> +    g_free(msg);
>> +    g_free(msg_old);
>> +
>> +}
>> +
>>   void error_set_errno(Error **errp, int os_errno, ErrorClass err_class,
>>                        const char *fmt, ...)
>>   {
>> --
>> 1.7.1
>>
>>
>

  reply	other threads:[~2014-01-06  1:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-03  3:08 [Qemu-devel] [PATCH V8 0/8] qcow2: rollback the modification on fail in snapshot creation Wenchao Xia
2014-01-03  3:08 ` [Qemu-devel] [PATCH V8 1/8] snapshot: add parameter *errp in snapshot create Wenchao Xia
2014-01-03  3:08 ` [Qemu-devel] [PATCH V8 2/8] qcow2: add error message in qcow2_write_snapshots() Wenchao Xia
2014-01-03  3:08 ` [Qemu-devel] [PATCH V8 3/8] util: add error_append() Wenchao Xia
2014-01-03 15:32   ` Peter Crosthwaite
2014-01-06  1:58     ` Wenchao Xia [this message]
2014-01-03  3:08 ` [Qemu-devel] [PATCH V8 4/8] qcow2: return int for qcow2_free_clusters() Wenchao Xia
2014-01-03  3:08 ` [Qemu-devel] [PATCH V8 5/8] qcow2: full rollback on fail in qcow2_write_snapshots() Wenchao Xia
2014-01-03  3:08 ` [Qemu-devel] [PATCH V8 6/8] qcow2: rollback on fail in qcow2_snapshot_create() Wenchao Xia
2014-01-03  3:08 ` [Qemu-devel] [PATCH V8 7/8] blkdebug: add debug events for snapshot Wenchao Xia
2014-01-03  3:08 ` [Qemu-devel] [PATCH V8 8/8] qemu-iotests: add test for qcow2 snapshot Wenchao Xia
2014-01-06  5:11 ` [Qemu-devel] [PATCH V8 0/8] qcow2: rollback the modification on fail in snapshot creation Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52CA0DA8.3030209@linux.vnet.ibm.com \
    --to=xiawenc@linux.vnet.ibm.com \
    --cc=jcody@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=peter.crosthwaite@xilinx.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).