added openbsd implementations (#790)

https://github.com/VictoriaMetrics/VictoriaMetrics/issues/785

removed fadvise for openbsd, added freespace implemenation for openbsd
This commit is contained in:
Nikolay Khramchikhin 2020-09-29 00:29:04 +03:00 committed by Aliaksandr Valialkin
parent bc37f1cbec
commit 658a05ef0f
4 changed files with 50 additions and 2 deletions

View file

@ -0,0 +1,30 @@
package filestream
import (
"fmt"
"golang.org/x/sys/unix"
)
func (st *streamTracker) adviseDontNeed(n int, fdatasync bool) error {
st.length += uint64(n)
if st.fd == 0 {
return nil
}
if st.length < dontNeedBlockSize {
return nil
}
blockSize := st.length - (st.length % dontNeedBlockSize)
if fdatasync {
if err := unix.Fsync(int(st.fd)); err != nil {
return fmt.Errorf("unix.Fsync error: %w", err)
}
}
st.length -= blockSize
return nil
}
func (st *streamTracker) close() error {
return nil
}

View file

@ -338,6 +338,6 @@ func mustGetFreeSpace(path string) uint64 {
if err := unix.Fstatfs(int(fd), &stat); err != nil { if err := unix.Fstatfs(int(fd), &stat); err != nil {
logger.Panicf("FATAL: cannot determine free disk space on %q: %s", path, err) logger.Panicf("FATAL: cannot determine free disk space on %q: %s", path, err)
} }
freeSpace := uint64(stat.Bavail) * uint64(stat.Bsize)
return freeSpace return freeSpace(stat)
} }

9
lib/fs/fs_nix.go Normal file
View file

@ -0,0 +1,9 @@
// +build linux darwin freebsd
package fs
import "golang.org/x/sys/unix"
func freeSpace(stat unix.Statfs_t) uint64 {
return uint64(stat.Bavail) * uint64(stat.Bsize)
}

9
lib/fs/fs_openbsd.go Normal file
View file

@ -0,0 +1,9 @@
package fs
import (
"golang.org/x/sys/unix"
)
func freeSpace(stat unix.Statfs_t) uint64 {
return uint64(stat.F_bavail) * uint64(stat.F_bsize)
}