vfio/pci: Use local error object in vfio_initfn
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> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
This commit is contained in:
parent
0975b8b823
commit
426ec9049e
@ -2493,6 +2493,7 @@ static int vfio_initfn(PCIDevice *pdev)
|
|||||||
VFIODevice *vbasedev_iter;
|
VFIODevice *vbasedev_iter;
|
||||||
VFIOGroup *group;
|
VFIOGroup *group;
|
||||||
char *tmp, group_path[PATH_MAX], *group_name;
|
char *tmp, group_path[PATH_MAX], *group_name;
|
||||||
|
Error *err = NULL;
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int groupid;
|
int groupid;
|
||||||
@ -2506,9 +2507,9 @@ static int vfio_initfn(PCIDevice *pdev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (stat(vdev->vbasedev.sysfsdev, &st) < 0) {
|
if (stat(vdev->vbasedev.sysfsdev, &st) < 0) {
|
||||||
error_report("vfio: error: no such host device: %s",
|
error_setg_errno(&err, errno, "no such host device");
|
||||||
vdev->vbasedev.sysfsdev);
|
ret = -errno;
|
||||||
return -errno;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
vdev->vbasedev.name = g_strdup(basename(vdev->vbasedev.sysfsdev));
|
vdev->vbasedev.name = g_strdup(basename(vdev->vbasedev.sysfsdev));
|
||||||
@ -2520,40 +2521,43 @@ static int vfio_initfn(PCIDevice *pdev)
|
|||||||
g_free(tmp);
|
g_free(tmp);
|
||||||
|
|
||||||
if (len <= 0 || len >= sizeof(group_path)) {
|
if (len <= 0 || len >= sizeof(group_path)) {
|
||||||
error_report("vfio: error no iommu_group for device");
|
ret = len < 0 ? -errno : -ENAMETOOLONG;
|
||||||
return len < 0 ? -errno : -ENAMETOOLONG;
|
error_setg_errno(&err, -ret, "no iommu_group found");
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
group_path[len] = 0;
|
group_path[len] = 0;
|
||||||
|
|
||||||
group_name = basename(group_path);
|
group_name = basename(group_path);
|
||||||
if (sscanf(group_name, "%d", &groupid) != 1) {
|
if (sscanf(group_name, "%d", &groupid) != 1) {
|
||||||
error_report("vfio: error reading %s: %m", group_path);
|
error_setg_errno(&err, errno, "failed to read %s", group_path);
|
||||||
return -errno;
|
ret = -errno;
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
trace_vfio_initfn(vdev->vbasedev.name, groupid);
|
trace_vfio_initfn(vdev->vbasedev.name, groupid);
|
||||||
|
|
||||||
group = vfio_get_group(groupid, pci_device_iommu_address_space(pdev));
|
group = vfio_get_group(groupid, pci_device_iommu_address_space(pdev));
|
||||||
if (!group) {
|
if (!group) {
|
||||||
error_report("vfio: failed to get group %d", groupid);
|
error_setg(&err, "failed to get group %d", groupid);
|
||||||
return -ENOENT;
|
ret = -ENOENT;
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLIST_FOREACH(vbasedev_iter, &group->device_list, next) {
|
QLIST_FOREACH(vbasedev_iter, &group->device_list, next) {
|
||||||
if (strcmp(vbasedev_iter->name, vdev->vbasedev.name) == 0) {
|
if (strcmp(vbasedev_iter->name, vdev->vbasedev.name) == 0) {
|
||||||
error_report("vfio: error: device %s is already attached",
|
error_setg(&err, "device is already attached");
|
||||||
vdev->vbasedev.name);
|
|
||||||
vfio_put_group(group);
|
vfio_put_group(group);
|
||||||
return -EBUSY;
|
ret = -EBUSY;
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = vfio_get_device(group, vdev->vbasedev.name, &vdev->vbasedev);
|
ret = vfio_get_device(group, vdev->vbasedev.name, &vdev->vbasedev);
|
||||||
if (ret) {
|
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);
|
vfio_put_group(group);
|
||||||
return ret;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = vfio_populate_device(vdev);
|
ret = vfio_populate_device(vdev);
|
||||||
@ -2567,8 +2571,8 @@ static int vfio_initfn(PCIDevice *pdev)
|
|||||||
vdev->config_offset);
|
vdev->config_offset);
|
||||||
if (ret < (int)MIN(pci_config_size(&vdev->pdev), vdev->config_size)) {
|
if (ret < (int)MIN(pci_config_size(&vdev->pdev), vdev->config_size)) {
|
||||||
ret = ret < 0 ? -errno : -EFAULT;
|
ret = ret < 0 ? -errno : -EFAULT;
|
||||||
error_report("vfio: Failed to read device config space");
|
error_setg_errno(&err, -ret, "failed to read device config space");
|
||||||
return ret;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vfio emulates a lot for us, but some bits need extra love */
|
/* 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 != PCI_ANY_ID) {
|
||||||
if (vdev->vendor_id >= 0xffff) {
|
if (vdev->vendor_id >= 0xffff) {
|
||||||
error_report("vfio: Invalid PCI vendor ID provided");
|
error_setg(&err, "invalid PCI vendor ID provided");
|
||||||
return -EINVAL;
|
ret = -EINVAL;
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
vfio_add_emulated_word(vdev, PCI_VENDOR_ID, vdev->vendor_id, ~0);
|
vfio_add_emulated_word(vdev, PCI_VENDOR_ID, vdev->vendor_id, ~0);
|
||||||
trace_vfio_pci_emulated_vendor_id(vdev->vbasedev.name, vdev->vendor_id);
|
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 != PCI_ANY_ID) {
|
||||||
if (vdev->device_id > 0xffff) {
|
if (vdev->device_id > 0xffff) {
|
||||||
error_report("vfio: Invalid PCI device ID provided");
|
error_setg(&err, "invalid PCI device ID provided");
|
||||||
return -EINVAL;
|
ret = -EINVAL;
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
vfio_add_emulated_word(vdev, PCI_DEVICE_ID, vdev->device_id, ~0);
|
vfio_add_emulated_word(vdev, PCI_DEVICE_ID, vdev->device_id, ~0);
|
||||||
trace_vfio_pci_emulated_device_id(vdev->vbasedev.name, vdev->device_id);
|
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 != PCI_ANY_ID) {
|
||||||
if (vdev->sub_vendor_id > 0xffff) {
|
if (vdev->sub_vendor_id > 0xffff) {
|
||||||
error_report("vfio: Invalid PCI subsystem vendor ID provided");
|
error_setg(&err, "invalid PCI subsystem vendor ID provided");
|
||||||
return -EINVAL;
|
ret = -EINVAL;
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
vfio_add_emulated_word(vdev, PCI_SUBSYSTEM_VENDOR_ID,
|
vfio_add_emulated_word(vdev, PCI_SUBSYSTEM_VENDOR_ID,
|
||||||
vdev->sub_vendor_id, ~0);
|
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 != PCI_ANY_ID) {
|
||||||
if (vdev->sub_device_id > 0xffff) {
|
if (vdev->sub_device_id > 0xffff) {
|
||||||
error_report("vfio: Invalid PCI subsystem device ID provided");
|
error_setg(&err, "invalid PCI subsystem device ID provided");
|
||||||
return -EINVAL;
|
ret = -EINVAL;
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
vfio_add_emulated_word(vdev, PCI_SUBSYSTEM_ID, vdev->sub_device_id, ~0);
|
vfio_add_emulated_word(vdev, PCI_SUBSYSTEM_ID, vdev->sub_device_id, ~0);
|
||||||
trace_vfio_pci_emulated_sub_device_id(vdev->vbasedev.name,
|
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;
|
struct vfio_region_info *opregion;
|
||||||
|
|
||||||
if (vdev->pdev.qdev.hotplugged) {
|
if (vdev->pdev.qdev.hotplugged) {
|
||||||
error_report("Cannot support IGD OpRegion feature on hotplugged "
|
error_setg(&err,
|
||||||
"device %s", vdev->vbasedev.name);
|
"cannot support IGD OpRegion feature on hotplugged "
|
||||||
|
"device");
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto out_teardown;
|
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_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL,
|
||||||
VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION, &opregion);
|
VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION, &opregion);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
error_report("Device %s does not support requested IGD OpRegion "
|
error_setg_errno(&err, -ret,
|
||||||
"feature", vdev->vbasedev.name);
|
"does not support requested IGD OpRegion feature");
|
||||||
goto out_teardown;
|
goto out_teardown;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = vfio_pci_igd_opregion_init(vdev, opregion);
|
ret = vfio_pci_igd_opregion_init(vdev, opregion);
|
||||||
g_free(opregion);
|
g_free(opregion);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
error_report("Device %s IGD OpRegion initialization failed",
|
error_setg_errno(&err, -ret, "IGD OpRegion initialization failed");
|
||||||
vdev->vbasedev.name);
|
|
||||||
goto out_teardown;
|
goto out_teardown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2726,6 +2734,10 @@ out_teardown:
|
|||||||
pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
|
pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
|
||||||
vfio_teardown_msi(vdev);
|
vfio_teardown_msi(vdev);
|
||||||
vfio_bars_exit(vdev);
|
vfio_bars_exit(vdev);
|
||||||
|
error:
|
||||||
|
if (err) {
|
||||||
|
error_reportf_err(err, ERR_PREFIX, vdev->vbasedev.name);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,9 @@
|
|||||||
#include <linux/vfio.h>
|
#include <linux/vfio.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define ERR_PREFIX "vfio error: %s: "
|
||||||
|
#define WARN_PREFIX "vfio warning: %s: "
|
||||||
|
|
||||||
/*#define DEBUG_VFIO*/
|
/*#define DEBUG_VFIO*/
|
||||||
#ifdef DEBUG_VFIO
|
#ifdef DEBUG_VFIO
|
||||||
#define DPRINTF(fmt, ...) \
|
#define DPRINTF(fmt, ...) \
|
||||||
|
Loading…
Reference in New Issue
Block a user