From 5520c20c493d52d83288bc2e321117006e38fd1a Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 22 Mar 2023 21:28:59 -0400 Subject: btrfsutil: RebuiltTree: Allow nodes with .Gen == .ParentGen --- lib/btrfsutil/rebuilt_tree.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/btrfsutil') diff --git a/lib/btrfsutil/rebuilt_tree.go b/lib/btrfsutil/rebuilt_tree.go index 3fff9b2..96d5a75 100644 --- a/lib/btrfsutil/rebuilt_tree.go +++ b/lib/btrfsutil/rebuilt_tree.go @@ -122,7 +122,7 @@ func (tree *RebuiltTree) isOwnerOK(owner btrfsprim.ObjID, gen btrfsprim.Generati if owner == tree.ID { return true } - if tree.Parent == nil || gen >= tree.ParentGen { + if tree.Parent == nil || gen > tree.ParentGen { return false } tree = tree.Parent -- cgit v1.2.3-2-g168b From d11a5357df7d155a7a3e92a67971d3d52ff6ad86 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 22 Mar 2023 13:43:15 -0400 Subject: btrfstree: Add a 'generation' argument the owner validation Validating a node's owner properly requires the generation. But don't worry about actually doing it properly yet, just update the API first. --- lib/btrfsutil/old_rebuilt_forrest.go | 2 +- lib/btrfsutil/rebuilt_readitem.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/btrfsutil') diff --git a/lib/btrfsutil/old_rebuilt_forrest.go b/lib/btrfsutil/old_rebuilt_forrest.go index bb5ab59..a3fc0e2 100644 --- a/lib/btrfsutil/old_rebuilt_forrest.go +++ b/lib/btrfsutil/old_rebuilt_forrest.go @@ -240,7 +240,7 @@ func (bt *OldRebuiltForrest) readNode(nodeInfo nodeInfo) *btrfstree.Node { LAddr: containers.OptionalValue(nodeInfo.LAddr), Level: containers.OptionalValue(nodeInfo.Level), Generation: containers.OptionalValue(nodeInfo.Generation), - Owner: func(treeID btrfsprim.ObjID) error { + Owner: func(treeID btrfsprim.ObjID, _ btrfsprim.Generation) error { if treeID != nodeInfo.Owner { return fmt.Errorf("expected owner=%v but claims to have owner=%v", nodeInfo.Owner, treeID) diff --git a/lib/btrfsutil/rebuilt_readitem.go b/lib/btrfsutil/rebuilt_readitem.go index ff919f0..5de6864 100644 --- a/lib/btrfsutil/rebuilt_readitem.go +++ b/lib/btrfsutil/rebuilt_readitem.go @@ -42,7 +42,7 @@ func (ts *RebuiltForrest) readNode(ctx context.Context, laddr btrfsvol.LogicalAd LAddr: containers.OptionalValue(laddr), Level: containers.OptionalValue(graphInfo.Level), Generation: containers.OptionalValue(graphInfo.Generation), - Owner: func(treeID btrfsprim.ObjID) error { + Owner: func(treeID btrfsprim.ObjID, _ btrfsprim.Generation) error { if treeID != graphInfo.Owner { return fmt.Errorf("expected owner=%v but claims to have owner=%v", graphInfo.Owner, treeID) -- cgit v1.2.3-2-g168b From 418553acc64567ebc95122e28b07657526c92923 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 22 Mar 2023 17:25:54 -0400 Subject: btrfs: Consider the generation when checking if a node owner is OK --- lib/btrfsutil/old_rebuilt_forrest.go | 9 +++++---- lib/btrfsutil/rebuilt_readitem.go | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'lib/btrfsutil') diff --git a/lib/btrfsutil/old_rebuilt_forrest.go b/lib/btrfsutil/old_rebuilt_forrest.go index a3fc0e2..5b99892 100644 --- a/lib/btrfsutil/old_rebuilt_forrest.go +++ b/lib/btrfsutil/old_rebuilt_forrest.go @@ -240,10 +240,11 @@ func (bt *OldRebuiltForrest) readNode(nodeInfo nodeInfo) *btrfstree.Node { LAddr: containers.OptionalValue(nodeInfo.LAddr), Level: containers.OptionalValue(nodeInfo.Level), Generation: containers.OptionalValue(nodeInfo.Generation), - Owner: func(treeID btrfsprim.ObjID, _ btrfsprim.Generation) error { - if treeID != nodeInfo.Owner { - return fmt.Errorf("expected owner=%v but claims to have owner=%v", - nodeInfo.Owner, treeID) + Owner: func(treeID btrfsprim.ObjID, gen btrfsprim.Generation) error { + if treeID != nodeInfo.Owner || gen != nodeInfo.Generation { + return fmt.Errorf("expected owner=%v generation=%v but claims to have owner=%v generation=%v", + nodeInfo.Owner, nodeInfo.Generation, + treeID, gen) } return nil }, diff --git a/lib/btrfsutil/rebuilt_readitem.go b/lib/btrfsutil/rebuilt_readitem.go index 5de6864..03a7cdc 100644 --- a/lib/btrfsutil/rebuilt_readitem.go +++ b/lib/btrfsutil/rebuilt_readitem.go @@ -42,10 +42,11 @@ func (ts *RebuiltForrest) readNode(ctx context.Context, laddr btrfsvol.LogicalAd LAddr: containers.OptionalValue(laddr), Level: containers.OptionalValue(graphInfo.Level), Generation: containers.OptionalValue(graphInfo.Generation), - Owner: func(treeID btrfsprim.ObjID, _ btrfsprim.Generation) error { - if treeID != graphInfo.Owner { - return fmt.Errorf("expected owner=%v but claims to have owner=%v", - graphInfo.Owner, treeID) + Owner: func(treeID btrfsprim.ObjID, gen btrfsprim.Generation) error { + if treeID != graphInfo.Owner || gen != graphInfo.Generation { + return fmt.Errorf("expected owner=%v generation=%v but claims to have owner=%v generation=%v", + graphInfo.Owner, graphInfo.Generation, + treeID, gen) } return nil }, -- cgit v1.2.3-2-g168b