From: Markus Armbruster <armbru@redhat.com>
To: Eric Auger <eric.auger@redhat.com>
Cc: eric.auger.pro@gmail.com, qemu-devel@nongnu.org,
alex.williamson@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 01/12] vfio/pci: Use local error object in vfio_initfn
Date: Thu, 22 Sep 2016 17:42:19 +0200 [thread overview]
Message-ID: <87into54bo.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <1474404352-28958-2-git-send-email-eric.auger@redhat.com> (Eric Auger's message of "Tue, 20 Sep 2016 20:45:41 +0000")
Eric Auger <eric.auger@redhat.com> writes:
> 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 <eric.auger@redhat.com>
> ---
>
> v2: creation
> ---
> hw/vfio/pci.c | 73 +++++++++++++++++++++++++------------------
> include/hw/vfio/vfio-common.h | 3 ++
> 2 files changed, 46 insertions(+), 30 deletions(-)
>
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index a5a620a..ca0293d 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(&err, "no such host device");
Any particular reason you don't use error_setg_errno() here?
> + ret = -errno;
> + goto error;
> }
>
> vdev->vbasedev.name = g_strdup(basename(vdev->vbasedev.sysfsdev));
> @@ -2520,40 +2521,44 @@ 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;
> + error_setg_errno(&err, len < 0 ? errno : ENAMETOOLONG,
> + "no iommu_group found");
> + ret = len < 0 ? -errno : -ENAMETOOLONG;
Suggest
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 +2572,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 +2589,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 +2601,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 +2613,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 +2625,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 +2680,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 +2691,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 +2735,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;
> }
The value assigned to ret doesn't matter as long as it's negative, which
makes me wonder why we bother with different values here. Peeking
ahead, I see you simplify this already as part of your conversion to
realize(). Okay, that works for me.
>
> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> index 94dfae3..fd19880 100644
> --- a/include/hw/vfio/vfio-common.h
> +++ b/include/hw/vfio/vfio-common.h
> @@ -30,6 +30,9 @@
> #include <linux/vfio.h>
> #endif
>
> +#define ERR_PREFIX "vfio error: %s: "
> +#define WARN_PREFIX "vfio warning: %s: "
> +
> /*#define DEBUG_VFIO*/
> #ifdef DEBUG_VFIO
> #define DPRINTF(fmt, ...) \
We already discussed error message prefixes and errno strings. I got my
taste, you got yours. Since this is your code, yours wins :)
next prev parent reply other threads:[~2016-09-22 15:42 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-20 20:45 [Qemu-devel] [PATCH v2 00/12] Convert VFIO-PCI to realize Eric Auger
2016-09-20 20:45 ` [Qemu-devel] [PATCH v2 01/12] vfio/pci: Use local error object in vfio_initfn Eric Auger
2016-09-22 15:42 ` Markus Armbruster [this message]
2016-09-30 13:35 ` Auger Eric
2016-09-20 20:45 ` [Qemu-devel] [PATCH v2 02/12] vfio/pci: Pass an error object to vfio_populate_device Eric Auger
2016-09-22 15:49 ` Markus Armbruster
2016-09-30 13:34 ` Auger Eric
2016-09-20 20:45 ` [Qemu-devel] [PATCH v2 03/12] vfio/pci: Pass an error object to vfio_msix_early_setup Eric Auger
2016-09-20 20:45 ` [Qemu-devel] [PATCH v2 04/12] vfio/pci: Pass an error object to vfio_intx_enable Eric Auger
2016-09-22 16:27 ` Markus Armbruster
2016-09-30 13:33 ` Auger Eric
2016-09-20 20:45 ` [Qemu-devel] [PATCH v2 05/12] vfio/pci: Pass an error object to vfio_add_capabilities Eric Auger
2016-09-22 16:52 ` Markus Armbruster
2016-09-30 13:33 ` Auger Eric
2016-09-20 20:45 ` [Qemu-devel] [PATCH v2 06/12] vfio/pci: Pass an error object to vfio_pci_igd_opregion_init Eric Auger
2016-09-20 20:45 ` [Qemu-devel] [PATCH v2 07/12] vfio: Pass an error object to vfio_get_group Eric Auger
2016-09-22 17:01 ` Markus Armbruster
2016-09-30 13:34 ` Auger Eric
2016-09-20 20:45 ` [Qemu-devel] [PATCH v2 08/12] vfio: Pass an error object to vfio_get_device Eric Auger
2016-09-20 20:45 ` [Qemu-devel] [PATCH v2 09/12] vfio/pci: Conversion to realize Eric Auger
2016-09-22 17:24 ` Markus Armbruster
2016-09-30 13:34 ` Auger Eric
2016-09-20 20:45 ` [Qemu-devel] [PATCH v2 10/12] vfio/pci: Remove vfio_msix_early_setup returned value Eric Auger
2016-09-20 20:45 ` [Qemu-devel] [PATCH v2 11/12] vfio/pci: Remove vfio_populate_device " Eric Auger
2016-09-20 20:45 ` [Qemu-devel] [PATCH v2 12/12] vfio/pci: Handle host oversight Eric Auger
2016-09-22 17:26 ` [Qemu-devel] [PATCH v2 00/12] Convert VFIO-PCI to realize Markus Armbruster
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=87into54bo.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=eric.auger.pro@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.