tstor/pkg/go-nfs
royalcat bc4b39b1c1
Some checks failed
docker / build-docker (linux/amd64) (push) Successful in 2m36s
docker / build-docker (linux/386) (push) Successful in 2m45s
docker / build-docker (linux/arm/v7) (push) Has been cancelled
docker / build-docker (linux/arm64/v8) (push) Has been cancelled
docker / build-docker (linux/arm64) (push) Has been cancelled
new kv, ctx in nfs handler
2024-06-17 00:34:46 +03:00
..
.github update 2024-03-28 16:09:42 +03:00
example update 2024-03-28 16:09:42 +03:00
file update 2024-03-28 16:09:42 +03:00
helpers new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
capability_check.go update 2024-03-28 16:09:42 +03:00
conn.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
CONTRIBUTING.md update 2024-03-28 16:09:42 +03:00
errors.go update 2024-03-28 16:09:42 +03:00
file.go update 2024-03-28 16:09:42 +03:00
filesystem.go refactor 2024-06-02 22:53:33 +03:00
handler.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
LICENSE update 2024-03-28 16:09:42 +03:00
log.go update 2024-03-28 16:09:42 +03:00
mount.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
mountinterface.go update 2024-03-28 16:09:42 +03:00
nfs.go update 2024-03-28 16:09:42 +03:00
nfs_onaccess.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
nfs_oncommit.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
nfs_oncreate.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
nfs_onfsinfo.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
nfs_onfsstat.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
nfs_ongetattr.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
nfs_onlink.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
nfs_onlookup.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
nfs_onmkdir.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
nfs_onmknod.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
nfs_onpathconf.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
nfs_onread.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
nfs_onreaddir.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
nfs_onreaddirplus.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
nfs_onreadlink.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
nfs_onremove.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
nfs_onrename.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
nfs_onrmdir.go update 2024-03-28 16:09:42 +03:00
nfs_onsetattr.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
nfs_onsymlink.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
nfs_onwrite.go new kv, ctx in nfs handler 2024-06-17 00:34:46 +03:00
nfs_test.go update 2024-03-28 16:09:42 +03:00
nfsinterface.go nfs timeout error 2024-04-06 16:51:17 +03:00
README.md update 2024-03-28 16:09:42 +03:00
SECURITY.md update 2024-03-28 16:09:42 +03:00
server.go update 2024-03-28 16:09:42 +03:00
time.go update 2024-03-28 16:09:42 +03:00

Golang Network File Server

NFSv3 protocol implementation in pure Golang.

Current Status:

  • Minimally tested
  • Mounts, read-only and read-write support

Usage

The most interesting demo is currently in example/osview.

Start the server go run ./example/osview ..

The local folder at . will be the initial view in the mount. mutations to metadata or contents will be stored purely in memory and not written back to the OS. When run, this demo will print the port it is listening on.

The mount can be accessed using a command similar to mount -o port=<n>,mountport=<n> -t nfs localhost:/mount <mountpoint> (For Mac users)

or

mount -o port=<n>,mountport=<n>,nfsvers=3,noacl,tcp -t nfs localhost:/mount <mountpoint> (For Linux users)

API

The NFS server runs on a net.Listener to export a file system to NFS clients. Usage is structured similarly to many other golang network servers.

package main

import (
	"fmt"
	"log"
	"net"

	"github.com/go-git/go-billy/v5/memfs"
	nfs "github.com/willscott/go-nfs"
	nfshelper "github.com/willscott/go-nfs/helpers"
)

func main() {
	listener, err := net.Listen("tcp", ":0")
	panicOnErr(err, "starting TCP listener")
	fmt.Printf("Server running at %s\n", listener.Addr())
	mem := memfs.New()
	f, err := mem.Create("hello.txt")
	panicOnErr(err, "creating file")
	_, err = f.Write([]byte("hello world"))
	panicOnErr(err, "writing data")
	f.Close()
	handler := nfshelper.NewNullAuthHandler(mem)
	cacheHelper := nfshelper.NewCachingHandler(handler, 1)
	panicOnErr(nfs.Serve(listener, cacheHelper), "serving nfs")
}

func panicOnErr(err error, desc ...interface{}) {
	if err == nil {
		return
	}
	log.Println(desc...)
	log.Panicln(err)
}

Notes

  • Ports are typically determined through portmap. The need for running portmap (which is the only part that needs a privileged listening port) can be avoided through specific mount options. e.g. mount -o port=n,mountport=n -t nfs host:/mount /localmount

  • This server currently uses billy to provide a file system abstraction layer. There are some edges of the NFS protocol which do not translate to this abstraction.

    • NFS expects access to an inode or equivalent unique identifier to reference files in a file system. These are considered opaque identifiers here, which means they will not work as expected in cases of hard linking.
    • The billy abstraction layer does not extend to exposing uid and gid ownership of files. If ownership is important to your file system, you will need to ensure that the os.FileInfo meets additional constraints. In particular, the Sys() escape hatch is queried by this library, and if your file system populates a syscall.Stat_t concrete struct, the ownership specified in that object will be used.
  • Relevant RFCS: 5531 - RPC protocol, 1813 - NFSv3, 1094 - NFS