mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #23444 from Microsoft/RevendorHcsshim
Update vendored hcsshim to v0.3.4
This commit is contained in:
commit
bf0e2cb1b6
6 changed files with 175 additions and 165 deletions
|
@ -43,7 +43,7 @@ esac
|
||||||
|
|
||||||
# the following lines are in sorted order, FYI
|
# the following lines are in sorted order, FYI
|
||||||
clone git github.com/Azure/go-ansiterm 388960b655244e76e24c75f48631564eaefade62
|
clone git github.com/Azure/go-ansiterm 388960b655244e76e24c75f48631564eaefade62
|
||||||
clone git github.com/Microsoft/hcsshim v0.3.2
|
clone git github.com/Microsoft/hcsshim v0.3.4
|
||||||
clone git github.com/Microsoft/go-winio v0.3.4
|
clone git github.com/Microsoft/go-winio v0.3.4
|
||||||
clone git github.com/Sirupsen/logrus v0.10.0 # logrus is a common dependency among multiple deps
|
clone git github.com/Sirupsen/logrus v0.10.0 # logrus is a common dependency among multiple deps
|
||||||
clone git github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a
|
clone git github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package hcsshim
|
package hcsshim
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
@ -26,14 +25,6 @@ var (
|
||||||
// Common notifications
|
// Common notifications
|
||||||
hcsNotificationInvalid hcsNotification = 0x00000000
|
hcsNotificationInvalid hcsNotification = 0x00000000
|
||||||
hcsNotificationServiceDisconnect hcsNotification = 0x01000000
|
hcsNotificationServiceDisconnect hcsNotification = 0x01000000
|
||||||
|
|
||||||
// ErrUnexpectedContainerExit is the error returned when a container exits while waiting for
|
|
||||||
// a different expected notification
|
|
||||||
ErrUnexpectedContainerExit = errors.New("unexpected container exit")
|
|
||||||
|
|
||||||
// ErrUnexpectedProcessAbort is the error returned when communication with the compute service
|
|
||||||
// is lost while waiting for a notification
|
|
||||||
ErrUnexpectedProcessAbort = errors.New("lost communication with compute service")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type hcsNotification uint32
|
type hcsNotification uint32
|
||||||
|
@ -58,6 +49,15 @@ func newChannels() notificationChannels {
|
||||||
channels[hcsNotificationServiceDisconnect] = make(notificationChannel, 1)
|
channels[hcsNotificationServiceDisconnect] = make(notificationChannel, 1)
|
||||||
return channels
|
return channels
|
||||||
}
|
}
|
||||||
|
func closeChannels(channels notificationChannels) {
|
||||||
|
close(channels[hcsNotificationSystemExited])
|
||||||
|
close(channels[hcsNotificationSystemCreateCompleted])
|
||||||
|
close(channels[hcsNotificationSystemStartCompleted])
|
||||||
|
close(channels[hcsNotificationSystemPauseCompleted])
|
||||||
|
close(channels[hcsNotificationSystemResumeCompleted])
|
||||||
|
close(channels[hcsNotificationProcessExited])
|
||||||
|
close(channels[hcsNotificationServiceDisconnect])
|
||||||
|
}
|
||||||
|
|
||||||
func notificationWatcher(notificationType hcsNotification, callbackNumber uintptr, notificationStatus uintptr, notificationData *uint16) uintptr {
|
func notificationWatcher(notificationType hcsNotification, callbackNumber uintptr, notificationStatus uintptr, notificationData *uint16) uintptr {
|
||||||
var result error
|
var result error
|
||||||
|
@ -66,10 +66,14 @@ func notificationWatcher(notificationType hcsNotification, callbackNumber uintpt
|
||||||
}
|
}
|
||||||
|
|
||||||
callbackMapLock.RLock()
|
callbackMapLock.RLock()
|
||||||
channels := callbackMap[callbackNumber].channels
|
context := callbackMap[callbackNumber]
|
||||||
callbackMapLock.RUnlock()
|
callbackMapLock.RUnlock()
|
||||||
|
|
||||||
channels[notificationType] <- result
|
if context == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
context.channels[notificationType] <- result
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
151
vendor/src/github.com/Microsoft/hcsshim/container.go
vendored
151
vendor/src/github.com/Microsoft/hcsshim/container.go
vendored
|
@ -13,11 +13,11 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
defaultTimeout = time.Minute * 4
|
defaultTimeout = time.Minute * 4
|
||||||
|
|
||||||
// ErrTimeout is an error encountered when waiting on a notification times out
|
|
||||||
ErrTimeout = errors.New("hcsshim: timeout waiting for notification")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const pendingUpdatesQuery = `{ "PropertyTypes" : ["PendingUpdates"]}`
|
||||||
|
|
||||||
|
// ContainerError is an error encountered in HCS
|
||||||
type ContainerError struct {
|
type ContainerError struct {
|
||||||
Container *container
|
Container *container
|
||||||
Operation string
|
Operation string
|
||||||
|
@ -71,9 +71,7 @@ func CreateContainer(id string, c *ContainerConfig) (Container, error) {
|
||||||
|
|
||||||
if createError == nil || createError == ErrVmcomputeOperationPending {
|
if createError == nil || createError == ErrVmcomputeOperationPending {
|
||||||
if err := container.registerCallback(); err != nil {
|
if err := container.registerCallback(); err != nil {
|
||||||
err := &ContainerError{Container: container, Operation: operation, Err: err}
|
return nil, makeContainerError(container, operation, "", err)
|
||||||
logrus.Error(err)
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -82,12 +80,7 @@ func CreateContainer(id string, c *ContainerConfig) (Container, error) {
|
||||||
|
|
||||||
err = processAsyncHcsResult(createError, resultp, container.callbackNumber, hcsNotificationSystemCreateCompleted, &defaultTimeout)
|
err = processAsyncHcsResult(createError, resultp, container.callbackNumber, hcsNotificationSystemCreateCompleted, &defaultTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == ErrTimeout || err == ErrUnexpectedProcessAbort || err == ErrUnexpectedContainerExit {
|
return nil, makeContainerError(container, operation, configuration, err)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
err := &ContainerError{Container: container, Operation: operation, ExtraInfo: configuration, Err: err}
|
|
||||||
logrus.Error(err)
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debugf(title+" succeeded id=%s handle=%d", id, container.handle)
|
logrus.Debugf(title+" succeeded id=%s handle=%d", id, container.handle)
|
||||||
|
@ -112,9 +105,7 @@ func OpenContainer(id string) (Container, error) {
|
||||||
err := hcsOpenComputeSystem(id, &handle, &resultp)
|
err := hcsOpenComputeSystem(id, &handle, &resultp)
|
||||||
err = processHcsResult(err, resultp)
|
err = processHcsResult(err, resultp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = &ContainerError{Container: container, Operation: operation, Err: err}
|
return nil, makeContainerError(container, operation, "", err)
|
||||||
logrus.Error(err)
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
container.handle = handle
|
container.handle = handle
|
||||||
|
@ -134,12 +125,7 @@ func (container *container) Start() error {
|
||||||
err := hcsStartComputeSystemTP5(container.handle, nil, &resultp)
|
err := hcsStartComputeSystemTP5(container.handle, nil, &resultp)
|
||||||
err = processAsyncHcsResult(err, resultp, container.callbackNumber, hcsNotificationSystemStartCompleted, &defaultTimeout)
|
err = processAsyncHcsResult(err, resultp, container.callbackNumber, hcsNotificationSystemStartCompleted, &defaultTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == ErrTimeout || err == ErrUnexpectedProcessAbort || err == ErrUnexpectedContainerExit {
|
return makeContainerError(container, operation, "", err)
|
||||||
return err
|
|
||||||
}
|
|
||||||
err := &ContainerError{Container: container, Operation: operation, Err: err}
|
|
||||||
logrus.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debugf(title+" succeeded id=%s", container.id)
|
logrus.Debugf(title+" succeeded id=%s", container.id)
|
||||||
|
@ -160,9 +146,7 @@ func (container *container) Shutdown() error {
|
||||||
if err == ErrVmcomputeOperationPending {
|
if err == ErrVmcomputeOperationPending {
|
||||||
return ErrVmcomputeOperationPending
|
return ErrVmcomputeOperationPending
|
||||||
}
|
}
|
||||||
err = &ContainerError{Container: container, Operation: operation, Err: err}
|
return makeContainerError(container, operation, "", err)
|
||||||
logrus.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debugf(title+" succeeded id=%s", container.id)
|
logrus.Debugf(title+" succeeded id=%s", container.id)
|
||||||
|
@ -183,9 +167,7 @@ func (container *container) Terminate() error {
|
||||||
if err == ErrVmcomputeOperationPending {
|
if err == ErrVmcomputeOperationPending {
|
||||||
return ErrVmcomputeOperationPending
|
return ErrVmcomputeOperationPending
|
||||||
}
|
}
|
||||||
err = &ContainerError{Container: container, Operation: operation, Err: err}
|
return makeContainerError(container, operation, "", err)
|
||||||
logrus.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debugf(title+" succeeded id=%s", container.id)
|
logrus.Debugf(title+" succeeded id=%s", container.id)
|
||||||
|
@ -201,19 +183,12 @@ func (container *container) Wait() error {
|
||||||
if hcsCallbacksSupported {
|
if hcsCallbacksSupported {
|
||||||
err := waitForNotification(container.callbackNumber, hcsNotificationSystemExited, nil)
|
err := waitForNotification(container.callbackNumber, hcsNotificationSystemExited, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == ErrUnexpectedProcessAbort || err == ErrUnexpectedContainerExit {
|
return makeContainerError(container, operation, "", err)
|
||||||
return err
|
|
||||||
}
|
|
||||||
err := &ContainerError{Container: container, Operation: operation, Err: err}
|
|
||||||
logrus.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_, err := container.waitTimeoutInternal(syscall.INFINITE)
|
_, err := container.waitTimeoutInternal(syscall.INFINITE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := &ContainerError{Container: container, Operation: operation, Err: err}
|
return makeContainerError(container, operation, "", err)
|
||||||
logrus.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,21 +210,14 @@ func (container *container) WaitTimeout(timeout time.Duration) error {
|
||||||
if hcsCallbacksSupported {
|
if hcsCallbacksSupported {
|
||||||
err := waitForNotification(container.callbackNumber, hcsNotificationSystemExited, &timeout)
|
err := waitForNotification(container.callbackNumber, hcsNotificationSystemExited, &timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == ErrTimeout || err == ErrUnexpectedProcessAbort || err == ErrUnexpectedContainerExit {
|
return makeContainerError(container, operation, "", err)
|
||||||
return err
|
|
||||||
}
|
|
||||||
err := &ContainerError{Container: container, Operation: operation, Err: err}
|
|
||||||
logrus.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
finished, err := waitTimeoutHelper(container, timeout)
|
finished, err := waitTimeoutHelper(container, timeout)
|
||||||
if !finished {
|
if !finished {
|
||||||
return ErrTimeout
|
return ErrTimeout
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
err := &ContainerError{Container: container, Operation: operation, Err: err}
|
return makeContainerError(container, operation, "", err)
|
||||||
logrus.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,12 +241,12 @@ func (container *container) hcsWait(timeout uint32) (bool, error) {
|
||||||
return waitForSingleObject(exitEvent, timeout)
|
return waitForSingleObject(exitEvent, timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *container) properties() (*containerProperties, error) {
|
func (container *container) properties(query string) (*containerProperties, error) {
|
||||||
var (
|
var (
|
||||||
resultp *uint16
|
resultp *uint16
|
||||||
propertiesp *uint16
|
propertiesp *uint16
|
||||||
)
|
)
|
||||||
err := hcsGetComputeSystemProperties(container.handle, "", &propertiesp, &resultp)
|
err := hcsGetComputeSystemProperties(container.handle, query, &propertiesp, &resultp)
|
||||||
err = processHcsResult(err, resultp)
|
err = processHcsResult(err, resultp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -302,11 +270,9 @@ func (container *container) HasPendingUpdates() (bool, error) {
|
||||||
operation := "HasPendingUpdates"
|
operation := "HasPendingUpdates"
|
||||||
title := "HCSShim::Container::" + operation
|
title := "HCSShim::Container::" + operation
|
||||||
logrus.Debugf(title+" id=%s", container.id)
|
logrus.Debugf(title+" id=%s", container.id)
|
||||||
properties, err := container.properties()
|
properties, err := container.properties(pendingUpdatesQuery)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := &ContainerError{Container: container, Operation: operation, Err: err}
|
return false, makeContainerError(container, operation, "", err)
|
||||||
logrus.Error(err)
|
|
||||||
return false, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debugf(title+" succeeded id=%s", container.id)
|
logrus.Debugf(title+" succeeded id=%s", container.id)
|
||||||
|
@ -323,12 +289,7 @@ func (container *container) Pause() error {
|
||||||
err := hcsPauseComputeSystemTP5(container.handle, nil, &resultp)
|
err := hcsPauseComputeSystemTP5(container.handle, nil, &resultp)
|
||||||
err = processAsyncHcsResult(err, resultp, container.callbackNumber, hcsNotificationSystemPauseCompleted, &defaultTimeout)
|
err = processAsyncHcsResult(err, resultp, container.callbackNumber, hcsNotificationSystemPauseCompleted, &defaultTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == ErrTimeout || err == ErrUnexpectedProcessAbort || err == ErrUnexpectedContainerExit {
|
return makeContainerError(container, operation, "", err)
|
||||||
return err
|
|
||||||
}
|
|
||||||
err := &ContainerError{Container: container, Operation: operation, Err: err}
|
|
||||||
logrus.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debugf(title+" succeeded id=%s", container.id)
|
logrus.Debugf(title+" succeeded id=%s", container.id)
|
||||||
|
@ -347,12 +308,7 @@ func (container *container) Resume() error {
|
||||||
err := hcsResumeComputeSystemTP5(container.handle, nil, &resultp)
|
err := hcsResumeComputeSystemTP5(container.handle, nil, &resultp)
|
||||||
err = processAsyncHcsResult(err, resultp, container.callbackNumber, hcsNotificationSystemResumeCompleted, &defaultTimeout)
|
err = processAsyncHcsResult(err, resultp, container.callbackNumber, hcsNotificationSystemResumeCompleted, &defaultTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == ErrTimeout || err == ErrUnexpectedProcessAbort || err == ErrUnexpectedContainerExit {
|
return makeContainerError(container, operation, "", err)
|
||||||
return err
|
|
||||||
}
|
|
||||||
err := &ContainerError{Container: container, Operation: operation, Err: err}
|
|
||||||
logrus.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debugf(title+" succeeded id=%s", container.id)
|
logrus.Debugf(title+" succeeded id=%s", container.id)
|
||||||
|
@ -386,9 +342,7 @@ func (container *container) CreateProcess(c *ProcessConfig) (Process, error) {
|
||||||
err = hcsCreateProcess(container.handle, configuration, &processInfo, &processHandle, &resultp)
|
err = hcsCreateProcess(container.handle, configuration, &processInfo, &processHandle, &resultp)
|
||||||
err = processHcsResult(err, resultp)
|
err = processHcsResult(err, resultp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = &ContainerError{Container: container, Operation: operation, ExtraInfo: configuration, Err: err}
|
return nil, makeContainerError(container, operation, configuration, err)
|
||||||
logrus.Error(err)
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
process := &process{
|
process := &process{
|
||||||
|
@ -404,9 +358,7 @@ func (container *container) CreateProcess(c *ProcessConfig) (Process, error) {
|
||||||
|
|
||||||
if hcsCallbacksSupported {
|
if hcsCallbacksSupported {
|
||||||
if err := process.registerCallback(); err != nil {
|
if err := process.registerCallback(); err != nil {
|
||||||
err = &ContainerError{Container: container, Operation: operation, Err: err}
|
return nil, makeContainerError(container, operation, "", err)
|
||||||
logrus.Error(err)
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,9 +380,7 @@ func (container *container) OpenProcess(pid int) (Process, error) {
|
||||||
err := hcsOpenProcess(container.handle, uint32(pid), &processHandle, &resultp)
|
err := hcsOpenProcess(container.handle, uint32(pid), &processHandle, &resultp)
|
||||||
err = processHcsResult(err, resultp)
|
err = processHcsResult(err, resultp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = &ContainerError{Container: container, Operation: operation, Err: err}
|
return nil, makeContainerError(container, operation, "", err)
|
||||||
logrus.Error(err)
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
process := &process{
|
process := &process{
|
||||||
|
@ -440,9 +390,7 @@ func (container *container) OpenProcess(pid int) (Process, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := process.registerCallback(); err != nil {
|
if err := process.registerCallback(); err != nil {
|
||||||
err = &ContainerError{Container: container, Operation: operation, Err: err}
|
return nil, makeContainerError(container, operation, "", err)
|
||||||
logrus.Error(err)
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debugf(title+" succeeded id=%s processid=%s", container.id, process.processID)
|
logrus.Debugf(title+" succeeded id=%s processid=%s", container.id, process.processID)
|
||||||
|
@ -463,16 +411,12 @@ func (container *container) Close() error {
|
||||||
|
|
||||||
if hcsCallbacksSupported {
|
if hcsCallbacksSupported {
|
||||||
if err := container.unregisterCallback(); err != nil {
|
if err := container.unregisterCallback(); err != nil {
|
||||||
err = &ContainerError{Container: container, Operation: operation, Err: err}
|
return makeContainerError(container, operation, "", err)
|
||||||
logrus.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := hcsCloseComputeSystem(container.handle); err != nil {
|
if err := hcsCloseComputeSystem(container.handle); err != nil {
|
||||||
err = &ContainerError{Container: container, Operation: operation, Err: err}
|
return makeContainerError(container, operation, "", err)
|
||||||
logrus.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
container.handle = 0
|
container.handle = 0
|
||||||
|
@ -487,16 +431,15 @@ func closeContainer(container *container) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *container) registerCallback() error {
|
func (container *container) registerCallback() error {
|
||||||
callbackMapLock.Lock()
|
|
||||||
defer callbackMapLock.Unlock()
|
|
||||||
|
|
||||||
callbackNumber := nextCallback
|
|
||||||
nextCallback++
|
|
||||||
|
|
||||||
context := ¬ifcationWatcherContext{
|
context := ¬ifcationWatcherContext{
|
||||||
channels: newChannels(),
|
channels: newChannels(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
callbackMapLock.Lock()
|
||||||
|
callbackNumber := nextCallback
|
||||||
|
nextCallback++
|
||||||
callbackMap[callbackNumber] = context
|
callbackMap[callbackNumber] = context
|
||||||
|
callbackMapLock.Unlock()
|
||||||
|
|
||||||
var callbackHandle hcsCallback
|
var callbackHandle hcsCallback
|
||||||
err := hcsRegisterComputeSystemCallback(container.handle, notificationWatcherCallback, callbackNumber, &callbackHandle)
|
err := hcsRegisterComputeSystemCallback(container.handle, notificationWatcherCallback, callbackNumber, &callbackHandle)
|
||||||
|
@ -512,21 +455,32 @@ func (container *container) registerCallback() error {
|
||||||
func (container *container) unregisterCallback() error {
|
func (container *container) unregisterCallback() error {
|
||||||
callbackNumber := container.callbackNumber
|
callbackNumber := container.callbackNumber
|
||||||
|
|
||||||
callbackMapLock.Lock()
|
callbackMapLock.RLock()
|
||||||
defer callbackMapLock.Unlock()
|
context := callbackMap[callbackNumber]
|
||||||
|
callbackMapLock.RUnlock()
|
||||||
|
|
||||||
handle := callbackMap[callbackNumber].handle
|
if context == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
handle := context.handle
|
||||||
|
|
||||||
if handle == 0 {
|
if handle == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// hcsUnregisterComputeSystemCallback has its own syncronization
|
||||||
|
// to wait for all callbacks to complete. We must NOT hold the callbackMapLock.
|
||||||
err := hcsUnregisterComputeSystemCallback(handle)
|
err := hcsUnregisterComputeSystemCallback(handle)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeChannels(context.channels)
|
||||||
|
|
||||||
|
callbackMapLock.Lock()
|
||||||
callbackMap[callbackNumber] = nil
|
callbackMap[callbackNumber] = nil
|
||||||
|
callbackMapLock.Unlock()
|
||||||
|
|
||||||
handle = 0
|
handle = 0
|
||||||
|
|
||||||
|
@ -558,3 +512,20 @@ func (e *ContainerError) Error() string {
|
||||||
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func makeContainerError(container *container, operation string, extraInfo string, err error) error {
|
||||||
|
// Don't wrap errors created in hcsshim
|
||||||
|
if err == ErrTimeout ||
|
||||||
|
err == ErrUnexpectedProcessAbort ||
|
||||||
|
err == ErrUnexpectedContainerExit ||
|
||||||
|
err == ErrHandleClose ||
|
||||||
|
err == ErrInvalidProcessState ||
|
||||||
|
err == ErrInvalidNotificationType ||
|
||||||
|
err == ErrVmcomputeOperationPending {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
containerError := &ContainerError{Container: container, Operation: operation, ExtraInfo: extraInfo, Err: err}
|
||||||
|
logrus.Error(containerError)
|
||||||
|
return containerError
|
||||||
|
}
|
||||||
|
|
|
@ -1,10 +1,33 @@
|
||||||
package hcsshim
|
package hcsshim
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// ErrInvalidNotificationType is an error encountered when an invalid notification type is used
|
||||||
|
ErrInvalidNotificationType = errors.New("hcsshim: invalid notification type")
|
||||||
|
|
||||||
|
// ErrTimeout is an error encountered when waiting on a notification times out
|
||||||
|
ErrTimeout = errors.New("hcsshim: timeout waiting for notification")
|
||||||
|
|
||||||
|
// ErrHandleClose is an error returned when the handle generating the notification being waited on has been closed
|
||||||
|
ErrHandleClose = errors.New("hcsshim: the handle generating this notification has been closed")
|
||||||
|
|
||||||
|
// ErrInvalidProcessState is an error encountered when the process is not in a valid state for the requested operation
|
||||||
|
ErrInvalidProcessState = errors.New("the process is in an invalid state for the attempted operation")
|
||||||
|
|
||||||
|
// ErrUnexpectedContainerExit is the error returned when a container exits while waiting for
|
||||||
|
// a different expected notification
|
||||||
|
ErrUnexpectedContainerExit = errors.New("unexpected container exit")
|
||||||
|
|
||||||
|
// ErrUnexpectedProcessAbort is the error returned when communication with the compute service
|
||||||
|
// is lost while waiting for a notification
|
||||||
|
ErrUnexpectedProcessAbort = errors.New("lost communication with compute service")
|
||||||
|
)
|
||||||
|
|
||||||
// ProcessConfig is used as both the input of Container.CreateProcess
|
// ProcessConfig is used as both the input of Container.CreateProcess
|
||||||
// and to convert the parameters to JSON for passing onto the HCS
|
// and to convert the parameters to JSON for passing onto the HCS
|
||||||
type ProcessConfig struct {
|
type ProcessConfig struct {
|
||||||
|
|
105
vendor/src/github.com/Microsoft/hcsshim/process.go
vendored
105
vendor/src/github.com/Microsoft/hcsshim/process.go
vendored
|
@ -11,13 +11,10 @@ import (
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
ErrInvalidProcessState = errors.New("the process is in an invalid state for the attempted operation")
|
|
||||||
)
|
|
||||||
|
|
||||||
type ProcessError struct {
|
type ProcessError struct {
|
||||||
Process *process
|
Process *process
|
||||||
Operation string
|
Operation string
|
||||||
|
ExtraInfo string
|
||||||
Err error
|
Err error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,9 +82,7 @@ func (process *process) Kill() error {
|
||||||
if err == ErrVmcomputeOperationPending {
|
if err == ErrVmcomputeOperationPending {
|
||||||
return ErrVmcomputeOperationPending
|
return ErrVmcomputeOperationPending
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
err := &ProcessError{Operation: operation, Process: process, Err: err}
|
return makeProcessError(process, operation, "", err)
|
||||||
logrus.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debugf(title+" succeeded processid=%d", process.processID)
|
logrus.Debugf(title+" succeeded processid=%d", process.processID)
|
||||||
|
@ -103,19 +98,12 @@ func (process *process) Wait() error {
|
||||||
if hcsCallbacksSupported {
|
if hcsCallbacksSupported {
|
||||||
err := waitForNotification(process.callbackNumber, hcsNotificationProcessExited, nil)
|
err := waitForNotification(process.callbackNumber, hcsNotificationProcessExited, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == ErrUnexpectedProcessAbort || err == ErrUnexpectedContainerExit {
|
return makeProcessError(process, operation, "", err)
|
||||||
return err
|
|
||||||
}
|
|
||||||
err := &ProcessError{Operation: operation, Process: process, Err: err}
|
|
||||||
logrus.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_, err := process.waitTimeoutInternal(syscall.INFINITE)
|
_, err := process.waitTimeoutInternal(syscall.INFINITE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := &ProcessError{Operation: operation, Process: process, Err: err}
|
return makeProcessError(process, operation, "", err)
|
||||||
logrus.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,21 +121,14 @@ func (process *process) WaitTimeout(timeout time.Duration) error {
|
||||||
if hcsCallbacksSupported {
|
if hcsCallbacksSupported {
|
||||||
err := waitForNotification(process.callbackNumber, hcsNotificationProcessExited, &timeout)
|
err := waitForNotification(process.callbackNumber, hcsNotificationProcessExited, &timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == ErrTimeout || err == ErrUnexpectedProcessAbort || err == ErrUnexpectedContainerExit {
|
return makeProcessError(process, operation, "", err)
|
||||||
return err
|
|
||||||
}
|
|
||||||
err := &ProcessError{Operation: operation, Process: process, Err: err}
|
|
||||||
logrus.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
finished, err := waitTimeoutHelper(process, timeout)
|
finished, err := waitTimeoutHelper(process, timeout)
|
||||||
if !finished {
|
if !finished {
|
||||||
return ErrTimeout
|
return ErrTimeout
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
err := &ProcessError{Operation: operation, Process: process, Err: err}
|
return makeProcessError(process, operation, "", err)
|
||||||
logrus.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,9 +164,7 @@ func (process *process) ExitCode() (int, error) {
|
||||||
|
|
||||||
properties, err := process.properties()
|
properties, err := process.properties()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := &ProcessError{Operation: operation, Process: process, Err: err}
|
return 0, makeProcessError(process, operation, "", err)
|
||||||
logrus.Error(err)
|
|
||||||
return 0, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if properties.Exited == false {
|
if properties.Exited == false {
|
||||||
|
@ -221,9 +200,7 @@ func (process *process) ResizeConsole(width, height uint16) error {
|
||||||
err = hcsModifyProcess(process.handle, modifyRequestStr, &resultp)
|
err = hcsModifyProcess(process.handle, modifyRequestStr, &resultp)
|
||||||
err = processHcsResult(err, resultp)
|
err = processHcsResult(err, resultp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := &ProcessError{Operation: operation, Process: process, Err: err}
|
return makeProcessError(process, operation, "", err)
|
||||||
logrus.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debugf(title+" succeeded processid=%d", process.processID)
|
logrus.Debugf(title+" succeeded processid=%d", process.processID)
|
||||||
|
@ -242,9 +219,7 @@ func (process *process) properties() (*processStatus, error) {
|
||||||
err := hcsGetProcessProperties(process.handle, &propertiesp, &resultp)
|
err := hcsGetProcessProperties(process.handle, &propertiesp, &resultp)
|
||||||
err = processHcsResult(err, resultp)
|
err = processHcsResult(err, resultp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := &ProcessError{Operation: operation, Process: process, Err: err}
|
return nil, makeProcessError(process, operation, "", err)
|
||||||
logrus.Error(err)
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if propertiesp == nil {
|
if propertiesp == nil {
|
||||||
|
@ -279,9 +254,7 @@ func (process *process) Stdio() (io.WriteCloser, io.ReadCloser, io.ReadCloser, e
|
||||||
err := hcsGetProcessInfo(process.handle, &processInfo, &resultp)
|
err := hcsGetProcessInfo(process.handle, &processInfo, &resultp)
|
||||||
err = processHcsResult(err, resultp)
|
err = processHcsResult(err, resultp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = &ProcessError{Operation: operation, Process: process, Err: err}
|
return nil, nil, nil, makeProcessError(process, operation, "", err)
|
||||||
logrus.Error(err)
|
|
||||||
return nil, nil, nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stdIn, stdOut, stdErr = processInfo.StdInput, processInfo.StdOutput, processInfo.StdError
|
stdIn, stdOut, stdErr = processInfo.StdInput, processInfo.StdOutput, processInfo.StdError
|
||||||
|
@ -327,9 +300,7 @@ func (process *process) CloseStdin() error {
|
||||||
err = hcsModifyProcess(process.handle, modifyRequestStr, &resultp)
|
err = hcsModifyProcess(process.handle, modifyRequestStr, &resultp)
|
||||||
err = processHcsResult(err, resultp)
|
err = processHcsResult(err, resultp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = &ProcessError{Operation: operation, Process: process, Err: err}
|
return makeProcessError(process, operation, "", err)
|
||||||
logrus.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debugf(title+" succeeded processid=%d", process.processID)
|
logrus.Debugf(title+" succeeded processid=%d", process.processID)
|
||||||
|
@ -350,16 +321,12 @@ func (process *process) Close() error {
|
||||||
|
|
||||||
if hcsCallbacksSupported {
|
if hcsCallbacksSupported {
|
||||||
if err := process.unregisterCallback(); err != nil {
|
if err := process.unregisterCallback(); err != nil {
|
||||||
err = &ProcessError{Operation: operation, Process: process, Err: err}
|
return makeProcessError(process, operation, "", err)
|
||||||
logrus.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := hcsCloseProcess(process.handle); err != nil {
|
if err := hcsCloseProcess(process.handle); err != nil {
|
||||||
err = &ProcessError{Operation: operation, Process: process, Err: err}
|
return makeProcessError(process, operation, "", err)
|
||||||
logrus.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
process.handle = 0
|
process.handle = 0
|
||||||
|
@ -374,16 +341,15 @@ func closeProcess(process *process) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (process *process) registerCallback() error {
|
func (process *process) registerCallback() error {
|
||||||
callbackMapLock.Lock()
|
|
||||||
defer callbackMapLock.Unlock()
|
|
||||||
|
|
||||||
callbackNumber := nextCallback
|
|
||||||
nextCallback++
|
|
||||||
|
|
||||||
context := ¬ifcationWatcherContext{
|
context := ¬ifcationWatcherContext{
|
||||||
channels: newChannels(),
|
channels: newChannels(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
callbackMapLock.Lock()
|
||||||
|
callbackNumber := nextCallback
|
||||||
|
nextCallback++
|
||||||
callbackMap[callbackNumber] = context
|
callbackMap[callbackNumber] = context
|
||||||
|
callbackMapLock.Unlock()
|
||||||
|
|
||||||
var callbackHandle hcsCallback
|
var callbackHandle hcsCallback
|
||||||
err := hcsRegisterProcessCallback(process.handle, notificationWatcherCallback, callbackNumber, &callbackHandle)
|
err := hcsRegisterProcessCallback(process.handle, notificationWatcherCallback, callbackNumber, &callbackHandle)
|
||||||
|
@ -399,20 +365,32 @@ func (process *process) registerCallback() error {
|
||||||
func (process *process) unregisterCallback() error {
|
func (process *process) unregisterCallback() error {
|
||||||
callbackNumber := process.callbackNumber
|
callbackNumber := process.callbackNumber
|
||||||
|
|
||||||
callbackMapLock.Lock()
|
callbackMapLock.RLock()
|
||||||
defer callbackMapLock.Unlock()
|
context := callbackMap[callbackNumber]
|
||||||
handle := callbackMap[callbackNumber].handle
|
callbackMapLock.RUnlock()
|
||||||
|
|
||||||
|
if context == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
handle := context.handle
|
||||||
|
|
||||||
if handle == 0 {
|
if handle == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// hcsUnregisterProcessCallback has its own syncronization
|
||||||
|
// to wait for all callbacks to complete. We must NOT hold the callbackMapLock.
|
||||||
err := hcsUnregisterProcessCallback(handle)
|
err := hcsUnregisterProcessCallback(handle)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeChannels(context.channels)
|
||||||
|
|
||||||
|
callbackMapLock.Lock()
|
||||||
callbackMap[callbackNumber] = nil
|
callbackMap[callbackNumber] = nil
|
||||||
|
callbackMapLock.Unlock()
|
||||||
|
|
||||||
handle = 0
|
handle = 0
|
||||||
|
|
||||||
|
@ -444,3 +422,20 @@ func (e *ProcessError) Error() string {
|
||||||
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func makeProcessError(process *process, operation string, extraInfo string, err error) error {
|
||||||
|
// Don't wrap errors created in hcsshim
|
||||||
|
if err == ErrTimeout ||
|
||||||
|
err == ErrUnexpectedProcessAbort ||
|
||||||
|
err == ErrUnexpectedContainerExit ||
|
||||||
|
err == ErrHandleClose ||
|
||||||
|
err == ErrInvalidProcessState ||
|
||||||
|
err == ErrInvalidNotificationType ||
|
||||||
|
err == ErrVmcomputeOperationPending {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
processError := &ProcessError{Process: process, Operation: operation, ExtraInfo: extraInfo, Err: err}
|
||||||
|
logrus.Error(processError)
|
||||||
|
return processError
|
||||||
|
}
|
||||||
|
|
|
@ -65,6 +65,7 @@ func waitForNotification(callbackNumber uintptr, expectedNotification hcsNotific
|
||||||
expectedChannel := channels[expectedNotification]
|
expectedChannel := channels[expectedNotification]
|
||||||
if expectedChannel == nil {
|
if expectedChannel == nil {
|
||||||
logrus.Errorf("unknown notification type in waitForNotification %x", expectedNotification)
|
logrus.Errorf("unknown notification type in waitForNotification %x", expectedNotification)
|
||||||
|
return ErrInvalidNotificationType
|
||||||
}
|
}
|
||||||
|
|
||||||
if timeout != nil {
|
if timeout != nil {
|
||||||
|
@ -72,38 +73,54 @@ func waitForNotification(callbackNumber uintptr, expectedNotification hcsNotific
|
||||||
defer timer.Stop()
|
defer timer.Stop()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case err := <-expectedChannel:
|
case err, ok := <-expectedChannel:
|
||||||
|
if !ok {
|
||||||
|
return ErrHandleClose
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
case err := <-channels[hcsNotificationSystemExited]:
|
case err, ok := <-channels[hcsNotificationSystemExited]:
|
||||||
|
if !ok {
|
||||||
|
return ErrHandleClose
|
||||||
|
}
|
||||||
// If the expected notification is hcsNotificationSystemExited which of the two selects
|
// If the expected notification is hcsNotificationSystemExited which of the two selects
|
||||||
// chosen is random. Return the raw error if hcsNotificationSystemExited is expected
|
// chosen is random. Return the raw error if hcsNotificationSystemExited is expected
|
||||||
if channels[hcsNotificationSystemExited] == expectedChannel {
|
if channels[hcsNotificationSystemExited] == expectedChannel {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return ErrUnexpectedContainerExit
|
return ErrUnexpectedContainerExit
|
||||||
case err := <-channels[hcsNotificationServiceDisconnect]:
|
case _, ok := <-channels[hcsNotificationServiceDisconnect]:
|
||||||
|
if !ok {
|
||||||
|
return ErrHandleClose
|
||||||
|
}
|
||||||
// hcsNotificationServiceDisconnect should never be an expected notification
|
// hcsNotificationServiceDisconnect should never be an expected notification
|
||||||
// it does not need the same handling as hcsNotificationSystemExited
|
// it does not need the same handling as hcsNotificationSystemExited
|
||||||
logrus.Error(err)
|
|
||||||
return ErrUnexpectedProcessAbort
|
return ErrUnexpectedProcessAbort
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
return ErrTimeout
|
return ErrTimeout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case err := <-expectedChannel:
|
case err, ok := <-expectedChannel:
|
||||||
|
if !ok {
|
||||||
|
return ErrHandleClose
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
case err := <-channels[hcsNotificationSystemExited]:
|
case err, ok := <-channels[hcsNotificationSystemExited]:
|
||||||
|
if !ok {
|
||||||
|
return ErrHandleClose
|
||||||
|
}
|
||||||
// If the expected notification is hcsNotificationSystemExited which of the two selects
|
// If the expected notification is hcsNotificationSystemExited which of the two selects
|
||||||
// chosen is random. Return the raw error if hcsNotificationSystemExited is expected
|
// chosen is random. Return the raw error if hcsNotificationSystemExited is expected
|
||||||
if channels[hcsNotificationSystemExited] == expectedChannel {
|
if channels[hcsNotificationSystemExited] == expectedChannel {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return ErrUnexpectedContainerExit
|
return ErrUnexpectedContainerExit
|
||||||
case err := <-channels[hcsNotificationServiceDisconnect]:
|
case _, ok := <-channels[hcsNotificationServiceDisconnect]:
|
||||||
|
if !ok {
|
||||||
|
return ErrHandleClose
|
||||||
|
}
|
||||||
// hcsNotificationServiceDisconnect should never be an expected notification
|
// hcsNotificationServiceDisconnect should never be an expected notification
|
||||||
// it does not need the same handling as hcsNotificationSystemExited
|
// it does not need the same handling as hcsNotificationSystemExited
|
||||||
logrus.Error(err)
|
|
||||||
return ErrUnexpectedProcessAbort
|
return ErrUnexpectedProcessAbort
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue