Commit afbcb85e authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

example/loopback: use new nodefs library

parent b14c4e22
...@@ -14,14 +14,11 @@ import ( ...@@ -14,14 +14,11 @@ import (
"os" "os"
"os/signal" "os/signal"
"path" "path"
"path/filepath"
"runtime/pprof" "runtime/pprof"
"syscall" "syscall"
"time" "time"
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/nodefs"
"github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/fuse/pathfs"
) )
func writeMemProfile(fn string, sigs <-chan os.Signal) { func writeMemProfile(fn string, sigs <-chan os.Signal) {
...@@ -48,7 +45,6 @@ func main() { ...@@ -48,7 +45,6 @@ func main() {
// Scans the arg list and sets up flags // Scans the arg list and sets up flags
debug := flag.Bool("debug", false, "print debugging messages.") debug := flag.Bool("debug", false, "print debugging messages.")
other := flag.Bool("allow-other", false, "mount with -o allowother.") other := flag.Bool("allow-other", false, "mount with -o allowother.")
enableLinks := flag.Bool("l", false, "Enable hard link support")
cpuprofile := flag.String("cpuprofile", "", "write cpu profile to this file") cpuprofile := flag.String("cpuprofile", "", "write cpu profile to this file")
memprofile := flag.String("memprofile", "", "write memory profile to this file") memprofile := flag.String("memprofile", "", "write memory profile to this file")
flag.Parse() flag.Parse()
...@@ -78,36 +74,26 @@ func main() { ...@@ -78,36 +74,26 @@ func main() {
fmt.Printf("Note: You must unmount gracefully, otherwise the profile file(s) will stay empty!\n") fmt.Printf("Note: You must unmount gracefully, otherwise the profile file(s) will stay empty!\n")
} }
var finalFs pathfs.FileSystem
orig := flag.Arg(1) orig := flag.Arg(1)
loopbackfs := pathfs.NewLoopbackFileSystem(orig) loopbackRoot, err := nodefs.NewLoopbackRoot(orig)
finalFs = loopbackfs if err != nil {
log.Fatalf("NewLoopbackRoot(%s): %v\n", orig, err)
}
sec := time.Second
opts := &nodefs.Options{ opts := &nodefs.Options{
// These options are to be compatible with libfuse defaults, // These options are to be compatible with libfuse defaults,
// making benchmarking easier. // making benchmarking easier.
NegativeTimeout: time.Second, AttrTimeout: &sec,
AttrTimeout: time.Second, EntryTimeout: &sec,
EntryTimeout: time.Second,
}
// Enable ClientInodes so hard links work
pathFsOpts := &pathfs.PathNodeFsOptions{ClientInodes: *enableLinks}
pathFs := pathfs.NewPathNodeFs(finalFs, pathFsOpts)
conn := nodefs.NewFileSystemConnector(pathFs.Root(), opts)
mountPoint := flag.Arg(0)
origAbs, _ := filepath.Abs(orig)
mOpts := &fuse.MountOptions{
AllowOther: *other,
Name: "loopbackfs",
FsName: origAbs,
Debug: *debug,
} }
state, err := fuse.NewServer(conn.RawFS(), mountPoint, mOpts) opts.Debug = *debug
opts.AllowOther = *other
server, err := nodefs.Mount(flag.Arg(0), loopbackRoot, opts)
if err != nil { if err != nil {
fmt.Printf("Mount fail: %v\n", err) log.Fatalf("Mount fail: %v\n", err)
os.Exit(1)
} }
fmt.Println("Mounted!") fmt.Println("Mounted!")
state.Serve() server.Wait()
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment