diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/btrfs/io3_btree.go | 11 | ||||
-rw-r--r-- | lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuildnodes.go | 16 |
2 files changed, 26 insertions, 1 deletions
diff --git a/lib/btrfs/io3_btree.go b/lib/btrfs/io3_btree.go index 9c4dd67..31cf857 100644 --- a/lib/btrfs/io3_btree.go +++ b/lib/btrfs/io3_btree.go @@ -8,6 +8,8 @@ import ( "context" "fmt" + "github.com/datawire/dlib/dlog" + "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsitem" "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsprim" "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfstree" @@ -39,6 +41,7 @@ func (fs *FS) populateTreeUUIDs(ctx context.Context) { fs.TreeWalk(ctx, btrfsprim.ROOT_TREE_OBJECTID, func(err *btrfstree.TreeError) { // do nothing + dlog.Errorf(ctx, "dbg err: %v", err) }, btrfstree.TreeWalkHandler{ Item: func(_ btrfstree.TreePath, item btrfstree.Item) error { @@ -56,6 +59,8 @@ func (fs *FS) populateTreeUUIDs(ctx context.Context) { } } +var noParents = make(map[btrfsprim.ObjID]struct{}) + func (fs *FS) ReadNode(path btrfstree.TreePath) (*diskio.Ref[btrfsvol.LogicalAddr, btrfstree.Node], error) { sb, err := fs.Superblock() if err != nil { @@ -72,10 +77,16 @@ func (fs *FS) ReadNode(path btrfstree.TreePath) (*diskio.Ref[btrfsvol.LogicalAdd objID := potentialOwners[len(potentialOwners)-1] parentUUID := fs.cacheTreeParent[objID] if parentUUID == (btrfsprim.UUID{}) { + if _, already := noParents[objID]; !already { + dlog.Infof(ctx, "dbg: objID=%v has no parent", objID) + noParents[objID] = struct{}{} + } break } + dlog.Infof(ctx, "dbg: parent of objID=%v is %v", objID, parentUUID) parentObjID, ok := fs.cacheUUID2ObjID[parentUUID] if !ok { + dlog.Errorf(ctx, "dbg: could not resolve parentUUID=%v to an ObjID", parentUUID) break } potentialOwners = append(potentialOwners, parentObjID) diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuildnodes.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuildnodes.go index 16b1e84..cac9483 100644 --- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuildnodes.go +++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuildnodes.go @@ -6,10 +6,12 @@ package rebuildnodes import ( "context" + "errors" "fmt" iofs "io/fs" "math" "sort" + "strings" "github.com/datawire/dlib/dlog" @@ -152,6 +154,9 @@ func lostAndFoundNodes(ctx context.Context, fs *btrfs.FS, nodeScanResults btrfsi }, Err: func(err *btrfsutil.WalkError) { // do nothing + if !errors.Is(err, btrfstree.ErrNotANode) && !strings.Contains(err.Error(), "read: could not map logical address") { + dlog.Errorf(ctx, "dbg walk err: %v", err) + } }, }) @@ -220,6 +225,7 @@ func getChunkTreeUUID(ctx context.Context, fs *btrfs.FS) (btrfsprim.UUID, bool) }, Err: func(err *btrfsutil.WalkError) { // do nothing + dlog.Errorf(ctx, "dbg err: %v", err) }, }) return ret, retOK @@ -255,9 +261,17 @@ func reInitBrokenNodes(ctx context.Context, fs *btrfs.FS, nodeScanResults btrfsi var done int rebuiltNodes := make(map[btrfsvol.LogicalAddr]*RebuiltNode) + dbg := make(map[btrfsvol.LogicalAddr]btrfstree.TreePath) walkHandler := btrfstree.TreeWalkHandler{ - Node: func(_ btrfstree.TreePath, _ *diskio.Ref[btrfsvol.LogicalAddr, btrfstree.Node]) error { + Node: func(path btrfstree.TreePath, _ *diskio.Ref[btrfsvol.LogicalAddr, btrfstree.Node]) error { + if other, conflict := dbg[path.Node(-1).ToNodeAddr]; conflict { + panic(fmt.Errorf("same node visited twice: %v != %v", other, path)) + } + dbg[path.Node(-1).ToNodeAddr] = path.DeepCopy() done++ + if done != len(dbg) { + panic(fmt.Errorf("done=%v != len(dbg)=%v", done, len(dbg))) + } progress(done) return nil }, |