cli: add configuration option to enable/disable vsocks

Add `use_vsock` option to enable or disable the use of vsocks
for communication between host and guest.

Signed-off-by: Jose Carlos Venegas Munoz <jose.carlos.venegas.munoz@intel.com>
Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
Julio Montes 2018-07-23 18:02:38 -05:00
parent f389b94d8a
commit 4680e58e08
5 changed files with 104 additions and 3 deletions

View File

@ -15,6 +15,7 @@ import (
"github.com/BurntSushi/toml"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/kata-containers/runtime/virtcontainers/utils"
"github.com/sirupsen/logrus"
)
@ -91,6 +92,7 @@ type hypervisor struct {
Debug bool `toml:"enable_debug"`
DisableNestingChecks bool `toml:"disable_nesting_checks"`
EnableIOThreads bool `toml:"enable_iothreads"`
UseVSock bool `toml:"use_vsock"`
}
type proxy struct {
@ -267,6 +269,10 @@ func (h hypervisor) msize9p() uint32 {
return h.Msize9p
}
func (h hypervisor) useVSock() bool {
return h.UseVSock
}
func (p proxy) path() string {
if p.Path == "" {
return defaultProxyPath
@ -333,6 +339,16 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
return vc.HypervisorConfig{}, err
}
useVSock := false
if h.useVSock() {
if utils.SupportsVsocks() {
kataLog.Info("vsock supported")
useVSock = true
} else {
kataLog.Warn("No vsock support, falling back to legacy serial port")
}
}
return vc.HypervisorConfig{
HypervisorPath: hypervisor,
KernelPath: kernel,
@ -355,6 +371,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
BlockDeviceDriver: blockDriver,
EnableIOThreads: h.EnableIOThreads,
Msize9p: h.msize9p(),
UseVSock: useVSock,
}, nil
}
@ -544,6 +561,13 @@ func loadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat
return "", config, err
}
// use no proxy if HypervisorConfig.UseVSock is true
if config.HypervisorConfig.UseVSock {
kataLog.Info("VSOCK supported, configure to not use proxy")
config.ProxyType = vc.NoProxyType
config.ProxyConfig = vc.ProxyConfig{}
}
return resolved, config, nil
}

View File

@ -134,6 +134,12 @@ enable_iothreads = @DEFENABLEIOTHREADS@
# used for 9p packet payload.
#msize_9p = @DEFMSIZE9P@
# If true and vsocks are supported, use vsocks to communicate directly
# with the agent and no proxy is started, otherwise use unix
# sockets and start a proxy to communicate with the agent.
# Default false
#use_vsock = true
[factory]
# VM templating support. Once enabled, new VMs are created from template
# using vm cloning. They will share the same initial kernel, initramfs and

View File

@ -20,6 +20,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/kata-containers/runtime/virtcontainers/utils"
"github.com/stretchr/testify/assert"
)
@ -552,6 +553,52 @@ func TestMinimalRuntimeConfig(t *testing.T) {
t.Fatalf("Got %+v\n expecting %+v", config, expectedConfig)
}
// minimal config with vsock enabled
runtimeMinimalConfig = `
# Runtime configuration file
[hypervisor.qemu]
use_vsock = true
[proxy.kata]
path = "` + proxyPath + `"
[shim.kata]
path = "` + shimPath + `"
[agent.kata]
`
orgVHostVSockDevicePath := utils.VHostVSockDevicePath
orgVSockDevicePath := utils.VSockDevicePath
defer func() {
utils.VHostVSockDevicePath = orgVHostVSockDevicePath
utils.VSockDevicePath = orgVSockDevicePath
}()
utils.VHostVSockDevicePath = "/dev/null"
utils.VSockDevicePath = "/dev/null"
configPath = path.Join(dir, "runtime.toml")
err = createConfig(configPath, runtimeMinimalConfig)
if err != nil {
t.Fatal(err)
}
_, config, err = loadConfiguration(configPath, false)
if err != nil {
t.Fatal(err)
}
if config.ProxyType != vc.NoProxyType {
t.Fatalf("Proxy type must be NoProxy, got %+v", config.ProxyType)
}
if !reflect.DeepEqual(config.ProxyConfig, vc.ProxyConfig{}) {
t.Fatalf("Got %+v\n expecting %+v", config.ProxyConfig, vc.ProxyConfig{})
}
if config.HypervisorConfig.UseVSock != true {
t.Fatalf("use_vsock must be true, got %v", config.HypervisorConfig.UseVSock)
}
if err := os.Remove(configPath); err != nil {
t.Fatal(err)
}
@ -570,6 +617,14 @@ func TestNewQemuHypervisorConfig(t *testing.T) {
machineType := "machineType"
disableBlock := true
enableIOThreads := true
orgVSockDevicePath := utils.VSockDevicePath
orgVHostVSockDevicePath := utils.VHostVSockDevicePath
defer func() {
utils.VSockDevicePath = orgVSockDevicePath
utils.VHostVSockDevicePath = orgVHostVSockDevicePath
}()
utils.VSockDevicePath = "/dev/abc/xyz"
utils.VHostVSockDevicePath = "/dev/abc/xyz"
hypervisor := hypervisor{
Path: hypervisorPath,
@ -578,6 +633,7 @@ func TestNewQemuHypervisorConfig(t *testing.T) {
MachineType: machineType,
DisableBlockDeviceUse: disableBlock,
EnableIOThreads: enableIOThreads,
UseVSock: true,
}
files := []string{hypervisorPath, kernelPath, imagePath}
@ -597,12 +653,21 @@ func TestNewQemuHypervisorConfig(t *testing.T) {
}
}
// all paths exist now
// falling back to legacy serial port
config, err := newQemuHypervisorConfig(hypervisor)
if err != nil {
t.Fatal(err)
}
utils.VSockDevicePath = "/dev/null"
utils.VHostVSockDevicePath = "/dev/null"
// all paths exist now
config, err = newQemuHypervisorConfig(hypervisor)
if err != nil {
t.Fatal(err)
}
if config.HypervisorPath != hypervisor.Path {
t.Errorf("Expected hypervisor path %v, got %v", hypervisor.Path, config.HypervisorPath)
}

View File

@ -11,19 +11,20 @@ import (
"os"
"strings"
runtim "runtime"
"github.com/BurntSushi/toml"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/urfave/cli"
runtim "runtime"
)
// Semantic version for the output of the command.
//
// XXX: Increment for every change to the output format
// (meaning any change to the EnvInfo type).
const formatVersion = "1.0.12"
const formatVersion = "1.0.13"
// MetaInfo stores information on the format of the output itself
type MetaInfo struct {
@ -80,6 +81,7 @@ type HypervisorInfo struct {
BlockDeviceDriver string
Msize9p uint32
Debug bool
UseVSock bool
}
// ProxyInfo stores proxy details
@ -276,6 +278,7 @@ func getHypervisorInfo(config oci.RuntimeConfig) HypervisorInfo {
Path: hypervisorPath,
BlockDeviceDriver: config.HypervisorConfig.BlockDeviceDriver,
Msize9p: config.HypervisorConfig.Msize9p,
UseVSock: config.HypervisorConfig.UseVSock,
}
}

View File

@ -217,6 +217,9 @@ type HypervisorConfig struct {
// Msize9p is used as the msize for 9p shares
Msize9p uint32
// UseVSock use a vsock for agent communication
UseVSock bool
// BootToBeTemplate used to indicate if the VM is created to be a template VM
BootToBeTemplate bool