예제 #1
0
func mkfs(addr string) (zx.Tree, func(), error) {
	if len(addr) == 0 {
		opts.Usage(os.Stderr)
		dbg.Fatal("usage")
	}
	var fs zx.Tree
	var st *zx.IOstats
	var err error
	if _, err := os.Stat(addr); err == nil {
		fs, st, err = mklfs(addr)
	} else {
		fs, st, err = mkrfs(addr)
	}
	if err != nil {
		return nil, nil, err
	}
	fn := func() {}
	if sflag {
		fn = func() {
			st.Averages()
			dbg.Warn("%s iostats:\n%s\n", fs.Name(), st)
		}
	}
	if mfscfs {
		dbg.Warn("%s: mfs cache", addr)
		return mfscache(fs, fn)
	}
	if lfsdir != "" {
		dbg.Warn("%s: lfs cache", addr)
		return lfscache(fs, fn)
	}
	if !nocaching && !delayed {
		dbg.Warn("%s: old cache", addr)
		return cache(fs, fn)
	}
	dbg.Warn("%s: uncached", addr)
	return fs, fn, nil
}
예제 #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
}