mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-28 19:54:35 +00:00
qemu/qmp: nic can works without vhost
If host doesn't support vhost_net, we won't pass vhost="on" in QMP. Signed-off-by: Ruidong Cao <caoruidong@huawei.com>
This commit is contained in:
parent
25277d52ad
commit
1a1fee75e5
@ -812,13 +812,15 @@ func (q *QMP) ExecuteNetdevChardevAdd(ctx context.Context, netdevType, netdevID,
|
||||
// Must be valid QMP identifier.
|
||||
func (q *QMP) ExecuteNetdevAddByFds(ctx context.Context, netdevType, netdevID string, fdNames, vhostFdNames []string) error {
|
||||
fdNameStr := strings.Join(fdNames, ":")
|
||||
vhostFdNameStr := strings.Join(vhostFdNames, ":")
|
||||
args := map[string]interface{}{
|
||||
"type": netdevType,
|
||||
"id": netdevID,
|
||||
"fds": fdNameStr,
|
||||
"vhost": "on",
|
||||
"vhostfds": vhostFdNameStr,
|
||||
}
|
||||
if len(vhostFdNames) > 0 {
|
||||
vhostFdNameStr := strings.Join(vhostFdNames, ":")
|
||||
args["vhost"] = "on"
|
||||
args["vhostfds"] = vhostFdNameStr
|
||||
}
|
||||
|
||||
return q.executeCommand(ctx, "netdev_add", args, nil)
|
||||
|
@ -458,10 +458,15 @@ func TestQMPNetdevAddByFds(t *testing.T) {
|
||||
disconnectedCh := make(chan struct{})
|
||||
buf := newQMPTestCommandBuffer(t)
|
||||
buf.AddCommand("netdev_add", nil, "return", nil)
|
||||
buf.AddCommand("netdev_add", nil, "return", nil)
|
||||
cfg := QMPConfig{Logger: qmpTestLogger{}}
|
||||
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
|
||||
q.version = checkVersion(t, connectedCh)
|
||||
err := q.ExecuteNetdevAddByFds(context.Background(), "tap", "br0", nil, nil)
|
||||
err := q.ExecuteNetdevAddByFds(context.Background(), "tap", "br0", nil, []string{})
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error %v", err)
|
||||
}
|
||||
err = q.ExecuteNetdevAddByFds(context.Background(), "tap", "br1", nil, []string{"3"})
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error %v", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user