Documentation
¶
Overview ¶
Package xunix contains convenience functions for interacting with various aspects of Linux.
Index ¶
- Constants
- func Environ(ctx context.Context) []string
- func GPUEnvs(ctx context.Context) []string
- func IsNoSpaceErr(err error) bool
- func MountFS(ctx context.Context, source, mountpoint, fstype string, options ...string) error
- func Mounter(ctx context.Context) mount.Interface
- func MustLookupEnv(e string) string
- func NetlinkMTU(name string) (int, error)
- func ReadCGroupSelf(ctx context.Context) (string, error)
- func SameDirSymlinks(afs FS, target string) ([]string, error)
- func SetOOMScore(ctx context.Context, pid, score string) error
- func TryUnmountProcGPUDrivers(ctx context.Context, log slog.Logger) ([]mount.MountPoint, error)
- func WithEnvironFn(ctx context.Context, fn EnvironFn) context.Context
- func WithExecer(ctx context.Context, execer Execer) context.Context
- func WithFS(ctx context.Context, f FS) context.Context
- func WithMounter(ctx context.Context, i mount.Interface) context.Context
- type CGroup
- type CPUQuota
- type Cmd
- type Device
- type DeviceType
- type Env
- type EnvironFn
- type Execer
- type FS
- type Mount
- type User
Constants ¶
const ( CPUPeriodPathCGroupV1 = "/sys/fs/cgroup/cpu,cpuacct/cpu.cfs_period_us" CPUQuotaPathCGroupV1 = "/sys/fs/cgroup/cpu,cpuacct/cpu.cfs_quota_us" )
const (
DeviceTypeChar = "c"
)
Variables ¶
This section is empty.
Functions ¶
func IsNoSpaceErr ¶
func MustLookupEnv ¶
func NetlinkMTU ¶
func ReadCGroupSelf ¶
readCGroup attempts to determine the cgroup for the container by reading the fields of /proc/self/cgroup (third field) We currently only check the first line of /proc/self/cgroup.
func SameDirSymlinks ¶
SameDirSymlinks returns all links in the same directory as `target` that point to target, either indirectly or directly. Only symlinks in the same directory as `target` are considered.
func TryUnmountProcGPUDrivers ¶
TryUnmountProcGPUDrivers unmounts any GPU-related mounts under /proc as it causes issues when creating any container in some cases. Errors encountered while unmounting are treated as non-fatal.
Types ¶
type CPUQuota ¶
func ReadCPUQuota ¶
ReadCPUQuota attempts to read the CFS CPU quota and period from the current container context. It first attempts to read the paths relevant to cgroupv2 and falls back to reading the paths relevant go cgroupv1
Relevant paths for cgroupv2: - /proc/self/cgroup - /sys/fs/cgroup/<self>/cpu.max
Relevant paths for cgroupv1: - /sys/fs/cgroup/cpu,cpuacct/cpu.cfs_quota_us - /sys/fs/cgroup/cpu,cpuacct/cpu.cfs_period_us
type Device ¶
type DeviceType ¶
type DeviceType string
type Execer ¶
type Execer interface { // CommandContext returns a Cmd instance which can be used to run a single command. // // The provided context is used to kill the process if the context becomes done // before the command completes on its own. For example, a timeout can be set in // the context. CommandContext(ctx context.Context, cmd string, args ...string) Cmd }