mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-02 02:02:24 +00:00
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:
parent
f389b94d8a
commit
4680e58e08
@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
|
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
|
||||||
|
"github.com/kata-containers/runtime/virtcontainers/utils"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -91,6 +92,7 @@ type hypervisor struct {
|
|||||||
Debug bool `toml:"enable_debug"`
|
Debug bool `toml:"enable_debug"`
|
||||||
DisableNestingChecks bool `toml:"disable_nesting_checks"`
|
DisableNestingChecks bool `toml:"disable_nesting_checks"`
|
||||||
EnableIOThreads bool `toml:"enable_iothreads"`
|
EnableIOThreads bool `toml:"enable_iothreads"`
|
||||||
|
UseVSock bool `toml:"use_vsock"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type proxy struct {
|
type proxy struct {
|
||||||
@ -267,6 +269,10 @@ func (h hypervisor) msize9p() uint32 {
|
|||||||
return h.Msize9p
|
return h.Msize9p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h hypervisor) useVSock() bool {
|
||||||
|
return h.UseVSock
|
||||||
|
}
|
||||||
|
|
||||||
func (p proxy) path() string {
|
func (p proxy) path() string {
|
||||||
if p.Path == "" {
|
if p.Path == "" {
|
||||||
return defaultProxyPath
|
return defaultProxyPath
|
||||||
@ -333,6 +339,16 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
|
|||||||
return vc.HypervisorConfig{}, err
|
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{
|
return vc.HypervisorConfig{
|
||||||
HypervisorPath: hypervisor,
|
HypervisorPath: hypervisor,
|
||||||
KernelPath: kernel,
|
KernelPath: kernel,
|
||||||
@ -355,6 +371,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
|
|||||||
BlockDeviceDriver: blockDriver,
|
BlockDeviceDriver: blockDriver,
|
||||||
EnableIOThreads: h.EnableIOThreads,
|
EnableIOThreads: h.EnableIOThreads,
|
||||||
Msize9p: h.msize9p(),
|
Msize9p: h.msize9p(),
|
||||||
|
UseVSock: useVSock,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -544,6 +561,13 @@ func loadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat
|
|||||||
return "", config, err
|
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
|
return resolved, config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,6 +134,12 @@ enable_iothreads = @DEFENABLEIOTHREADS@
|
|||||||
# used for 9p packet payload.
|
# used for 9p packet payload.
|
||||||
#msize_9p = @DEFMSIZE9P@
|
#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]
|
[factory]
|
||||||
# VM templating support. Once enabled, new VMs are created from template
|
# VM templating support. Once enabled, new VMs are created from template
|
||||||
# using vm cloning. They will share the same initial kernel, initramfs and
|
# using vm cloning. They will share the same initial kernel, initramfs and
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
|
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
|
||||||
|
"github.com/kata-containers/runtime/virtcontainers/utils"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -552,6 +553,52 @@ func TestMinimalRuntimeConfig(t *testing.T) {
|
|||||||
t.Fatalf("Got %+v\n expecting %+v", config, expectedConfig)
|
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 {
|
if err := os.Remove(configPath); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -570,6 +617,14 @@ func TestNewQemuHypervisorConfig(t *testing.T) {
|
|||||||
machineType := "machineType"
|
machineType := "machineType"
|
||||||
disableBlock := true
|
disableBlock := true
|
||||||
enableIOThreads := 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{
|
hypervisor := hypervisor{
|
||||||
Path: hypervisorPath,
|
Path: hypervisorPath,
|
||||||
@ -578,6 +633,7 @@ func TestNewQemuHypervisorConfig(t *testing.T) {
|
|||||||
MachineType: machineType,
|
MachineType: machineType,
|
||||||
DisableBlockDeviceUse: disableBlock,
|
DisableBlockDeviceUse: disableBlock,
|
||||||
EnableIOThreads: enableIOThreads,
|
EnableIOThreads: enableIOThreads,
|
||||||
|
UseVSock: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
files := []string{hypervisorPath, kernelPath, imagePath}
|
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)
|
config, err := newQemuHypervisorConfig(hypervisor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
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 {
|
if config.HypervisorPath != hypervisor.Path {
|
||||||
t.Errorf("Expected hypervisor path %v, got %v", hypervisor.Path, config.HypervisorPath)
|
t.Errorf("Expected hypervisor path %v, got %v", hypervisor.Path, config.HypervisorPath)
|
||||||
}
|
}
|
||||||
|
@ -11,19 +11,20 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
runtim "runtime"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
|
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
|
||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
runtim "runtime"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Semantic version for the output of the command.
|
// Semantic version for the output of the command.
|
||||||
//
|
//
|
||||||
// XXX: Increment for every change to the output format
|
// XXX: Increment for every change to the output format
|
||||||
// (meaning any change to the EnvInfo type).
|
// (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
|
// MetaInfo stores information on the format of the output itself
|
||||||
type MetaInfo struct {
|
type MetaInfo struct {
|
||||||
@ -80,6 +81,7 @@ type HypervisorInfo struct {
|
|||||||
BlockDeviceDriver string
|
BlockDeviceDriver string
|
||||||
Msize9p uint32
|
Msize9p uint32
|
||||||
Debug bool
|
Debug bool
|
||||||
|
UseVSock bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProxyInfo stores proxy details
|
// ProxyInfo stores proxy details
|
||||||
@ -276,6 +278,7 @@ func getHypervisorInfo(config oci.RuntimeConfig) HypervisorInfo {
|
|||||||
Path: hypervisorPath,
|
Path: hypervisorPath,
|
||||||
BlockDeviceDriver: config.HypervisorConfig.BlockDeviceDriver,
|
BlockDeviceDriver: config.HypervisorConfig.BlockDeviceDriver,
|
||||||
Msize9p: config.HypervisorConfig.Msize9p,
|
Msize9p: config.HypervisorConfig.Msize9p,
|
||||||
|
UseVSock: config.HypervisorConfig.UseVSock,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,6 +217,9 @@ type HypervisorConfig struct {
|
|||||||
// Msize9p is used as the msize for 9p shares
|
// Msize9p is used as the msize for 9p shares
|
||||||
Msize9p uint32
|
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 used to indicate if the VM is created to be a template VM
|
||||||
BootToBeTemplate bool
|
BootToBeTemplate bool
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user