diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-04-15 09:00:33 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-04-17 01:49:21 -0600 |
commit | f262c7bbc72796ae36b7e40dc38ab7167d138d5b (patch) | |
tree | 1dbcbd104be9e1034037a2d43b5927b1b61c08d6 /lib/btrfs/btrfstree | |
parent | 9814752ef68aa9ef377a4a939bc83d2409d4fcef (diff) |
btrfsutil: RebuiltForrest: Add a lax-ancestor mode
Diffstat (limited to 'lib/btrfs/btrfstree')
-rw-r--r-- | lib/btrfs/btrfstree/path.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/btrfs/btrfstree/path.go b/lib/btrfs/btrfstree/path.go index acc0e73..327a39b 100644 --- a/lib/btrfs/btrfstree/path.go +++ b/lib/btrfs/btrfstree/path.go @@ -12,6 +12,7 @@ import ( "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsprim" "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsvol" "git.lukeshu.com/btrfs-progs-ng/lib/containers" + "git.lukeshu.com/btrfs-progs-ng/lib/slices" ) // Path is a path from the superblock or a ROOT_ITEM to a node or @@ -137,6 +138,7 @@ func checkOwner( ctx context.Context, forrest Forrest, treeID btrfsprim.ObjID, ownerToCheck btrfsprim.ObjID, genToCheck btrfsprim.Generation, ) error { + var stack []btrfsprim.ObjID for { if ownerToCheck == treeID { return nil @@ -154,6 +156,12 @@ func checkOwner( ownerToCheck, genToCheck, err) } + stack = append(stack, treeID) + if slices.Contains(parentID, stack) { + // Don't get stuck in an infinite loop if there's a cycle. + parentID = 0 + } + if parentID == 0 && parentGen == 0 { return fmt.Errorf("owner=%v is not acceptable in this tree", ownerToCheck) |