diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-08-28 16:55:06 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-08-30 21:28:11 -0600 |
commit | 8aea2c35c9475293c89293a148134c0e6d5c4e7b (patch) | |
tree | 36f5290e2e7f0c05526d5b7e4306c37c0e65ca8e /lib/btrfs/io3_btree.go | |
parent | 8758b0e2000f0892e487afc376a6d75bb08ffb9b (diff) |
wip
Diffstat (limited to 'lib/btrfs/io3_btree.go')
-rw-r--r-- | lib/btrfs/io3_btree.go | 64 |
1 files changed, 21 insertions, 43 deletions
diff --git a/lib/btrfs/io3_btree.go b/lib/btrfs/io3_btree.go index 31cf857..8455eee 100644 --- a/lib/btrfs/io3_btree.go +++ b/lib/btrfs/io3_btree.go @@ -6,7 +6,6 @@ package btrfs import ( "context" - "fmt" "github.com/datawire/dlib/dlog" @@ -14,24 +13,23 @@ import ( "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" - "git.lukeshu.com/btrfs-progs-ng/lib/containers" "git.lukeshu.com/btrfs-progs-ng/lib/diskio" ) func (fs *FS) TreeWalk(ctx context.Context, treeID btrfsprim.ObjID, errHandle func(*btrfstree.TreeError), cbs btrfstree.TreeWalkHandler) { - btrfstree.TreesImpl{NodeSource: fs}.TreeWalk(ctx, treeID, errHandle, cbs) + btrfstree.TreeOperatorImpl{NodeSource: fs}.TreeWalk(ctx, treeID, errHandle, cbs) } func (fs *FS) TreeLookup(treeID btrfsprim.ObjID, key btrfsprim.Key) (btrfstree.Item, error) { - return btrfstree.TreesImpl{NodeSource: fs}.TreeLookup(treeID, key) + return btrfstree.TreeOperatorImpl{NodeSource: fs}.TreeLookup(treeID, key) } func (fs *FS) TreeSearch(treeID btrfsprim.ObjID, fn func(key btrfsprim.Key, size uint32) int) (btrfstree.Item, error) { - return btrfstree.TreesImpl{NodeSource: fs}.TreeSearch(treeID, fn) + return btrfstree.TreeOperatorImpl{NodeSource: fs}.TreeSearch(treeID, fn) } func (fs *FS) TreeSearchAll(treeID btrfsprim.ObjID, fn func(key btrfsprim.Key, size uint32) int) ([]btrfstree.Item, error) { - return btrfstree.TreesImpl{NodeSource: fs}.TreeSearchAll(treeID, fn) + return btrfstree.TreeOperatorImpl{NodeSource: fs}.TreeSearchAll(treeID, fn) } -var _ btrfstree.Trees = (*FS)(nil) +var _ btrfstree.TreeOperator = (*FS)(nil) func (fs *FS) populateTreeUUIDs(ctx context.Context) { if fs.cacheObjID2UUID == nil || fs.cacheUUID2ObjID == nil || fs.cacheTreeParent == nil { @@ -59,44 +57,24 @@ func (fs *FS) populateTreeUUIDs(ctx context.Context) { } } -var noParents = make(map[btrfsprim.ObjID]struct{}) - -func (fs *FS) ReadNode(path btrfstree.TreePath) (*diskio.Ref[btrfsvol.LogicalAddr, btrfstree.Node], error) { - sb, err := fs.Superblock() - if err != nil { - return nil, fmt.Errorf("btrfs.FS.ReadNode: %w", err) +func (fs *FS) ParentTree(tree btrfsprim.ObjID) (btrfsprim.ObjID, bool) { + ctx := context.TODO() + if tree < btrfsprim.FIRST_FREE_OBJECTID { + return 0, false } - - potentialOwners := []btrfsprim.ObjID{ - path.Node(-1).FromTree, + fs.populateTreeUUIDs(ctx) + parentUUID := fs.cacheTreeParent[tree] + if parentUUID == (btrfsprim.UUID{}) { + return 0, false } - if potentialOwners[0] >= btrfsprim.FIRST_FREE_OBJECTID { - ctx := context.TODO() - fs.populateTreeUUIDs(ctx) - for potentialOwners[len(potentialOwners)-1] >= btrfsprim.FIRST_FREE_OBJECTID { - objID := potentialOwners[len(potentialOwners)-1] - parentUUID := fs.cacheTreeParent[objID] - if parentUUID == (btrfsprim.UUID{}) { - if _, already := noParents[objID]; !already { - dlog.Infof(ctx, "dbg: objID=%v has no parent", objID) - noParents[objID] = struct{}{} - } - break - } - dlog.Infof(ctx, "dbg: parent of objID=%v is %v", objID, parentUUID) - parentObjID, ok := fs.cacheUUID2ObjID[parentUUID] - if !ok { - dlog.Errorf(ctx, "dbg: could not resolve parentUUID=%v to an ObjID", parentUUID) - break - } - potentialOwners = append(potentialOwners, parentObjID) - } + parentObjID, ok := fs.cacheUUID2ObjID[parentUUID] + if !ok { + dlog.Errorf(ctx, "dbg: could not resolve parentUUID=%v to an ObjID", parentUUID) + return 0, false } + return parentObjID, true +} - return btrfstree.ReadNode[btrfsvol.LogicalAddr](fs, *sb, path.Node(-1).ToNodeAddr, btrfstree.NodeExpectations{ - LAddr: containers.Optional[btrfsvol.LogicalAddr]{OK: true, Val: path.Node(-1).ToNodeAddr}, - Level: containers.Optional[uint8]{OK: true, Val: path.Node(-1).ToNodeLevel}, - MaxGeneration: containers.Optional[btrfsprim.Generation]{OK: true, Val: path.Node(-1).FromGeneration}, - Owner: potentialOwners, - }) +func (fs *FS) ReadNode(path btrfstree.TreePath) (*diskio.Ref[btrfsvol.LogicalAddr, btrfstree.Node], error) { + return btrfstree.FSReadNode(fs, path) } |