banger/internal/daemon/doc.go
Thales Maciel 59f2766139
Move subsystem state/locks off Daemon into owning types
Daemon no longer owns a coarse mu shared across unrelated concerns.
Each subsystem now carries its own state and lock:

- tapPool: entries, next, and mu move onto a new tapPool struct.
- sessionRegistry: sessionControllers + its mutex move off Daemon.
- opRegistry[T asyncOp]: generic registry collapses the two ad-hoc
  vm-create and image-build operation maps (and their mutexes) into one
  shared type; the Begin/Status/Cancel/Prune methods simplify.
- vmLockSet: the sync.Map of per-VM mutexes moves into its own type;
  lockVMID forwards.
- Daemon.mu splits into imageOpsMu (image-registry mutations) and
  createVMMu (CreateVM serialisation) so image ops and VM creates no
  longer block each other.

Lock ordering collapses to vmLocks[id] -> {createVMMu, imageOpsMu} ->
subsystem-local leaves. doc.go and ARCHITECTURE.md updated.

No behavior change; tests green.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-15 15:58:33 -03:00

61 lines
2.4 KiB
Go

// Package daemon hosts the Banger daemon process.
//
// The daemon exposes a JSON-RPC endpoint over a Unix socket and, optionally,
// a local web UI. It owns VM lifecycle, image management, guest sessions,
// host networking bootstrap, and state persistence via internal/store.
//
// The package is organised into cohesive groups. A phased refactor is
// splitting each group into a subpackage; file names below reflect the
// current (in-progress) grouping.
//
// VM lifecycle:
//
// vm_create.go CreateVM and create-time disk provisioning
// vm_lifecycle.go Start/Stop/Restart/Kill/Delete
// vm_set.go SetVM mutation
// vm_stats.go stats, health, ping, stale reaper
// vm_disk.go system overlay, work disk provisioning
// vm_authsync.go per-VM authorized_key, git identity, and auth file sync
// vm_create_ops.go async begin/status/cancel registry for create
// capabilities.go pluggable capability hooks executed at VM start
// preflight.go prereq validation for VM start
// snapshot.go device-mapper COW snapshot helpers
// ports.go port forwarding inspection
//
// Image management:
//
// images.go register, promote, delete, find, list
// imagebuild.go build via firecracker build VM
// image_build_ops.go async begin/status/cancel registry for build
// image_seed.go managed work-seed fingerprint refresh
//
// Guest interaction:
//
// guest_sessions.go long-lived guest commands, attach, logs
// ssh_client_config.go daemon-managed SSH client key material
// workspace.go materialising host repos into guest
// opencode.go opencode host-side helpers
//
// Host bootstrap:
//
// nat.go NAT prereq registration
// dns_routing.go systemd-resolved per-interface routing
// tap_pool.go TAP interface pool
//
// Core:
//
// daemon.go Daemon struct, Open/Close/Serve, dispatch
// dashboard.go dashboard metrics aggregation
// doctor.go host diagnostics
// logger.go slog configuration
// runtime_assets.go paths to bundled companion binaries
// web.go embedded web UI server
//
// Lock ordering:
//
// vmLocks[id] → {createVMMu, imageOpsMu} → subsystem-local locks
//
// Subsystem-local locks live on the owning type (tapPool.mu,
// sessionRegistry.mu, opRegistry.mu, guestSessionController.attachMu/writeMu)
// and do not contend with each other. See ARCHITECTURE.md for details.
package daemon