...

Source file src/github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/task.go

Documentation: github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1

     1  //go:build windows
     2  
     3  package main
     4  
     5  import (
     6  	"context"
     7  	"errors"
     8  	"time"
     9  
    10  	"github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options"
    11  	"github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/stats"
    12  	"github.com/Microsoft/hcsshim/internal/hcs"
    13  	"github.com/Microsoft/hcsshim/internal/shimdiag"
    14  	"github.com/Microsoft/hcsshim/pkg/ctrdtaskapi"
    15  	"github.com/containerd/containerd/errdefs"
    16  	"github.com/containerd/containerd/runtime/v2/task"
    17  	"github.com/opencontainers/runtime-spec/specs-go"
    18  )
    19  
    20  var (
    21  	errTaskNotIsolated              = errors.New("task is not isolated")
    22  	errNotSupportedResourcesRequest = errors.New("update resources must be of type *WindowsResources or *LinuxResources")
    23  )
    24  
    25  type shimTask interface {
    26  	// ID returns the original id used at `Create`.
    27  	ID() string
    28  	// CreateExec creates an additional exec within this task.
    29  	//
    30  	// If `req.ID==""` or `req.ID` is already a known exec this task MUST return
    31  	// `errdefs.ErrAlreadyExists`
    32  	//
    33  	// If the init exec is no longer running this task MUST return
    34  	// `errdefs.ErrFailedPrecondition`.
    35  	CreateExec(ctx context.Context, req *task.ExecProcessRequest, s *specs.Process) error
    36  	// GetExec returns an exec in this task that matches `eid`. If `eid == ""`
    37  	// returns the init exec from the initial call to `Create`.
    38  	//
    39  	// If `eid` is not found this task MUST return `errdefs.ErrNotFound`.
    40  	GetExec(eid string) (shimExec, error)
    41  	// GetExecs returns all execs in the task.
    42  	//
    43  	// If an exec fails to load, this will return an error.
    44  	ListExecs() ([]shimExec, error)
    45  	// KillExec sends `signal` to the exec that matches `eid`. If `all==true`
    46  	// `eid` MUST be empty and this task will send `signal` to all exec's in the
    47  	// task and lastly send `signal` to the init exec.
    48  	//
    49  	// If `all == true && eid != ""` this task MUST return
    50  	// `errdefs.ErrFailedPrecondition`.
    51  	//
    52  	// A call to `KillExec` is only valid when the exec is in the
    53  	// `shimExecStateRunning, shimExecStateExited` states. If the exec is not in
    54  	// this state this task MUST return `errdefs.ErrFailedPrecondition`. If
    55  	// `eid=="" && all == false` all additional exec's must be in the
    56  	// `shimExecStateExited` state.
    57  	KillExec(ctx context.Context, eid string, signal uint32, all bool) error
    58  	// DeleteExec deletes a `shimExec` in this `shimTask` that matches `eid`. If
    59  	// `eid == ""` deletes the init `shimExec` AND this `shimTask`.
    60  	//
    61  	// If `eid` is not found `shimExec` MUST return `errdefs.ErrNotFound`.
    62  	//
    63  	// A call to `DeleteExec` is only valid in `shimExecStateCreated` and
    64  	// `shimExecStateExited` states and MUST return
    65  	// `errdefs.ErrFailedPrecondition` if not in these states. If `eid==""` all
    66  	// additional exec's tracked by this task must also be in the
    67  	// `shimExecStateExited` state.
    68  	DeleteExec(ctx context.Context, eid string) (int, uint32, time.Time, error)
    69  	// Pids returns all process pid's in this `shimTask` including ones not
    70  	// created by the caller via a `CreateExec`.
    71  	Pids(ctx context.Context) ([]options.ProcessDetails, error)
    72  	// Waits for the the init task to complete.
    73  	//
    74  	// Note: If the `request.ExecID == ""` the caller should instead call `Wait`
    75  	// rather than `exec.Wait` on the init exec. This is because  the lifetime
    76  	// of the task is larger than just the init process and on shutdown we need
    77  	// to wait for the container and potentially UVM before unblocking any event
    78  	// based listeners or `Wait` based listeners.
    79  	Wait() *task.StateResponse
    80  	// ExecInHost execs a process in the host UVM. It is not tracked in the
    81  	// other lifetimes of the task and is used only for diagnostics.
    82  	//
    83  	// If the host is not hypervisor isolated returns error.
    84  	ExecInHost(ctx context.Context, req *shimdiag.ExecProcessRequest) (int, error)
    85  	// DumpGuestStacks dumps the GCS stacks associated with this task host.
    86  	//
    87  	// If the host is not hypervisor isolated returns `""`.
    88  	DumpGuestStacks(ctx context.Context) string
    89  	// Share shares a directory/file into the host UVM.
    90  	//
    91  	// If the host is not hypervisor isolated returns error.
    92  	Share(ctx context.Context, req *shimdiag.ShareRequest) error
    93  	// Stats returns various metrics for the task.
    94  	//
    95  	// If the host is hypervisor isolated and this task owns the host additional
    96  	// metrics on the UVM may be returned as well.
    97  	Stats(ctx context.Context) (*stats.Statistics, error)
    98  	// ProcessorInfo returns information on a task's compute system's processor settings
    99  	ProcessorInfo(ctx context.Context) (*processorInfo, error)
   100  	// Update updates a task's container
   101  	Update(ctx context.Context, req *task.UpdateTaskRequest) error
   102  }
   103  
   104  type processorInfo struct {
   105  	count int32
   106  }
   107  
   108  func verifyTaskUpdateResourcesType(data interface{}) error {
   109  	switch data.(type) {
   110  	case *specs.WindowsResources:
   111  	case *specs.LinuxResources:
   112  	case *ctrdtaskapi.PolicyFragment:
   113  	case *ctrdtaskapi.ContainerMount:
   114  	default:
   115  		return errNotSupportedResourcesRequest
   116  	}
   117  	return nil
   118  }
   119  
   120  // isStatsNotFound returns true if the err corresponds to a scenario
   121  // where statistics cannot be retrieved or found
   122  func isStatsNotFound(err error) bool {
   123  	return errdefs.IsNotFound(err) ||
   124  		hcs.IsNotExist(err) ||
   125  		hcs.IsOperationInvalidState(err) ||
   126  		hcs.IsAccessIsDenied(err) ||
   127  		hcs.IsErrorInvalidHandle(err)
   128  }
   129  

View as plain text