Skip to content

net: scope host device families per installation (net_scope) - #196

Merged
CMGS merged 3 commits into
masterfrom
net/scoped-device-gc
Aug 17, 2026
Merged

net: scope host device families per installation (net_scope)#196
CMGS merged 3 commits into
masterfrom
net/scoped-device-gc

Conversation

@CMGS

@CMGS CMGS commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Problem

GC sweeps two host-wide name families by name — bridge TAPs bt<vmid8>-<nic> in the host netns and CNI netns cocoon-<vmid> under /var/run/netns — and reclaims every entry whose VM its own DB does not know. Both prefixes were package constants, so any second installation on the same host (another root_dir, or a cocoon-derived runner such as cocoon-macos that provisions through cocoon's bridge/CNI backends) lands in the same families and has its live guests' TAPs / netns torn down by the peer's sweep (observed: btALZMITW2-0 reclaimed by the hourly GC, guest SSH No route to host).

Fix

One installation-identity knob; cocoon stays ignorant of any particular downstream — each installation only manages its own families.

  • config.Config.NetScope (net_scope, env COCOON_NET_SCOPE): two alphanumerics; empty keeps the legacy bt / cocoon- names. Scoped families are <scope><vmid8>-<nic> and <scope>-<vmid>. The fixed length means no two scopes are prefixes of each other, so families are disjoint by construction; bt and rm are rejected because they alias the legacy bridge family and CH's transient restore TAPs.
  • Naming primitives live in network next to TAPName: BridgeTAPPrefix(scope), NetnsPrefix(scope), ValidateScope, RestoreTAPPrefix (moved from cloudhypervisor).
  • bridge: New resolves the prefix once; GCModule(prefix) / CleanupTAPs(prefix, ids) take the resolved string like the sibling CgroupGCModule / vmlock.GCModule registrations; parseTAPName matches the configured prefix only.
  • cni: netnsName / netnsPath are Config methods; the GC netns scan cuts the scoped prefix.
  • cmd/core passes the resolved prefix; viper registers net_scope; docs (cli.md, networking.md, gc.md) describe the families and the knob.

Defaults are unchanged, so existing installations keep their device names. A second installation sets net_scope before its first VM.

Evidence

  • make lint GOOS=linux + darwin: 0 issues; asl ./... both GOOS: clean (the pre-existing meta/sqlite/store.go finding is fixed in the separate review: commit)
  • go test ./... darwin: green
  • Linux (docker golang:1.26.5): go test ./config/ ./network/... ./cmd/core/ ./hypervisor/cloudhypervisor/ green; linux-only TestParseTAPName runs and passes with a foreign-scope negative case
  • /simplify four lenses applied (single knob, primitives moved to network, resolved-string signatures, no cached-vs-derived duplication)

Follow-up (cocoon-macos)

Set NetScope in its config.Config literal (e.g. mt) and pass network.BridgeTAPPrefix(conf.NetScope) to bridge.CleanupTAPs.

CMGS added 2 commits August 17, 2026 15:26
Move the standalone RefuseManifest below the type blocks so the asl
funcpartition rule (type immediately followed by its methods) holds.
GC sweeps two host-wide name families by name — bridge TAPs bt<vmid8>-<nic>
in the host netns and CNI netns cocoon-<vmid> under /var/run/netns — and
reclaims every entry whose VM its own DB does not know. Both prefixes were
package constants, so a second installation on the same host (another
root_dir, or a cocoon-derived runner such as cocoon-macos provisioning
through cocoon's bridge/CNI backends) shares the families and has its live
guests' TAPs and netns torn down by the peer's sweep.

Add config net_scope: two alphanumerics keying an installation's families
(<scope><vmid8>-<nic>, <scope>-<vmid>); empty keeps the legacy names. The
fixed length keeps distinct scopes from being prefixes of each other, and
bt / rm are rejected as aliases of the legacy and restore TAP families. The
naming primitives live in package network next to TAPName; bridge and cni
take the resolved prefix, and cocoon stays ignorant of any downstream.
@CMGS
CMGS merged commit 2fe2e0e into master Aug 17, 2026
4 checks passed
@CMGS
CMGS deleted the net/scoped-device-gc branch August 17, 2026 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant