diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-28 08:05:47 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-28 08:05:47 -0700 |
commit | 996137cdfdff9ec6fbb5c93e21d75b21052e01ae (patch) | |
tree | a6dba9250b1a8d0fd4eadc3806a217833a9133ac /lib/btrfsprogs/btrfsinspect/rebuildnodes/keyio | |
parent | a7a3b5b08557abf7edc6aa4649e85069c3a450b4 (diff) |
rebuildnodes: Fix a data race
Calling FreeNodeRef while an item from that node is still in use is a BAD
TIME.
Diffstat (limited to 'lib/btrfsprogs/btrfsinspect/rebuildnodes/keyio')
-rw-r--r-- | lib/btrfsprogs/btrfsinspect/rebuildnodes/keyio/keyio.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/keyio/keyio.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/keyio/keyio.go index 9e3b144..04df2b6 100644 --- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/keyio/keyio.go +++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/keyio/keyio.go @@ -7,6 +7,7 @@ package keyio import ( "context" "fmt" + "sync" "github.com/datawire/dlib/dlog" @@ -48,6 +49,7 @@ type Handle struct { Names map[ItemPtr][]byte // DIR_INDEX Sizes map[ItemPtr]SizeAndErr // EXTENT_CSUM and EXTENT_DATA + mu sync.Mutex cache containers.ARCache[btrfsvol.LogicalAddr, *diskio.Ref[btrfsvol.LogicalAddr, btrfstree.Node]] } @@ -153,6 +155,8 @@ func (o *Handle) readNode(ctx context.Context, laddr btrfsvol.LogicalAddr) *disk } func (o *Handle) ReadItem(ctx context.Context, ptr ItemPtr) btrfsitem.Item { + o.mu.Lock() + defer o.mu.Unlock() if o.graph.Nodes[ptr.Node].Level != 0 { panic(fmt.Errorf("should not happen: keyio.Handle.ReadItem called for non-leaf node@%v", ptr.Node)) } @@ -164,5 +168,5 @@ func (o *Handle) ReadItem(ctx context.Context, ptr ItemPtr) btrfsitem.Item { panic(fmt.Errorf("should not happen: keyio.Handle.ReadItem called for out-of-bounds item index: index=%v len=%v", ptr.Idx, len(items))) } - return items[ptr.Idx].Body + return items[ptr.Idx].Body.CloneItem() } |