forked from TrueCloudLab/rclone
lib/file: don't run preallocate concurrently
This seems to cause file systems to get the amount of free space wrong.
This commit is contained in:
parent
40b58d59ad
commit
b9bf91c510
2 changed files with 9 additions and 0 deletions
|
@ -4,6 +4,7 @@ package file
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
|
@ -16,6 +17,7 @@ var (
|
||||||
unix.FALLOC_FL_KEEP_SIZE | unix.FALLOC_FL_PUNCH_HOLE, // for ZFS #3066
|
unix.FALLOC_FL_KEEP_SIZE | unix.FALLOC_FL_PUNCH_HOLE, // for ZFS #3066
|
||||||
}
|
}
|
||||||
fallocFlagsIndex int32
|
fallocFlagsIndex int32
|
||||||
|
preAllocateMu sync.Mutex
|
||||||
)
|
)
|
||||||
|
|
||||||
// PreallocateImplemented is a constant indicating whether the
|
// PreallocateImplemented is a constant indicating whether the
|
||||||
|
@ -27,6 +29,8 @@ func PreAllocate(size int64, out *os.File) error {
|
||||||
if size <= 0 {
|
if size <= 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
preAllocateMu.Lock()
|
||||||
|
defer preAllocateMu.Unlock()
|
||||||
index := atomic.LoadInt32(&fallocFlagsIndex)
|
index := atomic.LoadInt32(&fallocFlagsIndex)
|
||||||
again:
|
again:
|
||||||
if index >= int32(len(fallocFlags)) {
|
if index >= int32(len(fallocFlags)) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ package file
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
|
@ -15,6 +16,7 @@ var (
|
||||||
ntdll = windows.NewLazySystemDLL("ntdll.dll")
|
ntdll = windows.NewLazySystemDLL("ntdll.dll")
|
||||||
ntQueryVolumeInformationFile = ntdll.NewProc("NtQueryVolumeInformationFile")
|
ntQueryVolumeInformationFile = ntdll.NewProc("NtQueryVolumeInformationFile")
|
||||||
ntSetInformationFile = ntdll.NewProc("NtSetInformationFile")
|
ntSetInformationFile = ntdll.NewProc("NtSetInformationFile")
|
||||||
|
preAllocateMu sync.Mutex
|
||||||
)
|
)
|
||||||
|
|
||||||
type fileAllocationInformation struct {
|
type fileAllocationInformation struct {
|
||||||
|
@ -42,6 +44,9 @@ func PreAllocate(size int64, out *os.File) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
preAllocateMu.Lock()
|
||||||
|
defer preAllocateMu.Unlock()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
iosb ioStatusBlock
|
iosb ioStatusBlock
|
||||||
fsSizeInfo fileFsSizeInformation
|
fsSizeInfo fileFsSizeInformation
|
||||||
|
|
Loading…
Reference in a new issue