From 5adf6781fa9ee8fc748d8cd8e2a8dc7ac3fabf14 Mon Sep 17 00:00:00 2001 From: "Justin Terry (VM)" Date: Mon, 5 Aug 2019 12:22:56 -0700 Subject: [PATCH] Fix regression in DetachVhd When opening a disk it for deatch using 'Version == 2' parameters it is required that the'accessMask == VirtualDiskAccessNone'. Also updates the virtual disk 'flag' parameter to match the set specified by the product when activating the layer. Signed-off-by: Justin Terry (VM) --- vhd/vhd.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/vhd/vhd.go b/vhd/vhd.go index 48fb127..229ac25 100644 --- a/vhd/vhd.go +++ b/vhd/vhd.go @@ -117,9 +117,13 @@ func CreateVhdx(path string, maxSizeInGb, blockSizeInMb uint32) error { return nil } -// DetachVhd detaches a VHD attached at the given path. +// DetachVhd detaches a mounted container layer vhd found at `path`. func DetachVhd(path string) error { - handle, err := OpenVirtualDisk(path, VirtualDiskAccessDetach, OpenVirtualDiskFlagNone) + handle, err := OpenVirtualDisk( + path, + VirtualDiskAccessNone, + OpenVirtualDiskFlagCachedIO|OpenVirtualDiskFlagIgnoreRelativeParentLocator) + if err != nil { return err } @@ -127,7 +131,7 @@ func DetachVhd(path string) error { return detachVirtualDisk(handle, 0, 0) } -// OpenVirtuaDisk obtains a handle to a VHD opened with supplied access mask and flags. +// 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