This provides a frontend for the virpci internal "detach_group" flag. When virNodeDeviceDetachFlags is given the flag VIR_NODE_DEVICE_DETACH_GROUP (and the specified driver is "vfio"), all devices in the same VFIO group with the specified device will be detached from the host and bound to the vfio-pci driver (unless they have already been bound to either the pci-stub driver or pcieport driver, both of which are acceptable substitutes in the eyes of VFIO). --- include/libvirt/libvirt.h.in | 10 ++++++++++ src/qemu/qemu_driver.c | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index acf3218..ba471b2 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -3291,6 +3291,16 @@ char * virNodeDeviceGetXMLDesc (virNodeDevicePtr dev, int virNodeDeviceRef (virNodeDevicePtr dev); int virNodeDeviceFree (virNodeDevicePtr dev); +/* + * virNodeDeviceDetachFlags: + * + * Flags that can be sent to the virNodeDeviceDetachFlags() API. + * + */ +typedef enum { + VIR_NODE_DEVICE_DETACH_GROUP = 1 << 0, /* detach all devices in same group */ +} virNodeDeviceDetachFlagsType; + int virNodeDeviceDettach (virNodeDevicePtr dev); int virNodeDeviceDetachFlags(virNodeDevicePtr dev, const char *driverName, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8f498e6..dc6f2cd 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -10275,7 +10275,7 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, unsigned domain, bus, slot, function; int ret = -1; - virCheckFlags(0, -1); + virCheckFlags(VIR_NODE_DEVICE_DETACH_GROUP, -1); if (qemuNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function) < 0) return -1; @@ -10285,9 +10285,12 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, return -1; if (!driverName || STREQ(driverName, "kvm")) { + virCheckFlags(0, -1); if (virPCIDeviceSetStubDriver(pci, "pci-stub") < 0) goto out; } else if (STREQ(driverName, "vfio")) { + virPCIDeviceSetAttachGroup(pci, + !!(flags & VIR_NODE_DEVICE_DETACH_GROUP)); if (virPCIDeviceSetStubDriver(pci, "vfio-pci") < 0) goto out; } else { -- 1.7.11.7 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list