aboutsummaryrefslogtreecommitdiff
path: root/test/fuse_integration/vectored_io_unix.go
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2025-08-31 12:25:41 -0700
committerchrislu <chris.lu@gmail.com>2025-08-31 12:25:41 -0700
commitd7dc9a47d59c44b8ec0e2bd3923b42d10ac37506 (patch)
tree5bbfff429be6bf6f6b318a0740498f793a724b15 /test/fuse_integration/vectored_io_unix.go
parentfd1149e5b26c6a762980f2e36c44a19ab081ee8e (diff)
downloadseaweedfs-d7dc9a47d59c44b8ec0e2bd3923b42d10ac37506.tar.xz
seaweedfs-d7dc9a47d59c44b8ec0e2bd3923b42d10ac37506.zip
add more posix tests
Diffstat (limited to 'test/fuse_integration/vectored_io_unix.go')
-rw-r--r--test/fuse_integration/vectored_io_unix.go126
1 files changed, 126 insertions, 0 deletions
diff --git a/test/fuse_integration/vectored_io_unix.go b/test/fuse_integration/vectored_io_unix.go
new file mode 100644
index 000000000..59b2b2cc4
--- /dev/null
+++ b/test/fuse_integration/vectored_io_unix.go
@@ -0,0 +1,126 @@
+//go:build unix
+
+package fuse
+
+import (
+ "syscall"
+ "unsafe"
+)
+
+// Vectored I/O support for Unix-like systems
+
+// IOVec represents an I/O vector for readv/writev operations
+type IOVec struct {
+ Base *byte
+ Len uint64
+}
+
+func readvFile(fd int, iovs []IOVec) (int, error) {
+ if len(iovs) == 0 {
+ return 0, nil
+ }
+
+ n, _, errno := syscall.Syscall(syscall.SYS_READV,
+ uintptr(fd),
+ uintptr(unsafe.Pointer(&iovs[0])),
+ uintptr(len(iovs)))
+
+ if errno != 0 {
+ return 0, errno
+ }
+ return int(n), nil
+}
+
+func writevFile(fd int, iovs []IOVec) (int, error) {
+ if len(iovs) == 0 {
+ return 0, nil
+ }
+
+ n, _, errno := syscall.Syscall(syscall.SYS_WRITEV,
+ uintptr(fd),
+ uintptr(unsafe.Pointer(&iovs[0])),
+ uintptr(len(iovs)))
+
+ if errno != 0 {
+ return 0, errno
+ }
+ return int(n), nil
+}
+
+func preadvFile(fd int, iovs []IOVec, offset int64) (int, error) {
+ if len(iovs) == 0 {
+ return 0, nil
+ }
+
+ // preadv/pwritev may not be available on all Unix systems
+ // Fall back to individual pread calls
+ totalRead := 0
+ currentOffset := offset
+
+ for _, iov := range iovs {
+ if iov.Len == 0 {
+ continue
+ }
+
+ buf := (*[1 << 30]byte)(unsafe.Pointer(iov.Base))[:iov.Len:iov.Len]
+ n, err := syscall.Pread(fd, buf, currentOffset)
+ if err != nil {
+ return totalRead, err
+ }
+ totalRead += n
+ currentOffset += int64(n)
+
+ if n < int(iov.Len) {
+ break // EOF or partial read
+ }
+ }
+
+ return totalRead, nil
+}
+
+func pwritevFile(fd int, iovs []IOVec, offset int64) (int, error) {
+ if len(iovs) == 0 {
+ return 0, nil
+ }
+
+ // preadv/pwritev may not be available on all Unix systems
+ // Fall back to individual pwrite calls
+ totalWritten := 0
+ currentOffset := offset
+
+ for _, iov := range iovs {
+ if iov.Len == 0 {
+ continue
+ }
+
+ buf := (*[1 << 30]byte)(unsafe.Pointer(iov.Base))[:iov.Len:iov.Len]
+ n, err := syscall.Pwrite(fd, buf, currentOffset)
+ if err != nil {
+ return totalWritten, err
+ }
+ totalWritten += n
+ currentOffset += int64(n)
+
+ if n < int(iov.Len) {
+ break // Partial write
+ }
+ }
+
+ return totalWritten, nil
+}
+
+// Helper function to create IOVec from byte slices
+func makeIOVecs(buffers [][]byte) []IOVec {
+ iovs := make([]IOVec, len(buffers))
+ for i, buf := range buffers {
+ if len(buf) > 0 {
+ iovs[i].Base = &buf[0]
+ iovs[i].Len = uint64(len(buf))
+ }
+ }
+ return iovs
+}
+
+func isVectoredIOSupported() bool {
+ return true
+}