Skip to content

Commit

Permalink
sysfs: enable adding caches in unpredictable orders
Browse files Browse the repository at this point in the history
If the first saved cache was from level 3, saving level 1 after that
crashed on a nil map. This change makes sure that there are no nil
maps in sys.caches in the saved or levels below that.

Signed-off-by: Antti Kervinen <[email protected]>
  • Loading branch information
askervin committed Oct 16, 2024
1 parent 82025f6 commit 3c1a1b7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/sysfs/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -1678,8 +1678,12 @@ func (sys *system) saveCache(c *Cache) *Cache {
caches := sys.caches
sys.caches = make([][NumCacheTypes]map[idset.ID]*Cache, c.level)
copy(sys.caches, caches)
for ct := 0; ct < NumCacheTypes; ct++ {
sys.caches[c.level-1][ct] = make(map[idset.ID]*Cache)
for levelIdx := 0; levelIdx < c.level; levelIdx++ {
for ct := 0; ct < NumCacheTypes; ct++ {
if sys.caches[levelIdx][ct] == nil {
sys.caches[levelIdx][ct] = make(map[idset.ID]*Cache)
}
}
}
}

Expand Down

0 comments on commit 3c1a1b7

Please sign in to comment.