Exemple #1
0
func setupUfs(t *testing.T) (workdir string, cleanup func()) {
	wd := fuse.MakeTempDir()
	err := os.Mkdir(wd+"/mount", 0700)
	fuse.CheckSuccess(err)

	err = os.Mkdir(wd+"/rw", 0700)
	fuse.CheckSuccess(err)

	os.Mkdir(wd+"/ro", 0700)
	fuse.CheckSuccess(err)

	var fses []fuse.FileSystem
	fses = append(fses, fuse.NewLoopbackFileSystem(wd+"/rw"))
	fses = append(fses, fuse.NewLoopbackFileSystem(wd+"/ro"))
	ufs := NewUnionFs("testFs", fses, testOpts)

	opts := &fuse.FileSystemOptions{
		EntryTimeout:    entryTtl,
		AttrTimeout:     entryTtl,
		NegativeTimeout: entryTtl,
	}

	state, _, err := fuse.MountFileSystem(wd+"/mount", ufs, opts)
	CheckSuccess(err)
	state.Debug = true
	go state.Loop(false)

	return wd, func() {
		state.Unmount()
		os.RemoveAll(wd)
	}
}
func setup(t *testing.T) (workdir string, cleanup func()) {
	wd := fuse.MakeTempDir()
	err := os.Mkdir(wd+"/mount", 0700)
	fuse.CheckSuccess(err)

	err = os.Mkdir(wd+"/store", 0700)
	fuse.CheckSuccess(err)

	os.Mkdir(wd+"/ro", 0700)
	fuse.CheckSuccess(err)
	WriteFile(wd+"/ro/file1", "file1")
	WriteFile(wd+"/ro/file2", "file2")

	fs := NewAutoUnionFs(wd+"/store", testAOpts)
	state, conn, err := fuse.MountFileSystem(wd+"/mount", fs, &testAOpts.FileSystemOptions)
	CheckSuccess(err)
	state.Debug = true
	conn.Debug = true
	go state.Loop(false)

	return wd, func() {
		state.Unmount()
		os.RemoveAll(wd)
	}
}
func setupUfs(t *testing.T) (workdir string, cleanup func()) {
	wd := fuse.MakeTempDir()
	err := os.Mkdir(wd+"/mount", 0700)
	fuse.CheckSuccess(err)

	err = os.Mkdir(wd+"/rw", 0700)
	fuse.CheckSuccess(err)

	os.Mkdir(wd+"/ro", 0700)
	fuse.CheckSuccess(err)

	var fses []fuse.FileSystem
	fses = append(fses, fuse.NewLoopbackFileSystem(wd+"/rw"))
	fses = append(fses,
		NewCachingFileSystem(fuse.NewLoopbackFileSystem(wd+"/ro"), 0))
	ufs := NewUnionFs(fses, testOpts)

	// We configure timeouts are smaller, so we can check for
	// UnionFs's cache consistency.
	opts := &fuse.FileSystemOptions{
		EntryTimeout:    .5 * entryTtl,
		AttrTimeout:     .5 * entryTtl,
		NegativeTimeout: .5 * entryTtl,
	}

	state, _, err := fuse.MountFileSystem(wd+"/mount", ufs, opts)
	CheckSuccess(err)
	state.Debug = true
	go state.Loop(false)

	return wd, func() {
		state.Unmount()
		os.RemoveAll(wd)
	}
}
Exemple #4
0
func BenchmarkCFuseThreadedStat(b *testing.B) {
	log.Println("benchmarking CFuse")

	lines := GetTestLines()
	unique := map[string]int{}
	for _, l := range lines {
		unique[l] = 1
		dir, _ := filepath.Split(l)
		for dir != "/" && dir != "" {
			unique[dir] = 1
			dir = filepath.Clean(dir)
			dir, _ = filepath.Split(dir)
		}
	}

	out := []string{}
	for k, _ := range unique {
		out = append(out, k)
	}

	f, err := ioutil.TempFile("", "")
	CheckSuccess(err)
	sort.Strings(out)
	for _, k := range out {
		f.Write([]byte(fmt.Sprintf("/%s\n", k)))
	}
	f.Close()

	log.Println("Written:", f.Name())
	mountPoint := fuse.MakeTempDir()
	wd, _ := os.Getwd()
	cmd := exec.Command(wd+"/cstatfs", mountPoint)
	cmd.Env = append(os.Environ(), fmt.Sprintf("STATFS_INPUT=%s", f.Name()))
	cmd.Start()

	bin, err := exec.LookPath("fusermount")
	CheckSuccess(err)
	stop := exec.Command(bin, "-u", mountPoint)
	CheckSuccess(err)
	defer stop.Run()

	for i, l := range lines {
		lines[i] = filepath.Join(mountPoint, l)
	}

	// Wait for the daemon to mount.
	time.Sleep(0.2e9)
	ttl := 1.0
	log.Println("N = ", b.N)
	threads := runtime.GOMAXPROCS(0)
	results := TestingBOnePass(b, threads, ttl*1.2, lines)
	AnalyzeBenchmarkRuns(results)
}
Exemple #5
0
func TestZipFs(t *testing.T) {
	wd, err := os.Getwd()
	CheckSuccess(err)
	zfs, err := NewArchiveFileSystem(wd + "/test.zip")
	if err != nil {
		t.Error("NewZipArchiveFileSystem failed:", err)
	}

	mountPoint := fuse.MakeTempDir()
	defer os.RemoveAll(mountPoint)
	state, _, err := fuse.MountFileSystem(mountPoint, zfs, nil)
	defer state.Unmount()

	state.Debug = true
	go state.Loop(false)

	d, err := os.Open(mountPoint)
	CheckSuccess(err)

	names, err := d.Readdirnames(-1)
	CheckSuccess(err)
	err = d.Close()
	CheckSuccess(err)

	if len(names) != 2 {
		t.Error("wrong length", names)
	}
	fi, err := os.Stat(mountPoint + "/subdir")
	CheckSuccess(err)
	if !fi.IsDirectory() {
		t.Error("directory type", fi)
	}

	fi, err = os.Stat(mountPoint + "/file.txt")
	CheckSuccess(err)

	if !fi.IsRegular() {
		t.Error("file type", fi)
	}

	f, err := os.Open(mountPoint + "/file.txt")
	CheckSuccess(err)

	b := make([]byte, 1024)
	n, err := f.Read(b)

	b = b[:n]
	if string(b) != "hello\n" {
		t.Error("content fail", b[:n])
	}
	f.Close()
}
Exemple #6
0
func setupDevNullFs() (wd string, clean func()) {
	fs := NewDevnullFs()
	mountPoint := fuse.MakeTempDir()
	state, _, err := fuse.MountPathFileSystem(mountPoint, fs, nil)
	if err != nil {
		panic(err)
	}

	state.Debug = true
	go state.Loop(false)
	return mountPoint, func() {
		state.Unmount()
		os.RemoveAll(mountPoint)
	}
}
Exemple #7
0
func setupZipfs() (mountPoint string, cleanup func()) {
	zfs, err := NewArchiveFileSystem(testZipFile())
	CheckSuccess(err)

	mountPoint = fuse.MakeTempDir()

	state, _, err := fuse.MountNodeFileSystem(mountPoint, zfs, nil)

	state.Debug = true
	go state.Loop(false)

	return mountPoint, func() {
		state.Unmount()
		os.RemoveAll(mountPoint)
	}
}
Exemple #8
0
func setupMzfs() (mountPoint string, cleanup func()) {
	fs := NewMultiZipFs()
	mountPoint = fuse.MakeTempDir()
	state, _, err := fuse.MountPathFileSystem(mountPoint, fs, &fuse.FileSystemOptions{
		EntryTimeout:    testTtl,
		AttrTimeout:     testTtl,
		NegativeTimeout: 0.0,
	})
	CheckSuccess(err)
	state.Debug = true
	go state.Loop(true)

	return mountPoint, func() {
		state.Unmount()
		os.RemoveAll(mountPoint)
	}
}
Exemple #9
0
func setupFs(fs fuse.FileSystem, opts *fuse.FileSystemOptions) (string, func()) {
	mountPoint := fuse.MakeTempDir()
	state, _, err := fuse.MountFileSystem(mountPoint, fs, opts)
	if err != nil {
		panic(fmt.Sprintf("cannot mount %v", err)) // ugh - benchmark has no error methods.
	}
	// state.Debug = true
	go state.Loop(false)

	return mountPoint, func() {
		err := state.Unmount()
		if err != nil {
			log.Println("error during unmount", err)
		} else {
			os.RemoveAll(mountPoint)
		}
	}
}
Exemple #10
0
func TestCachingFs(t *testing.T) {
	wd := fuse.MakeTempDir()
	defer os.RemoveAll(wd)

	fs := fuse.NewLoopbackFileSystem(wd)
	cfs := NewCachingFileSystem(fs, 0)

	os.Mkdir(wd+"/orig", 0755)
	fi, code := cfs.GetAttr("orig", nil)
	if !code.Ok() {
		t.Fatal("GetAttr failure", code)
	}
	if !fi.IsDirectory() {
		t.Error("unexpected attr", fi)
	}

	os.Symlink("orig", wd+"/symlink")

	val, code := cfs.Readlink("symlink", nil)
	if val != "orig" {
		t.Error("unexpected readlink", val)
	}
	if !code.Ok() {
		t.Error("code !ok ", code)
	}

	stream, code := cfs.OpenDir("", nil)
	if !code.Ok() {
		t.Fatal("Readdir fail", code)
	}

	results := make(map[string]uint32)
	for v := range stream {
		results[v.Name] = v.Mode &^ 07777
	}
	expected := map[string]uint32{
		"symlink": syscall.S_IFLNK,
		"orig":    fuse.S_IFDIR,
	}
	if !modeMapEq(results, expected) {
		t.Error("Unexpected readdir result", results, expected)
	}
}
Exemple #11
0
func TestDisappearing(t *testing.T) {
	// This init is like setupUfs, but we want access to the
	// writable Fs.
	wd := fuse.MakeTempDir()
	defer os.RemoveAll(wd)
	err := os.Mkdir(wd+"/mount", 0700)
	fuse.CheckSuccess(err)

	err = os.Mkdir(wd+"/rw", 0700)
	fuse.CheckSuccess(err)

	os.Mkdir(wd+"/ro", 0700)
	fuse.CheckSuccess(err)

	wrFs := fuse.NewLoopbackFileSystem(wd + "/rw")
	var fses []fuse.FileSystem
	fses = append(fses, wrFs)
	fses = append(fses, fuse.NewLoopbackFileSystem(wd+"/ro"))
	ufs := NewUnionFs(fses, testOpts)

	opts := &fuse.FileSystemOptions{
		EntryTimeout:    entryTtl,
		AttrTimeout:     entryTtl,
		NegativeTimeout: entryTtl,
	}

	state, _, err := fuse.MountFileSystem(wd+"/mount", ufs, opts)
	CheckSuccess(err)
	defer state.Unmount()
	state.Debug = true
	go state.Loop(true)

	log.Println("TestDisappearing2")

	err = ioutil.WriteFile(wd+"/ro/file", []byte("blabla"), 0644)
	CheckSuccess(err)

	err = os.Remove(wd + "/mount/file")
	CheckSuccess(err)

	oldRoot := wrFs.Root
	wrFs.Root = "/dev/null"
	time.Sleep(1.5 * entryTtl * 1e9)

	_, err = ioutil.ReadDir(wd + "/mount")
	if err == nil {
		t.Fatal("Readdir should have failed")
	}
	log.Println("expected readdir failure:", err)

	err = ioutil.WriteFile(wd+"/mount/file2", []byte("blabla"), 0644)
	if err == nil {
		t.Fatal("write should have failed")
	}
	log.Println("expected write failure:", err)

	// Restore, and wait for caches to catch up.
	wrFs.Root = oldRoot
	time.Sleep(1.5 * entryTtl * 1e9)

	_, err = ioutil.ReadDir(wd + "/mount")
	if err != nil {
		t.Fatal("Readdir should succeed", err)
	}
	err = ioutil.WriteFile(wd+"/mount/file2", []byte("blabla"), 0644)
	if err != nil {
		t.Fatal("write should succeed", err)
	}
}
Exemple #12
0
func TestMultiZipFs(t *testing.T) {
	var err os.Error

	wd, err := os.Getwd()
	zipFile := wd + "/test.zip"

	fs := NewMultiZipFs()
	mountPoint := fuse.MakeTempDir()
	state, _, err := fuse.MountFileSystem(mountPoint, fs, &fuse.FileSystemOptions{
		EntryTimeout:    testTtl,
		AttrTimeout:     testTtl,
		NegativeTimeout: 0.0,
	})
	defer os.RemoveAll(mountPoint)
	CheckSuccess(err)
	defer state.Unmount()

	state.Debug = true

	go state.Loop(true)

	f, err := os.Open(mountPoint + "")
	CheckSuccess(err)

	names, err := f.Readdirnames(-1)
	CheckSuccess(err)

	if len(names) != 1 || string(names[0]) != "config" {
		t.Errorf("wrong names return. %v", names)
	}
	err = f.Close()
	CheckSuccess(err)

	f, err = os.Create(mountPoint + "/random")
	if err == nil {
		t.Error("Must fail writing in root.")
	}

	f, err = os.OpenFile(mountPoint+"/config/zipmount", os.O_WRONLY, 0)
	if err == nil {
		t.Error("Must fail without O_CREATE")
	}
	f, err = os.Create(mountPoint + "/config/zipmount")
	CheckSuccess(err)

	// Directory exists, but is empty.
	fi, err := os.Lstat(mountPoint + "/zipmount")
	CheckSuccess(err)
	if !fi.IsDirectory() {
		t.Errorf("Expect directory at /zipmount")
	}

	// Open the zip file.
	_, err = f.Write([]byte(zipFile))
	CheckSuccess(err)

	_, err = f.Write([]byte(zipFile))
	if err == nil {
		t.Error("Must fail second write.")
	}

	err = f.Close()
	CheckSuccess(err)
	fi, err = os.Lstat(mountPoint + "/zipmount")
	if !fi.IsDirectory() {
		t.Errorf("Expect directory at /zipmount")
	}

	// Check that zipfs itself works.
	fi, err = os.Stat(mountPoint + "/zipmount/subdir")
	CheckSuccess(err)
	if !fi.IsDirectory() {
		t.Error("directory type", fi)
	}

	// Removing the config dir unmount
	err = os.Remove(mountPoint + "/config/zipmount")
	CheckSuccess(err)

	// This is ugly but necessary: We don't have ways to signal
	// back to FUSE that the file disappeared.
	time.Sleep(1.5e9 * testTtl)

	fi, err = os.Stat(mountPoint + "/zipmount")
	if err == nil {
		t.Error("stat should fail after unmount.", fi)
	}
}