From 0286ff9e6eaabe9294d697c0cd45ce69d1f2928d Mon Sep 17 00:00:00 2001 From: Ruidong Cao Date: Tue, 21 Aug 2018 18:48:42 +0800 Subject: [PATCH] qemu/qmp: support hotplug a nic whose qdisc is mq If we hotplug a nic with args mq=on, its qdisc will be mq by default. This aligns with cold plug nics. Signed-off-by: Ruidong Cao --- qemu/qmp.go | 15 ++++++++++++++- qemu/qmp_test.go | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/qemu/qmp.go b/qemu/qmp.go index 92000fe03f..08c9de11ae 100644 --- a/qemu/qmp.go +++ b/qemu/qmp.go @@ -793,7 +793,8 @@ func (q *QMP) ExecuteNetdevDel(ctx context.Context, netdevID string) error { // ExecuteNetPCIDeviceAdd adds a Net PCI device to a QEMU instance // using the device_add command. devID is the id of the device to add. // Must be valid QMP identifier. netdevID is the id of nic added by previous netdev_add. -func (q *QMP) ExecuteNetPCIDeviceAdd(ctx context.Context, netdevID, devID, macAddr, addr, bus string) error { +// queues is the number of queues of a nic. +func (q *QMP) ExecuteNetPCIDeviceAdd(ctx context.Context, netdevID, devID, macAddr, addr, bus string, queues int) error { args := map[string]interface{}{ "id": devID, "driver": VirtioNetPCI, @@ -805,6 +806,18 @@ func (q *QMP) ExecuteNetPCIDeviceAdd(ctx context.Context, netdevID, devID, macAd if bus != "" { args["bus"] = bus } + + if queues > 0 { + // (2N+2 vectors, N for tx queues, N for rx queues, 1 for config, and one for possible control vq) + // -device virtio-net-pci,mq=on,vectors=2N+2... + // enable mq in guest by 'ethtool -L eth0 combined $queue_num' + // Clearlinux automatically sets up the queues properly + // The agent implementation should do this to ensure that it is + // always set + args["mq"] = "on" + args["vectors"] = 2*queues + 2 + } + return q.executeCommand(ctx, "device_add", args, nil) } diff --git a/qemu/qmp_test.go b/qemu/qmp_test.go index 7a59edc6fa..2d1da0a092 100644 --- a/qemu/qmp_test.go +++ b/qemu/qmp_test.go @@ -439,7 +439,7 @@ func TestQMPNetPCIDeviceAdd(t *testing.T) { cfg := QMPConfig{Logger: qmpTestLogger{}} q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh) checkVersion(t, connectedCh) - err := q.ExecuteNetPCIDeviceAdd(context.Background(), "br0", "virtio-0", "02:42:ac:11:00:02", "0x7", "") + err := q.ExecuteNetPCIDeviceAdd(context.Background(), "br0", "virtio-0", "02:42:ac:11:00:02", "0x7", "", 8) if err != nil { t.Fatalf("Unexpected error %v", err) }