From de5d27888950aaf0090d1be96a26c5cce5987dde Mon Sep 17 00:00:00 2001 From: Zhao Xinda Date: Tue, 18 Sep 2018 15:54:53 +0800 Subject: [PATCH] qemu/qmp: add vfio mediated device support on root bus In addition to supporting hotplug for VFIO mediated device on PCI bridge, this patch adds hotplug functionality on root bus. When parameter bus and addr are set to be empty, the system will pick up an empty slot on root bus. Signed-off-by: Zhao Xinda --- qemu/qmp.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/qemu/qmp.go b/qemu/qmp.go index e9fa65e52d..9f764f1236 100644 --- a/qemu/qmp.go +++ b/qemu/qmp.go @@ -937,20 +937,22 @@ func (q *QMP) ExecutePCIVFIODeviceAdd(ctx context.Context, devID, bdf, addr, bus } // ExecutePCIVFIOMediatedDeviceAdd adds a VFIO mediated device to a QEMU instance using the device_add command. -// This function can be used to hot plug VFIO mediated devices on PCI(E) bridges, unlike +// This function can be used to hot plug VFIO mediated devices on PCI(E) bridges or root bus, unlike // ExecuteVFIODeviceAdd this function receives the bus and the device address on its parent bus. -// bus is optional. devID is the id of the device to add. Must be valid QMP identifier. sysfsdev is the VFIO -// mediated device. +// devID is the id of the device to add. Must be valid QMP identifier. sysfsdev is the VFIO mediated device. +// Both bus and addr are optional. If they are both set to be empty, the system will pick up an empty slot on root bus. func (q *QMP) ExecutePCIVFIOMediatedDeviceAdd(ctx context.Context, devID, sysfsdev, addr, bus string) error { args := map[string]interface{}{ "id": devID, "driver": "vfio-pci", "sysfsdev": sysfsdev, - "addr": addr, } if bus != "" { args["bus"] = bus } + if addr != "" { + args["addr"] = addr + } return q.executeCommand(ctx, "device_add", args, nil) }