summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/btrfscheck/graph.go104
-rw-r--r--lib/btrfsutil/graph.go4
-rw-r--r--lib/btrfsutil/graph_loops.go4
-rw-r--r--lib/btrfsutil/nestedlock.go2
-rw-r--r--lib/btrfsutil/print_addrspace.go2
-rw-r--r--lib/btrfsutil/rebuilt_forrest.go10
-rw-r--r--lib/btrfsutil/rebuilt_readitem.go19
-rw-r--r--lib/btrfsutil/rebuilt_tree.go15
8 files changed, 78 insertions, 82 deletions
diff --git a/lib/btrfscheck/graph.go b/lib/btrfscheck/graph.go
index 710030c..c35baf8 100644
--- a/lib/btrfscheck/graph.go
+++ b/lib/btrfscheck/graph.go
@@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: GPL-2.0-or-later
-package rebuildnodes
+package btrfscheck
import (
"context"
@@ -15,17 +15,17 @@ import (
)
type rebuildCallbacks interface {
- fsErr(ctx context.Context, e error)
- want(ctx context.Context, reason string, treeID btrfsprim.ObjID, objID btrfsprim.ObjID, typ btrfsprim.ItemType)
- wantOff(ctx context.Context, reason string, treeID btrfsprim.ObjID, objID btrfsprim.ObjID, typ btrfsprim.ItemType, off uint64)
- wantDirIndex(ctx context.Context, reason string, treeID btrfsprim.ObjID, objID btrfsprim.ObjID, name []byte)
- wantCSum(ctx context.Context, reason string, inodeTree, inodeItem btrfsprim.ObjID, beg, end btrfsvol.LogicalAddr) // interval is [beg, end)
- wantFileExt(ctx context.Context, reason string, treeID btrfsprim.ObjID, ino btrfsprim.ObjID, size int64)
+ FSErr(ctx context.Context, e error)
+ Want(ctx context.Context, reason string, treeID btrfsprim.ObjID, objID btrfsprim.ObjID, typ btrfsprim.ItemType)
+ WantOff(ctx context.Context, reason string, treeID btrfsprim.ObjID, objID btrfsprim.ObjID, typ btrfsprim.ItemType, off uint64)
+ WantDirIndex(ctx context.Context, reason string, treeID btrfsprim.ObjID, objID btrfsprim.ObjID, name []byte)
+ WantCSum(ctx context.Context, reason string, inodeTree, inodeItem btrfsprim.ObjID, beg, end btrfsvol.LogicalAddr) // interval is [beg, end)
+ WantFileExt(ctx context.Context, reason string, treeID btrfsprim.ObjID, ino btrfsprim.ObjID, size int64)
}
// handleWouldBeNoOp returns whether or not a call to handleItem for a
// given item type would be a no-op.
-func handleWouldBeNoOp(typ btrfsprim.ItemType) bool {
+func HandleWouldBeNoOp(typ btrfsprim.ItemType) bool {
switch typ {
case // btrfsitem.Dev
btrfsprim.DEV_ITEM_KEY,
@@ -45,30 +45,30 @@ func handleWouldBeNoOp(typ btrfsprim.ItemType) bool {
}
}
-func handleItem(o rebuildCallbacks, ctx context.Context, treeID btrfsprim.ObjID, item btrfstree.Item) {
+func HandleItem(o rebuildCallbacks, ctx context.Context, treeID btrfsprim.ObjID, item btrfstree.Item) {
// Notionally, just express the relationships shown in
// https://btrfs.wiki.kernel.org/index.php/File:References.png (from the page
// https://btrfs.wiki.kernel.org/index.php/Data_Structures )
switch body := item.Body.(type) {
case *btrfsitem.BlockGroup:
- o.want(ctx, "Chunk",
+ o.Want(ctx, "Chunk",
btrfsprim.CHUNK_TREE_OBJECTID,
body.ChunkObjectID,
btrfsitem.CHUNK_ITEM_KEY)
- o.wantOff(ctx, "FreeSpaceInfo",
+ o.WantOff(ctx, "FreeSpaceInfo",
btrfsprim.FREE_SPACE_TREE_OBJECTID,
item.Key.ObjectID,
btrfsitem.FREE_SPACE_INFO_KEY,
item.Key.Offset)
case *btrfsitem.Chunk:
- o.want(ctx, "owning Root",
+ o.Want(ctx, "owning Root",
btrfsprim.ROOT_TREE_OBJECTID,
body.Head.Owner,
btrfsitem.ROOT_ITEM_KEY)
case *btrfsitem.Dev:
// nothing
case *btrfsitem.DevExtent:
- o.wantOff(ctx, "Chunk",
+ o.WantOff(ctx, "Chunk",
body.ChunkTree,
body.ChunkObjectID,
btrfsitem.CHUNK_ITEM_KEY,
@@ -77,7 +77,7 @@ func handleItem(o rebuildCallbacks, ctx context.Context, treeID btrfsprim.ObjID,
// nothing
case *btrfsitem.DirEntry:
// containing-directory
- o.wantOff(ctx, "containing dir inode",
+ o.WantOff(ctx, "containing dir inode",
treeID,
item.Key.ObjectID,
btrfsitem.INODE_ITEM_KEY,
@@ -85,12 +85,12 @@ func handleItem(o rebuildCallbacks, ctx context.Context, treeID btrfsprim.ObjID,
// siblings
switch item.Key.ItemType {
case btrfsitem.DIR_ITEM_KEY:
- o.wantDirIndex(ctx, "corresponding DIR_INDEX",
+ o.WantDirIndex(ctx, "corresponding DIR_INDEX",
treeID,
item.Key.ObjectID,
body.Name)
case btrfsitem.DIR_INDEX_KEY:
- o.wantOff(ctx, "corresponding DIR_ITEM",
+ o.WantOff(ctx, "corresponding DIR_ITEM",
treeID,
item.Key.ObjectID,
btrfsitem.DIR_ITEM_KEY,
@@ -107,23 +107,23 @@ func handleItem(o rebuildCallbacks, ctx context.Context, treeID btrfsprim.ObjID,
if body.Location != (btrfsprim.Key{}) {
switch body.Location.ItemType {
case btrfsitem.INODE_ITEM_KEY:
- o.wantOff(ctx, "item being pointed to",
+ o.WantOff(ctx, "item being pointed to",
treeID,
body.Location.ObjectID,
body.Location.ItemType,
body.Location.Offset)
- o.wantOff(ctx, "backref from item being pointed to",
+ o.WantOff(ctx, "backref from item being pointed to",
treeID,
body.Location.ObjectID,
btrfsitem.INODE_REF_KEY,
uint64(item.Key.ObjectID))
case btrfsitem.ROOT_ITEM_KEY:
- o.want(ctx, "Root of subvolume being pointed to",
+ o.Want(ctx, "Root of subvolume being pointed to",
btrfsprim.ROOT_TREE_OBJECTID,
body.Location.ObjectID,
body.Location.ItemType)
default:
- o.fsErr(ctx, fmt.Errorf("DirEntry: unexpected .Location.ItemType=%v", body.Location.ItemType))
+ o.FSErr(ctx, fmt.Errorf("DirEntry: unexpected .Location.ItemType=%v", body.Location.ItemType))
}
}
case *btrfsitem.Empty:
@@ -141,12 +141,12 @@ func handleItem(o rebuildCallbacks, ctx context.Context, treeID btrfsprim.ObjID,
case nil:
// nothing
case *btrfsitem.ExtentDataRef:
- o.wantOff(ctx, "referencing Inode",
+ o.WantOff(ctx, "referencing Inode",
refBody.Root,
refBody.ObjectID,
btrfsitem.INODE_ITEM_KEY,
0)
- o.wantOff(ctx, "referencing FileExtent",
+ o.WantOff(ctx, "referencing FileExtent",
refBody.Root,
refBody.ObjectID,
btrfsitem.EXTENT_DATA_KEY,
@@ -162,22 +162,22 @@ func handleItem(o rebuildCallbacks, ctx context.Context, treeID btrfsprim.ObjID,
case *btrfsitem.ExtentCSum:
// nothing
case *btrfsitem.ExtentDataRef:
- o.want(ctx, "Extent being referenced",
+ o.Want(ctx, "Extent being referenced",
btrfsprim.EXTENT_TREE_OBJECTID,
item.Key.ObjectID,
btrfsitem.EXTENT_ITEM_KEY)
- o.wantOff(ctx, "referencing Inode",
+ o.WantOff(ctx, "referencing Inode",
body.Root,
body.ObjectID,
btrfsitem.INODE_ITEM_KEY,
0)
- o.wantOff(ctx, "referencing FileExtent",
+ o.WantOff(ctx, "referencing FileExtent",
body.Root,
body.ObjectID,
btrfsitem.EXTENT_DATA_KEY,
uint64(body.Offset))
case *btrfsitem.FileExtent:
- o.wantOff(ctx, "containing Inode",
+ o.WantOff(ctx, "containing Inode",
treeID,
item.Key.ObjectID,
btrfsitem.INODE_ITEM_KEY,
@@ -187,64 +187,64 @@ func handleItem(o rebuildCallbacks, ctx context.Context, treeID btrfsprim.ObjID,
// nothing
case btrfsitem.FILE_EXTENT_REG, btrfsitem.FILE_EXTENT_PREALLOC:
// NB: o.wantCSum checks inodeBody.Flags.Has(btrfsitem.INODE_NODATASUM) for us.
- o.wantCSum(ctx, "data sum",
+ o.WantCSum(ctx, "data sum",
treeID, item.Key.ObjectID,
body.BodyExtent.DiskByteNr,
body.BodyExtent.DiskByteNr.Add(body.BodyExtent.DiskNumBytes))
default:
- o.fsErr(ctx, fmt.Errorf("FileExtent: unexpected body.Type=%v", body.Type))
+ o.FSErr(ctx, fmt.Errorf("FileExtent: unexpected body.Type=%v", body.Type))
}
case *btrfsitem.FreeSpaceBitmap:
- o.wantOff(ctx, "FreeSpaceInfo",
+ o.WantOff(ctx, "FreeSpaceInfo",
treeID,
item.Key.ObjectID,
btrfsitem.FREE_SPACE_INFO_KEY,
item.Key.Offset)
case *btrfsitem.FreeSpaceHeader:
- o.wantOff(ctx, ".Location",
+ o.WantOff(ctx, ".Location",
treeID,
body.Location.ObjectID,
body.Location.ItemType,
body.Location.Offset)
case *btrfsitem.FreeSpaceInfo:
if body.Flags.Has(btrfsitem.FREE_SPACE_USING_BITMAPS) {
- o.wantOff(ctx, "FreeSpaceBitmap",
+ o.WantOff(ctx, "FreeSpaceBitmap",
treeID,
item.Key.ObjectID,
btrfsitem.FREE_SPACE_BITMAP_KEY,
item.Key.Offset)
}
case *btrfsitem.Inode:
- o.want(ctx, "backrefs",
+ o.Want(ctx, "backrefs",
treeID, // TODO: validate the number of these against body.NLink
item.Key.ObjectID,
btrfsitem.INODE_REF_KEY)
- o.wantFileExt(ctx, "FileExtents",
+ o.WantFileExt(ctx, "FileExtents",
treeID, item.Key.ObjectID, body.Size)
if body.BlockGroup != 0 {
- o.want(ctx, "BlockGroup",
+ o.Want(ctx, "BlockGroup",
btrfsprim.EXTENT_TREE_OBJECTID,
body.BlockGroup,
btrfsitem.BLOCK_GROUP_ITEM_KEY)
}
case *btrfsitem.InodeRefs:
- o.wantOff(ctx, "child Inode",
+ o.WantOff(ctx, "child Inode",
treeID,
item.Key.ObjectID,
btrfsitem.INODE_ITEM_KEY,
0)
- o.wantOff(ctx, "parent Inode",
+ o.WantOff(ctx, "parent Inode",
treeID,
btrfsprim.ObjID(item.Key.Offset),
btrfsitem.INODE_ITEM_KEY,
0)
for _, ref := range body.Refs {
- o.wantOff(ctx, "DIR_ITEM",
+ o.WantOff(ctx, "DIR_ITEM",
treeID,
btrfsprim.ObjID(item.Key.Offset),
btrfsitem.DIR_ITEM_KEY,
btrfsitem.NameHash(ref.Name))
- o.wantOff(ctx, "DIR_INDEX",
+ o.WantOff(ctx, "DIR_INDEX",
treeID,
btrfsprim.ObjID(item.Key.Offset),
btrfsitem.DIR_INDEX_KEY,
@@ -256,12 +256,12 @@ func handleItem(o rebuildCallbacks, ctx context.Context, treeID btrfsprim.ObjID,
case nil:
// nothing
case *btrfsitem.ExtentDataRef:
- o.wantOff(ctx, "referencing INode",
+ o.WantOff(ctx, "referencing INode",
refBody.Root,
refBody.ObjectID,
btrfsitem.INODE_ITEM_KEY,
0)
- o.wantOff(ctx, "referencing FileExtent",
+ o.WantOff(ctx, "referencing FileExtent",
refBody.Root,
refBody.ObjectID,
btrfsitem.EXTENT_DATA_KEY,
@@ -276,7 +276,7 @@ func handleItem(o rebuildCallbacks, ctx context.Context, treeID btrfsprim.ObjID,
}
case *btrfsitem.Root:
if body.RootDirID != 0 {
- o.wantOff(ctx, "root directory",
+ o.WantOff(ctx, "root directory",
item.Key.ObjectID,
body.RootDirID,
btrfsitem.INODE_ITEM_KEY,
@@ -284,7 +284,7 @@ func handleItem(o rebuildCallbacks, ctx context.Context, treeID btrfsprim.ObjID,
}
if body.UUID != (btrfsprim.UUID{}) {
key := btrfsitem.UUIDToKey(body.UUID)
- o.wantOff(ctx, "uuid",
+ o.WantOff(ctx, "uuid",
btrfsprim.UUID_TREE_OBJECTID,
key.ObjectID,
key.ItemType,
@@ -292,7 +292,7 @@ func handleItem(o rebuildCallbacks, ctx context.Context, treeID btrfsprim.ObjID,
}
if body.ParentUUID != (btrfsprim.UUID{}) {
key := btrfsitem.UUIDToKey(body.ParentUUID)
- o.wantOff(ctx, "parent uuid",
+ o.WantOff(ctx, "parent uuid",
btrfsprim.UUID_TREE_OBJECTID,
key.ObjectID,
key.ItemType,
@@ -317,48 +317,48 @@ func handleItem(o rebuildCallbacks, ctx context.Context, treeID btrfsprim.ObjID,
panic(fmt.Errorf("should not happen: RootRef: unexpected ItemType=%v", item.Key.ItemType))
}
// sibling
- o.wantOff(ctx, fmt.Sprintf("corresponding %v", otherType),
+ o.WantOff(ctx, fmt.Sprintf("corresponding %v", otherType),
treeID,
btrfsprim.ObjID(item.Key.Offset),
otherType,
uint64(item.Key.ObjectID))
// parent
- o.want(ctx, "parent subvolume: Root",
+ o.Want(ctx, "parent subvolume: Root",
treeID,
parent,
btrfsitem.ROOT_ITEM_KEY)
- o.wantOff(ctx, "parent subvolume: Inode of parent dir",
+ o.WantOff(ctx, "parent subvolume: Inode of parent dir",
parent,
body.DirID,
btrfsitem.INODE_ITEM_KEY,
0)
- o.wantOff(ctx, "parent subvolume: DIR_ITEM in parent dir",
+ o.WantOff(ctx, "parent subvolume: DIR_ITEM in parent dir",
parent,
body.DirID,
btrfsitem.DIR_ITEM_KEY,
btrfsitem.NameHash(body.Name))
- o.wantOff(ctx, "parent subvolume: DIR_INDEX in parent dir",
+ o.WantOff(ctx, "parent subvolume: DIR_INDEX in parent dir",
parent,
body.DirID,
btrfsitem.DIR_INDEX_KEY,
uint64(body.Sequence))
// child
- o.want(ctx, "child subvolume: Root",
+ o.Want(ctx, "child subvolume: Root",
treeID,
child,
btrfsitem.ROOT_ITEM_KEY)
case *btrfsitem.SharedDataRef:
- o.want(ctx, "Extent",
+ o.Want(ctx, "Extent",
btrfsprim.EXTENT_TREE_OBJECTID,
item.Key.ObjectID,
btrfsitem.EXTENT_ITEM_KEY)
case *btrfsitem.UUIDMap:
- o.want(ctx, "subvolume Root",
+ o.Want(ctx, "subvolume Root",
btrfsprim.ROOT_TREE_OBJECTID,
body.ObjID,
btrfsitem.ROOT_ITEM_KEY)
case *btrfsitem.Error:
- o.fsErr(ctx, fmt.Errorf("error decoding item: %w", body.Err))
+ o.FSErr(ctx, fmt.Errorf("error decoding item: %w", body.Err))
default:
// This is a panic because the item decoder should not emit new types without this
// code also being updated.
diff --git a/lib/btrfsutil/graph.go b/lib/btrfsutil/graph.go
index 2a97ec8..f294a28 100644
--- a/lib/btrfsutil/graph.go
+++ b/lib/btrfsutil/graph.go
@@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: GPL-2.0-or-later
-package graph
+package btrfsutil
import (
"context"
@@ -120,7 +120,7 @@ func (g Graph) insertTreeRoot(sb btrfstree.Superblock, treeID btrfsprim.ObjID) {
})
}
-func New(sb btrfstree.Superblock) *Graph {
+func NewGraph(sb btrfstree.Superblock) *Graph {
g := &Graph{
Nodes: make(map[btrfsvol.LogicalAddr]Node),
BadNodes: make(map[btrfsvol.LogicalAddr]error),
diff --git a/lib/btrfsutil/graph_loops.go b/lib/btrfsutil/graph_loops.go
index 0e51805..9563d19 100644
--- a/lib/btrfsutil/graph_loops.go
+++ b/lib/btrfsutil/graph_loops.go
@@ -1,8 +1,8 @@
-// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com>
+// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later
-package graph
+package btrfsutil
import (
"fmt"
diff --git a/lib/btrfsutil/nestedlock.go b/lib/btrfsutil/nestedlock.go
index c1ffa18..917b4cd 100644
--- a/lib/btrfsutil/nestedlock.go
+++ b/lib/btrfsutil/nestedlock.go
@@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: GPL-2.0-or-later
-package btrees
+package btrfsutil
import (
"context"
diff --git a/lib/btrfsutil/print_addrspace.go b/lib/btrfsutil/print_addrspace.go
index e85e055..c9c51f0 100644
--- a/lib/btrfsutil/print_addrspace.go
+++ b/lib/btrfsutil/print_addrspace.go
@@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: GPL-2.0-or-later
-package btrfsinspect
+package btrfsutil
import (
"io"
diff --git a/lib/btrfsutil/rebuilt_forrest.go b/lib/btrfsutil/rebuilt_forrest.go
index dbbc6eb..8d4b810 100644
--- a/lib/btrfsutil/rebuilt_forrest.go
+++ b/lib/btrfsutil/rebuilt_forrest.go
@@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: GPL-2.0-or-later
-package btrees
+package btrfsutil
import (
"context"
@@ -13,8 +13,6 @@ 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"
- pkggraph "git.lukeshu.com/btrfs-progs-ng/lib/btrfsprogs/btrfsinspect/rebuildnodes/graph"
- "git.lukeshu.com/btrfs-progs-ng/lib/btrfsprogs/btrfsinspect/rebuildnodes/keyio"
"git.lukeshu.com/btrfs-progs-ng/lib/containers"
"git.lukeshu.com/btrfs-progs-ng/lib/slices"
"git.lukeshu.com/btrfs-progs-ng/lib/textui"
@@ -60,8 +58,8 @@ type Callbacks interface {
type RebuiltForrest struct {
// static
sb btrfstree.Superblock
- graph pkggraph.Graph
- keyIO *keyio.Handle
+ graph Graph
+ keyIO *KeyIO
cb Callbacks
// mutable
@@ -74,7 +72,7 @@ type RebuiltForrest struct {
// NewRebuiltForrest returns a new RebuiltForrest instance. All of
// the callbacks must be non-nil.
-func NewRebuiltForrest(sb btrfstree.Superblock, graph pkggraph.Graph, keyIO *keyio.Handle, cb Callbacks) *RebuiltForrest {
+func NewRebuiltForrest(sb btrfstree.Superblock, graph Graph, keyIO *KeyIO, cb Callbacks) *RebuiltForrest {
return &RebuiltForrest{
sb: sb,
graph: graph,
diff --git a/lib/btrfsutil/rebuilt_readitem.go b/lib/btrfsutil/rebuilt_readitem.go
index 56da32d..aa432bb 100644
--- a/lib/btrfsutil/rebuilt_readitem.go
+++ b/lib/btrfsutil/rebuilt_readitem.go
@@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: GPL-2.0-or-later
-package keyio
+package btrfsutil
import (
"context"
@@ -15,7 +15,6 @@ 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/btrfsprogs/btrfsinspect/rebuildnodes/graph"
"git.lukeshu.com/btrfs-progs-ng/lib/containers"
"git.lukeshu.com/btrfs-progs-ng/lib/diskio"
"git.lukeshu.com/btrfs-progs-ng/lib/textui"
@@ -40,10 +39,10 @@ type FlagsAndErr struct {
Err error
}
-type Handle struct {
+type KeyIO struct {
rawFile diskio.File[btrfsvol.LogicalAddr]
sb btrfstree.Superblock
- graph graph.Graph
+ graph Graph
Flags map[ItemPtr]FlagsAndErr // INODE_ITEM
Names map[ItemPtr][]byte // DIR_INDEX
@@ -53,8 +52,8 @@ type Handle struct {
cache containers.ARCache[btrfsvol.LogicalAddr, *diskio.Ref[btrfsvol.LogicalAddr, btrfstree.Node]]
}
-func NewHandle(file diskio.File[btrfsvol.LogicalAddr], sb btrfstree.Superblock) *Handle {
- return &Handle{
+func NewKeyIO(file diskio.File[btrfsvol.LogicalAddr], sb btrfstree.Superblock) *KeyIO {
+ return &KeyIO{
rawFile: file,
sb: sb,
@@ -71,7 +70,7 @@ func NewHandle(file diskio.File[btrfsvol.LogicalAddr], sb btrfstree.Superblock)
}
}
-func (o *Handle) InsertNode(nodeRef *diskio.Ref[btrfsvol.LogicalAddr, btrfstree.Node]) {
+func (o *KeyIO) InsertNode(nodeRef *diskio.Ref[btrfsvol.LogicalAddr, btrfstree.Node]) {
for i, item := range nodeRef.Data.BodyLeaf {
ptr := ItemPtr{
Node: nodeRef.Addr,
@@ -115,11 +114,11 @@ func (o *Handle) InsertNode(nodeRef *diskio.Ref[btrfsvol.LogicalAddr, btrfstree.
}
}
-func (o *Handle) SetGraph(graph graph.Graph) {
+func (o *KeyIO) SetGraph(graph Graph) {
o.graph = graph
}
-func (o *Handle) readNode(ctx context.Context, laddr btrfsvol.LogicalAddr) *diskio.Ref[btrfsvol.LogicalAddr, btrfstree.Node] {
+func (o *KeyIO) readNode(ctx context.Context, laddr btrfsvol.LogicalAddr) *diskio.Ref[btrfsvol.LogicalAddr, btrfstree.Node] {
if cached, ok := o.cache.Load(laddr); ok {
dlog.Tracef(ctx, "cache-hit node@%v", laddr)
return cached
@@ -154,7 +153,7 @@ func (o *Handle) readNode(ctx context.Context, laddr btrfsvol.LogicalAddr) *disk
return ref
}
-func (o *Handle) ReadItem(ctx context.Context, ptr ItemPtr) btrfsitem.Item {
+func (o *KeyIO) ReadItem(ctx context.Context, ptr ItemPtr) btrfsitem.Item {
o.mu.Lock()
defer o.mu.Unlock()
if o.graph.Nodes[ptr.Node].Level != 0 {
diff --git a/lib/btrfsutil/rebuilt_tree.go b/lib/btrfsutil/rebuilt_tree.go
index 39d8871..e61b45b 100644
--- a/lib/btrfsutil/rebuilt_tree.go
+++ b/lib/btrfsutil/rebuilt_tree.go
@@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: GPL-2.0-or-later
-package btrees
+package btrfsutil
import (
"context"
@@ -15,7 +15,6 @@ import (
"git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsitem"
"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/btrfsprogs/btrfsinspect/rebuildnodes/keyio"
"git.lukeshu.com/btrfs-progs-ng/lib/containers"
"git.lukeshu.com/btrfs-progs-ng/lib/maps"
"git.lukeshu.com/btrfs-progs-ng/lib/slices"
@@ -136,7 +135,7 @@ func (tree *RebuiltTree) isOwnerOK(owner btrfsprim.ObjID, gen btrfsprim.Generati
//
// Do not mutate the returned map; it is a pointer to the
// RebuiltTree's internal map!
-func (tree *RebuiltTree) Items(ctx context.Context) *containers.SortedMap[btrfsprim.Key, keyio.ItemPtr] {
+func (tree *RebuiltTree) Items(ctx context.Context) *containers.SortedMap[btrfsprim.Key, ItemPtr] {
ctx = dlog.WithField(ctx, "btrfsinspect.rebuild-nodes.rebuild.index-inc-items", fmt.Sprintf("tree=%v", tree.ID))
return tree.items(ctx, &tree.forrest.incItems, tree.Roots.HasAny)
}
@@ -146,7 +145,7 @@ func (tree *RebuiltTree) Items(ctx context.Context) *containers.SortedMap[btrfsp
//
// Do not mutate the returned map; it is a pointer to the
// RebuiltTree's internal map!
-func (tree *RebuiltTree) PotentialItems(ctx context.Context) *containers.SortedMap[btrfsprim.Key, keyio.ItemPtr] {
+func (tree *RebuiltTree) PotentialItems(ctx context.Context) *containers.SortedMap[btrfsprim.Key, ItemPtr] {
ctx = dlog.WithField(ctx, "btrfsinspect.rebuild-nodes.rebuild.index-exc-items", fmt.Sprintf("tree=%v", tree.ID))
return tree.items(ctx, &tree.forrest.excItems,
func(roots containers.Set[btrfsvol.LogicalAddr]) bool {
@@ -154,7 +153,7 @@ func (tree *RebuiltTree) PotentialItems(ctx context.Context) *containers.SortedM
})
}
-type itemIndex = containers.SortedMap[btrfsprim.Key, keyio.ItemPtr]
+type itemIndex = containers.SortedMap[btrfsprim.Key, ItemPtr]
type itemStats struct {
Leafs textui.Portion[int]
@@ -169,7 +168,7 @@ func (s itemStats) String() string {
func (tree *RebuiltTree) items(ctx context.Context, cache containers.Map[btrfsprim.ObjID, *itemIndex],
leafFn func(roots containers.Set[btrfsvol.LogicalAddr]) bool,
-) *containers.SortedMap[btrfsprim.Key, keyio.ItemPtr] {
+) *containers.SortedMap[btrfsprim.Key, ItemPtr] {
tree.mu.RLock()
defer tree.mu.RUnlock()
@@ -186,12 +185,12 @@ func (tree *RebuiltTree) items(ctx context.Context, cache containers.Map[btrfspr
stats.Leafs.D = len(leafs)
progressWriter := textui.NewProgress[itemStats](ctx, dlog.LogLevelInfo, textui.Tunable(1*time.Second))
- index := new(containers.SortedMap[btrfsprim.Key, keyio.ItemPtr])
+ index := new(containers.SortedMap[btrfsprim.Key, ItemPtr])
for i, leaf := range leafs {
stats.Leafs.N = i
progressWriter.Set(stats)
for j, itemKey := range tree.forrest.graph.Nodes[leaf].Items {
- newPtr := keyio.ItemPtr{
+ newPtr := ItemPtr{
Node: leaf,
Idx: j,
}