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

Commit

Permalink
virtcontainers: introducing HybridVSock type
Browse files Browse the repository at this point in the history
This new socket type is currently supported only by the firecracker hypervisor.
For more details about its internal implementation see:
https://github.com/firecracker-microvm/firecracker/blob/master/docs/vsock.md

Signed-off-by: Julio Montes <[email protected]>
  • Loading branch information
Julio Montes committed Sep 19, 2019
1 parent 2a8af23 commit 880bb2b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions virtcontainers/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ const (

// memoryDevice is memory device type
memoryDev

// hybridVirtioVsockDev is a hybrid virtio-vsock device supported
// only on certain hypervisors, like firecracker.
hybridVirtioVsockDev
)

type memoryDevice struct {
Expand Down
7 changes: 7 additions & 0 deletions virtcontainers/kata_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ func (k *kataAgent) agentURL() (string, error) {
return s.HostPath, nil
case kataVSOCK:
return s.String(), nil
case types.HybridVSock:
return s.String(), nil
default:
return "", fmt.Errorf("Invalid socket type")
}
Expand Down Expand Up @@ -398,6 +400,11 @@ func (k *kataAgent) configure(h hypervisor, id, sharePath string, builtin bool,
return err
}
k.vmSocket = s
case types.HybridVSock:
err = h.addDevice(s, hybridVirtioVsockDev)
if err != nil {
return err
}
default:
return vcTypes.ErrInvalidConfigType
}
Expand Down
17 changes: 17 additions & 0 deletions virtcontainers/types/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const (
StateStopped StateString = "stopped"
)

const HybridVSockScheme = "hvsock"

// SandboxState is a sandbox state structure
type SandboxState struct {
State StateString `json:"state"`
Expand Down Expand Up @@ -161,6 +163,21 @@ func (v *Volumes) String() string {
return strings.Join(volSlice, " ")
}

// 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
// guest side and multiple AF_UNIX sockets on the host side.
// This kind of socket is not supported in all hypervisors.
// Firecracker supports it.
type HybridVSock struct {
UdsPath string
Port uint32
}

func (s *HybridVSock) String() string {
return fmt.Sprintf("%s://%s:%d", HybridVSockScheme, s.UdsPath, s.Port)
}

// Socket defines a socket to communicate between
// the host and any process inside the VM.
type Socket struct {
Expand Down

0 comments on commit 880bb2b

Please sign in to comment.