From 3c1a1b70c92fa9cd5b0b1bacb17cd5ec6f26ec9d Mon Sep 17 00:00:00 2001 From: Antti Kervinen Date: Wed, 16 Oct 2024 18:14:33 +0300 Subject: [PATCH] sysfs: enable adding caches in unpredictable orders 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 --- pkg/sysfs/system.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/sysfs/system.go b/pkg/sysfs/system.go index 14e8638ed..53d280954 100644 --- a/pkg/sysfs/system.go +++ b/pkg/sysfs/system.go @@ -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) + } + } } }