mirror of
https://github.com/hanzoai/visor.git
synced 2026-09-24 17:04:14 +00:00
Add WithValues to context package and use it in restore.go
Create WithValues in pkg/context/context.go to replace multiple values using a map. Update runsc/boot/restore.go to use WithValues instead of multiple WithValue calls. PiperOrigin-RevId: 914896863
This commit is contained in:
committed by
gVisor bot
parent
d7d7d6cd39
commit
331d6af443
@@ -254,3 +254,28 @@ func (ctx *withValue) Value(key any) any {
|
||||
}
|
||||
return ctx.Context.Value(key)
|
||||
}
|
||||
|
||||
// WithValues returns a copy of parent in which the values associated with keys
|
||||
// are the corresponding values in the map.
|
||||
func WithValues(parent Context, values map[any]any) Context {
|
||||
if len(values) == 0 {
|
||||
return parent
|
||||
}
|
||||
return &withValues{
|
||||
Context: parent,
|
||||
values: values,
|
||||
}
|
||||
}
|
||||
|
||||
type withValues struct {
|
||||
Context
|
||||
values map[any]any
|
||||
}
|
||||
|
||||
// Value implements Context.Value.
|
||||
func (ctx *withValues) Value(key any) any {
|
||||
if val, ok := ctx.values[key]; ok {
|
||||
return val
|
||||
}
|
||||
return ctx.Context.Value(key)
|
||||
}
|
||||
|
||||
@@ -260,10 +260,12 @@ func (r *restorer) restore(l *Loader) error {
|
||||
|
||||
log.Debugf("Restore using fdmap: %#v", fdmap)
|
||||
ctx := l.k.SupervisorContext()
|
||||
ctx = context.WithValue(ctx, vfs.CtxRestoreFilesystemFDMap, fdmap)
|
||||
log.Debugf("Restore using mfmap: %v", mfmap)
|
||||
ctx = context.WithValue(ctx, pgalloc.CtxMemoryFileMap, mfmap)
|
||||
ctx = context.WithValue(ctx, devutil.CtxDevGoferClientProvider, l.k)
|
||||
ctx = context.WithValues(ctx, map[any]any{
|
||||
vfs.CtxRestoreFilesystemFDMap: fdmap,
|
||||
pgalloc.CtxMemoryFileMap: mfmap,
|
||||
devutil.CtxDevGoferClientProvider: l.k,
|
||||
})
|
||||
|
||||
if r.asyncMFLoader != nil {
|
||||
// Now that private memory files are known, kick off their loading in the
|
||||
|
||||
Reference in New Issue
Block a user