@@ -18,6 +18,8 @@ import (
1818 "fmt"
1919
2020 "gvisor.dev/gvisor/pkg/atomicbitops"
21+ "gvisor.dev/gvisor/pkg/context"
22+ "gvisor.dev/gvisor/pkg/sentry/fsimpl/nsfs"
2123 "gvisor.dev/gvisor/pkg/sentry/kernel/auth"
2224 "gvisor.dev/gvisor/pkg/sync"
2325 "gvisor.dev/gvisor/pkg/waiter"
@@ -207,6 +209,8 @@ type PIDNamespace struct {
207209
208210 // pidNamespaceData contains additional per-PID-namespace data.
209211 extra pidNamespaceData
212+
213+ inode * nsfs.Inode
210214}
211215
212216func newPIDNamespace (ts * TaskSet , parent * PIDNamespace , userns * auth.UserNamespace ) * PIDNamespace {
@@ -226,6 +230,11 @@ func newPIDNamespace(ts *TaskSet, parent *PIDNamespace, userns *auth.UserNamespa
226230 }
227231}
228232
233+ // InitInode creates and sets a new nsfs.Inode.
234+ func (ns * PIDNamespace ) InitInode (ctx context.Context , k * Kernel ) {
235+ ns .inode = nsfs .NewInode (ctx , k .nsfsMount , ns )
236+ }
237+
229238// lastPIDNSID is the last value of PIDNamespace.ID assigned to a PID
230239// namespace.
231240//
@@ -239,10 +248,35 @@ func NewRootPIDNamespace(userns *auth.UserNamespace) *PIDNamespace {
239248 return newPIDNamespace (nil , nil , userns )
240249}
241250
251+ // GetInode returns the nsfs inode associated with the namespace.
252+ func (ns * PIDNamespace ) GetInode () * nsfs.Inode {
253+ return ns .inode
254+ }
255+
256+ // IncRef increments the Namespace's refcount.
257+ func (ns * PIDNamespace ) IncRef () {
258+ ns .inode .IncRef ()
259+ }
260+
261+ // DecRef decrements the namespace's refcount.
262+ func (ns * PIDNamespace ) DecRef (ctx context.Context ) {
263+ ns .inode .DecRef (ctx )
264+ }
265+
266+ // Destroy implements nsfs.Namespace.Destroy.
267+ func (ns * PIDNamespace ) Destroy (ctx context.Context ) {}
268+
269+ // Type implements nsfs.Namespace.Type.
270+ func (ns * PIDNamespace ) Type () string {
271+ return "pid"
272+ }
273+
242274// NewChild returns a new, empty PID namespace that is a child of ns. Authority
243275// over the new PID namespace is controlled by userns.
244- func (ns * PIDNamespace ) NewChild (userns * auth.UserNamespace ) * PIDNamespace {
245- return newPIDNamespace (ns .owner , ns , userns )
276+ func (ns * PIDNamespace ) NewChild (ctx context.Context , k * Kernel , userns * auth.UserNamespace ) * PIDNamespace {
277+ pidns := newPIDNamespace (ns .owner , ns , userns )
278+ pidns .InitInode (ctx , k )
279+ return pidns
246280}
247281
248282// TaskWithID returns the task with thread ID tid in PID namespace ns. If no
@@ -538,6 +572,12 @@ func (t *Task) PIDNamespace() *PIDNamespace {
538572 return t .tg .pidns
539573}
540574
575+ // GetPIDNamespace returns the PID namespace containing t.
576+ func (t * Task ) GetPIDNamespace () * PIDNamespace {
577+ t .tg .pidns .IncRef ()
578+ return t .tg .pidns
579+ }
580+
541581// TaskSet returns the TaskSet containing t.
542582func (t * Task ) TaskSet () * TaskSet {
543583 return t .tg .pidns .owner
0 commit comments