Documentation
¶
Overview ¶
Package criu drives CRIU around a process tree: freeze it with pidfds, dump it with link remaps and an empty plugin directory (GPU state is cuda-checkpoint's business, never CRIU's), restore it left stopped in a fresh PID namespace, thaw it. The namespace's PID allocator is moved so a restored PID never collides with the receiver's own processes.
Index ¶
- Constants
- Variables
- func Dump(ctx context.Context, program, version string, tree int, images, work string) error
- func DumpArgs(tree int, images, work string, skipLock bool) []string
- func PrepareRestorePIDs(maxID int) error
- func PrepareWork(dir string) error
- func ReservePIDFloor() error
- func Restore(ctx context.Context, program, images, work string) (int, error)
- func RestoreArgs(images, work string) []string
- func SkipsNetworkLock(version string) bool
- type Frozen
- type Process
- type Tree
Constants ¶
const GhostLimit = 64 << 20
GhostLimit is how large a deleted-but-open file CRIU may carry inside its images instead of as a link remap next to the original.
const PIDFloor = 32768
PIDFloor is the first PID of a snapshotted tree. The donor namespace is moved there before the engine starts; a receiver keeps its own processes (PID 1, CRIU, helpers) below it.
const Timeout = 10 * time.Minute
Timeout bounds one CRIU invocation.
Variables ¶
var ErrNotIsolated = errors.New("criu: refusing to move the PID allocator outside a container")
ErrNotIsolated is returned when a namespace-wide operation would touch the host's PID namespace.
Functions ¶
func Dump ¶
Dump checkpoints the tree rooted at tree into images with the CRIU at program, whose version is version (criu --version). CRIU kills the tree afterwards; the caller reaps it.
func DumpArgs ¶
DumpArgs is the qualified dump invocation: shell job, file locks, external unix sockets, established TCP, link remaps for deleted files, and a plugin directory that is empty on purpose.
With skipLock the dump records network-lock method skip, which restore then follows. Every TCP connection of the engine joins two processes of the frozen tree over the container's loopback, so a lock guards nothing; and with iptables, the default, restore runs `iptables -D` once per connection against rules that only ever existed in the donor's network namespace: 280 failing runs, 0.8-1.7 s, for a TP4 engine.
func PrepareRestorePIDs ¶
PrepareRestorePIDs checks that nothing in the receiver namespace occupies a PID the dump needs and moves the allocator above the dumped tree, so CRIU's helpers never take a PID the tree wants back.
func PrepareWork ¶
PrepareWork creates a fresh work directory with the empty plugin directory CRIU is pointed at. Reusing one would hide an older log.
func ReservePIDFloor ¶
func ReservePIDFloor() error
ReservePIDFloor moves the namespace's PID allocator just below PIDFloor, so everything started after it gets a PID a receiver can honour.
func RestoreArgs ¶
RestoreArgs restores detached and leaves every task stopped, so the receiver can re-attach the GPUs before anything runs.
func SkipsNetworkLock ¶
SkipsNetworkLock reports whether a CRIU of this version (criu --version, "4.2.1") takes --network-lock skip; the 4 series all do.
Types ¶
type Frozen ¶
type Frozen struct {
Tree Tree
// contains filtered or unexported fields
}
Frozen is a stopped tree held through pidfds, so a signal reaches the process it was meant for even if its PID has been reused.
func Freeze ¶
Freeze stops root and every descendant with SIGSTOP in rounds until no new process appears, then waits for every thread to be stopped. A process that forks between rounds is caught by the next one; a stopped process cannot fork at all.
func RestoreStopped ¶
func RestoreStopped(ctx context.Context, program, images, work string, expectedRoot, maxID int) (*Frozen, error)
RestoreStopped runs as PID 1 of a fresh namespace: it moves the PID allocator above the dumped tree, restores the images with every task left stopped, checks the root PID is the expected one and holds the tree through pidfds until Thaw.
func (*Frozen) RootFD ¶
RootFD is the pidfd of the tree's root; it becomes readable when the root exits.
type Process ¶
type Process struct {
PID int `json:"pid"`
Parent int `json:"parent"`
Threads []int `json:"threads"`
Start string `json:"start"`
}
Process is one process of a tree with its threads and start ticks.
type Tree ¶
Tree is a process and its descendants, root first, then by PID.
func VisibleTree ¶
VisibleTree is root and its descendants as /proc shows them now.