mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-27 15:57:09 +00:00
virtcontainers: rename kataVSOCK type and move it into the types package
Rename kataVSOCK to VSock and move it into the types package, this way it can be accessible by other subpackages. This change is required because in next commits the socket address and type (socket, vsock, hybrid vsock) will be hypervisor specific. Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
parent
f42dd7d115
commit
f2f09230ee
@ -547,7 +547,7 @@ func (a *acrn) addDevice(devInfo interface{}, devType deviceType) error {
|
||||
err = nil
|
||||
case types.Socket:
|
||||
a.acrnConfig.Devices = a.arch.appendSocket(a.acrnConfig.Devices, v)
|
||||
case kataVSOCK:
|
||||
case types.VSock:
|
||||
// Not supported. return success
|
||||
err = nil
|
||||
case Endpoint:
|
||||
|
@ -145,16 +145,6 @@ type KataAgentConfig struct {
|
||||
KernelModules []string
|
||||
}
|
||||
|
||||
type kataVSOCK struct {
|
||||
contextID uint64
|
||||
port uint32
|
||||
vhostFd *os.File
|
||||
}
|
||||
|
||||
func (s *kataVSOCK) String() string {
|
||||
return fmt.Sprintf("%s://%d:%d", vsockSocketScheme, s.contextID, s.port)
|
||||
}
|
||||
|
||||
// KataAgentState is the structure describing the data stored from this
|
||||
// agent implementation.
|
||||
type KataAgentState struct {
|
||||
@ -340,7 +330,7 @@ func (k *kataAgent) agentURL() (string, error) {
|
||||
switch s := k.vmSocket.(type) {
|
||||
case types.Socket:
|
||||
return s.HostPath, nil
|
||||
case kataVSOCK:
|
||||
case types.VSock:
|
||||
return s.String(), nil
|
||||
case types.HybridVSock:
|
||||
return s.String(), nil
|
||||
@ -390,12 +380,12 @@ func (k *kataAgent) configure(h hypervisor, id, sharePath string, builtin bool,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case kataVSOCK:
|
||||
s.vhostFd, s.contextID, err = utils.FindContextID()
|
||||
case types.VSock:
|
||||
s.VhostFd, s.ContextID, err = utils.FindContextID()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.port = uint32(vSockPort)
|
||||
s.Port = uint32(vSockPort)
|
||||
if err = h.addDevice(s, vSockPCIDev); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -644,7 +644,7 @@ func TestAgentPathAPI(t *testing.T) {
|
||||
c.UseVSock = true
|
||||
err = k2.generateVMSocket(id, c)
|
||||
assert.Nil(err)
|
||||
_, ok = k2.vmSocket.(kataVSOCK)
|
||||
_, ok = k2.vmSocket.(types.VSock)
|
||||
assert.True(ok)
|
||||
}
|
||||
|
||||
|
@ -1591,8 +1591,8 @@ func (q *qemu) addDevice(devInfo interface{}, devType deviceType) error {
|
||||
}
|
||||
case types.Socket:
|
||||
q.qemuConfig.Devices = q.arch.appendSocket(q.qemuConfig.Devices, v)
|
||||
case kataVSOCK:
|
||||
q.fds = append(q.fds, v.vhostFd)
|
||||
case types.VSock:
|
||||
q.fds = append(q.fds, v.VhostFd)
|
||||
q.qemuConfig.Devices, err = q.arch.appendVSock(q.qemuConfig.Devices, v)
|
||||
case Endpoint:
|
||||
q.qemuConfig.Devices, err = q.arch.appendNetwork(q.qemuConfig.Devices, v)
|
||||
|
@ -80,7 +80,7 @@ type qemuArch interface {
|
||||
appendSocket(devices []govmmQemu.Device, socket types.Socket) []govmmQemu.Device
|
||||
|
||||
// appendVSock appends a vsock PCI to devices
|
||||
appendVSock(devices []govmmQemu.Device, vsock kataVSOCK) ([]govmmQemu.Device, error)
|
||||
appendVSock(devices []govmmQemu.Device, vsock types.VSock) ([]govmmQemu.Device, error)
|
||||
|
||||
// appendNetwork appends a endpoint device to devices
|
||||
appendNetwork(devices []govmmQemu.Device, endpoint Endpoint) ([]govmmQemu.Device, error)
|
||||
@ -451,12 +451,12 @@ func (q *qemuArchBase) appendSocket(devices []govmmQemu.Device, socket types.Soc
|
||||
return devices
|
||||
}
|
||||
|
||||
func (q *qemuArchBase) appendVSock(devices []govmmQemu.Device, vsock kataVSOCK) ([]govmmQemu.Device, error) {
|
||||
func (q *qemuArchBase) appendVSock(devices []govmmQemu.Device, vsock types.VSock) ([]govmmQemu.Device, error) {
|
||||
devices = append(devices,
|
||||
govmmQemu.VSOCKDevice{
|
||||
ID: fmt.Sprintf("vsock-%d", vsock.contextID),
|
||||
ContextID: vsock.contextID,
|
||||
VHostFD: vsock.vhostFd,
|
||||
ID: fmt.Sprintf("vsock-%d", vsock.ContextID),
|
||||
ContextID: vsock.ContextID,
|
||||
VHostFD: vsock.VhostFd,
|
||||
DisableModern: q.nestedRun,
|
||||
},
|
||||
)
|
||||
|
@ -274,10 +274,10 @@ func TestQemuAddDeviceKataVSOCK(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
vsock := kataVSOCK{
|
||||
contextID: contextID,
|
||||
port: port,
|
||||
vhostFd: vsockFile,
|
||||
vsock := types.VSock{
|
||||
ContextID: contextID,
|
||||
Port: port,
|
||||
VhostFd: vsockFile,
|
||||
}
|
||||
|
||||
testQemuAddDevice(t, vsock, vSockPCIDev, expectedOut)
|
||||
|
@ -7,6 +7,7 @@ package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
@ -29,7 +30,10 @@ const (
|
||||
StateStopped StateString = "stopped"
|
||||
)
|
||||
|
||||
const HybridVSockScheme = "hvsock"
|
||||
const (
|
||||
HybridVSockScheme = "hvsock"
|
||||
VSockScheme = "vsock"
|
||||
)
|
||||
|
||||
// SandboxState is a sandbox state structure
|
||||
type SandboxState struct {
|
||||
@ -163,6 +167,20 @@ func (v *Volumes) String() string {
|
||||
return strings.Join(volSlice, " ")
|
||||
}
|
||||
|
||||
// VSock defines a virtio-socket to communicate between
|
||||
// the host and any process inside the VM.
|
||||
// This kind of socket is not supported in all hypervisors.
|
||||
// QEMU and NEMU support it.
|
||||
type VSock struct {
|
||||
ContextID uint64
|
||||
Port uint32
|
||||
VhostFd *os.File
|
||||
}
|
||||
|
||||
func (s *VSock) String() string {
|
||||
return fmt.Sprintf("%s://%d:%d", VSockScheme, s.ContextID, s.Port)
|
||||
}
|
||||
|
||||
// HybridVSock defines a hybrid vsocket to communicate between
|
||||
// the host and any process inside the VM.
|
||||
// This is a virtio-vsock implementation based on AF_VSOCK on the
|
||||
|
Loading…
Reference in New Issue
Block a user