"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "vendor/github.com/Microsoft/hcsshim/internal/hcs/system.go" between
moby-20.10.6.tar.gz and moby-20.10.7.tar.gz

About: Moby is a framework to assemble specialized container systems (formerly project name Docker; see here to clarify the relationship between the projects).

system.go  (moby-20.10.6):system.go  (moby-20.10.7)
skipping to change at line 78 skipping to change at line 78
if createError == nil || IsPending(createError) { if createError == nil || IsPending(createError) {
defer func() { defer func() {
if err != nil { if err != nil {
computeSystem.Close() computeSystem.Close()
} }
}() }()
if err = computeSystem.registerCallback(ctx); err != nil { if err = computeSystem.registerCallback(ctx); err != nil {
// Terminate the compute system if it still exists. We're okay to // Terminate the compute system if it still exists. We're okay to
// ignore a failure here. // ignore a failure here.
computeSystem.Terminate(ctx) computeSystem.Terminate(ctx)
return nil, makeSystemError(computeSystem, operation, "", err, nil) return nil, makeSystemError(computeSystem, operation, err , nil)
} }
} }
events, err := processAsyncHcsResult(ctx, createError, resultJSON, comput eSystem.callbackNumber, hcsNotificationSystemCreateCompleted, &timeout.SystemCre ate) events, err := processAsyncHcsResult(ctx, createError, resultJSON, comput eSystem.callbackNumber, hcsNotificationSystemCreateCompleted, &timeout.SystemCre ate)
if err != nil { if err != nil {
if err == ErrTimeout { if err == ErrTimeout {
// Terminate the compute system if it still exists. We're okay to // Terminate the compute system if it still exists. We're okay to
// ignore a failure here. // ignore a failure here.
computeSystem.Terminate(ctx) computeSystem.Terminate(ctx)
} }
return nil, makeSystemError(computeSystem, operation, hcsDocument , err, events) return nil, makeSystemError(computeSystem, operation, err, events )
} }
go computeSystem.waitBackground() go computeSystem.waitBackground()
if err = computeSystem.getCachedProperties(ctx); err != nil { if err = computeSystem.getCachedProperties(ctx); err != nil {
return nil, err return nil, err
} }
return computeSystem, nil return computeSystem, nil
} }
// OpenComputeSystem opens an existing compute system by ID. // OpenComputeSystem opens an existing compute system by ID.
func OpenComputeSystem(ctx context.Context, id string) (*System, error) { func OpenComputeSystem(ctx context.Context, id string) (*System, error) {
operation := "hcsshim::OpenComputeSystem" operation := "hcsshim::OpenComputeSystem"
computeSystem := newSystem(id) computeSystem := newSystem(id)
handle, resultJSON, err := vmcompute.HcsOpenComputeSystem(ctx, id) handle, resultJSON, err := vmcompute.HcsOpenComputeSystem(ctx, id)
events := processHcsResult(ctx, resultJSON) events := processHcsResult(ctx, resultJSON)
if err != nil { if err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, ev ents) return nil, makeSystemError(computeSystem, operation, err, events )
} }
computeSystem.handle = handle computeSystem.handle = handle
defer func() { defer func() {
if err != nil { if err != nil {
computeSystem.Close() computeSystem.Close()
} }
}() }()
if err = computeSystem.registerCallback(ctx); err != nil { if err = computeSystem.registerCallback(ctx); err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, ni l) return nil, makeSystemError(computeSystem, operation, err, nil)
} }
go computeSystem.waitBackground() go computeSystem.waitBackground()
if err = computeSystem.getCachedProperties(ctx); err != nil { if err = computeSystem.getCachedProperties(ctx); err != nil {
return nil, err return nil, err
} }
return computeSystem, nil return computeSystem, nil
} }
func (computeSystem *System) getCachedProperties(ctx context.Context) error { func (computeSystem *System) getCachedProperties(ctx context.Context) error {
props, err := computeSystem.Properties(ctx) props, err := computeSystem.Properties(ctx)
skipping to change at line 191 skipping to change at line 191
// here to measure the full start time. // here to measure the full start time.
ctx, span := trace.StartSpan(ctx, operation) ctx, span := trace.StartSpan(ctx, operation)
defer span.End() defer span.End()
defer func() { oc.SetSpanStatus(span, err) }() defer func() { oc.SetSpanStatus(span, err) }()
span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) span.AddAttributes(trace.StringAttribute("cid", computeSystem.id))
computeSystem.handleLock.RLock() computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock() defer computeSystem.handleLock.RUnlock()
if computeSystem.handle == 0 { if computeSystem.handle == 0 {
return makeSystemError(computeSystem, operation, "", ErrAlreadyCl osed, nil) return makeSystemError(computeSystem, operation, ErrAlreadyClosed , nil)
} }
resultJSON, err := vmcompute.HcsStartComputeSystem(ctx, computeSystem.han dle, "") resultJSON, err := vmcompute.HcsStartComputeSystem(ctx, computeSystem.han dle, "")
events, err := processAsyncHcsResult(ctx, err, resultJSON, computeSystem. callbackNumber, hcsNotificationSystemStartCompleted, &timeout.SystemStart) events, err := processAsyncHcsResult(ctx, err, resultJSON, computeSystem. callbackNumber, hcsNotificationSystemStartCompleted, &timeout.SystemStart)
if err != nil { if err != nil {
return makeSystemError(computeSystem, operation, "", err, events) return makeSystemError(computeSystem, operation, err, events)
} }
return nil return nil
} }
// ID returns the compute system's identifier. // ID returns the compute system's identifier.
func (computeSystem *System) ID() string { func (computeSystem *System) ID() string {
return computeSystem.id return computeSystem.id
} }
skipping to change at line 224 skipping to change at line 224
if computeSystem.handle == 0 { if computeSystem.handle == 0 {
return nil return nil
} }
resultJSON, err := vmcompute.HcsShutdownComputeSystem(ctx, computeSystem. handle, "") resultJSON, err := vmcompute.HcsShutdownComputeSystem(ctx, computeSystem. handle, "")
events := processHcsResult(ctx, resultJSON) events := processHcsResult(ctx, resultJSON)
switch err { switch err {
case nil, ErrVmcomputeAlreadyStopped, ErrComputeSystemDoesNotExist, ErrVm computeOperationPending: case nil, ErrVmcomputeAlreadyStopped, ErrComputeSystemDoesNotExist, ErrVm computeOperationPending:
default: default:
return makeSystemError(computeSystem, operation, "", err, events) return makeSystemError(computeSystem, operation, err, events)
} }
return nil return nil
} }
// Terminate requests a compute system terminate. // Terminate requests a compute system terminate.
func (computeSystem *System) Terminate(ctx context.Context) error { func (computeSystem *System) Terminate(ctx context.Context) error {
computeSystem.handleLock.RLock() computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock() defer computeSystem.handleLock.RUnlock()
operation := "hcsshim::System::Terminate" operation := "hcsshim::System::Terminate"
if computeSystem.handle == 0 { if computeSystem.handle == 0 {
return nil return nil
} }
resultJSON, err := vmcompute.HcsTerminateComputeSystem(ctx, computeSystem .handle, "") resultJSON, err := vmcompute.HcsTerminateComputeSystem(ctx, computeSystem .handle, "")
events := processHcsResult(ctx, resultJSON) events := processHcsResult(ctx, resultJSON)
switch err { switch err {
case nil, ErrVmcomputeAlreadyStopped, ErrComputeSystemDoesNotExist, ErrVm computeOperationPending: case nil, ErrVmcomputeAlreadyStopped, ErrComputeSystemDoesNotExist, ErrVm computeOperationPending:
default: default:
return makeSystemError(computeSystem, operation, "", err, events) return makeSystemError(computeSystem, operation, err, events)
} }
return nil return nil
} }
// waitBackground waits for the compute system exit notification. Once received // waitBackground waits for the compute system exit notification. Once received
// sets `computeSystem.waitError` (if any) and unblocks all `Wait` calls. // sets `computeSystem.waitError` (if any) and unblocks all `Wait` calls.
// //
// This MUST be called exactly once per `computeSystem.handle` but `Wait` is // This MUST be called exactly once per `computeSystem.handle` but `Wait` is
// safe to call multiple times. // safe to call multiple times.
func (computeSystem *System) waitBackground() { func (computeSystem *System) waitBackground() {
skipping to change at line 267 skipping to change at line 267
ctx, span := trace.StartSpan(context.Background(), operation) ctx, span := trace.StartSpan(context.Background(), operation)
defer span.End() defer span.End()
span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) span.AddAttributes(trace.StringAttribute("cid", computeSystem.id))
err := waitForNotification(ctx, computeSystem.callbackNumber, hcsNotifica tionSystemExited, nil) err := waitForNotification(ctx, computeSystem.callbackNumber, hcsNotifica tionSystemExited, nil)
switch err { switch err {
case nil: case nil:
log.G(ctx).Debug("system exited") log.G(ctx).Debug("system exited")
case ErrVmcomputeUnexpectedExit: case ErrVmcomputeUnexpectedExit:
log.G(ctx).Debug("unexpected system exit") log.G(ctx).Debug("unexpected system exit")
computeSystem.exitError = makeSystemError(computeSystem, operatio n, "", err, nil) computeSystem.exitError = makeSystemError(computeSystem, operatio n, err, nil)
err = nil err = nil
default: default:
err = makeSystemError(computeSystem, operation, "", err, nil) err = makeSystemError(computeSystem, operation, err, nil)
} }
computeSystem.closedWaitOnce.Do(func() { computeSystem.closedWaitOnce.Do(func() {
computeSystem.waitError = err computeSystem.waitError = err
close(computeSystem.waitBlock) close(computeSystem.waitBlock)
}) })
oc.SetSpanStatus(span, err) oc.SetSpanStatus(span, err)
} }
// Wait synchronously waits for the compute system to shutdown or terminate. If // Wait synchronously waits for the compute system to shutdown or terminate. If
// the compute system has already exited returns the previous error (if any). // the compute system has already exited returns the previous error (if any).
skipping to change at line 308 skipping to change at line 308
// Properties returns the requested container properties targeting a V1 schema c ontainer. // Properties returns the requested container properties targeting a V1 schema c ontainer.
func (computeSystem *System) Properties(ctx context.Context, types ...schema1.Pr opertyType) (*schema1.ContainerProperties, error) { func (computeSystem *System) Properties(ctx context.Context, types ...schema1.Pr opertyType) (*schema1.ContainerProperties, error) {
computeSystem.handleLock.RLock() computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock() defer computeSystem.handleLock.RUnlock()
operation := "hcsshim::System::Properties" operation := "hcsshim::System::Properties"
queryBytes, err := json.Marshal(schema1.PropertyQuery{PropertyTypes: type s}) queryBytes, err := json.Marshal(schema1.PropertyQuery{PropertyTypes: type s})
if err != nil { if err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, ni l) return nil, makeSystemError(computeSystem, operation, err, nil)
} }
propertiesJSON, resultJSON, err := vmcompute.HcsGetComputeSystemPropertie s(ctx, computeSystem.handle, string(queryBytes)) propertiesJSON, resultJSON, err := vmcompute.HcsGetComputeSystemPropertie s(ctx, computeSystem.handle, string(queryBytes))
events := processHcsResult(ctx, resultJSON) events := processHcsResult(ctx, resultJSON)
if err != nil { if err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, ev ents) return nil, makeSystemError(computeSystem, operation, err, events )
} }
if propertiesJSON == "" { if propertiesJSON == "" {
return nil, ErrUnexpectedValue return nil, ErrUnexpectedValue
} }
properties := &schema1.ContainerProperties{} properties := &schema1.ContainerProperties{}
if err := json.Unmarshal([]byte(propertiesJSON), properties); err != nil { if err := json.Unmarshal([]byte(propertiesJSON), properties); err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, ni l) return nil, makeSystemError(computeSystem, operation, err, nil)
} }
return properties, nil return properties, nil
} }
// PropertiesV2 returns the requested container properties targeting a V2 schema container. // PropertiesV2 returns the requested container properties targeting a V2 schema container.
func (computeSystem *System) PropertiesV2(ctx context.Context, types ...hcsschem a.PropertyType) (*hcsschema.Properties, error) { func (computeSystem *System) PropertiesV2(ctx context.Context, types ...hcsschem a.PropertyType) (*hcsschema.Properties, error) {
computeSystem.handleLock.RLock() computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock() defer computeSystem.handleLock.RUnlock()
operation := "hcsshim::System::PropertiesV2" operation := "hcsshim::System::PropertiesV2"
queryBytes, err := json.Marshal(hcsschema.PropertyQuery{PropertyTypes: ty pes}) queryBytes, err := json.Marshal(hcsschema.PropertyQuery{PropertyTypes: ty pes})
if err != nil { if err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, ni l) return nil, makeSystemError(computeSystem, operation, err, nil)
} }
propertiesJSON, resultJSON, err := vmcompute.HcsGetComputeSystemPropertie s(ctx, computeSystem.handle, string(queryBytes)) propertiesJSON, resultJSON, err := vmcompute.HcsGetComputeSystemPropertie s(ctx, computeSystem.handle, string(queryBytes))
events := processHcsResult(ctx, resultJSON) events := processHcsResult(ctx, resultJSON)
if err != nil { if err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, ev ents) return nil, makeSystemError(computeSystem, operation, err, events )
} }
if propertiesJSON == "" { if propertiesJSON == "" {
return nil, ErrUnexpectedValue return nil, ErrUnexpectedValue
} }
properties := &hcsschema.Properties{} properties := &hcsschema.Properties{}
if err := json.Unmarshal([]byte(propertiesJSON), properties); err != nil { if err := json.Unmarshal([]byte(propertiesJSON), properties); err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, ni l) return nil, makeSystemError(computeSystem, operation, err, nil)
} }
return properties, nil return properties, nil
} }
// Pause pauses the execution of the computeSystem. This feature is not enabled in TP5. // Pause pauses the execution of the computeSystem. This feature is not enabled in TP5.
func (computeSystem *System) Pause(ctx context.Context) (err error) { func (computeSystem *System) Pause(ctx context.Context) (err error) {
operation := "hcsshim::System::Pause" operation := "hcsshim::System::Pause"
// hcsPauseComputeSystemContext is an async peration. Start the outer spa n // hcsPauseComputeSystemContext is an async peration. Start the outer spa n
// here to measure the full pause time. // here to measure the full pause time.
ctx, span := trace.StartSpan(ctx, operation) ctx, span := trace.StartSpan(ctx, operation)
defer span.End() defer span.End()
defer func() { oc.SetSpanStatus(span, err) }() defer func() { oc.SetSpanStatus(span, err) }()
span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) span.AddAttributes(trace.StringAttribute("cid", computeSystem.id))
computeSystem.handleLock.RLock() computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock() defer computeSystem.handleLock.RUnlock()
if computeSystem.handle == 0 { if computeSystem.handle == 0 {
return makeSystemError(computeSystem, operation, "", ErrAlreadyCl osed, nil) return makeSystemError(computeSystem, operation, ErrAlreadyClosed , nil)
} }
resultJSON, err := vmcompute.HcsPauseComputeSystem(ctx, computeSystem.han dle, "") resultJSON, err := vmcompute.HcsPauseComputeSystem(ctx, computeSystem.han dle, "")
events, err := processAsyncHcsResult(ctx, err, resultJSON, computeSystem. callbackNumber, hcsNotificationSystemPauseCompleted, &timeout.SystemPause) events, err := processAsyncHcsResult(ctx, err, resultJSON, computeSystem. callbackNumber, hcsNotificationSystemPauseCompleted, &timeout.SystemPause)
if err != nil { if err != nil {
return makeSystemError(computeSystem, operation, "", err, events) return makeSystemError(computeSystem, operation, err, events)
} }
return nil return nil
} }
// Resume resumes the execution of the computeSystem. This feature is not enable d in TP5. // Resume resumes the execution of the computeSystem. This feature is not enable d in TP5.
func (computeSystem *System) Resume(ctx context.Context) (err error) { func (computeSystem *System) Resume(ctx context.Context) (err error) {
operation := "hcsshim::System::Resume" operation := "hcsshim::System::Resume"
// hcsResumeComputeSystemContext is an async operation. Start the outer s pan // hcsResumeComputeSystemContext is an async operation. Start the outer s pan
// here to measure the full restore time. // here to measure the full restore time.
ctx, span := trace.StartSpan(ctx, operation) ctx, span := trace.StartSpan(ctx, operation)
defer span.End() defer span.End()
defer func() { oc.SetSpanStatus(span, err) }() defer func() { oc.SetSpanStatus(span, err) }()
span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) span.AddAttributes(trace.StringAttribute("cid", computeSystem.id))
computeSystem.handleLock.RLock() computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock() defer computeSystem.handleLock.RUnlock()
if computeSystem.handle == 0 { if computeSystem.handle == 0 {
return makeSystemError(computeSystem, operation, "", ErrAlreadyCl osed, nil) return makeSystemError(computeSystem, operation, ErrAlreadyClosed , nil)
} }
resultJSON, err := vmcompute.HcsResumeComputeSystem(ctx, computeSystem.ha ndle, "") resultJSON, err := vmcompute.HcsResumeComputeSystem(ctx, computeSystem.ha ndle, "")
events, err := processAsyncHcsResult(ctx, err, resultJSON, computeSystem. callbackNumber, hcsNotificationSystemResumeCompleted, &timeout.SystemResume) events, err := processAsyncHcsResult(ctx, err, resultJSON, computeSystem. callbackNumber, hcsNotificationSystemResumeCompleted, &timeout.SystemResume)
if err != nil { if err != nil {
return makeSystemError(computeSystem, operation, "", err, events) return makeSystemError(computeSystem, operation, err, events)
} }
return nil return nil
} }
func (computeSystem *System) createProcess(ctx context.Context, operation string , c interface{}) (*Process, *vmcompute.HcsProcessInformation, error) { func (computeSystem *System) createProcess(ctx context.Context, operation string , c interface{}) (*Process, *vmcompute.HcsProcessInformation, error) {
computeSystem.handleLock.RLock() computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock() defer computeSystem.handleLock.RUnlock()
if computeSystem.handle == 0 { if computeSystem.handle == 0 {
return nil, nil, makeSystemError(computeSystem, operation, "", Er rAlreadyClosed, nil) return nil, nil, makeSystemError(computeSystem, operation, ErrAlr eadyClosed, nil)
} }
configurationb, err := json.Marshal(c) configurationb, err := json.Marshal(c)
if err != nil { if err != nil {
return nil, nil, makeSystemError(computeSystem, operation, "", er r, nil) return nil, nil, makeSystemError(computeSystem, operation, err, n il)
} }
configuration := string(configurationb) configuration := string(configurationb)
processInfo, processHandle, resultJSON, err := vmcompute.HcsCreateProcess (ctx, computeSystem.handle, configuration) processInfo, processHandle, resultJSON, err := vmcompute.HcsCreateProcess (ctx, computeSystem.handle, configuration)
events := processHcsResult(ctx, resultJSON) events := processHcsResult(ctx, resultJSON)
if err != nil { if err != nil {
return nil, nil, makeSystemError(computeSystem, operation, config uration, err, events) return nil, nil, makeSystemError(computeSystem, operation, err, e vents)
} }
log.G(ctx).WithField("pid", processInfo.ProcessId).Debug("created process pid") log.G(ctx).WithField("pid", processInfo.ProcessId).Debug("created process pid")
return newProcess(processHandle, int(processInfo.ProcessId), computeSyste m), &processInfo, nil return newProcess(processHandle, int(processInfo.ProcessId), computeSyste m), &processInfo, nil
} }
// CreateProcess launches a new process within the computeSystem. // CreateProcess launches a new process within the computeSystem.
func (computeSystem *System) CreateProcess(ctx context.Context, c interface{}) ( cow.Process, error) { func (computeSystem *System) CreateProcess(ctx context.Context, c interface{}) ( cow.Process, error) {
operation := "hcsshim::System::CreateProcess" operation := "hcsshim::System::CreateProcess"
process, processInfo, err := computeSystem.createProcess(ctx, operation, c) process, processInfo, err := computeSystem.createProcess(ctx, operation, c)
skipping to change at line 450 skipping to change at line 450
return nil, err return nil, err
} }
defer func() { defer func() {
if err != nil { if err != nil {
process.Close() process.Close()
} }
}() }()
pipes, err := makeOpenFiles([]syscall.Handle{processInfo.StdInput, proces sInfo.StdOutput, processInfo.StdError}) pipes, err := makeOpenFiles([]syscall.Handle{processInfo.StdInput, proces sInfo.StdOutput, processInfo.StdError})
if err != nil { if err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, ni l) return nil, makeSystemError(computeSystem, operation, err, nil)
} }
process.stdin = pipes[0] process.stdin = pipes[0]
process.stdout = pipes[1] process.stdout = pipes[1]
process.stderr = pipes[2] process.stderr = pipes[2]
process.hasCachedStdio = true process.hasCachedStdio = true
if err = process.registerCallback(ctx); err != nil { if err = process.registerCallback(ctx); err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, ni l) return nil, makeSystemError(computeSystem, operation, err, nil)
} }
go process.waitBackground() go process.waitBackground()
return process, nil return process, nil
} }
// OpenProcess gets an interface to an existing process within the computeSystem . // OpenProcess gets an interface to an existing process within the computeSystem .
func (computeSystem *System) OpenProcess(ctx context.Context, pid int) (*Process , error) { func (computeSystem *System) OpenProcess(ctx context.Context, pid int) (*Process , error) {
computeSystem.handleLock.RLock() computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock() defer computeSystem.handleLock.RUnlock()
operation := "hcsshim::System::OpenProcess" operation := "hcsshim::System::OpenProcess"
if computeSystem.handle == 0 { if computeSystem.handle == 0 {
return nil, makeSystemError(computeSystem, operation, "", ErrAlre adyClosed, nil) return nil, makeSystemError(computeSystem, operation, ErrAlreadyC losed, nil)
} }
processHandle, resultJSON, err := vmcompute.HcsOpenProcess(ctx, computeSy stem.handle, uint32(pid)) processHandle, resultJSON, err := vmcompute.HcsOpenProcess(ctx, computeSy stem.handle, uint32(pid))
events := processHcsResult(ctx, resultJSON) events := processHcsResult(ctx, resultJSON)
if err != nil { if err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, ev ents) return nil, makeSystemError(computeSystem, operation, err, events )
} }
process := newProcess(processHandle, pid, computeSystem) process := newProcess(processHandle, pid, computeSystem)
if err = process.registerCallback(ctx); err != nil { if err = process.registerCallback(ctx); err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, ni l) return nil, makeSystemError(computeSystem, operation, err, nil)
} }
go process.waitBackground() go process.waitBackground()
return process, nil return process, nil
} }
// Close cleans up any state associated with the compute system but does not ter minate or wait for it. // Close cleans up any state associated with the compute system but does not ter minate or wait for it.
func (computeSystem *System) Close() (err error) { func (computeSystem *System) Close() (err error) {
operation := "hcsshim::System::Close" operation := "hcsshim::System::Close"
ctx, span := trace.StartSpan(context.Background(), operation) ctx, span := trace.StartSpan(context.Background(), operation)
skipping to change at line 508 skipping to change at line 508
computeSystem.handleLock.Lock() computeSystem.handleLock.Lock()
defer computeSystem.handleLock.Unlock() defer computeSystem.handleLock.Unlock()
// Don't double free this // Don't double free this
if computeSystem.handle == 0 { if computeSystem.handle == 0 {
return nil return nil
} }
if err = computeSystem.unregisterCallback(ctx); err != nil { if err = computeSystem.unregisterCallback(ctx); err != nil {
return makeSystemError(computeSystem, operation, "", err, nil) return makeSystemError(computeSystem, operation, err, nil)
} }
err = vmcompute.HcsCloseComputeSystem(ctx, computeSystem.handle) err = vmcompute.HcsCloseComputeSystem(ctx, computeSystem.handle)
if err != nil { if err != nil {
return makeSystemError(computeSystem, operation, "", err, nil) return makeSystemError(computeSystem, operation, err, nil)
} }
computeSystem.handle = 0 computeSystem.handle = 0
computeSystem.closedWaitOnce.Do(func() { computeSystem.closedWaitOnce.Do(func() {
computeSystem.waitError = ErrAlreadyClosed computeSystem.waitError = ErrAlreadyClosed
close(computeSystem.waitBlock) close(computeSystem.waitBlock)
}) })
return nil return nil
} }
skipping to change at line 590 skipping to change at line 590
} }
// Modify the System by sending a request to HCS // Modify the System by sending a request to HCS
func (computeSystem *System) Modify(ctx context.Context, config interface{}) err or { func (computeSystem *System) Modify(ctx context.Context, config interface{}) err or {
computeSystem.handleLock.RLock() computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock() defer computeSystem.handleLock.RUnlock()
operation := "hcsshim::System::Modify" operation := "hcsshim::System::Modify"
if computeSystem.handle == 0 { if computeSystem.handle == 0 {
return makeSystemError(computeSystem, operation, "", ErrAlreadyCl osed, nil) return makeSystemError(computeSystem, operation, ErrAlreadyClosed , nil)
} }
requestBytes, err := json.Marshal(config) requestBytes, err := json.Marshal(config)
if err != nil { if err != nil {
return err return err
} }
requestJSON := string(requestBytes) requestJSON := string(requestBytes)
resultJSON, err := vmcompute.HcsModifyComputeSystem(ctx, computeSystem.ha ndle, requestJSON) resultJSON, err := vmcompute.HcsModifyComputeSystem(ctx, computeSystem.ha ndle, requestJSON)
events := processHcsResult(ctx, resultJSON) events := processHcsResult(ctx, resultJSON)
if err != nil { if err != nil {
return makeSystemError(computeSystem, operation, requestJSON, err , events) return makeSystemError(computeSystem, operation, err, events)
} }
return nil return nil
} }
 End of changes. 32 change blocks. 
32 lines changed or deleted 32 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)