From patchwork Sun Oct 2 20:50:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 9359753 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BC14560459 for ; Sun, 2 Oct 2016 20:55:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB3AB28968 for ; Sun, 2 Oct 2016 20:55:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E34628979; Sun, 2 Oct 2016 20:55:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3C69028968 for ; Sun, 2 Oct 2016 20:55:51 +0000 (UTC) Received: from localhost ([::1]:60805 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqnna-0002wJ-9n for patchwork-qemu-devel@patchwork.kernel.org; Sun, 02 Oct 2016 16:55:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37804) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqniQ-0007VF-1h for qemu-devel@nongnu.org; Sun, 02 Oct 2016 16:50:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bqniN-0004Ry-Px for qemu-devel@nongnu.org; Sun, 02 Oct 2016 16:50:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58538) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqniN-0004Re-GK for qemu-devel@nongnu.org; Sun, 02 Oct 2016 16:50:27 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 00B0C9D0F4; Sun, 2 Oct 2016 20:50:27 +0000 (UTC) Received: from localhost.redhat.com (vpn1-6-108.ams2.redhat.com [10.36.6.108]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u92KoHte032661; Sun, 2 Oct 2016 16:50:25 -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: Sun, 2 Oct 2016 20:50:01 +0000 Message-Id: <1475441414-3118-4-git-send-email-eric.auger@redhat.com> In-Reply-To: <1475441414-3118-1-git-send-email-eric.auger@redhat.com> References: <1475441414-3118-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sun, 02 Oct 2016 20:50:27 +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 v3 03/16] 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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index db08dd3..8f825bd 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 " - "requested feature x-vga"); - error_reportf_err(err, ERR_PREFIX, vdev->vbasedev.name); + error_append_hint(errp, "device does not support " + "requested feature x-vga\n"); 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); - if (ret) { - return ret; + ret = vfio_populate_device(vdev, &err); + if (err) { + goto error; } /* Get a copy of config space */