xunix

package
v0.0.0-...-0f74808 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

Package xunix contains convenience functions for interacting with various aspects of Linux.

Index

Constants

View Source
const (
	CPUPeriodPathCGroupV1 = "/sys/fs/cgroup/cpu,cpuacct/cpu.cfs_period_us"
	CPUQuotaPathCGroupV1  = "/sys/fs/cgroup/cpu,cpuacct/cpu.cfs_quota_us"
)
View Source
const (
	DeviceTypeChar = "c"
)

Variables

This section is empty.

Functions

func Environ

func Environ(ctx context.Context) []string

func GPUEnvs

func GPUEnvs(ctx context.Context) []string

func IsNoSpaceErr

func IsNoSpaceErr(err error) bool

func MountFS

func MountFS(ctx context.Context, source, mountpoint, fstype string, options ...string) error

func Mounter

func Mounter(ctx context.Context) mount.Interface

func MustLookupEnv

func MustLookupEnv(e string) string

func NetlinkMTU

func NetlinkMTU(name string) (int, error)

func ReadCGroupSelf

func ReadCGroupSelf(ctx context.Context) (string, error)

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 SetOOMScore

func SetOOMScore(ctx context.Context, pid, score string) error

func TryUnmountProcGPUDrivers

func TryUnmountProcGPUDrivers(ctx context.Context, log slog.Logger) ([]mount.MountPoint, error)

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.

func WithEnvironFn

func WithEnvironFn(ctx context.Context, fn EnvironFn) context.Context

func WithExecer

func WithExecer(ctx context.Context, execer Execer) context.Context

func WithFS

func WithFS(ctx context.Context, f FS) context.Context

func WithMounter

func WithMounter(ctx context.Context, i mount.Interface) context.Context

Types

type CGroup

type CGroup int
const (
	CGroupV1 CGroup = iota
	CGroupV2
)

func (CGroup) String

func (c CGroup) String() string

type CPUQuota

type CPUQuota struct {
	Quota  int
	Period int
	CGroup CGroup
}

func ReadCPUQuota

func ReadCPUQuota(ctx context.Context, log slog.Logger) (CPUQuota, error)

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 Cmd

type Cmd interface {
	utilexec.Cmd
	OSProcess() *os.Process
}

type Device

type Device struct {
	Path     string
	Type     string
	Major    int64
	Minor    int64
	FileMode os.FileMode
	UID      int32
	GID      int32
}

func CreateFuseDevice

func CreateFuseDevice(ctx context.Context, path string) (Device, error)

func CreateTUNDevice

func CreateTUNDevice(ctx context.Context, path string) (Device, error)

func GPUs

func GPUs(ctx context.Context, log slog.Logger, usrLibDir string) ([]Device, []mount.MountPoint, error)

type DeviceType

type DeviceType string

type Env

type Env struct {
	Name  string
	Value string
}

func (Env) String

func (e Env) String() string

type EnvironFn

type EnvironFn func() []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
}

func GetExecer

func GetExecer(ctx context.Context) Execer

type FS

type FS interface {
	afero.Fs
	Mknod(path string, mode uint32, dev int) error
	LStat(path string) (fs.FileInfo, error)
	Readlink(path string) (string, error)
}

func GetFS

func GetFS(ctx context.Context) FS

type Mount

type Mount struct {
	Source     string
	Mountpoint string
	ReadOnly   bool
}

type User

type User struct {
	user.User
	Shell string
}

User is a linux user from /etc/passwd. It is basically a user.User with addition of the user's shell.

func ParsePasswd

func ParsePasswd(r io.Reader) ([]*User, error)

ParsePasswd parses user entries from an /etc/passwd.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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