How checkpoint-restore/go-criu works
Project Type and Purpose
• go-criu is primarily a Go library exposing bindings for the CRIU checkpoint/restore daemon (“criu”), plus ancillary tools:
• A CRIU RPC client (core “go-criu” package)
• The “crit” package for reading/writing CRIU image files, plus a CLI tool (“crit” binary)
• The “phaul” package implementing the PHaul image‐streaming protocol (server & client)
• Support packages (“stats” for metrics, “magic” for file‐type detection, utility shims)
• Code‐generation scripts for Protobuf and magic data
High‐Level Components
• External CRIU Daemon
• go-criu Core Library
• RPC Layer (rpc/rpc.proto → rpc/rpc.pb.go)
• Crit Library (crit/*.go)
• PHaul API (phaul/*.go)
• Stats Package (stats/*.proto, stats/*.go)
• Magic Package (magic/magic.go)
• Utility Shims (utils/*.go)
• Binaries
• crit CLI (crit/cmd/main.go + crit/cli)
• phaul Server (phaul/server.go)
• phaul Client (phaul/client.go) – can be embedded in user apps
• Top‐level main.go (if present)
• Build & Codegen
• scripts/proto-gen (generates .pb.go from .proto)
• scripts/magic-gen (generates magic data)
• Tests & Examples (test/*)
Relationships & Data Flows
• User’s Go application → imports go-criu → invokes MakeCriu() → RPC Layer → UNIX socket/TCP → External CRIU Daemon
• crit CLI → Crit Library → reads/writes image files on disk
• phaul Client ↔ phaul Server → streams image data → Server uses go-criu RPC layer → CRIU Daemon
• Stats package can be used by user code or server to collect and serialize metrics (via Protobuf)
• Codegen scripts run offline or during CI to keep .pb.go files up to date
Architectural Patterns & Design Principles
• Layered Architecture:
• Presentation layer: CLI binaries & user applications
• Library layer: core go-criu packages (RPC, Crit, PHaul, Stats, Magic)
• External layer: CRIU daemon, filesystem (image files), network (RPC & PHaul streams)
• Separation of Concerns:
• RPC protocol handling is isolated under rpc/
• Image encoding/decoding under crit/
• Streaming protocol under phaul/
• Codegen decoupled into scripts/
• Use of Protobuf for cross‐language contracts (rpc.proto, stats.proto)