Revendor Microsoft/hcsshim and go-winio

Signed-off-by: John Howard <john.howard@microsoft.com>
This commit is contained in:
John Howard
2018-08-20 11:31:28 -07:00
parent 5d8ed81e60
commit 8fe92ea5f3
6 changed files with 113 additions and 34 deletions

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"os"
"strconv"
"sync"
"syscall"
"time"
@@ -136,8 +137,26 @@ type ResourceModificationRequestResponse struct {
// is merged in the CreateContainer call to HCS.
var createContainerAdditionalJSON string
// currentContainerStarts is used to limit the number of concurrent container
// starts.
var currentContainerStarts containerStarts
type containerStarts struct {
maxParallel int
inProgress int
sync.Mutex
}
func init() {
createContainerAdditionalJSON = os.Getenv("HCSSHIM_CREATECONTAINER_ADDITIONALJSON")
mpsS := os.Getenv("HCSSHIM_MAX_PARALLEL_START")
if len(mpsS) > 0 {
mpsI, err := strconv.Atoi(mpsS)
if err != nil || mpsI < 0 {
return
}
currentContainerStarts.maxParallel = mpsI
}
}
// CreateContainer creates a new container with the given configuration but does not start it.
@@ -325,6 +344,32 @@ func (container *container) Start() error {
return makeContainerError(container, operation, "", ErrAlreadyClosed)
}
// This is a very simple backoff-retry loop to limit the number
// of parallel container starts if environment variable
// HCSSHIM_MAX_PARALLEL_START is set to a positive integer.
// It should generally only be used as a workaround to various
// platform issues that exist between RS1 and RS4 as of Aug 2018.
if currentContainerStarts.maxParallel > 0 {
for {
currentContainerStarts.Lock()
if currentContainerStarts.inProgress < currentContainerStarts.maxParallel {
currentContainerStarts.inProgress++
currentContainerStarts.Unlock()
break
}
if currentContainerStarts.inProgress == currentContainerStarts.maxParallel {
currentContainerStarts.Unlock()
time.Sleep(100 * time.Millisecond)
}
}
// Make sure we decrement the count when we are done.
defer func() {
currentContainerStarts.Lock()
currentContainerStarts.inProgress--
currentContainerStarts.Unlock()
}()
}
var resultp *uint16
err := hcsStartComputeSystem(container.handle, "", &resultp)
err = processAsyncHcsResult(err, resultp, container.callbackNumber, hcsNotificationSystemStartCompleted, &defaultTimeout)

View File

@@ -6,6 +6,30 @@ import (
"time"
)
// RegistryKey is used to specify registry key name
type RegistryKey struct {
Hive string
Name string
Volatile bool `json:",omitempty"`
}
// RegistryKey is used to specify registry key name
type RegistryValue struct {
Key RegistryKey
Name string
Type string
StringValue string `json:",omitempty"`
BinaryValue []byte `json:",omitempty"`
DWordValue *uint32 `json:",omitempty"`
QWordValue *uint64 `json:",omitempty"`
CustomType *uint32 `json:",omitempty"`
}
type RegistryChanges struct {
AddValues []RegistryValue `json:",omitempty"`
DeleteKeys []RegistryValue `json:",omitempty"`
}
// ProcessConfig is used as both the input of Container.CreateProcess
// and to convert the parameters to JSON for passing onto the HCS
type ProcessConfig struct {
@@ -36,6 +60,8 @@ type MappedDir struct {
BandwidthMaximum uint64
IOPSMaximum uint64
CreateInUtilityVM bool
// LinuxMetadata - Support added in 1803/RS4+.
LinuxMetadata bool `json:",omitempty"`
}
type MappedPipe struct {
@@ -62,6 +88,14 @@ type MappedVirtualDisk struct {
AttachOnly bool `json:",omitempty:`
}
// AssignedDevice represents a device that has been directly assigned to a container
//
// NOTE: Support added in RS5
type AssignedDevice struct {
// InterfaceClassGUID of the device to assign to container.
InterfaceClassGUID string `json:"InterfaceClassGuid,omitempty"`
}
// ContainerConfig is used as both the input of CreateContainer
// and to convert the parameters to JSON for passing onto the HCS
type ContainerConfig struct {
@@ -93,6 +127,8 @@ type ContainerConfig struct {
ContainerType string `json:",omitempty"` // "Linux" for Linux containers on Windows. Omitted otherwise.
TerminateOnLastHandleClosed bool `json:",omitempty"` // Should HCS terminate the container once all handles have been closed
MappedVirtualDisks []MappedVirtualDisk `json:",omitempty"` // Array of virtual disks to mount at start
AssignedDevices []AssignedDevice `json:",omitempty"` // Array of devices to assign. NOTE: Support added in RS5
RegistryChanges *RegistryChanges `json:",omitempty"` // Registry changes to be applied to the container
}
type ComputeSystemQuery struct {

View File

@@ -283,7 +283,7 @@ func (r *legacyLayerReader) Next() (path string, size int64, fileInfo *winio.Fil
if err != nil {
return
}
fileInfo.FileAttributes = uintptr(attr)
fileInfo.FileAttributes = attr
beginning := int64(4)
// Find the accurate file size.