summaryrefslogtreecommitdiff
path: root/vendor/github.com/Microsoft/hcsshim/internal/hcs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/Microsoft/hcsshim/internal/hcs')
-rw-r--r--vendor/github.com/Microsoft/hcsshim/internal/hcs/callback.go102
-rw-r--r--vendor/github.com/Microsoft/hcsshim/internal/hcs/errors.go75
-rw-r--r--vendor/github.com/Microsoft/hcsshim/internal/hcs/hcs.go48
-rw-r--r--vendor/github.com/Microsoft/hcsshim/internal/hcs/log.go20
-rw-r--r--vendor/github.com/Microsoft/hcsshim/internal/hcs/process.go405
-rw-r--r--vendor/github.com/Microsoft/hcsshim/internal/hcs/system.go658
-rw-r--r--vendor/github.com/Microsoft/hcsshim/internal/hcs/waithelper.go18
-rw-r--r--vendor/github.com/Microsoft/hcsshim/internal/hcs/watcher.go41
-rw-r--r--vendor/github.com/Microsoft/hcsshim/internal/hcs/zsyscall_windows.go533
9 files changed, 682 insertions, 1218 deletions
diff --git a/vendor/github.com/Microsoft/hcsshim/internal/hcs/callback.go b/vendor/github.com/Microsoft/hcsshim/internal/hcs/callback.go
index f9a922a4b..62ba81751 100644
--- a/vendor/github.com/Microsoft/hcsshim/internal/hcs/callback.go
+++ b/vendor/github.com/Microsoft/hcsshim/internal/hcs/callback.go
@@ -1,10 +1,13 @@
package hcs
import (
+ "fmt"
"sync"
"syscall"
"github.com/Microsoft/hcsshim/internal/interop"
+ "github.com/Microsoft/hcsshim/internal/logfields"
+ "github.com/Microsoft/hcsshim/internal/vmcompute"
"github.com/sirupsen/logrus"
)
@@ -40,35 +43,83 @@ var (
)
type hcsNotification uint32
+
+func (hn hcsNotification) String() string {
+ switch hn {
+ case hcsNotificationSystemExited:
+ return "SystemExited"
+ case hcsNotificationSystemCreateCompleted:
+ return "SystemCreateCompleted"
+ case hcsNotificationSystemStartCompleted:
+ return "SystemStartCompleted"
+ case hcsNotificationSystemPauseCompleted:
+ return "SystemPauseCompleted"
+ case hcsNotificationSystemResumeCompleted:
+ return "SystemResumeCompleted"
+ case hcsNotificationSystemCrashReport:
+ return "SystemCrashReport"
+ case hcsNotificationSystemSiloJobCreated:
+ return "SystemSiloJobCreated"
+ case hcsNotificationSystemSaveCompleted:
+ return "SystemSaveCompleted"
+ case hcsNotificationSystemRdpEnhancedModeStateChanged:
+ return "SystemRdpEnhancedModeStateChanged"
+ case hcsNotificationSystemShutdownFailed:
+ return "SystemShutdownFailed"
+ case hcsNotificationSystemGetPropertiesCompleted:
+ return "SystemGetPropertiesCompleted"
+ case hcsNotificationSystemModifyCompleted:
+ return "SystemModifyCompleted"
+ case hcsNotificationSystemCrashInitiated:
+ return "SystemCrashInitiated"
+ case hcsNotificationSystemGuestConnectionClosed:
+ return "SystemGuestConnectionClosed"
+ case hcsNotificationProcessExited:
+ return "ProcessExited"
+ case hcsNotificationInvalid:
+ return "Invalid"
+ case hcsNotificationServiceDisconnect:
+ return "ServiceDisconnect"
+ default:
+ return fmt.Sprintf("Unknown: %d", hn)
+ }
+}
+
type notificationChannel chan error
type notifcationWatcherContext struct {
channels notificationChannels
- handle hcsCallback
+ handle vmcompute.HcsCallback
+
+ systemID string
+ processID int
}
type notificationChannels map[hcsNotification]notificationChannel
-func newChannels() notificationChannels {
+func newSystemChannels() notificationChannels {
channels := make(notificationChannels)
+ for _, notif := range []hcsNotification{
+ hcsNotificationServiceDisconnect,
+ hcsNotificationSystemExited,
+ hcsNotificationSystemCreateCompleted,
+ hcsNotificationSystemStartCompleted,
+ hcsNotificationSystemPauseCompleted,
+ hcsNotificationSystemResumeCompleted,
+ } {
+ channels[notif] = make(notificationChannel, 1)
+ }
+ return channels
+}
- channels[hcsNotificationSystemExited] = make(notificationChannel, 1)
- channels[hcsNotificationSystemCreateCompleted] = make(notificationChannel, 1)
- channels[hcsNotificationSystemStartCompleted] = make(notificationChannel, 1)
- channels[hcsNotificationSystemPauseCompleted] = make(notificationChannel, 1)
- channels[hcsNotificationSystemResumeCompleted] = make(notificationChannel, 1)
- channels[hcsNotificationProcessExited] = make(notificationChannel, 1)
- channels[hcsNotificationServiceDisconnect] = make(notificationChannel, 1)
- channels[hcsNotificationSystemCrashReport] = make(notificationChannel, 1)
- channels[hcsNotificationSystemSiloJobCreated] = make(notificationChannel, 1)
- channels[hcsNotificationSystemSaveCompleted] = make(notificationChannel, 1)
- channels[hcsNotificationSystemRdpEnhancedModeStateChanged] = make(notificationChannel, 1)
- channels[hcsNotificationSystemShutdownFailed] = make(notificationChannel, 1)
- channels[hcsNotificationSystemGetPropertiesCompleted] = make(notificationChannel, 1)
- channels[hcsNotificationSystemModifyCompleted] = make(notificationChannel, 1)
- channels[hcsNotificationSystemCrashInitiated] = make(notificationChannel, 1)
- channels[hcsNotificationSystemGuestConnectionClosed] = make(notificationChannel, 1)
-
+func newProcessChannels() notificationChannels {
+ channels := make(notificationChannels)
+ for _, notif := range []hcsNotification{
+ hcsNotificationServiceDisconnect,
+ hcsNotificationProcessExited,
+ } {
+ channels[notif] = make(notificationChannel, 1)
+ }
return channels
}
@@ -92,12 +143,17 @@ func notificationWatcher(notificationType hcsNotification, callbackNumber uintpt
return 0
}
+ log := logrus.WithFields(logrus.Fields{
+ "notification-type": notificationType.String(),
+ "system-id": context.systemID,
+ })
+ if context.processID != 0 {
+ log.Data[logfields.ProcessID] = context.processID
+ }
+ log.Debug("HCS notification")
+
if channel, ok := context.channels[notificationType]; ok {
channel <- result
- } else {
- logrus.WithFields(logrus.Fields{
- "notification-type": notificationType,
- }).Warn("Received a callback of an unsupported type")
}
return 0
diff --git a/vendor/github.com/Microsoft/hcsshim/internal/hcs/errors.go b/vendor/github.com/Microsoft/hcsshim/internal/hcs/errors.go
index 079b56535..9a4705a49 100644
--- a/vendor/github.com/Microsoft/hcsshim/internal/hcs/errors.go
+++ b/vendor/github.com/Microsoft/hcsshim/internal/hcs/errors.go
@@ -1,14 +1,14 @@
package hcs
import (
+ "context"
"encoding/json"
"errors"
"fmt"
+ "net"
"syscall"
- "github.com/Microsoft/hcsshim/internal/interop"
- "github.com/Microsoft/hcsshim/internal/logfields"
- "github.com/sirupsen/logrus"
+ "github.com/Microsoft/hcsshim/internal/log"
)
var (
@@ -117,17 +117,11 @@ func (ev *ErrorEvent) String() string {
return evs
}
-func processHcsResult(resultp *uint16) []ErrorEvent {
- if resultp != nil {
- resultj := interop.ConvertAndFreeCoTaskMemString(resultp)
- logrus.WithField(logfields.JSON, resultj).
- Debug("HCS Result")
+func processHcsResult(ctx context.Context, resultJSON string) []ErrorEvent {
+ if resultJSON != "" {
result := &hcsResult{}
- if err := json.Unmarshal([]byte(resultj), result); err != nil {
- logrus.WithFields(logrus.Fields{
- logfields.JSON: resultj,
- logrus.ErrorKey: err,
- }).Warning("Could not unmarshal HCS result")
+ if err := json.Unmarshal([]byte(resultJSON), result); err != nil {
+ log.G(ctx).WithError(err).Warning("Could not unmarshal HCS result")
return nil
}
return result.ErrorEvents
@@ -141,6 +135,8 @@ type HcsError struct {
Events []ErrorEvent
}
+var _ net.Error = &HcsError{}
+
func (e *HcsError) Error() string {
s := e.Op + ": " + e.Err.Error()
for _, ev := range e.Events {
@@ -149,6 +145,16 @@ func (e *HcsError) Error() string {
return s
}
+func (e *HcsError) Temporary() bool {
+ err, ok := e.Err.(net.Error)
+ return ok && err.Temporary()
+}
+
+func (e *HcsError) Timeout() bool {
+ err, ok := e.Err.(net.Error)
+ return ok && err.Timeout()
+}
+
// ProcessError is an error encountered in HCS during an operation on a Process object
type ProcessError struct {
SystemID string
@@ -158,6 +164,8 @@ type ProcessError struct {
Events []ErrorEvent
}
+var _ net.Error = &ProcessError{}
+
// SystemError is an error encountered in HCS during an operation on a Container object
type SystemError struct {
ID string
@@ -167,6 +175,8 @@ type SystemError struct {
Events []ErrorEvent
}
+var _ net.Error = &SystemError{}
+
func (e *SystemError) Error() string {
s := e.Op + " " + e.ID + ": " + e.Err.Error()
for _, ev := range e.Events {
@@ -178,6 +188,16 @@ func (e *SystemError) Error() string {
return s
}
+func (e *SystemError) Temporary() bool {
+ err, ok := e.Err.(net.Error)
+ return ok && err.Temporary()
+}
+
+func (e *SystemError) Timeout() bool {
+ err, ok := e.Err.(net.Error)
+ return ok && err.Timeout()
+}
+
func makeSystemError(system *System, op string, extra string, err error, events []ErrorEvent) error {
// Don't double wrap errors
if _, ok := err.(*SystemError); ok {
@@ -200,6 +220,16 @@ func (e *ProcessError) Error() string {
return s
}
+func (e *ProcessError) Temporary() bool {
+ err, ok := e.Err.(net.Error)
+ return ok && err.Temporary()
+}
+
+func (e *ProcessError) Timeout() bool {
+ err, ok := e.Err.(net.Error)
+ return ok && err.Timeout()
+}
+
func makeProcessError(process *Process, op string, err error, events []ErrorEvent) error {
// Don't double wrap errors
if _, ok := err.(*ProcessError); ok {
@@ -242,6 +272,9 @@ func IsPending(err error) bool {
// IsTimeout returns a boolean indicating whether the error is caused by
// a timeout waiting for the operation to complete.
func IsTimeout(err error) bool {
+ if err, ok := err.(net.Error); ok && err.Timeout() {
+ return true
+ }
err = getInnerError(err)
return err == ErrTimeout
}
@@ -272,6 +305,13 @@ func IsNotSupported(err error) bool {
err == ErrVmcomputeUnknownMessage
}
+// IsOperationInvalidState returns true when err is caused by
+// `ErrVmcomputeOperationInvalidState`.
+func IsOperationInvalidState(err error) bool {
+ err = getInnerError(err)
+ return err == ErrVmcomputeOperationInvalidState
+}
+
func getInnerError(err error) error {
switch pe := err.(type) {
case nil:
@@ -285,3 +325,12 @@ func getInnerError(err error) error {
}
return err
}
+
+func getOperationLogResult(err error) (string, error) {
+ switch err {
+ case nil:
+ return "Success", nil
+ default:
+ return "Error", err
+ }
+}
diff --git a/vendor/github.com/Microsoft/hcsshim/internal/hcs/hcs.go b/vendor/github.com/Microsoft/hcsshim/internal/hcs/hcs.go
deleted file mode 100644
index b0d49cbcf..000000000
--- a/vendor/github.com/Microsoft/hcsshim/internal/hcs/hcs.go
+++ /dev/null
@@ -1,48 +0,0 @@
-// Shim for the Host Compute Service (HCS) to manage Windows Server
-// containers and Hyper-V containers.
-
-package hcs
-
-import (
- "syscall"
-)
-
-//go:generate go run ../../mksyscall_windows.go -output zsyscall_windows.go hcs.go
-
-//sys hcsEnumerateComputeSystems(query string, computeSystems **uint16, result **uint16) (hr error) = vmcompute.HcsEnumerateComputeSystems?
-//sys hcsCreateComputeSystem(id string, configuration string, identity syscall.Handle, computeSystem *hcsSystem, result **uint16) (hr error) = vmcompute.HcsCreateComputeSystem?
-//sys hcsOpenComputeSystem(id string, computeSystem *hcsSystem, result **uint16) (hr error) = vmcompute.HcsOpenComputeSystem?
-//sys hcsCloseComputeSystem(computeSystem hcsSystem) (hr error) = vmcompute.HcsCloseComputeSystem?
-//sys hcsStartComputeSystem(computeSystem hcsSystem, options string, result **uint16) (hr error) = vmcompute.HcsStartComputeSystem?
-//sys hcsShutdownComputeSystem(computeSystem hcsSystem, options string, result **uint16) (hr error) = vmcompute.HcsShutdownComputeSystem?
-//sys hcsTerminateComputeSystem(computeSystem hcsSystem, options string, result **uint16) (hr error) = vmcompute.HcsTerminateComputeSystem?
-//sys hcsPauseComputeSystem(computeSystem hcsSystem, options string, result **uint16) (hr error) = vmcompute.HcsPauseComputeSystem?
-//sys hcsResumeComputeSystem(computeSystem hcsSystem, options string, result **uint16) (hr error) = vmcompute.HcsResumeComputeSystem?
-//sys hcsGetComputeSystemProperties(computeSystem hcsSystem, propertyQuery string, properties **uint16, result **uint16) (hr error) = vmcompute.HcsGetComputeSystemProperties?
-//sys hcsModifyComputeSystem(computeSystem hcsSystem, configuration string, result **uint16) (hr error) = vmcompute.HcsModifyComputeSystem?
-//sys hcsRegisterComputeSystemCallback(computeSystem hcsSystem, callback uintptr, context uintptr, callbackHandle *hcsCallback) (hr error) = vmcompute.HcsRegisterComputeSystemCallback?
-//sys hcsUnregisterComputeSystemCallback(callbackHandle hcsCallback) (hr error) = vmcompute.HcsUnregisterComputeSystemCallback?
-
-//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?
-//sys hcsCloseProcess(process hcsProcess) (hr error) = vmcompute.HcsCloseProcess?
-//sys hcsTerminateProcess(process hcsProcess, result **uint16) (hr error) = vmcompute.HcsTerminateProcess?
-//sys hcsSignalProcess(process hcsProcess, options string, result **uint16) (hr error) = vmcompute.HcsTerminateProcess?
-//sys hcsGetProcessInfo(process hcsProcess, processInformation *hcsProcessInformation, result **uint16) (hr error) = vmcompute.HcsGetProcessInfo?
-//sys hcsGetProcessProperties(process hcsProcess, processProperties **uint16, result **uint16) (hr error) = vmcompute.HcsGetProcessProperties?
-//sys hcsModifyProcess(process hcsProcess, settings string, result **uint16) (hr error) = vmcompute.HcsModifyProcess?
-//sys hcsGetServiceProperties(propertyQuery string, properties **uint16, result **uint16) (hr error) = vmcompute.HcsGetServiceProperties?
-//sys hcsRegisterProcessCallback(process hcsProcess, callback uintptr, context uintptr, callbackHandle *hcsCallback) (hr error) = vmcompute.HcsRegisterProcessCallback?
-//sys hcsUnregisterProcessCallback(callbackHandle hcsCallback) (hr error) = vmcompute.HcsUnregisterProcessCallback?
-
-type hcsSystem syscall.Handle
-type hcsProcess syscall.Handle
-type hcsCallback syscall.Handle
-
-type hcsProcessInformation struct {
- ProcessId uint32
- Reserved uint32
- StdInput syscall.Handle
- StdOutput syscall.Handle
- StdError syscall.Handle
-}
diff --git a/vendor/github.com/Microsoft/hcsshim/internal/hcs/log.go b/vendor/github.com/Microsoft/hcsshim/internal/hcs/log.go
deleted file mode 100644
index 6d03b17a2..000000000
--- a/vendor/github.com/Microsoft/hcsshim/internal/hcs/log.go
+++ /dev/null
@@ -1,20 +0,0 @@
-package hcs
-
-import "github.com/sirupsen/logrus"
-
-func logOperationBegin(ctx logrus.Fields, msg string) {
- logrus.WithFields(ctx).Debug(msg)
-}
-
-func logOperationEnd(ctx logrus.Fields, msg string, err error) {
- // Copy the log and fields first.
- log := logrus.WithFields(ctx)
- if err == nil {
- log.Debug(msg)
- } else {
- // Edit only the copied field data to avoid race conditions on the
- // write.
- log.Data[logrus.ErrorKey] = err
- log.Error(msg)
- }
-}
diff --git a/vendor/github.com/Microsoft/hcsshim/internal/hcs/process.go b/vendor/github.com/Microsoft/hcsshim/internal/hcs/process.go
index 41e20bbf9..d366f629f 100644
--- a/vendor/github.com/Microsoft/hcsshim/internal/hcs/process.go
+++ b/vendor/github.com/Microsoft/hcsshim/internal/hcs/process.go
@@ -1,48 +1,45 @@
package hcs
import (
+ "context"
"encoding/json"
"io"
"sync"
"syscall"
"time"
- "github.com/Microsoft/hcsshim/internal/guestrequest"
- "github.com/Microsoft/hcsshim/internal/interop"
- "github.com/Microsoft/hcsshim/internal/logfields"
- "github.com/sirupsen/logrus"
+ "github.com/Microsoft/hcsshim/internal/log"
+ "github.com/Microsoft/hcsshim/internal/oc"
+ "github.com/Microsoft/hcsshim/internal/vmcompute"
+ "go.opencensus.io/trace"
)
// ContainerError is an error encountered in HCS
type Process struct {
handleLock sync.RWMutex
- handle hcsProcess
+ handle vmcompute.HcsProcess
processID int
system *System
- cachedPipes *cachedPipes
+ stdin io.WriteCloser
+ stdout io.ReadCloser
+ stderr io.ReadCloser
callbackNumber uintptr
- logctx logrus.Fields
+ closedWaitOnce sync.Once
+ waitBlock chan struct{}
+ exitCode int
+ waitError error
}
-func newProcess(process hcsProcess, processID int, computeSystem *System) *Process {
+func newProcess(process vmcompute.HcsProcess, processID int, computeSystem *System) *Process {
return &Process{
handle: process,
processID: processID,
system: computeSystem,
- logctx: logrus.Fields{
- logfields.ContainerID: computeSystem.ID(),
- logfields.ProcessID: processID,
- },
+ waitBlock: make(chan struct{}),
}
}
-type cachedPipes struct {
- stdIn syscall.Handle
- stdOut syscall.Handle
- stdErr syscall.Handle
-}
-
type processModifyRequest struct {
Operation string
ConsoleSize *consoleSize `json:",omitempty"`
@@ -58,7 +55,7 @@ type closeHandle struct {
Handle string
}
-type ProcessStatus struct {
+type processStatus struct {
ProcessID uint32
Exited bool
ExitCode uint32
@@ -86,120 +83,153 @@ func (process *Process) SystemID() string {
return process.system.ID()
}
-func (process *Process) logOperationBegin(operation string) {
- logOperationBegin(
- process.logctx,
- operation+" - Begin Operation")
-}
-
-func (process *Process) logOperationEnd(operation string, err error) {
- var result string
- if err == nil {
- result = "Success"
- } else {
- result = "Error"
+func (process *Process) processSignalResult(ctx context.Context, err error) (bool, error) {
+ switch err {
+ case nil:
+ return true, nil
+ case ErrVmcomputeOperationInvalidState, ErrComputeSystemDoesNotExist, ErrElementNotFound:
+ select {
+ case <-process.waitBlock:
+ // The process exit notification has already arrived.
+ default:
+ // The process should be gone, but we have not received the notification.
+ // After a second, force unblock the process wait to work around a possible
+ // deadlock in the HCS.
+ go func() {
+ time.Sleep(time.Second)
+ process.closedWaitOnce.Do(func() {
+ log.G(ctx).WithError(err).Warn("force unblocking process waits")
+ process.exitCode = -1
+ process.waitError = err
+ close(process.waitBlock)
+ })
+ }()
+ }
+ return false, nil
+ default:
+ return false, err
}
-
- logOperationEnd(
- process.logctx,
- operation+" - End Operation - "+result,
- err)
}
// Signal signals the process with `options`.
-func (process *Process) Signal(options guestrequest.SignalProcessOptions) (err error) {
+//
+// For LCOW `guestrequest.SignalProcessOptionsLCOW`.
+//
+// For WCOW `guestrequest.SignalProcessOptionsWCOW`.
+func (process *Process) Signal(ctx context.Context, options interface{}) (bool, error) {
process.handleLock.RLock()
defer process.handleLock.RUnlock()
operation := "hcsshim::Process::Signal"
- process.logOperationBegin(operation)
- defer func() { process.logOperationEnd(operation, err) }()
if process.handle == 0 {
- return makeProcessError(process, operation, ErrAlreadyClosed, nil)
+ return false, makeProcessError(process, operation, ErrAlreadyClosed, nil)
}
optionsb, err := json.Marshal(options)
if err != nil {
- return err
+ return false, err
}
- optionsStr := string(optionsb)
-
- var resultp *uint16
- syscallWatcher(process.logctx, func() {
- err = hcsSignalProcess(process.handle, optionsStr, &resultp)
- })
- events := processHcsResult(resultp)
+ resultJSON, err := vmcompute.HcsSignalProcess(ctx, process.handle, string(optionsb))
+ events := processHcsResult(ctx, resultJSON)
+ delivered, err := process.processSignalResult(ctx, err)
if err != nil {
- return makeProcessError(process, operation, err, events)
+ err = makeProcessError(process, operation, err, events)
}
-
- return nil
+ return delivered, err
}
// Kill signals the process to terminate but does not wait for it to finish terminating.
-func (process *Process) Kill() (err error) {
+func (process *Process) Kill(ctx context.Context) (bool, error) {
process.handleLock.RLock()
defer process.handleLock.RUnlock()
operation := "hcsshim::Process::Kill"
- process.logOperationBegin(operation)
- defer func() { process.logOperationEnd(operation, err) }()
if process.handle == 0 {
- return makeProcessError(process, operation, ErrAlreadyClosed, nil)
+ return false, makeProcessError(process, operation, ErrAlreadyClosed, nil)
}
- var resultp *uint16
- syscallWatcher(process.logctx, func() {
- err = hcsTerminateProcess(process.handle, &resultp)
- })
- events := processHcsResult(resultp)
+ resultJSON, err := vmcompute.HcsTerminateProcess(ctx, process.handle)
+ events := processHcsResult(ctx, resultJSON)
+ delivered, err := process.processSignalResult(ctx, err)
if err != nil {
- return makeProcessError(process, operation, err, events)
+ err = makeProcessError(process, operation, err, events)
}
-
- return nil
+ return delivered, err
}
-// Wait waits for the process to exit.
-func (process *Process) Wait() (err error) {
- operation := "hcsshim::Process::Wait"
- process.logOperationBegin(operation)
- defer func() { process.logOperationEnd(operation, err) }()
+// waitBackground waits for the process exit notification. Once received sets
+// `process.waitError` (if any) and unblocks all `Wait` calls.
+//
+// This MUST be called exactly once per `process.handle` but `Wait` is safe to
+// call multiple times.
+func (process *Process) waitBackground() {
+ operation := "hcsshim::Process::waitBackground"
+ ctx, span := trace.StartSpan(context.Background(), operation)
+ defer span.End()
+ span.AddAttributes(
+ trace.StringAttribute("cid", process.SystemID()),
+ trace.Int64Attribute("pid", int64(process.processID)))
+
+ var (
+ err error
+ exitCode = -1
+ )
- err = waitForNotification(process.callbackNumber, hcsNotificationProcessExited, nil)
+ err = waitForNotification(ctx, process.callbackNumber, hcsNotificationProcessExited, nil)
if err != nil {
- return makeProcessError(process, operation, err, nil)
+ err = makeProcessError(process, operation, err, nil)
+ log.G(ctx).WithError(err).Error("failed wait")
+ } else {
+ process.handleLock.RLock()
+ defer process.handleLock.RUnlock()
+
+ // Make sure we didnt race with Close() here
+ if process.handle != 0 {
+ propertiesJSON, resultJSON, err := vmcompute.HcsGetProcessProperties(ctx, process.handle)
+ events := processHcsResult(ctx, resultJSON)
+ if err != nil {
+ err = makeProcessError(process, operation, err, events)
+ } else {
+ properties := &processStatus{}
+ err = json.Unmarshal([]byte(propertiesJSON), properties)
+ if err != nil {
+ err = makeProcessError(process, operation, err, nil)
+ } else {
+ if properties.LastWaitResult != 0 {
+ log.G(ctx).WithField("wait-result", properties.LastWaitResult).Warning("non-zero last wait result")
+ } else {
+ exitCode = int(properties.ExitCode)
+ }
+ }
+ }
+ }
}
+ log.G(ctx).WithField("exitCode", exitCode).Debug("process exited")
- return nil
+ process.closedWaitOnce.Do(func() {
+ process.exitCode = exitCode
+ process.waitError = err
+ close(process.waitBlock)
+ })
+ oc.SetSpanStatus(span, err)
}
-// WaitTimeout waits for the process to exit or the duration to elapse. It returns
-// false if timeout occurs.
-func (process *Process) WaitTimeout(timeout time.Duration) (err error) {
- operation := "hcssshim::Process::WaitTimeout"
- process.logOperationBegin(operation)
- defer func() { process.logOperationEnd(operation, err) }()
-
- err = waitForNotification(process.callbackNumber, hcsNotificationProcessExited, &timeout)
- if err != nil {
- return makeProcessError(process, operation, err, nil)
- }
-
- return nil
+// Wait waits for the process to exit. If the process has already exited returns
+// the pervious error (if any).
+func (process *Process) Wait() error {
+ <-process.waitBlock
+ return process.waitError
}
// ResizeConsole resizes the console of the process.
-func (process *Process) ResizeConsole(width, height uint16) (err error) {
+func (process *Process) ResizeConsole(ctx context.Context, width, height uint16) error {
process.handleLock.RLock()
defer process.handleLock.RUnlock()
operation := "hcsshim::Process::ResizeConsole"
- process.logOperationBegin(operation)
- defer func() { process.logOperationEnd(operation, err) }()
if process.handle == 0 {
return makeProcessError(process, operation, ErrAlreadyClosed, nil)
@@ -218,11 +248,8 @@ func (process *Process) ResizeConsole(width, height uint16) (err error) {
return err
}
- modifyRequestStr := string(modifyRequestb)
-
- var resultp *uint16
- err = hcsModifyProcess(process.handle, modifyRequestStr, &resultp)
- events := processHcsResult(resultp)
+ resultJSON, err := vmcompute.HcsModifyProcess(ctx, process.handle, string(modifyRequestb))
+ events := processHcsResult(ctx, resultJSON)
if err != nil {
return makeProcessError(process, operation, err, events)
}
@@ -230,104 +257,46 @@ func (process *Process) ResizeConsole(width, height uint16) (err error) {
return nil
}
-func (process *Process) Properties() (_ *ProcessStatus, err error) {
- process.handleLock.RLock()
- defer process.handleLock.RUnlock()
-
- operation := "hcsshim::Process::Properties"
- process.logOperationBegin(operation)
- defer func() { process.logOperationEnd(operation, err) }()
-
- if process.handle == 0 {
- return nil, makeProcessError(process, operation, ErrAlreadyClosed, nil)
- }
-
- var (
- resultp *uint16
- propertiesp *uint16
- )
- syscallWatcher(process.logctx, func() {
- err = hcsGetProcessProperties(process.handle, &propertiesp, &resultp)
- })
- events := processHcsResult(resultp)
- if err != nil {
- return nil, makeProcessError(process, operation, err, events)
- }
-
- if propertiesp == nil {
- return nil, ErrUnexpectedValue
- }
- propertiesRaw := interop.ConvertAndFreeCoTaskMemBytes(propertiesp)
-
- properties := &ProcessStatus{}
- if err := json.Unmarshal(propertiesRaw, properties); err != nil {
- return nil, makeProcessError(process, operation, err, nil)
- }
-
- return properties, nil
-}
-
// ExitCode returns the exit code of the process. The process must have
// already terminated.
-func (process *Process) ExitCode() (_ int, err error) {
- operation := "hcsshim::Process::ExitCode"
- process.logOperationBegin(operation)
- defer func() { process.logOperationEnd(operation, err) }()
-
- properties, err := process.Properties()
- if err != nil {
- return 0, makeProcessError(process, operation, err, nil)
- }
-
- if properties.Exited == false {
- return 0, makeProcessError(process, operation, ErrInvalidProcessState, nil)
- }
-
- if properties.LastWaitResult != 0 {
- return 0, makeProcessError(process, operation, syscall.Errno(properties.LastWaitResult), nil)
+func (process *Process) ExitCode() (int, error) {
+ select {
+ case <-process.waitBlock:
+ if process.waitError != nil {
+ return -1, process.waitError
+ }
+ return process.exitCode, nil
+ default:
+ return -1, makeProcessError(process, "hcsshim::Process::ExitCode", ErrInvalidProcessState, nil)
}
-
- return int(properties.ExitCode), nil
}
-// Stdio returns the stdin, stdout, and stderr pipes, respectively. Closing
-// these pipes does not close the underlying pipes; it should be possible to
-// call this multiple times to get multiple interfaces.
-func (process *Process) Stdio() (_ io.WriteCloser, _ io.ReadCloser, _ io.ReadCloser, err error) {
+// StdioLegacy returns the stdin, stdout, and stderr pipes, respectively. Closing
+// these pipes does not close the underlying pipes; but this function can only
+// be called once on each Process.
+func (process *Process) StdioLegacy() (_ io.WriteCloser, _ io.ReadCloser, _ io.ReadCloser, err error) {
+ operation := "hcsshim::Process::StdioLegacy"
+ ctx, span := trace.StartSpan(context.Background(), operation)
+ defer span.End()
+ defer func() { oc.SetSpanStatus(span, err) }()
+ span.AddAttributes(
+ trace.StringAttribute("cid", process.SystemID()),
+ trace.Int64Attribute("pid", int64(process.processID)))
+
process.handleLock.RLock()
defer process.handleLock.RUnlock()
- operation := "hcsshim::Process::Stdio"
- process.logOperationBegin(operation)
- defer func() { process.logOperationEnd(operation, err) }()
-
if process.handle == 0 {
return nil, nil, nil, makeProcessError(process, operation, ErrAlreadyClosed, nil)
}
- var stdIn, stdOut, stdErr syscall.Handle
-
- if process.cachedPipes == nil {
- var (
- processInfo hcsProcessInformation
- resultp *uint16
- )
- err = hcsGetProcessInfo(process.handle, &processInfo, &resultp)
- events := processHcsResult(resultp)
- if err != nil {
- return nil, nil, nil, makeProcessError(process, operation, err, events)
- }
-
- stdIn, stdOut, stdErr = processInfo.StdInput, processInfo.StdOutput, processInfo.StdError
- } else {
- // Use cached pipes
- stdIn, stdOut, stdErr = process.cachedPipes.stdIn, process.cachedPipes.stdOut, process.cachedPipes.stdErr
-
- // Invalidate the cache
- process.cachedPipes = nil
+ processInfo, resultJSON, err := vmcompute.HcsGetProcessInfo(ctx, process.handle)
+ events := processHcsResult(ctx, resultJSON)
+ if err != nil {
+ return nil, nil, nil, makeProcessError(process, operation, err, events)
}
- pipes, err := makeOpenFiles([]syscall.Handle{stdIn, stdOut, stdErr})
+ pipes, err := makeOpenFiles([]syscall.Handle{processInfo.StdInput, processInfo.StdOutput, processInfo.StdError})
if err != nil {
return nil, nil, nil, makeProcessError(process, operation, err, nil)
}
@@ -335,15 +304,19 @@ func (process *Process) Stdio() (_ io.WriteCloser, _ io.ReadCloser, _ io.ReadClo
return pipes[0], pipes[1], pipes[2], nil
}
+// Stdio returns the stdin, stdout, and stderr pipes, respectively.
+// To close them, close the process handle.
+func (process *Process) Stdio() (stdin io.Writer, stdout, stderr io.Reader) {
+ return process.stdin, process.stdout, process.stderr
+}
+
// CloseStdin closes the write side of the stdin pipe so that the process is
// notified on the read side that there is no more data in stdin.
-func (process *Process) CloseStdin() (err error) {
+func (process *Process) CloseStdin(ctx context.Context) error {
process.handleLock.RLock()
defer process.handleLock.RUnlock()
operation := "hcsshim::Process::CloseStdin"
- process.logOperationBegin(operation)
- defer func() { process.logOperationEnd(operation, err) }()
if process.handle == 0 {
return makeProcessError(process, operation, ErrAlreadyClosed, nil)
@@ -361,96 +334,116 @@ func (process *Process) CloseStdin() (err error) {
return err
}
- modifyRequestStr := string(modifyRequestb)
-
- var resultp *uint16
- err = hcsModifyProcess(process.handle, modifyRequestStr, &resultp)
- events := processHcsResult(resultp)
+ resultJSON, err := vmcompute.HcsModifyProcess(ctx, process.handle, string(modifyRequestb))
+ events := processHcsResult(ctx, resultJSON)
if err != nil {
return makeProcessError(process, operation, err, events)
}
+ if process.stdin != nil {
+ process.stdin.Close()
+ }
return nil
}
// Close cleans up any state associated with the process but does not kill
// or wait on it.
func (process *Process) Close() (err error) {
+ operation := "hcsshim::Process::Close"
+ ctx, span := trace.StartSpan(context.Background(), operation)
+ defer span.End()
+ defer func() { oc.SetSpanStatus(span, err) }()
+ span.AddAttributes(
+ trace.StringAttribute("cid", process.SystemID()),
+ trace.Int64Attribute("pid", int64(process.processID)))
+
process.handleLock.Lock()
defer process.handleLock.Unlock()
- operation := "hcsshim::Process::Close"
- process.logOperationBegin(operation)
- defer func() { process.logOperationEnd(operation, err) }()
-
// Don't double free this
if process.handle == 0 {
return nil
}
- if err = process.unregisterCallback(); err != nil {
+ if process.stdin != nil {
+ process.stdin.Close()
+ }
+ if process.stdout != nil {
+ process.stdout.Close()
+ }
+ if process.stderr != nil {
+ process.stderr.Close()
+ }
+
+ if err = process.unregisterCallback(ctx); err != nil {
return makeProcessError(process, operation, err, nil)
}
- if err = hcsCloseProcess(process.handle); err != nil {
+ if err = vmcompute.HcsCloseProcess(ctx, process.handle); err != nil {
return makeProcessError(process, operation, err, nil)
}
process.handle = 0
+ process.closedWaitOnce.Do(func() {
+ process.exitCode = -1
+ process.waitError = ErrAlreadyClosed
+ close(process.waitBlock)
+ })
return nil
}
-func (process *Process) registerCallback() error {
- context := &notifcationWatcherContext{
- channels: newChannels(),
+func (process *Process) registerCallback(ctx context.Context) error {
+ callbackContext := &notifcationWatcherContext{
+ channels: newProcessChannels(),
+ systemID: process.SystemID(),
+ processID: process.processID,
}
callbackMapLock.Lock()
callbackNumber := nextCallback
nextCallback++
- callbackMap[callbackNumber] = context
+ callbackMap[callbackNumber] = callbackContext
callbackMapLock.Unlock()
- var callbackHandle hcsCallback
- err := hcsRegisterProcessCallback(process.handle, notificationWatcherCallback, callbackNumber, &callbackHandle)
+ callbackHandle, err := vmcompute.HcsRegisterProcessCallback(ctx, process.handle, notificationWatcherCallback, callbackNumber)
if err != nil {
return err
}
- context.handle = callbackHandle
+ callbackContext.handle = callbackHandle
process.callbackNumber = callbackNumber
return nil
}
-func (process *Process) unregisterCallback() error {
+func (process *Process) unregisterCallback(ctx context.Context) error {
callbackNumber := process.callbackNumber
callbackMapLock.RLock()
- context := callbackMap[callbackNumber]
+ callbackContext := callbackMap[callbackNumber]
callbackMapLock.RUnlock()
- if context == nil {
+ if callbackContext == nil {
return nil
}
- handle := context.handle
+ handle := callbackContext.handle
if handle == 0 {
return nil
}
- // hcsUnregisterProcessCallback has its own syncronization
- // to wait for all callbacks to complete. We must NOT hold the callbackMapLock.
- err := hcsUnregisterProcessCallback(handle)
+ // vmcompute.HcsUnregisterProcessCallback has its own synchronization to
+ // wait for all callbacks to complete. We must NOT hold the callbackMapLock.
+ err := vmcompute.HcsUnregisterProcessCallback(ctx, handle)
if err != nil {
return err
}
- closeChannels(context.channels)
+ closeChannels(callbackContext.channels)
callbackMapLock.Lock()
- callbackMap[callbackNumber] = nil
+ delete(callbackMap, callbackNumber)
callbackMapLock.Unlock()
handle = 0
diff --git a/vendor/github.com/Microsoft/hcsshim/internal/hcs/system.go b/vendor/github.com/Microsoft/hcsshim/internal/hcs/system.go
index 20b242524..98df25bd5 100644
--- a/vendor/github.com/Microsoft/hcsshim/internal/hcs/system.go
+++ b/vendor/github.com/Microsoft/hcsshim/internal/hcs/system.go
@@ -1,18 +1,24 @@
package hcs
import (
+ "context"
"encoding/json"
+ "errors"
"os"
"strconv"
+ "strings"
"sync"
"syscall"
"time"
- "github.com/Microsoft/hcsshim/internal/interop"
- "github.com/Microsoft/hcsshim/internal/logfields"
+ "github.com/Microsoft/hcsshim/internal/cow"
+ "github.com/Microsoft/hcsshim/internal/log"
+ "github.com/Microsoft/hcsshim/internal/oc"
"github.com/Microsoft/hcsshim/internal/schema1"
+ hcsschema "github.com/Microsoft/hcsshim/internal/schema2"
"github.com/Microsoft/hcsshim/internal/timeout"
- "github.com/sirupsen/logrus"
+ "github.com/Microsoft/hcsshim/internal/vmcompute"
+ "go.opencensus.io/trace"
)
// currentContainerStarts is used to limit the number of concurrent container
@@ -38,49 +44,37 @@ func init() {
type System struct {
handleLock sync.RWMutex
- handle hcsSystem
+ handle vmcompute.HcsSystem
id string
callbackNumber uintptr
- logctx logrus.Fields
+ closedWaitOnce sync.Once
+ waitBlock chan struct{}
+ waitError error
+ exitError error
+
+ os, typ string
}
func newSystem(id string) *System {
return &System{
- id: id,
- logctx: logrus.Fields{
- logfields.ContainerID: id,
- },
- }
-}
-
-func (computeSystem *System) logOperationBegin(operation string) {
- logOperationBegin(
- computeSystem.logctx,
- operation+" - Begin Operation")
-}
-
-func (computeSystem *System) logOperationEnd(operation string, err error) {
- var result string
- if err == nil {
- result = "Success"
- } else {
- result = "Error"
+ id: id,
+ waitBlock: make(chan struct{}),
}
-
- logOperationEnd(
- computeSystem.logctx,
- operation+" - End Operation - "+result,
- err)
}
// CreateComputeSystem creates a new compute system with the given configuration but does not start it.
-func CreateComputeSystem(id string, hcsDocumentInterface interface{}) (_ *System, err error) {
+func CreateComputeSystem(ctx context.Context, id string, hcsDocumentInterface interface{}) (_ *System, err error) {
operation := "hcsshim::CreateComputeSystem"
+ // hcsCreateComputeSystemContext is an async operation. Start the outer span
+ // here to measure the full create time.
+ ctx, span := trace.StartSpan(ctx, operation)
+ defer span.End()
+ defer func() { oc.SetSpanStatus(span, err) }()
+ span.AddAttributes(trace.StringAttribute("cid", id))
+
computeSystem := newSystem(id)
- computeSystem.logOperationBegin(operation)
- defer func() { computeSystem.logOperationEnd(operation, err) }()
hcsDocumentB, err := json.Marshal(hcsDocumentInterface)
if err != nil {
@@ -89,126 +83,114 @@ func CreateComputeSystem(id string, hcsDocumentInterface interface{}) (_ *System
hcsDocument := string(hcsDocumentB)
- logrus.WithFields(computeSystem.logctx).
- WithField(logfields.JSON, hcsDocument).
- Debug("HCS ComputeSystem Document")
-
var (
- resultp *uint16
identity syscall.Handle
+ resultJSON string
createError error
)
- syscallWatcher(computeSystem.logctx, func() {
- createError = hcsCreateComputeSystem(id, hcsDocument, identity, &computeSystem.handle, &resultp)
- })
-
+ computeSystem.handle, resultJSON, createError = vmcompute.HcsCreateComputeSystem(ctx, id, hcsDocument, identity)
if createError == nil || IsPending(createError) {
- if err = computeSystem.registerCallback(); err != nil {
+ defer func() {
+ if err != nil {
+ computeSystem.Close()
+ }
+ }()
+ if err = computeSystem.registerCallback(ctx); err != nil {
// Terminate the compute system if it still exists. We're okay to
// ignore a failure here.
- computeSystem.Terminate()
+ computeSystem.Terminate(ctx)
return nil, makeSystemError(computeSystem, operation, "", err, nil)
}
}
- events, err := processAsyncHcsResult(createError, resultp, computeSystem.callbackNumber, hcsNotificationSystemCreateCompleted, &timeout.SystemCreate)
+ events, err := processAsyncHcsResult(ctx, createError, resultJSON, computeSystem.callbackNumber, hcsNotificationSystemCreateCompleted, &timeout.SystemCreate)
if err != nil {
if err == ErrTimeout {
// Terminate the compute system if it still exists. We're okay to
// ignore a failure here.
- computeSystem.Terminate()
+ computeSystem.Terminate(ctx)
}
return nil, makeSystemError(computeSystem, operation, hcsDocument, err, events)
}
-
+ go computeSystem.waitBackground()
+ if err = computeSystem.getCachedProperties(ctx); err != nil {
+ return nil, err
+ }
return computeSystem, nil
}
// OpenComputeSystem opens an existing compute system by ID.
-func OpenComputeSystem(id string) (_ *System, err error) {
+func OpenComputeSystem(ctx context.Context, id string) (*System, error) {
operation := "hcsshim::OpenComputeSystem"
computeSystem := newSystem(id)
- computeSystem.logOperationBegin(operation)
+ handle, resultJSON, err := vmcompute.HcsOpenComputeSystem(ctx, id)
+ events := processHcsResult(ctx, resultJSON)
+ if err != nil {
+ return nil, makeSystemError(computeSystem, operation, "", err, events)
+ }
+ computeSystem.handle = handle
defer func() {
- if IsNotExist(err) {
- computeSystem.logOperationEnd(operation, nil)
- } else {
- computeSystem.logOperationEnd(operation, err)
+ if err != nil {
+ computeSystem.Close()
}
}()
+ if err = computeSystem.registerCallback(ctx); err != nil {
+ return nil, makeSystemError(computeSystem, operation, "", err, nil)
+ }
+ go computeSystem.waitBackground()
+ if err = computeSystem.getCachedProperties(ctx); err != nil {
+ return nil, err
+ }
+ return computeSystem, nil
+}
- var (
- handle hcsSystem
- resultp *uint16
- )
- err = hcsOpenComputeSystem(id, &handle, &resultp)
- events := processHcsResult(resultp)
+func (computeSystem *System) getCachedProperties(ctx context.Context) error {
+ props, err := computeSystem.Properties(ctx)
if err != nil {
- return nil, makeSystemError(computeSystem, operation, "", err, events)
+ return err
}
-
- computeSystem.handle = handle
-
- if err = computeSystem.registerCallback(); err != nil {
- return nil, makeSystemError(computeSystem, operation, "", err, nil)
+ computeSystem.typ = strings.ToLower(props.SystemType)
+ computeSystem.os = strings.ToLower(props.RuntimeOSType)
+ if computeSystem.os == "" && computeSystem.typ == "container" {
+ // Pre-RS5 HCS did not return the OS, but it only supported containers
+ // that ran Windows.
+ computeSystem.os = "windows"
}
+ return nil
+}
- return computeSystem, nil
+// OS returns the operating system of the compute system, "linux" or "windows".
+func (computeSystem *System) OS() string {
+ return computeSystem.os
+}
+
+// IsOCI returns whether processes in the compute system should be created via
+// OCI.
+func (computeSystem *System) IsOCI() bool {
+ return computeSystem.os == "linux" && computeSystem.typ == "container"
}
// GetComputeSystems gets a list of the compute systems on the system that match the query
-func GetComputeSystems(q schema1.ComputeSystemQuery) (_ []schema1.ContainerProperties, err error) {
+func GetComputeSystems(ctx context.Context, q schema1.ComputeSystemQuery) ([]schema1.ContainerProperties, error) {
operation := "hcsshim::GetComputeSystems"
- fields := logrus.Fields{}
- logOperationBegin(
- fields,
- operation+" - Begin Operation")
-
- defer func() {
- var result string
- if err == nil {
- result = "Success"
- } else {
- result = "Error"
- }
-
- logOperationEnd(
- fields,
- operation+" - End Operation - "+result,
- err)
- }()
queryb, err := json.Marshal(q)
if err != nil {
return nil, err
}
- query := string(queryb)
-
- logrus.WithFields(fields).
- WithField(logfields.JSON, query).
- Debug("HCS ComputeSystem Query")
-
- var (
- resultp *uint16
- computeSystemsp *uint16
- )
-
- syscallWatcher(fields, func() {
- err = hcsEnumerateComputeSystems(query, &computeSystemsp, &resultp)
- })
- events := processHcsResult(resultp)
+ computeSystemsJSON, resultJSON, err := vmcompute.HcsEnumerateComputeSystems(ctx, string(queryb))
+ events := processHcsResult(ctx, resultJSON)
if err != nil {
return nil, &HcsError{Op: operation, Err: err, Events: events}
}
- if computeSystemsp == nil {
+ if computeSystemsJSON == "" {
return nil, ErrUnexpectedValue
}
- computeSystemsRaw := interop.ConvertAndFreeCoTaskMemBytes(computeSystemsp)
computeSystems := []schema1.ContainerProperties{}
- if err = json.Unmarshal(computeSystemsRaw, &computeSystems); err != nil {
+ if err = json.Unmarshal([]byte(computeSystemsJSON), &computeSystems); err != nil {
return nil, err
}
@@ -216,16 +198,21 @@ func GetComputeSystems(q schema1.ComputeSystemQuery) (_ []schema1.ContainerPrope
}
// Start synchronously starts the computeSystem.
-func (computeSystem *System) Start() (err error) {
+func (computeSystem *System) Start(ctx context.Context) (err error) {
+ operation := "hcsshim::System::Start"
+
+ // hcsStartComputeSystemContext is an async operation. Start the outer span
+ // here to measure the full start 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()
- operation := "hcsshim::ComputeSystem::Start"
- computeSystem.logOperationBegin(operation)
- defer func() { computeSystem.logOperationEnd(operation, err) }()
-
if computeSystem.handle == 0 {
- return makeSystemError(computeSystem, "Start", "", ErrAlreadyClosed, nil)
+ return makeSystemError(computeSystem, operation, "", ErrAlreadyClosed, nil)
}
// This is a very simple backoff-retry loop to limit the number
@@ -254,13 +241,10 @@ func (computeSystem *System) Start() (err error) {
}()
}
- var resultp *uint16
- syscallWatcher(computeSystem.logctx, func() {
- err = hcsStartComputeSystem(computeSystem.handle, "", &resultp)
- })
- events, err := processAsyncHcsResult(err, resultp, computeSystem.callbackNumber, hcsNotificationSystemStartCompleted, &timeout.SystemStart)
+ resultJSON, err := vmcompute.HcsStartComputeSystem(ctx, computeSystem.handle, "")
+ events, err := processAsyncHcsResult(ctx, err, resultJSON, computeSystem.callbackNumber, hcsNotificationSystemStartCompleted, &timeout.SystemStart)
if err != nil {
- return makeSystemError(computeSystem, "Start", "", err, events)
+ return makeSystemError(computeSystem, operation, "", err, events)
}
return nil
@@ -271,360 +255,388 @@ func (computeSystem *System) ID() string {
return computeSystem.id
}
-// Shutdown requests a compute system shutdown, if IsPending() on the error returned is true,
-// it may not actually be shut down until Wait() succeeds.
-func (computeSystem *System) Shutdown() (err error) {
+// Shutdown requests a compute system shutdown.
+func (computeSystem *System) Shutdown(ctx context.Context) error {
computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock()
- operation := "hcsshim::ComputeSystem::Shutdown"
- computeSystem.logOperationBegin(operation)
- defer func() {
- if IsAlreadyStopped(err) {
- computeSystem.logOperationEnd(operation, nil)
- } else {
- computeSystem.logOperationEnd(operation, err)
- }
- }()
+ operation := "hcsshim::System::Shutdown"
if computeSystem.handle == 0 {
- return makeSystemError(computeSystem, "Shutdown", "", ErrAlreadyClosed, nil)
+ return nil
}
- var resultp *uint16
- syscallWatcher(computeSystem.logctx, func() {
- err = hcsShutdownComputeSystem(computeSystem.handle, "", &resultp)
- })
- events := processHcsResult(resultp)
- if err != nil {
- return makeSystemError(computeSystem, "Shutdown", "", err, events)
+ resultJSON, err := vmcompute.HcsShutdownComputeSystem(ctx, computeSystem.handle, "")
+ events := processHcsResult(ctx, resultJSON)
+ switch err {
+ case nil, ErrVmcomputeAlreadyStopped, ErrComputeSystemDoesNotExist, ErrVmcomputeOperationPending:
+ default:
+ return makeSystemError(computeSystem, operation, "", err, events)
}
-
return nil
}
-// Terminate requests a compute system terminate, if IsPending() on the error returned is true,
-// it may not actually be shut down until Wait() succeeds.
-func (computeSystem *System) Terminate() (err error) {
+// Terminate requests a compute system terminate.
+func (computeSystem *System) Terminate(ctx context.Context) error {
computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock()
- operation := "hcsshim::ComputeSystem::Terminate"
- computeSystem.logOperationBegin(operation)
- defer func() {
- if IsPending(err) {
- computeSystem.logOperationEnd(operation, nil)
- } else {
- computeSystem.logOperationEnd(operation, err)
- }
- }()
+ operation := "hcsshim::System::Terminate"
if computeSystem.handle == 0 {
- return makeSystemError(computeSystem, "Terminate", "", ErrAlreadyClosed, nil)
+ return nil
}
- var resultp *uint16
- syscallWatcher(computeSystem.logctx, func() {
- err = hcsTerminateComputeSystem(computeSystem.handle, "", &resultp)
- })
- events := processHcsResult(resultp)
- if err != nil && err != ErrVmcomputeAlreadyStopped {
- return makeSystemError(computeSystem, "Terminate", "", err, events)
+ resultJSON, err := vmcompute.HcsTerminateComputeSystem(ctx, computeSystem.handle, "")
+ events := processHcsResult(ctx, resultJSON)
+ switch err {
+ case nil, ErrVmcomputeAlreadyStopped, ErrComputeSystemDoesNotExist, ErrVmcomputeOperationPending:
+ default:
+ return makeSystemError(computeSystem, operation, "", err, events)
}
-
return nil
}
-// Wait synchronously waits for the compute system to shutdown or terminate.
-func (computeSystem *System) Wait() (err error) {
- operation := "hcsshim::ComputeSystem::Wait"
- computeSystem.logOperationBegin(operation)
- defer func() { computeSystem.logOperationEnd(operation, err) }()
-
- err = waitForNotification(computeSystem.callbackNumber, hcsNotificationSystemExited, nil)
- if err != nil {
- return makeSystemError(computeSystem, "Wait", "", err, nil)
- }
-
- return nil
+// waitBackground waits for the compute system exit notification. Once received
+// sets `computeSystem.waitError` (if any) and unblocks all `Wait` calls.
+//
+// This MUST be called exactly once per `computeSystem.handle` but `Wait` is
+// safe to call multiple times.
+func (computeSystem *System) waitBackground() {
+ operation := "hcsshim::System::waitBackground"
+ ctx, span := trace.StartSpan(context.Background(), operation)
+ defer span.End()
+ span.AddAttributes(trace.StringAttribute("cid", computeSystem.id))
+
+ err := waitForNotification(ctx, computeSystem.callbackNumber, hcsNotificationSystemExited, nil)
+ switch err {
+ case nil:
+ log.G(ctx).Debug("system exited")
+ case ErrVmcomputeUnexpectedExit:
+ log.G(ctx).Debug("unexpected system exit")
+ computeSystem.exitError = makeSystemError(computeSystem, operation, "", err, nil)
+ err = nil
+ default:
+ err = makeSystemError(computeSystem, operation, "", err, nil)
+ }
+ computeSystem.closedWaitOnce.Do(func() {
+ computeSystem.waitError = err
+ close(computeSystem.waitBlock)
+ })
+ oc.SetSpanStatus(span, err)
}
-// WaitExpectedError synchronously waits for the compute system to shutdown or
-// terminate, and ignores the passed error if it occurs.
-func (computeSystem *System) WaitExpectedError(expected error) (err error) {
- operation := "hcsshim::ComputeSystem::WaitExpectedError"
- computeSystem.logOperationBegin(operation)
- defer func() { computeSystem.logOperationEnd(operation, err) }()
+// Wait synchronously waits for the compute system to shutdown or terminate. If
+// the compute system has already exited returns the previous error (if any).
+func (computeSystem *System) Wait() error {
+ <-computeSystem.waitBlock
+ return computeSystem.waitError
+}
- err = waitForNotification(computeSystem.callbackNumber, hcsNotificationSystemExited, nil)
- if err != nil && getInnerError(err) != expected {
- return makeSystemError(computeSystem, "WaitExpectedError", "", err, nil)
+// ExitError returns an error describing the reason the compute system terminated.
+func (computeSystem *System) ExitError() error {
+ select {
+ case <-computeSystem.waitBlock:
+ if computeSystem.waitError != nil {
+ return computeSystem.waitError
+ }
+ return computeSystem.exitError
+ default:
+ return errors.New("container not exited")
}
-
- return nil
}
-// WaitTimeout synchronously waits for the compute system to terminate or the duration to elapse.
-// If the timeout expires, IsTimeout(err) == true
-func (computeSystem *System) WaitTimeout(timeout time.Duration) (err error) {
- operation := "hcsshim::ComputeSystem::WaitTimeout"
- computeSystem.logOperationBegin(operation)
- defer func() { computeSystem.logOperationEnd(operation, err) }()
+// Properties returns the requested container properties targeting a V1 schema container.
+func (computeSystem *System) Properties(ctx context.Context, types ...schema1.PropertyType) (*schema1.ContainerProperties, error) {
+ computeSystem.handleLock.RLock()
+ defer computeSystem.handleLock.RUnlock()
+
+ operation := "hcsshim::System::Properties"
+
+ queryBytes, err := json.Marshal(schema1.PropertyQuery{PropertyTypes: types})
+ if err != nil {
+ return nil, makeSystemError(computeSystem, operation, "", err, nil)
+ }
- err = waitForNotification(computeSystem.callbackNumber, hcsNotificationSystemExited, &timeout)
+ propertiesJSON, resultJSON, err := vmcompute.HcsGetComputeSystemProperties(ctx, computeSystem.handle, string(queryBytes))
+ events := processHcsResult(ctx, resultJSON)
if err != nil {
- return makeSystemError(computeSystem, "WaitTimeout", "", err, nil)
+ return nil, makeSystemError(computeSystem, operation, "", err, events)
}
- return nil
+ if propertiesJSON == "" {
+ return nil, ErrUnexpectedValue
+ }
+ properties := &schema1.ContainerProperties{}
+ if err := json.Unmarshal([]byte(propertiesJSON), properties); err != nil {
+ return nil, makeSystemError(computeSystem, operation, "", err, nil)
+ }
+
+ return properties, nil
}
-func (computeSystem *System) Properties(types ...schema1.PropertyType) (_ *schema1.ContainerProperties, err error) {
+// PropertiesV2 returns the requested container properties targeting a V2 schema container.
+func (computeSystem *System) PropertiesV2(ctx context.Context, types ...hcsschema.PropertyType) (*hcsschema.Properties, error) {
computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock()
- operation := "hcsshim::ComputeSystem::Properties"
- computeSystem.logOperationBegin(operation)
- defer func() { computeSystem.logOperationEnd(operation, err) }()
+ operation := "hcsshim::System::PropertiesV2"
- queryj, err := json.Marshal(schema1.PropertyQuery{types})
+ queryBytes, err := json.Marshal(hcsschema.PropertyQuery{PropertyTypes: types})
if err != nil {
- return nil, makeSystemError(computeSystem, "Properties", "", err, nil)
+ return nil, makeSystemError(computeSystem, operation, "", err, nil)
}
- logrus.WithFields(computeSystem.logctx).
- WithField(logfields.JSON, queryj).
- Debug("HCS ComputeSystem Properties Query")
-
- var resultp, propertiesp *uint16
- syscallWatcher(computeSystem.logctx, func() {
- err = hcsGetComputeSystemProperties(computeSystem.handle, string(queryj), &propertiesp, &resultp)
- })
- events := processHcsResult(resultp)
+ propertiesJSON, resultJSON, err := vmcompute.HcsGetComputeSystemProperties(ctx, computeSystem.handle, string(queryBytes))
+ events := processHcsResult(ctx, resultJSON)
if err != nil {
- return nil, makeSystemError(computeSystem, "Properties", "", err, events)
+ return nil, makeSystemError(computeSystem, operation, "", err, events)
}
- if propertiesp == nil {
+ if propertiesJSON == "" {
return nil, ErrUnexpectedValue
}
- propertiesRaw := interop.ConvertAndFreeCoTaskMemBytes(propertiesp)
- properties := &schema1.ContainerProperties{}
- if err := json.Unmarshal(propertiesRaw, properties); err != nil {
- return nil, makeSystemError(computeSystem, "Properties", "", err, nil)
+ properties := &hcsschema.Properties{}
+ if err := json.Unmarshal([]byte(propertiesJSON), properties); err != nil {
+ return nil, makeSystemError(computeSystem, operation, "", err, nil)
}
return properties, nil
}
// Pause pauses the execution of the computeSystem. This feature is not enabled in TP5.
-func (computeSystem *System) Pause() (err error) {
+func (computeSystem *System) Pause(ctx context.Context) (err error) {
+ operation := "hcsshim::System::Pause"
+
+ // hcsPauseComputeSystemContext is an async peration. Start the outer span
+ // here to measure the full pause 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()
- operation := "hcsshim::ComputeSystem::Pause"
- computeSystem.logOperationBegin(operation)
- defer func() { computeSystem.logOperationEnd(operation, err) }()
-
if computeSystem.handle == 0 {
- return makeSystemError(computeSystem, "Pause", "", ErrAlreadyClosed, nil)
+ return makeSystemError(computeSystem, operation, "", ErrAlreadyClosed, nil)
}
- var resultp *uint16
- syscallWatcher(computeSystem.logctx, func() {
- err = hcsPauseComputeSystem(computeSystem.handle, "", &resultp)
- })
- events, err := processAsyncHcsResult(err, resultp, computeSystem.callbackNumber, hcsNotificationSystemPauseCompleted, &timeout.SystemPause)
+ resultJSON, err := vmcompute.HcsPauseComputeSystem(ctx, computeSystem.handle, "")
+ events, err := processAsyncHcsResult(ctx, err, resultJSON, computeSystem.callbackNumber, hcsNotificationSystemPauseCompleted, &timeout.SystemPause)
if err != nil {
- return makeSystemError(computeSystem, "Pause", "", err, events)
+ return makeSystemError(computeSystem, operation, "", err, events)
}
return nil
}
// Resume resumes the execution of the computeSystem. This feature is not enabled in TP5.
-func (computeSystem *System) Resume() (err error) {
+func (computeSystem *System) Resume(ctx context.Context) (err error) {
+ operation := "hcsshim::System::Resume"
+
+ // hcsResumeComputeSystemContext is an async operation. Start the outer span
+ // here to measure the full restore 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()
- operation := "hcsshim::ComputeSystem::Resume"
- computeSystem.logOperationBegin(operation)
- defer func() { computeSystem.logOperationEnd(operation, err) }()
-
if computeSystem.handle == 0 {
- return makeSystemError(computeSystem, "Resume", "", ErrAlreadyClosed, nil)
+ return makeSystemError(computeSystem, operation, "", ErrAlreadyClosed, nil)
}
- var resultp *uint16
- syscallWatcher(computeSystem.logctx, func() {
- err = hcsResumeComputeSystem(computeSystem.handle, "", &resultp)
- })
- events, err := processAsyncHcsResult(err, resultp, computeSystem.callbackNumber, hcsNotificationSystemResumeCompleted, &timeout.SystemResume)
+ resultJSON, err := vmcompute.HcsResumeComputeSystem(ctx, computeSystem.handle, "")
+ events, err := processAsyncHcsResult(ctx, err, resultJSON, computeSystem.callbackNumber, hcsNotificationSystemResumeCompleted, &timeout.SystemResume)
if err != nil {
- return makeSystemError(computeSystem, "Resume", "", err, events)
+ return makeSystemError(computeSystem, operation, "", err, events)
}
return nil
}
-// CreateProcess launches a new process within the computeSystem.
-func (computeSystem *System) CreateProcess(c interface{}) (_ *Process, err error) {
+func (computeSystem *System) createProcess(ctx context.Context, operation string, c interface{}) (*Process, *vmcompute.HcsProcessInformation, error) {
computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock()
- operation := "hcsshim::ComputeSystem::CreateProcess"
- computeSystem.logOperationBegin(operation)
- defer func() { computeSystem.logOperationEnd(operation, err) }()
-
- var (
- processInfo hcsProcessInformation
- processHandle hcsProcess
- resultp *uint16
- )
-
if computeSystem.handle == 0 {
- return nil, makeSystemError(computeSystem, "CreateProcess", "", ErrAlreadyClosed, nil)
+ return nil, nil, makeSystemError(computeSystem, operation, "", ErrAlreadyClosed, nil)
}
configurationb, err := json.Marshal(c)
if err != nil {
- return nil, makeSystemError(computeSystem, "CreateProcess", "", err, nil)
+ return nil, nil, makeSystemError(computeSystem, operation, "", err, nil)
}
configuration := string(configurationb)
+ processInfo, processHandle, resultJSON, err := vmcompute.HcsCreateProcess(ctx, computeSystem.handle, configuration)
+ events := processHcsResult(ctx, resultJSON)
+ if err != nil {
+ return nil, nil, makeSystemError(computeSystem, operation, configuration, err, events)
+ }
- logrus.WithFields(computeSystem.logctx).
- WithField(logfields.JSON, configuration).
- Debug("HCS ComputeSystem Process Document")
+ log.G(ctx).WithField("pid", processInfo.ProcessId).Debug("created process pid")
+ return newProcess(processHandle, int(processInfo.ProcessId), computeSystem), &processInfo, nil
+}
- syscallWatcher(computeSystem.logctx, func() {
- err = hcsCreateProcess(computeSystem.handle, configuration, &processInfo, &processHandle, &resultp)
- })
- events := processHcsResult(resultp)
+// CreateProcessNoStdio launches a new process within the computeSystem. The
+// Stdio handles are not cached on the process struct.
+func (computeSystem *System) CreateProcessNoStdio(c interface{}) (_ cow.Process, err error) {
+ operation := "hcsshim::System::CreateProcessNoStdio"
+ ctx, span := trace.StartSpan(context.Background(), operation)
+ defer span.End()
+ defer func() { oc.SetSpanStatus(span, err) }()
+ span.AddAttributes(trace.StringAttribute("cid", computeSystem.id))
+
+ process, processInfo, err := computeSystem.createProcess(ctx, operation, c)
if err != nil {
- return nil, makeSystemError(computeSystem, "CreateProcess", configuration, err, events)
+ return nil, err
}
+ defer func() {
+ if err != nil {
+ process.Close()
+ }
+ }()
+
+ // We don't do anything with these handles. Close them so they don't leak.
+ syscall.Close(processInfo.StdInput)
+ syscall.Close(processInfo.StdOutput)
+ syscall.Close(processInfo.StdError)
- logrus.WithFields(computeSystem.logctx).
- WithField(logfields.ProcessID, processInfo.ProcessId).
- Debug("HCS ComputeSystem CreateProcess PID")
+ if err = process.registerCallback(ctx); err != nil {
+ return nil, makeSystemError(computeSystem, operation, "", err, nil)
+ }
+ go process.waitBackground()
+
+ return process, nil
+}
+
+// CreateProcess launches a new process within the computeSystem.
+func (computeSystem *System) CreateProcess(ctx context.Context, c interface{}) (cow.Process, error) {
+ operation := "hcsshim::System::CreateProcess"
+ process, processInfo, err := computeSystem.createProcess(ctx, operation, c)
+ if err != nil {
+ return nil, err
+ }
+ defer func() {
+ if err != nil {
+ process.Close()
+ }
+ }()
- process := newProcess(processHandle, int(processInfo.ProcessId), computeSystem)
- process.cachedPipes = &cachedPipes{
- stdIn: processInfo.StdInput,
- stdOut: processInfo.StdOutput,
- stdErr: processInfo.StdError,
+ pipes, err := makeOpenFiles([]syscall.Handle{processInfo.StdInput, processInfo.StdOutput, processInfo.StdError})
+ if err != nil {
+ return nil, makeSystemError(computeSystem, operation, "", err, nil)
}
+ process.stdin = pipes[0]
+ process.stdout = pipes[1]
+ process.stderr = pipes[2]
- if err = process.registerCallback(); err != nil {
- return nil, makeSystemError(computeSystem, "CreateProcess", "", err, nil)
+ if err = process.registerCallback(ctx); err != nil {
+ return nil, makeSystemError(computeSystem, operation, "", err, nil)
}
+ go process.waitBackground()
return process, nil
}
// OpenProcess gets an interface to an existing process within the computeSystem.
-func (computeSystem *System) OpenProcess(pid int) (_ *Process, err error) {
+func (computeSystem *System) OpenProcess(ctx context.Context, pid int) (*Process, error) {
computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock()
- // Add PID for the context of this operation
- computeSystem.logctx[logfields.ProcessID] = pid
- defer delete(computeSystem.logctx, logfields.ProcessID)
-
- operation := "hcsshim::ComputeSystem::OpenProcess"
- computeSystem.logOperationBegin(operation)
- defer func() { computeSystem.logOperationEnd(operation, err) }()
-
- var (
- processHandle hcsProcess
- resultp *uint16
- )
+ operation := "hcsshim::System::OpenProcess"
if computeSystem.handle == 0 {
- return nil, makeSystemError(computeSystem, "OpenProcess", "", ErrAlreadyClosed, nil)
+ return nil, makeSystemError(computeSystem, operation, "", ErrAlreadyClosed, nil)
}
- syscallWatcher(computeSystem.logctx, func() {
- err = hcsOpenProcess(computeSystem.handle, uint32(pid), &processHandle, &resultp)
- })
- events := processHcsResult(resultp)
+ processHandle, resultJSON, err := vmcompute.HcsOpenProcess(ctx, computeSystem.handle, uint32(pid))
+ events := processHcsResult(ctx, resultJSON)
if err != nil {
- return nil, makeSystemError(computeSystem, "OpenProcess", "", err, events)
+ return nil, makeSystemError(computeSystem, operation, "", err, events)
}
process := newProcess(processHandle, pid, computeSystem)
- if err = process.registerCallback(); err != nil {
- return nil, makeSystemError(computeSystem, "OpenProcess", "", err, nil)
+ if err = process.registerCallback(ctx); err != nil {
+ return nil, makeSystemError(computeSystem, operation, "", err, nil)
}
+ go process.waitBackground()
return process, nil
}
// Close cleans up any state associated with the compute system but does not terminate or wait for it.
func (computeSystem *System) Close() (err error) {
+ operation := "hcsshim::System::Close"
+ ctx, span := trace.StartSpan(context.Background(), operation)
+ defer span.End()
+ defer func() { oc.SetSpanStatus(span, err) }()
+ span.AddAttributes(trace.StringAttribute("cid", computeSystem.id))
+
computeSystem.handleLock.Lock()
defer computeSystem.handleLock.Unlock()
- operation := "hcsshim::ComputeSystem::Close"
- computeSystem.logOperationBegin(operation)
- defer func() { computeSystem.logOperationEnd(operation, err) }()
-
// Don't double free this
if computeSystem.handle == 0 {
return nil
}
- if err = computeSystem.unregisterCallback(); err != nil {
- return makeSystemError(computeSystem, "Close", "", err, nil)
+ if err = computeSystem.unregisterCallback(ctx); err != nil {
+ return makeSystemError(computeSystem, operation, "", err, nil)
}
- syscallWatcher(computeSystem.logctx, func() {
- err = hcsCloseComputeSystem(computeSystem.handle)
- })
+ err = vmcompute.HcsCloseComputeSystem(ctx, computeSystem.handle)
if err != nil {
- return makeSystemError(computeSystem, "Close", "", err, nil)
+ return makeSystemError(computeSystem, operation, "", err, nil)
}
computeSystem.handle = 0
+ computeSystem.closedWaitOnce.Do(func() {
+ computeSystem.waitError = ErrAlreadyClosed
+ close(computeSystem.waitBlock)
+ })
return nil
}
-func (computeSystem *System) registerCallback() error {
- context := &notifcationWatcherContext{
- channels: newChannels(),
+func (computeSystem *System) registerCallback(ctx context.Context) error {
+ callbackContext := &notifcationWatcherContext{
+ channels: newSystemChannels(),
+ systemID: computeSystem.id,
}
callbackMapLock.Lock()
callbackNumber := nextCallback
nextCallback++
- callbackMap[callbackNumber] = context
+ callbackMap[callbackNumber] = callbackContext
callbackMapLock.Unlock()
- var callbackHandle hcsCallback
- err := hcsRegisterComputeSystemCallback(computeSystem.handle, notificationWatcherCallback, callbackNumber, &callbackHandle)
+ callbackHandle, err := vmcompute.HcsRegisterComputeSystemCallback(ctx, computeSystem.handle, notificationWatcherCallback, callbackNumber)
if err != nil {
return err
}
- context.handle = callbackHandle
+ callbackContext.handle = callbackHandle
computeSystem.callbackNumber = callbackNumber
return nil
}
-func (computeSystem *System) unregisterCallback() error {
+func (computeSystem *System) unregisterCallback(ctx context.Context) error {
callbackNumber := computeSystem.callbackNumber
callbackMapLock.RLock()
- context := callbackMap[callbackNumber]
+ callbackContext := callbackMap[callbackNumber]
callbackMapLock.RUnlock()
- if context == nil {
+ if callbackContext == nil {
return nil
}
- handle := context.handle
+ handle := callbackContext.handle
if handle == 0 {
return nil
@@ -632,15 +644,15 @@ func (computeSystem *System) unregisterCallback() error {
// hcsUnregisterComputeSystemCallback has its own syncronization
// to wait for all callbacks to complete. We must NOT hold the callbackMapLock.
- err := hcsUnregisterComputeSystemCallback(handle)
+ err := vmcompute.HcsUnregisterComputeSystemCallback(ctx, handle)
if err != nil {
return err
}
- closeChannels(context.channels)
+ closeChannels(callbackContext.channels)
callbackMapLock.Lock()
- callbackMap[callbackNumber] = nil
+ delete(callbackMap, callbackNumber)
callbackMapLock.Unlock()
handle = 0
@@ -649,36 +661,26 @@ func (computeSystem *System) unregisterCallback() error {
}
// Modify the System by sending a request to HCS
-func (computeSystem *System) Modify(config interface{}) (err error) {
+func (computeSystem *System) Modify(ctx context.Context, config interface{}) error {
computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock()
- operation := "hcsshim::ComputeSystem::Modify"
- computeSystem.logOperationBegin(operation)
- defer func() { computeSystem.logOperationEnd(operation, err) }()
+ operation := "hcsshim::System::Modify"
if computeSystem.handle == 0 {
- return makeSystemError(computeSystem, "Modify", "", ErrAlreadyClosed, nil)
+ return makeSystemError(computeSystem, operation, "", ErrAlreadyClosed, nil)
}
- requestJSON, err := json.Marshal(config)
+ requestBytes, err := json.Marshal(config)
if err != nil {
return err
}
- requestString := string(requestJSON)
-
- logrus.WithFields(computeSystem.logctx).
- WithField(logfields.JSON, requestString).
- Debug("HCS ComputeSystem Modify Document")
-
- var resultp *uint16
- syscallWatcher(computeSystem.logctx, func() {
- err = hcsModifyComputeSystem(computeSystem.handle, requestString, &resultp)
- })
- events := processHcsResult(resultp)
+ requestJSON := string(requestBytes)
+ resultJSON, err := vmcompute.HcsModifyComputeSystem(ctx, computeSystem.handle, requestJSON)
+ events := processHcsResult(ctx, resultJSON)
if err != nil {
- return makeSystemError(computeSystem, "Modify", requestString, err, events)
+ return makeSystemError(computeSystem, operation, requestJSON, err, events)
}
return nil
diff --git a/vendor/github.com/Microsoft/hcsshim/internal/hcs/waithelper.go b/vendor/github.com/Microsoft/hcsshim/internal/hcs/waithelper.go
index 91e212c57..f07f532c1 100644
--- a/vendor/github.com/Microsoft/hcsshim/internal/hcs/waithelper.go
+++ b/vendor/github.com/Microsoft/hcsshim/internal/hcs/waithelper.go
@@ -1,28 +1,34 @@
package hcs
import (
+ "context"
"time"
- "github.com/sirupsen/logrus"
+ "github.com/Microsoft/hcsshim/internal/log"
)
-func processAsyncHcsResult(err error, resultp *uint16, callbackNumber uintptr, expectedNotification hcsNotification, timeout *time.Duration) ([]ErrorEvent, error) {
- events := processHcsResult(resultp)
+func processAsyncHcsResult(ctx context.Context, err error, resultJSON string, callbackNumber uintptr, expectedNotification hcsNotification, timeout *time.Duration) ([]ErrorEvent, error) {
+ events := processHcsResult(ctx, resultJSON)
if IsPending(err) {
- return nil, waitForNotification(callbackNumber, expectedNotification, timeout)
+ return nil, waitForNotification(ctx, callbackNumber, expectedNotification, timeout)
}
return events, err
}
-func waitForNotification(callbackNumber uintptr, expectedNotification hcsNotification, timeout *time.Duration) error {
+func waitForNotification(ctx context.Context, callbackNumber uintptr, expectedNotification hcsNotification, timeout *time.Duration) error {
callbackMapLock.RLock()
+ if _, ok := callbackMap[callbackNumber]; !ok {
+ callbackMapLock.RUnlock()
+ log.G(ctx).WithField("callbackNumber", callbackNumber).Error("failed to waitForNotification: callbackNumber does not exist in callbackMap")
+ return ErrHandleClose
+ }
channels := callbackMap[callbackNumber].channels
callbackMapLock.RUnlock()
expectedChannel := channels[expectedNotification]
if expectedChannel == nil {
- logrus.Errorf("unknown notification type in waitForNotification %x", expectedNotification)
+ log.G(ctx).WithField("type", expectedNotification).Error("unknown notification type in waitForNotification")
return ErrInvalidNotificationType
}
diff --git a/vendor/github.com/Microsoft/hcsshim/internal/hcs/watcher.go b/vendor/github.com/Microsoft/hcsshim/internal/hcs/watcher.go
deleted file mode 100644
index f85ed3187..000000000
--- a/vendor/github.com/Microsoft/hcsshim/internal/hcs/watcher.go
+++ /dev/null
@@ -1,41 +0,0 @@
-package hcs
-
-import (
- "context"
-
- "github.com/Microsoft/hcsshim/internal/logfields"
- "github.com/Microsoft/hcsshim/internal/timeout"
- "github.com/sirupsen/logrus"
-)
-
-// syscallWatcher is used as a very simple goroutine around calls into
-// the platform. In some cases, we have seen HCS APIs not returning due to
-// various bugs, and the goroutine making the syscall ends up not returning,
-// prior to its async callback. By spinning up a syscallWatcher, it allows
-// us to at least log a warning if a syscall doesn't complete in a reasonable
-// amount of time.
-//
-// Usage is:
-//
-// syscallWatcher(logContext, func() {
-// err = <syscall>(args...)
-// })
-//
-
-func syscallWatcher(logContext logrus.Fields, syscallLambda func()) {
- ctx, cancel := context.WithTimeout(context.Background(), timeout.SyscallWatcher)
- defer cancel()
- go watchFunc(ctx, logContext)
- syscallLambda()
-}
-
-func watchFunc(ctx context.Context, logContext logrus.Fields) {
- select {
- case <-ctx.Done():
- if ctx.Err() != context.Canceled {
- logrus.WithFields(logContext).
- WithField(logfields.Timeout, timeout.SyscallWatcher).
- Warning("Syscall did not complete within operation timeout. This may indicate a platform issue. If it appears to be making no forward progress, obtain the stacks and see if there is a syscall stuck in the platform API for a significant length of time.")
- }
- }
-}
diff --git a/vendor/github.com/Microsoft/hcsshim/internal/hcs/zsyscall_windows.go b/vendor/github.com/Microsoft/hcsshim/internal/hcs/zsyscall_windows.go
deleted file mode 100644
index fcd5cdc87..000000000
--- a/vendor/github.com/Microsoft/hcsshim/internal/hcs/zsyscall_windows.go
+++ /dev/null
@@ -1,533 +0,0 @@
-// Code generated mksyscall_windows.exe DO NOT EDIT
-
-package hcs
-
-import (
- "syscall"
- "unsafe"
-
- "golang.org/x/sys/windows"
-)
-
-var _ unsafe.Pointer
-
-// Do the interface allocations only once for common
-// Errno values.
-const (
- errnoERROR_IO_PENDING = 997
-)
-
-var (
- errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
-)
-
-// errnoErr returns common boxed Errno values, to prevent
-// allocations at runtime.
-func errnoErr(e syscall.Errno) error {
- switch e {
- case 0:
- return nil
- case errnoERROR_IO_PENDING:
- return errERROR_IO_PENDING
- }
- // TODO: add more here, after collecting data on the common
- // error values see on Windows. (perhaps when running
- // all.bat?)
- return e
-}
-
-var (
- modvmcompute = windows.NewLazySystemDLL("vmcompute.dll")
-
- procHcsEnumerateComputeSystems = modvmcompute.NewProc("HcsEnumerateComputeSystems")
- procHcsCreateComputeSystem = modvmcompute.NewProc("HcsCreateComputeSystem")
- procHcsOpenComputeSystem = modvmcompute.NewProc("HcsOpenComputeSystem")
- procHcsCloseComputeSystem = modvmcompute.NewProc("HcsCloseComputeSystem")
- procHcsStartComputeSystem = modvmcompute.NewProc("HcsStartComputeSystem")
- procHcsShutdownComputeSystem = modvmcompute.NewProc("HcsShutdownComputeSystem")
- procHcsTerminateComputeSystem = modvmcompute.NewProc("HcsTerminateComputeSystem")
- procHcsPauseComputeSystem = modvmcompute.NewProc("HcsPauseComputeSystem")
- procHcsResumeComputeSystem = modvmcompute.NewProc("HcsResumeComputeSystem")
- procHcsGetComputeSystemProperties = modvmcompute.NewProc("HcsGetComputeSystemProperties")
- procHcsModifyComputeSystem = modvmcompute.NewProc("HcsModifyComputeSystem")
- procHcsRegisterComputeSystemCallback = modvmcompute.NewProc("HcsRegisterComputeSystemCallback")
- procHcsUnregisterComputeSystemCallback = modvmcompute.NewProc("HcsUnregisterComputeSystemCallback")
- procHcsCreateProcess = modvmcompute.NewProc("HcsCreateProcess")
- procHcsOpenProcess = modvmcompute.NewProc("HcsOpenProcess")
- procHcsCloseProcess = modvmcompute.NewProc("HcsCloseProcess")
- procHcsTerminateProcess = modvmcompute.NewProc("HcsTerminateProcess")
-
- procHcsGetProcessInfo = modvmcompute.NewProc("HcsGetProcessInfo")
- procHcsGetProcessProperties = modvmcompute.NewProc("HcsGetProcessProperties")
- procHcsModifyProcess = modvmcompute.NewProc("HcsModifyProcess")
- procHcsGetServiceProperties = modvmcompute.NewProc("HcsGetServiceProperties")
- procHcsRegisterProcessCallback = modvmcompute.NewProc("HcsRegisterProcessCallback")
- procHcsUnregisterProcessCallback = modvmcompute.NewProc("HcsUnregisterProcessCallback")
-)
-
-func hcsEnumerateComputeSystems(query string, computeSystems **uint16, result **uint16) (hr error) {
- var _p0 *uint16
- _p0, hr = syscall.UTF16PtrFromString(query)
- if hr != nil {
- return
- }
- return _hcsEnumerateComputeSystems(_p0, computeSystems, result)
-}
-
-func _hcsEnumerateComputeSystems(query *uint16, computeSystems **uint16, result **uint16) (hr error) {
- if hr = procHcsEnumerateComputeSystems.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall(procHcsEnumerateComputeSystems.Addr(), 3, uintptr(unsafe.Pointer(query)), uintptr(unsafe.Pointer(computeSystems)), uintptr(unsafe.Pointer(result)))
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsCreateComputeSystem(id string, configuration string, identity syscall.Handle, computeSystem *hcsSystem, result **uint16) (hr error) {
- var _p0 *uint16
- _p0, hr = syscall.UTF16PtrFromString(id)
- if hr != nil {
- return
- }
- var _p1 *uint16
- _p1, hr = syscall.UTF16PtrFromString(configuration)
- if hr != nil {
- return
- }
- return _hcsCreateComputeSystem(_p0, _p1, identity, computeSystem, result)
-}
-
-func _hcsCreateComputeSystem(id *uint16, configuration *uint16, identity syscall.Handle, computeSystem *hcsSystem, result **uint16) (hr error) {
- if hr = procHcsCreateComputeSystem.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall6(procHcsCreateComputeSystem.Addr(), 5, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(configuration)), uintptr(identity), uintptr(unsafe.Pointer(computeSystem)), uintptr(unsafe.Pointer(result)), 0)
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsOpenComputeSystem(id string, computeSystem *hcsSystem, result **uint16) (hr error) {
- var _p0 *uint16
- _p0, hr = syscall.UTF16PtrFromString(id)
- if hr != nil {
- return
- }
- return _hcsOpenComputeSystem(_p0, computeSystem, result)
-}
-
-func _hcsOpenComputeSystem(id *uint16, computeSystem *hcsSystem, result **uint16) (hr error) {
- if hr = procHcsOpenComputeSystem.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall(procHcsOpenComputeSystem.Addr(), 3, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(computeSystem)), uintptr(unsafe.Pointer(result)))
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsCloseComputeSystem(computeSystem hcsSystem) (hr error) {
- if hr = procHcsCloseComputeSystem.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall(procHcsCloseComputeSystem.Addr(), 1, uintptr(computeSystem), 0, 0)
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsStartComputeSystem(computeSystem hcsSystem, options string, result **uint16) (hr error) {
- var _p0 *uint16
- _p0, hr = syscall.UTF16PtrFromString(options)
- if hr != nil {
- return
- }
- return _hcsStartComputeSystem(computeSystem, _p0, result)
-}
-
-func _hcsStartComputeSystem(computeSystem hcsSystem, options *uint16, result **uint16) (hr error) {
- if hr = procHcsStartComputeSystem.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall(procHcsStartComputeSystem.Addr(), 3, uintptr(computeSystem), uintptr(unsafe.Pointer(options)), uintptr(unsafe.Pointer(result)))
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsShutdownComputeSystem(computeSystem hcsSystem, options string, result **uint16) (hr error) {
- var _p0 *uint16
- _p0, hr = syscall.UTF16PtrFromString(options)
- if hr != nil {
- return
- }
- return _hcsShutdownComputeSystem(computeSystem, _p0, result)
-}
-
-func _hcsShutdownComputeSystem(computeSystem hcsSystem, options *uint16, result **uint16) (hr error) {
- if hr = procHcsShutdownComputeSystem.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall(procHcsShutdownComputeSystem.Addr(), 3, uintptr(computeSystem), uintptr(unsafe.Pointer(options)), uintptr(unsafe.Pointer(result)))
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsTerminateComputeSystem(computeSystem hcsSystem, options string, result **uint16) (hr error) {
- var _p0 *uint16
- _p0, hr = syscall.UTF16PtrFromString(options)
- if hr != nil {
- return
- }
- return _hcsTerminateComputeSystem(computeSystem, _p0, result)
-}
-
-func _hcsTerminateComputeSystem(computeSystem hcsSystem, options *uint16, result **uint16) (hr error) {
- if hr = procHcsTerminateComputeSystem.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall(procHcsTerminateComputeSystem.Addr(), 3, uintptr(computeSystem), uintptr(unsafe.Pointer(options)), uintptr(unsafe.Pointer(result)))
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsPauseComputeSystem(computeSystem hcsSystem, options string, result **uint16) (hr error) {
- var _p0 *uint16
- _p0, hr = syscall.UTF16PtrFromString(options)
- if hr != nil {
- return
- }
- return _hcsPauseComputeSystem(computeSystem, _p0, result)
-}
-
-func _hcsPauseComputeSystem(computeSystem hcsSystem, options *uint16, result **uint16) (hr error) {
- if hr = procHcsPauseComputeSystem.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall(procHcsPauseComputeSystem.Addr(), 3, uintptr(computeSystem), uintptr(unsafe.Pointer(options)), uintptr(unsafe.Pointer(result)))
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsResumeComputeSystem(computeSystem hcsSystem, options string, result **uint16) (hr error) {
- var _p0 *uint16
- _p0, hr = syscall.UTF16PtrFromString(options)
- if hr != nil {
- return
- }
- return _hcsResumeComputeSystem(computeSystem, _p0, result)
-}
-
-func _hcsResumeComputeSystem(computeSystem hcsSystem, options *uint16, result **uint16) (hr error) {
- if hr = procHcsResumeComputeSystem.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall(procHcsResumeComputeSystem.Addr(), 3, uintptr(computeSystem), uintptr(unsafe.Pointer(options)), uintptr(unsafe.Pointer(result)))
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsGetComputeSystemProperties(computeSystem hcsSystem, propertyQuery string, properties **uint16, result **uint16) (hr error) {
- var _p0 *uint16
- _p0, hr = syscall.UTF16PtrFromString(propertyQuery)
- if hr != nil {
- return
- }
- return _hcsGetComputeSystemProperties(computeSystem, _p0, properties, result)
-}
-
-func _hcsGetComputeSystemProperties(computeSystem hcsSystem, propertyQuery *uint16, properties **uint16, result **uint16) (hr error) {
- if hr = procHcsGetComputeSystemProperties.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall6(procHcsGetComputeSystemProperties.Addr(), 4, uintptr(computeSystem), uintptr(unsafe.Pointer(propertyQuery)), uintptr(unsafe.Pointer(properties)), uintptr(unsafe.Pointer(result)), 0, 0)
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsModifyComputeSystem(computeSystem hcsSystem, configuration string, result **uint16) (hr error) {
- var _p0 *uint16
- _p0, hr = syscall.UTF16PtrFromString(configuration)
- if hr != nil {
- return
- }
- return _hcsModifyComputeSystem(computeSystem, _p0, result)
-}
-
-func _hcsModifyComputeSystem(computeSystem hcsSystem, configuration *uint16, result **uint16) (hr error) {
- if hr = procHcsModifyComputeSystem.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall(procHcsModifyComputeSystem.Addr(), 3, uintptr(computeSystem), uintptr(unsafe.Pointer(configuration)), uintptr(unsafe.Pointer(result)))
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsRegisterComputeSystemCallback(computeSystem hcsSystem, callback uintptr, context uintptr, callbackHandle *hcsCallback) (hr error) {
- if hr = procHcsRegisterComputeSystemCallback.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall6(procHcsRegisterComputeSystemCallback.Addr(), 4, uintptr(computeSystem), uintptr(callback), uintptr(context), uintptr(unsafe.Pointer(callbackHandle)), 0, 0)
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsUnregisterComputeSystemCallback(callbackHandle hcsCallback) (hr error) {
- if hr = procHcsUnregisterComputeSystemCallback.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall(procHcsUnregisterComputeSystemCallback.Addr(), 1, uintptr(callbackHandle), 0, 0)
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsCreateProcess(computeSystem hcsSystem, processParameters string, processInformation *hcsProcessInformation, process *hcsProcess, result **uint16) (hr error) {
- var _p0 *uint16
- _p0, hr = syscall.UTF16PtrFromString(processParameters)
- if hr != nil {
- return
- }
- return _hcsCreateProcess(computeSystem, _p0, processInformation, process, result)
-}
-
-func _hcsCreateProcess(computeSystem hcsSystem, processParameters *uint16, processInformation *hcsProcessInformation, process *hcsProcess, result **uint16) (hr error) {
- if hr = procHcsCreateProcess.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall6(procHcsCreateProcess.Addr(), 5, uintptr(computeSystem), uintptr(unsafe.Pointer(processParameters)), uintptr(unsafe.Pointer(processInformation)), uintptr(unsafe.Pointer(process)), uintptr(unsafe.Pointer(result)), 0)
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsOpenProcess(computeSystem hcsSystem, pid uint32, process *hcsProcess, result **uint16) (hr error) {
- if hr = procHcsOpenProcess.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall6(procHcsOpenProcess.Addr(), 4, uintptr(computeSystem), uintptr(pid), uintptr(unsafe.Pointer(process)), uintptr(unsafe.Pointer(result)), 0, 0)
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsCloseProcess(process hcsProcess) (hr error) {
- if hr = procHcsCloseProcess.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall(procHcsCloseProcess.Addr(), 1, uintptr(process), 0, 0)
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsTerminateProcess(process hcsProcess, result **uint16) (hr error) {
- if hr = procHcsTerminateProcess.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall(procHcsTerminateProcess.Addr(), 2, uintptr(process), uintptr(unsafe.Pointer(result)), 0)
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsSignalProcess(process hcsProcess, options string, result **uint16) (hr error) {
- var _p0 *uint16
- _p0, hr = syscall.UTF16PtrFromString(options)
- if hr != nil {
- return
- }
- return _hcsSignalProcess(process, _p0, result)
-}
-
-func _hcsSignalProcess(process hcsProcess, options *uint16, result **uint16) (hr error) {
- if hr = procHcsTerminateProcess.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall(procHcsTerminateProcess.Addr(), 3, uintptr(process), uintptr(unsafe.Pointer(options)), uintptr(unsafe.Pointer(result)))
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsGetProcessInfo(process hcsProcess, processInformation *hcsProcessInformation, result **uint16) (hr error) {
- if hr = procHcsGetProcessInfo.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall(procHcsGetProcessInfo.Addr(), 3, uintptr(process), uintptr(unsafe.Pointer(processInformation)), uintptr(unsafe.Pointer(result)))
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsGetProcessProperties(process hcsProcess, processProperties **uint16, result **uint16) (hr error) {
- if hr = procHcsGetProcessProperties.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall(procHcsGetProcessProperties.Addr(), 3, uintptr(process), uintptr(unsafe.Pointer(processProperties)), uintptr(unsafe.Pointer(result)))
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsModifyProcess(process hcsProcess, settings string, result **uint16) (hr error) {
- var _p0 *uint16
- _p0, hr = syscall.UTF16PtrFromString(settings)
- if hr != nil {
- return
- }
- return _hcsModifyProcess(process, _p0, result)
-}
-
-func _hcsModifyProcess(process hcsProcess, settings *uint16, result **uint16) (hr error) {
- if hr = procHcsModifyProcess.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall(procHcsModifyProcess.Addr(), 3, uintptr(process), uintptr(unsafe.Pointer(settings)), uintptr(unsafe.Pointer(result)))
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsGetServiceProperties(propertyQuery string, properties **uint16, result **uint16) (hr error) {
- var _p0 *uint16
- _p0, hr = syscall.UTF16PtrFromString(propertyQuery)
- if hr != nil {
- return
- }
- return _hcsGetServiceProperties(_p0, properties, result)
-}
-
-func _hcsGetServiceProperties(propertyQuery *uint16, properties **uint16, result **uint16) (hr error) {
- if hr = procHcsGetServiceProperties.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall(procHcsGetServiceProperties.Addr(), 3, uintptr(unsafe.Pointer(propertyQuery)), uintptr(unsafe.Pointer(properties)), uintptr(unsafe.Pointer(result)))
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsRegisterProcessCallback(process hcsProcess, callback uintptr, context uintptr, callbackHandle *hcsCallback) (hr error) {
- if hr = procHcsRegisterProcessCallback.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall6(procHcsRegisterProcessCallback.Addr(), 4, uintptr(process), uintptr(callback), uintptr(context), uintptr(unsafe.Pointer(callbackHandle)), 0, 0)
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}
-
-func hcsUnregisterProcessCallback(callbackHandle hcsCallback) (hr error) {
- if hr = procHcsUnregisterProcessCallback.Find(); hr != nil {
- return
- }
- r0, _, _ := syscall.Syscall(procHcsUnregisterProcessCallback.Addr(), 1, uintptr(callbackHandle), 0, 0)
- if int32(r0) < 0 {
- if r0&0x1fff0000 == 0x00070000 {
- r0 &= 0xffff
- }
- hr = syscall.Errno(r0)
- }
- return
-}