From patchwork Thu Oct 6 16:07:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 678989 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sqdDW1wlBz9s5w for ; Fri, 7 Oct 2016 03:20:43 +1100 (AEDT) Received: from localhost ([::1]:57722 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsBPU-0003AX-0T for incoming@patchwork.ozlabs.org; Thu, 06 Oct 2016 12:20:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51490) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsBDB-0000MS-W6 for qemu-devel@nongnu.org; Thu, 06 Oct 2016 12:08:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bsBD7-00074M-KD for qemu-devel@nongnu.org; Thu, 06 Oct 2016 12:07:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36448) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsBD7-000744-A7 for qemu-devel@nongnu.org; Thu, 06 Oct 2016 12:07:53 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D6AFEC9B2D; Thu, 6 Oct 2016 16:07:52 +0000 (UTC) Received: from localhost.redhat.com (vpn1-4-62.ams2.redhat.com [10.36.4.62]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u96G7iwS018457; Thu, 6 Oct 2016 12:07:51 -0400 From: Eric Auger To: eric.auger@redhat.com, eric.auger.pro@gmail.com, qemu-devel@nongnu.org, alex.williamson@redhat.com, armbru@redhat.com Date: Thu, 6 Oct 2016 16:07:24 +0000 Message-Id: <1475770058-20409-4-git-send-email-eric.auger@redhat.com> In-Reply-To: <1475770058-20409-1-git-send-email-eric.auger@redhat.com> References: <1475770058-20409-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 06 Oct 2016 16:07:52 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 03/17] vfio/pci: Pass an error object to vfio_populate_device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Pass an error object to prepare for migration to VFIO-PCI realize. The returned value will be removed later on. The case where error recovery cannot be enabled is not converted into an error object but directly reported through error_report, as before. Populating an error instead would cause the future realize function to fail, which is not wanted. Signed-off-by: Eric Auger Reviewed-by: Markus Armbruster --- v4 -> v5: - test ret instead of err to avoid subsequent revert v2 -> v3: - propagate the error from vfio_populate_vga v1 -> v2: - this patch now comes before the actual realize migration - do not handle the error recovery issue as an error --- hw/vfio/pci.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 9645a77..46e3cb8 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2202,28 +2202,27 @@ int vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp) return 0; } -static int vfio_populate_device(VFIOPCIDevice *vdev) +static int vfio_populate_device(VFIOPCIDevice *vdev, Error **errp) { VFIODevice *vbasedev = &vdev->vbasedev; struct vfio_region_info *reg_info; struct vfio_irq_info irq_info = { .argsz = sizeof(irq_info) }; int i, ret = -1; - Error *err = NULL; /* Sanity check device */ if (!(vbasedev->flags & VFIO_DEVICE_FLAGS_PCI)) { - error_report("vfio: Um, this isn't a PCI device"); + error_setg(errp, "this isn't a PCI device"); goto error; } if (vbasedev->num_regions < VFIO_PCI_CONFIG_REGION_INDEX + 1) { - error_report("vfio: unexpected number of io regions %u", - vbasedev->num_regions); + error_setg(errp, "unexpected number of io regions %u", + vbasedev->num_regions); goto error; } if (vbasedev->num_irqs < VFIO_PCI_MSIX_IRQ_INDEX + 1) { - error_report("vfio: unexpected number of irqs %u", vbasedev->num_irqs); + error_setg(errp, "unexpected number of irqs %u", vbasedev->num_irqs); goto error; } @@ -2235,7 +2234,7 @@ static int vfio_populate_device(VFIOPCIDevice *vdev) g_free(name); if (ret) { - error_report("vfio: Error getting region %d info: %m", i); + error_setg_errno(errp, -ret, "failed to get region %d info", i); goto error; } @@ -2245,7 +2244,7 @@ static int vfio_populate_device(VFIOPCIDevice *vdev) ret = vfio_get_region_info(vbasedev, VFIO_PCI_CONFIG_REGION_INDEX, ®_info); if (ret) { - error_report("vfio: Error getting config info: %m"); + error_setg_errno(errp, -ret, "failed to get config info"); goto error; } @@ -2263,11 +2262,10 @@ static int vfio_populate_device(VFIOPCIDevice *vdev) g_free(reg_info); if (vdev->features & VFIO_FEATURE_ENABLE_VGA) { - ret = vfio_populate_vga(vdev, &err); + ret = vfio_populate_vga(vdev, errp); if (ret) { - error_append_hint(&err, "device does not support " + error_append_hint(errp, "device does not support " "requested feature x-vga\n"); - error_reportf_err(err, ERR_PREFIX, vdev->vbasedev.name); goto error; } } @@ -2282,7 +2280,7 @@ static int vfio_populate_device(VFIOPCIDevice *vdev) } else if (irq_info.count == 1) { vdev->pci_aer = true; } else { - error_report("vfio: %s " + error_report(WARN_PREFIX "Could not enable error recovery for the device", vbasedev->name); } @@ -2565,9 +2563,9 @@ static int vfio_initfn(PCIDevice *pdev) goto error; } - ret = vfio_populate_device(vdev); + ret = vfio_populate_device(vdev, &err); if (ret) { - return ret; + goto error; } /* Get a copy of config space */