virPCIDeviceListSteal;
virPCIDeviceListStealIndex;
virPCIDeviceNew;
+virPCIDeviceOpenVfioFd;
virPCIDeviceReattach;
virPCIDeviceRebind;
virPCIDeviceReset;
static int
qemuProcessOpenVfioDeviceFd(virDomainHostdevDef *hostdev)
{
- g_autofree char *vfioPath = NULL;
- int fd = -1;
-
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
return -1;
}
- if (virPCIDeviceGetVfioPath(&hostdev->source.subsys.u.pci.addr, &vfioPath) < 0)
- return -1;
-
- VIR_DEBUG("Opening VFIO device %s", vfioPath);
-
- if ((fd = open(vfioPath, O_RDWR | O_CLOEXEC)) < 0) {
- if (errno == ENOENT) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("VFIO device %1$s not found - ensure device is bound to vfio-pci driver"),
- vfioPath);
- } else {
- virReportSystemError(errno,
- _("cannot open VFIO device %1$s"), vfioPath);
- }
- return -1;
- }
-
- VIR_DEBUG("Opened VFIO device FD %d for %s", fd, vfioPath);
- return fd;
+ return virPCIDeviceOpenVfioFd(&hostdev->source.subsys.u.pci.addr);
}
/**
addrStr);
return -1;
}
+
+/**
+ * virPCIDeviceOpenVfioFd:
+ * @addr:
+ *
+ * Opens VFIO device and returns its FD.
+ *
+ * Returns: FD on success, -1 on failure
+ */
+int
+virPCIDeviceOpenVfioFd(virPCIDeviceAddress *addr)
+{
+ g_autofree char *vfioPath = NULL;
+ int fd = -1;
+
+ if (virPCIDeviceGetVfioPath(addr, &vfioPath) < 0)
+ return -1;
+
+ VIR_DEBUG("Opening VFIO device %s", vfioPath);
+
+ if ((fd = open(vfioPath, O_RDWR | O_CLOEXEC)) < 0) {
+ virReportSystemError(errno, _("cannot open VFIO device %1$s"), vfioPath);
+ return -1;
+ }
+
+ VIR_DEBUG("Opened VFIO device FD %d for %s", fd, vfioPath);
+ return fd;
+}
int virPCIDeviceGetVfioPath(virPCIDeviceAddress *addr, char **vfioPath);
+int virPCIDeviceOpenVfioFd(virPCIDeviceAddress *addr);
+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virPCIDevice, virPCIDeviceFree);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virPCIDeviceAddress, virPCIDeviceAddressFree);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virPCIEDeviceInfo, virPCIEDeviceInfoFree);