示例#1
0
func newRpcFsTestCase(t *testing.T) (me *rpcFsTestCase) {
	me = &rpcFsTestCase{tester: t}
	me.tmp, _ = ioutil.TempDir("", "term-fss")

	me.mnt = me.tmp + "/mnt"
	me.orig = me.tmp + "/orig"
	srvCache := me.tmp + "/server-cache"

	os.Mkdir(me.mnt, 0700)
	os.Mkdir(me.orig, 0700)

	copts := cba.StoreOptions{
		Dir: srvCache,
	}
	me.serverStore = cba.NewStore(&copts)
	me.attr = attr.NewAttributeCache(
		func(n string) *attr.FileAttr { return me.getattr(n) },
		func(n string) *fuse.Attr {
			return StatForTest(t, filepath.Join(me.orig, n))
		})
	me.attr.Paranoia = true
	me.server = NewFsServer(me.attr, me.serverStore)

	var err error
	me.sockL, me.sockR, err = unixSocketpair()
	if err != nil {
		t.Fatal(err)
	}
	me.contentL, me.contentR, err = unixSocketpair()
	if err != nil {
		t.Fatal(err)
	}

	rpcServer := rpc.NewServer()
	rpcServer.Register(me.server)
	go rpcServer.ServeConn(me.sockL)
	go me.serverStore.ServeConn(me.contentL)
	rpcClient := rpc.NewClient(me.sockR)
	cOpts := cba.StoreOptions{
		Dir: me.tmp + "/client-cache",
	}
	me.clientStore = cba.NewStore(&cOpts)
	me.rpcFs = NewRpcFs(rpcClient, me.clientStore, me.contentR)
	me.rpcFs.id = "rpcfs_test"
	nfs := fuse.NewPathNodeFs(me.rpcFs, nil)
	me.state, _, err = fuse.MountNodeFileSystem(me.mnt, nfs, nil)
	me.state.Debug = fuse.VerboseTest()
	if err != nil {
		t.Fatal("Mount", err)
	}

	go me.state.Loop()
	return me
}
示例#2
0
文件: rpcfs.go 项目: hanwen/termite
func NewRpcFs(attrClient *attr.Client, cache *cba.Store, contentConn io.ReadWriteCloser) *RpcFs {
	fs := &RpcFs{
		FileSystem:    pathfs.NewDefaultFileSystem(),
		attrClient:    attrClient,
		contentClient: cache.NewClient(contentConn),
		timings:       stats.NewTimerStats(),
	}

	fs.attr = attr.NewAttributeCache(
		func(n string) *attr.FileAttr {
			a := attr.FileAttr{}
			err := attrClient.GetAttr(n, &a)
			if err != nil {
				log.Printf("GetAttr %s: %v", n, err)
				return nil
			}
			return &a
		}, nil)
	fs.cache = cache
	return fs
}