lib/file: retry preallocate on EINTR
Before this change, sometimes preallocate failed with EINTR which rclone ignored. Retrying the syscall is the correct thing to do and seems to make preallocate 100% reliable.
This commit is contained in:
parent
4b4e531846
commit
5e038a5e1e
1 changed files with 27 additions and 18 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"os"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
|
||||
"github.com/rclone/rclone/fs"
|
||||
"golang.org/x/sys/unix"
|
||||
|
@ -25,19 +26,23 @@ var (
|
|||
const PreallocateImplemented = true
|
||||
|
||||
// PreAllocate the file for performance reasons
|
||||
func PreAllocate(size int64, out *os.File) error {
|
||||
func PreAllocate(size int64, out *os.File) (err error) {
|
||||
if size <= 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
preAllocateMu.Lock()
|
||||
defer preAllocateMu.Unlock()
|
||||
|
||||
for {
|
||||
|
||||
index := atomic.LoadInt32(&fallocFlagsIndex)
|
||||
again:
|
||||
if index >= int32(len(fallocFlags)) {
|
||||
return nil // Fallocate is disabled
|
||||
}
|
||||
flags := fallocFlags[index]
|
||||
err := unix.Fallocate(int(out.Fd()), flags, 0, size)
|
||||
err = unix.Fallocate(int(out.Fd()), flags, 0, size)
|
||||
if err == unix.ENOTSUP {
|
||||
// Try the next flags combination
|
||||
index++
|
||||
|
@ -50,6 +55,10 @@ again:
|
|||
if err == unix.ENOSPC {
|
||||
return ErrDiskFull
|
||||
}
|
||||
if err != syscall.EINTR {
|
||||
break
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue