Skip to content

Commit

Permalink
Fix regression in DetachVhd
Browse files Browse the repository at this point in the history
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) <[email protected]>
  • Loading branch information
jterry75 committed Aug 6, 2019
1 parent a969fb0 commit 5adf678
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions vhd/vhd.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,21 @@ 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
}
defer syscall.CloseHandle(handle)
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
Expand Down

0 comments on commit 5adf678

Please sign in to comment.