Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion image/pkg/blobinfocache/internal/prioritize/prioritize.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func destructivelyPrioritizeReplacementCandidatesWithMax(cs []CandidateWithTime,
remainingCapacity := totalLimit - knownLocationCandidatesUsed
unknownLocationCandidatesUsed := min(noLocationLimit, remainingCapacity, len(unknownLocationCandidates))
res := make([]blobinfocache.BICReplacementCandidate2, knownLocationCandidatesUsed)
for i := 0; i < knownLocationCandidatesUsed; i++ {
for i := range knownLocationCandidatesUsed {
res[i] = knownLocationCandidates[i].candidate
}
// If candidates with unknown location are found, lets add them to final list
Expand Down
20 changes: 10 additions & 10 deletions storage/pkg/chunked/storage_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1965,19 +1965,19 @@ func (c *chunkedDiffer) mergeTocEntries(fileType compressedFileType, entries []m
}
// stargz/estargz doesn't store EndOffset so let's calculate it here
lastOffset := c.tocOffset
for i := len(mergedEntries) - 1; i >= 0; i-- {
if mergedEntries[i].EndOffset == 0 {
mergedEntries[i].EndOffset = lastOffset
for _, entry := range slices.Backward(mergedEntries) {
if entry.EndOffset == 0 {
entry.EndOffset = lastOffset
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think this works, entry is a copy by value.

}
if mergedEntries[i].Offset != 0 {
lastOffset = mergedEntries[i].Offset
if entry.Offset != 0 {
lastOffset = entry.Offset
}

lastChunkOffset := mergedEntries[i].EndOffset
for j := len(mergedEntries[i].chunks) - 1; j >= 0; j-- {
mergedEntries[i].chunks[j].EndOffset = lastChunkOffset
mergedEntries[i].chunks[j].Size = mergedEntries[i].chunks[j].EndOffset - mergedEntries[i].chunks[j].Offset
lastChunkOffset = mergedEntries[i].chunks[j].Offset
lastChunkOffset := entry.EndOffset
for _, v := range slices.Backward(entry.chunks) {
v.EndOffset = lastChunkOffset
v.Size = v.EndOffset - v.Offset
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

lastChunkOffset = v.Offset
}
}
return mergedEntries, nil
Expand Down
8 changes: 4 additions & 4 deletions storage/pkg/locker/locker.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ type lockCtr struct {
mu sync.Mutex
// waiters is the number of waiters waiting to acquire the lock
// this is int32 instead of uint32 so we can add `-1` in `dec()`
waiters int32
waiters atomic.Int32
}

// inc increments the number of waiters waiting for the lock
func (l *lockCtr) inc() {
atomic.AddInt32(&l.waiters, 1)
l.waiters.Add(1)
}

// dec decrements the number of waiters waiting on the lock
func (l *lockCtr) dec() {
atomic.AddInt32(&l.waiters, -1)
l.waiters.Add(-1)
}

// count gets the current number of waiters
func (l *lockCtr) count() int32 {
return atomic.LoadInt32(&l.waiters)
return l.waiters.Load()
}

// Lock locks the mutex
Expand Down
8 changes: 4 additions & 4 deletions storage/pkg/locker/locker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ func TestLockCounter(t *testing.T) {
l := &lockCtr{}
l.inc()

if l.waiters != 1 {
if l.count() != 1 {
t.Fatal("counter inc failed")
}

l.dec()
if l.waiters != 0 {
if l.count() != 0 {
t.Fatal("counter dec failed")
}
}
Expand All @@ -27,8 +27,8 @@ func TestLockerLock(t *testing.T) {
l.Lock("test")
ctr := l.locks["test"]

if ctr.count() != 0 {
t.Fatalf("expected waiters to be 0, got :%d", ctr.waiters)
if c := ctr.count(); c != 0 {
t.Fatalf("expected waiters to be 0, got %d", c)
}

chDone := make(chan struct{})
Expand Down
4 changes: 2 additions & 2 deletions storage/pkg/lockfile/lastwrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type LastWrite struct {
state []byte // Contents of the lock file.
}

var lastWriterIDCounter uint64 // Private state for newLastWriterID
var lastWriterIDCounter atomic.Uint64 // Private state for newLastWriterID

const lastWriterIDSize = 64 // This must be the same as len(stringid.GenerateRandomID)
// newLastWrite returns a new "last write" ID.
Expand All @@ -37,7 +37,7 @@ func newLastWrite() LastWrite {
// efficiently if the size of the value changes.
pid := os.Getpid()
tm := time.Now().UnixNano()
counter := atomic.AddUint64(&lastWriterIDCounter, 1)
counter := lastWriterIDCounter.Add(1)

res := make([]byte, lastWriterIDSize)
binary.LittleEndian.PutUint64(res[0:8], uint64(tm))
Expand Down
4 changes: 2 additions & 2 deletions storage/pkg/mount/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mount

import (
"fmt"
"slices"
"strings"
)

Expand Down Expand Up @@ -78,8 +79,7 @@ func MergeTmpfsOptions(options []string) ([]string, error) {

var newOptions []string
// We process in reverse order
for i := len(options) - 1; i >= 0; i-- {
option := options[i]
for _, option := range slices.Backward(options) {
if option == "defaults" {
continue
}
Expand Down
Loading