feat: full NFSv4.2 server and client in pure Go
Test / test (push) Successful in 2m4s
Release / gates (push) Successful in 2m5s
Release / build (amd64, freebsd) (push) Successful in 1m27s
Release / build (amd64, linux) (push) Successful in 1m22s
Release / build (amd64, netbsd) (push) Successful in 1m19s
Release / build (amd64, openbsd) (push) Successful in 1m20s
Release / build (arm64, darwin) (push) Successful in 1m21s
Release / build (arm64, freebsd) (push) Successful in 1m26s
Release / build (arm64, linux) (push) Successful in 1m25s
Release / build (arm64, netbsd) (push) Successful in 1m31s
Release / build (arm64, openbsd) (push) Successful in 1m27s
Release / build (loong64, linux) (push) Successful in 1m37s
Release / build (riscv64, linux) (push) Successful in 1m21s
Release / release (push) Successful in 40s
Test / test (push) Successful in 2m4s
Release / gates (push) Successful in 2m5s
Release / build (amd64, freebsd) (push) Successful in 1m27s
Release / build (amd64, linux) (push) Successful in 1m22s
Release / build (amd64, netbsd) (push) Successful in 1m19s
Release / build (amd64, openbsd) (push) Successful in 1m20s
Release / build (arm64, darwin) (push) Successful in 1m21s
Release / build (arm64, freebsd) (push) Successful in 1m26s
Release / build (arm64, linux) (push) Successful in 1m25s
Release / build (arm64, netbsd) (push) Successful in 1m31s
Release / build (arm64, openbsd) (push) Successful in 1m27s
Release / build (loong64, linux) (push) Successful in 1m37s
Release / build (riscv64, linux) (push) Successful in 1m21s
Release / release (push) Successful in 40s
Assisted-by: GLM 5.3 Flash
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
//go:build linux
|
||||
|
||||
package nfsfs
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLocalSparse(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
if err := os.WriteFile(filepath.Join(root, "s.bin"), make([]byte, 8192), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
l, err := NewLocal(root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rootHandle, err := l.Root()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fh, _, err := l.Lookup(rootHandle, "s.bin")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The file is all data: the only hole is the virtual one every file
|
||||
// carries at its end, so the seek answers the size with the eof flag,
|
||||
// RFC 7862 section 15.11.
|
||||
off, eof, err := l.SeekHole(fh, 0)
|
||||
if err != nil || off != 8192 || !eof {
|
||||
t.Fatalf("hole in a full file: %d %v %v", off, eof, err)
|
||||
}
|
||||
if off, eof, err := l.SeekData(fh, 0); err != nil || off != 0 || eof {
|
||||
t.Fatalf("seek data: %d %v %v", off, eof, err)
|
||||
}
|
||||
// A seek past the end is NXIO, not an answer.
|
||||
if _, _, err := l.SeekData(fh, 8193); err != ErrBeyondEOF {
|
||||
t.Fatalf("seek past the end: %v", err)
|
||||
}
|
||||
// Punching a hole moves the first hole to the punched offset.
|
||||
if err := l.Deallocate(fh, 4096, 4096); err != nil {
|
||||
t.Fatalf("deallocate: %v", err)
|
||||
}
|
||||
off, eof, err = l.SeekHole(fh, 0)
|
||||
if err != nil || off != 4096 || eof {
|
||||
t.Fatalf("seek hole: %d %v %v", off, eof, err)
|
||||
}
|
||||
// No data follows inside the hole: the answer names the size with
|
||||
// the eof flag.
|
||||
if off, eof, err := l.SeekData(fh, 4096); err != nil || off != 8192 || !eof {
|
||||
t.Fatalf("data in the hole: %d %v %v", off, eof, err)
|
||||
}
|
||||
// Allocate reserves the space without moving the hole back.
|
||||
if err := l.Allocate(fh, 4096, 4096); err != nil {
|
||||
t.Fatalf("allocate: %v", err)
|
||||
}
|
||||
if off, eof, err := l.SeekHole(fh, 0); err != nil || off != 4096 || eof {
|
||||
t.Fatalf("seek hole after allocate: %d %v %v", off, eof, err)
|
||||
}
|
||||
// Allocate past the end grows the file to the end of the reserved
|
||||
// range, which RFC 7862 section 15.1 requires.
|
||||
if err := l.Allocate(fh, 8192, 4096); err != nil {
|
||||
t.Fatalf("allocate past eof: %v", err)
|
||||
}
|
||||
info, err := l.Getattr(fh)
|
||||
if err != nil || info.Size != 12288 {
|
||||
t.Fatalf("size after the allocate past eof: %d, %v", info.Size, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user