posix: Fix windows performance issues. (#3132)

Do not attempt to fetch volume/drive information for
each i/o situation. In our case we do this in all calls
`posix.go` this in-turn created a terrible situation for
windows. This issue does not affect the i/o path on Unix
platforms since statvfs calls are in the range of micro
seconds on these platforms.

This verification is only needed during startup and we
let things fail at a later stage on windows.
This commit is contained in:
Harshavardhana
2016-10-31 09:34:44 -07:00
committed by GitHub
parent a773a6dce6
commit f3c6c55719
6 changed files with 160 additions and 78 deletions

View File

@@ -24,6 +24,19 @@ import (
"unsafe"
)
var (
kernel32 = syscall.NewLazyDLL("kernel32.dll")
// GetDiskFreeSpaceEx - https://msdn.microsoft.com/en-us/library/windows/desktop/aa364937(v=vs.85).aspx
// Retrieves information about the amount of space that is available on a disk volume,
// which is the total amount of space, the total amount of free space, and the total
// amount of free space available to the user that is associated with the calling thread.
GetDiskFreeSpaceEx = kernel32.NewProc("GetDiskFreeSpaceExW")
// GetDiskFreeSpace - https://msdn.microsoft.com/en-us/library/windows/desktop/aa364935(v=vs.85).aspx
// Retrieves information about the specified disk, including the amount of free space on the disk.
GetDiskFreeSpace = kernel32.NewProc("GetDiskFreeSpaceW")
)
// GetInfo returns total and free bytes available in a directory, e.g. `C:\`.
// It returns free space available to the user (including quota limitations)
//
@@ -34,13 +47,6 @@ func GetInfo(path string) (info Info, err error) {
return Info{}, err
}
dll := syscall.MustLoadDLL("kernel32.dll")
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa364937(v=vs.85).aspx
// Retrieves information about the amount of space that is available on a disk volume,
// which is the total amount of space, the total amount of free space, and the total
// amount of free space available to the user that is associated with the calling thread.
GetDiskFreeSpaceEx := dll.MustFindProc("GetDiskFreeSpaceExW")
lpFreeBytesAvailable := int64(0)
lpTotalNumberOfBytes := int64(0)
lpTotalNumberOfFreeBytes := int64(0)
@@ -61,10 +67,6 @@ func GetInfo(path string) (info Info, err error) {
info.Free = int64(lpFreeBytesAvailable)
info.FSType = getFSType(path)
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa364935(v=vs.85).aspx
// Retrieves information about the specified disk, including the amount of free space on the disk.
GetDiskFreeSpace := dll.MustFindProc("GetDiskFreeSpaceW")
// Return values of GetDiskFreeSpace()
lpSectorsPerCluster := uint32(0)
lpBytesPerSector := uint32(0)

View File

@@ -24,11 +24,13 @@ import (
"unsafe"
)
var (
// GetVolumeInformation provides windows drive volume information.
GetVolumeInformation = kernel32.NewProc("GetVolumeInformationW")
)
// getFSType returns the filesystem type of the underlying mounted filesystem
func getFSType(path string) string {
dll := syscall.MustLoadDLL("kernel32.dll")
GetVolumeInformation := dll.MustFindProc("GetVolumeInformationW")
var volumeNameSize uint32 = 260
var nFileSystemNameSize, lpVolumeSerialNumber uint32
var lpFileSystemFlags, lpMaximumComponentLength uint32