qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: John Snow <jsnow@redhat.com>,
	Mao Zhongyi <maozy.fnst@cn.fujitsu.com>,
	qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 1/6] hw/ide: Convert DeviceClass init to realize
Date: Fri, 15 Sep 2017 16:42:43 -0500	[thread overview]
Message-ID: <162e5e37-d90d-9f25-ed73-9a7e914324c0@redhat.com> (raw)
In-Reply-To: <3d9adc5b-0cc4-ed0a-521c-265d9e3e5cb4@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1695 bytes --]

On 09/15/2017 04:35 PM, John Snow wrote:
> 
> 
> On 08/04/2017 06:26 AM, Mao Zhongyi wrote:
>> Replace init with realize in IDEDeviceClass, which has errp
>> as a parameter. So all the implementations now use error_setg
>> instead of error_report for reporting error.
>>

>> @@ -2398,7 +2399,7 @@ int ide_init_drive(IDEState *s, BlockBackend *blk, IDEDriveKind kind,
>>                     const char *version, const char *serial, const char *model,
>>                     uint64_t wwn,
>>                     uint32_t cylinders, uint32_t heads, uint32_t secs,
>> -                   int chs_trans)
>> +                   int chs_trans, Error **errp)
> 
> this function now requires an additional invariant, which is that we
> must return -1 AND set errp. Probably wisest to just get rid of the
> return code so that we don't accidentally goof this up in the future.
> 
> I think Markus has had some guidance on this in the past, but admittedly
> I can't remember his preference.

Returning void requires callers to use boilerplate:

bar(..., Error **errp)
{
    Error *err = NULL;
    foo(..., &err);
    if (err) {
        error_propagate(errp, err);
        handle error ...;
        return;
    }
}

whereas keeping the invariant that a -1 return is synonymous with err
being set is simpler:

bar(..., Error **errp)
{
    if (foo(..., errp) < 0) {
        handle error ...;
        return;
    }
}

So these days, the preference is to KEEP the redundancy rather than
eliminate it, due to ease-of-use concerns.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]

  reply	other threads:[~2017-09-15 21:42 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-04 10:26 [Qemu-devel] [PATCH v2 0/6] Convert to realize and improve error handling Mao Zhongyi
2017-08-04 10:26 ` [Qemu-devel] [PATCH v2 1/6] hw/ide: Convert DeviceClass init to realize Mao Zhongyi
2017-09-15 21:35   ` John Snow
2017-09-15 21:42     ` Eric Blake [this message]
2017-09-15 21:46       ` John Snow
2017-09-15 22:03     ` [Qemu-devel] [Qemu-block] " John Snow
2017-09-18  1:37       ` Mao Zhongyi
2017-09-18  1:35     ` [Qemu-devel] " Mao Zhongyi
2017-08-04 10:26 ` [Qemu-devel] [PATCH v2 2/6] hw/block/fdc: Convert " Mao Zhongyi
2017-09-15 22:12   ` John Snow
2017-08-04 10:26 ` [Qemu-devel] [PATCH v2 3/6] hw/block/nvme: " Mao Zhongyi
2017-08-04 10:26 ` [Qemu-devel] [PATCH v2 4/6] hw/block: Fix the return type Mao Zhongyi
2017-08-04 12:53   ` Stefan Hajnoczi
2017-08-04 10:26 ` [Qemu-devel] [PATCH v2 5/6] hw/block: Use errp directly rather than local_err Mao Zhongyi
2017-08-04 12:53   ` Stefan Hajnoczi
2017-08-04 10:26 ` [Qemu-devel] [PATCH v2 6/6] dev-storage: Fix the unusual function name Mao Zhongyi
2017-08-04 16:26   ` Philippe Mathieu-Daudé

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=162e5e37-d90d-9f25-ed73-9a7e914324c0@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=maozy.fnst@cn.fujitsu.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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).