Merge pull request #2510 from thaJeztah/bump_hcsshim

vendor: Microsoft/hcsshim v0.8.9
This commit is contained in:
Silvin Lubecki 2020-05-11 14:31:58 +02:00 committed by GitHub
commit 65e139ee4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 745 additions and 349 deletions

View File

@ -42,7 +42,7 @@ github.com/konsorten/go-windows-terminal-sequences edb144dfd453055e1e49a3d8b410
github.com/mattn/go-shellwords 36a9b3c57cb5caa559ff63fb7e9b585f1c00df75 # v1.0.6 github.com/mattn/go-shellwords 36a9b3c57cb5caa559ff63fb7e9b585f1c00df75 # v1.0.6
github.com/matttproud/golang_protobuf_extensions c12348ce28de40eed0136aa2b644d0ee0650e56c # v1.0.1 github.com/matttproud/golang_protobuf_extensions c12348ce28de40eed0136aa2b644d0ee0650e56c # v1.0.1
github.com/Microsoft/go-winio 6c72808b55902eae4c5943626030429ff20f3b63 # v0.4.14 github.com/Microsoft/go-winio 6c72808b55902eae4c5943626030429ff20f3b63 # v0.4.14
github.com/Microsoft/hcsshim b3f49c06ffaeef24d09c6c08ec8ec8425a0303e2 # v0.8.7 github.com/Microsoft/hcsshim 5bc557dd210ff2caf615e6e22d398123de77fc11 # v0.8.9
github.com/miekg/pkcs11 210dc1e16747c5ba98a03bcbcf728c38086ea357 # v1.0.3 github.com/miekg/pkcs11 210dc1e16747c5ba98a03bcbcf728c38086ea357 # v1.0.3
github.com/mitchellh/mapstructure f15292f7a699fcc1a38a80977f80a046874ba8ac github.com/mitchellh/mapstructure f15292f7a699fcc1a38a80977f80a046874ba8ac
github.com/moby/buildkit ae7ff7174f73bcb4df89b97e1623b3fb0bfb0a0c github.com/moby/buildkit ae7ff7174f73bcb4df89b97e1623b3fb0bfb0a0c

151
vendor/github.com/Microsoft/go-winio/vhd/vhd.go generated vendored Normal file
View File

@ -0,0 +1,151 @@
// +build windows
package vhd
import "syscall"
//go:generate go run mksyscall_windows.go -output zvhd.go vhd.go
//sys createVirtualDisk(virtualStorageType *virtualStorageType, path string, virtualDiskAccessMask uint32, securityDescriptor *uintptr, flags uint32, providerSpecificFlags uint32, parameters *createVirtualDiskParameters, o *syscall.Overlapped, handle *syscall.Handle) (err error) [failretval != 0] = VirtDisk.CreateVirtualDisk
//sys openVirtualDisk(virtualStorageType *virtualStorageType, path string, virtualDiskAccessMask uint32, flags uint32, parameters *openVirtualDiskParameters, handle *syscall.Handle) (err error) [failretval != 0] = VirtDisk.OpenVirtualDisk
//sys detachVirtualDisk(handle syscall.Handle, flags uint32, providerSpecificFlags uint32) (err error) [failretval != 0] = VirtDisk.DetachVirtualDisk
type virtualStorageType struct {
DeviceID uint32
VendorID [16]byte
}
type (
createVirtualDiskFlag uint32
VirtualDiskAccessMask uint32
VirtualDiskFlag uint32
)
const (
// Flags for creating a VHD (not exported)
createVirtualDiskFlagNone createVirtualDiskFlag = 0
createVirtualDiskFlagFullPhysicalAllocation createVirtualDiskFlag = 1
createVirtualDiskFlagPreventWritesToSourceDisk createVirtualDiskFlag = 2
createVirtualDiskFlagDoNotCopyMetadataFromParent createVirtualDiskFlag = 4
// Access Mask for opening a VHD
VirtualDiskAccessNone VirtualDiskAccessMask = 0
VirtualDiskAccessAttachRO VirtualDiskAccessMask = 65536
VirtualDiskAccessAttachRW VirtualDiskAccessMask = 131072
VirtualDiskAccessDetach VirtualDiskAccessMask = 262144
VirtualDiskAccessGetInfo VirtualDiskAccessMask = 524288
VirtualDiskAccessCreate VirtualDiskAccessMask = 1048576
VirtualDiskAccessMetaOps VirtualDiskAccessMask = 2097152
VirtualDiskAccessRead VirtualDiskAccessMask = 851968
VirtualDiskAccessAll VirtualDiskAccessMask = 4128768
VirtualDiskAccessWritable VirtualDiskAccessMask = 3276800
// Flags for opening a VHD
OpenVirtualDiskFlagNone VirtualDiskFlag = 0
OpenVirtualDiskFlagNoParents VirtualDiskFlag = 0x1
OpenVirtualDiskFlagBlankFile VirtualDiskFlag = 0x2
OpenVirtualDiskFlagBootDrive VirtualDiskFlag = 0x4
OpenVirtualDiskFlagCachedIO VirtualDiskFlag = 0x8
OpenVirtualDiskFlagCustomDiffChain VirtualDiskFlag = 0x10
OpenVirtualDiskFlagParentCachedIO VirtualDiskFlag = 0x20
OpenVirtualDiskFlagVhdSetFileOnly VirtualDiskFlag = 0x40
OpenVirtualDiskFlagIgnoreRelativeParentLocator VirtualDiskFlag = 0x80
OpenVirtualDiskFlagNoWriteHardening VirtualDiskFlag = 0x100
)
type createVersion2 struct {
UniqueID [16]byte // GUID
MaximumSize uint64
BlockSizeInBytes uint32
SectorSizeInBytes uint32
ParentPath *uint16 // string
SourcePath *uint16 // string
OpenFlags uint32
ParentVirtualStorageType virtualStorageType
SourceVirtualStorageType virtualStorageType
ResiliencyGUID [16]byte // GUID
}
type createVirtualDiskParameters struct {
Version uint32 // Must always be set to 2
Version2 createVersion2
}
type openVersion2 struct {
GetInfoOnly int32 // bool but 4-byte aligned
ReadOnly int32 // bool but 4-byte aligned
ResiliencyGUID [16]byte // GUID
}
type openVirtualDiskParameters struct {
Version uint32 // Must always be set to 2
Version2 openVersion2
}
// CreateVhdx will create a simple vhdx file at the given path using default values.
func CreateVhdx(path string, maxSizeInGb, blockSizeInMb uint32) error {
var (
defaultType virtualStorageType
handle syscall.Handle
)
parameters := createVirtualDiskParameters{
Version: 2,
Version2: createVersion2{
MaximumSize: uint64(maxSizeInGb) * 1024 * 1024 * 1024,
BlockSizeInBytes: blockSizeInMb * 1024 * 1024,
},
}
if err := createVirtualDisk(
&defaultType,
path,
uint32(VirtualDiskAccessNone),
nil,
uint32(createVirtualDiskFlagNone),
0,
&parameters,
nil,
&handle); err != nil {
return err
}
if err := syscall.CloseHandle(handle); err != nil {
return err
}
return nil
}
// DetachVhd detaches a mounted container layer vhd found at `path`.
func DetachVhd(path string) error {
handle, err := OpenVirtualDisk(
path,
VirtualDiskAccessNone,
OpenVirtualDiskFlagCachedIO|OpenVirtualDiskFlagIgnoreRelativeParentLocator)
if err != nil {
return err
}
defer syscall.CloseHandle(handle)
return detachVirtualDisk(handle, 0, 0)
}
// OpenVirtualDisk obtains a handle to a VHD opened with supplied access mask and flags.
func OpenVirtualDisk(path string, accessMask VirtualDiskAccessMask, flag VirtualDiskFlag) (syscall.Handle, error) {
var (
defaultType virtualStorageType
handle syscall.Handle
)
parameters := openVirtualDiskParameters{Version: 2}
if err := openVirtualDisk(
&defaultType,
path,
uint32(accessMask),
uint32(flag),
&parameters,
&handle); err != nil {
return 0, err
}
return handle, nil
}

99
vendor/github.com/Microsoft/go-winio/vhd/zvhd.go generated vendored Normal file
View File

@ -0,0 +1,99 @@
// MACHINE GENERATED BY 'go generate' COMMAND; DO NOT EDIT
package vhd
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 (
modVirtDisk = windows.NewLazySystemDLL("VirtDisk.dll")
procCreateVirtualDisk = modVirtDisk.NewProc("CreateVirtualDisk")
procOpenVirtualDisk = modVirtDisk.NewProc("OpenVirtualDisk")
procDetachVirtualDisk = modVirtDisk.NewProc("DetachVirtualDisk")
)
func createVirtualDisk(virtualStorageType *virtualStorageType, path string, virtualDiskAccessMask uint32, securityDescriptor *uintptr, flags uint32, providerSpecificFlags uint32, parameters *createVirtualDiskParameters, o *syscall.Overlapped, handle *syscall.Handle) (err error) {
var _p0 *uint16
_p0, err = syscall.UTF16PtrFromString(path)
if err != nil {
return
}
return _createVirtualDisk(virtualStorageType, _p0, virtualDiskAccessMask, securityDescriptor, flags, providerSpecificFlags, parameters, o, handle)
}
func _createVirtualDisk(virtualStorageType *virtualStorageType, path *uint16, virtualDiskAccessMask uint32, securityDescriptor *uintptr, flags uint32, providerSpecificFlags uint32, parameters *createVirtualDiskParameters, o *syscall.Overlapped, handle *syscall.Handle) (err error) {
r1, _, e1 := syscall.Syscall9(procCreateVirtualDisk.Addr(), 9, uintptr(unsafe.Pointer(virtualStorageType)), uintptr(unsafe.Pointer(path)), uintptr(virtualDiskAccessMask), uintptr(unsafe.Pointer(securityDescriptor)), uintptr(flags), uintptr(providerSpecificFlags), uintptr(unsafe.Pointer(parameters)), uintptr(unsafe.Pointer(o)), uintptr(unsafe.Pointer(handle)))
if r1 != 0 {
if e1 != 0 {
err = errnoErr(e1)
} else {
err = syscall.EINVAL
}
}
return
}
func openVirtualDisk(virtualStorageType *virtualStorageType, path string, virtualDiskAccessMask uint32, flags uint32, parameters *openVirtualDiskParameters, handle *syscall.Handle) (err error) {
var _p0 *uint16
_p0, err = syscall.UTF16PtrFromString(path)
if err != nil {
return
}
return _openVirtualDisk(virtualStorageType, _p0, virtualDiskAccessMask, flags, parameters, handle)
}
func _openVirtualDisk(virtualStorageType *virtualStorageType, path *uint16, virtualDiskAccessMask uint32, flags uint32, parameters *openVirtualDiskParameters, handle *syscall.Handle) (err error) {
r1, _, e1 := syscall.Syscall6(procOpenVirtualDisk.Addr(), 6, uintptr(unsafe.Pointer(virtualStorageType)), uintptr(unsafe.Pointer(path)), uintptr(virtualDiskAccessMask), uintptr(flags), uintptr(unsafe.Pointer(parameters)), uintptr(unsafe.Pointer(handle)))
if r1 != 0 {
if e1 != 0 {
err = errnoErr(e1)
} else {
err = syscall.EINVAL
}
}
return
}
func detachVirtualDisk(handle syscall.Handle, flags uint32, providerSpecificFlags uint32) (err error) {
r1, _, e1 := syscall.Syscall(procDetachVirtualDisk.Addr(), 3, uintptr(handle), uintptr(flags), uintptr(providerSpecificFlags))
if r1 != 0 {
if e1 != 0 {
err = errnoErr(e1)
} else {
err = syscall.EINVAL
}
}
return
}

View File

@ -2,7 +2,7 @@
[![Build status](https://ci.appveyor.com/api/projects/status/nbcw28mnkqml0loa/branch/master?svg=true)](https://ci.appveyor.com/project/WindowsVirtualization/hcsshim/branch/master) [![Build status](https://ci.appveyor.com/api/projects/status/nbcw28mnkqml0loa/branch/master?svg=true)](https://ci.appveyor.com/project/WindowsVirtualization/hcsshim/branch/master)
This package contains the Golang interface for using the Windows [Host Compute Service](https://blogs.technet.microsoft.com/virtualization/2017/01/27/introducing-the-host-compute-service-hcs/) (HCS) to launch and manage [Windows Containers](https://docs.microsoft.com/en-us/virtualization/windowscontainers/about/). It also contains other helpers and functions for managing Windows Containers such as the Golang interface for the Host Network Service (HNS). This package contains the Golang interface for using the Windows [Host Compute Service](https://techcommunity.microsoft.com/t5/containers/introducing-the-host-compute-service-hcs/ba-p/382332) (HCS) to launch and manage [Windows Containers](https://docs.microsoft.com/en-us/virtualization/windowscontainers/about/). It also contains other helpers and functions for managing Windows Containers such as the Golang interface for the Host Network Service (HNS).
It is primarily used in the [Moby Project](https://github.com/moby/moby), but it can be freely used by other projects as well. It is primarily used in the [Moby Project](https://github.com/moby/moby), but it can be freely used by other projects as well.
@ -16,6 +16,11 @@ When you submit a pull request, a CLA-bot will automatically determine whether y
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA. provided by the bot. You will only need to do this once across all repos using our CLA.
We also ask that contributors [sign their commits](https://git-scm.com/docs/git-commit) using `git commit -s` or `git commit --signoff` to certify they either authored the work themselves or otherwise have permission to use it in this project.
## Code of Conduct
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

View File

@ -4,34 +4,32 @@ go 1.13
require ( require (
github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5 github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5
github.com/blang/semver v3.1.0+incompatible // indirect
github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f
github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1 github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1
github.com/containerd/containerd v1.3.0-beta.2.0.20190828155532-0293cbd26c69 github.com/containerd/containerd v1.3.2
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc // indirect github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc // indirect
github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448 // indirect github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448 // indirect
github.com/containerd/go-runc v0.0.0-20180907222934-5a6d9f37cfa3 github.com/containerd/go-runc v0.0.0-20180907222934-5a6d9f37cfa3
github.com/containerd/ttrpc v0.0.0-20190828154514-0e0f228740de github.com/containerd/ttrpc v0.0.0-20190828154514-0e0f228740de
github.com/containerd/typeurl v0.0.0-20180627222232-a93fcdb778cd github.com/containerd/typeurl v0.0.0-20180627222232-a93fcdb778cd
github.com/gogo/protobuf v1.2.1 github.com/gogo/protobuf v1.3.1
github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce // indirect github.com/golang/protobuf v1.3.2 // indirect
github.com/hashicorp/go-multierror v0.0.0-20161216184304-ed905158d874 // indirect github.com/kr/pretty v0.1.0 // indirect
github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2 // indirect github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2 // indirect
github.com/opencontainers/runc v0.0.0-20190115041553-12f6a991201f // indirect github.com/opencontainers/runc v0.0.0-20190115041553-12f6a991201f // indirect
github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700 github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700
github.com/opencontainers/runtime-tools v0.0.0-20181011054405-1d69bd0f9c39
github.com/pkg/errors v0.8.1 github.com/pkg/errors v0.8.1
github.com/prometheus/procfs v0.0.5 // indirect github.com/prometheus/procfs v0.0.0-20180125133057-cb4147076ac7 // indirect
github.com/sirupsen/logrus v1.4.1 github.com/sirupsen/logrus v1.4.2
github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8 // indirect github.com/stretchr/testify v1.4.0 // indirect
github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5 github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f // indirect
go.opencensus.io v0.22.0 go.opencensus.io v0.22.0
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 // indirect
golang.org/x/sync v0.0.0-20190423024810-112230192c58
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3 golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3
google.golang.org/grpc v1.20.1 google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873 // indirect
google.golang.org/grpc v1.23.1
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
gotest.tools v2.2.0+incompatible // indirect gotest.tools v2.2.0+incompatible // indirect
k8s.io/kubernetes v1.13.0
) )

View File

@ -21,8 +21,11 @@ const (
OutboundNat = hns.OutboundNat OutboundNat = hns.OutboundNat
ExternalLoadBalancer = hns.ExternalLoadBalancer ExternalLoadBalancer = hns.ExternalLoadBalancer
Route = hns.Route Route = hns.Route
Proxy = hns.Proxy
) )
type ProxyPolicy = hns.ProxyPolicy
type NatPolicy = hns.NatPolicy type NatPolicy = hns.NatPolicy
type QosPolicy = hns.QosPolicy type QosPolicy = hns.QosPolicy

View File

@ -1,7 +0,0 @@
package hcs
import "C"
// This import is needed to make the library compile as CGO because HCSSHIM
// only works with CGO due to callbacks from HCS comming back from a C thread
// which is not supported without CGO. See https://github.com/golang/go/issues/10973

View File

@ -0,0 +1,5 @@
package hcs
//go:generate go run ../../mksyscall_windows.go -output zsyscall_windows.go syscall.go
//sys hcsFormatWritableLayerVhd(handle uintptr) (hr error) = computestorage.HcsFormatWritableLayerVhd

View File

@ -4,12 +4,9 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"errors" "errors"
"os"
"strconv"
"strings" "strings"
"sync" "sync"
"syscall" "syscall"
"time"
"github.com/Microsoft/hcsshim/internal/cow" "github.com/Microsoft/hcsshim/internal/cow"
"github.com/Microsoft/hcsshim/internal/log" "github.com/Microsoft/hcsshim/internal/log"
@ -21,27 +18,6 @@ import (
"go.opencensus.io/trace" "go.opencensus.io/trace"
) )
// 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() {
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
}
}
type System struct { type System struct {
handleLock sync.RWMutex handleLock sync.RWMutex
handle vmcompute.HcsSystem handle vmcompute.HcsSystem
@ -215,32 +191,6 @@ func (computeSystem *System) Start(ctx context.Context) (err error) {
return makeSystemError(computeSystem, operation, "", ErrAlreadyClosed, nil) return makeSystemError(computeSystem, operation, "", ErrAlreadyClosed, nil)
} }
// 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()
}()
}
resultJSON, err := vmcompute.HcsStartComputeSystem(ctx, computeSystem.handle, "") resultJSON, err := vmcompute.HcsStartComputeSystem(ctx, computeSystem.handle, "")
events, err := processAsyncHcsResult(ctx, err, resultJSON, computeSystem.callbackNumber, hcsNotificationSystemStartCompleted, &timeout.SystemStart) events, err := processAsyncHcsResult(ctx, err, resultJSON, computeSystem.callbackNumber, hcsNotificationSystemStartCompleted, &timeout.SystemStart)
if err != nil { if err != nil {

View File

@ -1,10 +1,14 @@
package hcs package hcs
import ( import (
"context"
"io" "io"
"syscall" "syscall"
"github.com/Microsoft/go-winio" "github.com/Microsoft/go-winio"
diskutil "github.com/Microsoft/go-winio/vhd"
"github.com/pkg/errors"
"golang.org/x/sys/windows"
) )
// makeOpenFiles calls winio.MakeOpenFile for each handle in a slice but closes all the handles // makeOpenFiles calls winio.MakeOpenFile for each handle in a slice but closes all the handles
@ -31,3 +35,27 @@ func makeOpenFiles(hs []syscall.Handle) (_ []io.ReadWriteCloser, err error) {
} }
return fs, nil return fs, nil
} }
// creates a VHD formatted with NTFS of size `sizeGB` at the given `vhdPath`.
func CreateNTFSVHD(ctx context.Context, vhdPath string, sizeGB uint32) (err error) {
if err := diskutil.CreateVhdx(vhdPath, sizeGB, 1); err != nil {
return errors.Wrap(err, "failed to create VHD")
}
vhd, err := diskutil.OpenVirtualDisk(vhdPath, diskutil.VirtualDiskAccessNone, diskutil.OpenVirtualDiskFlagNone)
if err != nil {
return errors.Wrap(err, "failed to open VHD")
}
defer func() {
err2 := windows.CloseHandle(windows.Handle(vhd))
if err == nil {
err = errors.Wrap(err2, "failed to close VHD")
}
}()
if err := hcsFormatWritableLayerVhd(uintptr(vhd)); err != nil {
return errors.Wrap(err, "failed to format VHD")
}
return nil
}

View File

@ -0,0 +1,54 @@
// 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 (
modcomputestorage = windows.NewLazySystemDLL("computestorage.dll")
procHcsFormatWritableLayerVhd = modcomputestorage.NewProc("HcsFormatWritableLayerVhd")
)
func hcsFormatWritableLayerVhd(handle uintptr) (hr error) {
r0, _, _ := syscall.Syscall(procHcsFormatWritableLayerVhd.Addr(), 1, uintptr(handle), 0, 0)
if int32(r0) < 0 {
if r0&0x1fff0000 == 0x00070000 {
r0 &= 0xffff
}
hr = syscall.Errno(r0)
}
return
}

View File

@ -173,6 +173,27 @@ func (endpoint *HNSEndpoint) ApplyACLPolicy(policies ...*ACLPolicy) error {
return err return err
} }
// ApplyProxyPolicy applies a set of Proxy Policies on the Endpoint
func (endpoint *HNSEndpoint) ApplyProxyPolicy(policies ...*ProxyPolicy) error {
operation := "ApplyProxyPolicy"
title := "hcsshim::HNSEndpoint::" + operation
logrus.Debugf(title+" id=%s", endpoint.Id)
for _, policy := range policies {
if policy == nil {
continue
}
jsonString, err := json.Marshal(policy)
if err != nil {
return err
}
endpoint.Policies = append(endpoint.Policies, jsonString)
}
_, err := endpoint.Update()
return err
}
// ContainerAttach attaches an endpoint to container // ContainerAttach attaches an endpoint to container
func (endpoint *HNSEndpoint) ContainerAttach(containerID string, compartmentID uint16) error { func (endpoint *HNSEndpoint) ContainerAttach(containerID string, compartmentID uint16) error {
operation := "ContainerAttach" operation := "ContainerAttach"

View File

@ -17,6 +17,7 @@ const (
OutboundNat PolicyType = "OutBoundNAT" OutboundNat PolicyType = "OutBoundNAT"
ExternalLoadBalancer PolicyType = "ELB" ExternalLoadBalancer PolicyType = "ELB"
Route PolicyType = "ROUTE" Route PolicyType = "ROUTE"
Proxy PolicyType = "PROXY"
) )
type NatPolicy struct { type NatPolicy struct {
@ -60,6 +61,15 @@ type OutboundNatPolicy struct {
Destinations []string `json:",omitempty"` Destinations []string `json:",omitempty"`
} }
type ProxyPolicy struct {
Type PolicyType `json:"Type"`
IP string `json:",omitempty"`
Port string `json:",omitempty"`
ExceptionList []string `json:",omitempty"`
Destination string `json:",omitempty"`
OutboundNat bool `json:",omitempty"`
}
type ActionType string type ActionType string
type DirectionType string type DirectionType string
type RuleType string type RuleType string

View File

@ -214,9 +214,10 @@ type MappedVirtualDiskController struct {
// GuestDefinedCapabilities is part of the GuestConnectionInfo returned by a GuestConnection call on a utility VM // GuestDefinedCapabilities is part of the GuestConnectionInfo returned by a GuestConnection call on a utility VM
type GuestDefinedCapabilities struct { type GuestDefinedCapabilities struct {
NamespaceAddRequestSupported bool `json:",omitempty"` NamespaceAddRequestSupported bool `json:",omitempty"`
SignalProcessSupported bool `json:",omitempty"` SignalProcessSupported bool `json:",omitempty"`
DumpStacksSupported bool `json:",omitempty"` DumpStacksSupported bool `json:",omitempty"`
DeleteContainerStateSupported bool `json:",omitempty"`
} }
// GuestConnectionInfo is the structure of an iterm return by a GuestConnection call on a utility VM // GuestConnectionInfo is the structure of an iterm return by a GuestConnection call on a utility VM

View File

@ -39,4 +39,8 @@ type Devices struct {
FlexibleIov map[string]FlexibleIoDevice `json:"FlexibleIov,omitempty"` FlexibleIov map[string]FlexibleIoDevice `json:"FlexibleIov,omitempty"`
SharedMemory *SharedMemoryConfiguration `json:"SharedMemory,omitempty"` SharedMemory *SharedMemoryConfiguration `json:"SharedMemory,omitempty"`
// TODO: This is pre-release support in schema 2.3. Need to add build number
// docs when a public build with this is out.
VirtualPci map[string]VirtualPciDevice `json:",omitempty"`
} }

View File

@ -27,4 +27,23 @@ type Memory2 struct {
// to the VM, allowing it to trim non-zeroed pages from the working set (if supported by // to the VM, allowing it to trim non-zeroed pages from the working set (if supported by
// the guest operating system). // the guest operating system).
EnableColdDiscardHint bool `json:"EnableColdDiscardHint,omitempty"` EnableColdDiscardHint bool `json:"EnableColdDiscardHint,omitempty"`
// LowMmioGapInMB is the low MMIO region allocated below 4GB.
//
// TODO: This is pre-release support in schema 2.3. Need to add build number
// docs when a public build with this is out.
LowMMIOGapInMB uint64 `json:"LowMmioGapInMB,omitempty"`
// HighMmioBaseInMB is the high MMIO region allocated above 4GB (base and
// size).
//
// TODO: This is pre-release support in schema 2.3. Need to add build number
// docs when a public build with this is out.
HighMMIOBaseInMB uint64 `json:"HighMmioBaseInMB,omitempty"`
// HighMmioGapInMB is the high MMIO region.
//
// TODO: This is pre-release support in schema 2.3. Need to add build number
// docs when a public build with this is out.
HighMMIOGapInMB uint64 `json:"HighMmioGapInMB,omitempty"`
} }

View File

@ -0,0 +1,16 @@
/*
* HCS API
*
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* API version: 2.3
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package hcsschema
// TODO: This is pre-release support in schema 2.3. Need to add build number
// docs when a public build with this is out.
type VirtualPciDevice struct {
Functions []VirtualPciFunction `json:",omitempty"`
}

View File

@ -0,0 +1,18 @@
/*
* HCS API
*
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* API version: 2.3
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package hcsschema
// TODO: This is pre-release support in schema 2.3. Need to add build number
// docs when a public build with this is out.
type VirtualPciFunction struct {
DeviceInstancePath string `json:",omitempty"`
VirtualFunction uint16 `json:",omitempty"`
}

View File

@ -1,28 +1,23 @@
package wclayer package wclayer
import ( import (
"context"
"github.com/Microsoft/hcsshim/internal/hcserror" "github.com/Microsoft/hcsshim/internal/hcserror"
"github.com/sirupsen/logrus" "github.com/Microsoft/hcsshim/internal/oc"
"go.opencensus.io/trace"
) )
// ActivateLayer will find the layer with the given id and mount it's filesystem. // ActivateLayer will find the layer with the given id and mount it's filesystem.
// For a read/write layer, the mounted filesystem will appear as a volume on the // For a read/write layer, the mounted filesystem will appear as a volume on the
// host, while a read-only layer is generally expected to be a no-op. // host, while a read-only layer is generally expected to be a no-op.
// An activated layer must later be deactivated via DeactivateLayer. // An activated layer must later be deactivated via DeactivateLayer.
func ActivateLayer(path string) (err error) { func ActivateLayer(ctx context.Context, path string) (err error) {
title := "hcsshim::ActivateLayer" title := "hcsshim::ActivateLayer"
fields := logrus.Fields{ ctx, span := trace.StartSpan(ctx, title)
"path": path, defer span.End()
} defer func() { oc.SetSpanStatus(span, err) }()
logrus.WithFields(fields).Debug(title) span.AddAttributes(trace.StringAttribute("path", path))
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
err = activateLayer(&stdDriverInfo, path) err = activateLayer(&stdDriverInfo, path)
if err != nil { if err != nil {

View File

@ -1,6 +1,7 @@
package wclayer package wclayer
import ( import (
"context"
"errors" "errors"
"os" "os"
"path/filepath" "path/filepath"
@ -8,10 +9,15 @@ import (
"github.com/Microsoft/go-winio" "github.com/Microsoft/go-winio"
"github.com/Microsoft/hcsshim/internal/hcserror" "github.com/Microsoft/hcsshim/internal/hcserror"
"github.com/Microsoft/hcsshim/internal/oc"
"github.com/Microsoft/hcsshim/internal/safefile" "github.com/Microsoft/hcsshim/internal/safefile"
"go.opencensus.io/trace"
) )
type baseLayerWriter struct { type baseLayerWriter struct {
ctx context.Context
s *trace.Span
root *os.File root *os.File
f *os.File f *os.File
bw *winio.BackupFileWriter bw *winio.BackupFileWriter
@ -136,12 +142,15 @@ func (w *baseLayerWriter) Write(b []byte) (int, error) {
return n, err return n, err
} }
func (w *baseLayerWriter) Close() error { func (w *baseLayerWriter) Close() (err error) {
defer w.s.End()
defer func() { oc.SetSpanStatus(w.s, err) }()
defer func() { defer func() {
w.root.Close() w.root.Close()
w.root = nil w.root = nil
}() }()
err := w.closeCurrentFile()
err = w.closeCurrentFile()
if err != nil { if err != nil {
return err return err
} }
@ -153,7 +162,7 @@ func (w *baseLayerWriter) Close() error {
return err return err
} }
err = ProcessBaseLayer(w.root.Name()) err = ProcessBaseLayer(w.ctx, w.root.Name())
if err != nil { if err != nil {
return err return err
} }
@ -163,7 +172,7 @@ func (w *baseLayerWriter) Close() error {
if err != nil { if err != nil {
return err return err
} }
err = ProcessUtilityVMImage(filepath.Join(w.root.Name(), "UtilityVM")) err = ProcessUtilityVMImage(w.ctx, filepath.Join(w.root.Name(), "UtilityVM"))
if err != nil { if err != nil {
return err return err
} }

View File

@ -1,27 +1,23 @@
package wclayer package wclayer
import ( import (
"context"
"github.com/Microsoft/hcsshim/internal/hcserror" "github.com/Microsoft/hcsshim/internal/hcserror"
"github.com/sirupsen/logrus" "github.com/Microsoft/hcsshim/internal/oc"
"go.opencensus.io/trace"
) )
// CreateLayer creates a new, empty, read-only layer on the filesystem based on // CreateLayer creates a new, empty, read-only layer on the filesystem based on
// the parent layer provided. // the parent layer provided.
func CreateLayer(path, parent string) (err error) { func CreateLayer(ctx context.Context, path, parent string) (err error) {
title := "hcsshim::CreateLayer" title := "hcsshim::CreateLayer"
fields := logrus.Fields{ ctx, span := trace.StartSpan(ctx, title)
"parent": parent, defer span.End()
"path": path, defer func() { oc.SetSpanStatus(span, err) }()
} span.AddAttributes(
logrus.WithFields(fields).Debug(title) trace.StringAttribute("path", path),
defer func() { trace.StringAttribute("parent", parent))
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
err = createLayer(&stdDriverInfo, path, parent) err = createLayer(&stdDriverInfo, path, parent)
if err != nil { if err != nil {

View File

@ -1,31 +1,29 @@
package wclayer package wclayer
import ( import (
"context"
"strings"
"github.com/Microsoft/hcsshim/internal/hcserror" "github.com/Microsoft/hcsshim/internal/hcserror"
"github.com/sirupsen/logrus" "github.com/Microsoft/hcsshim/internal/oc"
"go.opencensus.io/trace"
) )
// CreateScratchLayer creates and populates new read-write layer for use by a container. // CreateScratchLayer creates and populates new read-write layer for use by a container.
// This requires both the id of the direct parent layer, as well as the full list // This requires both the id of the direct parent layer, as well as the full list
// of paths to all parent layers up to the base (and including the direct parent // of paths to all parent layers up to the base (and including the direct parent
// whose id was provided). // whose id was provided).
func CreateScratchLayer(path string, parentLayerPaths []string) (err error) { func CreateScratchLayer(ctx context.Context, path string, parentLayerPaths []string) (err error) {
title := "hcsshim::CreateScratchLayer" title := "hcsshim::CreateScratchLayer"
fields := logrus.Fields{ ctx, span := trace.StartSpan(ctx, title)
"path": path, defer span.End()
} defer func() { oc.SetSpanStatus(span, err) }()
logrus.WithFields(fields).Debug(title) span.AddAttributes(
defer func() { trace.StringAttribute("path", path),
if err != nil { trace.StringAttribute("parentLayerPaths", strings.Join(parentLayerPaths, ", ")))
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
// Generate layer descriptors // Generate layer descriptors
layers, err := layerPathsToDescriptors(parentLayerPaths) layers, err := layerPathsToDescriptors(ctx, parentLayerPaths)
if err != nil { if err != nil {
return err return err
} }

View File

@ -1,25 +1,20 @@
package wclayer package wclayer
import ( import (
"context"
"github.com/Microsoft/hcsshim/internal/hcserror" "github.com/Microsoft/hcsshim/internal/hcserror"
"github.com/sirupsen/logrus" "github.com/Microsoft/hcsshim/internal/oc"
"go.opencensus.io/trace"
) )
// DeactivateLayer will dismount a layer that was mounted via ActivateLayer. // DeactivateLayer will dismount a layer that was mounted via ActivateLayer.
func DeactivateLayer(path string) (err error) { func DeactivateLayer(ctx context.Context, path string) (err error) {
title := "hcsshim::DeactivateLayer" title := "hcsshim::DeactivateLayer"
fields := logrus.Fields{ ctx, span := trace.StartSpan(ctx, title)
"path": path, defer span.End()
} defer func() { oc.SetSpanStatus(span, err) }()
logrus.WithFields(fields).Debug(title) span.AddAttributes(trace.StringAttribute("path", path))
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
err = deactivateLayer(&stdDriverInfo, path) err = deactivateLayer(&stdDriverInfo, path)
if err != nil { if err != nil {

View File

@ -1,26 +1,21 @@
package wclayer package wclayer
import ( import (
"context"
"github.com/Microsoft/hcsshim/internal/hcserror" "github.com/Microsoft/hcsshim/internal/hcserror"
"github.com/sirupsen/logrus" "github.com/Microsoft/hcsshim/internal/oc"
"go.opencensus.io/trace"
) )
// DestroyLayer will remove the on-disk files representing the layer with the given // DestroyLayer will remove the on-disk files representing the layer with the given
// path, including that layer's containing folder, if any. // path, including that layer's containing folder, if any.
func DestroyLayer(path string) (err error) { func DestroyLayer(ctx context.Context, path string) (err error) {
title := "hcsshim::DestroyLayer" title := "hcsshim::DestroyLayer"
fields := logrus.Fields{ ctx, span := trace.StartSpan(ctx, title)
"path": path, defer span.End()
} defer func() { oc.SetSpanStatus(span, err) }()
logrus.WithFields(fields).Debug(title) span.AddAttributes(trace.StringAttribute("path", path))
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
err = destroyLayer(&stdDriverInfo, path) err = destroyLayer(&stdDriverInfo, path)
if err != nil { if err != nil {

View File

@ -1,32 +1,27 @@
package wclayer package wclayer
import ( import (
"context"
"os" "os"
"path/filepath" "path/filepath"
"syscall" "syscall"
"unsafe" "unsafe"
"github.com/Microsoft/hcsshim/internal/hcserror" "github.com/Microsoft/hcsshim/internal/hcserror"
"github.com/Microsoft/hcsshim/internal/oc"
"github.com/Microsoft/hcsshim/osversion" "github.com/Microsoft/hcsshim/osversion"
"github.com/sirupsen/logrus" "go.opencensus.io/trace"
) )
// ExpandScratchSize expands the size of a layer to at least size bytes. // ExpandScratchSize expands the size of a layer to at least size bytes.
func ExpandScratchSize(path string, size uint64) (err error) { func ExpandScratchSize(ctx context.Context, path string, size uint64) (err error) {
title := "hcsshim::ExpandScratchSize" title := "hcsshim::ExpandScratchSize"
fields := logrus.Fields{ ctx, span := trace.StartSpan(ctx, title)
"path": path, defer span.End()
"size": size, defer func() { oc.SetSpanStatus(span, err) }()
} span.AddAttributes(
logrus.WithFields(fields).Debug(title) trace.StringAttribute("path", path),
defer func() { trace.Int64Attribute("size", int64(size)))
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
err = expandSandboxSize(&stdDriverInfo, path, size) err = expandSandboxSize(&stdDriverInfo, path, size)
if err != nil { if err != nil {
@ -36,7 +31,7 @@ func ExpandScratchSize(path string, size uint64) (err error) {
// Manually expand the volume now in order to work around bugs in 19H1 and // Manually expand the volume now in order to work around bugs in 19H1 and
// prerelease versions of Vb. Remove once this is fixed in Windows. // prerelease versions of Vb. Remove once this is fixed in Windows.
if build := osversion.Get().Build; build >= osversion.V19H1 && build < 19020 { if build := osversion.Get().Build; build >= osversion.V19H1 && build < 19020 {
err = expandSandboxVolume(path) err = expandSandboxVolume(ctx, path)
if err != nil { if err != nil {
return err return err
} }
@ -84,7 +79,7 @@ func attachVhd(path string) (syscall.Handle, error) {
return handle, nil return handle, nil
} }
func expandSandboxVolume(path string) error { func expandSandboxVolume(ctx context.Context, path string) error {
// Mount the sandbox VHD temporarily. // Mount the sandbox VHD temporarily.
vhdPath := filepath.Join(path, "sandbox.vhdx") vhdPath := filepath.Join(path, "sandbox.vhdx")
vhd, err := attachVhd(vhdPath) vhd, err := attachVhd(vhdPath)
@ -94,7 +89,7 @@ func expandSandboxVolume(path string) error {
defer syscall.Close(vhd) defer syscall.Close(vhd)
// Open the volume. // Open the volume.
volumePath, err := GetLayerMountPath(path) volumePath, err := GetLayerMountPath(ctx, path)
if err != nil { if err != nil {
return err return err
} }

View File

@ -1,12 +1,15 @@
package wclayer package wclayer
import ( import (
"context"
"io/ioutil" "io/ioutil"
"os" "os"
"strings"
"github.com/Microsoft/go-winio" "github.com/Microsoft/go-winio"
"github.com/Microsoft/hcsshim/internal/hcserror" "github.com/Microsoft/hcsshim/internal/hcserror"
"github.com/sirupsen/logrus" "github.com/Microsoft/hcsshim/internal/oc"
"go.opencensus.io/trace"
) )
// ExportLayer will create a folder at exportFolderPath and fill that folder with // ExportLayer will create a folder at exportFolderPath and fill that folder with
@ -14,24 +17,18 @@ import (
// format includes any metadata required for later importing the layer (using // format includes any metadata required for later importing the layer (using
// ImportLayer), and requires the full list of parent layer paths in order to // ImportLayer), and requires the full list of parent layer paths in order to
// perform the export. // perform the export.
func ExportLayer(path string, exportFolderPath string, parentLayerPaths []string) (err error) { func ExportLayer(ctx context.Context, path string, exportFolderPath string, parentLayerPaths []string) (err error) {
title := "hcsshim::ExportLayer" title := "hcsshim::ExportLayer"
fields := logrus.Fields{ ctx, span := trace.StartSpan(ctx, title)
"path": path, defer span.End()
"exportFolderPath": exportFolderPath, defer func() { oc.SetSpanStatus(span, err) }()
} span.AddAttributes(
logrus.WithFields(fields).Debug(title) trace.StringAttribute("path", path),
defer func() { trace.StringAttribute("exportFolderPath", exportFolderPath),
if err != nil { trace.StringAttribute("parentLayerPaths", strings.Join(parentLayerPaths, ", ")))
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
// Generate layer descriptors // Generate layer descriptors
layers, err := layerPathsToDescriptors(parentLayerPaths) layers, err := layerPathsToDescriptors(ctx, parentLayerPaths)
if err != nil { if err != nil {
return err return err
} }
@ -52,25 +49,46 @@ type LayerReader interface {
// NewLayerReader returns a new layer reader for reading the contents of an on-disk layer. // NewLayerReader returns a new layer reader for reading the contents of an on-disk layer.
// The caller must have taken the SeBackupPrivilege privilege // The caller must have taken the SeBackupPrivilege privilege
// to call this and any methods on the resulting LayerReader. // to call this and any methods on the resulting LayerReader.
func NewLayerReader(path string, parentLayerPaths []string) (LayerReader, error) { func NewLayerReader(ctx context.Context, path string, parentLayerPaths []string) (_ LayerReader, err error) {
ctx, span := trace.StartSpan(ctx, "hcsshim::NewLayerReader")
defer func() {
if err != nil {
oc.SetSpanStatus(span, err)
span.End()
}
}()
span.AddAttributes(
trace.StringAttribute("path", path),
trace.StringAttribute("parentLayerPaths", strings.Join(parentLayerPaths, ", ")))
exportPath, err := ioutil.TempDir("", "hcs") exportPath, err := ioutil.TempDir("", "hcs")
if err != nil { if err != nil {
return nil, err return nil, err
} }
err = ExportLayer(path, exportPath, parentLayerPaths) err = ExportLayer(ctx, path, exportPath, parentLayerPaths)
if err != nil { if err != nil {
os.RemoveAll(exportPath) os.RemoveAll(exportPath)
return nil, err return nil, err
} }
return &legacyLayerReaderWrapper{newLegacyLayerReader(exportPath)}, nil return &legacyLayerReaderWrapper{
ctx: ctx,
s: span,
legacyLayerReader: newLegacyLayerReader(exportPath),
}, nil
} }
type legacyLayerReaderWrapper struct { type legacyLayerReaderWrapper struct {
ctx context.Context
s *trace.Span
*legacyLayerReader *legacyLayerReader
} }
func (r *legacyLayerReaderWrapper) Close() error { func (r *legacyLayerReaderWrapper) Close() (err error) {
err := r.legacyLayerReader.Close() defer r.s.End()
defer func() { oc.SetSpanStatus(r.s, err) }()
err = r.legacyLayerReader.Close()
os.RemoveAll(r.root) os.RemoveAll(r.root)
return err return err
} }

View File

@ -1,36 +1,31 @@
package wclayer package wclayer
import ( import (
"context"
"syscall" "syscall"
"github.com/Microsoft/hcsshim/internal/hcserror" "github.com/Microsoft/hcsshim/internal/hcserror"
"github.com/sirupsen/logrus" "github.com/Microsoft/hcsshim/internal/log"
"github.com/Microsoft/hcsshim/internal/oc"
"go.opencensus.io/trace"
) )
// GetLayerMountPath will look for a mounted layer with the given path and return // GetLayerMountPath will look for a mounted layer with the given path and return
// the path at which that layer can be accessed. This path may be a volume path // the path at which that layer can be accessed. This path may be a volume path
// if the layer is a mounted read-write layer, otherwise it is expected to be the // if the layer is a mounted read-write layer, otherwise it is expected to be the
// folder path at which the layer is stored. // folder path at which the layer is stored.
func GetLayerMountPath(path string) (_ string, err error) { func GetLayerMountPath(ctx context.Context, path string) (_ string, err error) {
title := "hcsshim::GetLayerMountPath" title := "hcsshim::GetLayerMountPath"
fields := logrus.Fields{ ctx, span := trace.StartSpan(ctx, title)
"path": path, defer span.End()
} defer func() { oc.SetSpanStatus(span, err) }()
logrus.WithFields(fields).Debug(title) span.AddAttributes(trace.StringAttribute("path", path))
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
var mountPathLength uintptr var mountPathLength uintptr
mountPathLength = 0 mountPathLength = 0
// Call the procedure itself. // Call the procedure itself.
logrus.WithFields(fields).Debug("Calling proc (1)") log.G(ctx).Debug("Calling proc (1)")
err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, nil) err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, nil)
if err != nil { if err != nil {
return "", hcserror.New(err, title+" - failed", "(first call)") return "", hcserror.New(err, title+" - failed", "(first call)")
@ -44,13 +39,13 @@ func GetLayerMountPath(path string) (_ string, err error) {
mountPathp[0] = 0 mountPathp[0] = 0
// Call the procedure again // Call the procedure again
logrus.WithFields(fields).Debug("Calling proc (2)") log.G(ctx).Debug("Calling proc (2)")
err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, &mountPathp[0]) err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, &mountPathp[0])
if err != nil { if err != nil {
return "", hcserror.New(err, title+" - failed", "(second call)") return "", hcserror.New(err, title+" - failed", "(second call)")
} }
mountPath := syscall.UTF16ToString(mountPathp[0:]) mountPath := syscall.UTF16ToString(mountPathp[0:])
fields["mountPath"] = mountPath span.AddAttributes(trace.StringAttribute("mountPath", mountPath))
return mountPath, nil return mountPath, nil
} }

View File

@ -1,29 +1,29 @@
package wclayer package wclayer
import ( import (
"context"
"github.com/Microsoft/hcsshim/internal/hcserror" "github.com/Microsoft/hcsshim/internal/hcserror"
"github.com/Microsoft/hcsshim/internal/interop" "github.com/Microsoft/hcsshim/internal/interop"
"github.com/sirupsen/logrus" "github.com/Microsoft/hcsshim/internal/oc"
"go.opencensus.io/trace"
) )
// GetSharedBaseImages will enumerate the images stored in the common central // GetSharedBaseImages will enumerate the images stored in the common central
// image store and return descriptive info about those images for the purpose // image store and return descriptive info about those images for the purpose
// of registering them with the graphdriver, graph, and tagstore. // of registering them with the graphdriver, graph, and tagstore.
func GetSharedBaseImages() (imageData string, err error) { func GetSharedBaseImages(ctx context.Context) (_ string, err error) {
title := "hcsshim::GetSharedBaseImages" title := "hcsshim::GetSharedBaseImages"
logrus.Debug(title) ctx, span := trace.StartSpan(ctx, title)
defer func() { defer span.End()
if err != nil { defer func() { oc.SetSpanStatus(span, err) }()
logrus.WithError(err).Error(err)
} else {
logrus.WithField("imageData", imageData).Debug(title + " - succeeded")
}
}()
var buffer *uint16 var buffer *uint16
err = getBaseImages(&buffer) err = getBaseImages(&buffer)
if err != nil { if err != nil {
return "", hcserror.New(err, title+" - failed", "") return "", hcserror.New(err, title+" - failed", "")
} }
return interop.ConvertAndFreeCoTaskMemString(buffer), nil imageData := interop.ConvertAndFreeCoTaskMemString(buffer)
span.AddAttributes(trace.StringAttribute("imageData", imageData))
return imageData, nil
} }

View File

@ -1,26 +1,22 @@
package wclayer package wclayer
import ( import (
"context"
"github.com/Microsoft/hcsshim/internal/hcserror" "github.com/Microsoft/hcsshim/internal/hcserror"
"github.com/sirupsen/logrus" "github.com/Microsoft/hcsshim/internal/oc"
"go.opencensus.io/trace"
) )
// GrantVmAccess adds access to a file for a given VM // GrantVmAccess adds access to a file for a given VM
func GrantVmAccess(vmid string, filepath string) (err error) { func GrantVmAccess(ctx context.Context, vmid string, filepath string) (err error) {
title := "hcsshim::GrantVmAccess" title := "hcsshim::GrantVmAccess"
fields := logrus.Fields{ ctx, span := trace.StartSpan(ctx, title)
"vm-id": vmid, defer span.End()
"path": filepath, defer func() { oc.SetSpanStatus(span, err) }()
} span.AddAttributes(
logrus.WithFields(fields).Debug(title) trace.StringAttribute("vm-id", vmid),
defer func() { trace.StringAttribute("path", filepath))
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
err = grantVmAccess(vmid, filepath) err = grantVmAccess(vmid, filepath)
if err != nil { if err != nil {

View File

@ -1,38 +1,35 @@
package wclayer package wclayer
import ( import (
"context"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"github.com/Microsoft/go-winio" "github.com/Microsoft/go-winio"
"github.com/Microsoft/hcsshim/internal/hcserror" "github.com/Microsoft/hcsshim/internal/hcserror"
"github.com/Microsoft/hcsshim/internal/oc"
"github.com/Microsoft/hcsshim/internal/safefile" "github.com/Microsoft/hcsshim/internal/safefile"
"github.com/sirupsen/logrus" "go.opencensus.io/trace"
) )
// ImportLayer will take the contents of the folder at importFolderPath and import // ImportLayer will take the contents of the folder at importFolderPath and import
// that into a layer with the id layerId. Note that in order to correctly populate // that into a layer with the id layerId. Note that in order to correctly populate
// the layer and interperet the transport format, all parent layers must already // the layer and interperet the transport format, all parent layers must already
// be present on the system at the paths provided in parentLayerPaths. // be present on the system at the paths provided in parentLayerPaths.
func ImportLayer(path string, importFolderPath string, parentLayerPaths []string) (err error) { func ImportLayer(ctx context.Context, path string, importFolderPath string, parentLayerPaths []string) (err error) {
title := "hcsshim::ImportLayer" title := "hcsshim::ImportLayer"
fields := logrus.Fields{ ctx, span := trace.StartSpan(ctx, title)
"path": path, defer span.End()
"importFolderPath": importFolderPath, defer func() { oc.SetSpanStatus(span, err) }()
} span.AddAttributes(
logrus.WithFields(fields).Debug(title) trace.StringAttribute("path", path),
defer func() { trace.StringAttribute("importFolderPath", importFolderPath),
if err != nil { trace.StringAttribute("parentLayerPaths", strings.Join(parentLayerPaths, ", ")))
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
// Generate layer descriptors // Generate layer descriptors
layers, err := layerPathsToDescriptors(parentLayerPaths) layers, err := layerPathsToDescriptors(ctx, parentLayerPaths)
if err != nil { if err != nil {
return err return err
} }
@ -60,20 +57,26 @@ type LayerWriter interface {
} }
type legacyLayerWriterWrapper struct { type legacyLayerWriterWrapper struct {
ctx context.Context
s *trace.Span
*legacyLayerWriter *legacyLayerWriter
path string path string
parentLayerPaths []string parentLayerPaths []string
} }
func (r *legacyLayerWriterWrapper) Close() error { func (r *legacyLayerWriterWrapper) Close() (err error) {
defer r.s.End()
defer func() { oc.SetSpanStatus(r.s, err) }()
defer os.RemoveAll(r.root.Name()) defer os.RemoveAll(r.root.Name())
defer r.legacyLayerWriter.CloseRoots() defer r.legacyLayerWriter.CloseRoots()
err := r.legacyLayerWriter.Close()
err = r.legacyLayerWriter.Close()
if err != nil { if err != nil {
return err return err
} }
if err = ImportLayer(r.destRoot.Name(), r.path, r.parentLayerPaths); err != nil { if err = ImportLayer(r.ctx, r.destRoot.Name(), r.path, r.parentLayerPaths); err != nil {
return err return err
} }
for _, name := range r.Tombstones { for _, name := range r.Tombstones {
@ -96,7 +99,7 @@ func (r *legacyLayerWriterWrapper) Close() error {
if err != nil { if err != nil {
return err return err
} }
err = ProcessUtilityVMImage(filepath.Join(r.destRoot.Name(), "UtilityVM")) err = ProcessUtilityVMImage(r.ctx, filepath.Join(r.destRoot.Name(), "UtilityVM"))
if err != nil { if err != nil {
return err return err
} }
@ -107,7 +110,18 @@ func (r *legacyLayerWriterWrapper) Close() error {
// NewLayerWriter returns a new layer writer for creating a layer on disk. // NewLayerWriter returns a new layer writer for creating a layer on disk.
// The caller must have taken the SeBackupPrivilege and SeRestorePrivilege privileges // The caller must have taken the SeBackupPrivilege and SeRestorePrivilege privileges
// to call this and any methods on the resulting LayerWriter. // to call this and any methods on the resulting LayerWriter.
func NewLayerWriter(path string, parentLayerPaths []string) (LayerWriter, error) { func NewLayerWriter(ctx context.Context, path string, parentLayerPaths []string) (_ LayerWriter, err error) {
ctx, span := trace.StartSpan(ctx, "hcsshim::NewLayerWriter")
defer func() {
if err != nil {
oc.SetSpanStatus(span, err)
span.End()
}
}()
span.AddAttributes(
trace.StringAttribute("path", path),
trace.StringAttribute("parentLayerPaths", strings.Join(parentLayerPaths, ", ")))
if len(parentLayerPaths) == 0 { if len(parentLayerPaths) == 0 {
// This is a base layer. It gets imported differently. // This is a base layer. It gets imported differently.
f, err := safefile.OpenRoot(path) f, err := safefile.OpenRoot(path)
@ -115,6 +129,8 @@ func NewLayerWriter(path string, parentLayerPaths []string) (LayerWriter, error)
return nil, err return nil, err
} }
return &baseLayerWriter{ return &baseLayerWriter{
ctx: ctx,
s: span,
root: f, root: f,
}, nil }, nil
} }
@ -128,6 +144,8 @@ func NewLayerWriter(path string, parentLayerPaths []string) (LayerWriter, error)
return nil, err return nil, err
} }
return &legacyLayerWriterWrapper{ return &legacyLayerWriterWrapper{
ctx: ctx,
s: span,
legacyLayerWriter: w, legacyLayerWriter: w,
path: importPath, path: importPath,
parentLayerPaths: parentLayerPaths, parentLayerPaths: parentLayerPaths,

View File

@ -1,26 +1,21 @@
package wclayer package wclayer
import ( import (
"context"
"github.com/Microsoft/hcsshim/internal/hcserror" "github.com/Microsoft/hcsshim/internal/hcserror"
"github.com/sirupsen/logrus" "github.com/Microsoft/hcsshim/internal/oc"
"go.opencensus.io/trace"
) )
// LayerExists will return true if a layer with the given id exists and is known // LayerExists will return true if a layer with the given id exists and is known
// to the system. // to the system.
func LayerExists(path string) (_ bool, err error) { func LayerExists(ctx context.Context, path string) (_ bool, err error) {
title := "hcsshim::LayerExists" title := "hcsshim::LayerExists"
fields := logrus.Fields{ ctx, span := trace.StartSpan(ctx, title)
"path": path, defer span.End()
} defer func() { oc.SetSpanStatus(span, err) }()
logrus.WithFields(fields).Debug(title) span.AddAttributes(trace.StringAttribute("path", path))
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
// Call the procedure itself. // Call the procedure itself.
var exists uint32 var exists uint32
@ -28,6 +23,6 @@ func LayerExists(path string) (_ bool, err error) {
if err != nil { if err != nil {
return false, hcserror.New(err, title+" - failed", "") return false, hcserror.New(err, title+" - failed", "")
} }
fields["layer-exists"] = exists != 0 span.AddAttributes(trace.BoolAttribute("layer-exists", exists != 0))
return exists != 0, nil return exists != 0, nil
} }

View File

@ -1,13 +1,22 @@
package wclayer package wclayer
import ( import (
"context"
"path/filepath" "path/filepath"
"github.com/Microsoft/go-winio/pkg/guid" "github.com/Microsoft/go-winio/pkg/guid"
"github.com/Microsoft/hcsshim/internal/oc"
"go.opencensus.io/trace"
) )
// LayerID returns the layer ID of a layer on disk. // LayerID returns the layer ID of a layer on disk.
func LayerID(path string) (guid.GUID, error) { func LayerID(ctx context.Context, path string) (_ guid.GUID, err error) {
title := "hcsshim::LayerID"
ctx, span := trace.StartSpan(ctx, title)
defer span.End()
defer func() { oc.SetSpanStatus(span, err) }()
span.AddAttributes(trace.StringAttribute("path", path))
_, file := filepath.Split(path) _, file := filepath.Split(path)
return NameToGuid(file) return NameToGuid(ctx, file)
} }

View File

@ -4,6 +4,7 @@ package wclayer
// functionality. // functionality.
import ( import (
"context"
"syscall" "syscall"
"github.com/Microsoft/go-winio/pkg/guid" "github.com/Microsoft/go-winio/pkg/guid"
@ -68,12 +69,12 @@ type WC_LAYER_DESCRIPTOR struct {
Pathp *uint16 Pathp *uint16
} }
func layerPathsToDescriptors(parentLayerPaths []string) ([]WC_LAYER_DESCRIPTOR, error) { func layerPathsToDescriptors(ctx context.Context, parentLayerPaths []string) ([]WC_LAYER_DESCRIPTOR, error) {
// Array of descriptors that gets constructed. // Array of descriptors that gets constructed.
var layers []WC_LAYER_DESCRIPTOR var layers []WC_LAYER_DESCRIPTOR
for i := 0; i < len(parentLayerPaths); i++ { for i := 0; i < len(parentLayerPaths); i++ {
g, err := LayerID(parentLayerPaths[i]) g, err := LayerID(ctx, parentLayerPaths[i])
if err != nil { if err != nil {
logrus.WithError(err).Debug("Failed to convert name to guid") logrus.WithError(err).Debug("Failed to convert name to guid")
return nil, err return nil, err

View File

@ -1,34 +1,29 @@
package wclayer package wclayer
import ( import (
"context"
"github.com/Microsoft/go-winio/pkg/guid" "github.com/Microsoft/go-winio/pkg/guid"
"github.com/Microsoft/hcsshim/internal/hcserror" "github.com/Microsoft/hcsshim/internal/hcserror"
"github.com/sirupsen/logrus" "github.com/Microsoft/hcsshim/internal/oc"
"go.opencensus.io/trace"
) )
// NameToGuid converts the given string into a GUID using the algorithm in the // NameToGuid converts the given string into a GUID using the algorithm in the
// Host Compute Service, ensuring GUIDs generated with the same string are common // Host Compute Service, ensuring GUIDs generated with the same string are common
// across all clients. // across all clients.
func NameToGuid(name string) (id guid.GUID, err error) { func NameToGuid(ctx context.Context, name string) (_ guid.GUID, err error) {
title := "hcsshim::NameToGuid" title := "hcsshim::NameToGuid"
fields := logrus.Fields{ ctx, span := trace.StartSpan(ctx, title)
"name": name, defer span.End()
} defer func() { oc.SetSpanStatus(span, err) }()
logrus.WithFields(fields).Debug(title) span.AddAttributes(trace.StringAttribute("name", name))
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
var id guid.GUID
err = nameToGuid(name, &id) err = nameToGuid(name, &id)
if err != nil { if err != nil {
err = hcserror.New(err, title+" - failed", "") return guid.GUID{}, hcserror.New(err, title+" - failed", "")
return
} }
fields["guid"] = id.String() span.AddAttributes(trace.StringAttribute("guid", id.String()))
return return id, nil
} }

View File

@ -1,10 +1,13 @@
package wclayer package wclayer
import ( import (
"context"
"strings"
"sync" "sync"
"github.com/Microsoft/hcsshim/internal/hcserror" "github.com/Microsoft/hcsshim/internal/hcserror"
"github.com/sirupsen/logrus" "github.com/Microsoft/hcsshim/internal/oc"
"go.opencensus.io/trace"
) )
var prepareLayerLock sync.Mutex var prepareLayerLock sync.Mutex
@ -14,23 +17,17 @@ var prepareLayerLock sync.Mutex
// parent layers, and is necessary in order to view or interact with the layer // parent layers, and is necessary in order to view or interact with the layer
// as an actual filesystem (reading and writing files, creating directories, etc). // as an actual filesystem (reading and writing files, creating directories, etc).
// Disabling the filter must be done via UnprepareLayer. // Disabling the filter must be done via UnprepareLayer.
func PrepareLayer(path string, parentLayerPaths []string) (err error) { func PrepareLayer(ctx context.Context, path string, parentLayerPaths []string) (err error) {
title := "hcsshim::PrepareLayer" title := "hcsshim::PrepareLayer"
fields := logrus.Fields{ ctx, span := trace.StartSpan(ctx, title)
"path": path, defer span.End()
} defer func() { oc.SetSpanStatus(span, err) }()
logrus.WithFields(fields).Debug(title) span.AddAttributes(
defer func() { trace.StringAttribute("path", path),
if err != nil { trace.StringAttribute("parentLayerPaths", strings.Join(parentLayerPaths, ", ")))
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
// Generate layer descriptors // Generate layer descriptors
layers, err := layerPathsToDescriptors(parentLayerPaths) layers, err := layerPathsToDescriptors(ctx, parentLayerPaths)
if err != nil { if err != nil {
return err return err
} }

View File

@ -1,23 +1,41 @@
package wclayer package wclayer
import "os" import (
"context"
"os"
"github.com/Microsoft/hcsshim/internal/oc"
"go.opencensus.io/trace"
)
// ProcessBaseLayer post-processes a base layer that has had its files extracted. // ProcessBaseLayer post-processes a base layer that has had its files extracted.
// The files should have been extracted to <path>\Files. // The files should have been extracted to <path>\Files.
func ProcessBaseLayer(path string) error { func ProcessBaseLayer(ctx context.Context, path string) (err error) {
err := processBaseImage(path) title := "hcsshim::ProcessBaseLayer"
ctx, span := trace.StartSpan(ctx, title)
defer span.End()
defer func() { oc.SetSpanStatus(span, err) }()
span.AddAttributes(trace.StringAttribute("path", path))
err = processBaseImage(path)
if err != nil { if err != nil {
return &os.PathError{Op: "ProcessBaseLayer", Path: path, Err: err} return &os.PathError{Op: title, Path: path, Err: err}
} }
return nil return nil
} }
// ProcessUtilityVMImage post-processes a utility VM image that has had its files extracted. // ProcessUtilityVMImage post-processes a utility VM image that has had its files extracted.
// The files should have been extracted to <path>\Files. // The files should have been extracted to <path>\Files.
func ProcessUtilityVMImage(path string) error { func ProcessUtilityVMImage(ctx context.Context, path string) (err error) {
err := processUtilityImage(path) title := "hcsshim::ProcessUtilityVMImage"
ctx, span := trace.StartSpan(ctx, title)
defer span.End()
defer func() { oc.SetSpanStatus(span, err) }()
span.AddAttributes(trace.StringAttribute("path", path))
err = processUtilityImage(path)
if err != nil { if err != nil {
return &os.PathError{Op: "ProcessUtilityVMImage", Path: path, Err: err} return &os.PathError{Op: title, Path: path, Err: err}
} }
return nil return nil
} }

View File

@ -1,26 +1,21 @@
package wclayer package wclayer
import ( import (
"context"
"github.com/Microsoft/hcsshim/internal/hcserror" "github.com/Microsoft/hcsshim/internal/hcserror"
"github.com/sirupsen/logrus" "github.com/Microsoft/hcsshim/internal/oc"
"go.opencensus.io/trace"
) )
// UnprepareLayer disables the filesystem filter for the read-write layer with // UnprepareLayer disables the filesystem filter for the read-write layer with
// the given id. // the given id.
func UnprepareLayer(path string) (err error) { func UnprepareLayer(ctx context.Context, path string) (err error) {
title := "hcsshim::UnprepareLayer" title := "hcsshim::UnprepareLayer"
fields := logrus.Fields{ ctx, span := trace.StartSpan(ctx, title)
"path": path, defer span.End()
} defer func() { oc.SetSpanStatus(span, err) }()
logrus.WithFields(fields).Debug(title) span.AddAttributes(trace.StringAttribute("path", path))
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
err = unprepareLayer(&stdDriverInfo, path) err = unprepareLayer(&stdDriverInfo, path)
if err != nil { if err != nil {

View File

@ -1,6 +1,7 @@
package hcsshim package hcsshim
import ( import (
"context"
"crypto/sha1" "crypto/sha1"
"path/filepath" "path/filepath"
@ -13,59 +14,59 @@ func layerPath(info *DriverInfo, id string) string {
} }
func ActivateLayer(info DriverInfo, id string) error { func ActivateLayer(info DriverInfo, id string) error {
return wclayer.ActivateLayer(layerPath(&info, id)) return wclayer.ActivateLayer(context.Background(), layerPath(&info, id))
} }
func CreateLayer(info DriverInfo, id, parent string) error { func CreateLayer(info DriverInfo, id, parent string) error {
return wclayer.CreateLayer(layerPath(&info, id), parent) return wclayer.CreateLayer(context.Background(), layerPath(&info, id), parent)
} }
// New clients should use CreateScratchLayer instead. Kept in to preserve API compatibility. // New clients should use CreateScratchLayer instead. Kept in to preserve API compatibility.
func CreateSandboxLayer(info DriverInfo, layerId, parentId string, parentLayerPaths []string) error { func CreateSandboxLayer(info DriverInfo, layerId, parentId string, parentLayerPaths []string) error {
return wclayer.CreateScratchLayer(layerPath(&info, layerId), parentLayerPaths) return wclayer.CreateScratchLayer(context.Background(), layerPath(&info, layerId), parentLayerPaths)
} }
func CreateScratchLayer(info DriverInfo, layerId, parentId string, parentLayerPaths []string) error { func CreateScratchLayer(info DriverInfo, layerId, parentId string, parentLayerPaths []string) error {
return wclayer.CreateScratchLayer(layerPath(&info, layerId), parentLayerPaths) return wclayer.CreateScratchLayer(context.Background(), layerPath(&info, layerId), parentLayerPaths)
} }
func DeactivateLayer(info DriverInfo, id string) error { func DeactivateLayer(info DriverInfo, id string) error {
return wclayer.DeactivateLayer(layerPath(&info, id)) return wclayer.DeactivateLayer(context.Background(), layerPath(&info, id))
} }
func DestroyLayer(info DriverInfo, id string) error { func DestroyLayer(info DriverInfo, id string) error {
return wclayer.DestroyLayer(layerPath(&info, id)) return wclayer.DestroyLayer(context.Background(), layerPath(&info, id))
} }
// New clients should use ExpandScratchSize instead. Kept in to preserve API compatibility. // New clients should use ExpandScratchSize instead. Kept in to preserve API compatibility.
func ExpandSandboxSize(info DriverInfo, layerId string, size uint64) error { func ExpandSandboxSize(info DriverInfo, layerId string, size uint64) error {
return wclayer.ExpandScratchSize(layerPath(&info, layerId), size) return wclayer.ExpandScratchSize(context.Background(), layerPath(&info, layerId), size)
} }
func ExpandScratchSize(info DriverInfo, layerId string, size uint64) error { func ExpandScratchSize(info DriverInfo, layerId string, size uint64) error {
return wclayer.ExpandScratchSize(layerPath(&info, layerId), size) return wclayer.ExpandScratchSize(context.Background(), layerPath(&info, layerId), size)
} }
func ExportLayer(info DriverInfo, layerId string, exportFolderPath string, parentLayerPaths []string) error { func ExportLayer(info DriverInfo, layerId string, exportFolderPath string, parentLayerPaths []string) error {
return wclayer.ExportLayer(layerPath(&info, layerId), exportFolderPath, parentLayerPaths) return wclayer.ExportLayer(context.Background(), layerPath(&info, layerId), exportFolderPath, parentLayerPaths)
} }
func GetLayerMountPath(info DriverInfo, id string) (string, error) { func GetLayerMountPath(info DriverInfo, id string) (string, error) {
return wclayer.GetLayerMountPath(layerPath(&info, id)) return wclayer.GetLayerMountPath(context.Background(), layerPath(&info, id))
} }
func GetSharedBaseImages() (imageData string, err error) { func GetSharedBaseImages() (imageData string, err error) {
return wclayer.GetSharedBaseImages() return wclayer.GetSharedBaseImages(context.Background())
} }
func ImportLayer(info DriverInfo, layerID string, importFolderPath string, parentLayerPaths []string) error { func ImportLayer(info DriverInfo, layerID string, importFolderPath string, parentLayerPaths []string) error {
return wclayer.ImportLayer(layerPath(&info, layerID), importFolderPath, parentLayerPaths) return wclayer.ImportLayer(context.Background(), layerPath(&info, layerID), importFolderPath, parentLayerPaths)
} }
func LayerExists(info DriverInfo, id string) (bool, error) { func LayerExists(info DriverInfo, id string) (bool, error) {
return wclayer.LayerExists(layerPath(&info, id)) return wclayer.LayerExists(context.Background(), layerPath(&info, id))
} }
func PrepareLayer(info DriverInfo, layerId string, parentLayerPaths []string) error { func PrepareLayer(info DriverInfo, layerId string, parentLayerPaths []string) error {
return wclayer.PrepareLayer(layerPath(&info, layerId), parentLayerPaths) return wclayer.PrepareLayer(context.Background(), layerPath(&info, layerId), parentLayerPaths)
} }
func ProcessBaseLayer(path string) error { func ProcessBaseLayer(path string) error {
return wclayer.ProcessBaseLayer(path) return wclayer.ProcessBaseLayer(context.Background(), path)
} }
func ProcessUtilityVMImage(path string) error { func ProcessUtilityVMImage(path string) error {
return wclayer.ProcessUtilityVMImage(path) return wclayer.ProcessUtilityVMImage(context.Background(), path)
} }
func UnprepareLayer(info DriverInfo, layerId string) error { func UnprepareLayer(info DriverInfo, layerId string) error {
return wclayer.UnprepareLayer(layerPath(&info, layerId)) return wclayer.UnprepareLayer(context.Background(), layerPath(&info, layerId))
} }
type DriverInfo struct { type DriverInfo struct {
@ -76,7 +77,7 @@ type DriverInfo struct {
type GUID [16]byte type GUID [16]byte
func NameToGuid(name string) (id GUID, err error) { func NameToGuid(name string) (id GUID, err error) {
g, err := wclayer.NameToGuid(name) g, err := wclayer.NameToGuid(context.Background(), name)
return g.ToWindowsArray(), err return g.ToWindowsArray(), err
} }
@ -94,13 +95,13 @@ func (g *GUID) ToString() string {
type LayerReader = wclayer.LayerReader type LayerReader = wclayer.LayerReader
func NewLayerReader(info DriverInfo, layerID string, parentLayerPaths []string) (LayerReader, error) { func NewLayerReader(info DriverInfo, layerID string, parentLayerPaths []string) (LayerReader, error) {
return wclayer.NewLayerReader(layerPath(&info, layerID), parentLayerPaths) return wclayer.NewLayerReader(context.Background(), layerPath(&info, layerID), parentLayerPaths)
} }
type LayerWriter = wclayer.LayerWriter type LayerWriter = wclayer.LayerWriter
func NewLayerWriter(info DriverInfo, layerID string, parentLayerPaths []string) (LayerWriter, error) { func NewLayerWriter(info DriverInfo, layerID string, parentLayerPaths []string) (LayerWriter, error) {
return wclayer.NewLayerWriter(layerPath(&info, layerID), parentLayerPaths) return wclayer.NewLayerWriter(context.Background(), layerPath(&info, layerID), parentLayerPaths)
} }
type WC_LAYER_DESCRIPTOR = wclayer.WC_LAYER_DESCRIPTOR type WC_LAYER_DESCRIPTOR = wclayer.WC_LAYER_DESCRIPTOR