Documentation ¶
Overview ¶
Package btrfsutil implements userspace utilities for working with btrfs filesystems.
Index ¶
- func ListNodes(ctx context.Context, fs *btrfs.FS) ([]btrfsvol.LogicalAddr, error)
- func Open(ctx context.Context, flag int, filenames ...string) (*btrfs.FS, error)
- func ScanDevices[Stats comparable, Result any](ctx context.Context, fs *btrfs.FS, ...) (map[btrfsvol.DeviceID]Result, error)
- func ScanOneDevice[Stats comparable, Result any](ctx context.Context, dev *btrfs.Device, ...) (Result, error)
- func WalkAllTrees(ctx context.Context, fs btrfs.ReadableFS, cbs WalkAllTreesHandler)
- type DeviceScanner
- type DeviceScannerFactory
- type Graph
- type GraphEdge
- type GraphNode
- type ItemPtr
- type KeyAndSize
- type RebuiltForrest
- func (ts *RebuiltForrest) AcquireNode(ctx context.Context, addr btrfsvol.LogicalAddr, exp btrfstree.NodeExpectations) (*btrfstree.Node, error)
- func (ts *RebuiltForrest) ForrestLookup(ctx context.Context, treeID btrfsprim.ObjID) (btrfstree.Tree, error)
- func (ts *RebuiltForrest) Name() string
- func (ts *RebuiltForrest) ReadAt(p []byte, off btrfsvol.LogicalAddr) (int, error)
- func (ts *RebuiltForrest) RebuiltAddRoots(ctx context.Context, ...)
- func (ts *RebuiltForrest) RebuiltListRoots(ctx context.Context) map[btrfsprim.ObjID]containers.Set[btrfsvol.LogicalAddr]
- func (ts *RebuiltForrest) RebuiltTree(ctx context.Context, treeID btrfsprim.ObjID) (*RebuiltTree, error)
- func (ts *RebuiltForrest) ReleaseNode(node *btrfstree.Node)
- func (ts *RebuiltForrest) Superblock() (*btrfstree.Superblock, error)
- type RebuiltForrestCallbacks
- type RebuiltForrestExtendedCallbacks
- type RebuiltTree
- func (tree *RebuiltTree) RebuiltAcquireItems(ctx context.Context) *containers.SortedMap[btrfsprim.Key, ItemPtr]
- func (tree *RebuiltTree) RebuiltAcquirePotentialItems(ctx context.Context) *containers.SortedMap[btrfsprim.Key, ItemPtr]
- func (tree *RebuiltTree) RebuiltAddRoot(ctx context.Context, rootNode btrfsvol.LogicalAddr)
- func (tree *RebuiltTree) RebuiltCOWDistance(parentID btrfsprim.ObjID) (dist int, ok bool)
- func (tree *RebuiltTree) RebuiltLeafToRoots(ctx context.Context, leaf btrfsvol.LogicalAddr) containers.Set[btrfsvol.LogicalAddr]
- func (tree *RebuiltTree) RebuiltReleaseItems()
- func (tree *RebuiltTree) RebuiltReleasePotentialItems()
- func (tree *RebuiltTree) RebuiltShouldReplace(oldNode, newNode btrfsvol.LogicalAddr) bool
- func (tree *RebuiltTree) TreeLookup(ctx context.Context, key btrfsprim.Key) (btrfstree.Item, error)
- func (tree *RebuiltTree) TreeParentID(_ context.Context) (btrfsprim.ObjID, btrfsprim.Generation, error)
- func (tree *RebuiltTree) TreeRange(ctx context.Context, handleFn func(btrfstree.Item) bool) error
- func (tree *RebuiltTree) TreeSearch(ctx context.Context, searcher btrfstree.TreeSearcher) (btrfstree.Item, error)
- func (tree *RebuiltTree) TreeSubrange(ctx context.Context, min int, searcher btrfstree.TreeSearcher, ...) error
- func (tree *RebuiltTree) TreeWalk(ctx context.Context, cbs btrfstree.TreeWalkHandler)
- type WalkAllTreesHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ScanDevices ¶
func ScanDevices[Stats comparable, Result any](ctx context.Context, fs *btrfs.FS, newScanner DeviceScannerFactory[Stats, Result]) (map[btrfsvol.DeviceID]Result, error)
func ScanOneDevice ¶
func ScanOneDevice[Stats comparable, Result any](ctx context.Context, dev *btrfs.Device, newScanner DeviceScannerFactory[Stats, Result]) (Result, error)
func WalkAllTrees ¶
func WalkAllTrees(ctx context.Context, fs btrfs.ReadableFS, cbs WalkAllTreesHandler)
WalkAllTrees walks all trees in a btrfs.ReadableFS. Rather than returning an error, it calls the appropriate "BadXXX" callback (BadTree, BadNode, BadItem) each time an error is encountered.
Types ¶
type DeviceScanner ¶
type DeviceScannerFactory ¶
type DeviceScannerFactory[Stats comparable, Result any] func(ctx context.Context, sb btrfstree.Superblock, numBytes btrfsvol.PhysicalAddr, numSectors int) DeviceScanner[Stats, Result]
type Graph ¶
type Graph struct { Nodes map[btrfsvol.LogicalAddr]GraphNode BadNodes map[btrfsvol.LogicalAddr]error EdgesFrom map[btrfsvol.LogicalAddr][]*GraphEdge EdgesTo map[btrfsvol.LogicalAddr][]*GraphEdge }
func ReadGraph ¶
func (Graph) FinalCheck ¶
type GraphEdge ¶
type GraphEdge struct { // It is invalid for both 'FromRoot' and 'FromNode' to be // non-zero. If both are zero, then the GraphEdge is from the // superblock. FromRoot btrfsvol.LogicalAddr FromNode btrfsvol.LogicalAddr FromSlot int // only valid if one of FromRoot or FromNode is non-zero FromTree btrfsprim.ObjID ToNode btrfsvol.LogicalAddr ToLevel uint8 ToKey btrfsprim.Key ToGeneration btrfsprim.Generation }
type GraphNode ¶
type GraphNode struct { Addr btrfsvol.LogicalAddr Level uint8 Generation btrfsprim.Generation Owner btrfsprim.ObjID Items []KeyAndSize }
type ItemPtr ¶
type ItemPtr struct { Node btrfsvol.LogicalAddr Slot int }
type RebuiltForrest ¶
type RebuiltForrest struct {
// contains filtered or unexported fields
}
RebuiltForrest is an abstraction for rebuilding and accessing potentially broken btrees.
Additionally, it provides some functionality on top of a vanilla btrfs.ReadableFS:
it provides a RebuiltTree.RebuiltAddRoot() method for repairing a tree.
it provides a RebuiltForrest.RebuiltListRoots() method for listing how trees have been repaired.
it provides a RebuiltForrest.RebuiltAddRoots() method for batch-loading the results from RebuiltForrest.RebuiltListroots().
it provides several RebuiltTree methods that provide advice on what roots should be added to a tree in order to repair it:
.RebuiltAcquireItems()/.RebuiltReleaseItems() and .RebuiltAcquirePotentialItems()/.RebuiltReleasePotentialItems() to compare what's in the tree and what could be in the tree.
.RebuiltLeafToRoots() to map potential items to things that can be passed to .RebuiltAddRoot().
.RebuiltCOWDistance() and .RebuiltShouldReplace() to provide information on deciding on an option from .RebuiltLeafToRoots().
A zero RebuiltForrest is invalid; it must be initialized with NewRebuiltForrest().
func NewRebuiltForrest ¶
func NewRebuiltForrest(fs btrfs.ReadableFS, graph Graph, cb RebuiltForrestCallbacks, laxAncestors bool) *RebuiltForrest
NewRebuiltForrest returns a new RebuiltForrest instance.
The `cb` RebuiltForrestCallbacks may be nil. If `cb` also implements RebuiltForrestExtendedCallbacks, then a series of .AddedItem() calls will be made before each call to .AddedRoot().
`laxAncestors` is whether or not an error instantiating an ancestor tree should prevent instantiating an descendant tree (lax=false prevents it, lax=true allows it).
`laxAncestors` inhibits calls to RebuiltForrestExtendedCallbacks.AddedItem().
`laxAncestors` causes a call to RebuiltTree.RebuiltAddRoot on the ROOT_TREE or the UUID_TREE to panic if a tree other than the ROOT_TREE or the UUID_TREE has been read from.
func (*RebuiltForrest) AcquireNode ¶
func (ts *RebuiltForrest) AcquireNode(ctx context.Context, addr btrfsvol.LogicalAddr, exp btrfstree.NodeExpectations) (*btrfstree.Node, error)
AcquireNode implements btrfstree.NodeSource (and btrfs.ReadableFS).
func (*RebuiltForrest) ForrestLookup ¶
func (ts *RebuiltForrest) ForrestLookup(ctx context.Context, treeID btrfsprim.ObjID) (btrfstree.Tree, error)
ForrestLookup implements btrfstree.Forrest (and btrfs.ReadableFS).
It is identical to .RebuiltTree(), but returns an interface rather than a concrete type.
func (*RebuiltForrest) Name ¶
func (ts *RebuiltForrest) Name() string
Name implements btrfs.ReadableFS.
func (*RebuiltForrest) ReadAt ¶
func (ts *RebuiltForrest) ReadAt(p []byte, off btrfsvol.LogicalAddr) (int, error)
ReadAt implements diskio.ReaderAt[btrfsvol.LogicalAddr] (and btrfs.ReadableFS).
func (*RebuiltForrest) RebuiltAddRoots ¶
func (ts *RebuiltForrest) RebuiltAddRoots(ctx context.Context, roots map[btrfsprim.ObjID]containers.Set[btrfsvol.LogicalAddr])
RebuiltAddRoots takes a listing of the root nodes for trees (as returned by RebuiltListRoots), and augments the trees to include them.
func (*RebuiltForrest) RebuiltListRoots ¶
func (ts *RebuiltForrest) RebuiltListRoots(ctx context.Context) map[btrfsprim.ObjID]containers.Set[btrfsvol.LogicalAddr]
RebuiltListRoots returns a listing of all initialized trees and their root nodes.
Do not mutate the set of roots for a tree; it is a pointer to the RebuiltForrest's internal set!
func (*RebuiltForrest) RebuiltTree ¶
func (ts *RebuiltForrest) RebuiltTree(ctx context.Context, treeID btrfsprim.ObjID) (*RebuiltTree, error)
RebuiltTree returns a given tree, initializing it if nescessary.
The tree is initialized with the normal root node of the tree.
This is identical to .ForrestLookup(), but returns a concrete type rather than an interface.
func (*RebuiltForrest) ReleaseNode ¶
func (ts *RebuiltForrest) ReleaseNode(node *btrfstree.Node)
ReleaseNode implements btrfstree.NodeSource (and btrfs.ReadableFS).
func (*RebuiltForrest) Superblock ¶
func (ts *RebuiltForrest) Superblock() (*btrfstree.Superblock, error)
Superblock implements btrfstree.NodeSource (and btrfs.ReadableFS).
type RebuiltForrestCallbacks ¶
type RebuiltForrestCallbacks interface { AddedRoot(ctx context.Context, tree btrfsprim.ObjID, root btrfsvol.LogicalAddr) LookupRoot(ctx context.Context, tree btrfsprim.ObjID) (offset btrfsprim.Generation, item btrfsitem.Root, err error) LookupUUID(ctx context.Context, uuid btrfsprim.UUID) (id btrfsprim.ObjID, err error) }
type RebuiltForrestExtendedCallbacks ¶
type RebuiltTree ¶
type RebuiltTree struct { ID btrfsprim.ObjID UUID btrfsprim.UUID Root btrfsvol.LogicalAddr Parent *RebuiltTree ParentGen btrfsprim.Generation // offset of this tree's root item Roots containers.Set[btrfsvol.LogicalAddr] // contains filtered or unexported fields }
func (*RebuiltTree) RebuiltAcquireItems ¶
func (tree *RebuiltTree) RebuiltAcquireItems(ctx context.Context) *containers.SortedMap[btrfsprim.Key, ItemPtr]
RebuiltAcquireItems returns a map of the items contained in this tree.
Do not mutate the returned map; it is a pointer to the RebuiltTree's internal map!
When done with the map, call .RebuiltReleaseItems().
func (*RebuiltTree) RebuiltAcquirePotentialItems ¶
func (tree *RebuiltTree) RebuiltAcquirePotentialItems(ctx context.Context) *containers.SortedMap[btrfsprim.Key, ItemPtr]
RebuiltAcquirePotentialItems returns a map of items that could be added to this tree with .RebuiltAddRoot().
Do not mutate the returned map; it is a pointer to the RebuiltTree's internal map!
When done with the map, call .RebuiltReleasePotentialItems().
func (*RebuiltTree) RebuiltAddRoot ¶
func (tree *RebuiltTree) RebuiltAddRoot(ctx context.Context, rootNode btrfsvol.LogicalAddr)
RebuiltAddRoot adds an additional root node to the tree. It is useful to call .RebuiltAddRoot() to re-attach part of the tree that has been broken off.
If the RebuiltForrest has laxAncestors=false, then:
calls to RebuiltForrestExtendedCallbacks.AddedItem() are inhibited.
calling RebuiltAddRoot on the ROOT_TREE or the UUID_TREE will panic if a tree other than the ROOT_TREE or UUID_TREE has been read from.
func (*RebuiltTree) RebuiltCOWDistance ¶
func (tree *RebuiltTree) RebuiltCOWDistance(parentID btrfsprim.ObjID) (dist int, ok bool)
RebuiltCOWDistance returns how many COW-snapshots down the 'tree' is from the 'parent'.
func (*RebuiltTree) RebuiltLeafToRoots ¶
func (tree *RebuiltTree) RebuiltLeafToRoots(ctx context.Context, leaf btrfsvol.LogicalAddr) containers.Set[btrfsvol.LogicalAddr]
RebuiltLeafToRoots returns the list of potential roots (to pass to .RebuiltAddRoot) that include a given leaf-node.
func (*RebuiltTree) RebuiltReleaseItems ¶
func (tree *RebuiltTree) RebuiltReleaseItems()
RebuiltReleaseItems releases resources after a call to .RebuiltAcquireItems().
func (*RebuiltTree) RebuiltReleasePotentialItems ¶
func (tree *RebuiltTree) RebuiltReleasePotentialItems()
RebuiltReleasePotentialItems releases resources after a call to .RebuiltAcquirePotentialItems().
func (*RebuiltTree) RebuiltShouldReplace ¶
func (tree *RebuiltTree) RebuiltShouldReplace(oldNode, newNode btrfsvol.LogicalAddr) bool
func (*RebuiltTree) TreeLookup ¶
TreeLookup implements btrfstree.Tree.
func (*RebuiltTree) TreeParentID ¶
func (tree *RebuiltTree) TreeParentID(_ context.Context) (btrfsprim.ObjID, btrfsprim.Generation, error)
TreeParentID implements btrfstree.Tree.
func (*RebuiltTree) TreeRange ¶
TreeRange implements btrfstree.Tree. It is a thin wrapper around tree.RebuiltItems(ctx).Range (to do the iteration) and tree.TreeLookup (to read item bodies).
func (*RebuiltTree) TreeSearch ¶
func (tree *RebuiltTree) TreeSearch(ctx context.Context, searcher btrfstree.TreeSearcher) (btrfstree.Item, error)
TreeSearch implements btrfstree.Tree. It is a thin wrapper around tree.RebuiltItems(ctx).Search (to do the search) and tree.TreeLookup (to read item bodies).
func (*RebuiltTree) TreeSubrange ¶
func (tree *RebuiltTree) TreeSubrange(ctx context.Context, min int, searcher btrfstree.TreeSearcher, handleFn func(btrfstree.Item) bool, ) error
TreeSubrange implements btrfstree.Tree. It is a thin wrapper around tree.RebuiltItems(ctx).Subrange (to do the iteration) and tree.TreeLookup (to read item bodies).
func (*RebuiltTree) TreeWalk ¶
func (tree *RebuiltTree) TreeWalk(ctx context.Context, cbs btrfstree.TreeWalkHandler)
TreeWalk implements btrfstree.Tree.