diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-03-30 12:14:34 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-03-30 12:14:34 -0600 |
commit | 3d5e080385ed64ca5e0810263acc2d9970f14baa (patch) | |
tree | af7a1e957d0ffcae3e2ba3d3a11a8c64a545a65f /lib/btrfs/io2_lv.go | |
parent | e62b128e088346e891b8b2a5e6458cf77abc9d02 (diff) | |
parent | c7b6460ee9b3c07c13c973cbc8c8f690560fefc6 (diff) |
Merge branch 'lukeshu/tree-api-pt3-forrest'
Diffstat (limited to 'lib/btrfs/io2_lv.go')
-rw-r--r-- | lib/btrfs/io2_lv.go | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/lib/btrfs/io2_lv.go b/lib/btrfs/io2_lv.go index 44378a0..e9de215 100644 --- a/lib/btrfs/io2_lv.go +++ b/lib/btrfs/io2_lv.go @@ -161,37 +161,39 @@ func (fs *FS) initDev(ctx context.Context, sb btrfstree.Superblock) error { } } } + chunkTree, err := fs.ForrestLookup(ctx, btrfsprim.CHUNK_TREE_OBJECTID) + if err != nil { + return err + } + var errs derror.MultiError - fs.TreeWalk(ctx, btrfsprim.CHUNK_TREE_OBJECTID, - func(err *btrfstree.TreeError) { - errs = append(errs, err) - }, - btrfstree.TreeWalkHandler{ - Item: func(_ btrfstree.Path, item btrfstree.Item) { - if item.Key.ItemType != btrfsitem.CHUNK_ITEM_KEY { - return - } - switch itemBody := item.Body.(type) { - case *btrfsitem.Chunk: - for _, mapping := range itemBody.Mappings(item.Key) { - if err := fs.LV.AddMapping(mapping); err != nil { - errs = append(errs, err) - } - } - case *btrfsitem.Error: - // do nothing - default: - // This is a panic because the item decoder should not emit CHUNK_ITEM items as - // anything but btrfsitem.Chunk or btrfsitem.Error without this code also being - // updated. - panic(fmt.Errorf("should not happen: CHUNK_ITEM has unexpected item type: %T", itemBody)) + if err := chunkTree.TreeRange(ctx, func(item btrfstree.Item) bool { + if item.Key.ItemType != btrfsitem.CHUNK_ITEM_KEY { + return true + } + switch itemBody := item.Body.(type) { + case *btrfsitem.Chunk: + for _, mapping := range itemBody.Mappings(item.Key) { + if err := fs.LV.AddMapping(mapping); err != nil { + errs = append(errs, err) } - }, - }, - ) + } + case *btrfsitem.Error: + // do nothing + default: + // This is a panic because the item decoder should not emit CHUNK_ITEM items as + // anything but btrfsitem.Chunk or btrfsitem.Error without this code also being + // updated. + panic(fmt.Errorf("should not happen: CHUNK_ITEM has unexpected item type: %T", itemBody)) + } + return true + }); err != nil { + errs = append(errs, err) + } if len(errs) > 0 { return errs } + return nil } |