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:
Ruidong Cao 2018-09-10 11:28:21 +08:00
parent 25277d52ad
commit 1a1fee75e5
2 changed files with 14 additions and 7 deletions

View File

@ -812,13 +812,15 @@ func (q *QMP) ExecuteNetdevChardevAdd(ctx context.Context, netdevType, netdevID,
// Must be valid QMP identifier. // Must be valid QMP identifier.
func (q *QMP) ExecuteNetdevAddByFds(ctx context.Context, netdevType, netdevID string, fdNames, vhostFdNames []string) error { func (q *QMP) ExecuteNetdevAddByFds(ctx context.Context, netdevType, netdevID string, fdNames, vhostFdNames []string) error {
fdNameStr := strings.Join(fdNames, ":") fdNameStr := strings.Join(fdNames, ":")
vhostFdNameStr := strings.Join(vhostFdNames, ":")
args := map[string]interface{}{ args := map[string]interface{}{
"type": netdevType, "type": netdevType,
"id": netdevID, "id": netdevID,
"fds": fdNameStr, "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) return q.executeCommand(ctx, "netdev_add", args, nil)

View File

@ -458,10 +458,15 @@ func TestQMPNetdevAddByFds(t *testing.T) {
disconnectedCh := make(chan struct{}) disconnectedCh := make(chan struct{})
buf := newQMPTestCommandBuffer(t) buf := newQMPTestCommandBuffer(t)
buf.AddCommand("netdev_add", nil, "return", nil) buf.AddCommand("netdev_add", nil, "return", nil)
buf.AddCommand("netdev_add", nil, "return", nil)
cfg := QMPConfig{Logger: qmpTestLogger{}} cfg := QMPConfig{Logger: qmpTestLogger{}}
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh) q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
q.version = checkVersion(t, connectedCh) 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 { if err != nil {
t.Fatalf("Unexpected error %v", err) t.Fatalf("Unexpected error %v", err)
} }