agent

package
v2.0.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package agent is PID 1 of the donor and receiver containers. The host drives it through a fixed sequence of steps over a unix socket; this file is the wire protocol: one JSON object per line, requests carrying an id and a step name, responses echoing the id. There is no journal and no replay: after a failed step the agent refuses every further one and the host removes the container.

Index

Constants

View Source
const (
	ModeSnapshot = "snapshot"
	ModeRestore  = "restore"
)

Modes of the agent.

View Source
const CoordinatorTimeout = 5 * time.Minute

CoordinatorTimeout bounds one cuInterpose checkpoint or restore: it moves the shared allocations' bytes, tens to hundreds of MiB per process.

View Source
const Grace = 20 * time.Second

Grace is how long a stopping engine gets before the container goes.

View Source
const MaxLine = 16 << 20

MaxLine bounds one protocol line.

Variables

View Source
var DefaultTrees = []Tree{
	{Name: "workspace", Path: "/workspace"},
	{Name: "tmp", Path: "/tmp"},
	{Name: "shm", Path: "/dev/shm"},
}

DefaultTrees are what an engine writes after the image: compile and JIT caches under /workspace, scratch in /tmp, shared memory in /dev/shm.

View Source
var ErrPoisoned = errors.New("an earlier step failed")

ErrPoisoned is reported for every step after a failed one.

View Source
var Steps = map[string][]string{
	ModeSnapshot: {"ipc", "cuda", "freeze", "dump", "fs", "finish"},
	ModeRestore:  {"install-fs", "criu", "thaw", "cuda", "ipc"},
}

Steps are the agent's fixed sequences. A step may be skipped, never repeated or run out of order; "status" is allowed at any time.

Functions

func Proxy

func Proxy(ctx context.Context, socket, addr string) error

Proxy bridges connections on a unix socket to a TCP address until ctx ends.

func Run

func Run(ctx context.Context, configPath string, log io.Writer) error

Run serves the control socket until a snapshot session finishes or a restored engine exits. It is the container's main process, under docker-init, or in a pod a child of an in-place `warmctl up` under tini.

func Serve

func Serve(ctx context.Context, conn net.Conn, handle Handler) error

Serve answers requests on conn until the peer closes it. The first failed step poisons the session: later steps get ErrPoisoned without running.

Types

type CUDARestoreArgs

type CUDARestoreArgs struct {
	Owners    []int  `json:"owners"`
	Parallel  []int  `json:"parallel,omitempty"`
	DeviceMap string `json:"device_map"`
}

CUDARestoreArgs drive the restore's cuda step.

type CUDAResult

type CUDAResult struct {
	Owners  []int   `json:"owners"`
	Seconds float64 `json:"seconds"`
}

CUDAResult lists the processes whose CUDA state moved.

type Client

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

Client sends steps over one connection, one at a time.

func NewClient

func NewClient(conn net.Conn) *Client

NewClient wraps a connected socket.

func (*Client) Call

func (c *Client) Call(ctx context.Context, step string, args, result any) error

Call runs step with args and decodes the agent's result into result, which may be nil. Cancelling ctx aborts the wait.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection.

type Config

type Config struct {
	Mode string `json:"mode"`
	// Control is the unix socket the host drives the agent through.
	Control string `json:"control"`
	// Inference, when set, is a unix socket bridged to EngineAddr: the
	// container has no network, the engine listens on its loopback.
	Inference  string `json:"inference,omitempty"`
	EngineAddr string `json:"engine_addr,omitempty"`
	CRIU       string `json:"criu"`
	// CUDACheckpoint is NVIDIA's cuda-checkpoint.
	CUDACheckpoint string `json:"cuda_checkpoint"`
	Trees          []Tree `json:"trees"`
	// Watch are paths the freeze step looks for among the tree's open
	// files and mappings, so the host knows which mounts a restore needs.
	Watch []string `json:"watch,omitempty"`
	// IPC is the profile's resolved ipc: native, interpose or auto. Under
	// interpose or auto the snapshot agent may start the engine under
	// cuInterpose (docs/interpose.md); IPCCoordinator runs its checkpoints.
	IPC            string `json:"ipc,omitempty"`
	IPCCoordinator string `json:"ipc_coordinator,omitempty"`
	// Hostname, when set, is the host name the agent gives the UTS
	// namespace of its own it was started in, before anything runs: a
	// restore in place, where the container's host name is the pod's (or,
	// with hostNetwork, the node's) and the engine ran under a receiver's.
	Hostname string `json:"hostname,omitempty"`

	// Snapshot: the engine to start and where results go.
	Argv []string `json:"argv,omitempty"`
	Env  []string `json:"env,omitempty"`
	Dir  string   `json:"dir,omitempty"`
	Log  string   `json:"log,omitempty"`
	Out  string   `json:"out,omitempty"`

	// Restore: where the snapshot is and which tree to expect.
	Images string `json:"images,omitempty"`
	FS     string `json:"fs,omitempty"`
	Work   string `json:"work,omitempty"`
	Root   int    `json:"root,omitempty"`
	MaxID  int    `json:"max_id,omitempty"`
}

Config is the agent's whole input, written by the host into the read-only control directory.

func ReadConfig

func ReadConfig(name string) (Config, error)

ReadConfig loads and checks a config file.

func (Config) Validate

func (c Config) Validate() error

Validate checks the fields the mode needs.

func (Config) Write

func (c Config) Write(name string) error

Write stores the config.

type DumpResult

type DumpResult struct {
	Seconds float64 `json:"seconds"`
	Version string  `json:"criu_version"`
}

DumpResult reports the CRIU dump.

type FSResult

type FSResult struct {
	Trees   []FSTree `json:"trees"`
	Seconds float64  `json:"seconds"`
}

FSResult reports the trees.

type FSTree

type FSTree struct {
	Name    string `json:"name"`
	Path    string `json:"path"`
	Entries int    `json:"entries"`
	Bytes   int64  `json:"bytes"`
}

FSTree is one archived or installed tree.

type Final

type Final struct{ Result any }

Final wraps a step's result to end the session once the answer is sent.

type FreezeResult

type FreezeResult struct {
	Tree       criu.Tree      `json:"tree"`
	References map[string]int `json:"references"`
}

FreezeResult is the stopped tree and how many of its open files and mappings sit under each watched path.

type Handler

type Handler func(ctx context.Context, step string, args json.RawMessage) (any, error)

Handler runs one step and returns its JSON-encodable result.

type IPCRestoreArgs

type IPCRestoreArgs struct {
	Processes []int `json:"processes"`
}

IPCRestoreArgs drive the restore's ipc step: the processes the coordinator prepared.

type IPCResult

type IPCResult struct {
	Interposed bool   `json:"interposed"`
	Reason     string `json:"reason,omitempty"`
	// Participants are the processes the coordinator prepared.
	Participants []int   `json:"participants,omitempty"`
	Seconds      float64 `json:"seconds"`
}

IPCResult reports the cross-process memory step: whether the engine runs under cuInterpose and why.

type Request

type Request struct {
	ID   int64           `json:"id"`
	Step string          `json:"step"`
	Args json.RawMessage `json:"args,omitempty"`
}

Request asks the agent to run one step.

type Response

type Response struct {
	ID     int64           `json:"id"`
	OK     bool            `json:"ok"`
	Result json.RawMessage `json:"result,omitempty"`
	Error  string          `json:"error,omitempty"`
}

Response answers the request with the same id.

type RestoreResult

type RestoreResult struct {
	Tree    criu.Tree `json:"tree"`
	Seconds float64   `json:"seconds"`
}

RestoreResult reports the CRIU restore.

type Status

type Status struct {
	Mode      string `json:"mode"`
	Step      string `json:"step"`
	EnginePID int    `json:"engine_pid"`
	Running   bool   `json:"running"`
	Exit      string `json:"exit,omitempty"`
	Failed    string `json:"failed,omitempty"`
}

Status answers "status" at any time.

type StepError

type StepError struct {
	Step    string
	Message string
}

StepError is a step's failure as the agent reported it.

func (*StepError) Error

func (e *StepError) Error() string

type Tree

type Tree struct {
	Name string `json:"name"`
	Path string `json:"path"`
}

Tree is a directory the snapshot carries as a runtimefs archive.

Jump to

Keyboard shortcuts

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