Optimize FUSE - make command restic mount faster and consume less memory

- Add Open() functionality to dir
- only access index for blobs when file is read
- Implement NodeOpener and put one-time file stuff there
- Add comment about locking as suggested by bazil.org/fuse

=> Thanks at Michael Eischer for suggesting the last two improvements
This commit is contained in:
Alexander Weiss
2020-06-14 13:47:13 +02:00
committed by Michael Eischer
parent be54ceff66
commit f8316948d1
4 changed files with 109 additions and 67 deletions

View File

@@ -62,7 +62,7 @@ func TestCache(t *testing.T) {
rtest.Equals(t, cacheSize, c.free)
}
func testRead(t testing.TB, f *file, offset, length int, data []byte) {
func testRead(t testing.TB, f fs.Handle, offset, length int, data []byte) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
@@ -73,7 +73,8 @@ func testRead(t testing.TB, f *file, offset, length int, data []byte) {
resp := &fuse.ReadResponse{
Data: data,
}
rtest.OK(t, f.Read(ctx, req, resp))
fr := f.(fs.HandleReader)
rtest.OK(t, fr.Read(ctx, req, resp))
}
func firstSnapshotID(t testing.TB, repo restic.Repository) (first restic.ID) {
@@ -156,11 +157,13 @@ func TestFuseFile(t *testing.T) {
Size: filesize,
Content: content,
}
root := NewRoot(repo, Config{})
root := &Root{repo: repo, blobCache: newBlobCache(blobCacheSize)}
inode := fs.GenerateDynamicInode(1, "foo")
f, err := newFile(context.TODO(), root, inode, node)
rtest.OK(t, err)
of, err := f.Open(context.TODO(), nil, nil)
rtest.OK(t, err)
attr := fuse.Attr{}
rtest.OK(t, f.Attr(ctx, &attr))
@@ -178,7 +181,7 @@ func TestFuseFile(t *testing.T) {
buf := make([]byte, length)
testRead(t, f, offset, length, buf)
testRead(t, of, offset, length, buf)
if !bytes.Equal(b, buf) {
t.Errorf("test %d failed, wrong data returned (offset %v, length %v)", i, offset, length)
}