From 4780e2371f6025d7b00ba14d039b03fe6ad95cbb Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Thu, 15 Sep 2016 13:21:24 +0200 Subject: [PATCH] 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 --- qemu.go | 21 +++++++++++++++++++++ qemu_test.go | 5 +++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/qemu.go b/qemu.go index e4824d40cd..3a035439b3 100644 --- a/qemu.go +++ b/qemu.go @@ -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, "")) } diff --git a/qemu_test.go b/qemu_test.go index 4eef5bece8..6d634bb955 100644 --- a/qemu_test.go +++ b/qemu_test.go @@ -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)