github.com/opencontainers/runc@v1.2.0-rc.1.0.20240520010911-492dc558cdd6/libcontainer/cgroups/cgroups.go (about)

     1  package cgroups
     2  
     3  import (
     4  	"errors"
     5  
     6  	"github.com/opencontainers/runc/libcontainer/configs"
     7  )
     8  
     9  var (
    10  	// ErrDevicesUnsupported is an error returned when a cgroup manager
    11  	// is not configured to set device rules.
    12  	ErrDevicesUnsupported = errors.New("cgroup manager is not configured to set device rules")
    13  
    14  	// DevicesSetV1 and DevicesSetV2 are functions to set devices for
    15  	// cgroup v1 and v2, respectively. Unless
    16  	// [github.com/opencontainers/runc/libcontainer/cgroups/devices]
    17  	// package is imported, it is set to nil, so cgroup managers can't
    18  	// manage devices.
    19  	DevicesSetV1 func(path string, r *configs.Resources) error
    20  	DevicesSetV2 func(path string, r *configs.Resources) error
    21  )
    22  
    23  type Manager interface {
    24  	// Apply creates a cgroup, if not yet created, and adds a process
    25  	// with the specified pid into that cgroup.  A special value of -1
    26  	// can be used to merely create a cgroup.
    27  	Apply(pid int) error
    28  
    29  	// GetPids returns the PIDs of all processes inside the cgroup.
    30  	GetPids() ([]int, error)
    31  
    32  	// GetAllPids returns the PIDs of all processes inside the cgroup
    33  	// any all its sub-cgroups.
    34  	GetAllPids() ([]int, error)
    35  
    36  	// GetStats returns cgroups statistics.
    37  	GetStats() (*Stats, error)
    38  
    39  	// Freeze sets the freezer cgroup to the specified state.
    40  	Freeze(state configs.FreezerState) error
    41  
    42  	// Destroy removes cgroup.
    43  	Destroy() error
    44  
    45  	// Path returns a cgroup path to the specified controller/subsystem.
    46  	// For cgroupv2, the argument is unused and can be empty.
    47  	Path(string) string
    48  
    49  	// Set sets cgroup resources parameters/limits. If the argument is nil,
    50  	// the resources specified during Manager creation (or the previous call
    51  	// to Set) are used.
    52  	Set(r *configs.Resources) error
    53  
    54  	// GetPaths returns cgroup path(s) to save in a state file in order to
    55  	// restore later.
    56  	//
    57  	// For cgroup v1, a key is cgroup subsystem name, and the value is the
    58  	// path to the cgroup for this subsystem.
    59  	//
    60  	// For cgroup v2 unified hierarchy, a key is "", and the value is the
    61  	// unified path.
    62  	GetPaths() map[string]string
    63  
    64  	// GetCgroups returns the cgroup data as configured.
    65  	GetCgroups() (*configs.Cgroup, error)
    66  
    67  	// GetFreezerState retrieves the current FreezerState of the cgroup.
    68  	GetFreezerState() (configs.FreezerState, error)
    69  
    70  	// Exists returns whether the cgroup path exists or not.
    71  	Exists() bool
    72  
    73  	// OOMKillCount reports OOM kill count for the cgroup.
    74  	OOMKillCount() (uint64, error)
    75  
    76  	// GetEffectiveCPUs returns the effective CPUs of the cgroup, an empty
    77  	// value means that the cgroups cpuset subsystem/controller is not enabled.
    78  	GetEffectiveCPUs() string
    79  }