summaryrefslogtreecommitdiff
path: root/lib/btrfsprogs/btrfsinspect/rebuildnodes
diff options
context:
space:
mode:
Diffstat (limited to 'lib/btrfsprogs/btrfsinspect/rebuildnodes')
-rw-r--r--lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuilttrees.go2
-rw-r--r--lib/btrfsprogs/btrfsinspect/rebuildnodes/s2_classify.go1
-rw-r--r--lib/btrfsprogs/btrfsinspect/rebuildnodes/s3_reinit.go2
-rw-r--r--lib/btrfsprogs/btrfsinspect/rebuildnodes/s3_reinit_test.go80
4 files changed, 83 insertions, 2 deletions
diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuilttrees.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuilttrees.go
index 0a321ea..9daf97f 100644
--- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuilttrees.go
+++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuilttrees.go
@@ -23,7 +23,7 @@ type RebuiltTrees struct {
type _FS interface {
diskio.File[btrfsvol.LogicalAddr]
- ParentTree(btrfsprim.ObjID) (btrfsprim.ObjID, bool)
+ btrfstree.NodeFile
btrfstree.NodeSource
btrfstree.TreeOperator
}
diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/s2_classify.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/s2_classify.go
index 36e5395..57c26e7 100644
--- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/s2_classify.go
+++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/s2_classify.go
@@ -74,6 +74,7 @@ func classifyNodes(ctx context.Context, fs _FS, scanResults btrfsinspect.ScanDev
},
}
+ progress()
btrfsutil.WalkAllTrees(ctx, fs, btrfsutil.WalkAllTreesHandler{
TreeWalkHandler: walkHandler,
Err: func(err *btrfsutil.WalkError) {
diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/s3_reinit.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/s3_reinit.go
index a7b2f29..fc46d27 100644
--- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/s3_reinit.go
+++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/s3_reinit.go
@@ -105,7 +105,7 @@ func reInitBrokenNodes(ctx context.Context, fs _FS, badNodes []badNode) (map[btr
min, max := spanOfTreePath(fs, path)
node := RebuiltNode{
- Errs: containers.Set[string]{err.Error(): struct{}{}},
+ Errs: containers.Set[string]{badNode.Err: struct{}{}},
MinKey: min,
MaxKey: max,
InTrees: containers.Set[btrfsprim.ObjID]{path.Node(-1).FromTree: struct{}{}},
diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/s3_reinit_test.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/s3_reinit_test.go
new file mode 100644
index 0000000..b361606
--- /dev/null
+++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/s3_reinit_test.go
@@ -0,0 +1,80 @@
+// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com>
+//
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+package rebuildnodes_test
+
+import (
+ "strings"
+ "testing"
+
+ "git.lukeshu.com/go/lowmemjson"
+ "github.com/stretchr/testify/assert"
+
+ "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsprim"
+ "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfstree"
+ "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsvol"
+ "git.lukeshu.com/btrfs-progs-ng/lib/btrfsprogs/btrfsinspect/rebuildnodes"
+ "git.lukeshu.com/btrfs-progs-ng/lib/containers"
+)
+
+func TestEncodeRebuiltNodes(t *testing.T) {
+ dat := map[btrfsvol.LogicalAddr]*rebuildnodes.RebuiltNode{
+ 100007133184: {
+ Errs: containers.Set[string]{
+ "btrfs.ReadNode: node@0x0000001748e3c000: expected generation\u003c=6596014 but claims to be generation=6596025": struct{}{},
+ },
+ MinKey: btrfsprim.Key{},
+ MaxKey: btrfsprim.Key{},
+ InTrees: containers.Set[btrfsprim.ObjID]{
+ 257: struct{}{},
+ },
+ Node: btrfstree.Node{},
+ },
+ }
+ var buf strings.Builder
+ assert.NoError(t, lowmemjson.Encode(&lowmemjson.ReEncoder{
+ Out: &buf,
+
+ Indent: "\t",
+ ForceTrailingNewlines: true,
+ }, dat))
+ assert.Equal(t, `{
+ "100007133184": {
+ "Errs": [
+ "btrfs.ReadNode: node@0x0000001748e3c000: expected generation\u003c=6596014 but claims to be generation=6596025"
+ ],
+ "MinKey": {
+ "ObjectID": 0,
+ "ItemType": 0,
+ "Offset": 0
+ },
+ "MaxKey": {
+ "ObjectID": 0,
+ "ItemType": 0,
+ "Offset": 0
+ },
+ "InTrees": [
+ 257
+ ],
+ "Size": 0,
+ "ChecksumType": 0,
+ "Head": {
+ "Checksum": "0000000000000000000000000000000000000000000000000000000000000000",
+ "MetadataUUID": "00000000-0000-0000-0000-000000000000",
+ "Addr": 0,
+ "Flags": 0,
+ "BackrefRev": 0,
+ "ChunkTreeUUID": "00000000-0000-0000-0000-000000000000",
+ "Generation": 0,
+ "Owner": 0,
+ "NumItems": 0,
+ "Level": 0
+ },
+ "BodyInternal": null,
+ "BodyLeaf": null,
+ "Padding": null
+ }
+}
+`, buf.String())
+}