From 8530a8b7b5f9f27bb5b5c319f285bb5a26470285 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 6 Jan 2023 02:03:50 -0700 Subject: rebuildnodes: Rework to be clear about what went wrong when reading --- .../btrfsinspect/rebuildnodes/rebuild.go | 24 +++------------------- 1 file changed, 3 insertions(+), 21 deletions(-) (limited to 'lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild.go') diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild.go index 624441f..d11ca58 100644 --- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild.go +++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild.go @@ -91,12 +91,6 @@ func NewRebuilder(ctx context.Context, fs *btrfs.FS, nodeScanResults btrfsinspec return o, nil } -func (o *rebuilder) ioErr(ctx context.Context, err error) { - err = fmt.Errorf("should not happen: i/o error: %w", err) - dlog.Error(ctx, err) - panic(err) -} - func (o *rebuilder) ListRoots() map[btrfsprim.ObjID]containers.Set[btrfsvol.LogicalAddr] { return o.rebuilt.ListRoots() } @@ -174,13 +168,9 @@ func (o *rebuilder) Rebuild(_ctx context.Context) error { return err } itemCtx := dlog.WithField(stepCtx, "btrfsinspect.rebuild-nodes.rebuild.process.item", key) - itemBody, ok := o.rebuilt.Tree(itemCtx, key.TreeID).ReadItem(itemCtx, key.Key) - if !ok { - o.ioErr(itemCtx, fmt.Errorf("could not read previously read item: %v", key)) - } itemChan <- keyAndBody{ keyAndTree: key, - Body: itemBody, + Body: o.rebuilt.Tree(itemCtx, key.TreeID).ReadItem(itemCtx, key.Key), } } return nil @@ -285,11 +275,7 @@ func (o *rebuilder) cbLookupRoot(ctx context.Context, tree btrfsprim.ObjID) (off o.enqueueRetry() return 0, btrfsitem.Root{}, false } - itemBody, ok := o.rebuilt.Tree(ctx, key.TreeID).ReadItem(ctx, key.Key) - if !ok { - o.ioErr(ctx, fmt.Errorf("could not read previously read item: %v", key)) - } - switch itemBody := itemBody.(type) { + switch itemBody := o.rebuilt.Tree(ctx, key.TreeID).ReadItem(ctx, key.Key).(type) { case *btrfsitem.Root: return btrfsprim.Generation(key.Offset), *itemBody, true case *btrfsitem.Error: @@ -310,11 +296,7 @@ func (o *rebuilder) cbLookupUUID(ctx context.Context, uuid btrfsprim.UUID) (id b o.enqueueRetry() return 0, false } - itemBody, ok := o.rebuilt.Tree(ctx, key.TreeID).ReadItem(ctx, key.Key) - if !ok { - o.ioErr(ctx, fmt.Errorf("could not read previously read item: %v", key)) - } - switch itemBody := itemBody.(type) { + switch itemBody := o.rebuilt.Tree(ctx, key.TreeID).ReadItem(ctx, key.Key).(type) { case *btrfsitem.UUIDMap: return itemBody.ObjID, true case *btrfsitem.Error: -- cgit v1.2.3-2-g168b