示例#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)
	}
}
示例#2
0
文件: main.go 项目: jravasi/go-fuse
func main() {
	debug := flag.Bool("debug", false, "debug on")
	threaded := flag.Bool("threaded", true, "debug on")
	delcache_ttl := flag.Float64("deletion_cache_ttl", 5.0, "Deletion cache TTL in seconds.")
	branchcache_ttl := flag.Float64("branchcache_ttl", 5.0, "Branch cache TTL in seconds.")
	deldirname := flag.String(
		"deletion_dirname", "GOUNIONFS_DELETIONS", "Directory name to use for deletions.")
	flag.Parse()

	if len(flag.Args()) < 2 {
		fmt.Println("Usage:\n  main MOUNTPOINT RW-DIRECTORY RO-DIRECTORY ...")
		os.Exit(2)
	}

	ufsOptions := unionfs.UnionFsOptions{
		DeletionCacheTTLSecs: *delcache_ttl,
		BranchCacheTTLSecs:   *branchcache_ttl,
		DeletionDirName:      *deldirname,
	}

	ufs, err := unionfs.NewUnionFsFromRoots(flag.Args()[1:], &ufsOptions)
	if err != nil {
		log.Fatal("Cannot create UnionFs", err)
		os.Exit(1)
	}
	mountState, _, err := fuse.MountFileSystem(flag.Arg(0), ufs, nil)
	if err != nil {
		log.Fatal("Mount fail:", err)
	}

	mountState.Debug = *debug
	mountState.Loop(*threaded)
}
示例#3
0
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)
	}
}
示例#4
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,
		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)
	}
}
示例#5
0
func main() {
	flag.Parse()
	if len(flag.Args()) < 1 {
		log.Fatal("Usage:\n  hello MOUNTPOINT")
	}
	state, _, err := fuse.MountFileSystem(flag.Arg(0), &HelloFs{}, nil)
	if err != nil {
		log.Fatal("Mount fail: %v\n", err)
	}
	state.Loop(true)
}
示例#6
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()
}
示例#7
0
func setupMzfs() (mountPoint string, cleanup func()) {
	fs := NewMultiZipFs()
	mountPoint = fuse.MakeTempDir()
	state, _, err := fuse.MountFileSystem(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)
	}
}
示例#8
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)
		}
	}
}
示例#9
0
func setupZipfs() (mountPoint string, cleanup func()) {
	wd, err := os.Getwd()
	CheckSuccess(err)
	zfs, err := NewArchiveFileSystem(wd + "/test.zip")
	CheckSuccess(err)

	mountPoint = fuse.MakeTempDir()

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

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

	return mountPoint, func() {
		state.Unmount()
		os.RemoveAll(mountPoint)
	}
}
示例#10
0
func main() {
	// Scans the arg list and sets up flags
	debug := flag.Bool("debug", false, "debug on")
	flag.Parse()
	if flag.NArg() < 1 {
		// TODO - where to get program name?
		fmt.Println("usage: main MOUNTPOINT")
		os.Exit(2)
	}

	fs := zipfs.NewMultiZipFs()
	state, _, err := fuse.MountFileSystem(flag.Arg(0), fs, nil)
	if err != nil {
		fmt.Printf("Mount fail: %v\n", err)
		os.Exit(1)
	}

	state.Debug = *debug
	state.Loop(true)
}
示例#11
0
文件: main.go 项目: abneptis/tarwfs
func main() {
	flag.Parse()
	if flag.NArg() != 2 {
		log.Fatalf("Usage: $0 mountpoint tarfile")
	}
	fp, err := os.OpenFile(flag.Arg(1), os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0600)
	if err != nil {
		log.Fatalf("Couldn't open tarfile: %v", err)
	}
	fs := tarwfs.New(fp)
	state, _, err := fuse.MountFileSystem(flag.Arg(0), fuse.NewLoggingFileSystem(fs), nil)
	log.Printf("State: %v\tErr: %v", state, err)

	if err != nil {
		log.Fatal("Mount fail: %v\n", err)
	}
	state.Loop(true)
	fs.Unmount() // isn't getting called!
	fp.Close()

}
示例#12
0
文件: main.go 项目: klimek/go-fuse
func main() {
	// Scans the arg list and sets up flags
	debug := flag.Bool("debug", false, "print debugging messages.")
	latencies := flag.Bool("latencies", false, "record operation latencies.")

	flag.Parse()
	if flag.NArg() < 2 {
		fmt.Fprintf(os.Stderr, "usage: %s MOUNTPOINT ZIP-FILE\n", os.Args[0])
		os.Exit(2)
	}

	var fs fuse.FileSystem
	fs, err := zipfs.NewArchiveFileSystem(flag.Arg(1))
	if err != nil {
		fmt.Fprintf(os.Stderr, "NewArchiveFileSystem failed: %v\n", err)
		os.Exit(1)
	}
	debugFs := fuse.NewFileSystemDebug()

	if *latencies {
		debugFs.FileSystem = fs
		fs = debugFs
	}

	state, conn, err := fuse.MountFileSystem(flag.Arg(0), fs, nil)
	if err != nil {
		fmt.Printf("Mount fail: %v\n", err)
		os.Exit(1)
	}

	if *latencies {
		debugFs.AddFileSystemConnector(conn)
		debugFs.AddMountState(state)
	}

	state.SetRecordStatistics(*latencies)
	state.Debug = *debug
	state.Loop(true)
}
示例#13
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)
	}
}
示例#14
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)
	}
}