Skip to content

Commit 9e29e80

Browse files
committed
refactor(hypervisor): consolidate helper files into utils; dedup reserve skeleton
helpers.go/helper.go merge into each package's utils.go per the file-naming standard; CreateSequence and CloneSetup share one reservePlaceholder (ReserveVM is a single DB transaction, so the skipped rollback on reserve failure was already a no-op); decompressKernel dispatches through a decode field instead of re-switching on codec name.
1 parent d9fa4df commit 9e29e80

12 files changed

Lines changed: 356 additions & 386 deletions

File tree

hypervisor/clone.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,7 @@ type AfterExtractFn func(ctx context.Context, vmID string, vmCfg *types.VMConfig
1616

1717
// CloneSetup is the shared pre-clone sequence: validate CPU, reserve a placeholder, ensure dirs, return a cleanup that rolls back both.
1818
func (b *Backend) CloneSetup(ctx context.Context, vmID string, vmCfg *types.VMConfig, snapshotConfig *types.SnapshotConfig) (runDir, logDir string, now time.Time, cleanup func(), err error) {
19-
if err = ValidateHostCPU(vmCfg.CPU); err != nil {
20-
return "", "", time.Time{}, nil, err
21-
}
22-
now = time.Now()
23-
runDir = b.Conf.VMRunDir(vmID)
24-
logDir = b.Conf.VMLogDir(vmID)
25-
26-
cleanup = func() {
27-
_ = RemoveVMDirs(runDir, logDir)
28-
b.RollbackCreate(ctx, vmID, vmCfg.Name)
29-
}
30-
31-
if err = b.ReserveVM(ctx, vmID, vmCfg, snapshotConfig.ImageBlobIDs, runDir, logDir); err != nil {
32-
return "", "", time.Time{}, nil, fmt.Errorf("reserve VM record: %w", err)
33-
}
34-
if err = utils.EnsureDirs(runDir, logDir); err != nil {
35-
cleanup()
36-
return "", "", time.Time{}, nil, fmt.Errorf("ensure dirs: %w", err)
37-
}
38-
return runDir, logDir, now, cleanup, nil
19+
return b.reservePlaceholder(ctx, vmID, vmCfg, snapshotConfig.ImageBlobIDs)
3920
}
4021

4122
// DirectCloneBase clones from a local snapshot directory. Used when the snapshot lives on the same host (no tar streaming needed).

hypervisor/cloudhypervisor/helper.go

Lines changed: 0 additions & 267 deletions
This file was deleted.

0 commit comments

Comments
 (0)