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)