Extract opstate and dmsnap into subpackages

Two leaves of the daemon package that carry no back-references to Daemon
move out:

- internal/daemon/opstate: generic Registry[T AsyncOp]. The AsyncOp
  interface methods are capitalised (ID, IsDone, UpdatedAt, Cancel);
  vmCreateOperationState and imageBuildOperationState implement it.
- internal/daemon/dmsnap: Create, Cleanup, Remove plus the Handles type
  for device-mapper snapshot lifecycle. Takes an explicit Runner
  interface. The daemon-package snapshot.go keeps thin forwarders and a
  type alias so existing call sites and tests are untouched.

Skipped on purpose: tap_pool has too many Daemon-scoped dependencies
(config, store, closing, createTap) for a clean extraction at this
stage; nat.go is already a thin facade over internal/hostnat;
dns_routing.go tests tightly couple to package internals, so extraction
would be more churn than payoff. Each can be revisited when a
subsystem-level refactor forces the boundary.

All tests green.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Thales Maciel 2026-04-15 16:02:43 -03:00
parent 59f2766139
commit fdab4a7e68
No known key found for this signature in database
GPG key ID: 33112E6833C34679
7 changed files with 214 additions and 170 deletions

View file

@ -18,6 +18,7 @@ import (
"banger/internal/api"
"banger/internal/buildinfo"
"banger/internal/config"
"banger/internal/daemon/opstate"
"banger/internal/model"
"banger/internal/paths"
"banger/internal/rpc"
@ -34,8 +35,8 @@ type Daemon struct {
logger *slog.Logger
imageOpsMu sync.Mutex
createVMMu sync.Mutex
createOps opRegistry[*vmCreateOperationState]
imageBuildOps opRegistry[*imageBuildOperationState]
createOps opstate.Registry[*vmCreateOperationState]
imageBuildOps opstate.Registry[*imageBuildOperationState]
vmLocks vmLockSet
sessions sessionRegistry
tapPool tapPool