本文整理匯總了Golang中github.com/hanwen/go-fuse/fuse/nodefs.MountRoot函數的典型用法代碼示例。如果您正苦於以下問題:Golang MountRoot函數的具體用法?Golang MountRoot怎麽用?Golang MountRoot使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了MountRoot函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestNonseekable
func TestNonseekable(t *testing.T) {
fs := &nonseekFs{FileSystem: pathfs.NewDefaultFileSystem()}
fs.Length = 200 * 1024
dir, err := ioutil.TempDir("", "go-fuse-cache_test")
if err != nil {
t.Fatalf("failed: %v", err)
}
defer os.RemoveAll(dir)
nfs := pathfs.NewPathNodeFs(fs, nil)
state, _, err := nodefs.MountRoot(dir, nfs.Root(), nil)
if err != nil {
t.Fatalf("failed: %v", err)
}
state.SetDebug(VerboseTest())
defer state.Unmount()
go state.Serve()
f, err := os.Open(dir + "/file")
if err != nil {
t.Fatalf("failed: %v", err)
}
defer f.Close()
b := make([]byte, 200)
n, err := f.ReadAt(b, 20)
if err == nil || n > 0 {
t.Errorf("file was opened nonseekable, but seek successful")
}
}
示例2: setupCacheTest
func setupCacheTest(t *testing.T) (string, *pathfs.PathNodeFs, func()) {
dir, err := ioutil.TempDir("", "go-fuse-cachetest")
if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
os.Mkdir(dir+"/mnt", 0755)
os.Mkdir(dir+"/orig", 0755)
fs := &cacheFs{
pathfs.NewLoopbackFileSystem(dir + "/orig"),
}
pfs := pathfs.NewPathNodeFs(fs, nil)
state, conn, err := nodefs.MountRoot(dir+"/mnt", pfs.Root(), nil)
if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err)
}
state.SetDebug(VerboseTest())
conn.SetDebug(VerboseTest())
pfs.SetDebug(VerboseTest())
go state.Serve()
return dir, pfs, func() {
err := state.Unmount()
if err == nil {
os.RemoveAll(dir)
}
}
}
示例3: main
func main() {
if len(os.Args) != 2 {
fmt.Println("Usage: %s <mountpath>")
os.Exit(1)
}
root := os.Args[1]
dialOpts := []grpc.DialOption{grpc.WithInsecure()}
conn, err := grpc.Dial("127.0.0.1:50000", dialOpts...)
if err != nil {
log.Fatal(err)
}
cli := pb.NewPathFSClient(conn)
fs := grpcfs.New(cli)
nfs := pathfs.NewPathNodeFs(fs, nil)
server, _, err := nodefs.MountRoot(root, nfs.Root(), nil)
if err != nil {
log.Fatal(err)
}
go server.Serve()
log.Printf("Fs mounted to root %s", root)
sigCh := make(chan os.Signal)
signal.Notify(sigCh, os.Interrupt)
for range sigCh {
server.Unmount()
os.Exit(0)
}
}
示例4: main
func main() {
if len(os.Args) != 2 {
fmt.Println("Usage: %s <mountpath>")
os.Exit(1)
}
root := os.Args[1]
hfs := &HelloFs{FileSystem: pathfs.NewDefaultFileSystem()}
nfs := pathfs.NewPathNodeFs(hfs, nil)
fuseSrv, _, err := nodefs.MountRoot(root, nfs.Root(), nil)
if err != nil {
log.Fatal(err)
}
go fuseSrv.Serve()
l, err := net.Listen("tcp", "127.0.0.1:50000")
if err != nil {
log.Fatal(err)
}
s := grpc.NewServer()
pb.RegisterPathFSServer(s, server.New(hfs))
go s.Serve(l)
log.Printf("Listen on %s for dir %s", l.Addr(), root)
sigCh := make(chan os.Signal)
signal.Notify(sigCh, os.Interrupt)
for range sigCh {
fuseSrv.Unmount()
s.Stop()
os.Exit(0)
}
}
示例5: New
func New(config *conf.Fuse, logger log_driver.Logger) (*GitFs, error) {
gitfsDir, err := gitfsDir(logger)
if err != nil {
return nil, err
}
defaultfs := pathfs.NewDefaultFileSystem()
gitfs := &GitFs{FileSystem: pathfs.NewReadonlyFileSystem(defaultfs), GitRepoDir: config.GitRepoDir, GitFsDir: gitfsDir, logger: logger}
fs := pathfs.NewPathNodeFs(gitfs, nil)
server, _, err := nodefs.MountRoot(gitfsDir, fs.Root(), nil)
if err != nil {
logger.Errorf("Failed to mount GitFS on %s due to %s", gitfsDir, err)
return nil, err
}
logger.Debugf("Mount GitFs on %s", gitfsDir)
gitfs.server = server
server.SetDebug(config.Debug)
gitfs.cache, err = cache.New(1024)
if err != nil {
logger.Errorf("Failed to initialize object cache due to %s\n", err)
return nil, err
}
return gitfs, nil
}
示例6: TestLiveness
func TestLiveness(t *testing.T) {
dir := testutil.TempDir()
defer os.RemoveAll(dir)
root := nodefs.NewDefaultNode()
s, _, err := nodefs.MountRoot(dir, root, nil)
if err != nil {
t.Fatalf("MountRoot: %v", err)
}
go s.Serve()
if err := s.WaitMount(); err != nil {
t.Fatal("WaitMount", err)
}
defer s.Unmount()
if _, err := ioutil.ReadDir(dir); err != nil {
t.Fatalf("ReadDir: %v", err)
}
// We previously encountered a sitation where a finalizer would close our fd out from under us. Try to force both finalizers to run and object destruction to complete.
runtime.GC()
runtime.GC()
if _, err := ioutil.ReadDir(dir); err != nil {
t.Fatalf("ReadDir: %v", err)
}
}
示例7: setupFs
func setupFs(fs pathfs.FileSystem) (string, func()) {
opts := &nodefs.Options{
EntryTimeout: 0.0,
AttrTimeout: 0.0,
NegativeTimeout: 0.0,
}
mountPoint, _ := ioutil.TempDir("", "stat_test")
nfs := pathfs.NewPathNodeFs(fs, nil)
state, _, err := nodefs.MountRoot(mountPoint, nfs.Root(), opts)
if err != nil {
panic(fmt.Sprintf("cannot mount %v", err)) // ugh - benchmark has no error methods.
}
lmap := NewLatencyMap()
state.RecordLatencies(lmap)
// state.SetDebug(true)
go state.Serve()
return mountPoint, func() {
lc, lns := lmap.Get("LOOKUP")
gc, gns := lmap.Get("GETATTR")
fmt.Printf("GETATTR %v/call n=%d, LOOKUP %v/call n=%d\n",
gns/time.Duration(gc), gc,
lns/time.Duration(lc), lc)
err := state.Unmount()
if err != nil {
log.Println("error during unmount", err)
} else {
os.RemoveAll(mountPoint)
}
}
}
示例8: Create
func (d *etcDriver) Create(rq dkvolume.Request) dkvolume.Response {
var res dkvolume.Response
if !strings.HasPrefix(rq.Name, "@") {
return responseErrorString("a etcd path has to start with a @")
}
d.mux.Lock()
defer d.mux.Unlock()
_, ok := d.mountpoints[rq.Name]
if ok {
return res
}
pt := d.createPath(rq.Name)
if err := os.MkdirAll(pt, 0755); err != nil {
return responseError(fmt.Errorf("cannot mkdir: %s", err))
}
rootfs := "/" + d.asEtcdRoot(rq.Name)
root := pathfs.NewPrefixFileSystem(&d.etcdbackend, rootfs)
nfs := pathfs.NewPathNodeFs(root, nil)
server, _, err := nodefs.MountRoot(pt, nfs.Root(), nil)
if err != nil {
return responseError(fmt.Errorf("cannot mount root : %s", err))
}
es := etcdFuseServer{pt, server, 0}
d.mountpoints[rq.Name] = &es
go server.Serve()
return res
}
示例9: TestDefaultNodeMount
func TestDefaultNodeMount(t *testing.T) {
dir, err := ioutil.TempDir("", "go-fuse")
if err != nil {
t.Fatalf("TempDir: %v", err)
}
defer os.RemoveAll(dir)
root := nodefs.NewDefaultNode()
s, conn, err := nodefs.MountRoot(dir, root, nil)
if err != nil {
t.Fatalf("MountRoot: %v", err)
}
go s.Serve()
defer s.Unmount()
if err := conn.Mount(root.Inode(), "sub", nodefs.NewDefaultNode(), nil); !err.Ok() {
t.Fatalf("Mount: %v", err)
}
if entries, err := ioutil.ReadDir(dir); err != nil {
t.Fatalf("ReadDir: %v", err)
} else if len(entries) != 1 {
t.Fatalf("got %d entries", len(entries))
} else if entries[0].Name() != "sub" {
t.Fatalf("got %q, want %q", entries[0].Name(), "sub")
}
}
示例10: NewNotifyTest
func NewNotifyTest(t *testing.T) *NotifyTest {
me := &NotifyTest{}
me.fs = newNotifyFs()
var err error
me.dir, err = ioutil.TempDir("", "go-fuse-notify_test")
if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
entryTtl := 100 * time.Millisecond
opts := &nodefs.Options{
EntryTimeout: entryTtl,
AttrTimeout: entryTtl,
NegativeTimeout: entryTtl,
Debug: VerboseTest(),
}
me.pathfs = pathfs.NewPathNodeFs(me.fs, nil)
me.state, me.connector, err = nodefs.MountRoot(me.dir, me.pathfs.Root(), opts)
if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err)
}
go me.state.Serve()
if err := me.state.WaitMount(); err != nil {
t.Fatal("WaitMount", err)
}
return me
}
示例11: TestDefaultXAttr
func TestDefaultXAttr(t *testing.T) {
dir := testutil.TempDir()
defer os.RemoveAll(dir)
root := &xattrNode{
Node: nodefs.NewDefaultNode(),
}
opts := nodefs.NewOptions()
opts.Debug = testutil.VerboseTest()
s, _, err := nodefs.MountRoot(dir, root, opts)
if err != nil {
t.Fatalf("MountRoot: %v", err)
}
go s.Serve()
if err := s.WaitMount(); err != nil {
t.Fatal("WaitMount", err)
}
defer s.Unmount()
var data [1024]byte
sz, err := syscall.Getxattr(filepath.Join(dir, "child"), "attr", data[:])
if err != nil {
t.Fatalf("Getxattr: %v", err)
} else if val := string(data[:sz]); val != "value" {
t.Fatalf("got %v, want 'value'", val)
}
}
示例12: setup
func setup(t *testing.T) (workdir string, cleanup func()) {
wd, _ := ioutil.TempDir("", "")
err := os.Mkdir(wd+"/mnt", 0700)
if err != nil {
t.Fatalf("Mkdir failed: %v", err)
}
err = os.Mkdir(wd+"/store", 0700)
if err != nil {
t.Fatalf("Mkdir failed: %v", err)
}
os.Mkdir(wd+"/ro", 0700)
if err != nil {
t.Fatalf("Mkdir failed: %v", err)
}
WriteFile(t, wd+"/ro/file1", "file1")
WriteFile(t, wd+"/ro/file2", "file2")
fs := NewAutoUnionFs(wd+"/store", testAOpts)
nfs := pathfs.NewPathNodeFs(fs, nil)
state, _, err := nodefs.MountRoot(wd+"/mnt", nfs.Root(), &testAOpts.Options)
if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err)
}
fs.SetDebug(VerboseTest())
go state.Serve()
return wd, func() {
state.Unmount()
os.RemoveAll(wd)
}
}
示例13: defaultReadTest
func defaultReadTest(t *testing.T) (root string, cleanup func()) {
fs := &DefaultReadFS{
FileSystem: pathfs.NewDefaultFileSystem(),
size: 22,
}
var err error
dir, err := ioutil.TempDir("", "go-fuse")
if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
pathfs := pathfs.NewPathNodeFs(fs, nil)
opts := nodefs.NewOptions()
opts.Debug = VerboseTest()
state, _, err := nodefs.MountRoot(dir, pathfs.Root(), opts)
if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err)
}
go state.Serve()
if err := state.WaitMount(); err != nil {
t.Fatal("WaitMount", err)
}
return dir, func() {
state.Unmount()
os.Remove(dir)
}
}
示例14: setupMulti
func setupMulti() (*testCase, error) {
dir, err := ioutil.TempDir("", "fs_test")
if err != nil {
return nil, err
}
repo, err := setupRepo(filepath.Join(dir, "repo"))
if err != nil {
return nil, err
}
root := NewMultiGitFSRoot(nil)
if err != nil {
return nil, err
}
mnt := filepath.Join(dir, "mnt")
if err := os.Mkdir(mnt, 0755); err != nil {
return nil, err
}
server, _, err := nodefs.MountRoot(mnt, root, nil)
go server.Serve()
if err != nil {
return nil, err
}
return &testCase{
repo,
server,
mnt,
}, nil
}
示例15: setupBasic
func setupBasic(opts *GitFSOptions) (*testCase, error) {
dir, err := ioutil.TempDir("", "fs_test")
if err != nil {
return nil, err
}
repo, err := setupRepo(filepath.Join(dir, "repo"))
if err != nil {
return nil, err
}
root, err := NewTreeFSRoot(repo, "refs/heads/master", nil)
if err != nil {
return nil, err
}
mnt := filepath.Join(dir, "mnt")
if err := os.Mkdir(mnt, 0755); err != nil {
return nil, err
}
server, _, err := nodefs.MountRoot(mnt, root, nil)
server.SetDebug(true)
go server.Serve()
if err != nil {
return nil, err
}
return &testCase{
repo,
server,
mnt,
}, nil
}