smallfz / libnfs-go

Experimental NFS(v4) server library
MIT License
24 stars 10 forks source link

Go Reference

NFS Server Library

Experimental NFSv4 server library in pure go.

The motive I started this project is mainly I need to immigrate a few projects to k8s and there are no other storage services except an OSS(like aws s3). So I need something to join OSS and k8s PV together. To me NFS is a interesting choice.

Currently this repo doesn't include any COS wrapper in it.

Getting start

To give it a try:

package main

import (
    "fmt"
    "os"

    "github.com/smallfz/libnfs-go/backend"
    "github.com/smallfz/libnfs-go/memfs"
    "github.com/smallfz/libnfs-go/server"
)

func main() {
    mfs := memfs.NewMemFS()
    backend := backend.New(mfs)

    mfs.MkdirAll("/test", os.FileMode(0755))
    mfs.MkdirAll("/test2", os.FileMode(0755))
    mfs.MkdirAll("/many", os.FileMode(0755))

    perm := os.FileMode(0755)
    for i := 0; i < 256; i++ {
        mfs.MkdirAll(fmt.Sprintf("/many/sub-%d", i+1), perm)
    }

    // TODO: replace the in-memory backend with your own implementation.
    // ....

    svr, err := server.NewServerTCP(":2049", backend)
    if err != nil {
        fmt.Printf("server.NewServerTCP: %v"\n, err)
        return
    }

    if err := svr.Serve(); err != nil {
        fmt.Printf("svr.Serve: %v\n", err)
    }
}

After the server started you can mount the in-memory filesystem to local:

on Mac:

mount -o nfsvers=4,noacl,tcp -t nfs localhost:/ /Users/smallfz/mnt

on Linux:

mount -o nfsvers=4,minorversion=0,noacl,tcp -t nfs localhost:/ /mnt

Status

Recent testing results of nfstest_posix with --nfsversion=4:

Contributing

Firing an issue if anything. Any advice is appreciated.