Skip to content

feat(vm): data disks via --data-disk, aligned with cocoon - #6

Merged
CMGS merged 2 commits into
masterfrom
feat/data-disks
Jul 2, 2026
Merged

feat(vm): data disks via --data-disk, aligned with cocoon#6
CMGS merged 2 commits into
masterfrom
feat/data-disks

Conversation

@CMGS

@CMGS CMGS commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

What

Adds data disks to vm run/create/clone through a repeatable --data-disk flag whose UX mirrors cocoon's: comma-separated key=value specs parsed into cocoon's types.DataDiskSpec (reused, not re-invented), validated with types.ValidDataDiskName.

cocoon-macos vm run <IMAGE> --data-disk size=20G --data-disk name=scratch,size=50G
  • size= required, units.RAMInBytes syntax, min 16MiB (local const mirroring cocoon hypervisor.MinDataDiskSize — that package pulls in storage/metering/backend, so it is not import-worthy for one const).
  • name= optional, defaults data0, data1, … ; duplicates error.
  • Disks are created as empty qcow2 (qemu-img create -f qcow2 <path> <bytes>), attached with the same AHCI/IDE perf tuning as MacHDD (cache=writeback,aio=io_uring,discard=unmap,detect-zeroes=unmap), and roll back with the VM (snapshot/restore) and travel with clone (SRC's disks are reflink-copied; extra --data-disk specs add more, name collisions with a copied disk error).

Intentional macOS divergences from cocoon

  • fstype= / mount= / directio= are rejected. A macOS guest has no cloud-init/agent to partition, format, or mount a disk, so the disk is attached raw — the user formats it in-guest with Disk Utility / diskutil. cocoon's Linux path formats/mounts for you; here that would silently do nothing.
  • At most 4 data disks. macOS has no virtio-blk driver (the OS disk itself rides AHCI), so data disks take the single ich9-ahci controller's remaining SATA ports. OpenCoreBoot (sata.2) and MacHDD (sata.4) leave exactly ports 0, 1, 3, 5 free. Enforced at parse time.

Validation

  • gofumpt -l . clean; go build + GOOS=linux go build; golangci-lint 0 issues for darwin and linux; go test -race green.
  • New table-driven parser test (cmd/vm/datadisk_test.go): single/multi, default names, size units, missing/too-small size, bad/dup names, rejected fstype/mount/directio, >4 cap, clone-reserved collisions + cap.
  • qemu/launch_test.go TestArgsDataDisks: port mapping [0,1,3,5], id/if=none pairing, MacHDD-equal tuning, and no drives when empty.
  • Drove the built binary: --data-disk shows in --help; below-min, fstype=, and >4 specs all error with clear messages; confirmed qemu-img create <path> <bytes> yields the expected qcow2.

Stacking

Stacked on PR 1 (fix/audit-findings); this PR targets that branch as its base. Review/merge PR 1 first.

🤖 Generated with Claude Code

@CMGS

CMGS commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Aligned the auto-naming with cocoon: default disk names now start at data1 (cocoon's normalizeDataDiskSpecs uses autoIdx := 1) — the initial 0-based naming was an unintended divergence. Tests and README updated; full gate re-run green.

Base automatically changed from fix/audit-findings to master July 2, 2026 04:54
CMGS added 2 commits July 2, 2026 13:14
Mirror cocoon's repeatable --data-disk key=value surface for macOS, reusing
types.DataDiskSpec/ValidDataDiskName. macOS only supports name=/size= (no
in-guest agent to format or mount, so fstype=/mount=/directio= are rejected)
and caps at 4 disks: with no virtio-blk driver the disks ride the ich9-ahci
controller's free SATA ports (0,1,3,5). Disks are created as empty qcow2, ride
the same AHCI/IDE perf tuning as MacHDD, and participate in snapshot/clone.
cocoon's normalizeDataDiskSpecs auto-names from data1 (autoIdx := 1); a
0-based default was an unintended divergence in a feature whose point is
alignment.
@CMGS
CMGS force-pushed the feat/data-disks branch from f8fcbab to 130aed8 Compare July 2, 2026 05:15
@CMGS
CMGS merged commit 8174c9b into master Jul 2, 2026
3 checks passed
@CMGS
CMGS deleted the feat/data-disks branch July 2, 2026 05:15
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