Skip to content

Commit 130aed8

Browse files
committed
fix(vm): start auto data-disk names at data1, matching cocoon
cocoon's normalizeDataDiskSpecs auto-names from data1 (autoIdx := 1); a 0-based default was an unintended divergence in a feature whose point is alignment.
1 parent 57223e6 commit 130aed8

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ cocoon-macos vm run <IMAGE> --data-disk size=20G --data-disk name=scratch,size=5
7575

7676
`--data-disk` (on `run`/`create`/`clone`) attaches empty qcow2 data disks. Keys: `size=` (required,
7777
`units.RAMInBytes` syntax e.g. `20G`, min 16MiB) and `name=` (optional, `[a-z][a-z0-9_-]{0,19}`,
78-
default `data0`, `data1`, …; duplicates error). **At most 4 disks:** macOS has no virtio-blk driver
78+
default `data1`, `data2`, … (cocoon's auto-naming); duplicates error). **At most 4 disks:** macOS has no virtio-blk driver
7979
(the OS disk itself rides AHCI), so data disks take the `ich9-ahci` controller's remaining SATA
8080
ports — `OpenCoreBoot` (sata.2) and `MacHDD` (sata.4) leave exactly ports 0, 1, 3, 5 free. They
8181
snapshot/restore and clone with the VM (clone copies SRC's disks and can add more). **Unlike cocoon,

cmd/vm/datadisk.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const (
2525
)
2626

2727
// parseDataDisks parses every --data-disk arg into a DataDiskSpec, fills default names
28-
// (data0, data1, …), rejects duplicate names, and caps the total at maxDataDisks. reserved names
28+
// (data1, data2, … — same 1-based auto-naming as cocoon), rejects duplicate names, and caps the total at maxDataDisks. reserved names
2929
// (a clone's copied disks) count against both the duplicate check and the AHCI cap.
3030
func parseDataDisks(raw, reserved []string) ([]types.DataDiskSpec, error) {
3131
used := make(map[string]bool, len(reserved))
@@ -50,7 +50,7 @@ func parseDataDisks(raw, reserved []string) ([]types.DataDiskSpec, error) {
5050
}
5151
used[s.Name] = true
5252
}
53-
autoIdx := 0
53+
autoIdx := 1
5454
for i := range specs {
5555
if specs[i].Name != "" {
5656
continue

cmd/vm/datadisk_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ func TestParseDataDisks(t *testing.T) {
1515
wantNames []string
1616
wantSizes []int64
1717
}{
18-
{name: "single default name", raw: []string{"size=1G"}, wantNames: []string{"data0"}, wantSizes: []int64{gib}},
18+
{name: "single default name", raw: []string{"size=1G"}, wantNames: []string{"data1"}, wantSizes: []int64{gib}},
1919
{name: "explicit name", raw: []string{"name=logs,size=512M"}, wantNames: []string{"logs"}, wantSizes: []int64{512 << 20}},
20-
{name: "multiple default names count up", raw: []string{"size=1G", "size=2G"}, wantNames: []string{"data0", "data1"}, wantSizes: []int64{gib, 2 * gib}},
21-
{name: "auto name skips an explicit one", raw: []string{"name=data0,size=1G", "size=1G"}, wantNames: []string{"data0", "data1"}, wantSizes: []int64{gib, gib}},
22-
{name: "size at 16MiB minimum", raw: []string{"size=16M"}, wantNames: []string{"data0"}, wantSizes: []int64{16 << 20}},
23-
{name: "four disks is the cap", raw: []string{"size=1G", "size=1G", "size=1G", "size=1G"}, wantNames: []string{"data0", "data1", "data2", "data3"}, wantSizes: []int64{gib, gib, gib, gib}},
20+
{name: "multiple default names count up", raw: []string{"size=1G", "size=2G"}, wantNames: []string{"data1", "data2"}, wantSizes: []int64{gib, 2 * gib}},
21+
{name: "auto name skips an explicit one", raw: []string{"name=data1,size=1G", "size=1G"}, wantNames: []string{"data1", "data2"}, wantSizes: []int64{gib, gib}},
22+
{name: "size at 16MiB minimum", raw: []string{"size=16M"}, wantNames: []string{"data1"}, wantSizes: []int64{16 << 20}},
23+
{name: "four disks is the cap", raw: []string{"size=1G", "size=1G", "size=1G", "size=1G"}, wantNames: []string{"data1", "data2", "data3", "data4"}, wantSizes: []int64{gib, gib, gib, gib}},
2424

2525
{name: "empty spec", raw: []string{""}, wantErr: true},
2626
{name: "missing size", raw: []string{"name=foo"}, wantErr: true},
@@ -37,9 +37,9 @@ func TestParseDataDisks(t *testing.T) {
3737
{name: "over the four-disk cap", raw: []string{"size=1G", "size=1G", "size=1G", "size=1G", "size=1G"}, wantErr: true},
3838

3939
// clone reserves the copied disks' names: collisions error and reserved count against the cap
40-
{name: "collides with a reserved name", raw: []string{"name=data0,size=1G"}, reserved: []string{"data0"}, wantErr: true},
41-
{name: "auto name skips reserved", raw: []string{"size=1G"}, reserved: []string{"data0"}, wantNames: []string{"data1"}, wantSizes: []int64{gib}},
42-
{name: "reserved fills the cap", raw: []string{"size=1G", "size=1G"}, reserved: []string{"data0", "data1", "data2"}, wantErr: true},
40+
{name: "collides with a reserved name", raw: []string{"name=data1,size=1G"}, reserved: []string{"data1"}, wantErr: true},
41+
{name: "auto name skips reserved", raw: []string{"size=1G"}, reserved: []string{"data1"}, wantNames: []string{"data2"}, wantSizes: []int64{gib}},
42+
{name: "reserved fills the cap", raw: []string{"size=1G", "size=1G"}, reserved: []string{"data1", "data2", "data3"}, wantErr: true},
4343
}
4444
for _, tt := range tests {
4545
t.Run(tt.name, func(t *testing.T) {
@@ -70,7 +70,7 @@ func TestParseDataDisks(t *testing.T) {
7070

7171
func TestDataDiskNameRoundTrip(t *testing.T) {
7272
// clone recovers reserved names from the copied disks' paths, so this must invert dataDiskPath
73-
for _, name := range []string{"data0", "logs", "a-b_c"} {
73+
for _, name := range []string{"data1", "logs", "a-b_c"} {
7474
if got := dataDiskName(dataDiskPath("/vm/dir", name)); got != name {
7575
t.Errorf("dataDiskName(dataDiskPath(%q)) = %q", name, got)
7676
}

0 commit comments

Comments
 (0)