From a177a5acecf4d27751aa91ba0d6d1191d09de2ec Mon Sep 17 00:00:00 2001 From: Daniel Canter Date: Mon, 1 Aug 2022 13:54:15 -0700 Subject: [PATCH] Revert "Pass disk handle for computestorage.FormatWritableLayerVhd on RS5 (#1204)" This reverts commit aaf5db90ef6961e767a4d5ca4bcf7f1f6465bcca. We'd added a change to FormatWritableLayerVhd to help the caller work around a breaking change in the OS, but this would actually cause a breaking change in our wrapper of it if the caller was already working around the issue themselves. To avoid this scenario, revert the commit that added the "friendly" behavior. Signed-off-by: Daniel Canter --- computestorage/format.go | 54 ++-------------------------------------- 1 file changed, 2 insertions(+), 52 deletions(-) diff --git a/computestorage/format.go b/computestorage/format.go index 4a5735e989..7cd7741ed0 100644 --- a/computestorage/format.go +++ b/computestorage/format.go @@ -4,40 +4,12 @@ package computestorage import ( "context" - "os" - "syscall" - "github.com/Microsoft/go-winio/vhd" "github.com/Microsoft/hcsshim/internal/oc" - "github.com/Microsoft/hcsshim/osversion" "github.com/pkg/errors" "golang.org/x/sys/windows" ) -func openDisk(path string) (windows.Handle, error) { - u16, err := windows.UTF16PtrFromString(path) - if err != nil { - return 0, err - } - h, err := windows.CreateFile( - u16, - windows.GENERIC_READ|windows.GENERIC_WRITE, - windows.FILE_SHARE_READ|windows.FILE_SHARE_WRITE, - nil, - windows.OPEN_EXISTING, - windows.FILE_ATTRIBUTE_NORMAL|windows.FILE_FLAG_NO_BUFFERING, - 0, - ) - if err != nil { - return 0, &os.PathError{ - Op: "CreateFile", - Path: path, - Err: err, - } - } - return h, nil -} - // FormatWritableLayerVhd formats a virtual disk for use as a writable container layer. // // If the VHD is not mounted it will be temporarily mounted. @@ -47,31 +19,9 @@ func FormatWritableLayerVhd(ctx context.Context, vhdHandle windows.Handle) (err defer span.End() defer func() { oc.SetSpanStatus(span, err) }() - h := vhdHandle - // On RS5 HcsFormatWritableLayerVhd expects to receive a disk handle instead of a vhd handle. - if osversion.Build() < osversion.V19H1 { - if err := vhd.AttachVirtualDisk(syscall.Handle(vhdHandle), vhd.AttachVirtualDiskFlagNone, &vhd.AttachVirtualDiskParameters{Version: 1}); err != nil { - return err - } - defer func() { - if detachErr := vhd.DetachVirtualDisk(syscall.Handle(vhdHandle)); err == nil && detachErr != nil { - err = detachErr - } - }() - diskPath, err := vhd.GetVirtualDiskPhysicalPath(syscall.Handle(vhdHandle)) - if err != nil { - return err - } - diskHandle, err := openDisk(diskPath) - if err != nil { - return err - } - defer windows.CloseHandle(diskHandle) // nolint: errcheck - h = diskHandle - } - err = hcsFormatWritableLayerVhd(h) + err = hcsFormatWritableLayerVhd(vhdHandle) if err != nil { return errors.Wrap(err, "failed to format writable layer vhd") } - return + return nil }