Skip to content

Commit b7d2c0f

Browse files
committed
fix restore cloudimg issues
1 parent d746a27 commit b7d2c0f

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

hypervisor/cloudhypervisor/restore.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,19 @@ func (ch *CloudHypervisor) restoreAfterExtract(ctx context.Context, vmID string,
8585
}()
8686

8787
chConfigPath := filepath.Join(rec.RunDir, "config.json")
88-
// activeDisks keeps post-first-boot cloudimg restore aligned with config.json.
88+
// Match snapshot's disk count — rec.StorageConfigs is ordered [overlay, cidata],
89+
// prefix-slice to whatever was attached when the snapshot was taken.
90+
snapshotCfg, _, parseErr := parseCHConfig(chConfigPath)
91+
if parseErr != nil {
92+
return nil, fmt.Errorf("parse snapshot config: %w", parseErr)
93+
}
94+
diskCount := len(snapshotCfg.Disks)
95+
if diskCount > len(rec.StorageConfigs) {
96+
return nil, fmt.Errorf("snapshot has %d disks, VM record has %d", diskCount, len(rec.StorageConfigs))
97+
}
98+
8999
if err = patchCHConfig(chConfigPath, &patchOptions{
90-
storageConfigs: activeDisks(rec),
100+
storageConfigs: rec.StorageConfigs[:diskCount],
91101
consoleSock: hypervisor.ConsoleSockPath(rec.RunDir),
92102
directBoot: directBoot,
93103
windows: vmCfg.Windows,

0 commit comments

Comments
 (0)