From patchwork Sun Oct 2 20:49:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 677540 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 3snHRX143fz9s5g for ; Mon, 3 Oct 2016 07:52:06 +1100 (AEDT) Received: from localhost ([::1]:60787 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqnjt-0000Jl-7b for incoming@patchwork.ozlabs.org; Sun, 02 Oct 2016 16:52:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37772) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqniM-0007V4-Ot for qemu-devel@nongnu.org; Sun, 02 Oct 2016 16:50:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bqniJ-0004Pl-IV for qemu-devel@nongnu.org; Sun, 02 Oct 2016 16:50:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50564) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqniJ-0004PB-8y for qemu-devel@nongnu.org; Sun, 02 Oct 2016 16:50:23 -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 A53FFC04B954; Sun, 2 Oct 2016 20:50:22 +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 u92KoHtc032661; Sun, 2 Oct 2016 16:50:20 -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:49:59 +0000 Message-Id: <1475441414-3118-2-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.31]); Sun, 02 Oct 2016 20:50:22 +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 01/16] vfio/pci: Use local error object in vfio_initfn 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" To prepare for migration to realize, let's use a local error object in vfio_initfn. Also let's use the same error prefix for all error messages. On top of the 1-1 conversion, we start using a common error prefix for all error messages. We also introduce a similar warning prefix which will be used later on. Signed-off-by: Eric Auger --- v2 -> v3: - use error_setg_errno on "no such host device" case - on "no iommu_group found", use previously computed ret value v2: creation --- hw/vfio/pci.c | 72 +++++++++++++++++++++++++------------------ include/hw/vfio/vfio-common.h | 3 ++ 2 files changed, 45 insertions(+), 30 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index a5a620a..417bf7f 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2493,6 +2493,7 @@ static int vfio_initfn(PCIDevice *pdev) VFIODevice *vbasedev_iter; VFIOGroup *group; char *tmp, group_path[PATH_MAX], *group_name; + Error *err = NULL; ssize_t len; struct stat st; int groupid; @@ -2506,9 +2507,9 @@ static int vfio_initfn(PCIDevice *pdev) } if (stat(vdev->vbasedev.sysfsdev, &st) < 0) { - error_report("vfio: error: no such host device: %s", - vdev->vbasedev.sysfsdev); - return -errno; + error_setg_errno(&err, errno, "no such host device"); + ret = -errno; + goto error; } vdev->vbasedev.name = g_strdup(basename(vdev->vbasedev.sysfsdev)); @@ -2520,40 +2521,43 @@ static int vfio_initfn(PCIDevice *pdev) g_free(tmp); if (len <= 0 || len >= sizeof(group_path)) { - error_report("vfio: error no iommu_group for device"); - return len < 0 ? -errno : -ENAMETOOLONG; + ret = len < 0 ? -errno : -ENAMETOOLONG; + error_setg_errno(&err, -ret, "no iommu_group found"); + goto error; } group_path[len] = 0; group_name = basename(group_path); if (sscanf(group_name, "%d", &groupid) != 1) { - error_report("vfio: error reading %s: %m", group_path); - return -errno; + error_setg_errno(&err, errno, "failed to read %s", group_path); + ret = -errno; + goto error; } trace_vfio_initfn(vdev->vbasedev.name, groupid); group = vfio_get_group(groupid, pci_device_iommu_address_space(pdev)); if (!group) { - error_report("vfio: failed to get group %d", groupid); - return -ENOENT; + error_setg(&err, "failed to get group %d", groupid); + ret = -ENOENT; + goto error; } QLIST_FOREACH(vbasedev_iter, &group->device_list, next) { if (strcmp(vbasedev_iter->name, vdev->vbasedev.name) == 0) { - error_report("vfio: error: device %s is already attached", - vdev->vbasedev.name); + error_setg(&err, "device is already attached"); vfio_put_group(group); - return -EBUSY; + ret = -EBUSY; + goto error; } } ret = vfio_get_device(group, vdev->vbasedev.name, &vdev->vbasedev); if (ret) { - error_report("vfio: failed to get device %s", vdev->vbasedev.name); + error_setg_errno(&err, -ret, "failed to get device"); vfio_put_group(group); - return ret; + goto error; } ret = vfio_populate_device(vdev); @@ -2567,8 +2571,8 @@ static int vfio_initfn(PCIDevice *pdev) vdev->config_offset); if (ret < (int)MIN(pci_config_size(&vdev->pdev), vdev->config_size)) { ret = ret < 0 ? -errno : -EFAULT; - error_report("vfio: Failed to read device config space"); - return ret; + error_setg_errno(&err, -ret, "failed to read device config space"); + goto error; } /* vfio emulates a lot for us, but some bits need extra love */ @@ -2584,8 +2588,9 @@ static int vfio_initfn(PCIDevice *pdev) */ if (vdev->vendor_id != PCI_ANY_ID) { if (vdev->vendor_id >= 0xffff) { - error_report("vfio: Invalid PCI vendor ID provided"); - return -EINVAL; + error_setg(&err, "invalid PCI vendor ID provided"); + ret = -EINVAL; + goto error; } vfio_add_emulated_word(vdev, PCI_VENDOR_ID, vdev->vendor_id, ~0); trace_vfio_pci_emulated_vendor_id(vdev->vbasedev.name, vdev->vendor_id); @@ -2595,8 +2600,9 @@ static int vfio_initfn(PCIDevice *pdev) if (vdev->device_id != PCI_ANY_ID) { if (vdev->device_id > 0xffff) { - error_report("vfio: Invalid PCI device ID provided"); - return -EINVAL; + error_setg(&err, "invalid PCI device ID provided"); + ret = -EINVAL; + goto error; } vfio_add_emulated_word(vdev, PCI_DEVICE_ID, vdev->device_id, ~0); trace_vfio_pci_emulated_device_id(vdev->vbasedev.name, vdev->device_id); @@ -2606,8 +2612,9 @@ static int vfio_initfn(PCIDevice *pdev) if (vdev->sub_vendor_id != PCI_ANY_ID) { if (vdev->sub_vendor_id > 0xffff) { - error_report("vfio: Invalid PCI subsystem vendor ID provided"); - return -EINVAL; + error_setg(&err, "invalid PCI subsystem vendor ID provided"); + ret = -EINVAL; + goto error; } vfio_add_emulated_word(vdev, PCI_SUBSYSTEM_VENDOR_ID, vdev->sub_vendor_id, ~0); @@ -2617,8 +2624,9 @@ static int vfio_initfn(PCIDevice *pdev) if (vdev->sub_device_id != PCI_ANY_ID) { if (vdev->sub_device_id > 0xffff) { - error_report("vfio: Invalid PCI subsystem device ID provided"); - return -EINVAL; + error_setg(&err, "invalid PCI subsystem device ID provided"); + ret = -EINVAL; + goto error; } vfio_add_emulated_word(vdev, PCI_SUBSYSTEM_ID, vdev->sub_device_id, ~0); trace_vfio_pci_emulated_sub_device_id(vdev->vbasedev.name, @@ -2671,8 +2679,9 @@ static int vfio_initfn(PCIDevice *pdev) struct vfio_region_info *opregion; if (vdev->pdev.qdev.hotplugged) { - error_report("Cannot support IGD OpRegion feature on hotplugged " - "device %s", vdev->vbasedev.name); + error_setg(&err, + "cannot support IGD OpRegion feature on hotplugged " + "device"); ret = -EINVAL; goto out_teardown; } @@ -2681,16 +2690,15 @@ static int vfio_initfn(PCIDevice *pdev) VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL, VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION, &opregion); if (ret) { - error_report("Device %s does not support requested IGD OpRegion " - "feature", vdev->vbasedev.name); + error_setg_errno(&err, -ret, + "does not support requested IGD OpRegion feature"); goto out_teardown; } ret = vfio_pci_igd_opregion_init(vdev, opregion); g_free(opregion); if (ret) { - error_report("Device %s IGD OpRegion initialization failed", - vdev->vbasedev.name); + error_setg_errno(&err, -ret, "IGD OpRegion initialization failed"); goto out_teardown; } } @@ -2726,6 +2734,10 @@ out_teardown: pci_device_set_intx_routing_notifier(&vdev->pdev, NULL); vfio_teardown_msi(vdev); vfio_bars_exit(vdev); +error: + if (err) { + error_reportf_err(err, ERR_PREFIX, vdev->vbasedev.name); + } return ret; } diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index c17602e..b26b6cf 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -30,6 +30,9 @@ #include #endif +#define ERR_PREFIX "vfio error: %s: " +#define WARN_PREFIX "vfio warning: %s: " + /*#define DEBUG_VFIO*/ #ifdef DEBUG_VFIO #define DPRINTF(fmt, ...) \