Skip to content

Commit

Permalink
Add support for saving hcs compute system.
Browse files Browse the repository at this point in the history
This is one of the many small PRs that enable the support for late cloning.
This PR simply adds the go wrappers required for saving a HCS compute system
which is used during template creation.

Signed-off-by: Amit Barve <[email protected]>
  • Loading branch information
ambarve committed Jun 11, 2020
1 parent e50252d commit f976169
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/hcs/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func newSystemChannels() notificationChannels {
hcsNotificationSystemStartCompleted,
hcsNotificationSystemPauseCompleted,
hcsNotificationSystemResumeCompleted,
hcsNotificationSystemSaveCompleted,
} {
channels[notif] = make(notificationChannel, 1)
}
Expand Down
27 changes: 27 additions & 0 deletions internal/hcs/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,33 @@ func (computeSystem *System) Resume(ctx context.Context) (err error) {
return nil
}

// Save the compute system
func (computeSystem *System) Save(ctx context.Context, options string) (err error) {
operation := "hcsshim::System::Save"

// hcsSaveComputeSystemContext is an async peration. Start the outer span
// here to measure the full save time.
ctx, span := trace.StartSpan(ctx, operation)
defer span.End()
defer func() { oc.SetSpanStatus(span, err) }()
span.AddAttributes(trace.StringAttribute("cid", computeSystem.id))

computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock()

if computeSystem.handle == 0 {
return makeSystemError(computeSystem, operation, "", ErrAlreadyClosed, nil)
}

result, err := vmcompute.HcsSaveComputeSystem(ctx, computeSystem.handle, options)
events, err := processAsyncHcsResult(ctx, err, result, computeSystem.callbackNumber, hcsNotificationSystemSaveCompleted, &timeout.SystemSave)
if err != nil {
return makeSystemError(computeSystem, operation, "", err, events)
}

return nil
}

func (computeSystem *System) createProcess(ctx context.Context, operation string, c interface{}) (*Process, *vmcompute.HcsProcessInformation, error) {
computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock()
Expand Down
4 changes: 4 additions & 0 deletions internal/timeout/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ var (
// SystemResume is the timeout for resuming a compute system
SystemResume time.Duration = defaultTimeout

// SystemSave is the timeout for saving a compute system
SystemSave time.Duration = defaultTimeout

// SyscallWatcher is the timeout before warning of a potential stuck platform syscall.
SyscallWatcher time.Duration = defaultTimeout

Expand All @@ -51,6 +54,7 @@ func init() {
SystemStart = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSTEMSTART", SystemStart)
SystemPause = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSTEMPAUSE", SystemPause)
SystemResume = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSTEMRESUME", SystemResume)
SystemSave = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSTEMSAVE", SystemSave)
SyscallWatcher = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSCALLWATCHER", SyscallWatcher)
Tar2VHD = durationFromEnvironment("HCSSHIM_TIMEOUT_TAR2VHD", Tar2VHD)
ExternalCommandToStart = durationFromEnvironment("HCSSHIM_TIMEOUT_EXTERNALCOMMANDSTART", ExternalCommandToStart)
Expand Down
23 changes: 23 additions & 0 deletions internal/vmcompute/vmcompute.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
//sys hcsModifyServiceSettings(settings string, result **uint16) (hr error) = vmcompute.HcsModifyServiceSettings?
//sys hcsRegisterComputeSystemCallback(computeSystem HcsSystem, callback uintptr, context uintptr, callbackHandle *HcsCallback) (hr error) = vmcompute.HcsRegisterComputeSystemCallback?
//sys hcsUnregisterComputeSystemCallback(callbackHandle HcsCallback) (hr error) = vmcompute.HcsUnregisterComputeSystemCallback?
//sys hcsSaveComputeSystem(computeSystem HcsSystem, options string, result **uint16) (hr error) = vmcompute.HcsSaveComputeSystem?

//sys hcsCreateProcess(computeSystem HcsSystem, processParameters string, processInformation *HcsProcessInformation, process *HcsProcess, result **uint16) (hr error) = vmcompute.HcsCreateProcess?
//sys hcsOpenProcess(computeSystem HcsSystem, pid uint32, process *HcsProcess, result **uint16) (hr error) = vmcompute.HcsOpenProcess?
Expand Down Expand Up @@ -585,3 +586,25 @@ func HcsUnregisterProcessCallback(ctx gcontext.Context, callbackHandle HcsCallba
return hcsUnregisterProcessCallback(callbackHandle)
})
}

func HcsSaveComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) {
ctx, span := trace.StartSpan(ctx, "HcsSaveComputeSystem")
defer span.End()
defer func() {
if result != "" {
span.AddAttributes(trace.StringAttribute("result", result))
}
if hr != errVmcomputeOperationPending {
oc.SetSpanStatus(span, hr)
}
}()

return result, execute(ctx, timeout.SyscallWatcher, func() error {
var resultp *uint16
err := hcsSaveComputeSystem(computeSystem, options, &resultp)
if resultp != nil {
result = interop.ConvertAndFreeCoTaskMemString(resultp)
}
return err
})
}
24 changes: 24 additions & 0 deletions internal/vmcompute/zsyscall_windows.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f976169

Please sign in to comment.