From: Eric Blake <eblake@redhat.com>
To: Cao jin <caoj.fnst@cn.fujitsu.com>, qemu-devel@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>, stefano.stabellini@eu.citrix.com
Subject: Re: [Qemu-devel] [PATCH v4 2/5] Add Error **errp for xen_host_pci_device_get()
Date: Fri, 8 Jan 2016 15:50:28 -0700 [thread overview]
Message-ID: <56903D34.2020204@redhat.com> (raw)
In-Reply-To: <1452242274-8345-3-git-send-email-caoj.fnst@cn.fujitsu.com>
[-- Attachment #1: Type: text/plain, Size: 4844 bytes --]
On 01/08/2016 01:37 AM, Cao jin wrote:
> To catch the error msg. Also modify the caller
>
> Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
> ---
> hw/xen/xen-host-pci-device.c | 134 ++++++++++++++++++++++---------------------
> hw/xen/xen-host-pci-device.h | 5 +-
> hw/xen/xen_pt.c | 13 +++--
> 3 files changed, 81 insertions(+), 71 deletions(-)
>
> @@ -40,16 +40,16 @@ static int xen_host_pci_sysfs_path(const XenHostPCIDevice *d,
> d->domain, d->bus, d->dev, d->func, name);
>
> if (rc >= size || rc < 0) {
> - /* The output is truncated, or some other error was encountered */
> - return -ENODEV;
> + /* The output is truncated, or some other error was encountered.
> + * Assert here since user can do nothing in case of failure */
> + assert(0);
> }
Might be shorter to drop the 'if' block, and just write:
assert(rc >= 0 && rc < size);
where you then don't need a comment, because the body of the assert() is
then more specific on the caller's responsibility for passing in a
decent size argument.
> buf[rc] = 0;
> rc = qemu_strtoul(buf, &endptr, base, &value);
Do you still need a local 'value' variable, or can you just reuse pvalue
here?
> if (!rc) {
> *pvalue = value;
> + } else if (rc == -EINVAL) {
> + error_setg(errp, "strtoul: Invalid argument");
> + } else {
> + error_setg_errno(errp, errno, "strtoul err");
Still not quite right - you are not guaranteed that 'errno' is sane
after qemu_strtoul(), only that -rc is sane. And feels repetitive.
Better might be:
rc = qemu_strtoul(buf, &endptr, base, pvalue);
if (rc) {
error_setg_errno(errp, -rc, "failed to parse value '%s'", buf);
}
> -static inline int xen_host_pci_get_hex_value(XenHostPCIDevice *d,
> +static inline void xen_host_pci_get_hex_value(XenHostPCIDevice *d,
> const char *name,
> - unsigned int *pvalue)
> + unsigned int *pvalue,
> + Error **errp)
Indentation is off.
> {
> - return xen_host_pci_get_value(d, name, pvalue, 16);
> + xen_host_pci_get_value(d, name, pvalue, 16, errp);
> }
>
> -static inline int xen_host_pci_get_dec_value(XenHostPCIDevice *d,
> +static inline void xen_host_pci_get_dec_value(XenHostPCIDevice *d,
> const char *name,
> - unsigned int *pvalue)
> + unsigned int *pvalue,
> + Error **errp)
and again.
> -int xen_host_pci_device_get(XenHostPCIDevice *d, uint16_t domain,
> - uint8_t bus, uint8_t dev, uint8_t func)
> +void xen_host_pci_device_get(XenHostPCIDevice *d, uint16_t domain,
> + uint8_t bus, uint8_t dev, uint8_t func,
> + Error **errp)
and again.
> +++ b/hw/xen/xen-host-pci-device.h
> @@ -36,8 +36,9 @@ typedef struct XenHostPCIDevice {
> int config_fd;
> } XenHostPCIDevice;
>
> -int xen_host_pci_device_get(XenHostPCIDevice *d, uint16_t domain,
> - uint8_t bus, uint8_t dev, uint8_t func);
> +void xen_host_pci_device_get(XenHostPCIDevice *d, uint16_t domain,
> + uint8_t bus, uint8_t dev, uint8_t func,
> + Error **errp);
and again
> @@ -774,11 +775,13 @@ static int xen_pt_initfn(PCIDevice *d)
> s->hostaddr.bus, s->hostaddr.slot, s->hostaddr.function,
> s->dev.devfn);
>
> - rc = xen_host_pci_device_get(&s->real_device,
> - s->hostaddr.domain, s->hostaddr.bus,
> - s->hostaddr.slot, s->hostaddr.function);
> - if (rc) {
> - XEN_PT_ERR(d, "Failed to \"open\" the real pci device. rc: %i\n", rc);
> + xen_host_pci_device_get(&s->real_device,
> + s->hostaddr.domain, s->hostaddr.bus,
> + s->hostaddr.slot, s->hostaddr.function,
> + &err);
> + if (err) {
> + error_append_hint(&err, "Failed to \"open\" the real pci device");
Markus may have an opinion on whether his new error_prepend code is a
better fit (error_append_hint lists _after_ the original failure, but it
sounds like you want "failed to open the real pci device: low level
details").
But looks like you're getting closer.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2016-01-08 22:50 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-08 8:37 [Qemu-devel] [PATCH v4 0/5] Xen PCI passthru: Convert to realize() Cao jin
2016-01-08 8:37 ` [Qemu-devel] [PATCH v4 1/5] Use qemu_strtoul instead of strtol Cao jin
2016-01-08 17:35 ` Eric Blake
2016-01-09 9:42 ` Cao jin
2016-01-08 8:37 ` [Qemu-devel] [PATCH v4 2/5] Add Error **errp for xen_host_pci_device_get() Cao jin
2016-01-08 22:50 ` Eric Blake [this message]
2016-01-09 10:49 ` Cao jin
2016-01-09 11:20 ` Cao jin
2016-01-08 8:37 ` [Qemu-devel] [PATCH v4 3/5] Add Error **errp for xen_pt_setup_vga() Cao jin
2016-01-08 8:37 ` [Qemu-devel] [PATCH v4 4/5] Add Error **errp for xen_pt_config_init() Cao jin
2016-01-08 8:37 ` [Qemu-devel] [PATCH v4 5/5] Xen PCI passthru: convert to realize() Cao jin
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=56903D34.2020204@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=caoj.fnst@cn.fujitsu.com \
--cc=qemu-devel@nongnu.org \
--cc=stefano.stabellini@eu.citrix.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.