diff --git a/lib/filestream/filestream_solaris.go b/lib/filestream/filestream_solaris.go new file mode 100644 index 000000000..631a915d4 --- /dev/null +++ b/lib/filestream/filestream_solaris.go @@ -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.offset += blockSize + st.length -= blockSize + return nil +} + +func (st *streamTracker) close() error { + return nil +} diff --git a/lib/fs/fadvise_solaris.go b/lib/fs/fadvise_solaris.go new file mode 100644 index 000000000..2a158b771 --- /dev/null +++ b/lib/fs/fadvise_solaris.go @@ -0,0 +1,8 @@ +package fs + +import "os" + +func fadviseSequentialRead(f *os.File, prefetch bool) error { + // TODO: implement this properly + return nil +} diff --git a/lib/fs/fs_solaris.go b/lib/fs/fs_solaris.go new file mode 100644 index 000000000..8cddca829 --- /dev/null +++ b/lib/fs/fs_solaris.go @@ -0,0 +1,68 @@ +package fs + +import ( + "fmt" + "os" + + "github.com/VictoriaMetrics/VictoriaMetrics/lib/logger" + "golang.org/x/sys/unix" +) + +func mmap(fd int, length int) (data []byte, err error) { + return unix.Mmap(fd, 0, length, unix.PROT_READ, unix.MAP_SHARED) + +} +func mUnmap(data []byte) error { + return unix.Munmap(data) +} + +func mustSyncPath(path string) { + d, err := os.Open(path) + if err != nil { + logger.Panicf("FATAL: cannot open %q: %s", path, err) + } + if err := d.Sync(); err != nil { + _ = d.Close() + logger.Panicf("FATAL: cannot flush %q to storage: %s", path, err) + } + if err := d.Close(); err != nil { + logger.Panicf("FATAL: cannot close %q: %s", path, err) + } +} + +func createFlockFile(flockFile string) (*os.File, error) { + flockF, err := os.Create(flockFile) + if err != nil { + return nil, fmt.Errorf("cannot create lock file %q: %w", flockFile, err) + } + + flock := unix.Flock_t{ + Type: unix.F_WRLCK, + Start: 0, + Len: 0, + Whence: 0, + } + if err := unix.FcntlFlock(flockF.Fd(), unix.F_SETLK, &flock); err != nil { + return nil, fmt.Errorf("cannot acquire lock on file %q: %w", flockFile, err) + } + return flockF, nil +} + +func mustGetFreeSpace(path string) uint64 { + d, err := os.Open(path) + if err != nil { + logger.Panicf("FATAL: cannot determine free disk space on %q: %s", path, err) + } + defer MustClose(d) + + fd := d.Fd() + var stat unix.Statvfs_t + if err := unix.Fstatvfs(int(fd), &stat); err != nil { + logger.Panicf("FATAL: cannot determine free disk space on %q: %s", path, err) + } + return freeSpace(stat) +} + +func freeSpace(stat unix.Statvfs_t) uint64 { + return uint64(stat.Bavail) * uint64(stat.Bsize) +} diff --git a/lib/memory/memory_solaris.go b/lib/memory/memory_solaris.go new file mode 100644 index 000000000..2e29d9ac6 --- /dev/null +++ b/lib/memory/memory_solaris.go @@ -0,0 +1,20 @@ +package memory + +import ( + "github.com/VictoriaMetrics/VictoriaMetrics/lib/logger" + "golang.org/x/sys/unix" +) + +const PHYS_PAGES = 0x1f4 + +func sysTotalMemory() int { + memPageSize := unix.Getpagesize() + // https://man7.org/linux/man-pages/man3/sysconf.3.html + // _SC_PHYS_PAGES + memPagesCnt, err := unix.Sysconf(PHYS_PAGES) + if err != nil { + logger.Panicf("FATAL: error in unix.Sysconf: %s", err) + } + + return memPageSize * int(memPagesCnt) +}