mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-06 20:09:44 +00:00
qemu: Add PCI option to the NetDevice
The existing NetDevice relies on virtio-net driver, but there is a useful PCI variant which was not available: virtio-net-pci. This patch adds this new driver and adds two parameters specific to this: "bus" and "addr". Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
a84228ae99
commit
d48b5b5f48
23
qemu.go
23
qemu.go
@ -29,6 +29,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
@ -62,6 +63,9 @@ const (
|
|||||||
// VirtioNet is the virt-io networking device driver.
|
// VirtioNet is the virt-io networking device driver.
|
||||||
VirtioNet = "virtio-net"
|
VirtioNet = "virtio-net"
|
||||||
|
|
||||||
|
// VirtioNetPCI is the virt-io pci networking device driver.
|
||||||
|
VirtioNetPCI = "virtio-net-pci"
|
||||||
|
|
||||||
// VirtioSerial is the serial device driver.
|
// VirtioSerial is the serial device driver.
|
||||||
VirtioSerial = "virtio-serial-pci"
|
VirtioSerial = "virtio-serial-pci"
|
||||||
|
|
||||||
@ -341,6 +345,12 @@ type NetDevice struct {
|
|||||||
// IfName is the interface name,
|
// IfName is the interface name,
|
||||||
IFName string
|
IFName string
|
||||||
|
|
||||||
|
// Bus is the bus path name of a PCI device.
|
||||||
|
Bus string
|
||||||
|
|
||||||
|
// Addr is the address offset of a PCI device.
|
||||||
|
Addr string
|
||||||
|
|
||||||
// DownScript is the tap interface deconfiguration script.
|
// DownScript is the tap interface deconfiguration script.
|
||||||
DownScript string
|
DownScript string
|
||||||
|
|
||||||
@ -384,6 +394,19 @@ func (netdev NetDevice) QemuParams(config *Config) []string {
|
|||||||
deviceParams = append(deviceParams, fmt.Sprintf(",netdev=%s", netdev.ID))
|
deviceParams = append(deviceParams, fmt.Sprintf(",netdev=%s", netdev.ID))
|
||||||
deviceParams = append(deviceParams, fmt.Sprintf(",mac=%s", netdev.MACAddress))
|
deviceParams = append(deviceParams, fmt.Sprintf(",mac=%s", netdev.MACAddress))
|
||||||
|
|
||||||
|
if netdev.Driver == VirtioNetPCI {
|
||||||
|
if netdev.Bus != "" {
|
||||||
|
deviceParams = append(deviceParams, fmt.Sprintf(",bus=%s", netdev.Bus))
|
||||||
|
}
|
||||||
|
|
||||||
|
if netdev.Addr != "" {
|
||||||
|
addr, err := strconv.Atoi(netdev.Addr)
|
||||||
|
if err == nil && addr >= 0 {
|
||||||
|
deviceParams = append(deviceParams, fmt.Sprintf(",addr=%x", addr))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
netdevParams = append(netdevParams, string(netdev.Type))
|
netdevParams = append(netdevParams, string(netdev.Type))
|
||||||
netdevParams = append(netdevParams, fmt.Sprintf(",id=%s", netdev.ID))
|
netdevParams = append(netdevParams, fmt.Sprintf(",id=%s", netdev.ID))
|
||||||
netdevParams = append(netdevParams, fmt.Sprintf(",ifname=%s", netdev.IFName))
|
netdevParams = append(netdevParams, fmt.Sprintf(",ifname=%s", netdev.IFName))
|
||||||
|
26
qemu_test.go
26
qemu_test.go
@ -143,6 +143,32 @@ func TestAppendDeviceNetwork(t *testing.T) {
|
|||||||
testAppend(netdev, deviceNetworkString, t)
|
testAppend(netdev, deviceNetworkString, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var deviceNetworkPCIString = "-device virtio-net-pci,netdev=tap0,mac=01:02:de:ad:be:ef,bus=/pci-bus/pcie.0,addr=ff -netdev tap,id=tap0,ifname=ceth0,downscript=no,script=no,fds=3:4,vhost=on"
|
||||||
|
|
||||||
|
func TestAppendDeviceNetworkPCI(t *testing.T) {
|
||||||
|
foo, _ := ioutil.TempFile(os.TempDir(), "qemu-ciao-test")
|
||||||
|
bar, _ := ioutil.TempFile(os.TempDir(), "qemu-ciao-test")
|
||||||
|
|
||||||
|
defer os.Remove(foo.Name())
|
||||||
|
defer os.Remove(bar.Name())
|
||||||
|
|
||||||
|
netdev := NetDevice{
|
||||||
|
Driver: VirtioNetPCI,
|
||||||
|
Type: TAP,
|
||||||
|
ID: "tap0",
|
||||||
|
IFName: "ceth0",
|
||||||
|
Bus: "/pci-bus/pcie.0",
|
||||||
|
Addr: "255",
|
||||||
|
Script: "no",
|
||||||
|
DownScript: "no",
|
||||||
|
FDs: []*os.File{foo, bar},
|
||||||
|
VHost: true,
|
||||||
|
MACAddress: "01:02:de:ad:be:ef",
|
||||||
|
}
|
||||||
|
|
||||||
|
testAppend(netdev, deviceNetworkPCIString, t)
|
||||||
|
}
|
||||||
|
|
||||||
var deviceSerialString = "-device virtio-serial-pci,id=serial0"
|
var deviceSerialString = "-device virtio-serial-pci,id=serial0"
|
||||||
|
|
||||||
func TestAppendDeviceSerial(t *testing.T) {
|
func TestAppendDeviceSerial(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user