virtcontainers/fc: Add support for hybrid vsocks

Currently only firecracker supports hybrid vsocks, change the implementation
to use hybrid vsocks in firecracker.

Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
Julio Montes 2019-09-11 16:05:31 +00:00
parent 2c4cf392f7
commit f42dd7d115

View File

@ -58,6 +58,12 @@ const (
// We attach a pool of placeholder drives before the guest has started, and then // We attach a pool of placeholder drives before the guest has started, and then
// patch the replace placeholder drives with drives with actual contents. // patch the replace placeholder drives with drives with actual contents.
fcDiskPoolSize = 8 fcDiskPoolSize = 8
defaultHybridVSocketName = "kata.hvsock"
// This is the first usable vsock context ID. All the vsocks can use the same
// ID, since it's only used in the guest.
defaultGuestVSockCID = int64(0x3)
) )
var fcKernelParams = append(commonVirtioblkKernelRootParams, []Param{ var fcKernelParams = append(commonVirtioblkKernelRootParams, []Param{
@ -737,14 +743,18 @@ func (fc *firecracker) resumeSandbox() error {
return nil return nil
} }
func (fc *firecracker) fcAddVsock(vs kataVSOCK) error { func (fc *firecracker) fcAddVsock(hvs types.HybridVSock) error {
span, _ := fc.trace("fcAddVsock") span, _ := fc.trace("fcAddVsock")
defer span.Finish() defer span.Finish()
udsPath := hvs.UdsPath
if fc.jailed {
udsPath = filepath.Join("/", defaultHybridVSocketName)
}
vsockParams := ops.NewPutGuestVsockByIDParams() vsockParams := ops.NewPutGuestVsockByIDParams()
vsockID := "root" vsockID := "root"
ctxID := int64(vs.contextID) ctxID := defaultGuestVSockCID
udsPath := ""
vsock := &models.Vsock{ vsock := &models.Vsock{
GuestCid: &ctxID, GuestCid: &ctxID,
UdsPath: &udsPath, UdsPath: &udsPath,
@ -752,15 +762,14 @@ func (fc *firecracker) fcAddVsock(vs kataVSOCK) error {
} }
vsockParams.SetID(vsockID) vsockParams.SetID(vsockID)
vsockParams.SetBody(vsock) vsockParams.SetBody(vsock)
_, err := fc.client().Operations.PutGuestVsockByID(vsockParams) _, err := fc.client().Operations.PutGuestVsockByID(vsockParams)
if err != nil { if err != nil {
return err return err
} }
//Still racy. There is no way to send an fd to the firecracker
//REST API. We could release this just before we start the instance
//but even that will not eliminate the race
vs.vhostFd.Close()
return nil return nil
} }
func (fc *firecracker) fcAddNetDevice(endpoint Endpoint) error { func (fc *firecracker) fcAddNetDevice(endpoint Endpoint) error {
@ -878,8 +887,8 @@ func (fc *firecracker) addDevice(devInfo interface{}, devType deviceType) error
case config.BlockDrive: case config.BlockDrive:
fc.Logger().WithField("device-type-blockdrive", devInfo).Info("Adding device") fc.Logger().WithField("device-type-blockdrive", devInfo).Info("Adding device")
return fc.fcAddBlockDrive(v) return fc.fcAddBlockDrive(v)
case kataVSOCK: case types.HybridVSock:
fc.Logger().WithField("device-type-vsock", devInfo).Info("Adding device") fc.Logger().WithField("device-type-hybrid-vsock", devInfo).Info("Adding device")
return fc.fcAddVsock(v) return fc.fcAddVsock(v)
default: default:
fc.Logger().WithField("unknown-device-type", devInfo).Error("Adding device") fc.Logger().WithField("unknown-device-type", devInfo).Error("Adding device")