From patchwork Thu Oct 6 16:07:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 9365147 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 9B2ED607D3 for ; Thu, 6 Oct 2016 16:38:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C162291AB for ; Thu, 6 Oct 2016 16:38:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7ED56291AD; Thu, 6 Oct 2016 16:38:53 +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 A79B8291AB for ; Thu, 6 Oct 2016 16:38:52 +0000 (UTC) Received: from localhost ([::1]:57874 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsBh4-00020U-KJ for patchwork-qemu-devel@patchwork.kernel.org; Thu, 06 Oct 2016 12:38:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51838) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsBDX-0000lQ-Uc for qemu-devel@nongnu.org; Thu, 06 Oct 2016 12:08:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bsBDQ-0007PN-KR for qemu-devel@nongnu.org; Thu, 06 Oct 2016 12:08:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44122) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsBDQ-0007Os-At for qemu-devel@nongnu.org; Thu, 06 Oct 2016 12:08:12 -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 E767932DD84; Thu, 6 Oct 2016 16:08:11 +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 u96G7iwc018457; Thu, 6 Oct 2016 12:08:10 -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:34 +0000 Message-Id: <1475770058-20409-14-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.29]); Thu, 06 Oct 2016 16:08:11 +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 13/17] vfio/platform: Pass an error object to vfio_base_device_init 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch propagates errors encountered during vfio_base_device_init up to the realize function. In case the host value is not set or badly formed we now report an error. Signed-off-by: Eric Auger Reviewed-by: Markus Armbruster --- v4 -> v5: - mention error returned on badly formed host value - rework error message on stat failure v3: creation --- hw/vfio/platform.c | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index 484e31f..a4663c9 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -541,13 +541,14 @@ static VFIODeviceOps vfio_platform_ops = { /** * vfio_base_device_init - perform preliminary VFIO setup * @vbasedev: the VFIO device handle + * @errp: error object * * Implement the VFIO command sequence that allows to discover * assigned device resources: group extraction, device * fd retrieval, resource query. * Precondition: the device name must be initialized */ -static int vfio_base_device_init(VFIODevice *vbasedev) +static int vfio_base_device_init(VFIODevice *vbasedev, Error **errp) { VFIOGroup *group; VFIODevice *vbasedev_iter; @@ -555,7 +556,6 @@ 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 */ @@ -564,6 +564,7 @@ static int vfio_base_device_init(VFIODevice *vbasedev) vbasedev->name = g_strdup(basename(vbasedev->sysfsdev)); } else { if (!vbasedev->name || strchr(vbasedev->name, '/')) { + error_setg(errp, "wrong host device name"); return -EINVAL; } @@ -572,8 +573,8 @@ static int vfio_base_device_init(VFIODevice *vbasedev) } if (stat(vbasedev->sysfsdev, &st) < 0) { - error_report("vfio: error: no such host device: %s", - vbasedev->sysfsdev); + error_setg_errno(errp, errno, + "failed to get the sysfs host device file status"); return -errno; } @@ -582,49 +583,44 @@ static int vfio_base_device_init(VFIODevice *vbasedev) 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(errp, -ret, "no iommu_group found"); + return ret; } 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); + error_setg_errno(errp, errno, "failed to read %s", group_path); return -errno; } trace_vfio_platform_base_device_init(vbasedev->name, groupid); - group = vfio_get_group(groupid, &address_space_memory, &err); + group = vfio_get_group(groupid, &address_space_memory, errp); if (!group) { - ret = -ENOENT; - goto error; + return -ENOENT; } QLIST_FOREACH(vbasedev_iter, &group->device_list, next) { if (strcmp(vbasedev_iter->name, vbasedev->name) == 0) { - error_report("vfio: error: device %s is already attached", - vbasedev->name); + error_setg(errp, "device is already attached"); vfio_put_group(group); return -EBUSY; } } - ret = vfio_get_device(group, vbasedev->name, vbasedev, &err); + ret = vfio_get_device(group, vbasedev->name, vbasedev, errp); if (ret) { vfio_put_group(group); - goto error; + return ret; } - ret = vfio_populate_device(vbasedev, &err); + ret = vfio_populate_device(vbasedev, errp); if (ret) { vfio_put_group(group); } -error: - if (err) { - error_reportf_err(err, ERR_PREFIX, vbasedev->name); - } return ret; } @@ -650,11 +646,9 @@ static void vfio_platform_realize(DeviceState *dev, Error **errp) vbasedev->sysfsdev : vbasedev->name, vdev->compat); - ret = vfio_base_device_init(vbasedev); + ret = vfio_base_device_init(vbasedev, errp); if (ret) { - error_setg(errp, "vfio: vfio_base_device_init failed for %s", - vbasedev->name); - return; + goto out; } for (i = 0; i < vbasedev->num_regions; i++) { @@ -664,6 +658,16 @@ static void vfio_platform_realize(DeviceState *dev, Error **errp) } sysbus_init_mmio(sbdev, vdev->regions[i]->mem); } +out: + if (!ret) { + return; + } + + if (vdev->vbasedev.name) { + error_prepend(errp, ERR_PREFIX, vdev->vbasedev.name); + } else { + error_prepend(errp, "vfio error: "); + } } static const VMStateDescription vfio_platform_vmstate = {