diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-08-29 21:19:18 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-08-30 21:29:19 -0600 |
commit | 461ca655ff576c81a78c6abd7f4ffa6cd6fae920 (patch) | |
tree | 4d108e0435768a9ea26b47135d1a4f6c95d60340 /lib/btrfsprogs/btrfsinspect/rebuildnodes | |
parent | 96eb8d5f11ab6654d0f963be1777cb92493ee0ab (diff) |
wip
Diffstat (limited to 'lib/btrfsprogs/btrfsinspect/rebuildnodes')
3 files changed, 16 insertions, 6 deletions
diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuildnodes.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuildnodes.go index db722a5..e5365c9 100644 --- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuildnodes.go +++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuildnodes.go @@ -36,12 +36,10 @@ func RebuildNodes(ctx context.Context, fs *btrfs.FS, nodeScanResults btrfsinspec return nil, err } - dlog.Info(ctx, "Initializing nodes to re-build...") rebuiltNodes, err := reInitBrokenNodes(ctx, nfs, nodeScanResults, foundRoots) if err != nil { return nil, err } - dlog.Infof(ctx, "Initialized %d nodes", len(rebuiltNodes)) dlog.Info(ctx, "Attaching lost+found nodes to rebuilt nodes...") if err := reAttachNodes(ctx, nfs, foundRoots, rebuiltNodes); err != nil { @@ -149,7 +147,7 @@ func getChunkTreeUUID(ctx context.Context, fs _FS) (btrfsprim.UUID, bool) { } type RebuiltNode struct { - Err error + Err string MinKey, MaxKey btrfsprim.Key btrfstree.Node } diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuilttrees.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuilttrees.go index d2f0798..0a321ea 100644 --- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuilttrees.go +++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuilttrees.go @@ -39,6 +39,10 @@ func (fs *RebuiltTrees) ReadAt(p []byte, off btrfsvol.LogicalAddr) (int, error) return 0, err } if rebuilt, ok := fs.nodes[off]; ok && len(p) == int(sb.NodeSize) { + rebuilt.Node.Head.Checksum, err = rebuilt.Node.CalculateChecksum() + if err != nil { + panic(fmt.Errorf("should not happen: %w", err)) + } bs, err := rebuilt.Node.MarshalBinary() if err != nil { panic(fmt.Errorf("should not happen: %w", err)) diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/s3_reinit.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/s3_reinit.go index 343956c..eb49435 100644 --- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/s3_reinit.go +++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/s3_reinit.go @@ -19,6 +19,8 @@ import ( ) func reInitBrokenNodes(ctx context.Context, fs _FS, nodeScanResults btrfsinspect.ScanDevicesResult, foundRoots map[btrfsvol.LogicalAddr]struct{}) (map[btrfsvol.LogicalAddr]*RebuiltNode, error) { + dlog.Info(ctx, "Initializing nodes to re-build...") + sb, err := fs.Superblock() if err != nil { return nil, err @@ -59,15 +61,17 @@ func reInitBrokenNodes(ctx context.Context, fs _FS, nodeScanResults btrfsinspect BadNode: func(path btrfstree.TreePath, node *diskio.Ref[btrfsvol.LogicalAddr, btrfstree.Node], err error) error { min, max := spanOfTreePath(fs, path) rebuiltNodes[path.Node(-1).ToNodeAddr] = &RebuiltNode{ - Err: err, + Err: err.Error(), MinKey: min, MaxKey: max, Node: btrfstree.Node{ + Size: sb.NodeSize, + ChecksumType: sb.ChecksumType, Head: btrfstree.NodeHeader{ MetadataUUID: sb.EffectiveMetadataUUID(), Addr: path.Node(-1).ToNodeAddr, ChunkTreeUUID: chunkTreeUUID, - Owner: path.Node(-1).FromTree, + Owner: path.Node(-1).FromTree, // FIXME: handle it being a child tree? Generation: path.Node(-1).FromGeneration, Level: path.Node(-1).ToNodeLevel, }, @@ -95,7 +99,11 @@ func reInitBrokenNodes(ctx context.Context, fs _FS, nodeScanResults btrfsinspect }, walkHandler) } - progress() + if done != total { + panic("should not happen") + } + + dlog.Infof(ctx, "... initialized %d nodes", len(rebuiltNodes)) return rebuiltNodes, nil } |