2015-05-14 06:42:16 +08:00
|
|
|
// +build linux
|
|
|
|
|
2014-05-15 06:21:44 +08:00
|
|
|
package cgroups
|
|
|
|
|
|
|
|
import (
|
2014-08-21 01:32:01 +08:00
|
|
|
"fmt"
|
2014-02-18 07:14:30 +08:00
|
|
|
|
2015-06-22 10:29:59 +08:00
|
|
|
"github.com/opencontainers/runc/libcontainer/configs"
|
2014-05-15 06:21:44 +08:00
|
|
|
)
|
|
|
|
|
2015-01-13 05:54:00 +08:00
|
|
|
type Manager interface {
|
2016-03-25 11:11:48 +08:00
|
|
|
// Applies cgroup configuration to the process with the specified pid
|
2015-01-13 05:54:00 +08:00
|
|
|
Apply(pid int) error
|
|
|
|
|
2015-01-14 23:23:42 +08:00
|
|
|
// Returns the PIDs inside the cgroup set
|
2015-01-13 05:54:00 +08:00
|
|
|
GetPids() ([]int, error)
|
2015-01-14 23:23:42 +08:00
|
|
|
|
2016-01-09 03:37:18 +08:00
|
|
|
// Returns the PIDs inside the cgroup set & all sub-cgroups
|
|
|
|
GetAllPids() ([]int, error)
|
|
|
|
|
2015-01-14 23:23:42 +08:00
|
|
|
// Returns statistics for the cgroup set
|
2015-01-13 05:54:00 +08:00
|
|
|
GetStats() (*Stats, error)
|
|
|
|
|
2015-01-14 23:23:42 +08:00
|
|
|
// Toggles the freezer cgroup according with specified state
|
2015-02-01 11:56:27 +08:00
|
|
|
Freeze(state configs.FreezerState) error
|
2015-01-13 19:52:14 +08:00
|
|
|
|
2015-01-14 23:23:42 +08:00
|
|
|
// Destroys the cgroup set
|
|
|
|
Destroy() error
|
|
|
|
|
2017-01-03 22:40:12 +08:00
|
|
|
// The option func SystemdCgroups() and Cgroupfs() require following attributes:
|
2015-01-14 23:23:42 +08:00
|
|
|
// Paths map[string]string
|
2017-01-03 22:40:12 +08:00
|
|
|
// Cgroups *configs.Cgroup
|
2015-01-14 23:23:42 +08:00
|
|
|
// Paths maps cgroup subsystem to path at which it is mounted.
|
|
|
|
// Cgroups specifies specific cgroup settings for the various subsystems
|
|
|
|
|
|
|
|
// Returns cgroup paths to save in a state file and to be able to
|
|
|
|
// restore the object later.
|
2015-01-13 05:54:00 +08:00
|
|
|
GetPaths() map[string]string
|
2015-02-25 17:20:01 +08:00
|
|
|
|
2016-09-09 16:18:54 +08:00
|
|
|
// Sets the cgroup as configured.
|
2015-02-25 17:20:01 +08:00
|
|
|
Set(container *configs.Config) error
|
2015-01-13 05:54:00 +08:00
|
|
|
}
|
|
|
|
|
2014-08-21 01:32:01 +08:00
|
|
|
type NotFoundError struct {
|
|
|
|
Subsystem string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *NotFoundError) Error() string {
|
|
|
|
return fmt.Sprintf("mountpoint for %s not found", e.Subsystem)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewNotFoundError(sub string) error {
|
|
|
|
return &NotFoundError{
|
|
|
|
Subsystem: sub,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsNotFound(err error) bool {
|
|
|
|
if err == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
_, ok := err.(*NotFoundError)
|
|
|
|
return ok
|
|
|
|
}
|