mirror of
https://github.com/octoleo/restic.git
synced 2024-11-04 12:34:13 +00:00
fuse: Add debug logs
This commit is contained in:
parent
7c76ff3aaf
commit
6ee9baa9c5
@ -11,6 +11,7 @@ import (
|
|||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
"restic"
|
"restic"
|
||||||
|
"restic/debug"
|
||||||
"restic/repository"
|
"restic/repository"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -27,8 +28,10 @@ type dir struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newDir(repo *repository.Repository, node *restic.Node, ownerIsRoot bool) (*dir, error) {
|
func newDir(repo *repository.Repository, node *restic.Node, ownerIsRoot bool) (*dir, error) {
|
||||||
|
debug.Log("newDir", "new dir for %v (%v)", node.Name, node.Subtree.Str())
|
||||||
tree, err := restic.LoadTree(repo, *node.Subtree)
|
tree, err := restic.LoadTree(repo, *node.Subtree)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
debug.Log("newDir", " error loading tree %v: %v", node.Subtree.Str(), err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
items := make(map[string]*restic.Node)
|
items := make(map[string]*restic.Node)
|
||||||
@ -65,14 +68,17 @@ func replaceSpecialNodes(repo *repository.Repository, node *restic.Node) ([]*res
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newDirFromSnapshot(repo *repository.Repository, snapshot SnapshotWithId, ownerIsRoot bool) (*dir, error) {
|
func newDirFromSnapshot(repo *repository.Repository, snapshot SnapshotWithId, ownerIsRoot bool) (*dir, error) {
|
||||||
|
debug.Log("newDirFromSnapshot", "new dir for snapshot %v (%v)", snapshot.ID.Str(), snapshot.Tree.Str())
|
||||||
tree, err := restic.LoadTree(repo, *snapshot.Tree)
|
tree, err := restic.LoadTree(repo, *snapshot.Tree)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
debug.Log("newDirFromSnapshot", " loadTree(%v) failed: %v", snapshot.ID.Str(), err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
items := make(map[string]*restic.Node)
|
items := make(map[string]*restic.Node)
|
||||||
for _, n := range tree.Nodes {
|
for _, n := range tree.Nodes {
|
||||||
nodes, err := replaceSpecialNodes(repo, n)
|
nodes, err := replaceSpecialNodes(repo, n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
debug.Log("newDirFromSnapshot", " replaceSpecialNodes(%v) failed: %v", n, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,6 +104,7 @@ func newDirFromSnapshot(repo *repository.Repository, snapshot SnapshotWithId, ow
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *dir) Attr(ctx context.Context, a *fuse.Attr) error {
|
func (d *dir) Attr(ctx context.Context, a *fuse.Attr) error {
|
||||||
|
debug.Log("dir.Attr", "called")
|
||||||
a.Inode = d.inode
|
a.Inode = d.inode
|
||||||
a.Mode = os.ModeDir | d.node.Mode
|
a.Mode = os.ModeDir | d.node.Mode
|
||||||
|
|
||||||
@ -112,6 +119,7 @@ func (d *dir) Attr(ctx context.Context, a *fuse.Attr) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
|
func (d *dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
|
||||||
|
debug.Log("dir.ReadDirAll", "called")
|
||||||
ret := make([]fuse.Dirent, 0, len(d.items))
|
ret := make([]fuse.Dirent, 0, len(d.items))
|
||||||
|
|
||||||
for _, node := range d.items {
|
for _, node := range d.items {
|
||||||
@ -136,8 +144,10 @@ func (d *dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *dir) Lookup(ctx context.Context, name string) (fs.Node, error) {
|
func (d *dir) Lookup(ctx context.Context, name string) (fs.Node, error) {
|
||||||
|
debug.Log("dir.Lookup", "Lookup(%v)", name)
|
||||||
node, ok := d.items[name]
|
node, ok := d.items[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
debug.Log("dir.Lookup", " Lookup(%v) -> not found", name)
|
||||||
return nil, fuse.ENOENT
|
return nil, fuse.ENOENT
|
||||||
}
|
}
|
||||||
switch node.Type {
|
switch node.Type {
|
||||||
@ -148,6 +158,7 @@ func (d *dir) Lookup(ctx context.Context, name string) (fs.Node, error) {
|
|||||||
case "symlink":
|
case "symlink":
|
||||||
return newLink(d.repo, node, d.ownerIsRoot)
|
return newLink(d.repo, node, d.ownerIsRoot)
|
||||||
default:
|
default:
|
||||||
|
debug.Log("dir.Lookup", " node %v has unknown type %v", name, node.Type)
|
||||||
return nil, fuse.ENOENT
|
return nil, fuse.ENOENT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
"restic"
|
"restic"
|
||||||
"restic/backend"
|
"restic/backend"
|
||||||
|
"restic/debug"
|
||||||
"restic/pack"
|
"restic/pack"
|
||||||
|
|
||||||
"bazil.org/fuse"
|
"bazil.org/fuse"
|
||||||
@ -47,6 +48,7 @@ var blobPool = sync.Pool{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newFile(repo BlobLoader, node *restic.Node, ownerIsRoot bool) (*file, error) {
|
func newFile(repo BlobLoader, node *restic.Node, ownerIsRoot bool) (*file, error) {
|
||||||
|
debug.Log("newFile", "create new file for %v with %d blobs", node.Name, len(node.Content))
|
||||||
sizes := make([]uint, len(node.Content))
|
sizes := make([]uint, len(node.Content))
|
||||||
for i, id := range node.Content {
|
for i, id := range node.Content {
|
||||||
size, err := repo.LookupBlobSize(id)
|
size, err := repo.LookupBlobSize(id)
|
||||||
@ -67,6 +69,7 @@ func newFile(repo BlobLoader, node *restic.Node, ownerIsRoot bool) (*file, error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *file) Attr(ctx context.Context, a *fuse.Attr) error {
|
func (f *file) Attr(ctx context.Context, a *fuse.Attr) error {
|
||||||
|
debug.Log("file.Attr", "Attr(%v)", f.node.Name)
|
||||||
a.Inode = f.node.Inode
|
a.Inode = f.node.Inode
|
||||||
a.Mode = f.node.Mode
|
a.Mode = f.node.Mode
|
||||||
a.Size = f.node.Size
|
a.Size = f.node.Size
|
||||||
@ -84,6 +87,7 @@ func (f *file) Attr(ctx context.Context, a *fuse.Attr) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *file) getBlobAt(i int) (blob []byte, err error) {
|
func (f *file) getBlobAt(i int) (blob []byte, err error) {
|
||||||
|
debug.Log("file.getBlobAt", "getBlobAt(%v, %v)", f.node.Name, i)
|
||||||
if f.blobs[i] != nil {
|
if f.blobs[i] != nil {
|
||||||
return f.blobs[i], nil
|
return f.blobs[i], nil
|
||||||
}
|
}
|
||||||
@ -100,6 +104,7 @@ func (f *file) getBlobAt(i int) (blob []byte, err error) {
|
|||||||
|
|
||||||
blob, err = f.repo.LoadBlob(pack.Data, f.node.Content[i], buf)
|
blob, err = f.repo.LoadBlob(pack.Data, f.node.Content[i], buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
debug.Log("file.getBlobAt", "LoadBlob(%v, %v) failed: %v", f.node.Name, f.node.Content[i], err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
f.blobs[i] = blob
|
f.blobs[i] = blob
|
||||||
@ -108,6 +113,7 @@ func (f *file) getBlobAt(i int) (blob []byte, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *file) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error {
|
func (f *file) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error {
|
||||||
|
debug.Log("file.Read", "Read(%v), file size %v", req.Size, f.node.Size)
|
||||||
offset := req.Offset
|
offset := req.Offset
|
||||||
|
|
||||||
// Skip blobs before the offset
|
// Skip blobs before the offset
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"restic"
|
"restic"
|
||||||
"restic/backend"
|
"restic/backend"
|
||||||
|
"restic/debug"
|
||||||
"restic/repository"
|
"restic/repository"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
@ -39,6 +40,7 @@ type SnapshotsDir struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewSnapshotsDir(repo *repository.Repository, ownerIsRoot bool) *SnapshotsDir {
|
func NewSnapshotsDir(repo *repository.Repository, ownerIsRoot bool) *SnapshotsDir {
|
||||||
|
debug.Log("NewSnapshotsDir", "fuse mount initiated")
|
||||||
return &SnapshotsDir{
|
return &SnapshotsDir{
|
||||||
repo: repo,
|
repo: repo,
|
||||||
knownSnapshots: make(map[string]SnapshotWithId),
|
knownSnapshots: make(map[string]SnapshotWithId),
|
||||||
@ -54,10 +56,12 @@ func (sn *SnapshotsDir) Attr(ctx context.Context, attr *fuse.Attr) error {
|
|||||||
attr.Uid = uint32(os.Getuid())
|
attr.Uid = uint32(os.Getuid())
|
||||||
attr.Gid = uint32(os.Getgid())
|
attr.Gid = uint32(os.Getgid())
|
||||||
}
|
}
|
||||||
|
debug.Log("SnapshotsDir.Attr", "attr is %v", attr)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sn *SnapshotsDir) updateCache(ctx context.Context) error {
|
func (sn *SnapshotsDir) updateCache(ctx context.Context) error {
|
||||||
|
debug.Log("SnapshotsDir.updateCache", "called")
|
||||||
sn.Lock()
|
sn.Lock()
|
||||||
defer sn.Unlock()
|
defer sn.Unlock()
|
||||||
|
|
||||||
@ -75,10 +79,12 @@ func (sn *SnapshotsDir) get(name string) (snapshot SnapshotWithId, ok bool) {
|
|||||||
sn.RLock()
|
sn.RLock()
|
||||||
snapshot, ok = sn.knownSnapshots[name]
|
snapshot, ok = sn.knownSnapshots[name]
|
||||||
sn.RUnlock()
|
sn.RUnlock()
|
||||||
|
debug.Log("SnapshotsDir.get", "get(%s) -> %v %v", name, snapshot, ok)
|
||||||
return snapshot, ok
|
return snapshot, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sn *SnapshotsDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
|
func (sn *SnapshotsDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
|
||||||
|
debug.Log("SnapshotsDir.ReadDirAll", "called")
|
||||||
err := sn.updateCache(ctx)
|
err := sn.updateCache(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -96,21 +102,25 @@ func (sn *SnapshotsDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug.Log("SnapshotsDir.ReadDirAll", " -> %d entries", len(ret))
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sn *SnapshotsDir) Lookup(ctx context.Context, name string) (fs.Node, error) {
|
func (sn *SnapshotsDir) Lookup(ctx context.Context, name string) (fs.Node, error) {
|
||||||
|
debug.Log("SnapshotsDir.updateCache", "Lookup(%s)", name)
|
||||||
snapshot, ok := sn.get(name)
|
snapshot, ok := sn.get(name)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
// We don't know about it, update the cache
|
// We don't know about it, update the cache
|
||||||
err := sn.updateCache(ctx)
|
err := sn.updateCache(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
debug.Log("SnapshotsDir.updateCache", " Lookup(%s) -> err %v", name, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
snapshot, ok = sn.get(name)
|
snapshot, ok = sn.get(name)
|
||||||
if !ok {
|
if !ok {
|
||||||
// We still don't know about it, this time it really doesn't exist
|
// We still don't know about it, this time it really doesn't exist
|
||||||
|
debug.Log("SnapshotsDir.updateCache", " Lookup(%s) -> not found", name)
|
||||||
return nil, fuse.ENOENT
|
return nil, fuse.ENOENT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user