diff options
author | gVisor bot <gvisor-bot@google.com> | 2019-12-12 21:23:50 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-12-12 21:23:50 +0000 |
commit | f0b295134c90ff33886f9afa8022c677ba2025b1 (patch) | |
tree | f88c9606f5e0d4a7a51165b259087ba9f50ffd78 /pkg/sentry/vfs/context.go | |
parent | c166476f2ec3b8bae5590c74e61865eb6aa5a408 (diff) | |
parent | 93d429d5b1e3801fb4c29568bcd40d6854c9fe94 (diff) |
Merge release-20191210.0-27-g93d429d (automated)
Diffstat (limited to 'pkg/sentry/vfs/context.go')
-rwxr-xr-x | pkg/sentry/vfs/context.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/pkg/sentry/vfs/context.go b/pkg/sentry/vfs/context.go index 32cf9151b..705194ebc 100755 --- a/pkg/sentry/vfs/context.go +++ b/pkg/sentry/vfs/context.go @@ -24,6 +24,9 @@ type contextID int const ( // CtxMountNamespace is a Context.Value key for a MountNamespace. CtxMountNamespace contextID = iota + + // CtxRoot is a Context.Value key for a VFS root. + CtxRoot ) // MountNamespaceFromContext returns the MountNamespace used by ctx. It does @@ -35,3 +38,13 @@ func MountNamespaceFromContext(ctx context.Context) *MountNamespace { } return nil } + +// RootFromContext returns the VFS root used by ctx. It takes a reference on +// the returned VirtualDentry. If ctx does not have a specific VFS root, +// RootFromContext returns a zero-value VirtualDentry. +func RootFromContext(ctx context.Context) VirtualDentry { + if v := ctx.Value(CtxRoot); v != nil { + return v.(VirtualDentry) + } + return VirtualDentry{} +} |