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

Commit

Permalink
Merge pull request #3 from kata-containers/master
Browse files Browse the repository at this point in the history
Merge #3 of kata-containers/runtime
  • Loading branch information
ericooper authored Nov 25, 2019
2 parents 164fa18 + 562d9fd commit 7b8e15f
Show file tree
Hide file tree
Showing 17 changed files with 547 additions and 93 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.git-commit
.git-commit.tmp
/cli/config/configuration-acrn.toml
/cli/config/configuration-clh.toml
/cli/config/configuration-fc.toml
/cli/config/configuration-nemu.toml
/cli/config/configuration-qemu.toml
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10.0-alpha0
1.10.0-alpha1
4 changes: 3 additions & 1 deletion cli/config/configuration-fc.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ path = "@FCPATH@"
# If the jailer path is not set kata will launch firecracker
# without a jail. If the jailer is set firecracker will be
# launched in a jailed enviornment created by the jailer
jailer_path = "@FCJAILERPATH@"
# This is disabled by default as additional setup is required
# for this feature today.
#jailer_path = "@FCJAILERPATH@"
kernel = "@KERNELPATH_FC@"
image = "@IMAGEPATH@"

Expand Down
24 changes: 24 additions & 0 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/kata-containers/runtime/pkg/rootless"
"github.com/kata-containers/runtime/pkg/signals"
vc "github.com/kata-containers/runtime/virtcontainers"
exp "github.com/kata-containers/runtime/virtcontainers/experimental"
vf "github.com/kata-containers/runtime/virtcontainers/factory"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
specs "github.com/opencontainers/runtime-spec/specs-go"
Expand Down Expand Up @@ -346,6 +347,11 @@ func beforeSubcommands(c *cli.Context) error {
"arguments": `"` + args + `"`,
}

err = addExpFeatures(c, runtimeConfig)
if err != nil {
return err
}

kataLog.WithFields(fields).Info()

// make the data accessible to the sub-commands.
Expand Down Expand Up @@ -401,6 +407,24 @@ func setupTracing(context *cli.Context, rootSpanName string) error {
return nil
}

// add supported experimental features in context
func addExpFeatures(clictx *cli.Context, runtimeConfig oci.RuntimeConfig) error {
ctx, err := cliContextToContext(clictx)
if err != nil {
return err
}

var exps []string
for _, e := range runtimeConfig.Experimental {
exps = append(exps, e.Name)
}

ctx = exp.ContextWithExp(ctx, exps)
// Add tracer to metadata and update the context
clictx.App.Metadata["context"] = ctx
return nil
}

func afterSubcommands(c *cli.Context) error {
ctx, err := cliContextToContext(c)
if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion containerd-shim-v2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func New(ctx context.Context, id string, publisher events.Publisher) (cdshim.Shi
// it will output into stdio, from which containerd would like
// to get the shim's socket address.
logrus.SetOutput(ioutil.Discard)
opts := ctx.Value(cdshim.OptsKey{}).(cdshim.Opts)
if !opts.Debug {
logrus.SetLevel(logrus.WarnLevel)
}
vci.SetLogger(ctx, logger)
katautils.SetLogger(ctx, logger, logger.Logger.Level)

Expand Down Expand Up @@ -141,7 +145,10 @@ func newCommand(ctx context.Context, containerdBinary, id, containerdAddress str
"-address", containerdAddress,
"-publish-binary", containerdBinary,
"-id", id,
"-debug",
}
opts := ctx.Value(cdshim.OptsKey{}).(cdshim.Opts)
if opts.Debug {
args = append(args, "-debug")
}
cmd := sysexec.Command(self, args...)
cmd.Dir = cwd
Expand Down
7 changes: 7 additions & 0 deletions versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ assets:
hypervisor:
description: "Component used to create virtual machines"

cloud_hypervisor:
description: "Cloud Hypervisor is an open source Virtual Machine Monitor"
url: "https://github.com/intel/cloud-hypervisor"
uscan-url: >-
https://github.com/intel/cloud-hypervisor/tags.*/v?(\d\S+)\.tar\.gz
version: "v0.3.0"

firecracker:
description: "Firecracker micro-VMM"
url: "https://github.com/firecracker-microvm/firecracker"
Expand Down
10 changes: 3 additions & 7 deletions virtcontainers/acrn.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,15 +513,11 @@ func (a *Acrn) stopSandbox() (err error) {

pid := a.state.PID

// Check if VM process is running, in case it is not, let's
// return from here.
if err = syscall.Kill(pid, syscall.Signal(0)); err != nil {
a.Logger().Info("acrn VM already stopped")
return nil
}

// Send signal to the VM process to try to stop it properly
if err = syscall.Kill(pid, syscall.SIGINT); err != nil {
if err == syscall.ESRCH {
return nil
}
a.Logger().Info("Sending signal to stop acrn VM failed")
return err
}
Expand Down
10 changes: 9 additions & 1 deletion virtcontainers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

deviceApi "github.com/kata-containers/runtime/virtcontainers/device/api"
deviceConfig "github.com/kata-containers/runtime/virtcontainers/device/config"
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/store"
"github.com/kata-containers/runtime/virtcontainers/types"
Expand Down Expand Up @@ -307,7 +308,14 @@ func ListSandbox(ctx context.Context) ([]SandboxStatus, error) {
span, ctx := trace(ctx, "ListSandbox")
defer span.Finish()

dir, err := os.Open(store.ConfigStoragePath())
var sbsdir string
if supportNewStore(ctx) {
sbsdir = fs.RunStoragePath()
} else {
sbsdir = store.RunStoragePath()
}

dir, err := os.Open(sbsdir)
if err != nil {
if os.IsNotExist(err) {
// No sandbox directory is not an error
Expand Down
32 changes: 20 additions & 12 deletions virtcontainers/clh.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,6 @@ func (clh *cloudHypervisor) createSandbox(ctx context.Context, id string, networ
iommu: false,
})

// Add the hybrid vsock device to hypervisor
clh.cliBuilder.SetVsock(&CLIVsock{
cid: 3,
socketPath: clh.socketPath,
iommu: false,
})

// set the initial root/boot disk of hypervisor
imagePath, err := clh.config.ImageAssetPath()
if err != nil {
Expand Down Expand Up @@ -436,7 +429,18 @@ func (clh *cloudHypervisor) addDevice(devInfo interface{}, devType deviceType) e
device: v.Name(),
mac: v.HardwareAddr(),
})

case types.HybridVSock:
clh.Logger().WithFields(log.Fields{
"function": "addDevice",
"path": v.UdsPath,
"cid": v.ContextID,
"port": v.Port,
}).Info("Adding HybridVSock")
clh.cliBuilder.SetVsock(&CLIVsock{
cid: uint32(v.ContextID),
socketPath: v.UdsPath,
iommu: false,
})
default:
clh.Logger().WithField("function", "addDevice").Warnf("Add device of type %v is not supported.", v)
}
Expand Down Expand Up @@ -544,19 +548,23 @@ func (clh *cloudHypervisor) reset() {

func (clh *cloudHypervisor) generateSocket(id string, useVsock bool) (interface{}, error) {
if !useVsock {
return nil, fmt.Errorf("Can't generate socket path for cloud-hypervisor: vsocks is disabled")
return nil, fmt.Errorf("Can't generate hybrid vsocket for cloud-hypervisor: vsocks is disabled")
}

udsPath, err := clh.vsockSocketPath(id)
if err != nil {
clh.Logger().Info("Can't generate socket path for cloud-hypervisor")
return types.HybridVSock{}, err
}
clh.Logger().WithField("function", "generateSocket").Infof("Using hybrid vsock %s:%d", udsPath, vSockPort)
_, cid, err := utils.FindContextID()
if err != nil {
return nil, err
}
clh.socketPath = udsPath
return types.HybridVSock{
UdsPath: udsPath,
Port: uint32(vSockPort),
UdsPath: udsPath,
ContextID: cid,
Port: uint32(vSockPort),
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions virtcontainers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ func (c *Container) storeContainer() error {
if err := c.sandbox.Save(); err != nil {
return err
}
return nil
}
return c.store.Store(store.Configuration, *(c.config))
}
Expand Down
17 changes: 17 additions & 0 deletions virtcontainers/experimental/experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package experimental

import (
"context"
"fmt"
"regexp"
)
Expand All @@ -22,8 +23,11 @@ type Feature struct {
ExpRelease string
}

type contextKey struct{}

var (
supportedFeatures = make(map[string]Feature)
expContextKey = contextKey{}
)

// Register register a new experimental feature
Expand Down Expand Up @@ -61,3 +65,16 @@ func validateFeature(feature Feature) error {

return nil
}

func ContextWithExp(ctx context.Context, names []string) context.Context {
return context.WithValue(ctx, expContextKey, names)
}

func ExpFromContext(ctx context.Context) []string {
value := ctx.Value(expContextKey)
if value == nil {
return nil
}
names := value.([]string)
return names
}
86 changes: 78 additions & 8 deletions virtcontainers/fc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"syscall"
"time"

"github.com/containerd/fifo"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
kataclient "github.com/kata-containers/agent/protocols/client"
Expand Down Expand Up @@ -62,13 +63,16 @@ const (
// firecracker guest VM.
// We attach a pool of placeholder drives before the guest has started, and then
// 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)

// This is related to firecracker logging scheme
fcLogFifo = "logs.fifo"
fcMetricsFifo = "metrics.fifo"
)

// Specify the minimum version of firecracker supported
Expand Down Expand Up @@ -467,14 +471,11 @@ func (fc *firecracker) fcEnd() (err error) {

pid := fc.info.PID

// Check if VM process is running, in case it is not, let's
// return from here.
if err = syscall.Kill(pid, syscall.Signal(0)); err != nil {
return nil
}

// Send a SIGTERM to the VM process to try to stop it properly
if err = syscall.Kill(pid, syscall.SIGTERM); err != nil {
if err == syscall.ESRCH {
return nil
}
return err
}

Expand Down Expand Up @@ -616,6 +617,69 @@ func (fc *firecracker) fcSetVMBaseConfig(mem int64, vcpus int64, htEnabled bool)
return err
}

func (fc *firecracker) fcSetLogger() error {
span, _ := fc.trace("fcSetLogger")
defer span.Finish()

fcLogLevel := "Error"

// listen to log fifo file and transfer error info
jailedLogFifo, err := fc.fcListenToFifo(fcLogFifo)
if err != nil {
return fmt.Errorf("Failed setting log: %s", err)
}

// listen to metrics file and transfer error info
jailedMetricsFifo, err := fc.fcListenToFifo(fcMetricsFifo)
if err != nil {
return fmt.Errorf("Failed setting log: %s", err)
}

param := ops.NewPutLoggerParams()
cfg := &models.Logger{
Level: &fcLogLevel,
LogFifo: &jailedLogFifo,
MetricsFifo: &jailedMetricsFifo,
Options: []string{},
}
param.SetBody(cfg)
_, err = fc.client().Operations.PutLogger(param)

return err
}

func (fc *firecracker) fcListenToFifo(fifoName string) (string, error) {
fcFifoPath := filepath.Join(fc.vmPath, fifoName)
fcFifo, err := fifo.OpenFifo(context.Background(), fcFifoPath, syscall.O_CREAT|syscall.O_RDONLY|syscall.O_NONBLOCK, 0)
if err != nil {
return "", fmt.Errorf("Failed to open/create fifo file %s", err)
}

jailedFifoPath, err := fc.fcJailResource(fcFifoPath, fifoName)
if err != nil {
return "", err
}

go func() {
scanner := bufio.NewScanner(fcFifo)
for scanner.Scan() {
fc.Logger().WithFields(logrus.Fields{
"fifoName": fifoName,
"contents": scanner.Text()}).Error("firecracker failed")
}

if err := scanner.Err(); err != nil {
fc.Logger().WithError(err).Errorf("Failed reading firecracker fifo file")
}

if err := fcFifo.Close(); err != nil {
fc.Logger().WithError(err).Errorf("Failed closing firecracker fifo file")
}
}()

return jailedFifoPath, nil
}

func (fc *firecracker) fcStartVM() error {
fc.Logger().Info("start firecracker virtual machine")
span, _ := fc.trace("fcStartVM")
Expand Down Expand Up @@ -712,6 +776,10 @@ func (fc *firecracker) startSandbox(timeout int) error {
}
}

if err := fc.fcSetLogger(); err != nil {
return err
}

if err := fc.fcStartVM(); err != nil {
return err
}
Expand Down Expand Up @@ -772,6 +840,8 @@ func (fc *firecracker) cleanupJail() {

fc.umountResource(fcKernel)
fc.umountResource(fcRootfs)
fc.umountResource(fcLogFifo)
fc.umountResource(fcMetricsFifo)

fc.Logger().WithField("cleaningJail", fc.vmPath).Info()
if err := os.RemoveAll(fc.vmPath); err != nil {
Expand Down
Loading

0 comments on commit 7b8e15f

Please sign in to comment.