If --group is specified on the virsh nodedev-reattach commandline, the flag VIR_NODE_DEVICE_REATTACH_GROUP is used and the new virNodeDeviceReAttachFlags() API is called (instead of virNodeDeviceReAttach()). This causes the following change in behavior (only if the given device is currently attached to the vfio-pci driver): 1) If any device in the same iommu group as the given device is still in use by a domain, no reattachment of any device is performed (i.e. this device remains attached to vfio-pci), and an error is reported. 2) If none of the devices in the same iommu group as the given device are in use by a domain, then *all* devices that are currently attached to vfio-pci are re-attached to their respective host drivers (any devices that are currently attached to pci-stub or pcieport will remain attached to those drivers). --- tools/virsh-nodedev.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 39f74f2..8282129 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -677,6 +677,10 @@ static const vshCmdOptDef opts_node_device_reattach[] = { .flags = VSH_OFLAG_REQ, .help = N_("device key") }, + {.name = "group", + .type = VSH_OT_BOOL, + .help = N_("re-attach all devices in the same IOMMU group, but only if none are in use") + }, {.name = NULL} }; @@ -685,6 +689,7 @@ cmdNodeDeviceReAttach(vshControl *ctl, const vshCmd *cmd) { const char *name = NULL; virNodeDevicePtr device; + bool group = vshCommandOptBool(cmd, "group"); bool ret = true; if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0) @@ -695,7 +700,17 @@ cmdNodeDeviceReAttach(vshControl *ctl, const vshCmd *cmd) return false; } - if (virNodeDeviceReAttach(device) == 0) { + if (group) { + unsigned int flags = VIR_NODE_DEVICE_REATTACH_GROUP; + + if (virNodeDeviceReAttachFlags(device, flags) < 0) + ret = false; + } else { + if (virNodeDeviceReAttach(device) < 0) + ret = false; + } + + if (ret) { vshPrint(ctl, _("Device %s re-attached\n"), name); } else { vshError(ctl, _("Failed to re-attach device %s"), name); -- 1.7.11.7 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list