summaryrefslogtreecommitdiff
path: root/lib/btrfsutil/rebuilt_readitem.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/btrfsutil/rebuilt_readitem.go')
-rw-r--r--lib/btrfsutil/rebuilt_readitem.go20
1 files changed, 7 insertions, 13 deletions
diff --git a/lib/btrfsutil/rebuilt_readitem.go b/lib/btrfsutil/rebuilt_readitem.go
index 03a7cdc..d3a2253 100644
--- a/lib/btrfsutil/rebuilt_readitem.go
+++ b/lib/btrfsutil/rebuilt_readitem.go
@@ -26,18 +26,14 @@ func (ptr ItemPtr) String() string {
return fmt.Sprintf("node@%v[%v]", ptr.Node, ptr.Slot)
}
-func (ts *RebuiltForrest) readNode(ctx context.Context, laddr btrfsvol.LogicalAddr) *btrfstree.Node {
- if cached, ok := ts.nodes.Load(laddr); ok {
- dlog.Tracef(ctx, "cache-hit node@%v", laddr)
- return cached
- }
+func (ts *RebuiltForrest) readNode(ctx context.Context, laddr btrfsvol.LogicalAddr, out *btrfstree.Node) {
+ dlog.Debugf(ctx, "cache-miss node@%v, reading...", laddr)
graphInfo, ok := ts.graph.Nodes[laddr]
if !ok {
panic(fmt.Errorf("should not happen: node@%v is not mentioned in the in-memory graph", laddr))
}
- dlog.Debugf(ctx, "cache-miss node@%v, reading...", laddr)
node, err := btrfstree.ReadNode[btrfsvol.LogicalAddr](ts.file, ts.sb, laddr, btrfstree.NodeExpectations{
LAddr: containers.OptionalValue(laddr),
Level: containers.OptionalValue(graphInfo.Level),
@@ -56,22 +52,20 @@ func (ts *RebuiltForrest) readNode(ctx context.Context, laddr btrfsvol.LogicalAd
if err != nil {
panic(fmt.Errorf("should not happen: i/o error: %w", err))
}
-
- ts.nodes.Store(laddr, node)
-
- return node
+ *out = *node
}
func (ts *RebuiltForrest) readItem(ctx context.Context, ptr ItemPtr) btrfsitem.Item {
- ts.nodesMu.Lock()
- defer ts.nodesMu.Unlock()
if ts.graph.Nodes[ptr.Node].Level != 0 {
panic(fmt.Errorf("should not happen: btrfsutil.RebuiltForrest.readItem called for non-leaf node@%v", ptr.Node))
}
if ptr.Slot < 0 {
panic(fmt.Errorf("should not happen: btrfsutil.RebuiltForrest.readItem called for negative item slot: %v", ptr.Slot))
}
- items := ts.readNode(ctx, ptr.Node).BodyLeaf
+
+ items := ts.nodes.Acquire(ctx, ptr.Node).BodyLeaf
+ defer ts.nodes.Release(ptr.Node)
+
if ptr.Slot >= len(items) {
panic(fmt.Errorf("should not happen: btrfsutil.RebuiltForrest.readItem called for out-of-bounds item slot: slot=%v len=%v",
ptr.Slot, len(items)))