From: Auger Eric <eric.auger@redhat.com>
To: eric.auger.pro@gmail.com, qemu-devel@nongnu.org,
alex.williamson@redhat.com, armbru@redhat.com
Subject: Re: [Qemu-devel] [PATCH v3 08/16] vfio: Pass an error object to vfio_get_group
Date: Mon, 3 Oct 2016 09:55:52 +0200 [thread overview]
Message-ID: <7706860d-96a4-04b4-b4d5-952b1328534e@redhat.com> (raw)
In-Reply-To: <1475441414-3118-9-git-send-email-eric.auger@redhat.com>
Hi,
On 02/10/2016 22:50, Eric Auger wrote:
> Pass an error object to prepare for migration to VFIO-PCI realize.
>
> For the time being let's just simply report the error in
> vfio platform's vfio_base_device_init(). A subsequent patch will
> duly propagate the error up to vfio_platform_realize.
>
> Signed-off-by: Eric Auger <eric.auger@redhat.com>
>
> ---
>
> v2 -> v3:
> - In the commit message, add a comment about not propagating the
> vfio_get_group in vfio_base_device_init
>
> v2: creation
> ---
> hw/vfio/common.c | 20 +++++++++++---------
> hw/vfio/pci.c | 3 +--
> hw/vfio/platform.c | 11 ++++++++---
> include/hw/vfio/vfio-common.h | 2 +-
> 4 files changed, 21 insertions(+), 15 deletions(-)
>
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index 29188a1..0d33b56 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -34,6 +34,7 @@
> #include "qemu/range.h"
> #include "sysemu/kvm.h"
> #include "trace.h"
> +#include "qapi/error.h"
>
> struct vfio_group_head vfio_group_list =
> QLIST_HEAD_INITIALIZER(vfio_group_list);
> @@ -1115,7 +1116,7 @@ static void vfio_disconnect_container(VFIOGroup *group)
> }
> }
>
> -VFIOGroup *vfio_get_group(int groupid, AddressSpace *as)
> +VFIOGroup *vfio_get_group(int groupid, AddressSpace *as, Error **errp)
> {
> VFIOGroup *group;
> char path[32];
> @@ -1127,8 +1128,8 @@ VFIOGroup *vfio_get_group(int groupid, AddressSpace *as)
> if (group->container->space->as == as) {
> return group;
> } else {
> - error_report("vfio: group %d used in multiple address spaces",
> - group->groupid);
> + error_setg(errp, "group %d used in multiple address spaces",
> + group->groupid);
> return NULL;
> }
> }
> @@ -1139,19 +1140,20 @@ VFIOGroup *vfio_get_group(int groupid, AddressSpace *as)
> snprintf(path, sizeof(path), "/dev/vfio/%d", groupid);
> group->fd = qemu_open(path, O_RDWR);
> if (group->fd < 0) {
> - error_report("vfio: error opening %s: %m", path);
> + error_setg_errno(errp, errno, "failed to open %s", path);
> goto free_group_exit;
> }
>
> if (ioctl(group->fd, VFIO_GROUP_GET_STATUS, &status)) {
> - error_report("vfio: error getting group status: %m");
> + error_setg_errno(errp, errno, "failed to get group %d status", groupid);
> goto close_fd_exit;
> }
>
> if (!(status.flags & VFIO_GROUP_FLAGS_VIABLE)) {
> - error_report("vfio: error, group %d is not viable, please ensure "
> - "all devices within the iommu_group are bound to their "
> - "vfio bus driver.", groupid);
> + error_setg(errp, "group %d is not viable", groupid);
> + error_append_hint(errp,
> + "Please ensure all devices within the iommu_group "
> + "are bound to their vfio bus driver.\n");
> goto close_fd_exit;
> }
>
> @@ -1159,7 +1161,7 @@ VFIOGroup *vfio_get_group(int groupid, AddressSpace *as)
> QLIST_INIT(&group->device_list);
>
> if (vfio_connect_container(group, as)) {
Looking at vfio_connect_container() there are plenty of error_report
that deserve to be converted too. Won another respin anyway.
Thanks
Eric
> - error_report("vfio: failed to setup container for group %d", groupid);
> + error_setg(errp, "failed to setup container for group %d", groupid);
> goto close_fd_exit;
> }
>
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index 3757bc3..910c371 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -2563,9 +2563,8 @@ static int vfio_initfn(PCIDevice *pdev)
>
> trace_vfio_initfn(vdev->vbasedev.name, groupid);
>
> - group = vfio_get_group(groupid, pci_device_iommu_address_space(pdev));
> + group = vfio_get_group(groupid, pci_device_iommu_address_space(pdev), &err);
> if (!group) {
> - error_setg(&err, "failed to get group %d", groupid);
> ret = -ENOENT;
> goto error;
> }
> diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
> index a559e7b..7bf525b 100644
> --- a/hw/vfio/platform.c
> +++ b/hw/vfio/platform.c
> @@ -552,6 +552,7 @@ static int vfio_base_device_init(VFIODevice *vbasedev)
> ssize_t len;
> struct stat st;
> int groupid;
> + Error *err = NULL;
> int ret;
>
> /* @sysfsdev takes precedence over @host */
> @@ -592,10 +593,10 @@ static int vfio_base_device_init(VFIODevice *vbasedev)
>
> trace_vfio_platform_base_device_init(vbasedev->name, groupid);
>
> - group = vfio_get_group(groupid, &address_space_memory);
> + group = vfio_get_group(groupid, &address_space_memory, &err);
> if (!group) {
> - error_report("vfio: failed to get group %d", groupid);
> - return -ENOENT;
> + ret = -ENOENT;
> + goto error;
> }
>
> QLIST_FOREACH(vbasedev_iter, &group->device_list, next) {
> @@ -619,6 +620,10 @@ static int vfio_base_device_init(VFIODevice *vbasedev)
> vfio_put_group(group);
> }
>
> +error:
> + if (err) {
> + error_reportf_err(err, ERR_PREFIX, vbasedev->name);
> + }
> return ret;
> }
>
> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> index b26b6cf..286fa31 100644
> --- a/include/hw/vfio/vfio-common.h
> +++ b/include/hw/vfio/vfio-common.h
> @@ -155,7 +155,7 @@ void vfio_region_mmaps_set_enabled(VFIORegion *region, bool enabled);
> void vfio_region_exit(VFIORegion *region);
> void vfio_region_finalize(VFIORegion *region);
> void vfio_reset_handler(void *opaque);
> -VFIOGroup *vfio_get_group(int groupid, AddressSpace *as);
> +VFIOGroup *vfio_get_group(int groupid, AddressSpace *as, Error **errp);
> void vfio_put_group(VFIOGroup *group);
> int vfio_get_device(VFIOGroup *group, const char *name,
> VFIODevice *vbasedev);
>
next prev parent reply other threads:[~2016-10-03 7:56 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-02 20:49 [Qemu-devel] [PATCH v3 00/16] Convert VFIO-PCI to realize Eric Auger
2016-10-02 20:49 ` [Qemu-devel] [PATCH v3 01/16] vfio/pci: Use local error object in vfio_initfn Eric Auger
2016-10-02 20:50 ` [Qemu-devel] [PATCH v3 02/16] vfio/pci: Pass an error object to vfio_populate_vga Eric Auger
2016-10-02 20:50 ` [Qemu-devel] [PATCH v3 03/16] vfio/pci: Pass an error object to vfio_populate_device Eric Auger
2016-10-02 20:50 ` [Qemu-devel] [PATCH v3 04/16] vfio/pci: Pass an error object to vfio_msix_early_setup Eric Auger
2016-10-02 20:50 ` [Qemu-devel] [PATCH v3 05/16] vfio/pci: Pass an error object to vfio_intx_enable Eric Auger
2016-10-02 20:50 ` [Qemu-devel] [PATCH v3 06/16] vfio/pci: Pass an error object to vfio_add_capabilities Eric Auger
2016-10-02 20:50 ` [Qemu-devel] [PATCH v3 07/16] vfio/pci: Pass an error object to vfio_pci_igd_opregion_init Eric Auger
2016-10-02 20:50 ` [Qemu-devel] [PATCH v3 08/16] vfio: Pass an error object to vfio_get_group Eric Auger
2016-10-03 7:55 ` Auger Eric [this message]
2016-10-02 20:50 ` [Qemu-devel] [PATCH v3 09/16] vfio: Pass an error object to vfio_get_device Eric Auger
2016-10-02 20:50 ` [Qemu-devel] [PATCH v3 10/16] vfio/platform: Pass an error object to vfio_populate_device Eric Auger
2016-10-02 20:50 ` [Qemu-devel] [PATCH v3 11/16] vfio/platform: fix a wrong returned value in vfio_populate_device Eric Auger
2016-10-02 20:50 ` [Qemu-devel] [PATCH v3 12/16] vfio/platform: Pass an error object to vfio_base_device_init Eric Auger
2016-10-02 20:50 ` [Qemu-devel] [PATCH v3 13/16] vfio/pci: Conversion to realize Eric Auger
2016-10-02 20:50 ` [Qemu-devel] [PATCH v3 14/16] vfio/pci: Remove vfio_msix_early_setup returned value Eric Auger
2016-10-02 20:50 ` [Qemu-devel] [PATCH v3 15/16] vfio/pci: Remove vfio_populate_device " Eric Auger
2016-10-02 20:50 ` [Qemu-devel] [PATCH v3 16/16] vfio/pci: Handle host oversight Eric Auger
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=7706860d-96a4-04b4-b4d5-952b1328534e@redhat.com \
--to=eric.auger@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=armbru@redhat.com \
--cc=eric.auger.pro@gmail.com \
--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).