diff --git a/qemu/qmp.go b/qemu/qmp.go index 1e2542fb6d..bada7bc4e5 100644 --- a/qemu/qmp.go +++ b/qemu/qmp.go @@ -25,6 +25,7 @@ import ( "io" "net" "os" + "strconv" "syscall" "time" @@ -1058,12 +1059,12 @@ func (q *QMP) ExecuteDeviceDel(ctx context.Context, devID string) error { // ExecutePCIDeviceAdd is the PCI version of ExecuteDeviceAdd. This function can be used // to hot plug PCI devices on PCI(E) bridges, unlike ExecuteDeviceAdd this function receive the -// device address on its parent bus. bus is optional. shared denotes if the drive can be shared -// allowing it to be passed more than once. +// device address on its parent bus. bus is optional. queues specifies the number of queues of +// a block device. shared denotes if the drive can be shared allowing it to be passed more than once. // disableModern indicates if virtio version 1.0 should be replaced by the // former version 0.9, as there is a KVM bug that occurs when using virtio // 1.0 in nested environments. -func (q *QMP) ExecutePCIDeviceAdd(ctx context.Context, blockdevID, devID, driver, addr, bus, romfile string, shared, disableModern bool) error { +func (q *QMP) ExecutePCIDeviceAdd(ctx context.Context, blockdevID, devID, driver, addr, bus, romfile string, queues int, shared, disableModern bool) error { args := map[string]interface{}{ "id": devID, "driver": driver, @@ -1076,6 +1077,9 @@ func (q *QMP) ExecutePCIDeviceAdd(ctx context.Context, blockdevID, devID, driver if shared && (q.version.Major > 2 || (q.version.Major == 2 && q.version.Minor >= 10)) { args["share-rw"] = "on" } + if queues > 0 { + args["num-queues"] = strconv.Itoa(queues) + } if isVirtioPCI[DeviceDriver(driver)] { args["romfile"] = romfile diff --git a/qemu/qmp_test.go b/qemu/qmp_test.go index 61710669f8..5b11e94f64 100644 --- a/qemu/qmp_test.go +++ b/qemu/qmp_test.go @@ -1025,7 +1025,7 @@ func TestQMPPCIDeviceAdd(t *testing.T) { blockdevID := fmt.Sprintf("drive_%s", volumeUUID) devID := fmt.Sprintf("device_%s", volumeUUID) err := q.ExecutePCIDeviceAdd(context.Background(), blockdevID, devID, - "virtio-blk-pci", "0x1", "", "", true, false) + "virtio-blk-pci", "0x1", "", "", 1, true, false) if err != nil { t.Fatalf("Unexpected error %v", err) }