Пример #1
0
func serveFor(t zx.Tree, c nchan.Conn) {
	ai, err := auth.AtServer(c, "", "zx", "finder")
	if err != nil && err != auth.ErrDisabled {
		dbg.Warn("auth %s: %s\n", c.Tag, err)
		close(c.In, err)
		close(c.Out, err)
		return
	}
	srv := Serve("rfs:"+c.Tag, c, ai, RW, t)
	srv.Debug = false
}
Пример #2
0
func main() {
	defer dbg.Exits("")
	os.Args[0] = "zx"
	port = "8002"
	opts.NewFlag("p", "port: tcp server port (8002 by default)", &port)
	wport = "9002"
	opts.NewFlag("w", "port: wax http server port", &wport)
	svc = "zx"
	opts.NewFlag("s", "srv: service name (zx by default)", &svc)
	addr = "*!*!zx"
	opts.NewFlag("a", "addr: service address (*!*!zx by default)", &addr)
	opts.NewFlag("v", "report users logged in/out (verbose)", &Verbose)
	opts.NewFlag("D", "debug", &Debug)
	opts.NewFlag("Z", "verbose debug", &Zdebug)
	opts.NewFlag("M", "debug mutexes", &cfs.DebugLocks)
	nopings := false
	opts.NewFlag("k", "do not use zx keep alives", &nopings)
	args, err := opts.Parse(os.Args)
	if err != nil {
		usage(err)
	}
	if len(args) == 0 {
		usage(errors.New("missing arguments"))
	}
	Debug = Debug || Zdebug
	auth.Debug = Debug
	cfs.Debug = Debug
	rfs.Verb = Verbose
	var trs []zx.Tree
	var ros = map[bool]string{false: "rw", true: "ro"}

	for i := 0; i < len(args); i++ {
		al := strings.Split(args[i], "!")
		if len(al) == 1 {
			al = append(al, al[0])
			al[0] = path.Base(al[0])
		}
		ronly := false
		caching := true
		if len(al) == 3 && strings.Contains(al[2], "ro") {
			ronly = true
		}
		if len(al) == 3 && strings.Contains(al[2], "nc") {
			caching = false
		}
		t, err := lfs.New(al[0], al[1], ronly && !caching)
		if err != nil {
			dbg.Warn("%s: %s", al[0], err)
			continue
		}
		t.ReadAttrs(true)
		t.SaveAttrs(caching)
		t.IOstats = &zx.IOstats{}
		fp, _ := filepath.Abs(al[1])
		if caching {
			dbg.Warn("%s mfs + lfs %s caching", al[0], ros[ronly])
			cache, err := mfs.New("mfs:" + al[0])
			if err != nil {
				dbg.Warn("%s: mfs: %s", al[0], err)
				continue
			}
			cache.IOstats = &zx.IOstats{}
			cache.Dbg = Zdebug
			cache.WstatAll = true // cfs must be able to write it all
			x, err := cfs.New(al[0], cache, t, ronly)
			if err != nil {
				dbg.Warn("%s: cfs: %s", al[0], err)
				continue
			}
			x.IOstats = &zx.IOstats{}
			zxw[al[0]] = fp
			trs = append(trs, x)

		} else {
			dbg.Warn("%s lfs %s uncached", al[0], ros[ronly])
			zxw[al[0]] = fp
			t.Dbg = Debug
			trs = append(trs, t)
		}
	}
	if len(trs) == 0 {
		dbg.Fatal("no trees to serve")
	}

	ds.DefSvc(svc, port)
	Vprintf("%s: serve %s...\n", os.Args[0], addr)
	cc, _, err := ds.Serve(os.Args[0], addr)
	if err != nil {
		dbg.Fatal("%s: serve: %s", os.Args[0], err)
	}

	go zxwax()
	for c := range cc {
		go func(c nchan.Conn) {
			ai, err := auth.AtServer(c, "", "zx", "finder")
			if err != nil && err != auth.ErrDisabled {
				Vprintf("%s: auth %s: %s\n", os.Args[0], c.Tag, err)
				close(c.In, err)
				close(c.Out, err)
				return
			}
			srv := rfs.Serve("rfs:"+c.Tag, c, ai, rfs.RW, trs...)
			if false {
				srv.Debug = Debug
			}
			srv.Pings = !nopings

		}(*c)
	}
	if err := cerror(cc); err != nil {
		dbg.Fatal("%s: serve: %s", os.Args[0], err)
	}
}
Пример #3
0
func main() {
	defer dbg.Exits("")
	os.Args[0] = "zx"
	port = "8002"
	opts.NewFlag("p", "port: tcp server port", &port)
	wport = "9002"
	opts.NewFlag("w", "port: wax http server port", &wport)
	svc = "zx"
	opts.NewFlag("s", "srv: service name", &svc)
	addr = "*!*!zx"
	opts.NewFlag("a", "addr: service address", &addr)
	opts.NewFlag("D", "debug", &Debug)
	opts.NewFlag("Z", "verbose debug", &Zdebug)
	opts.NewFlag("k", "make cfg entries persist in the ns", &Persist)
	opts.NewFlag("N", "use new cfs", &New)
	args, err := opts.Parse(os.Args)
	if err != nil {
		usage(err)
	}
	if len(args) == 0 {
		usage(nil)
	}
	Debug = Debug || Zdebug
	auth.Debug = Debug
	ncfs.Debug = Debug
	cfs.Debug = Debug
	cfs.Cdebug = Zdebug
	cfs.Zdebug = Zdebug
	rfs.Verb = Verbose
	var trs []zx.Tree
	var ros = map[bool]string{false: "rw", true: "ro"}

	for i := 0; i < len(args); i++ {
		al := strings.Split(args[i], "!")
		if len(al) == 1 {
			al = append(al, al[0])
			al[0] = path.Base(al[0])
		}
		ronly := false
		caching := true
		if len(al) == 3 && strings.Contains(al[2], "ro") {
			ronly = true
		}
		if len(al) == 3 && strings.Contains(al[2], "nc") {
			caching = false
		}
		t, err := lfs.New(al[0], al[1], ronly && !caching)
		if err != nil {
			dbg.Warn("%s: %s", al[0], err)
			continue
		}
		t.ReadAttrs(true)
		t.SaveAttrs(caching)
		t.IOstats = &zx.IOstats{}
		fp, _ := filepath.Abs(al[1])
		if New && caching {
			dbg.Warn("%s mfs + lfs %s caching", al[0], ros[ronly])
			cache, err := mfs.New("mfs:" + al[0])
			if err != nil {
				dbg.Warn("%s: mfs: %s", al[0], err)
				continue
			}
			cache.IOstats = &zx.IOstats{}
			cache.Dbg = Zdebug
			x, err := ncfs.New("cfs", cache, t, ronly)
			if err != nil {
				dbg.Warn("%s: cfs: %s", al[0], err)
				continue
			}
			x.IOstats = &zx.IOstats{}
			zxw[al[0]] = fp
			trs = append(trs, x)

		} else if !New && caching {
			dbg.Warn("%s old cfs + lfs %s caching", al[0], ros[ronly])
			x, err := cfs.New("", t, ronly)
			if err != nil {
				dbg.Warn("%s: cfs: %s", al[0], err)
				continue
			}
			x.IOstats = &zx.IOstats{}
			zxw[al[0]] = fp
			trs = append(trs, x)
		} else {
			dbg.Warn("%s lfs %s uncached", al[0], ros[ronly])
			zxw[al[0]] = fp
			t.Dbg = Debug
			trs = append(trs, t)
		}
	}
	if len(trs) == 0 {
		dbg.Fatal("no trees to serve")
	}

	ds.DefSvc(svc, port)
	Vprintf("%s: serve %s...\n", os.Args[0], addr)
	cc, _, err := ds.Serve(os.Args[0], addr)
	if err != nil {
		dbg.Fatal("%s: serve: %s", os.Args[0], err)
	}

	go zxwax()
	for c := range cc {
		go func(c nchan.Conn) {
			ai, err := auth.AtServer(c, "", "zx", "finder")
			if err != nil && err != auth.ErrDisabled {
				Vprintf("%s: auth %s: %s\n", os.Args[0], c.Tag, err)
				close(c.In, err)
				close(c.Out, err)
				return
			}
			srv := rfs.Serve("rfs:"+c.Tag, c, ai, rfs.RW, trs...)
			if false {
				srv.Debug = Debug
			}

		}(*c)
	}
	if err := cerror(cc); err != nil {
		dbg.Fatal("%s: serve: %s", os.Args[0], err)
	}
}
Пример #4
0
func mkrns(t *testing.T, d bool) *Tree {
	fstest.MkTree(t, tdir)
	lfs1, err := lfs.New(tdir, tdir, lfs.RW)
	if err != nil {
		t.Fatalf("lfs: %s", err)
	}
	hs, hc := fifo.NewChanHandler()
	s := fifo.New("rfs", "rfs", hs)
	if err = s.Serve(); err != nil {
		t.Fatalf("%s", err)
	}
	go func() {
		for c := range hc {
			ai, err := auth.AtServer(*c, "", "zx", "finder")
			if err!=nil && err!=auth.ErrDisabled {
				dbg.Warn("auth %s: %s\n", c.Tag, err)
				close(c.In, err)
				close(c.Out, err)
				return
			}
			rfs.Serve("srv", *c, ai, rfs.RW, lfs1)
		}
	}()
	rfs1, err := rfs.Import("fifo!*!rfs")
	if err != nil {
		t.Fatalf("lfs: %s", err)
	}
	ns := New()

	ns.Debug = d
	ns.DebugFind = d

	root1, err := zx.Stat(lfs1, "/")
	if err != nil {
		t.Fatalf("stat: %s", err)
	}
	err = <-ns.Mount("/", root1, Repl)
	if err != nil {
		t.Fatalf("mount: %s", err)
	}

	root2, err := zx.Stat(rfs1, "/")
	if err != nil {
		t.Fatalf("stat: %s", err)
	}
	err = <-ns.Mount("/a/b", root2, Repl)
	if err != nil {
		t.Fatalf("mount: %s", err)
	}
	d1 := zx.Dir{"path": "x", "name": "x", "proto": "p1"}
	err = <-ns.Mount("/d", d1, Before)
	if err != nil {
		t.Fatalf("mount: %s", err)
	}
	d2 := zx.Dir{"path": "x", "name": "x", "proto": "p2"}
	err = <-ns.Mount("/d", d2, After)
	if err != nil {
		t.Fatalf("mount: %s", err)
	}
	err = <-ns.Mount("/d", d2, After)
	if err != nil {
		t.Fatalf("mount: %s", err)
	}
	printf("ns is `%s`\n", ns)
	return ns
}