qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: qemu-devel@nongnu.org
Cc: Eric Auger <eric.auger@redhat.com>,
	Markus Armbruster <armbru@redhat.com>
Subject: [Qemu-devel] [PULL 09/19] vfio: Pass an error object to vfio_get_group
Date: Mon, 17 Oct 2016 13:53:04 -0600	[thread overview]
Message-ID: <20161017195302.17307.20082.stgit@gimli.home> (raw)
In-Reply-To: <20161017194945.17307.78340.stgit@gimli.home>

From: Eric Auger <eric.auger@redhat.com>

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>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 hw/vfio/common.c              |   24 ++++++++++++------------
 hw/vfio/pci.c                 |    3 +--
 hw/vfio/platform.c            |   11 ++++++++---
 include/hw/vfio/vfio-common.h |    2 +-
 4 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 85a7759..90b1ebb 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -1123,12 +1123,11 @@ 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];
     struct vfio_group_status status = { .argsz = sizeof(status) };
-    Error *err = NULL;
 
     QLIST_FOREACH(group, &vfio_group_list, next) {
         if (group->groupid == groupid) {
@@ -1136,8 +1135,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;
             }
         }
@@ -1148,28 +1147,29 @@ 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;
     }
 
     group->groupid = groupid;
     QLIST_INIT(&group->device_list);
 
-    if (vfio_connect_container(group, as, &err)) {
-        error_reportf_err(err, "vfio: failed to setup container for group %d",
-                          groupid);
+    if (vfio_connect_container(group, as, errp)) {
+        error_prepend(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 3d84126..fdb0616 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);

  parent reply	other threads:[~2016-10-17 19:53 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-17 19:51 [Qemu-devel] [PULL 00/19] VFIO updates 2016-10-17 Alex Williamson
2016-10-17 19:51 ` [Qemu-devel] [PULL 01/19] vfio/pci: Use local error object in vfio_initfn Alex Williamson
2016-10-17 19:52 ` [Qemu-devel] [PULL 02/19] vfio/pci: Pass an error object to vfio_populate_vga Alex Williamson
2016-10-17 19:52 ` [Qemu-devel] [PULL 03/19] vfio/pci: Pass an error object to vfio_populate_device Alex Williamson
2016-10-17 19:52 ` [Qemu-devel] [PULL 04/19] vfio/pci: Pass an error object to vfio_msix_early_setup Alex Williamson
2016-10-17 19:52 ` [Qemu-devel] [PULL 05/19] vfio/pci: Pass an error object to vfio_intx_enable Alex Williamson
2016-10-17 19:52 ` [Qemu-devel] [PULL 06/19] vfio/pci: Pass an error object to vfio_add_capabilities Alex Williamson
2016-10-17 19:52 ` [Qemu-devel] [PULL 07/19] vfio/pci: Pass an error object to vfio_pci_igd_opregion_init Alex Williamson
2016-10-17 19:52 ` [Qemu-devel] [PULL 08/19] vfio: Pass an Error object to vfio_connect_container Alex Williamson
2016-10-17 19:53 ` Alex Williamson [this message]
2016-10-17 19:53 ` [Qemu-devel] [PULL 10/19] vfio: Pass an error object to vfio_get_device Alex Williamson
2016-10-17 19:53 ` [Qemu-devel] [PULL 11/19] vfio/platform: Pass an error object to vfio_populate_device Alex Williamson
2016-10-17 19:53 ` [Qemu-devel] [PULL 12/19] vfio/platform: fix a wrong returned value in vfio_populate_device Alex Williamson
2016-10-17 19:53 ` [Qemu-devel] [PULL 13/19] vfio/platform: Pass an error object to vfio_base_device_init Alex Williamson
2016-10-17 19:53 ` [Qemu-devel] [PULL 14/19] vfio/pci: Conversion to realize Alex Williamson
2016-10-17 19:53 ` [Qemu-devel] [PULL 15/19] vfio/pci: Remove vfio_msix_early_setup returned value Alex Williamson
2016-10-17 19:54 ` [Qemu-devel] [PULL 16/19] vfio/pci: Remove vfio_populate_device " Alex Williamson
2016-10-17 19:54 ` [Qemu-devel] [PULL 17/19] vfio/pci: Handle host oversight Alex Williamson
2016-10-17 19:54 ` [Qemu-devel] [PULL 18/19] vfio/pci: Fix vfio_rtl8168_quirk_data_read address offset Alex Williamson
2016-10-17 19:54 ` [Qemu-devel] [PULL 19/19] vfio: fix duplicate function call Alex Williamson
2016-10-18 11:34 ` [Qemu-devel] [PULL 00/19] VFIO updates 2016-10-17 Peter Maydell

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=20161017195302.17307.20082.stgit@gimli.home \
    --to=alex.williamson@redhat.com \
    --cc=armbru@redhat.com \
    --cc=eric.auger@redhat.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).