diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-05-04 18:04:29 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-05-04 18:04:29 +0000 |
commit | 23c3b58f2d7ade5f9aa1e8c545223941ded690e4 (patch) | |
tree | f1a0dfdd7f921920e7e80ced792fd1b7a532752f /pkg/sentry/vfs/context.go | |
parent | 95cb42d3ad61bc1827f6be769ea66981414d5527 (diff) | |
parent | cbc5bef2a66ece1f9e63b213d4dfa616db488df8 (diff) |
Merge release-20200422.0-16-gcbc5bef (automated)
Diffstat (limited to 'pkg/sentry/vfs/context.go')
-rwxr-xr-x | pkg/sentry/vfs/context.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/pkg/sentry/vfs/context.go b/pkg/sentry/vfs/context.go index 82781e6d3..c9e724fef 100755 --- a/pkg/sentry/vfs/context.go +++ b/pkg/sentry/vfs/context.go @@ -49,3 +49,27 @@ func RootFromContext(ctx context.Context) VirtualDentry { } return VirtualDentry{} } + +type rootContext struct { + context.Context + root VirtualDentry +} + +// WithRoot returns a copy of ctx with the given root. +func WithRoot(ctx context.Context, root VirtualDentry) context.Context { + return &rootContext{ + Context: ctx, + root: root, + } +} + +// Value implements Context.Value. +func (rc rootContext) Value(key interface{}) interface{} { + switch key { + case CtxRoot: + rc.root.IncRef() + return rc.root + default: + return rc.Context.Value(key) + } +} |