소스 검색

Revendor Microsoft/HCSShim v0.5.7

Signed-off-by: John Howard <jhoward@microsoft.com>
John Howard 8 년 전
부모
커밋
8ae9160643

+ 1 - 1
vendor.conf

@@ -1,6 +1,6 @@
 # the following lines are in sorted order, FYI
 # the following lines are in sorted order, FYI
 github.com/Azure/go-ansiterm 388960b655244e76e24c75f48631564eaefade62
 github.com/Azure/go-ansiterm 388960b655244e76e24c75f48631564eaefade62
-github.com/Microsoft/hcsshim v0.5.2
+github.com/Microsoft/hcsshim v0.5.7
 github.com/Microsoft/go-winio v0.3.5
 github.com/Microsoft/go-winio v0.3.5
 github.com/Sirupsen/logrus f76d643702a30fbffecdfe50831e11881c96ceb3 https://github.com/aaronlehmann/logrus
 github.com/Sirupsen/logrus f76d643702a30fbffecdfe50831e11881c96ceb3 https://github.com/aaronlehmann/logrus
 github.com/davecgh/go-spew 6d212800a42e8ab5c146b8ace3490ee17e5225f9
 github.com/davecgh/go-spew 6d212800a42e8ab5c146b8ace3490ee17e5225f9

+ 53 - 13
vendor/github.com/Microsoft/hcsshim/container.go

@@ -27,7 +27,8 @@ type container struct {
 	callbackNumber uintptr
 	callbackNumber uintptr
 }
 }
 
 
-type containerProperties struct {
+// ContainerProperties holds the properties for a container and the processes running in that container
+type ContainerProperties struct {
 	ID                string `json:"Id"`
 	ID                string `json:"Id"`
 	Name              string
 	Name              string
 	SystemType        string
 	SystemType        string
@@ -35,6 +36,8 @@ type containerProperties struct {
 	SiloGUID          string            `json:"SiloGuid,omitempty"`
 	SiloGUID          string            `json:"SiloGuid,omitempty"`
 	IsDummy           bool              `json:",omitempty"`
 	IsDummy           bool              `json:",omitempty"`
 	RuntimeID         string            `json:"RuntimeId,omitempty"`
 	RuntimeID         string            `json:"RuntimeId,omitempty"`
+	IsRuntimeTemplate bool              `json:",omitempty"`
+	RuntimeImagePath  string            `json:",omitempty"`
 	Stopped           bool              `json:",omitempty"`
 	Stopped           bool              `json:",omitempty"`
 	ExitType          string            `json:",omitempty"`
 	ExitType          string            `json:",omitempty"`
 	AreUpdatesPending bool              `json:",omitempty"`
 	AreUpdatesPending bool              `json:",omitempty"`
@@ -161,11 +164,47 @@ func OpenContainer(id string) (Container, error) {
 
 
 	container.handle = handle
 	container.handle = handle
 
 
+	if err := container.registerCallback(); err != nil {
+		return nil, makeContainerError(container, operation, "", err)
+	}
+
 	logrus.Debugf(title+" succeeded id=%s handle=%d", id, handle)
 	logrus.Debugf(title+" succeeded id=%s handle=%d", id, handle)
 	runtime.SetFinalizer(container, closeContainer)
 	runtime.SetFinalizer(container, closeContainer)
 	return container, nil
 	return container, nil
 }
 }
 
 
+// GetContainers gets a list of the containers on the system that match the query
+func GetContainers(q ComputeSystemQuery) ([]ContainerProperties, error) {
+	operation := "GetContainers"
+	title := "HCSShim::" + operation
+
+	queryb, err := json.Marshal(q)
+	if err != nil {
+		return nil, err
+	}
+
+	query := string(queryb)
+	logrus.Debugf(title+" query=%s", query)
+
+	var (
+		resultp         *uint16
+		computeSystemsp *uint16
+	)
+	err = hcsEnumerateComputeSystems(query, &computeSystemsp, &resultp)
+	err = processHcsResult(err, resultp)
+	if computeSystemsp == nil {
+		return nil, ErrUnexpectedValue
+	}
+	computeSystemsRaw := convertAndFreeCoTaskMemBytes(computeSystemsp)
+	computeSystems := []ContainerProperties{}
+	if err := json.Unmarshal(computeSystemsRaw, &computeSystems); err != nil {
+		return nil, err
+	}
+
+	logrus.Debugf(title + " succeeded")
+	return computeSystems, nil
+}
+
 // Start synchronously starts the container.
 // Start synchronously starts the container.
 func (container *container) Start() error {
 func (container *container) Start() error {
 	container.handleLock.RLock()
 	container.handleLock.RLock()
@@ -175,7 +214,7 @@ func (container *container) Start() error {
 	logrus.Debugf(title+" id=%s", container.id)
 	logrus.Debugf(title+" id=%s", container.id)
 
 
 	if container.handle == 0 {
 	if container.handle == 0 {
-		return makeContainerError(container, operation, "", ErrInvalidHandle)
+		return makeContainerError(container, operation, "", ErrAlreadyClosed)
 	}
 	}
 
 
 	var resultp *uint16
 	var resultp *uint16
@@ -199,7 +238,7 @@ func (container *container) Shutdown() error {
 	logrus.Debugf(title+" id=%s", container.id)
 	logrus.Debugf(title+" id=%s", container.id)
 
 
 	if container.handle == 0 {
 	if container.handle == 0 {
-		return makeContainerError(container, operation, "", ErrInvalidHandle)
+		return makeContainerError(container, operation, "", ErrAlreadyClosed)
 	}
 	}
 
 
 	var resultp *uint16
 	var resultp *uint16
@@ -223,7 +262,7 @@ func (container *container) Terminate() error {
 	logrus.Debugf(title+" id=%s", container.id)
 	logrus.Debugf(title+" id=%s", container.id)
 
 
 	if container.handle == 0 {
 	if container.handle == 0 {
-		return makeContainerError(container, operation, "", ErrInvalidHandle)
+		return makeContainerError(container, operation, "", ErrAlreadyClosed)
 	}
 	}
 
 
 	var resultp *uint16
 	var resultp *uint16
@@ -268,7 +307,7 @@ func (container *container) WaitTimeout(timeout time.Duration) error {
 	return nil
 	return nil
 }
 }
 
 
-func (container *container) properties(query string) (*containerProperties, error) {
+func (container *container) properties(query string) (*ContainerProperties, error) {
 	var (
 	var (
 		resultp     *uint16
 		resultp     *uint16
 		propertiesp *uint16
 		propertiesp *uint16
@@ -283,7 +322,7 @@ func (container *container) properties(query string) (*containerProperties, erro
 		return nil, ErrUnexpectedValue
 		return nil, ErrUnexpectedValue
 	}
 	}
 	propertiesRaw := convertAndFreeCoTaskMemBytes(propertiesp)
 	propertiesRaw := convertAndFreeCoTaskMemBytes(propertiesp)
-	properties := &containerProperties{}
+	properties := &ContainerProperties{}
 	if err := json.Unmarshal(propertiesRaw, properties); err != nil {
 	if err := json.Unmarshal(propertiesRaw, properties); err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
@@ -299,7 +338,7 @@ func (container *container) HasPendingUpdates() (bool, error) {
 	logrus.Debugf(title+" id=%s", container.id)
 	logrus.Debugf(title+" id=%s", container.id)
 
 
 	if container.handle == 0 {
 	if container.handle == 0 {
-		return false, makeContainerError(container, operation, "", ErrInvalidHandle)
+		return false, makeContainerError(container, operation, "", ErrAlreadyClosed)
 	}
 	}
 
 
 	properties, err := container.properties(pendingUpdatesQuery)
 	properties, err := container.properties(pendingUpdatesQuery)
@@ -320,7 +359,7 @@ func (container *container) Statistics() (Statistics, error) {
 	logrus.Debugf(title+" id=%s", container.id)
 	logrus.Debugf(title+" id=%s", container.id)
 
 
 	if container.handle == 0 {
 	if container.handle == 0 {
-		return Statistics{}, makeContainerError(container, operation, "", ErrInvalidHandle)
+		return Statistics{}, makeContainerError(container, operation, "", ErrAlreadyClosed)
 	}
 	}
 
 
 	properties, err := container.properties(statisticsQuery)
 	properties, err := container.properties(statisticsQuery)
@@ -341,7 +380,7 @@ func (container *container) ProcessList() ([]ProcessListItem, error) {
 	logrus.Debugf(title+" id=%s", container.id)
 	logrus.Debugf(title+" id=%s", container.id)
 
 
 	if container.handle == 0 {
 	if container.handle == 0 {
-		return nil, makeContainerError(container, operation, "", ErrInvalidHandle)
+		return nil, makeContainerError(container, operation, "", ErrAlreadyClosed)
 	}
 	}
 
 
 	properties, err := container.properties(processListQuery)
 	properties, err := container.properties(processListQuery)
@@ -362,7 +401,7 @@ func (container *container) Pause() error {
 	logrus.Debugf(title+" id=%s", container.id)
 	logrus.Debugf(title+" id=%s", container.id)
 
 
 	if container.handle == 0 {
 	if container.handle == 0 {
-		return makeContainerError(container, operation, "", ErrInvalidHandle)
+		return makeContainerError(container, operation, "", ErrAlreadyClosed)
 	}
 	}
 
 
 	var resultp *uint16
 	var resultp *uint16
@@ -385,7 +424,7 @@ func (container *container) Resume() error {
 	logrus.Debugf(title+" id=%s", container.id)
 	logrus.Debugf(title+" id=%s", container.id)
 
 
 	if container.handle == 0 {
 	if container.handle == 0 {
-		return makeContainerError(container, operation, "", ErrInvalidHandle)
+		return makeContainerError(container, operation, "", ErrAlreadyClosed)
 	}
 	}
 
 
 	var resultp *uint16
 	var resultp *uint16
@@ -412,7 +451,7 @@ func (container *container) CreateProcess(c *ProcessConfig) (Process, error) {
 	)
 	)
 
 
 	if container.handle == 0 {
 	if container.handle == 0 {
-		return nil, makeContainerError(container, operation, "", ErrInvalidHandle)
+		return nil, makeContainerError(container, operation, "", ErrAlreadyClosed)
 	}
 	}
 
 
 	// If we are not emulating a console, ignore any console size passed to us
 	// If we are not emulating a console, ignore any console size passed to us
@@ -468,7 +507,7 @@ func (container *container) OpenProcess(pid int) (Process, error) {
 	)
 	)
 
 
 	if container.handle == 0 {
 	if container.handle == 0 {
-		return nil, makeContainerError(container, operation, "", ErrInvalidHandle)
+		return nil, makeContainerError(container, operation, "", ErrAlreadyClosed)
 	}
 	}
 
 
 	err := hcsOpenProcess(container.handle, uint32(pid), &processHandle, &resultp)
 	err := hcsOpenProcess(container.handle, uint32(pid), &processHandle, &resultp)
@@ -514,6 +553,7 @@ func (container *container) Close() error {
 	}
 	}
 
 
 	container.handle = 0
 	container.handle = 0
+	runtime.SetFinalizer(container, nil)
 
 
 	logrus.Debugf(title+" succeeded id=%s", container.id)
 	logrus.Debugf(title+" succeeded id=%s", container.id)
 	return nil
 	return nil

+ 9 - 2
vendor/github.com/Microsoft/hcsshim/errors.go

@@ -16,8 +16,8 @@ var (
 	// ErrHandleClose is an error encountered when the handle generating the notification being waited on has been closed
 	// ErrHandleClose is an error encountered when the handle generating the notification being waited on has been closed
 	ErrHandleClose = errors.New("hcsshim: the handle generating this notification has been closed")
 	ErrHandleClose = errors.New("hcsshim: the handle generating this notification has been closed")
 
 
-	// ErrInvalidHandle is an error encountered when using an invalid handle
-	ErrInvalidHandle = errors.New("hcsshim: the handle is invalid")
+	// ErrAlreadyClosed is an error encountered when using a handle that has been closed by the Close method
+	ErrAlreadyClosed = errors.New("hcsshim: the handle has already been closed")
 
 
 	// ErrInvalidNotificationType is an error encountered when an invalid notification type is used
 	// ErrInvalidNotificationType is an error encountered when an invalid notification type is used
 	ErrInvalidNotificationType = errors.New("hcsshim: invalid notification type")
 	ErrInvalidNotificationType = errors.New("hcsshim: invalid notification type")
@@ -159,6 +159,13 @@ func IsNotExist(err error) bool {
 		err == ErrProcNotFound
 		err == ErrProcNotFound
 }
 }
 
 
+// IsAlreadyClosed checks if an error is caused by the Container or Process having been
+// already closed by a call to the Close() method.
+func IsAlreadyClosed(err error) bool {
+	err = getInnerError(err)
+	return err == ErrAlreadyClosed
+}
+
 // IsPending returns a boolean indicating whether the error is that
 // IsPending returns a boolean indicating whether the error is that
 // the requested operation is being completed in the background.
 // the requested operation is being completed in the background.
 func IsPending(err error) bool {
 func IsPending(err error) bool {

+ 3 - 2
vendor/github.com/Microsoft/hcsshim/hnsfuncs.go

@@ -52,7 +52,7 @@ type MacPool struct {
 
 
 // HNSNetwork represents a network in HNS
 // HNSNetwork represents a network in HNS
 type HNSNetwork struct {
 type HNSNetwork struct {
-	Id                   string            `json:",omitempty"`
+	Id                   string            `json:"ID,omitempty"`
 	Name                 string            `json:",omitempty"`
 	Name                 string            `json:",omitempty"`
 	Type                 string            `json:",omitempty"`
 	Type                 string            `json:",omitempty"`
 	NetworkAdapterName   string            `json:",omitempty"`
 	NetworkAdapterName   string            `json:",omitempty"`
@@ -68,7 +68,7 @@ type HNSNetwork struct {
 
 
 // HNSEndpoint represents a network endpoint in HNS
 // HNSEndpoint represents a network endpoint in HNS
 type HNSEndpoint struct {
 type HNSEndpoint struct {
-	Id                 string            `json:",omitempty"`
+	Id                 string            `json:"ID,omitempty"`
 	Name               string            `json:",omitempty"`
 	Name               string            `json:",omitempty"`
 	VirtualNetwork     string            `json:",omitempty"`
 	VirtualNetwork     string            `json:",omitempty"`
 	VirtualNetworkName string            `json:",omitempty"`
 	VirtualNetworkName string            `json:",omitempty"`
@@ -79,6 +79,7 @@ type HNSEndpoint struct {
 	DNSServerList      string            `json:",omitempty"`
 	DNSServerList      string            `json:",omitempty"`
 	GatewayAddress     string            `json:",omitempty"`
 	GatewayAddress     string            `json:",omitempty"`
 	EnableInternalDNS  bool              `json:",omitempty"`
 	EnableInternalDNS  bool              `json:",omitempty"`
+	DisableICC         bool              `json:",omitempty"`
 	PrefixLength       uint8             `json:",omitempty"`
 	PrefixLength       uint8             `json:",omitempty"`
 	IsRemoteEndpoint   bool              `json:",omitempty"`
 	IsRemoteEndpoint   bool              `json:",omitempty"`
 }
 }

+ 8 - 0
vendor/github.com/Microsoft/hcsshim/interface.go

@@ -10,6 +10,7 @@ import (
 type ProcessConfig struct {
 type ProcessConfig struct {
 	ApplicationName  string
 	ApplicationName  string
 	CommandLine      string
 	CommandLine      string
+	User             string
 	WorkingDirectory string
 	WorkingDirectory string
 	Environment      map[string]string
 	Environment      map[string]string
 	EmulateConsole   bool
 	EmulateConsole   bool
@@ -66,6 +67,13 @@ type ContainerConfig struct {
 	AllowUnqualifiedDNSQuery bool        // True to allow unqualified DNS name resolution
 	AllowUnqualifiedDNSQuery bool        // True to allow unqualified DNS name resolution
 }
 }
 
 
+type ComputeSystemQuery struct {
+	IDs    []string `json:"Ids,omitempty"`
+	Types  []string `json:",omitempty"`
+	Names  []string `json:",omitempty"`
+	Owners []string `json:",omitempty"`
+}
+
 // Container represents a created (but not necessarily running) container.
 // Container represents a created (but not necessarily running) container.
 type Container interface {
 type Container interface {
 	// Start synchronously starts the container.
 	// Start synchronously starts the container.

+ 7 - 5
vendor/github.com/Microsoft/hcsshim/process.go

@@ -3,6 +3,7 @@ package hcsshim
 import (
 import (
 	"encoding/json"
 	"encoding/json"
 	"io"
 	"io"
+	"runtime"
 	"sync"
 	"sync"
 	"syscall"
 	"syscall"
 	"time"
 	"time"
@@ -73,7 +74,7 @@ func (process *process) Kill() error {
 	logrus.Debugf(title+" processid=%d", process.processID)
 	logrus.Debugf(title+" processid=%d", process.processID)
 
 
 	if process.handle == 0 {
 	if process.handle == 0 {
-		return makeProcessError(process, operation, "", ErrInvalidHandle)
+		return makeProcessError(process, operation, "", ErrAlreadyClosed)
 	}
 	}
 
 
 	var resultp *uint16
 	var resultp *uint16
@@ -128,7 +129,7 @@ func (process *process) ExitCode() (int, error) {
 	logrus.Debugf(title+" processid=%d", process.processID)
 	logrus.Debugf(title+" processid=%d", process.processID)
 
 
 	if process.handle == 0 {
 	if process.handle == 0 {
-		return 0, makeProcessError(process, operation, "", ErrInvalidHandle)
+		return 0, makeProcessError(process, operation, "", ErrAlreadyClosed)
 	}
 	}
 
 
 	properties, err := process.properties()
 	properties, err := process.properties()
@@ -157,7 +158,7 @@ func (process *process) ResizeConsole(width, height uint16) error {
 	logrus.Debugf(title+" processid=%d", process.processID)
 	logrus.Debugf(title+" processid=%d", process.processID)
 
 
 	if process.handle == 0 {
 	if process.handle == 0 {
-		return makeProcessError(process, operation, "", ErrInvalidHandle)
+		return makeProcessError(process, operation, "", ErrAlreadyClosed)
 	}
 	}
 
 
 	modifyRequest := processModifyRequest{
 	modifyRequest := processModifyRequest{
@@ -226,7 +227,7 @@ func (process *process) Stdio() (io.WriteCloser, io.ReadCloser, io.ReadCloser, e
 	logrus.Debugf(title+" processid=%d", process.processID)
 	logrus.Debugf(title+" processid=%d", process.processID)
 
 
 	if process.handle == 0 {
 	if process.handle == 0 {
-		return nil, nil, nil, makeProcessError(process, operation, "", ErrInvalidHandle)
+		return nil, nil, nil, makeProcessError(process, operation, "", ErrAlreadyClosed)
 	}
 	}
 
 
 	var stdIn, stdOut, stdErr syscall.Handle
 	var stdIn, stdOut, stdErr syscall.Handle
@@ -270,7 +271,7 @@ func (process *process) CloseStdin() error {
 	logrus.Debugf(title+" processid=%d", process.processID)
 	logrus.Debugf(title+" processid=%d", process.processID)
 
 
 	if process.handle == 0 {
 	if process.handle == 0 {
-		return makeProcessError(process, operation, "", ErrInvalidHandle)
+		return makeProcessError(process, operation, "", ErrAlreadyClosed)
 	}
 	}
 
 
 	modifyRequest := processModifyRequest{
 	modifyRequest := processModifyRequest{
@@ -321,6 +322,7 @@ func (process *process) Close() error {
 	}
 	}
 
 
 	process.handle = 0
 	process.handle = 0
+	runtime.SetFinalizer(process, nil)
 
 
 	logrus.Debugf(title+" succeeded processid=%d", process.processID)
 	logrus.Debugf(title+" succeeded processid=%d", process.processID)
 	return nil
 	return nil

+ 5 - 27
vendor/github.com/Microsoft/hcsshim/waithelper.go

@@ -26,37 +26,13 @@ func waitForNotification(callbackNumber uintptr, expectedNotification hcsNotific
 		return ErrInvalidNotificationType
 		return ErrInvalidNotificationType
 	}
 	}
 
 
+	var c <-chan time.Time
 	if timeout != nil {
 	if timeout != nil {
 		timer := time.NewTimer(*timeout)
 		timer := time.NewTimer(*timeout)
+		c = timer.C
 		defer timer.Stop()
 		defer timer.Stop()
-
-		select {
-		case err, ok := <-expectedChannel:
-			if !ok {
-				return ErrHandleClose
-			}
-			return err
-		case err, ok := <-channels[hcsNotificationSystemExited]:
-			if !ok {
-				return ErrHandleClose
-			}
-			// If the expected notification is hcsNotificationSystemExited which of the two selects
-			// chosen is random. Return the raw error if hcsNotificationSystemExited is expected
-			if channels[hcsNotificationSystemExited] == expectedChannel {
-				return err
-			}
-			return ErrUnexpectedContainerExit
-		case _, ok := <-channels[hcsNotificationServiceDisconnect]:
-			if !ok {
-				return ErrHandleClose
-			}
-			// hcsNotificationServiceDisconnect should never be an expected notification
-			// it does not need the same handling as hcsNotificationSystemExited
-			return ErrUnexpectedProcessAbort
-		case <-timer.C:
-			return ErrTimeout
-		}
 	}
 	}
+
 	select {
 	select {
 	case err, ok := <-expectedChannel:
 	case err, ok := <-expectedChannel:
 		if !ok {
 		if !ok {
@@ -80,5 +56,7 @@ func waitForNotification(callbackNumber uintptr, expectedNotification hcsNotific
 		// 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
 		return ErrUnexpectedProcessAbort
 		return ErrUnexpectedProcessAbort
+	case <-c:
+		return ErrTimeout
 	}
 	}
 }
 }