Skip to content

Commit 9ed6b6a

Browse files
committed
minor enhance the boot/run/clone speed of ch and fc
1 parent 15a151e commit 9ed6b6a

4 files changed

Lines changed: 8 additions & 7 deletions

File tree

hypervisor/cloudhypervisor/clone.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,11 @@ func (ch *CloudHypervisor) restoreAndResumeClone(
178178
}
179179
}()
180180

181-
if err = restoreVM(ctx, sockPath, runDir, opts.onDemand); err != nil {
181+
hc := utils.NewSocketHTTPClientWithTimeout(sockPath, hypervisor.VMMemTransferTimeout)
182+
183+
if err = restoreVM(ctx, hc, runDir, opts.onDemand); err != nil {
182184
return fmt.Errorf("vm.restore: %w", err)
183185
}
184-
hc := utils.NewSocketHTTPClient(sockPath)
185186

186187
if err = hotSwapNets(ctx, hc, opts.snapshotCfg.Nets, opts.networkConfigs); err != nil {
187188
return fmt.Errorf("hot-swap NICs: %w", err)

hypervisor/cloudhypervisor/helper.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ type chRestoreConfig struct {
9696
MemoryRestoreMode chMemoryRestoreMode `json:"memory_restore_mode,omitempty"`
9797
}
9898

99-
func restoreVM(ctx context.Context, sockPath, sourceDir string, onDemand bool) error {
99+
func restoreVM(ctx context.Context, hc *http.Client, sourceDir string, onDemand bool) error {
100100
cfg := chRestoreConfig{
101101
SourceURL: "file://" + sourceDir,
102102
}
@@ -107,7 +107,6 @@ func restoreVM(ctx context.Context, sockPath, sourceDir string, onDemand bool) e
107107
if err != nil {
108108
return fmt.Errorf("marshal restore request: %w", err)
109109
}
110-
hc := utils.NewSocketHTTPClientWithTimeout(sockPath, hypervisor.VMMemTransferTimeout)
111110
_, err = utils.DoAPI(ctx, hc, http.MethodPut,
112111
"http://localhost/api/v1/vm.restore", body, http.StatusNoContent)
113112
return err

hypervisor/cloudhypervisor/restore.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@ func (ch *CloudHypervisor) restoreAfterExtract(ctx context.Context, vmID string,
135135
}
136136
}()
137137

138-
if err = restoreVM(ctx, sockPath, rec.RunDir, vmCfg.OnDemand); err != nil {
138+
hc := utils.NewSocketHTTPClientWithTimeout(sockPath, hypervisor.VMMemTransferTimeout)
139+
140+
if err = restoreVM(ctx, hc, rec.RunDir, vmCfg.OnDemand); err != nil {
139141
return nil, fmt.Errorf("vm.restore: %w", err)
140142
}
141-
hc := utils.NewSocketHTTPClient(sockPath)
142143
if err = resumeVM(ctx, hc); err != nil {
143144
return nil, fmt.Errorf("vm.resume: %w", err)
144145
}

hypervisor/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func VerifyBaseFiles(storageConfigs []*types.StorageConfig, boot *types.BootConf
182182

183183
// WaitForSocket polls until socketPath is connectable or the process exits.
184184
func WaitForSocket(ctx context.Context, socketPath string, pid int, timeout time.Duration, processName string) error {
185-
return utils.WaitFor(ctx, timeout, 100*time.Millisecond, func() (bool, error) { //nolint:mnd
185+
return utils.WaitFor(ctx, timeout, 1*time.Millisecond, func() (bool, error) { //nolint:mnd
186186
if utils.CheckSocket(socketPath) == nil {
187187
return true, nil
188188
}

0 commit comments

Comments
 (0)