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
- Variables
- func Proxy(ctx context.Context, socket, addr string) error
- func Run(ctx context.Context, configPath string, log io.Writer) error
- func Serve(ctx context.Context, conn net.Conn, handle Handler) error
- type CUDARestoreArgs
- type CUDAResult
- type Client
- type Config
- type DumpResult
- type FSResult
- type FSTree
- type Final
- type FreezeResult
- type Handler
- type IPCRestoreArgs
- type IPCResult
- type Request
- type Response
- type RestoreResult
- type Status
- type StepError
- type Tree
Constants ¶
const ( ModeSnapshot = "snapshot" ModeRestore = "restore" )
Modes of the agent.
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.
const Grace = 20 * time.Second
Grace is how long a stopping engine gets before the container goes.
const MaxLine = 16 << 20
MaxLine bounds one protocol line.
Variables ¶
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.
var ErrPoisoned = errors.New("an earlier step failed")
ErrPoisoned is reported for every step after a failed one.
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 ¶
Types ¶
type CUDARestoreArgs ¶
type CUDARestoreArgs struct {
Owners []int `json:"owners"`
Parallel []int `json:"parallel,omitempty"`
Concurrent bool `json:"concurrent,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"`
Phases map[string]float64 `json:"phases,omitempty"`
Backend string `json:"backend,omitempty"`
}
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.
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"`
// CUDABackend moves CUDA state through libcuda's checkpoint API in the
// agent (driver), cuda-checkpoint (cli), or the first that works here
// (auto, the default).
CUDABackend string `json:"cuda_backend,omitempty"`
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 ¶
ReadConfig loads and checks a config file.
type DumpResult ¶
DumpResult reports the CRIU dump.
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 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 ¶
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.