From 9814752ef68aa9ef377a4a939bc83d2409d4fcef Mon Sep 17 00:00:00 2001
From: Luke Shumaker <lukeshu@lukeshu.com>
Date: Sun, 16 Apr 2023 23:51:14 -0600
Subject: btrfstree: Path.NodeExpectations(): Drop the ability to fail open

---
 lib/btrfs/btrfstree/btree_tree.go    |  2 +-
 lib/btrfs/btrfstree/path.go          | 14 ++++----------
 lib/btrfsutil/old_rebuilt_forrest.go |  2 +-
 lib/btrfsutil/rebuilt_tree.go        |  2 +-
 4 files changed, 7 insertions(+), 13 deletions(-)

(limited to 'lib')

diff --git a/lib/btrfs/btrfstree/btree_tree.go b/lib/btrfs/btrfstree/btree_tree.go
index 6056ae8..b9b9201 100644
--- a/lib/btrfs/btrfstree/btree_tree.go
+++ b/lib/btrfs/btrfstree/btree_tree.go
@@ -54,7 +54,7 @@ func (tree *RawTree) walk(ctx context.Context, sb Superblock, path Path, cbs Tre
 	}
 
 	// 001
-	nodeAddr, nodeExp, ok := path.NodeExpectations(ctx, true) // TODO(lukeshu): Consider whether failing open is the right thing here
+	nodeAddr, nodeExp, ok := path.NodeExpectations(ctx)
 	if !ok {
 		return
 	}
diff --git a/lib/btrfs/btrfstree/path.go b/lib/btrfs/btrfstree/path.go
index 57669ee..acc0e73 100644
--- a/lib/btrfs/btrfstree/path.go
+++ b/lib/btrfs/btrfstree/path.go
@@ -134,7 +134,7 @@ func (path Path) String() string {
 }
 
 func checkOwner(
-	ctx context.Context, forrest Forrest, treeID btrfsprim.ObjID, failOpen bool,
+	ctx context.Context, forrest Forrest, treeID btrfsprim.ObjID,
 	ownerToCheck btrfsprim.ObjID, genToCheck btrfsprim.Generation,
 ) error {
 	for {
@@ -144,18 +144,12 @@ func checkOwner(
 
 		tree, err := forrest.ForrestLookup(ctx, treeID)
 		if err != nil {
-			if failOpen {
-				return nil
-			}
 			return fmt.Errorf("unable to determine whether owner=%v generation=%v is acceptable: %w",
 				ownerToCheck, genToCheck, err)
 		}
 
 		parentID, parentGen, err := tree.TreeParentID(ctx)
 		if err != nil {
-			if failOpen {
-				return nil
-			}
 			return fmt.Errorf("unable to determine whether owner=%v generation=%v is acceptable: %w",
 				ownerToCheck, genToCheck, err)
 		}
@@ -177,7 +171,7 @@ func checkOwner(
 //
 // `ok` is false if the path is empty or if this Path points to an
 // item rather than a node.
-func (path Path) NodeExpectations(ctx context.Context, failOpen bool) (_ btrfsvol.LogicalAddr, _ NodeExpectations, ok bool) {
+func (path Path) NodeExpectations(ctx context.Context) (_ btrfsvol.LogicalAddr, _ NodeExpectations, ok bool) {
 	if len(path) == 0 {
 		return 0, NodeExpectations{}, false
 	}
@@ -192,7 +186,7 @@ func (path Path) NodeExpectations(ctx context.Context, failOpen bool) (_ btrfsvo
 			Level:      containers.OptionalValue(lastElem.ToLevel),
 			Generation: containers.OptionalValue(lastElem.ToGeneration),
 			Owner: func(owner btrfsprim.ObjID, gen btrfsprim.Generation) error {
-				return checkOwner(ctx, firstElem.Forrest, lastElem.TreeID, failOpen,
+				return checkOwner(ctx, firstElem.Forrest, lastElem.TreeID,
 					owner, gen)
 			},
 			MinItem: containers.OptionalValue(btrfsprim.Key{}),
@@ -204,7 +198,7 @@ func (path Path) NodeExpectations(ctx context.Context, failOpen bool) (_ btrfsvo
 			Level:      containers.OptionalValue(lastElem.ToLevel),
 			Generation: containers.OptionalValue(lastElem.ToGeneration),
 			Owner: func(owner btrfsprim.ObjID, gen btrfsprim.Generation) error {
-				return checkOwner(ctx, firstElem.Forrest, lastElem.FromTree, failOpen,
+				return checkOwner(ctx, firstElem.Forrest, lastElem.FromTree,
 					owner, gen)
 			},
 			MinItem: containers.OptionalValue(lastElem.ToMinKey),
diff --git a/lib/btrfsutil/old_rebuilt_forrest.go b/lib/btrfsutil/old_rebuilt_forrest.go
index b03ddc2..a23278c 100644
--- a/lib/btrfsutil/old_rebuilt_forrest.go
+++ b/lib/btrfsutil/old_rebuilt_forrest.go
@@ -190,7 +190,7 @@ func (bt *OldRebuiltForrest) rawTreeWalk(ctx context.Context, treeID btrfsprim.O
 	var curNode oldRebuiltNodeInfo
 	cbs := btrfstree.TreeWalkHandler{
 		BadNode: func(path btrfstree.Path, node *btrfstree.Node, err error) bool {
-			nodeAddr, nodeExp, _ := path.NodeExpectations(ctx, false)
+			nodeAddr, nodeExp, _ := path.NodeExpectations(ctx)
 			cacheEntry.Errors.Insert(oldRebuiltTreeError{
 				Min:  nodeExp.MinItem.Val,
 				Max:  nodeExp.MaxItem.Val,
diff --git a/lib/btrfsutil/rebuilt_tree.go b/lib/btrfsutil/rebuilt_tree.go
index 8d5921b..e963f0a 100644
--- a/lib/btrfsutil/rebuilt_tree.go
+++ b/lib/btrfsutil/rebuilt_tree.go
@@ -660,7 +660,7 @@ func (walker *rebuiltWalker) walk(ctx context.Context, path btrfstree.Path) {
 	}
 
 	// 001
-	nodeAddr, nodeExp, ok := path.NodeExpectations(ctx, false)
+	nodeAddr, nodeExp, ok := path.NodeExpectations(ctx)
 	if !ok {
 		panic(fmt.Errorf("should not happen: btrfsutil.rebuiltWalker.walk called with non-node path: %v",
 			path))
-- 
cgit v1.2.3-2-g168b