summaryrefslogtreecommitdiff
path: root/lib/btrfsutil
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-04-05 11:18:11 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2023-04-13 13:18:40 -0600
commit05456e5ffe328c975529645f8e1588ef89f49da0 (patch)
tree4306edfe012ed0e38c0d0f862932349e137091ee /lib/btrfsutil
parentf37ad3c90dab9b77e7c2796e963f5992458ad4a4 (diff)
btrfsutil: RebuiltForrest: Simplify by taking a btrfs.ReadableFS
Diffstat (limited to 'lib/btrfsutil')
-rw-r--r--lib/btrfsutil/rebuilt_forrest.go22
-rw-r--r--lib/btrfsutil/rebuilt_readitem.go4
2 files changed, 14 insertions, 12 deletions
diff --git a/lib/btrfsutil/rebuilt_forrest.go b/lib/btrfsutil/rebuilt_forrest.go
index 6231563..99213f1 100644
--- a/lib/btrfsutil/rebuilt_forrest.go
+++ b/lib/btrfsutil/rebuilt_forrest.go
@@ -10,9 +10,9 @@ import (
"github.com/datawire/dlib/dlog"
+ "git.lukeshu.com/btrfs-progs-ng/lib/btrfs"
"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"
"git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsvol"
"git.lukeshu.com/btrfs-progs-ng/lib/containers"
"git.lukeshu.com/btrfs-progs-ng/lib/slices"
@@ -134,8 +134,7 @@ func (cb noopRebuiltForrestCallbacks) LookupUUID(ctx context.Context, uuid btrfs
// NewRebuiltForrest().
type RebuiltForrest struct {
// static
- file btrfstree.NodeSource
- sb btrfstree.Superblock
+ inner btrfs.ReadableFS
graph Graph
cb RebuiltForrestCallbacks
@@ -149,10 +148,9 @@ type RebuiltForrest struct {
// NewRebuiltForrest returns a new RebuiltForrest instance. The
// RebuiltForrestCallbacks may be nil.
-func NewRebuiltForrest(file btrfstree.NodeSource, sb btrfstree.Superblock, graph Graph, cb RebuiltForrestCallbacks) *RebuiltForrest {
+func NewRebuiltForrest(fs btrfs.ReadableFS, graph Graph, cb RebuiltForrestCallbacks) *RebuiltForrest {
ret := &RebuiltForrest{
- file: file,
- sb: sb,
+ inner: fs,
graph: graph,
cb: cb,
@@ -213,13 +211,17 @@ func (ts *RebuiltForrest) addTree(ctx context.Context, treeID btrfsprim.ObjID, s
var root btrfsvol.LogicalAddr
switch treeID {
case btrfsprim.ROOT_TREE_OBJECTID:
- root = ts.sb.RootTree
+ sb, _ := ts.inner.Superblock()
+ root = sb.RootTree
case btrfsprim.CHUNK_TREE_OBJECTID:
- root = ts.sb.ChunkTree
+ sb, _ := ts.inner.Superblock()
+ root = sb.ChunkTree
case btrfsprim.TREE_LOG_OBJECTID:
- root = ts.sb.LogTree
+ sb, _ := ts.inner.Superblock()
+ root = sb.LogTree
case btrfsprim.BLOCK_GROUP_TREE_OBJECTID:
- root = ts.sb.BlockGroupRoot
+ sb, _ := ts.inner.Superblock()
+ root = sb.BlockGroupRoot
default:
if !ts.addTree(ctx, btrfsprim.ROOT_TREE_OBJECTID, stack) {
dlog.Error(ctx, "failed to add tree: add ROOT_TREE")
diff --git a/lib/btrfsutil/rebuilt_readitem.go b/lib/btrfsutil/rebuilt_readitem.go
index 80a9e4b..d1d1319 100644
--- a/lib/btrfsutil/rebuilt_readitem.go
+++ b/lib/btrfsutil/rebuilt_readitem.go
@@ -36,7 +36,7 @@ func (ts *RebuiltForrest) readItem(ctx context.Context, ptr ItemPtr) btrfsitem.I
panic(fmt.Errorf("should not happen: btrfsutil.RebuiltForrest.readItem called for negative item slot: %v", ptr.Slot))
}
- node, err := ts.file.AcquireNode(ctx, ptr.Node, btrfstree.NodeExpectations{
+ node, err := ts.inner.AcquireNode(ctx, ptr.Node, btrfstree.NodeExpectations{
LAddr: containers.OptionalValue(ptr.Node),
Level: containers.OptionalValue(graphInfo.Level),
Generation: containers.OptionalValue(graphInfo.Generation),
@@ -51,7 +51,7 @@ func (ts *RebuiltForrest) readItem(ctx context.Context, ptr ItemPtr) btrfsitem.I
MinItem: containers.OptionalValue(graphInfo.MinItem(ts.graph)),
MaxItem: containers.OptionalValue(graphInfo.MaxItem(ts.graph)),
})
- defer ts.file.ReleaseNode(node)
+ defer ts.inner.ReleaseNode(node)
if err != nil {
panic(fmt.Errorf("should not happen: i/o error: %w", err))
}