-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
69 lines (57 loc) · 1.57 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2012 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"flag"
"io/ioutil"
"log"
"os"
"runtime/pprof"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/p4fuse/p4"
)
func main() {
fsdebug := flag.Bool("fs-debug", false, "switch on FS debugging")
p4port := flag.String("p4-server", "", "address for P4 server")
p4binary := flag.String("p4-binary", "p4", "binary for P4 commandline client")
backingDir := flag.String("backing", "", "directory to store file contents.")
profile := flag.String("profile", "", "record cpu profile.")
flag.Parse()
if len(flag.Args()) != 1 {
log.Fatal("Usage: p4fs MOUNT-POINT")
}
mountpoint := flag.Arg(0)
opts := p4.ConnOptions{
Binary: *p4binary,
Address: *p4port,
}
p4conn := p4.NewConn(opts)
if *backingDir == "" {
d, err := ioutil.TempDir("", "p4fs")
if err != nil {
log.Fatalf("TempDir failed: %v", err)
}
*backingDir = d
defer os.RemoveAll(d)
}
root := NewP4FSRoot(p4conn, *backingDir)
conn := nodefs.NewFileSystemConnector(root, nodefs.NewOptions())
mount, err := fuse.NewServer(conn.RawFS(),mountpoint, nil)
if err != nil {
log.Fatalf("mount failed: %v", err)
}
conn.SetDebug(*fsdebug)
mount.SetDebug(*fsdebug)
log.Println("starting FUSE.")
if *profile != "" {
profFile, err := os.Create(*profile)
if err != nil {
log.Fatalf("os.Create: %v", err)
}
pprof.StartCPUProfile(profFile)
defer pprof.StopCPUProfile()
}
mount.Serve()
}