Exemple #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
}
Exemple #2
0
func NewWorker(options *WorkerOptions) *Worker {
	copied := *options
	options = &copied
	if options.ReapCount == 0 {
		options.ReapCount = 4
	}
	if options.ReportInterval == 0 {
		options.ReportInterval = 60 * time.Second
	}
	if options.LameDuckPeriod == 0 {
		options.LameDuckPeriod = 5 * time.Second
	}

	if fi, _ := os.Stat(options.TempDir); fi == nil || !fi.IsDir() {
		log.Fatalf("directory %s does not exist, or is not a dir", options.TempDir)
	}
	// TODO - check that we can do renames from temp to cache.

	cache := cba.NewStore(&options.StoreOptions)

	me := &Worker{
		content:    cache,
		pending:    NewPendingConnections(),
		rpcServer:  rpc.NewServer(),
		stats:      stats.NewServerStats(),
		options:    &copied,
		accepting:  true,
		canRestart: true,
	}
	me.stats.PhaseOrder = []string{"run", "fuse", "reap"}
	me.mirrors = NewWorkerMirrors(me)
	me.stopListener = make(chan int, 1)
	me.rpcServer.Register(me)
	return me
}
Exemple #3
0
func main() {
	// coordinator := flag.String("coordinator", "localhost:1230", "address of coordinator. Overrides -workers")
	secretFile := flag.String("secret", "secret.txt", "file containing password.")
	cachedir := flag.String("cachedir", "/var/cache/termite/worker-cache", "content cache")
	port := flag.Int("port", 0, "RPC port")

	flag.Parse()

	secret, err := ioutil.ReadFile(*secretFile)
	if err != nil {
		log.Fatal("ReadFile", err)
	}
	opts := cba.StoreOptions{
		Dir: *cachedir,
	}
	store := cba.NewStore(&opts)
	listener := termite.AuthenticatedListener(*port, secret, 10)
	for {
		conn, err := listener.Accept()
		if err == syscall.EINVAL {
			break
		}
		if err != nil {
			if e, ok := err.(*net.OpError); ok && e.Err == syscall.EINVAL {
				break
			}
			log.Println("me.listener", err)
			break
		}

		log.Println("Authenticated connection from", conn.RemoteAddr())
		go store.ServeConn(conn)
	}
}