summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-04-05 11:23:03 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2023-04-13 13:33:18 -0600
commitc9ca78f970f0b48fbf6965e8ec15f6b8f31ce485 (patch)
tree01e7a80fe15f3b14cf8df64b1b03bc91f9677487
parentdf6444f337ae24220b4e14443d9cd6e74e8d0606 (diff)
btrfsutil: RebuiltForrest: readItem: Return a full btrfstree.Item
-rw-r--r--lib/btrfsutil/rebuilt_callbacks.go12
-rw-r--r--lib/btrfsutil/rebuilt_readitem.go8
-rw-r--r--lib/btrfsutil/rebuilt_tree.go2
3 files changed, 12 insertions, 10 deletions
diff --git a/lib/btrfsutil/rebuilt_callbacks.go b/lib/btrfsutil/rebuilt_callbacks.go
index 3a7e6e6..41fe7f1 100644
--- a/lib/btrfsutil/rebuilt_callbacks.go
+++ b/lib/btrfsutil/rebuilt_callbacks.go
@@ -48,9 +48,9 @@ func (cb noopRebuiltForrestCallbacks) LookupRoot(ctx context.Context, tree btrfs
if !ok {
return 0, btrfsitem.Root{}, false
}
- itemBody := cb.forrest.readItem(ctx, itemPtr)
- defer itemBody.Free()
- switch itemBody := itemBody.(type) {
+ item := cb.forrest.readItem(ctx, itemPtr)
+ defer item.Body.Free()
+ switch itemBody := item.Body.(type) {
case *btrfsitem.Root:
return btrfsprim.Generation(itemKey.Offset), *itemBody, true
case *btrfsitem.Error:
@@ -73,9 +73,9 @@ func (cb noopRebuiltForrestCallbacks) LookupUUID(ctx context.Context, uuid btrfs
if !ok {
return 0, false
}
- itemBody := cb.forrest.readItem(ctx, itemPtr)
- defer itemBody.Free()
- switch itemBody := itemBody.(type) {
+ item := cb.forrest.readItem(ctx, itemPtr)
+ defer item.Body.Free()
+ switch itemBody := item.Body.(type) {
case *btrfsitem.UUIDMap:
return itemBody.ObjID, true
case *btrfsitem.Error:
diff --git a/lib/btrfsutil/rebuilt_readitem.go b/lib/btrfsutil/rebuilt_readitem.go
index d1d1319..e5faa45 100644
--- a/lib/btrfsutil/rebuilt_readitem.go
+++ b/lib/btrfsutil/rebuilt_readitem.go
@@ -8,7 +8,6 @@ import (
"context"
"fmt"
- "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"
@@ -24,7 +23,7 @@ func (ptr ItemPtr) String() string {
return fmt.Sprintf("node@%v[%v]", ptr.Node, ptr.Slot)
}
-func (ts *RebuiltForrest) readItem(ctx context.Context, ptr ItemPtr) btrfsitem.Item {
+func (ts *RebuiltForrest) readItem(ctx context.Context, ptr ItemPtr) btrfstree.Item {
graphInfo, ok := ts.graph.Nodes[ptr.Node]
if !ok {
panic(fmt.Errorf("should not happen: btrfsutil.RebuiltForrest.readItem called for node@%v not mentioned in the in-memory graph", ptr.Node))
@@ -62,5 +61,8 @@ func (ts *RebuiltForrest) readItem(ctx context.Context, ptr ItemPtr) btrfsitem.I
panic(fmt.Errorf("should not happen: btrfsutil.RebuiltForrest.readItem called for out-of-bounds item slot: slot=%v len=%v",
ptr.Slot, len(items)))
}
- return items[ptr.Slot].Body.CloneItem()
+
+ item := items[ptr.Slot]
+ item.Body = item.Body.CloneItem()
+ return item
}
diff --git a/lib/btrfsutil/rebuilt_tree.go b/lib/btrfsutil/rebuilt_tree.go
index c291319..ca5ccf3 100644
--- a/lib/btrfsutil/rebuilt_tree.go
+++ b/lib/btrfsutil/rebuilt_tree.go
@@ -473,7 +473,7 @@ func (tree *RebuiltTree) ReadItem(ctx context.Context, key btrfsprim.Key) btrfsi
if !ok {
panic(fmt.Errorf("should not happen: btrfsutil.RebuiltTree.ReadItem called for not-included key: %v", key))
}
- return tree.forrest.readItem(ctx, ptr)
+ return tree.forrest.readItem(ctx, ptr).Body
}
// RebuiltLeafToRoots returns the list of potential roots (to pass to