Skip to content

Commit 0356996

Browse files
author
Justin Terry
committed
Update hcs package to computecore
This updates the hcs package and all references to the computecore dll. It removes the vmcompute package since it is no longer needed. Signed-off-by: Justin Terry <terryjustin@microsoft.com>
1 parent 8ca8bc0 commit 0356996

8 files changed

Lines changed: 187 additions & 1685 deletions

File tree

internal/hcs/callback.go

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

internal/hcs/process.go

Lines changed: 41 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,24 @@ import (
1414

1515
"go.opencensus.io/trace"
1616

17+
"github.com/Microsoft/hcsshim/internal/computecore"
1718
"github.com/Microsoft/hcsshim/internal/cow"
1819
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
1920
"github.com/Microsoft/hcsshim/internal/log"
2021
"github.com/Microsoft/hcsshim/internal/oc"
2122
"github.com/Microsoft/hcsshim/internal/protocol/guestrequest"
22-
"github.com/Microsoft/hcsshim/internal/vmcompute"
2323
)
2424

2525
type Process struct {
2626
handleLock sync.RWMutex
27-
handle vmcompute.HcsProcess
27+
handle computecore.HcsProcess
2828
processID int
2929
system *System
3030
hasCachedStdio bool
3131
stdioLock sync.Mutex
3232
stdin io.WriteCloser
3333
stdout io.ReadCloser
3434
stderr io.ReadCloser
35-
callbackNumber uintptr
3635
killSignalDelivered bool
3736

3837
closedWaitOnce sync.Once
@@ -43,7 +42,7 @@ type Process struct {
4342

4443
var _ cow.Process = &Process{}
4544

46-
func newProcess(process vmcompute.HcsProcess, processID int, computeSystem *System) *Process {
45+
func newProcess(process computecore.HcsProcess, processID int, computeSystem *System) *Process {
4746
return &Process{
4847
handle: process,
4948
processID: processID,
@@ -106,7 +105,9 @@ func (process *Process) Signal(ctx context.Context, options interface{}) (bool,
106105
return false, err
107106
}
108107

109-
resultJSON, err := vmcompute.HcsSignalProcess(ctx, process.handle, string(optionsb))
108+
resultJSON, err := withOperation(ctx, func(op computecore.HcsOperation) error {
109+
return computecore.HcsSignalProcess(ctx, process.handle, op, string(optionsb))
110+
})
110111
events := processHcsResult(ctx, resultJSON)
111112
delivered, err := process.processSignalResult(ctx, err)
112113
if err != nil {
@@ -171,7 +172,9 @@ func (process *Process) Kill(ctx context.Context) (bool, error) {
171172
}
172173
defer newProcessHandle.Close()
173174

174-
resultJSON, err := vmcompute.HcsTerminateProcess(ctx, newProcessHandle.handle)
175+
resultJSON, err := withOperation(ctx, func(op computecore.HcsOperation) error {
176+
return computecore.HcsTerminateProcess(ctx, newProcessHandle.handle, op, "")
177+
})
175178
if err != nil {
176179
// We still need to check these two cases, as processes may still be killed by an
177180
// external actor (human operator, OOM, random script etc).
@@ -221,23 +224,27 @@ func (process *Process) waitBackground() {
221224
err error
222225
exitCode = -1
223226
propertiesJSON string
224-
resultJSON string
225227
)
226228

227-
err = waitForNotification(ctx, process.callbackNumber, hcsNotificationProcessExited, nil)
228-
if err != nil {
229-
err = makeProcessError(process, operation, err, nil)
229+
process.handleLock.RLock()
230+
handle := process.handle
231+
process.handleLock.RUnlock()
232+
233+
_, waitErr := computecore.HcsWaitForProcessExit(ctx, handle, 0xFFFFFFFF)
234+
if waitErr != nil {
235+
err = makeProcessError(process, operation, waitErr, nil)
230236
log.G(ctx).WithError(err).Error("failed wait")
231237
} else {
232238
process.handleLock.RLock()
233239
defer process.handleLock.RUnlock()
234240

235241
// Make sure we didn't race with Close() here
236242
if process.handle != 0 {
237-
propertiesJSON, resultJSON, err = vmcompute.HcsGetProcessProperties(ctx, process.handle)
238-
events := processHcsResult(ctx, resultJSON)
243+
propertiesJSON, err = withOperation(ctx, func(op computecore.HcsOperation) error {
244+
return computecore.HcsGetProcessProperties(ctx, process.handle, op, "")
245+
})
239246
if err != nil {
240-
err = makeProcessError(process, operation, err, events)
247+
err = makeProcessError(process, operation, err, nil)
241248
} else {
242249
properties := &hcsschema.ProcessStatus{}
243250
err = json.Unmarshal([]byte(propertiesJSON), properties)
@@ -303,7 +310,9 @@ func (process *Process) ResizeConsole(ctx context.Context, width, height uint16)
303310
return err
304311
}
305312

306-
resultJSON, err := vmcompute.HcsModifyProcess(ctx, process.handle, string(modifyRequestb))
313+
resultJSON, err := withOperation(ctx, func(op computecore.HcsOperation) error {
314+
return computecore.HcsModifyProcess(ctx, process.handle, op, string(modifyRequestb))
315+
})
307316
events := processHcsResult(ctx, resultJSON)
308317
if err != nil {
309318
return makeProcessError(process, operation, err, events)
@@ -352,9 +361,21 @@ func (process *Process) StdioLegacy() (_ io.WriteCloser, _ io.ReadCloser, _ io.R
352361
return stdin, stdout, stderr, nil
353362
}
354363

355-
processInfo, resultJSON, err := vmcompute.HcsGetProcessInfo(ctx, process.handle)
356-
events := processHcsResult(ctx, resultJSON)
364+
processInfo, resultJSON, err := func() (computecore.HcsProcessInformation, string, error) {
365+
op, err := computecore.HcsCreateOperation(ctx, 0, 0)
366+
if err != nil {
367+
return computecore.HcsProcessInformation{}, "", err
368+
}
369+
defer computecore.HcsCloseOperation(ctx, op)
370+
371+
if err := computecore.HcsGetProcessInfo(ctx, process.handle, op); err != nil {
372+
return computecore.HcsProcessInformation{}, "", err
373+
}
374+
processInfo, resultJSON, err := computecore.HcsWaitForOperationResultAndProcessInfo(ctx, op, 0xFFFFFFFF)
375+
return processInfo, resultJSON, err
376+
}()
357377
if err != nil {
378+
events := processHcsResult(ctx, resultJSON)
358379
return nil, nil, nil, makeProcessError(process, operation, err, events)
359380
}
360381

@@ -406,7 +427,9 @@ func (process *Process) CloseStdin(ctx context.Context) (err error) {
406427
return err
407428
}
408429

409-
resultJSON, err := vmcompute.HcsModifyProcess(ctx, process.handle, string(modifyRequestb))
430+
resultJSON, err := withOperation(ctx, func(op computecore.HcsOperation) error {
431+
return computecore.HcsModifyProcess(ctx, process.handle, op, string(modifyRequestb))
432+
})
410433
events := processHcsResult(ctx, resultJSON)
411434
if err != nil {
412435
return makeProcessError(process, operation, err, events)
@@ -505,13 +528,7 @@ func (process *Process) Close() (err error) {
505528
}
506529
process.stdioLock.Unlock()
507530

508-
if err = process.unregisterCallback(ctx); err != nil {
509-
return makeProcessError(process, operation, err, nil)
510-
}
511-
512-
if err = vmcompute.HcsCloseProcess(ctx, process.handle); err != nil {
513-
return makeProcessError(process, operation, err, nil)
514-
}
531+
computecore.HcsCloseProcess(ctx, process.handle)
515532

516533
process.handle = 0
517534
process.closedWaitOnce.Do(func() {
@@ -522,61 +539,3 @@ func (process *Process) Close() (err error) {
522539

523540
return nil
524541
}
525-
526-
func (process *Process) registerCallback(ctx context.Context) error {
527-
callbackContext := &notificationWatcherContext{
528-
channels: newProcessChannels(),
529-
systemID: process.SystemID(),
530-
processID: process.processID,
531-
}
532-
533-
callbackMapLock.Lock()
534-
callbackNumber := nextCallback
535-
nextCallback++
536-
callbackMap[callbackNumber] = callbackContext
537-
callbackMapLock.Unlock()
538-
539-
callbackHandle, err := vmcompute.HcsRegisterProcessCallback(ctx, process.handle, notificationWatcherCallback, callbackNumber)
540-
if err != nil {
541-
return err
542-
}
543-
callbackContext.handle = callbackHandle
544-
process.callbackNumber = callbackNumber
545-
546-
return nil
547-
}
548-
549-
func (process *Process) unregisterCallback(ctx context.Context) error {
550-
callbackNumber := process.callbackNumber
551-
552-
callbackMapLock.RLock()
553-
callbackContext := callbackMap[callbackNumber]
554-
callbackMapLock.RUnlock()
555-
556-
if callbackContext == nil {
557-
return nil
558-
}
559-
560-
handle := callbackContext.handle
561-
562-
if handle == 0 {
563-
return nil
564-
}
565-
566-
// vmcompute.HcsUnregisterProcessCallback has its own synchronization to
567-
// wait for all callbacks to complete. We must NOT hold the callbackMapLock.
568-
err := vmcompute.HcsUnregisterProcessCallback(ctx, handle)
569-
if err != nil {
570-
return err
571-
}
572-
573-
closeChannels(callbackContext.channels)
574-
575-
callbackMapLock.Lock()
576-
delete(callbackMap, callbackNumber)
577-
callbackMapLock.Unlock()
578-
579-
handle = 0 //nolint:ineffassign
580-
581-
return nil
582-
}

0 commit comments

Comments
 (0)