From 1b7de33b1cc24f329efe63130858a5cd562d5378 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 1 Mar 2023 00:09:13 -0700 Subject: rebuildtrees: Be careful about what types are exported --- cmd/btrfs-rec/inspect/rebuildtrees/rebuild.go | 22 ++++++++++---------- .../inspect/rebuildtrees/rebuild_treecb.go | 6 +++--- .../inspect/rebuildtrees/rebuild_wantcb.go | 24 +++++++++++----------- .../inspect/rebuildtrees/rebuild_wanttyp.go | 22 ++++++++++---------- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/cmd/btrfs-rec/inspect/rebuildtrees/rebuild.go b/cmd/btrfs-rec/inspect/rebuildtrees/rebuild.go index b1bbdb5..4937ee3 100644 --- a/cmd/btrfs-rec/inspect/rebuildtrees/rebuild.go +++ b/cmd/btrfs-rec/inspect/rebuildtrees/rebuild.go @@ -66,9 +66,9 @@ type rebuilder struct { } type treeAugmentQueue struct { - zero map[Want]struct{} - single map[Want]btrfsvol.LogicalAddr - multi map[Want]containers.Set[btrfsvol.LogicalAddr] + zero map[want]struct{} + single map[want]btrfsvol.LogicalAddr + multi map[want]containers.Set[btrfsvol.LogicalAddr] } type Rebuilder interface { @@ -208,7 +208,7 @@ func (o *rebuilder) processAddedItemQueue(ctx context.Context) error { } excPtr, ok := tree.PotentialItems(ctx).Load(key.Key) if ok && tree.ShouldReplace(incPtr.Node, excPtr.Node) { - wantKey := WantWithTree{ + wantKey := wantWithTree{ TreeID: key.TreeID, Key: wantFromKey(key.Key), } @@ -520,7 +520,7 @@ func (o *rebuilder) resolveTreeAugments(ctx context.Context, treeID btrfsprim.Ob //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -func (queue *treeAugmentQueue) has(wantKey Want) bool { +func (queue *treeAugmentQueue) has(wantKey want) bool { if queue != nil { if queue.zero != nil { if _, ok := queue.zero[wantKey]; ok { @@ -541,7 +541,7 @@ func (queue *treeAugmentQueue) has(wantKey Want) bool { return false } -func (queue *treeAugmentQueue) store(wantKey Want, choices containers.Set[btrfsvol.LogicalAddr]) { +func (queue *treeAugmentQueue) store(wantKey want, choices containers.Set[btrfsvol.LogicalAddr]) { if len(choices) == 0 && wantKey.OffsetType > offsetExact { // This wantKey is unlikely to come up again, so it's // not worth the RAM of storing a negative result. @@ -550,27 +550,27 @@ func (queue *treeAugmentQueue) store(wantKey Want, choices containers.Set[btrfsv switch len(choices) { case 0: if queue.zero == nil { - queue.zero = make(map[Want]struct{}) + queue.zero = make(map[want]struct{}) } queue.zero[wantKey] = struct{}{} case 1: if queue.single == nil { - queue.single = make(map[Want]btrfsvol.LogicalAddr) + queue.single = make(map[want]btrfsvol.LogicalAddr) } queue.single[wantKey] = choices.TakeOne() default: if queue.multi == nil { - queue.multi = make(map[Want]containers.Set[btrfsvol.LogicalAddr]) + queue.multi = make(map[want]containers.Set[btrfsvol.LogicalAddr]) } queue.multi[wantKey] = choices } } -func (o *rebuilder) hasAugment(wantKey WantWithTree) bool { +func (o *rebuilder) hasAugment(wantKey wantWithTree) bool { return o.augmentQueue[wantKey.TreeID].has(wantKey.Key) } -func (o *rebuilder) wantAugment(ctx context.Context, wantKey WantWithTree, choices containers.Set[btrfsvol.LogicalAddr]) { +func (o *rebuilder) wantAugment(ctx context.Context, wantKey wantWithTree, choices containers.Set[btrfsvol.LogicalAddr]) { if o.augmentQueue[wantKey.TreeID] == nil { o.augmentQueue[wantKey.TreeID] = new(treeAugmentQueue) } diff --git a/cmd/btrfs-rec/inspect/rebuildtrees/rebuild_treecb.go b/cmd/btrfs-rec/inspect/rebuildtrees/rebuild_treecb.go index c632e10..765ee76 100644 --- a/cmd/btrfs-rec/inspect/rebuildtrees/rebuild_treecb.go +++ b/cmd/btrfs-rec/inspect/rebuildtrees/rebuild_treecb.go @@ -34,9 +34,9 @@ func (o forrestCallbacks) AddedRoot(_ context.Context, tree btrfsprim.ObjID, _ b // LookupRoot implements btrfsutil.RebuiltForrestCallbacks. func (o forrestCallbacks) LookupRoot(ctx context.Context, tree btrfsprim.ObjID) (offset btrfsprim.Generation, item btrfsitem.Root, ok bool) { - wantKey := WantWithTree{ + wantKey := wantWithTree{ TreeID: btrfsprim.ROOT_TREE_OBJECTID, - Key: Want{ + Key: want{ ObjectID: tree, ItemType: btrfsitem.ROOT_ITEM_KEY, OffsetType: offsetAny, @@ -65,7 +65,7 @@ func (o forrestCallbacks) LookupRoot(ctx context.Context, tree btrfsprim.ObjID) // LookupUUID implements btrfsutil.RebuiltForrestCallbacks. func (o forrestCallbacks) LookupUUID(ctx context.Context, uuid btrfsprim.UUID) (id btrfsprim.ObjID, ok bool) { - wantKey := WantWithTree{ + wantKey := wantWithTree{ TreeID: btrfsprim.UUID_TREE_OBJECTID, Key: wantFromKey(btrfsitem.UUIDToKey(uuid)), } diff --git a/cmd/btrfs-rec/inspect/rebuildtrees/rebuild_wantcb.go b/cmd/btrfs-rec/inspect/rebuildtrees/rebuild_wantcb.go index 10fdcff..8bfdd06 100644 --- a/cmd/btrfs-rec/inspect/rebuildtrees/rebuild_wantcb.go +++ b/cmd/btrfs-rec/inspect/rebuildtrees/rebuild_wantcb.go @@ -30,9 +30,9 @@ func (graphCallbacks) FSErr(ctx context.Context, e error) { // Want implements btrfscheck.GraphCallbacks. func (o graphCallbacks) Want(ctx context.Context, reason string, treeID btrfsprim.ObjID, objID btrfsprim.ObjID, typ btrfsprim.ItemType) { - wantKey := WantWithTree{ + wantKey := wantWithTree{ TreeID: treeID, - Key: Want{ + Key: want{ ObjectID: objID, ItemType: typ, OffsetType: offsetAny, @@ -42,7 +42,7 @@ func (o graphCallbacks) Want(ctx context.Context, reason string, treeID btrfspri o._want(ctx, wantKey) } -func (o *rebuilder) _want(ctx context.Context, wantKey WantWithTree) (key btrfsprim.Key, ok bool) { +func (o *rebuilder) _want(ctx context.Context, wantKey wantWithTree) (key btrfsprim.Key, ok bool) { if o.rebuilt.Tree(ctx, wantKey.TreeID) == nil { o.enqueueRetry(wantKey.TreeID) return btrfsprim.Key{}, false @@ -79,9 +79,9 @@ func (o *rebuilder) _want(ctx context.Context, wantKey WantWithTree) (key btrfsp // WantOff implements btrfscheck.GraphCallbacks. func (o graphCallbacks) WantOff(ctx context.Context, reason string, treeID btrfsprim.ObjID, objID btrfsprim.ObjID, typ btrfsprim.ItemType, off uint64) { - wantKey := WantWithTree{ + wantKey := wantWithTree{ TreeID: treeID, - Key: Want{ + Key: want{ ObjectID: objID, ItemType: typ, OffsetType: offsetExact, @@ -92,7 +92,7 @@ func (o graphCallbacks) WantOff(ctx context.Context, reason string, treeID btrfs o._wantOff(ctx, wantKey) } -func (o *rebuilder) _wantOff(ctx context.Context, wantKey WantWithTree) (ok bool) { +func (o *rebuilder) _wantOff(ctx context.Context, wantKey wantWithTree) (ok bool) { if o.rebuilt.Tree(ctx, wantKey.TreeID) == nil { o.enqueueRetry(wantKey.TreeID) return false @@ -123,9 +123,9 @@ func (o *rebuilder) _wantOff(ctx context.Context, wantKey WantWithTree) (ok bool // WantDirIndex implements btrfscheck.GraphCallbacks. func (o graphCallbacks) WantDirIndex(ctx context.Context, reason string, treeID btrfsprim.ObjID, objID btrfsprim.ObjID, name []byte) { - wantKey := WantWithTree{ + wantKey := wantWithTree{ TreeID: treeID, - Key: Want{ + Key: want{ ObjectID: objID, ItemType: btrfsitem.DIR_INDEX_KEY, OffsetType: offsetName, @@ -248,9 +248,9 @@ func (o graphCallbacks) _wantRange( treeID btrfsprim.ObjID, objID btrfsprim.ObjID, typ btrfsprim.ItemType, beg, end uint64, ) { - wantKey := WantWithTree{ + wantKey := wantWithTree{ TreeID: treeID, - Key: Want{ + Key: want{ ObjectID: objID, ItemType: typ, OffsetType: offsetAny, @@ -358,9 +358,9 @@ func (o graphCallbacks) _wantRange( // // interval is [beg, end) func (o graphCallbacks) WantCSum(ctx context.Context, reason string, inodeTree, inode btrfsprim.ObjID, beg, end btrfsvol.LogicalAddr) { - inodeWant := WantWithTree{ + inodeWant := wantWithTree{ TreeID: inodeTree, - Key: Want{ + Key: want{ ObjectID: inode, ItemType: btrfsitem.INODE_ITEM_KEY, OffsetType: offsetExact, diff --git a/cmd/btrfs-rec/inspect/rebuildtrees/rebuild_wanttyp.go b/cmd/btrfs-rec/inspect/rebuildtrees/rebuild_wanttyp.go index 8fe8a49..6c9d72b 100644 --- a/cmd/btrfs-rec/inspect/rebuildtrees/rebuild_wanttyp.go +++ b/cmd/btrfs-rec/inspect/rebuildtrees/rebuild_wanttyp.go @@ -23,8 +23,8 @@ const ( offsetName ) -type Want struct { - // TODO(lukeshu): Delete the 'Want' type in favor of +type want struct { + // TODO(lukeshu): Delete the 'want' type in favor of // btrfstree.Search. ObjectID btrfsprim.ObjID ItemType btrfsprim.ItemType @@ -34,7 +34,7 @@ type Want struct { OffsetName string } -func (a Want) Compare(b Want) int { +func (a want) Compare(b want) int { if d := containers.NativeCompare(a.ObjectID, b.ObjectID); d != 0 { return d } @@ -56,7 +56,7 @@ func (a Want) Compare(b Want) int { return 0 } -func (o Want) Key() btrfsprim.Key { +func (o want) Key() btrfsprim.Key { return btrfsprim.Key{ ObjectID: o.ObjectID, ItemType: o.ItemType, @@ -64,8 +64,8 @@ func (o Want) Key() btrfsprim.Key { } } -func wantFromKey(k btrfsprim.Key) Want { - return Want{ +func wantFromKey(k btrfsprim.Key) want { + return want{ ObjectID: k.ObjectID, ItemType: k.ItemType, OffsetType: offsetExact, @@ -73,7 +73,7 @@ func wantFromKey(k btrfsprim.Key) Want { } } -func (o Want) String() string { +func (o want) String() string { switch o.OffsetType { case offsetAny: return fmt.Sprintf("{%v %v ?}", o.ObjectID, o.ItemType) @@ -88,12 +88,12 @@ func (o Want) String() string { } } -type WantWithTree struct { +type wantWithTree struct { TreeID btrfsprim.ObjID - Key Want + Key want } -func (o WantWithTree) String() string { +func (o wantWithTree) String() string { return fmt.Sprintf("tree=%v key=%v", o.TreeID, o.Key) } @@ -102,7 +102,7 @@ const ( logFieldTreeWant = "btrfs.util.rebuilt-forrest.add-tree.want" ) -func withWant(ctx context.Context, logField, reason string, wantKey WantWithTree) context.Context { +func withWant(ctx context.Context, logField, reason string, wantKey wantWithTree) context.Context { ctx = dlog.WithField(ctx, logField+".reason", reason) ctx = dlog.WithField(ctx, logField+".key", wantKey) return ctx -- cgit v1.1-4-g5e80