qemu: Add multi-queue and vhost definitions to NetDevice

We can now specify if we want vhost to be enabled and wich fds we should
use for multiqueue support.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz 2016-09-15 13:21:24 +02:00
parent 137e7c7242
commit 4780e2371f
2 changed files with 24 additions and 2 deletions

21
qemu.go
View File

@ -191,6 +191,13 @@ type NetDevice struct {
// Script is the tap interface configuration script.
Script string
// FDs represents the list of already existing file descriptors to be used.
// This is mostly useful for mq support.
FDs []int
// VHost enables virtio device emulation from the host kernel instead of from qemu.
VHost bool
}
// Config is the qemu configuration structure.
@ -557,6 +564,20 @@ func appendNetDevices(params []string, config Config) []string {
netdevParams = append(netdevParams, fmt.Sprintf(",script=%s", d.Script))
}
if len(d.FDs) > 0 {
var fdParams []string
for _, fd := range d.FDs {
fdParams = append(fdParams, fmt.Sprintf("%d", fd))
}
netdevParams = append(netdevParams, fmt.Sprintf(",fds=%s", strings.Join(fdParams, ":")))
}
if d.VHost == true {
netdevParams = append(netdevParams, ",vhost=on")
}
params = append(params, "-netdev")
params = append(params, strings.Join(netdevParams, ""))
}

View File

@ -266,15 +266,16 @@ func TestAppendStrings(t *testing.T) {
}
}
var netdevString = "-netdev tap,id=ceth0,ifname=ceth0,downscript=no,script=no"
var netdevString = "-netdev tap,id=ceth0,downscript=no,script=no,fds=8:9:10,vhost=on"
func TestAppendNetDevices(t *testing.T) {
netdev := NetDevice{
Type: "tap",
ID: "ceth0",
IfName: "ceth0",
Script: "no",
DownScript: "no",
FDs: []int{8, 9, 10},
VHost: true,
}
testAppend(netdev, netdevString, t)