cgroup

package
v0.0.0-...-195614b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NoPerms is uninitialized file/directory permissions used for task/control files.
	NoPerms = C.NO_PERMS

	// NoUIDGid in uninitialized UID/GID used for task/control files.
	NoUIDGid = C.NO_UID_GID
)
View Source
const (
	// DeleteIgnoreMigration ignore errors caused by migration of tasks to parent group.
	DeleteIgnoreMigration = DeleteFlag(C.CGFLAG_DELETE_IGNORE_MIGRATION)

	// DeleteRecursive recursively delete all child groups.
	DeleteRecursive = DeleteFlag(C.CGFLAG_DELETE_RECURSIVE)

	// DeleteEmptyOnly deletes the cgroup only if it is empty, i.e. it has no
	// subgroups and no processes inside. This flag cannot be used with DeleteRecursive
	DeleteEmptyOnly = DeleteFlag(C.CGFLAG_DELETE_EMPTY_ONLY)
)
View Source
const (
	// FileTypeFile mapping to C.CGROUP_FILE_TYPE_FILE
	FileTypeFile = FileType(C.CGROUP_FILE_TYPE_FILE)

	// FileTypeDir mapping to C.CGROUP_FILE_TYPE_DIR
	FileTypeDir = FileType(C.CGROUP_FILE_TYPE_DIR)

	// FileTypeOther mapping to C.CGROUP_FILE_TYPE_OTHER
	FileTypeOther = FileType(C.CGROUP_FILE_TYPE_OTHER)
)

Variables

View Source
var (
	// ErrEOF End-of-file for iterators
	ErrEOF = errors.New(C.GoString(C.cgroup_strerror(C.ECGEOF)))

	// ErrOther (todo)
	ErrOther = errors.New(C.GoString(C.cgroup_strerror(C.ECGOTHER)))

	// ErrRoupNotEqual (todo)
	ErrRoupNotEqual = errors.New(C.GoString(C.cgroup_strerror(C.ECGROUPNOTEQUAL)))

	// ErrControllerNotEqual (todo)
	ErrControllerNotEqual = errors.New(C.GoString(C.cgroup_strerror(C.ECGCONTROLLERNOTEQUAL)))
)

Functions

func CompareCgroup

func CompareCgroup(a, b Cgroup) error

CompareCgroup names, owners, controllers, parameters and values of two groups.

Return value of: * nil - a and b are equal * ErrRoupNotEqual - groups are not equal * ErrControllerNotEqual - controllers are not equal

func CompareControllers

func CompareControllers(a, b Controller) error

CompareControllers compares names, parameters and values of two controllers.

Return value of: * nil - a and b are equal * ErrControllerNotEqual - controllers are not equal

func CopyCgroup

func CopyCgroup(src, dest Cgroup) error

CopyCgroup all controllers, parameters and their values. All existing controllers in the source group are discarded.

func GetSubSysMountPoint

func GetSubSysMountPoint(controller string) (string, error)

GetSubSysMountPoint mount point getter

func Init

func Init() error

Init initializes libcgroup. Information about mounted hierarchies are examined and cached internally (just what's mounted where, not the groups themselves).

func LastError

func LastError() error

LastError returns last errno, which caused ErrOther error.

func LoadConfig

func LoadConfig(filename string) error

LoadConfig loads configuration file and mount and create control groups described there. See cgconfig.conf man page for format of the file.

func SetDefault

func SetDefault(cg Cgroup) error

SetDefault sets default permissions of groups created by subsequent cgroup_config_load_config() calls. If a config file contains a 'default {}' section, the default permissions from the config file is then used.

Use cgroup_new_cgroup() to create a dummy group and cgroup_set_uid_gid() and cgroup_set_permissions() to set its permissions. Use NoUIDGid instead of GID/UID and NoPerms instead of file/directory permissions to let kernel decide the default permissions where you don't want specific user and/or permissions. Kernel then uses current user/group and permissions from umask then.

New default permissions from this group are copied to libcgroup internal structures.

func Unload

func Unload() error

Unload deletes all control groups and unmount all hierarchies.

func UnloadFromConfig

func UnloadFromConfig(filename string, flags DeleteFlag) error

UnloadFromConfig deletes all cgroups and unmount all mount points defined in specified config file.

The groups are either removed recursively or only the empty ones, based on given flags. Mount point are always umounted only if they are empty, regardless of any flags.

The groups are sorted before they are removed, so the removal of empty ones actually works (i.e. subgroups are removed first).

Types

type Cgroup

type Cgroup struct {
	// contains filtered or unexported fields
}

Cgroup definition

func NewCgroup

func NewCgroup(name string) *Cgroup

NewCgroup creates new Cgroup instance

func (*Cgroup) AddController

func (cg *Cgroup) AddController(name string) (Controller, error)

AddController adds controller to cg

func (Cgroup) Create

func (cg Cgroup) Create() error

Create physically create a control group in kernel. The group is created in all hierarchies, which cover controllers added by Cgroup.AddController().

TODO correct docs for golang implementation

All parameters set by cgroup_add_value_* functions are written. The created groups has owner which was set by cgroup_set_uid_gid() and permissions set by cgroup_set_permissions.

foo = cgroup.NewCgroup("foo)
foo.Create()

func (Cgroup) CreateFromParent

func (cg Cgroup) CreateFromParent() error

CreateFromParent physically creates new control group in kernel, with all parameters and values copied from its parent group. The group is created in all hierarchies, where the parent group exists. I.e. following code creates subgroup in all hierarchies, because all of them have root (=parent) group.

foo = cgroup.NewCgroup("foo)
foo.CreateFromParent()

func (Cgroup) CreateFromParentIgnoreOwnership

func (cg Cgroup) CreateFromParentIgnoreOwnership() error

CreateFromParentIgnoreOwnership is the same as CreateFromParent(), but all errors are ignored when setting owner of the group and/or its tasks file.

func (Cgroup) CreateIgnoreOwnership

func (cg Cgroup) CreateIgnoreOwnership() error

CreateIgnoreOwnership is the same as Create(), but all errors are ignored when setting owner of the group and/or its tasks file.

func (Cgroup) Delete

func (cg Cgroup) Delete() error

Delete physically removes a control group from kernel. The group is removed from all hierarchies, which cover controllers added by Cgroup.AddController() or GetCgroup(). All tasks inside the group are automatically moved to parent group.

The group being removed must be empty, i.e. without subgroups. Use cgroup_delete_cgroup_ext() for recursive delete.

TODO correct docs for golang implementation

func (Cgroup) DeleteExt

func (cg Cgroup) DeleteExt(flags DeleteFlag) error

DeleteExt physically removes a control group from kernel. All tasks are automatically moved to parent group. If DeleteIgnoreMigration flag is used, the errors that occurred during the task movement are ignored. DeleteRecursive flag specifies that all subgroups should be removed too. If root group is being removed with this flag specified, all subgroups are removed but the root group itself is left undeleted.

func (Cgroup) DeleteIgnoreMigration

func (cg Cgroup) DeleteIgnoreMigration() error

DeleteIgnoreMigration is the same as Delete(), but ignores errors when migrating.

func (Cgroup) Get

func (cg Cgroup) Get() error

Get all information regarding the group from kernel. Based on name of the group, list of controllers and all parameters and their values are read from all hierarchies, where a group with given name exists. All existing controllers are replaced. I.e. following code will fill root with controllers from all hierarchies, because the root group is available in all of them.

root := cgroup.NewCgroup("/")
err := root.Get()

func (*Cgroup) GetController

func (cg *Cgroup) GetController(name string) Controller

GetController controller getter

func (Cgroup) GetUIDGid

func (cg Cgroup) GetUIDGid() (tasksUID UID, tasksGid GID, controlUID UID, controlGid GID, err error)

GetUIDGid returns owners of the group's @c tasks file and control files. The data is read from libcgroup internal cgroup structure, use Cgroup.SetUIDGid() or Cgroup.Get() to fill it.

func (Cgroup) Modify

func (cg Cgroup) Modify() error

Modify physically modify a control group in kernel. All parameters added by cgroup_add_value_ or cgroup_set_value_ are written. Currently it's not possible to change and owner of a group.

TODO correct docs for golang implementation

func (Cgroup) SetPermissions

func (cg Cgroup) SetPermissions(controlDperm, controlFperm, taskFperm Mode)

SetPermissions stores given file permissions of the group's control and tasks files into the cgroup data structure. Use NoPerms if permissions shouldn't be changed or a value which applicable to chmod(2). Please note that the given permissions are masked with the file owner's permissions. For example if a control file has permissions 640 and control_fperm is 471 the result will be 460.

control_dperm Directory permission for the group. control_fperm File permission for the control files. task_fperm File permissions for task file.

g := cgroup.NewCgroup("foo")
g.SetPermissions(cgroup.Mode(0777), cgroup.Mode(0777), cgroup.Mode(0777))

func (Cgroup) SetUIDGid

func (cg Cgroup) SetUIDGid(tasksUID UID, tasksGid GID,
	controlUID UID, controlGid GID) error

SetUIDGid Sets owner of the group control files and the @c tasks file. This function modifies only libcgroup internal cgroup structure, use Cgroup.Create() afterwards to create the group with given owners.

@param cgroup @param tasks_uid UID of the owner of group's @c tasks file. @param tasks_gid GID of the owner of group's @c tasks file. @param control_uid UID of the owner of group's control files (i.e. parameters). @param control_gid GID of the owner of group's control files (i.e. parameters).

type Controller

type Controller struct {
	// contains filtered or unexported fields
}

Controller structure describing a controller attached to one struct @c cgroup, including parameters of the group and their values. The structure is opaque to applications.

func (Controller) AddValueBool

func (c Controller) AddValueBool(name string, value bool) error

AddValueBool adds boolean to cgroup controller

func (Controller) AddValueInt64

func (c Controller) AddValueInt64(name string, value int64) error

AddValueInt64 adds integer value to cgroup controller

func (Controller) AddValueString

func (c Controller) AddValueString(name, value string) error

AddValueString adds parameter and its value to internal libcgroup structures. Use Cgroup.Modify() or Cgroup.Create() to write it to kernel. Name of the parameter and its value

func (Controller) GetValueBool

func (c Controller) GetValueBool(name string) (value bool, err error)

GetValueBool boolean value getter from cgroup controller

func (Controller) GetValueInt64

func (c Controller) GetValueInt64(name string) (value int64, err error)

GetValueInt64 integer value getter from cgroup controller

func (Controller) GetValueString

func (c Controller) GetValueString(name string) (value string, err error)

GetValueString uses Cgroup.Get() to fill these values with data from the kernel

func (Controller) SetValueBool

func (c Controller) SetValueBool(name string, value bool) error

SetValueBool sets boolean to cgroup controller

func (Controller) SetValueInt64

func (c Controller) SetValueInt64(name string, value int64) error

SetValueInt64 sets int64 to cgroup controller

func (Controller) SetValueString

func (c Controller) SetValueString(name, value string) error

SetValueString sets a parameter value in @c libcgroup internal structures. Use Cgroup.Modify() or Cgroup.Create() to write it to kernel.

func (Controller) SetValueUint64

func (c Controller) SetValueUint64(name string, value uint64) error

SetValueUint64 sets uint64 to cgroup controller

type ControllerData

type ControllerData struct {
	Name       string
	Hierarchy  int
	NumCgroups int
	Enabled    int
}

ControllerData defenition

func GetAllControllers

func GetAllControllers() (controllers []ControllerData, err error)

GetAllControllers returns all available controllers

type DeleteFlag

type DeleteFlag int

DeleteFlag defenition

type FileInfo

type FileInfo struct {
	Type     FileType
	Path     string
	Parent   string
	FullPath string
	Depth    int8
}

FileInfo definition

type FileType

type FileType int

FileType definition

type GID

type GID C.gid_t

GID map C type gid_t

type Mode

type Mode C.mode_t

Mode map C type mode_t

type UID

type UID C.uid_t

UID map C type uid_t

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL