Skip to content

Commit

Permalink
Merge pull request #77 from darrenstahlmsft/RemoveTP5
Browse files Browse the repository at this point in the history
Remove TP5 support
  • Loading branch information
swernli authored Oct 4, 2016
2 parents 0a4175a + f63798c commit 00e2942
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 569 deletions.
96 changes: 24 additions & 72 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,15 @@ func CreateContainer(id string, c *ContainerConfig) (Container, error) {
logrus.Debugf(title+" id=%s config=%s", id, configuration)

var (
resultp *uint16
createError error
resultp *uint16
identity syscall.Handle
)
if hcsCallbacksSupported {
var identity syscall.Handle
createError = hcsCreateComputeSystem(id, configuration, identity, &container.handle, &resultp)

if createError == nil || IsPending(createError) {
if err := container.registerCallback(); err != nil {
return nil, makeContainerError(container, operation, "", err)
}
createError := hcsCreateComputeSystem(id, configuration, identity, &container.handle, &resultp)

if createError == nil || IsPending(createError) {
if err := container.registerCallback(); err != nil {
return nil, makeContainerError(container, operation, "", err)
}
} else {
createError = hcsCreateComputeSystemTP5(id, configuration, &container.handle, &resultp)
}

err = processAsyncHcsResult(createError, resultp, container.callbackNumber, hcsNotificationSystemCreateCompleted, &defaultTimeout)
Expand Down Expand Up @@ -184,7 +179,7 @@ func (container *container) Start() error {
}

var resultp *uint16
err := hcsStartComputeSystemTP5(container.handle, nil, &resultp)
err := hcsStartComputeSystem(container.handle, "", &resultp)
err = processAsyncHcsResult(err, resultp, container.callbackNumber, hcsNotificationSystemStartCompleted, &defaultTimeout)
if err != nil {
return makeContainerError(container, operation, "", err)
Expand All @@ -208,7 +203,7 @@ func (container *container) Shutdown() error {
}

var resultp *uint16
err := hcsShutdownComputeSystemTP5(container.handle, nil, &resultp)
err := hcsShutdownComputeSystem(container.handle, "", &resultp)
err = processHcsResult(err, resultp)
if err != nil {
return makeContainerError(container, operation, "", err)
Expand All @@ -232,7 +227,7 @@ func (container *container) Terminate() error {
}

var resultp *uint16
err := hcsTerminateComputeSystemTP5(container.handle, nil, &resultp)
err := hcsTerminateComputeSystem(container.handle, "", &resultp)
err = processHcsResult(err, resultp)
if err != nil {
return makeContainerError(container, operation, "", err)
Expand All @@ -248,68 +243,31 @@ func (container *container) Wait() error {
title := "HCSShim::Container::" + operation
logrus.Debugf(title+" id=%s", container.id)

if hcsCallbacksSupported {
err := waitForNotification(container.callbackNumber, hcsNotificationSystemExited, nil)
if err != nil {
return makeContainerError(container, operation, "", err)
}
} else {
_, err := container.waitTimeoutInternal(syscall.INFINITE)
if err != nil {
return makeContainerError(container, operation, "", err)
}
err := waitForNotification(container.callbackNumber, hcsNotificationSystemExited, nil)
if err != nil {
return makeContainerError(container, operation, "", err)
}

logrus.Debugf(title+" succeeded id=%s", container.id)
return nil
}

func (container *container) waitTimeoutInternal(timeout uint32) (bool, error) {
return waitTimeoutInternalHelper(container, timeout)
}

// WaitTimeout synchronously waits for the container to terminate or the duration to elapse.
// If the timeout expires, IsTimeout(err) == true
func (container *container) WaitTimeout(timeout time.Duration) error {
operation := "WaitTimeout"
title := "HCSShim::Container::" + operation
logrus.Debugf(title+" id=%s", container.id)

if hcsCallbacksSupported {
err := waitForNotification(container.callbackNumber, hcsNotificationSystemExited, &timeout)
if err != nil {
return makeContainerError(container, operation, "", err)
}
} else {
finished, err := waitTimeoutHelper(container, timeout)
if !finished {
err = ErrTimeout
}
if err != nil {
return makeContainerError(container, operation, "", err)
}
err := waitForNotification(container.callbackNumber, hcsNotificationSystemExited, &timeout)
if err != nil {
return makeContainerError(container, operation, "", err)
}

logrus.Debugf(title+" succeeded id=%s", container.id)
return nil
}

func (container *container) hcsWait(timeout uint32) (bool, error) {
var (
resultp *uint16
exitEvent syscall.Handle
)

err := hcsCreateComputeSystemWait(container.handle, &exitEvent, &resultp)
err = processHcsResult(err, resultp)
if err != nil {
return false, err
}
defer syscall.CloseHandle(exitEvent)

return waitForSingleObject(exitEvent, timeout)
}

func (container *container) properties(query string) (*containerProperties, error) {
var (
resultp *uint16
Expand Down Expand Up @@ -408,7 +366,7 @@ func (container *container) Pause() error {
}

var resultp *uint16
err := hcsPauseComputeSystemTP5(container.handle, nil, &resultp)
err := hcsPauseComputeSystem(container.handle, "", &resultp)
err = processAsyncHcsResult(err, resultp, container.callbackNumber, hcsNotificationSystemPauseCompleted, &defaultTimeout)
if err != nil {
return makeContainerError(container, operation, "", err)
Expand All @@ -431,7 +389,7 @@ func (container *container) Resume() error {
}

var resultp *uint16
err := hcsResumeComputeSystemTP5(container.handle, nil, &resultp)
err := hcsResumeComputeSystem(container.handle, "", &resultp)
err = processAsyncHcsResult(err, resultp, container.callbackNumber, hcsNotificationSystemResumeCompleted, &defaultTimeout)
if err != nil {
return makeContainerError(container, operation, "", err)
Expand Down Expand Up @@ -488,10 +446,8 @@ func (container *container) CreateProcess(c *ProcessConfig) (Process, error) {
},
}

if hcsCallbacksSupported {
if err := process.registerCallback(); err != nil {
return nil, makeContainerError(container, operation, "", err)
}
if err := process.registerCallback(); err != nil {
return nil, makeContainerError(container, operation, "", err)
}

logrus.Debugf(title+" succeeded id=%s processid=%s", container.id, process.processID)
Expand Down Expand Up @@ -527,10 +483,8 @@ func (container *container) OpenProcess(pid int) (Process, error) {
container: container,
}

if hcsCallbacksSupported {
if err := process.registerCallback(); err != nil {
return nil, makeContainerError(container, operation, "", err)
}
if err := process.registerCallback(); err != nil {
return nil, makeContainerError(container, operation, "", err)
}

logrus.Debugf(title+" succeeded id=%s processid=%s", container.id, process.processID)
Expand All @@ -551,10 +505,8 @@ func (container *container) Close() error {
return nil
}

if hcsCallbacksSupported {
if err := container.unregisterCallback(); err != nil {
return makeContainerError(container, operation, "", err)
}
if err := container.unregisterCallback(); err != nil {
return makeContainerError(container, operation, "", err)
}

if err := hcsCloseComputeSystem(container.handle); err != nil {
Expand Down
27 changes: 5 additions & 22 deletions hcsshim.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ import (
//sys exportLayerRead(context uintptr, buffer []byte, bytesRead *uint32) (hr error) = vmcompute.ExportLayerRead?
//sys exportLayerEnd(context uintptr) (hr error) = vmcompute.ExportLayerEnd?

//sys createComputeSystem(id string, configuration string) (hr error) = vmcompute.CreateComputeSystem?
//sys createProcessWithStdHandlesInComputeSystem(id string, paramsJson string, pid *uint32, stdin *syscall.Handle, stdout *syscall.Handle, stderr *syscall.Handle) (hr error) = vmcompute.CreateProcessWithStdHandlesInComputeSystem?
//sys resizeConsoleInComputeSystem(id string, pid uint32, height uint16, width uint16, flags uint32) (hr error) = vmcompute.ResizeConsoleInComputeSystem?
//sys shutdownComputeSystem(id string, timeout uint32) (hr error) = vmcompute.ShutdownComputeSystem?
//sys startComputeSystem(id string) (hr error) = vmcompute.StartComputeSystem?
//sys terminateComputeSystem(id string) (hr error) = vmcompute.TerminateComputeSystem?
//sys terminateProcessInComputeSystem(id string, pid uint32) (hr error) = vmcompute.TerminateProcessInComputeSystem?
//sys waitForProcessInComputeSystem(id string, pid uint32, timeout uint32, exitCode *uint32) (hr error) = vmcompute.WaitForProcessInComputeSystem?
//sys getComputeSystemProperties(id string, flags uint32, properties **uint16) (hr error) = vmcompute.GetComputeSystemProperties?

//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?
Expand All @@ -65,29 +55,22 @@ import (
//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 hcsCreateComputeSystemWait(computeSystem hcsSystem, exitEvent *syscall.Handle, result **uint16) (hr error) = vmcompute.HcsCreateComputeSystemWait?
//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 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 hcsCreateProcessWait(process hcsProcess, settings *syscall.Handle, result **uint16) (hr error) = vmcompute.HcsCreateProcessWait?
//sys hcsGetServiceProperties(propertyQuery string, properties **uint16, result **uint16) (hr error) = vmcompute.HcsGetServiceProperties?
//sys hcsModifyServiceSettings(settings string, result **uint16) (hr error) = vmcompute.HcsModifyServiceSettings?

//sys hcsCreateComputeSystemTP5(id string, configuration string, computeSystem *hcsSystem, result **uint16) (hr error) = vmcompute.HcsCreateComputeSystem?
//sys hcsStartComputeSystemTP5(computeSystem hcsSystem, options *uint16, result **uint16) (hr error) = vmcompute.HcsStartComputeSystem?
//sys hcsShutdownComputeSystemTP5(computeSystem hcsSystem, options *uint16, result **uint16) (hr error) = vmcompute.HcsShutdownComputeSystem?
//sys hcsTerminateComputeSystemTP5(computeSystem hcsSystem, options *uint16, result **uint16) (hr error) = vmcompute.HcsTerminateComputeSystem?
//sys hcsPauseComputeSystemTP5(computeSystem hcsSystem, options *uint16, result **uint16) (hr error) = vmcompute.HcsPauseComputeSystem?
//sys hcsResumeComputeSystemTP5(computeSystem hcsSystem, options *uint16, result **uint16) (hr error) = vmcompute.HcsResumeComputeSystem?
//sys hcsRegisterComputeSystemCallback(computeSystem hcsSystem, callback uintptr, context uintptr, callbackHandle *hcsCallback) (hr error) = vmcompute.HcsRegisterComputeSystemCallback?
//sys hcsUnregisterComputeSystemCallback(callbackHandle hcsCallback) (hr error) = vmcompute.HcsUnregisterComputeSystemCallback?
//sys hcsRegisterProcessCallback(process hcsProcess, callback uintptr, context uintptr, callbackHandle *hcsCallback) (hr error) = vmcompute.HcsRegisterProcessCallback?
//sys hcsUnregisterProcessCallback(callbackHandle hcsCallback) (hr error) = vmcompute.HcsUnregisterProcessCallback?

//sys hcsModifyServiceSettings(settings string, result **uint16) (hr error) = vmcompute.HcsModifyServiceSettings?

//sys _hnsCall(method string, path string, object string, response **uint16) (hr error) = vmcompute.HNSCall?

const (
Expand Down
54 changes: 8 additions & 46 deletions process.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,9 @@ func (process *process) Wait() error {
title := "HCSShim::Process::" + operation
logrus.Debugf(title+" processid=%d", process.processID)

if hcsCallbacksSupported {
err := waitForNotification(process.callbackNumber, hcsNotificationProcessExited, nil)
if err != nil {
return makeProcessError(process, operation, "", err)
}
} else {
_, err := process.waitTimeoutInternal(syscall.INFINITE)
if err != nil {
return makeProcessError(process, operation, "", err)
}
err := waitForNotification(process.callbackNumber, hcsNotificationProcessExited, nil)
if err != nil {
return makeProcessError(process, operation, "", err)
}

logrus.Debugf(title+" succeeded processid=%d", process.processID)
Expand All @@ -116,44 +109,15 @@ func (process *process) WaitTimeout(timeout time.Duration) error {
title := "HCSShim::Process::" + operation
logrus.Debugf(title+" processid=%d", process.processID)

if hcsCallbacksSupported {
err := waitForNotification(process.callbackNumber, hcsNotificationProcessExited, &timeout)
if err != nil {
return makeProcessError(process, operation, "", err)
}
} else {
finished, err := waitTimeoutHelper(process, timeout)
if !finished {
err = ErrTimeout
}
if err != nil {
return makeProcessError(process, operation, "", err)
}
err := waitForNotification(process.callbackNumber, hcsNotificationProcessExited, &timeout)
if err != nil {
return makeProcessError(process, operation, "", err)
}

logrus.Debugf(title+" succeeded processid=%d", process.processID)
return nil
}

func (process *process) hcsWait(timeout uint32) (bool, error) {
var (
resultp *uint16
exitEvent syscall.Handle
)
err := hcsCreateProcessWait(process.handle, &exitEvent, &resultp)
err = processHcsResult(err, resultp)
if err != nil {
return false, err
}
defer syscall.CloseHandle(exitEvent)

return waitForSingleObject(exitEvent, timeout)
}

func (process *process) waitTimeoutInternal(timeout uint32) (bool, error) {
return waitTimeoutInternalHelper(process, timeout)
}

// ExitCode returns the exit code of the process. The process must have
// already terminated.
func (process *process) ExitCode() (int, error) {
Expand Down Expand Up @@ -348,10 +312,8 @@ func (process *process) Close() error {
return nil
}

if hcsCallbacksSupported {
if err := process.unregisterCallback(); err != nil {
return makeProcessError(process, operation, "", err)
}
if err := process.unregisterCallback(); err != nil {
return makeProcessError(process, operation, "", err)
}

if err := hcsCloseProcess(process.handle); err != nil {
Expand Down
6 changes: 0 additions & 6 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ import (
"github.com/Microsoft/go-winio"
)

var (
vmcomputedll = syscall.NewLazyDLL("vmcompute.dll")
hcsCallbackAPI = vmcomputedll.NewProc("HcsRegisterComputeSystemCallback")
hcsCallbacksSupported = hcsCallbackAPI.Find() == nil
)

// makeOpenFiles calls winio.MakeOpenFile for each handle in a slice but closes all the handles
// if there is an error.
func makeOpenFiles(hs []syscall.Handle) (_ []io.ReadWriteCloser, err error) {
Expand Down
46 changes: 2 additions & 44 deletions waithelper.go
Original file line number Diff line number Diff line change
@@ -1,52 +1,10 @@
package hcsshim

import (
"github.com/Sirupsen/logrus"
"syscall"
"time"
)

type waitable interface {
waitTimeoutInternal(timeout uint32) (bool, error)
hcsWait(timeout uint32) (bool, error)
}

func waitTimeoutHelper(object waitable, timeout time.Duration) (bool, error) {
var (
millis uint32
)

for totalMillis := uint64(timeout / time.Millisecond); totalMillis > 0; totalMillis = totalMillis - uint64(millis) {
if totalMillis >= syscall.INFINITE {
millis = syscall.INFINITE - 1
} else {
millis = uint32(totalMillis)
}

result, err := object.waitTimeoutInternal(millis)

if err != nil {
return result, err
}
}
return true, nil
}

func waitTimeoutInternalHelper(object waitable, timeout uint32) (bool, error) {
return object.hcsWait(timeout)
}

func waitForSingleObject(handle syscall.Handle, timeout uint32) (bool, error) {
s, e := syscall.WaitForSingleObject(handle, timeout)
switch s {
case syscall.WAIT_OBJECT_0:
return true, nil
case syscall.WAIT_TIMEOUT:
return false, nil
default:
return false, e
}
}
"github.com/Sirupsen/logrus"
)

func processAsyncHcsResult(err error, resultp *uint16, callbackNumber uintptr, expectedNotification hcsNotification, timeout *time.Duration) error {
err = processHcsResult(err, resultp)
Expand Down
Loading

0 comments on commit 00e2942

Please sign in to comment.