func (r *Repl) dial() error { lt, err := rfs.Import(r.Laddr) if err != nil { return fmt.Errorf("%s: %s", r.Laddr, err) } rt, err := rfs.Import(r.Raddr) if err != nil { return fmt.Errorf("%s: %s", r.Raddr, err) } r.lfs = lt r.rfs = rt return nil }
func mkrfs(addr string) (zx.RWTree, *zx.Flags, *zx.IOstats, error) { fs, err := rfs.Import(addr) if err != nil { return nil, nil, nil, err } if r, ok := fs.(*rfs.Rfs); ok && !nopings { r.Pings(30 * time.Second) } var st *zx.IOstats if sflag { switch x := fs.(type) { case *lfs.Lfs: x.IOstats = &zx.IOstats{} st = x.IOstats case *rfs.Rfs: x.IOstats = &zx.IOstats{} st = x.IOstats } } var flg *zx.Flags if r, ok := fs.(*rfs.Rfs); ok { flg = r.Flags } else if l, ok := fs.(*lfs.Lfs); ok { flg = l.Flags } else { flg = &zx.Flags{} } return fs, flg, st, nil }
// If ln is "path addr" and addr is of the form // net ! addr ! proto ! tree ! path // or // /one/path // the dial the tree and walk to the path. func specialForm(ln string) (string, zx.Dir) { if len(ln)==0 || ln[0]!='/' { return "", nil } toks := strings.Fields(ln) if len(toks)!=2 || len(toks[0])==0 || len(toks[1])==0 { return "", nil } p, addr := toks[0], toks[1] if addr[0] == '/' { addr = "*!*!lfs!main!" + addr } atoks := strings.SplitN(addr, "!", -1) if len(atoks) < 2 { return "", nil } t, err := rfs.Import(addr) if err != nil { dbg.Warn("ns: %s: import: %s", ln, err) return "", nil } path := "/" if len(atoks)>=5 && atoks[2]!="lfs" { path = atoks[4] } d, err := zx.Stat(t, path) if err != nil { dbg.Warn("ns: %s: stat: %s", ln, err) return "", nil } return p, d }
func mkrfs(addr string) (zx.Tree, *zx.IOstats, error) { fs, err := rfs.Import(addr) if err != nil { return nil, nil, fmt.Errorf("rfs: %s: %s", addr, err) } var st *zx.IOstats if sflag { switch x := fs.(type) { case *lfs.Lfs: x.IOstats = &zx.IOstats{} st = x.IOstats case *rfs.Rfs: x.IOstats = &zx.IOstats{} st = x.IOstats } } return fs, st, nil }
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 }