virtcontainers: Use vsock if host support it

When the hypervisor option `use_vsock` is true the runtime will check for vsock
support. If vsock is supported, not proxy will be used and the shims
will connect to the VM using VSOCKS. This flag is true by default, so will use
VSOCK when possible and no proxy will be started.

fixes #383

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-25 09:45:24 -05:00
parent 3c15bc50d0
commit 33643797ad
3 changed files with 28 additions and 8 deletions

View File

@ -214,6 +214,10 @@ func getHostInfo() (HostInfo, error) {
} }
func getProxyInfo(config oci.RuntimeConfig) (ProxyInfo, error) { func getProxyInfo(config oci.RuntimeConfig) (ProxyInfo, error) {
if config.ProxyType == vc.NoProxyType {
return ProxyInfo{Type: string(config.ProxyType)}, nil
}
version, err := getCommandVersion(defaultProxyPath) version, err := getCommandVersion(defaultProxyPath)
if err != nil { if err != nil {
version = unknown version = unknown

View File

@ -68,6 +68,9 @@ const (
// SerialPortDev is the serial port device type. // SerialPortDev is the serial port device type.
serialPortDev serialPortDev
// vSockPCIDev is the vhost vsock PCI device type.
vSockPCIDev
// VFIODevice is VFIO device type // VFIODevice is VFIO device type
vfioDev vfioDev

View File

@ -47,13 +47,16 @@ var (
kataGuestSandboxDir = "/run/kata-containers/sandbox/" kataGuestSandboxDir = "/run/kata-containers/sandbox/"
type9pFs = "9p" type9pFs = "9p"
vsockSocketScheme = "vsock" vsockSocketScheme = "vsock"
kata9pDevType = "9p" // port numbers below 1024 are called privileged ports. Only a process with
kataBlkDevType = "blk" // CAP_NET_BIND_SERVICE capability may bind to these port numbers.
kataSCSIDevType = "scsi" vSockPort = 1024
sharedDir9pOptions = []string{"trans=virtio,version=9p2000.L", "nodev"} kata9pDevType = "9p"
shmDir = "shm" kataBlkDevType = "blk"
kataEphemeralDevType = "ephemeral" kataSCSIDevType = "scsi"
ephemeralPath = filepath.Join(kataGuestSandboxDir, kataEphemeralDevType) sharedDir9pOptions = []string{"trans=virtio,version=9p2000.L", "nodev"}
shmDir = "shm"
kataEphemeralDevType = "ephemeral"
ephemeralPath = filepath.Join(kataGuestSandboxDir, kataEphemeralDevType)
) )
// KataAgentConfig is a structure storing information needed // KataAgentConfig is a structure storing information needed
@ -66,6 +69,7 @@ type KataAgentConfig struct {
type kataVSOCK struct { type kataVSOCK struct {
contextID uint32 contextID uint32
port uint32 port uint32
vhostFd *os.File
} }
func (s *kataVSOCK) String() string { func (s *kataVSOCK) String() string {
@ -203,7 +207,16 @@ func (k *kataAgent) configure(h hypervisor, id, sharePath string, builtin bool,
return err return err
} }
case kataVSOCK: case kataVSOCK:
// TODO Add an hypervisor vsock var err error
s.vhostFd, s.contextID, err = utils.FindContextID()
if err != nil {
return err
}
s.port = uint32(vSockPort)
if err := h.addDevice(s, vSockPCIDev); err != nil {
return err
}
k.vmSocket = s
default: default:
return fmt.Errorf("Invalid config type") return fmt.Errorf("Invalid config type")
} }