2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-10 15:21:03 +00:00

fuse mount: speedup

This commit is contained in:
Tobias Klein 2017-10-08 17:47:10 +02:00
parent 8ceb22fe8a
commit 7e4ce0dacc
2 changed files with 101 additions and 70 deletions

View File

@ -27,6 +27,7 @@ type Root struct {
inode uint64 inode uint64
snapshots restic.Snapshots snapshots restic.Snapshots
blobSizeCache *BlobSizeCache blobSizeCache *BlobSizeCache
snCount int
*MetaDir *MetaDir
} }

View File

@ -25,6 +25,7 @@ type SnapshotsDir struct {
latest string latest string
tag string tag string
host string host string
snCount int
} }
// SnapshotsIDSDir is a fuse directory which contains snapshots named by ids. // SnapshotsIDSDir is a fuse directory which contains snapshots named by ids.
@ -32,6 +33,7 @@ type SnapshotsIDSDir struct {
inode uint64 inode uint64
root *Root root *Root
names map[string]*restic.Snapshot names map[string]*restic.Snapshot
snCount int
} }
// HostsDir is a fuse directory which contains hosts. // HostsDir is a fuse directory which contains hosts.
@ -39,6 +41,7 @@ type HostsDir struct {
inode uint64 inode uint64
root *Root root *Root
hosts map[string]bool hosts map[string]bool
snCount int
} }
// TagsDir is a fuse directory which contains tags. // TagsDir is a fuse directory which contains tags.
@ -46,6 +49,7 @@ type TagsDir struct {
inode uint64 inode uint64
root *Root root *Root
tags map[string]bool tags map[string]bool
snCount int
} }
// SnapshotLink // SnapshotLink
@ -68,29 +72,38 @@ var _ = fs.NodeStringLookuper(&HostsDir{})
var _ = fs.NodeReadlinker(&snapshotLink{}) var _ = fs.NodeReadlinker(&snapshotLink{})
// read tag names from the current repository-state. // read tag names from the current repository-state.
func getTagNames(d *TagsDir) { func updateTagNames(d *TagsDir) {
if d.snCount != d.root.snCount {
d.snCount = d.root.snCount
d.tags = make(map[string]bool, len(d.root.snapshots)) d.tags = make(map[string]bool, len(d.root.snapshots))
for _, snapshot := range d.root.snapshots { for _, snapshot := range d.root.snapshots {
for _, tag := range snapshot.Tags { for _, tag := range snapshot.Tags {
d.tags[tag] = true d.tags[tag] = true
} }
} }
}
} }
// read host names from the current repository-state. // read host names from the current repository-state.
func getHostsNames(d *HostsDir) { func updateHostsNames(d *HostsDir) {
if d.snCount != d.root.snCount {
d.snCount = d.root.snCount
d.hosts = make(map[string]bool, len(d.root.snapshots)) d.hosts = make(map[string]bool, len(d.root.snapshots))
for _, snapshot := range d.root.snapshots { for _, snapshot := range d.root.snapshots {
d.hosts[snapshot.Hostname] = true d.hosts[snapshot.Hostname] = true
} }
}
} }
// read snapshot id names from the current repository-state. // read snapshot id names from the current repository-state.
func getSnapshotIDSNames(d *SnapshotsIDSDir) { func updateSnapshotIDSNames(d *SnapshotsIDSDir) {
if d.snCount != d.root.snCount {
d.snCount = d.root.snCount
for _, sn := range d.root.snapshots { for _, sn := range d.root.snapshots {
name := sn.ID().Str() name := sn.ID().Str()
d.names[name] = sn d.names[name] = sn
} }
}
} }
// NewSnapshotsDir returns a new directory containing snapshots. // NewSnapshotsDir returns a new directory containing snapshots.
@ -206,8 +219,20 @@ func isElem(e string, list []string) bool {
return false return false
} }
// update snapshots if repository has changed
func updateSnapshots(ctx context.Context, root *Root) {
snapshots := restic.FindFilteredSnapshots(ctx, root.repo, root.cfg.Host, root.cfg.Tags, root.cfg.Paths)
if root.snCount != len(snapshots) {
root.snCount = len(snapshots)
root.repo.LoadIndex(ctx)
root.snapshots = snapshots
}
}
// read snapshot timestamps from the current repository-state. // read snapshot timestamps from the current repository-state.
func getSnapshotNames(d *SnapshotsDir) { func updateSnapshotNames(d *SnapshotsDir) {
if d.snCount != d.root.snCount {
d.snCount = d.root.snCount
var latestTime time.Time var latestTime time.Time
d.latest = "" d.latest = ""
d.names = make(map[string]*restic.Snapshot, len(d.root.snapshots)) d.names = make(map[string]*restic.Snapshot, len(d.root.snapshots))
@ -231,16 +256,18 @@ func getSnapshotNames(d *SnapshotsDir) {
} }
} }
} }
}
} }
// ReadDirAll returns all entries of the SnapshotsDir. // ReadDirAll returns all entries of the SnapshotsDir.
func (d *SnapshotsDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) { func (d *SnapshotsDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
debug.Log("ReadDirAll()") debug.Log("ReadDirAll()")
d.root.repo.LoadIndex(ctx) // update snapshots
d.root.snapshots = restic.FindFilteredSnapshots(ctx, d.root.repo, d.root.cfg.Host, d.root.cfg.Tags, d.root.cfg.Paths) updateSnapshots(ctx, d.root)
getSnapshotNames(d) // update snapshot names
updateSnapshotNames(d)
items := []fuse.Dirent{ items := []fuse.Dirent{
{ {
@ -278,10 +305,11 @@ func (d *SnapshotsDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
func (d *SnapshotsIDSDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) { func (d *SnapshotsIDSDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
debug.Log("ReadDirAll()") debug.Log("ReadDirAll()")
d.root.repo.LoadIndex(ctx) // update snapshots
d.root.snapshots = restic.FindFilteredSnapshots(ctx, d.root.repo, d.root.cfg.Host, d.root.cfg.Tags, d.root.cfg.Paths) updateSnapshots(ctx, d.root)
getSnapshotIDSNames(d) // update snapshot ids
updateSnapshotIDSNames(d)
items := []fuse.Dirent{ items := []fuse.Dirent{
{ {
@ -311,10 +339,11 @@ func (d *SnapshotsIDSDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error)
func (d *HostsDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) { func (d *HostsDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
debug.Log("ReadDirAll()") debug.Log("ReadDirAll()")
d.root.repo.LoadIndex(ctx) // update snapshots
d.root.snapshots = restic.FindFilteredSnapshots(ctx, d.root.repo, d.root.cfg.Host, d.root.cfg.Tags, d.root.cfg.Paths) updateSnapshots(ctx, d.root)
getHostsNames(d) // update host names
updateHostsNames(d)
items := []fuse.Dirent{ items := []fuse.Dirent{
{ {
@ -344,10 +373,11 @@ func (d *HostsDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
func (d *TagsDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) { func (d *TagsDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
debug.Log("ReadDirAll()") debug.Log("ReadDirAll()")
d.root.repo.LoadIndex(ctx) // update snapshots
d.root.snapshots = restic.FindFilteredSnapshots(ctx, d.root.repo, d.root.cfg.Host, d.root.cfg.Tags, d.root.cfg.Paths) updateSnapshots(ctx, d.root)
getTagNames(d) // update tag names
updateTagNames(d)
items := []fuse.Dirent{ items := []fuse.Dirent{
{ {
@ -408,10 +438,10 @@ func (d *SnapshotsDir) Lookup(ctx context.Context, name string) (fs.Node, error)
sn, ok := d.names[name] sn, ok := d.names[name]
if !ok { if !ok {
// could not find entry. Updating repository-state // could not find entry. Updating repository-state
d.root.repo.LoadIndex(ctx) updateSnapshots(ctx, d.root)
d.root.snapshots = restic.FindFilteredSnapshots(ctx, d.root.repo, d.root.cfg.Host, d.root.cfg.Tags, d.root.cfg.Paths)
getSnapshotNames(d) // update snapshot names
updateSnapshotNames(d)
sn, ok := d.names[name] sn, ok := d.names[name]
if ok { if ok {
@ -441,10 +471,10 @@ func (d *SnapshotsIDSDir) Lookup(ctx context.Context, name string) (fs.Node, err
sn, ok := d.names[name] sn, ok := d.names[name]
if !ok { if !ok {
// could not find entry. Updating repository-state // could not find entry. Updating repository-state
d.root.repo.LoadIndex(ctx) updateSnapshots(ctx, d.root)
d.root.snapshots = restic.FindFilteredSnapshots(ctx, d.root.repo, d.root.cfg.Host, d.root.cfg.Tags, d.root.cfg.Paths)
getSnapshotIDSNames(d) // update snapshot ids
updateSnapshotIDSNames(d)
sn, ok := d.names[name] sn, ok := d.names[name]
if ok { if ok {
@ -464,10 +494,10 @@ func (d *HostsDir) Lookup(ctx context.Context, name string) (fs.Node, error) {
_, ok := d.hosts[name] _, ok := d.hosts[name]
if !ok { if !ok {
// could not find entry. Updating repository-state // could not find entry. Updating repository-state
d.root.repo.LoadIndex(ctx) updateSnapshots(ctx, d.root)
d.root.snapshots = restic.FindFilteredSnapshots(ctx, d.root.repo, d.root.cfg.Host, d.root.cfg.Tags, d.root.cfg.Paths)
getHostsNames(d) // update host names
updateHostsNames(d)
_, ok := d.hosts[name] _, ok := d.hosts[name]
if ok { if ok {
@ -487,10 +517,10 @@ func (d *TagsDir) Lookup(ctx context.Context, name string) (fs.Node, error) {
_, ok := d.tags[name] _, ok := d.tags[name]
if !ok { if !ok {
// could not find entry. Updating repository-state // could not find entry. Updating repository-state
d.root.repo.LoadIndex(ctx) updateSnapshots(ctx, d.root)
d.root.snapshots = restic.FindFilteredSnapshots(ctx, d.root.repo, d.root.cfg.Host, d.root.cfg.Tags, d.root.cfg.Paths)
getTagNames(d) // update tag names
updateTagNames(d)
_, ok := d.tags[name] _, ok := d.tags[name]
if ok { if ok {