mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
pkg/fileutil: treat not support error as nil error in preallocate
This commit is contained in:
parent
e1dfcec0ab
commit
3ca5482251
@ -18,6 +18,11 @@ package fileutil
|
|||||||
|
|
||||||
import "os"
|
import "os"
|
||||||
|
|
||||||
|
// Preallocate tries to allocate the space for given
|
||||||
|
// file. This operation is only supported on linux by a
|
||||||
|
// few filesystems (btrfs, ext4, etc.).
|
||||||
|
// If the operation is unsupported, no error will be returned.
|
||||||
|
// Otherwise, the error encountered will be returned.
|
||||||
func Preallocate(f *os.File, sizeInBytes int) error {
|
func Preallocate(f *os.File, sizeInBytes int) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,22 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Preallocate tries to allocate the space for given
|
||||||
|
// file. This operation is only supported on linux by a
|
||||||
|
// few filesystems (btrfs, ext4, etc.).
|
||||||
|
// If the operation is unsupported, no error will be returned.
|
||||||
|
// Otherwise, the error encountered will be returned.
|
||||||
func Preallocate(f *os.File, sizeInBytes int) error {
|
func Preallocate(f *os.File, sizeInBytes int) error {
|
||||||
// use mode = 1 to keep size
|
// use mode = 1 to keep size
|
||||||
// see FALLOC_FL_KEEP_SIZE
|
// see FALLOC_FL_KEEP_SIZE
|
||||||
return syscall.Fallocate(int(f.Fd()), 1, 0, int64(sizeInBytes))
|
err := syscall.Fallocate(int(f.Fd()), 1, 0, int64(sizeInBytes))
|
||||||
|
if err != nil {
|
||||||
|
errno, ok := err.(syscall.Errno)
|
||||||
|
// treat not support as nil error
|
||||||
|
if ok && errno == syscall.ENOTSUP {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user