2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-16 15:52:23 +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
snapshots restic.Snapshots
blobSizeCache *BlobSizeCache
snCount int
*MetaDir
}

View File

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