local: preallocate files on linux with fallocate(2)

This commit is contained in:
Nick Craig-Wood 2018-08-20 20:14:19 +01:00
parent f29c6049fc
commit 9fa8c959ee
2 changed files with 23 additions and 1 deletions

View File

@ -1,4 +1,4 @@
//+build !windows
//+build !windows,!linux
package local

View File

@ -0,0 +1,22 @@
//+build linux
package local
import (
"os"
"golang.org/x/sys/unix"
)
// preAllocate the file for performance reasons
func preAllocate(size int64, out *os.File) error {
if size <= 0 {
return nil
}
err := unix.Fallocate(int(out.Fd()), unix.FALLOC_FL_KEEP_SIZE, 0, size)
// FIXME could be doing something here
// if err == unix.ENOSPC {
// log.Printf("No space")
// }
return err
}