Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/containerd-shim-runhcs-v1/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func createPod(ctx context.Context, events publisher, req *task.CreateTaskReques
}
// LCOW (and WCOW Process Isolated for the time being) requires a real
// task for the sandbox.
lt, err := newHcsTask(ctx, events, parent, true, req, s)
lt, err := newHcsTask(ctx, events, parent, true, req, s, req.ID)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -408,7 +408,7 @@ func (p *pod) CreateTask(ctx context.Context, req *task.CreateTaskRequest, s *sp
sid)
}

st, err := newHcsTask(ctx, p.events, p.host, false, req, s)
st, err := newHcsTask(ctx, p.events, p.host, false, req, s, p.id)
if err != nil {
return nil, err
}
Expand Down
10 changes: 7 additions & 3 deletions cmd/containerd-shim-runhcs-v1/task_hcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func newHcsStandaloneTask(ctx context.Context, events publisher, req *task.Creat
return nil, errors.Wrap(errdefs.ErrFailedPrecondition, "oci spec does not contain WCOW or LCOW spec")
}

shim, err := newHcsTask(ctx, events, parent, true, req, s)
shim, err := newHcsTask(ctx, events, parent, true, req, s, req.ID)
if err != nil {
if parent != nil {
parent.Close()
Expand All @@ -126,6 +126,7 @@ func createContainer(
parent *uvm.UtilityVM,
shimOpts *runhcsopts.Options,
rootfs []*types.Mount,
sandboxID string,
) (cow.Container, *resources.Resources, error) {
var (
err error
Expand Down Expand Up @@ -157,6 +158,7 @@ func createContainer(
} else {
opts := &hcsoci.CreateOptions{
ID: id,
SandboxID: sandboxID,
Owner: owner,
Spec: s,
HostingSystem: parent,
Expand Down Expand Up @@ -186,7 +188,9 @@ func newHcsTask(
parent *uvm.UtilityVM,
ownsParent bool,
req *task.CreateTaskRequest,
s *specs.Spec) (_ shimTask, err error) {
s *specs.Spec,
sandboxID string,
) (_ shimTask, err error) {
log.G(ctx).WithFields(logrus.Fields{
"tid": req.ID,
"ownsParent": ownsParent,
Expand Down Expand Up @@ -219,7 +223,7 @@ func newHcsTask(
return nil, err
}

container, resources, err := createContainer(ctx, req.ID, owner, netNS, s, parent, shimOpts, req.Rootfs)
container, resources, err := createContainer(ctx, req.ID, owner, netNS, s, parent, shimOpts, req.Rootfs, sandboxID)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/guestpath/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package guestpath
const (
// LCOWRootPrefixInUVM is the path inside UVM where LCOW container's root
// file system will be mounted
LCOWRootPrefixInUVM = "/run/gcs/c"
LCOWRootPrefixInUVM = "/run/gcs/pods"
// WCOWRootPrefixInUVM is the path inside UVM where WCOW container's root
// file system will be mounted
WCOWRootPrefixInUVM = `C:\c`
Expand Down
17 changes: 17 additions & 0 deletions internal/hcs/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type System struct {
exitError error
os, typ, owner string
startTime time.Time
stopTime time.Time
}

var _ cow.Container = &System{}
Expand Down Expand Up @@ -291,6 +292,7 @@ func (computeSystem *System) waitBackground() {
err = makeSystemError(computeSystem, operation, err, nil)
}
computeSystem.closedWaitOnce.Do(func() {
computeSystem.stopTime = time.Now()
computeSystem.waitError = err
close(computeSystem.waitBlock)
})
Expand Down Expand Up @@ -333,6 +335,21 @@ func (computeSystem *System) stopped() bool {
return false
}

// Stopped returns true if the compute system is in stopped state.
func (computeSystem *System) Stopped() bool {
return computeSystem.stopped()
}

// StartTime returns the time at which the compute system started.
func (computeSystem *System) StartTime() time.Time {
return computeSystem.startTime
}

// StopTime returns the time at which the compute system stopped.
func (computeSystem *System) StopTime() time.Time {
return computeSystem.stopTime
}

// ExitError returns an error describing the reason the compute system terminated.
func (computeSystem *System) ExitError() error {
if !computeSystem.stopped() {
Expand Down
7 changes: 5 additions & 2 deletions internal/hcsoci/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

var (
lcowRootInUVM = guestpath.LCOWRootPrefixInUVM + "/%s"
lcowRootInUVM = guestpath.LCOWRootPrefixInUVM + "/%s/%s"
wcowRootInUVM = guestpath.WCOWRootPrefixInUVM + "/%s"
)

Expand All @@ -43,6 +43,7 @@ var (
type CreateOptions struct {
// Common parameters
ID string // Identifier for the container
SandboxID string // Identifier for the pod of this container.
Owner string // Specifies the owner. Defaults to executable name.
Spec *specs.Spec // Definition of the container or utility VM being created
SchemaVersion *hcsschema.Version // Requested Schema Version. Defaults to v2 for RS5, v1 for RS1..RS4
Expand Down Expand Up @@ -205,7 +206,9 @@ func CreateContainer(ctx context.Context, createOptions *CreateOptions) (_ cow.C

if coi.HostingSystem != nil {
if coi.Spec.Linux != nil {
r.SetContainerRootInUVM(fmt.Sprintf(lcowRootInUVM, coi.ID))
// The container root within the UVM would be as below-
// <Root Dir>/pods/<PodID>/<ContainerID>
r.SetContainerRootInUVM(fmt.Sprintf(lcowRootInUVM, coi.SandboxID, coi.ID))
} else {
n := coi.HostingSystem.ContainerCounter()
r.SetContainerRootInUVM(fmt.Sprintf(wcowRootInUVM, strconv.FormatUint(n, 16)))
Expand Down
13 changes: 13 additions & 0 deletions internal/hcsoci/hcsdoc_lcow.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ func createLCOWSpec(ctx context.Context, coi *createOptionsInternal) (*specs.Spe
// Hooks are not supported (they should be run in the host)
spec.Hooks = nil

// Set default CPU period and quota if not set for LCOW containers.
if spec.Linux != nil &&
spec.Linux.Resources != nil &&
spec.Linux.Resources.CPU != nil {

if spec.Linux.Resources.CPU.Period != nil && *spec.Linux.Resources.CPU.Period == 0 {
*spec.Linux.Resources.CPU.Period = 100000 // Default CPU period
}
if spec.Linux.Resources.CPU.Quota != nil && *spec.Linux.Resources.CPU.Quota == 0 {
*spec.Linux.Resources.CPU.Quota = -1 // No CPU limit
}
}

// Clear unsupported features
spec.Linux.CgroupsPath = "" // GCS controls its cgroups hierarchy on its own.
if spec.Linux.Resources != nil {
Expand Down
Loading