Skip to content

Commit

Permalink
Merge pull request #536 from jiangliu/cachemgr
Browse files Browse the repository at this point in the history
cache: fix null pointer access when cachemanager.Disable is true
  • Loading branch information
changweige authored Sep 25, 2023
2 parents 14bcfed + 02a5c14 commit 2cc7d81
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion misc/snapshotter/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ threads_number = 4
# Log rotation size for nydusd, in unit MB(megabytes)
log_rotation_size = 100


[cgroup]
# Whether to use separate cgroup for nydusd.
enable = true
Expand Down Expand Up @@ -89,7 +88,9 @@ enable_kata_volume = false
sync_remove = false

[cache_manager]
# Disable or enable recyclebin
disable = false
# How long to keep deleted files in recyclebin
gc_period = "24h"
# Directory to host cached files
cache_dir = ""
Expand Down
1 change: 1 addition & 0 deletions pkg/cache/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Manager struct {
}

type Opt struct {
Disabled bool
CacheDir string
Period time.Duration
Database *store.Database
Expand Down
19 changes: 9 additions & 10 deletions snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,16 @@ func NewSnapshotter(ctx context.Context, cfg *config.SnapshotterConfig) (snapsho
}

cacheConfig := &cfg.CacheManagerConfig
if !cacheConfig.Disable {
cacheMgr, err := cache.NewManager(cache.Opt{
Database: db,
Period: config.GetCacheGCPeriod(),
CacheDir: cacheConfig.CacheDir,
})
if err != nil {
return nil, errors.Wrap(err, "create cache manager")
}
opts = append(opts, filesystem.WithCacheManager(cacheMgr))
cacheMgr, err := cache.NewManager(cache.Opt{
Database: db,
Period: config.GetCacheGCPeriod(),
CacheDir: cacheConfig.CacheDir,
Disabled: cacheConfig.Disable,
})
if err != nil {
return nil, errors.Wrap(err, "create cache manager")
}
opts = append(opts, filesystem.WithCacheManager(cacheMgr))

if cfg.Experimental.EnableReferrerDetect {
referrerMgr := referrer.NewManager(skipSSLVerify)
Expand Down

0 comments on commit 2cc7d81

Please sign in to comment.