Skip to content

refactor: dedup helpers across cmd/hypervisor/snapshot#59

Merged
CMGS merged 1 commit into
masterfrom
refactor/dedup-helpers
May 20, 2026
Merged

refactor: dedup helpers across cmd/hypervisor/snapshot#59
CMGS merged 1 commit into
masterfrom
refactor/dedup-helpers

Conversation

@CMGS
Copy link
Copy Markdown
Contributor

@CMGS CMGS commented May 20, 2026

Summary

4 small dedup extractions from the final master audit (reuse agent findings #1, #2, #5, #22). Net -29 LOC.

  • hypervisor.ResolveAndLoad(ctx, ref) (id, VMRecord, error) combines ResolveRef + LoadRecord under a single DB lock. 3 call sites: hypervisor/cloudhypervisor/console.go, hypervisor/firecracker/console.go, hypervisor/cloudhypervisor/extend.go's runningVMClientWithRecord.
  • cmdcore.CloseOnCancel(ctx, c) func() bool wraps the context.AfterFunc(...stream.Close)+defer stop() boilerplate. 4 call sites: cmd/snapshot/handler.go × 2, cmd/vm/run.go × 2.
  • snapshot/localfile.insertRecord folds the 18-line name-collision check + Snapshots[id]+Names[name] insert shared by Create (Pending) and Import (finalized).
  • cmd/vm/status_test.go swaps hand-rolled equalStrings for slices.Equal.

Followups: perf/batch-tx-and-cache (separate PR) for List off-lock IO + DeleteAll batch tx + FindVMMByCmdline per-batch cache.

Based on chore/ship-ready-cleanup (PR #58) to avoid hypervisor/inspect.go conflict.

Test plan

  • make fmt-check && make lint && go test -race ./... — 21 packages green, lint 0, fmt 0
  • AST layout audit — 0 violations

@CMGS CMGS force-pushed the refactor/dedup-helpers branch 3 times, most recently from 6856f27 to 24a9988 Compare May 20, 2026 09:28
- hypervisor.ResolveAndLoad combines ResolveRef+LoadRecord under one DB
  lock; collapses 3 call sites (CH console, FC console, CH extend's
  runningVMClientWithRecord)
- cmdcore.CloseOnCancel wraps context.AfterFunc(stream.Close); 4 call
  sites (cmd/snapshot/handler.go × 2, cmd/vm/run.go × 2) shrink to one
  defer line each
- snapshot/localfile.insertRecord folds the 18-line name-collision +
  Snapshots[id]+Names[name] block shared by Create (Pending) and Import
- cmd/vm/status_test.go: equalStrings → slices.Equal (Go stdlib)
@CMGS CMGS force-pushed the refactor/dedup-helpers branch from 24a9988 to cbacfea Compare May 20, 2026 09:37
@CMGS CMGS merged commit 01bc7e7 into master May 20, 2026
4 checks passed
@CMGS CMGS deleted the refactor/dedup-helpers branch May 20, 2026 09:46
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