daemon split (1/5): extract *HostNetwork service
First phase of splitting the daemon god-struct into focused services with explicit ownership. HostNetwork now owns everything host-networking: the TAP interface pool (initializeTapPool / ensureTapPool / acquireTap / releaseTap / createTap), bridge + socket dir setup, firecracker process primitives (find/resolve/kill/wait/ensureSocketAccess/sendCtrlAltDel), DM snapshot lifecycle, NAT rule enforcement, guest DNS server lifecycle + routing setup, and the vsock-agent readiness probe. That's 7 files whose receivers flipped from *Daemon to *HostNetwork, plus a new host_network.go that declares the struct, its hostNetworkDeps, and the factored firecracker + DNS helpers that used to live in vm.go. Daemon gives up the tapPool and vmDNS fields entirely; they're now HostNetwork's business. Construction goes through newHostNetwork in Daemon.Open with an explicit dependency bag (runner, logger, config, layout, closing). A lazy-init hostNet() helper on Daemon supports test literals that don't wire net explicitly — production always populates it eagerly. Signature tightenings where the old receiver reached into VM-service state: - ensureNAT(ctx, vm, enable) → ensureNAT(ctx, guestIP, tap, enable). Callers resolve tap from the handle cache themselves. - initializeTapPool(ctx) → initializeTapPool(usedTaps []string). Daemon.Open enumerates VMs, collects taps from handles, hands the slice in. rebuildDNS stays on *Daemon as the orchestrator — it filters by vm-alive (a VMService concern handles will move to in phase 4) then calls HostNetwork.replaceDNS with the already-filtered map. Capability hooks continue to take *Daemon; they now use it as a facade to reach services (d.net.ensureNAT, d.hostNet().*). Planned CapabilityHost interface extraction is orthogonal, left for later. Tests: dns_routing_test.go + fastpath_test.go + nat_test.go + snapshot_test.go + open_close_test.go were touched to construct HostNetwork literals where they exercise its methods directly, or route through d.hostNet() where they exercise the Daemon entry points. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
eba9a553bf
commit
362009d747
18 changed files with 461 additions and 326 deletions
|
|
@ -74,7 +74,7 @@ func TestCreateDMSnapshotFailsWithoutRollbackWhenBaseLoopSetupFails(t *testing.T
|
|||
}
|
||||
d := &Daemon{runner: runner}
|
||||
|
||||
_, err := d.createDMSnapshot(context.Background(), "/rootfs.ext4", "/cow.ext4", "fc-rootfs-test")
|
||||
_, err := d.hostNet().createDMSnapshot(context.Background(), "/rootfs.ext4", "/cow.ext4", "fc-rootfs-test")
|
||||
if !errors.Is(err, attachErr) {
|
||||
t.Fatalf("error = %v, want %v", err, attachErr)
|
||||
}
|
||||
|
|
@ -98,7 +98,7 @@ func TestCreateDMSnapshotRollsBackBaseLoopWhenCowLoopSetupFails(t *testing.T) {
|
|||
}
|
||||
d := &Daemon{runner: runner}
|
||||
|
||||
_, err := d.createDMSnapshot(context.Background(), "/rootfs.ext4", "/cow.ext4", "fc-rootfs-test")
|
||||
_, err := d.hostNet().createDMSnapshot(context.Background(), "/rootfs.ext4", "/cow.ext4", "fc-rootfs-test")
|
||||
if !errors.Is(err, attachErr) {
|
||||
t.Fatalf("error = %v, want %v", err, attachErr)
|
||||
}
|
||||
|
|
@ -121,7 +121,7 @@ func TestCreateDMSnapshotRollsBackBothLoopsWhenBlockdevFails(t *testing.T) {
|
|||
}
|
||||
d := &Daemon{runner: runner}
|
||||
|
||||
_, err := d.createDMSnapshot(context.Background(), "/rootfs.ext4", "/cow.ext4", "fc-rootfs-test")
|
||||
_, err := d.hostNet().createDMSnapshot(context.Background(), "/rootfs.ext4", "/cow.ext4", "fc-rootfs-test")
|
||||
if !errors.Is(err, blockdevErr) {
|
||||
t.Fatalf("error = %v, want %v", err, blockdevErr)
|
||||
}
|
||||
|
|
@ -145,7 +145,7 @@ func TestCreateDMSnapshotRollsBackLoopsWhenDMSetupFails(t *testing.T) {
|
|||
}
|
||||
d := &Daemon{runner: runner}
|
||||
|
||||
_, err := d.createDMSnapshot(context.Background(), "/rootfs.ext4", "/cow.ext4", "fc-rootfs-test")
|
||||
_, err := d.hostNet().createDMSnapshot(context.Background(), "/rootfs.ext4", "/cow.ext4", "fc-rootfs-test")
|
||||
if !errors.Is(err, dmErr) {
|
||||
t.Fatalf("error = %v, want %v", err, dmErr)
|
||||
}
|
||||
|
|
@ -174,7 +174,7 @@ func TestCreateDMSnapshotJoinsRollbackErrors(t *testing.T) {
|
|||
}
|
||||
d := &Daemon{runner: runner}
|
||||
|
||||
_, err := d.createDMSnapshot(context.Background(), "/rootfs.ext4", "/cow.ext4", "fc-rootfs-test")
|
||||
_, err := d.hostNet().createDMSnapshot(context.Background(), "/rootfs.ext4", "/cow.ext4", "fc-rootfs-test")
|
||||
if err == nil {
|
||||
t.Fatal("expected createDMSnapshot to return an error")
|
||||
}
|
||||
|
|
@ -198,7 +198,7 @@ func TestCreateDMSnapshotReturnsHandlesOnSuccess(t *testing.T) {
|
|||
}
|
||||
d := &Daemon{runner: runner}
|
||||
|
||||
handles, err := d.createDMSnapshot(context.Background(), "/rootfs.ext4", "/cow.ext4", "fc-rootfs-test")
|
||||
handles, err := d.hostNet().createDMSnapshot(context.Background(), "/rootfs.ext4", "/cow.ext4", "fc-rootfs-test")
|
||||
if err != nil {
|
||||
t.Fatalf("createDMSnapshot returned error: %v", err)
|
||||
}
|
||||
|
|
@ -227,7 +227,7 @@ func TestCleanupDMSnapshotRemovesResourcesInReverseOrder(t *testing.T) {
|
|||
}
|
||||
d := &Daemon{runner: runner}
|
||||
|
||||
err := d.cleanupDMSnapshot(context.Background(), dmSnapshotHandles{
|
||||
err := d.hostNet().cleanupDMSnapshot(context.Background(), dmSnapshotHandles{
|
||||
BaseLoop: "/dev/loop10",
|
||||
COWLoop: "/dev/loop11",
|
||||
DMName: "fc-rootfs-test",
|
||||
|
|
@ -251,7 +251,7 @@ func TestCleanupDMSnapshotUsesPartialHandles(t *testing.T) {
|
|||
}
|
||||
d := &Daemon{runner: runner}
|
||||
|
||||
err := d.cleanupDMSnapshot(context.Background(), dmSnapshotHandles{
|
||||
err := d.hostNet().cleanupDMSnapshot(context.Background(), dmSnapshotHandles{
|
||||
BaseLoop: "/dev/loop10",
|
||||
DMDev: "/dev/mapper/fc-rootfs-test",
|
||||
})
|
||||
|
|
@ -277,7 +277,7 @@ func TestCleanupDMSnapshotJoinsTeardownErrors(t *testing.T) {
|
|||
}
|
||||
d := &Daemon{runner: runner}
|
||||
|
||||
err := d.cleanupDMSnapshot(context.Background(), dmSnapshotHandles{
|
||||
err := d.hostNet().cleanupDMSnapshot(context.Background(), dmSnapshotHandles{
|
||||
BaseLoop: "/dev/loop10",
|
||||
COWLoop: "/dev/loop11",
|
||||
DMName: "fc-rootfs-test",
|
||||
|
|
@ -307,7 +307,7 @@ func TestRemoveDMSnapshotRetriesBusyDevice(t *testing.T) {
|
|||
}
|
||||
d := &Daemon{runner: runner}
|
||||
|
||||
if err := d.removeDMSnapshot(context.Background(), "fc-rootfs-test"); err != nil {
|
||||
if err := d.hostNet().removeDMSnapshot(context.Background(), "fc-rootfs-test"); err != nil {
|
||||
t.Fatalf("removeDMSnapshot returned error: %v", err)
|
||||
}
|
||||
runner.assertExhausted()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue