Exemple #1
0
func main() {
	defer app.Exiting()
	x := app.New()
	stacks := false
	opts.NewFlag("F", "debug fuse requests", &zxfs.Debug)
	opts.NewFlag("D", "debug", &x.Debug)
	opts.NewFlag("s", "statistics", &sflag)
	opts.NewFlag("x", "addr: re-export locally the ql tree to this address", &xaddr)
	opts.NewFlag("S", "dump stacks on unmount for debugging", &stacks)
	args, err := opts.Parse(x.Args)
	if err != nil {
		app.Warn("%s", err)
		opts.Usage()
		app.Exits(err)
	}
	switch len(args) {
	case 0:
	case 1:
		mntdir = args[1]
	default:
		app.Warn("wrong number of arguments")
		opts.Usage()
		app.Exits("usage")
	}
	dprintf("debug on\n")
	qfs, err := qlfs.New("qlfs")
	if err != nil {
		app.Fatal(err)
	}
	qfs.Dbg = x.Debug
	qfs.Flags.Add("fdebug", &zxfs.Debug)
	st := &zx.IOstats{}
	qfs.IOstats = st
	if xaddr != "" {
		rfs.Server(qfs, xaddr)
	}
	err = zxfs.MountServer(qfs, mntdir)
	if sflag {
		st.Averages()
		app.Warn("%s iostats:\n%s\n", qfs.Name(), st)
	}
	if stacks {
		app.Warn("*** PANICING ON USER REQUEST (-S) ***")
		panic("stack dump")
	}
	if err != nil {
		app.Fatal("%s", err)
	}
	app.Warn("unmounted: exiting")
}
Exemple #2
0
func mkfs(addr string, quiet bool) (zx.Tree, func(), error) {
	if len(addr) == 0 {
		dbg.Warn("missing address")
		opts.Usage()
		dbg.Fatal("usage")
	}
	dbp := &fs.Debug
	var m, fs zx.RWTree
	var fsst *zx.IOstats
	var err error
	var lflags, flags *zx.Flags
	if _, err = os.Stat(addr); err == nil {
		fs, flags, fsst, err = mklfs(addr)
	} else {
		fs, flags, fsst, err = mkrfs(addr)
	}
	if err != nil {
		return nil, nil, err
	}

	switch {
	case nocache:
		dbg.Warn("%s: uncached", addr)
		if xaddr != "" {
			rfs.Server(fs, xaddr)
		}
		fn := func() {}
		if sflag {
			fn = func() {
				fsst.Averages()
				dbg.Warn("%s iostats:\n%s\n", fs.Name(), fsst)
			}
		}
		return fs, fn, nil
	case lfscache != "":
		dbg.Warn("%s: lfs cache %s", addr, lfscache)
		m, lflags, err = dcache()
	case mlfscache != "":
		dbg.Warn("%s: mdfs cache %s", addr, mlfscache)
		m, lflags, err = mdcache()
	default:
		dbg.Warn("%s: mfs cache", addr)
		m, lflags, err = mcache()
	}
	if err != nil {
		return nil, nil, err
	}

	cfs.Debug = zxdebug
	xfs, err := cfs.New("cfs", m, fs, rflag)
	if err != nil {
		return nil, nil, fmt.Errorf("cfs: %s", err)
	}
	xfs.Flags.Add("rdebug", &flags.Dbg)
	if lflags != nil {
		xfs.Flags.Add("ldebug", &lflags.Dbg)
	}
	xfs.Flags.Add("fdebug", &zxfs.Debug)
	xfs.Flags.Add("vdebug", dbp)
	xfs.Flags.Set("verbsync", !quiet)
	st := &zx.IOstats{}
	xfs.IOstats = st
	if xaddr != "" {
		rfs.Server(xfs, xaddr)
	}
	fn := func() {}
	if sflag {
		fn = func() {
			st.Averages()
			dbg.Warn("%s iostats:\n%s\n", xfs.Name(), st)
			fsst.Averages()
			dbg.Warn("%s iostats:\n%s\n", fs.Name(), fsst)
		}
	}
	return xfs, fn, nil
}