mirror of
				https://github.com/kata-containers/kata-containers.git
				synced 2025-10-31 17:37:20 +00:00 
			
		
		
		
	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 <caoruidong@huawei.com>
This commit is contained in:
		
							
								
								
									
										15
									
								
								qemu/qmp.go
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								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) | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -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) | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user