Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
virtcontainers: rename kataVSOCK type and move it into the types package
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Julio Montes committed Sep 19, 2019
1 parent f42dd7d commit f2f0923
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 28 deletions.
2 changes: 1 addition & 1 deletion virtcontainers/acrn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 4 additions & 14 deletions virtcontainers/kata_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/kata_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions virtcontainers/qemu_arch_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
},
)
Expand Down
8 changes: 4 additions & 4 deletions virtcontainers/qemu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 19 additions & 1 deletion virtcontainers/types/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package types

import (
"fmt"
"os"
"strings"

"github.com/opencontainers/runtime-spec/specs-go"
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f2f0923

Please sign in to comment.