summaryrefslogtreecommitdiff
path: root/lib/btrfs/btrfstree/readnode.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-03-30 10:04:09 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2023-03-30 10:04:09 -0600
commitcdc2df19c59965149e11c3a5710458c626ea0668 (patch)
tree2e0bafd99a433d7271bf42e68ab1b5c1eba99e2b /lib/btrfs/btrfstree/readnode.go
parent0b092a27122fcf19479d6cdeae5f7c9493d9741a (diff)
parent94aa0ec3e9f7145cdf177ad6f6d3d8b7d5bdbef7 (diff)
Merge branch 'lukeshu/node-cache'
Diffstat (limited to 'lib/btrfs/btrfstree/readnode.go')
-rw-r--r--lib/btrfs/btrfstree/readnode.go24
1 files changed, 11 insertions, 13 deletions
diff --git a/lib/btrfs/btrfstree/readnode.go b/lib/btrfs/btrfstree/readnode.go
index ac82c62..a4ccf10 100644
--- a/lib/btrfs/btrfstree/readnode.go
+++ b/lib/btrfs/btrfstree/readnode.go
@@ -14,8 +14,7 @@ import (
)
type NodeFile interface {
- diskio.File[btrfsvol.LogicalAddr]
- Superblock() (*Superblock, error)
+ diskio.ReaderAt[btrfsvol.LogicalAddr]
// ParentTree, given a tree ID, returns that tree's parent
// tree, if it has one.
@@ -29,15 +28,14 @@ type NodeFile interface {
ParentTree(btrfsprim.ObjID) (btrfsprim.ObjID, btrfsprim.Generation, bool)
}
-// FSReadNode is a utility function to help with implementing the
-// 'NodeSource' interface.
-func FSReadNode(
- fs NodeFile,
- path Path,
-) (*Node, error) {
- sb, err := fs.Superblock()
- if err != nil {
- return nil, fmt.Errorf("btrfs.FS.ReadNode: %w", err)
+// NodeExpectations returns the address to read and the expectations
+// to have when reading the node pointed to by this Path.
+//
+// `ok` is false if the path is empty or if this Path points to an
+// item rather than a node.
+func (path Path) NodeExpectations(fs NodeFile) (_ btrfsvol.LogicalAddr, _ NodeExpectations, ok bool) {
+ if path.Node(-1).ToNodeAddr == 0 && path.Node(-1).ToNodeGeneration == 0 && path.Node(-1).ToNodeLevel == 0 {
+ return 0, NodeExpectations{}, false
}
checkOwner := func(owner btrfsprim.ObjID, gen btrfsprim.Generation) error {
@@ -70,12 +68,12 @@ func FSReadNode(
}
}
- return ReadNode[btrfsvol.LogicalAddr](fs, *sb, path.Node(-1).ToNodeAddr, NodeExpectations{
+ return path.Node(-1).ToNodeAddr, NodeExpectations{
LAddr: containers.OptionalValue(path.Node(-1).ToNodeAddr),
Level: containers.OptionalValue(path.Node(-1).ToNodeLevel),
Generation: containers.OptionalValue(path.Node(-1).ToNodeGeneration),
Owner: checkOwner,
MinItem: containers.OptionalValue(path.Node(-1).ToKey),
MaxItem: containers.OptionalValue(path.Node(-1).ToMaxKey),
- })
+ }, true
}