Skip to content

Commit 9fda4a5

Browse files
committed
Bumps the version of go-winio.
This also refactors the lcow and windows snapshotters to use go-winio's utility functions for checking the filesystem type. Signed-off-by: Eric Hotinger <[email protected]>
1 parent 6617def commit 9fda4a5

22 files changed

Lines changed: 794 additions & 186 deletions

File tree

cmd/containerd/command/main_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func setupDumpStacks() {
9393
}()
9494
}
9595

96-
func etwCallback(sourceID *guid.GUID, state etw.ProviderState, level etw.Level, matchAnyKeyword uint64, matchAllKeyword uint64, filterData uintptr) {
96+
func etwCallback(sourceID guid.GUID, state etw.ProviderState, level etw.Level, matchAnyKeyword uint64, matchAllKeyword uint64, filterData uintptr) {
9797
if state == etw.ProviderStateCaptureState {
9898
dumpStacks(false)
9999
}

snapshots/lcow/lcow.go

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ import (
2828
"strconv"
2929
"strings"
3030
"sync"
31-
"syscall"
3231
"time"
33-
"unsafe"
3432

33+
winfs "github.com/Microsoft/go-winio/pkg/fs"
3534
"github.com/Microsoft/hcsshim/pkg/go-runhcs"
3635
"github.com/containerd/containerd/errdefs"
3736
"github.com/containerd/containerd/log"
@@ -42,7 +41,6 @@ import (
4241
"github.com/containerd/continuity/fs"
4342
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
4443
"github.com/pkg/errors"
45-
"golang.org/x/sys/windows"
4644
)
4745

4846
func init() {
@@ -68,7 +66,7 @@ type snapshotter struct {
6866

6967
// NewSnapshotter returns a new windows snapshotter
7068
func NewSnapshotter(root string) (snapshots.Snapshotter, error) {
71-
fsType, err := getFileSystemType(root)
69+
fsType, err := winfs.GetFileSystemType(root)
7270
if err != nil {
7371
return nil, err
7472
}
@@ -404,35 +402,3 @@ func (s *snapshotter) parentIDsToParentPaths(parentIDs []string) []string {
404402
}
405403
return parentLayerPaths
406404
}
407-
408-
// getFileSystemType obtains the type of a file system through GetVolumeInformation
409-
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa364993(v=vs.85).aspx
410-
func getFileSystemType(path string) (fsType string, hr error) {
411-
drive := filepath.VolumeName(path)
412-
if len(drive) != 2 {
413-
return "", errors.New("getFileSystemType path must start with a drive letter")
414-
}
415-
416-
var (
417-
modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
418-
procGetVolumeInformation = modkernel32.NewProc("GetVolumeInformationW")
419-
buf = make([]uint16, 255)
420-
size = windows.MAX_PATH + 1
421-
)
422-
drive += `\`
423-
n := uintptr(unsafe.Pointer(nil))
424-
r0, _, _ := syscall.Syscall9(procGetVolumeInformation.Addr(), 8, uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(drive))), n, n, n, n, n, uintptr(unsafe.Pointer(&buf[0])), uintptr(size), 0)
425-
if int32(r0) < 0 {
426-
hr = syscall.Errno(win32FromHresult(r0))
427-
}
428-
fsType = windows.UTF16ToString(buf)
429-
return
430-
}
431-
432-
// win32FromHresult is a helper function to get the win32 error code from an HRESULT
433-
func win32FromHresult(hr uintptr) uintptr {
434-
if hr&0x1fff0000 == 0x00070000 {
435-
return hr & 0xffff
436-
}
437-
return hr
438-
}

snapshots/windows/windows.go

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ import (
2424
"os"
2525
"path/filepath"
2626
"strings"
27-
"syscall"
28-
"unsafe"
2927

28+
winfs "github.com/Microsoft/go-winio/pkg/fs"
3029
"github.com/Microsoft/go-winio/vhd"
3130
"github.com/Microsoft/hcsshim"
3231
"github.com/containerd/containerd/errdefs"
@@ -37,7 +36,6 @@ import (
3736
"github.com/containerd/containerd/snapshots/storage"
3837
"github.com/containerd/continuity/fs"
3938
"github.com/pkg/errors"
40-
"golang.org/x/sys/windows"
4139
)
4240

4341
func init() {
@@ -58,7 +56,7 @@ type snapshotter struct {
5856

5957
// NewSnapshotter returns a new windows snapshotter
6058
func NewSnapshotter(root string) (snapshots.Snapshotter, error) {
61-
fsType, err := getFileSystemType(root)
59+
fsType, err := winfs.GetFileSystemType(root)
6260
if err != nil {
6361
return nil, err
6462
}
@@ -338,35 +336,3 @@ func (s *snapshotter) parentIDsToParentPaths(parentIDs []string) []string {
338336
}
339337
return parentLayerPaths
340338
}
341-
342-
// getFileSystemType obtains the type of a file system through GetVolumeInformation
343-
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa364993(v=vs.85).aspx
344-
func getFileSystemType(path string) (fsType string, hr error) {
345-
drive := filepath.VolumeName(path)
346-
if len(drive) != 2 {
347-
return "", errors.New("getFileSystemType path must start with a drive letter")
348-
}
349-
350-
var (
351-
modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
352-
procGetVolumeInformation = modkernel32.NewProc("GetVolumeInformationW")
353-
buf = make([]uint16, 255)
354-
size = windows.MAX_PATH + 1
355-
)
356-
drive += `\`
357-
n := uintptr(unsafe.Pointer(nil))
358-
r0, _, _ := syscall.Syscall9(procGetVolumeInformation.Addr(), 8, uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(drive))), n, n, n, n, n, uintptr(unsafe.Pointer(&buf[0])), uintptr(size), 0)
359-
if int32(r0) < 0 {
360-
hr = syscall.Errno(win32FromHresult(r0))
361-
}
362-
fsType = windows.UTF16ToString(buf)
363-
return
364-
}
365-
366-
// win32FromHresult is a helper function to get the win32 error code from an HRESULT
367-
func win32FromHresult(hr uintptr) uintptr {
368-
if hr&0x1fff0000 == 0x00070000 {
369-
return hr & 0xffff
370-
}
371-
return hr
372-
}

vendor.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ github.com/opencontainers/image-spec v1.0.1
3333
golang.org/x/sync 42b317875d0fa942474b76e1b46a6060d720ae6e
3434
github.com/BurntSushi/toml v0.3.1
3535
github.com/grpc-ecosystem/go-grpc-prometheus 6b7015e65d366bf3f19b2b2a000a831940f0f7e0
36-
github.com/Microsoft/go-winio 84b4ab48a50763fe7b3abcef38e5205c12027fac
36+
github.com/Microsoft/go-winio 7cdfd71a950d40d0da2167ccb690b541f7ba98c0
3737
github.com/Microsoft/hcsshim 8abdbb8205e4192c68b5f84c31197156f31be517
3838
google.golang.org/genproto d80a6e20e776b0b17a324d0ba1ab50a39c8e8944
3939
golang.org/x/text 19e51611da83d6be54ddafce4a4af510cb3e9ea4

vendor/github.com/Microsoft/go-winio/file.go

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Microsoft/go-winio/go.mod

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)