mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Plumb context through more layers of filesytem.
All functions which allocate objects containing AtomicRefCounts will soon need a context. PiperOrigin-RevId: 253147709
This commit is contained in:
@@ -33,7 +33,7 @@ func NewInode(ctx context.Context) *fs.Inode {
|
||||
User: fs.PermMask{Read: true, Write: true},
|
||||
}, linux.ANON_INODE_FS_MAGIC),
|
||||
}
|
||||
return fs.NewInode(iops, fs.NewPseudoMountSource(), fs.StableAttr{
|
||||
return fs.NewInode(ctx, iops, fs.NewPseudoMountSource(ctx), fs.StableAttr{
|
||||
Type: fs.Anonymous,
|
||||
DeviceID: PseudoDevice.DeviceID(),
|
||||
InodeID: PseudoDevice.NextIno(),
|
||||
|
||||
@@ -116,8 +116,8 @@ func (a *Area) ConfigureMMap(ctx context.Context, file *fs.File, opts *memmap.MM
|
||||
|
||||
if a.tmpfsFile == nil {
|
||||
tmpfsInodeOps := tmpfs.NewInMemoryFile(ctx, usage.Tmpfs, fs.UnstableAttr{})
|
||||
tmpfsInode := fs.NewInode(tmpfsInodeOps, fs.NewPseudoMountSource(), fs.StableAttr{})
|
||||
dirent := fs.NewDirent(tmpfsInode, namePrefix+"/"+a.name)
|
||||
tmpfsInode := fs.NewInode(ctx, tmpfsInodeOps, fs.NewPseudoMountSource(ctx), fs.StableAttr{})
|
||||
dirent := fs.NewDirent(ctx, tmpfsInode, namePrefix+"/"+a.name)
|
||||
tmpfsFile, err := tmpfsInode.GetFile(ctx, dirent, fs.FileFlags{Read: true, Write: true})
|
||||
// Drop the extra reference on the Dirent.
|
||||
dirent.DecRef()
|
||||
|
||||
@@ -102,7 +102,7 @@ func makeOverlayTestFiles(t *testing.T) []*overlayTestFile {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to mount tmpfs: %v", err)
|
||||
}
|
||||
lowerRoot := fs.NewDirent(lower, "")
|
||||
lowerRoot := fs.NewDirent(ctx, lower, "")
|
||||
|
||||
// Make a deep set of subdirectories that everyone shares.
|
||||
next := lowerRoot
|
||||
|
||||
+14
-14
@@ -40,8 +40,8 @@ const (
|
||||
urandomDevMinor uint32 = 9
|
||||
)
|
||||
|
||||
func newCharacterDevice(iops fs.InodeOperations, msrc *fs.MountSource) *fs.Inode {
|
||||
return fs.NewInode(iops, msrc, fs.StableAttr{
|
||||
func newCharacterDevice(ctx context.Context, iops fs.InodeOperations, msrc *fs.MountSource) *fs.Inode {
|
||||
return fs.NewInode(ctx, iops, msrc, fs.StableAttr{
|
||||
DeviceID: devDevice.DeviceID(),
|
||||
InodeID: devDevice.NextIno(),
|
||||
BlockSize: usermem.PageSize,
|
||||
@@ -49,8 +49,8 @@ func newCharacterDevice(iops fs.InodeOperations, msrc *fs.MountSource) *fs.Inode
|
||||
})
|
||||
}
|
||||
|
||||
func newMemDevice(iops fs.InodeOperations, msrc *fs.MountSource, minor uint32) *fs.Inode {
|
||||
return fs.NewInode(iops, msrc, fs.StableAttr{
|
||||
func newMemDevice(ctx context.Context, iops fs.InodeOperations, msrc *fs.MountSource, minor uint32) *fs.Inode {
|
||||
return fs.NewInode(ctx, iops, msrc, fs.StableAttr{
|
||||
DeviceID: devDevice.DeviceID(),
|
||||
InodeID: devDevice.NextIno(),
|
||||
BlockSize: usermem.PageSize,
|
||||
@@ -62,7 +62,7 @@ func newMemDevice(iops fs.InodeOperations, msrc *fs.MountSource, minor uint32) *
|
||||
|
||||
func newDirectory(ctx context.Context, msrc *fs.MountSource) *fs.Inode {
|
||||
iops := ramfs.NewDir(ctx, nil, fs.RootOwner, fs.FilePermsFromMode(0555))
|
||||
return fs.NewInode(iops, msrc, fs.StableAttr{
|
||||
return fs.NewInode(ctx, iops, msrc, fs.StableAttr{
|
||||
DeviceID: devDevice.DeviceID(),
|
||||
InodeID: devDevice.NextIno(),
|
||||
BlockSize: usermem.PageSize,
|
||||
@@ -72,7 +72,7 @@ func newDirectory(ctx context.Context, msrc *fs.MountSource) *fs.Inode {
|
||||
|
||||
func newSymlink(ctx context.Context, target string, msrc *fs.MountSource) *fs.Inode {
|
||||
iops := ramfs.NewSymlink(ctx, fs.RootOwner, target)
|
||||
return fs.NewInode(iops, msrc, fs.StableAttr{
|
||||
return fs.NewInode(ctx, iops, msrc, fs.StableAttr{
|
||||
DeviceID: devDevice.DeviceID(),
|
||||
InodeID: devDevice.NextIno(),
|
||||
BlockSize: usermem.PageSize,
|
||||
@@ -88,17 +88,17 @@ func New(ctx context.Context, msrc *fs.MountSource, binderEnabled bool, ashmemEn
|
||||
"stdout": newSymlink(ctx, "/proc/self/fd/1", msrc),
|
||||
"stderr": newSymlink(ctx, "/proc/self/fd/2", msrc),
|
||||
|
||||
"null": newMemDevice(newNullDevice(ctx, fs.RootOwner, 0666), msrc, nullDevMinor),
|
||||
"zero": newMemDevice(newZeroDevice(ctx, fs.RootOwner, 0666), msrc, zeroDevMinor),
|
||||
"full": newMemDevice(newFullDevice(ctx, fs.RootOwner, 0666), msrc, fullDevMinor),
|
||||
"null": newMemDevice(ctx, newNullDevice(ctx, fs.RootOwner, 0666), msrc, nullDevMinor),
|
||||
"zero": newMemDevice(ctx, newZeroDevice(ctx, fs.RootOwner, 0666), msrc, zeroDevMinor),
|
||||
"full": newMemDevice(ctx, newFullDevice(ctx, fs.RootOwner, 0666), msrc, fullDevMinor),
|
||||
|
||||
// This is not as good as /dev/random in linux because go
|
||||
// runtime uses sys_random and /dev/urandom internally.
|
||||
// According to 'man 4 random', this will be sufficient unless
|
||||
// application uses this to generate long-lived GPG/SSL/SSH
|
||||
// keys.
|
||||
"random": newMemDevice(newRandomDevice(ctx, fs.RootOwner, 0444), msrc, randomDevMinor),
|
||||
"urandom": newMemDevice(newRandomDevice(ctx, fs.RootOwner, 0444), msrc, urandomDevMinor),
|
||||
"random": newMemDevice(ctx, newRandomDevice(ctx, fs.RootOwner, 0444), msrc, randomDevMinor),
|
||||
"urandom": newMemDevice(ctx, newRandomDevice(ctx, fs.RootOwner, 0444), msrc, urandomDevMinor),
|
||||
|
||||
"shm": tmpfs.NewDir(ctx, nil, fs.RootOwner, fs.FilePermsFromMode(0777), msrc),
|
||||
|
||||
@@ -120,16 +120,16 @@ func New(ctx context.Context, msrc *fs.MountSource, binderEnabled bool, ashmemEn
|
||||
|
||||
if binderEnabled {
|
||||
binder := binder.NewDevice(ctx, fs.RootOwner, fs.FilePermsFromMode(0666))
|
||||
contents["binder"] = newCharacterDevice(binder, msrc)
|
||||
contents["binder"] = newCharacterDevice(ctx, binder, msrc)
|
||||
}
|
||||
|
||||
if ashmemEnabled {
|
||||
ashmem := ashmem.NewDevice(ctx, fs.RootOwner, fs.FilePermsFromMode(0666))
|
||||
contents["ashmem"] = newCharacterDevice(ashmem, msrc)
|
||||
contents["ashmem"] = newCharacterDevice(ctx, ashmem, msrc)
|
||||
}
|
||||
|
||||
iops := ramfs.NewDir(ctx, contents, fs.RootOwner, fs.FilePermsFromMode(0555))
|
||||
return fs.NewInode(iops, msrc, fs.StableAttr{
|
||||
return fs.NewInode(ctx, iops, msrc, fs.StableAttr{
|
||||
DeviceID: devDevice.DeviceID(),
|
||||
InodeID: devDevice.NextIno(),
|
||||
BlockSize: usermem.PageSize,
|
||||
|
||||
@@ -95,5 +95,5 @@ func (f *filesystem) Mount(ctx context.Context, device string, flags fs.MountSou
|
||||
}
|
||||
|
||||
// Construct the devtmpfs root.
|
||||
return New(ctx, fs.NewNonCachingMountSource(f, flags), binderEnabled, ashmemEnabled), nil
|
||||
return New(ctx, fs.NewNonCachingMountSource(ctx, f, flags), binderEnabled, ashmemEnabled), nil
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ type Dirent struct {
|
||||
|
||||
// NewDirent returns a new root Dirent, taking the caller's reference on inode. The caller
|
||||
// holds the only reference to the Dirent. Parents may call hashChild to parent this Dirent.
|
||||
func NewDirent(inode *Inode, name string) *Dirent {
|
||||
func NewDirent(ctx context.Context, inode *Inode, name string) *Dirent {
|
||||
d := newDirent(inode, name)
|
||||
allDirents.add(d)
|
||||
d.userVisible = true
|
||||
@@ -1068,7 +1068,7 @@ func (d *Dirent) mount(ctx context.Context, inode *Inode) (newChild *Dirent, err
|
||||
//
|
||||
// Note that NewDirent returns with one reference taken; the reference
|
||||
// is donated to the caller as the mount reference.
|
||||
replacement := NewDirent(inode, d.name)
|
||||
replacement := NewDirent(ctx, inode, d.name)
|
||||
replacement.mounted = true
|
||||
|
||||
weakRef, ok := d.parent.hashChild(replacement)
|
||||
|
||||
@@ -31,7 +31,7 @@ func TestWalkPositive(t *testing.T) {
|
||||
// refs == -1 -> has been destroyed.
|
||||
|
||||
ctx := contexttest.Context(t)
|
||||
root := NewDirent(newMockDirInode(ctx, nil), "root")
|
||||
root := NewDirent(ctx, newMockDirInode(ctx, nil), "root")
|
||||
|
||||
if got := root.ReadRefs(); got != 1 {
|
||||
t.Fatalf("root has a ref count of %d, want %d", got, 1)
|
||||
@@ -73,7 +73,7 @@ func TestWalkNegative(t *testing.T) {
|
||||
// refs == -1 -> has been destroyed.
|
||||
|
||||
ctx := contexttest.Context(t)
|
||||
root := NewDirent(NewEmptyDir(ctx, nil), "root")
|
||||
root := NewDirent(ctx, NewEmptyDir(ctx, nil), "root")
|
||||
mn := root.Inode.InodeOperations.(*mockInodeOperationsLookupNegative)
|
||||
|
||||
if got := root.ReadRefs(); got != 1 {
|
||||
@@ -144,7 +144,7 @@ type mockInodeOperationsLookupNegative struct {
|
||||
|
||||
func NewEmptyDir(ctx context.Context, cache *DirentCache) *Inode {
|
||||
m := NewMockMountSource(cache)
|
||||
return NewInode(&mockInodeOperationsLookupNegative{
|
||||
return NewInode(ctx, &mockInodeOperationsLookupNegative{
|
||||
MockInodeOperations: NewMockInodeOperations(ctx),
|
||||
}, m, StableAttr{Type: Directory})
|
||||
}
|
||||
@@ -162,7 +162,7 @@ func TestHashNegativeToPositive(t *testing.T) {
|
||||
// refs == -1 -> has been destroyed.
|
||||
|
||||
ctx := contexttest.Context(t)
|
||||
root := NewDirent(NewEmptyDir(ctx, nil), "root")
|
||||
root := NewDirent(ctx, NewEmptyDir(ctx, nil), "root")
|
||||
|
||||
name := "d"
|
||||
_, err := root.walk(ctx, root, name, false)
|
||||
@@ -215,7 +215,6 @@ func TestRevalidate(t *testing.T) {
|
||||
// refs == 0 -> one reference.
|
||||
// refs == -1 -> has been destroyed.
|
||||
|
||||
ctx := contexttest.Context(t)
|
||||
for _, test := range []struct {
|
||||
// desc is the test's description.
|
||||
desc string
|
||||
@@ -233,7 +232,8 @@ func TestRevalidate(t *testing.T) {
|
||||
},
|
||||
} {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
root := NewDirent(NewMockInodeRevalidate(ctx, test.makeNegative), "root")
|
||||
ctx := contexttest.Context(t)
|
||||
root := NewDirent(ctx, NewMockInodeRevalidate(ctx, test.makeNegative), "root")
|
||||
|
||||
name := "d"
|
||||
d1, err := root.walk(ctx, root, name, false)
|
||||
@@ -263,7 +263,7 @@ func NewMockInodeRevalidate(ctx context.Context, makeNegative bool) *Inode {
|
||||
mn := NewMockInodeOperations(ctx)
|
||||
m := NewMockMountSource(nil)
|
||||
m.MountSourceOperations.(*MockMountSourceOps).revalidate = true
|
||||
return NewInode(&MockInodeOperationsRevalidate{MockInodeOperations: mn, makeNegative: makeNegative}, m, StableAttr{Type: Directory})
|
||||
return NewInode(ctx, &MockInodeOperationsRevalidate{MockInodeOperations: mn, makeNegative: makeNegative}, m, StableAttr{Type: Directory})
|
||||
}
|
||||
|
||||
func (m *MockInodeOperationsRevalidate) Lookup(ctx context.Context, dir *Inode, p string) (*Dirent, error) {
|
||||
@@ -290,12 +290,12 @@ func TestCreateExtraRefs(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
desc: "Create caching",
|
||||
root: NewDirent(NewEmptyDir(ctx, NewDirentCache(1)), "root"),
|
||||
root: NewDirent(ctx, NewEmptyDir(ctx, NewDirentCache(1)), "root"),
|
||||
refs: 2,
|
||||
},
|
||||
{
|
||||
desc: "Create not caching",
|
||||
root: NewDirent(NewEmptyDir(ctx, nil), "root"),
|
||||
root: NewDirent(ctx, NewEmptyDir(ctx, nil), "root"),
|
||||
refs: 1,
|
||||
},
|
||||
} {
|
||||
@@ -328,11 +328,11 @@ func TestRemoveExtraRefs(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
desc: "Remove caching",
|
||||
root: NewDirent(NewEmptyDir(ctx, NewDirentCache(1)), "root"),
|
||||
root: NewDirent(ctx, NewEmptyDir(ctx, NewDirentCache(1)), "root"),
|
||||
},
|
||||
{
|
||||
desc: "Remove not caching",
|
||||
root: NewDirent(NewEmptyDir(ctx, nil), "root"),
|
||||
root: NewDirent(ctx, NewEmptyDir(ctx, nil), "root"),
|
||||
},
|
||||
} {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
@@ -366,7 +366,6 @@ func TestRenameExtraRefs(t *testing.T) {
|
||||
// refs == 0 -> one reference.
|
||||
// refs == -1 -> has been destroyed.
|
||||
|
||||
ctx := contexttest.Context(t)
|
||||
for _, test := range []struct {
|
||||
// desc is the test's description.
|
||||
desc string
|
||||
@@ -384,10 +383,12 @@ func TestRenameExtraRefs(t *testing.T) {
|
||||
},
|
||||
} {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
ctx := contexttest.Context(t)
|
||||
|
||||
dirAttr := StableAttr{Type: Directory}
|
||||
|
||||
oldParent := NewDirent(NewMockInode(ctx, NewMockMountSource(test.cache), dirAttr), "old_parent")
|
||||
newParent := NewDirent(NewMockInode(ctx, NewMockMountSource(test.cache), dirAttr), "new_parent")
|
||||
oldParent := NewDirent(ctx, NewMockInode(ctx, NewMockMountSource(test.cache), dirAttr), "old_parent")
|
||||
newParent := NewDirent(ctx, NewMockInode(ctx, NewMockMountSource(test.cache), dirAttr), "new_parent")
|
||||
|
||||
renamed, err := oldParent.Walk(ctx, oldParent, "old_child")
|
||||
if err != nil {
|
||||
|
||||
@@ -359,7 +359,7 @@ func TestCopiedReadAheadBuffer(t *testing.T) {
|
||||
inode := fs.NewMockInode(ctx, fs.NewMockMountSource(nil), fs.StableAttr{
|
||||
Type: fs.Pipe,
|
||||
})
|
||||
file := fs.NewFile(ctx, fs.NewDirent(inode, "pipe"), fs.FileFlags{Read: true}, pipeOps)
|
||||
file := fs.NewFile(ctx, fs.NewDirent(ctx, inode, "pipe"), fs.FileFlags{Read: true}, pipeOps)
|
||||
|
||||
// Check that the file we opened points to a pipe with a non-empty read ahead buffer.
|
||||
bufsize := len(pipeOps.readAheadBuffer)
|
||||
|
||||
@@ -50,11 +50,11 @@ func mockPipeDirent(t *testing.T) *fs.Dirent {
|
||||
User: fs.PermMask{Read: true, Write: true},
|
||||
},
|
||||
}
|
||||
inode := fs.NewInode(node, fs.NewMockMountSource(nil), fs.StableAttr{
|
||||
inode := fs.NewInode(ctx, node, fs.NewMockMountSource(nil), fs.StableAttr{
|
||||
Type: fs.Pipe,
|
||||
BlockSize: usermem.PageSize,
|
||||
})
|
||||
return fs.NewDirent(inode, "")
|
||||
return fs.NewDirent(ctx, inode, "")
|
||||
}
|
||||
|
||||
func TestNewPipe(t *testing.T) {
|
||||
@@ -285,7 +285,7 @@ func TestPipeRequest(t *testing.T) {
|
||||
defer p.Release()
|
||||
|
||||
inode := fs.NewMockInode(ctx, fs.NewMockMountSource(nil), fs.StableAttr{Type: fs.Pipe})
|
||||
file := fs.NewFile(ctx, fs.NewDirent(inode, "pipe"), fs.FileFlags{Read: true}, p)
|
||||
file := fs.NewFile(ctx, fs.NewDirent(ctx, inode, "pipe"), fs.FileFlags{Read: true}, p)
|
||||
|
||||
// Issue request via the appropriate function.
|
||||
switch c := test.context.(type) {
|
||||
@@ -339,7 +339,7 @@ func TestPipeReadAheadBuffer(t *testing.T) {
|
||||
inode := fs.NewMockInode(ctx, fs.NewMockMountSource(nil), fs.StableAttr{
|
||||
Type: fs.Pipe,
|
||||
})
|
||||
file := fs.NewFile(ctx, fs.NewDirent(inode, "pipe"), fs.FileFlags{Read: true}, p)
|
||||
file := fs.NewFile(ctx, fs.NewDirent(ctx, inode, "pipe"), fs.FileFlags{Read: true}, p)
|
||||
|
||||
// In total we expect to read data + buffered.
|
||||
total := append(buffered, data...)
|
||||
@@ -385,7 +385,7 @@ func TestPipeReadsAccumulate(t *testing.T) {
|
||||
inode := fs.NewMockInode(ctx, fs.NewMockMountSource(nil), fs.StableAttr{
|
||||
Type: fs.Pipe,
|
||||
})
|
||||
file := fs.NewFile(ctx, fs.NewDirent(inode, "pipe"), fs.FileFlags{Read: true}, p)
|
||||
file := fs.NewFile(ctx, fs.NewDirent(ctx, inode, "pipe"), fs.FileFlags{Read: true}, p)
|
||||
|
||||
// Write some some bytes to the pipe.
|
||||
data := []byte("some message")
|
||||
@@ -453,7 +453,7 @@ func TestPipeWritesAccumulate(t *testing.T) {
|
||||
inode := fs.NewMockInode(ctx, fs.NewMockMountSource(nil), fs.StableAttr{
|
||||
Type: fs.Pipe,
|
||||
})
|
||||
file := fs.NewFile(ctx, fs.NewDirent(inode, "pipe"), fs.FileFlags{Read: true}, p)
|
||||
file := fs.NewFile(ctx, fs.NewDirent(ctx, inode, "pipe"), fs.FileFlags{Read: true}, p)
|
||||
|
||||
// Construct a segment vec that is larger than the pipe size to trigger an EWOULDBLOCK.
|
||||
wantBytes := 65536 * 2
|
||||
|
||||
@@ -29,7 +29,7 @@ func TestReaddir(t *testing.T) {
|
||||
ctx := contexttest.Context(t)
|
||||
ctx = &rootContext{
|
||||
Context: ctx,
|
||||
root: fs.NewDirent(newTestRamfsDir(ctx, nil, nil), "root"),
|
||||
root: fs.NewDirent(ctx, newTestRamfsDir(ctx, nil, nil), "root"),
|
||||
}
|
||||
for _, test := range []struct {
|
||||
// Test description.
|
||||
@@ -103,7 +103,7 @@ func TestReaddir(t *testing.T) {
|
||||
},
|
||||
} {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
openDir, err := test.dir.GetFile(ctx, fs.NewDirent(test.dir, "stub"), fs.FileFlags{Read: true})
|
||||
openDir, err := test.dir.GetFile(ctx, fs.NewDirent(ctx, test.dir, "stub"), fs.FileFlags{Read: true})
|
||||
if err != nil {
|
||||
t.Fatalf("GetFile got error %v, want nil", err)
|
||||
}
|
||||
@@ -126,7 +126,7 @@ func TestReaddirRevalidation(t *testing.T) {
|
||||
ctx := contexttest.Context(t)
|
||||
ctx = &rootContext{
|
||||
Context: ctx,
|
||||
root: fs.NewDirent(newTestRamfsDir(ctx, nil, nil), "root"),
|
||||
root: fs.NewDirent(ctx, newTestRamfsDir(ctx, nil, nil), "root"),
|
||||
}
|
||||
|
||||
// Create an overlay with two directories, each with one file.
|
||||
@@ -139,7 +139,7 @@ func TestReaddirRevalidation(t *testing.T) {
|
||||
upperDir := upper.InodeOperations.(*dir).InodeOperations.(*ramfs.Dir)
|
||||
|
||||
// Check that overlay returns the files from both upper and lower.
|
||||
openDir, err := overlay.GetFile(ctx, fs.NewDirent(overlay, "stub"), fs.FileFlags{Read: true})
|
||||
openDir, err := overlay.GetFile(ctx, fs.NewDirent(ctx, overlay, "stub"), fs.FileFlags{Read: true})
|
||||
if err != nil {
|
||||
t.Fatalf("GetFile got error %v, want nil", err)
|
||||
}
|
||||
@@ -156,7 +156,7 @@ func TestReaddirRevalidation(t *testing.T) {
|
||||
if err := upperDir.Remove(ctx, upper, "a"); err != nil {
|
||||
t.Fatalf("error removing child: %v", err)
|
||||
}
|
||||
upperDir.AddChild(ctx, "c", fs.NewInode(fsutil.NewSimpleFileInode(ctx, fs.RootOwner, fs.FilePermissions{}, 0),
|
||||
upperDir.AddChild(ctx, "c", fs.NewInode(ctx, fsutil.NewSimpleFileInode(ctx, fs.RootOwner, fs.FilePermissions{}, 0),
|
||||
upper.MountSource, fs.StableAttr{Type: fs.RegularFile}))
|
||||
|
||||
// Seek to beginning of the directory and do the readdir again.
|
||||
@@ -186,7 +186,7 @@ func TestReaddirOverlayFrozen(t *testing.T) {
|
||||
overlayInode := fs.NewTestOverlayDir(ctx, upper, lower, false)
|
||||
|
||||
// Set that overlay as the root.
|
||||
root := fs.NewDirent(overlayInode, "root")
|
||||
root := fs.NewDirent(ctx, overlayInode, "root")
|
||||
ctx = &rootContext{
|
||||
Context: ctx,
|
||||
root: root,
|
||||
|
||||
@@ -46,7 +46,7 @@ type TestFileOperations struct {
|
||||
// NewTestFile creates and initializes a new test file.
|
||||
func NewTestFile(tb testing.TB) *fs.File {
|
||||
ctx := contexttest.Context(tb)
|
||||
dirent := fs.NewDirent(anon.NewInode(ctx), "test")
|
||||
dirent := fs.NewDirent(ctx, anon.NewInode(ctx), "test")
|
||||
return fs.NewFile(ctx, dirent, fs.FileFlags{}, &TestFileOperations{})
|
||||
}
|
||||
|
||||
|
||||
@@ -253,11 +253,11 @@ func (noopMappingSpace) Invalidate(ar usermem.AddrRange, opts memmap.InvalidateO
|
||||
}
|
||||
|
||||
func anonInode(ctx context.Context) *fs.Inode {
|
||||
return fs.NewInode(&SimpleFileInode{
|
||||
return fs.NewInode(ctx, &SimpleFileInode{
|
||||
InodeSimpleAttributes: NewInodeSimpleAttributes(ctx, fs.FileOwnerFromContext(ctx), fs.FilePermissions{
|
||||
User: fs.PermMask{Read: true, Write: true},
|
||||
}, 0),
|
||||
}, fs.NewPseudoMountSource(), fs.StableAttr{
|
||||
}, fs.NewPseudoMountSource(ctx), fs.StableAttr{
|
||||
Type: fs.Anonymous,
|
||||
BlockSize: usermem.PageSize,
|
||||
})
|
||||
@@ -276,7 +276,7 @@ func TestRead(t *testing.T) {
|
||||
|
||||
// Construct a 3-page file.
|
||||
buf := pagesOf('a', 'b', 'c')
|
||||
file := fs.NewFile(ctx, fs.NewDirent(anonInode(ctx), "anon"), fs.FileFlags{}, nil)
|
||||
file := fs.NewFile(ctx, fs.NewDirent(ctx, anonInode(ctx), "anon"), fs.FileFlags{}, nil)
|
||||
uattr := fs.UnstableAttr{
|
||||
Size: int64(len(buf)),
|
||||
}
|
||||
|
||||
@@ -62,8 +62,8 @@ func rootTest(t *testing.T, name string, cp cachePolicy, fn func(context.Context
|
||||
sattr, rootInodeOperations := newInodeOperations(ctx, s, contextFile{
|
||||
file: rootFile,
|
||||
}, root.QID, p9.AttrMaskAll(), root.Attr, false /* socket */)
|
||||
m := fs.NewMountSource(s, &filesystem{}, fs.MountSourceFlags{})
|
||||
rootInode := fs.NewInode(rootInodeOperations, m, sattr)
|
||||
m := fs.NewMountSource(ctx, s, &filesystem{}, fs.MountSourceFlags{})
|
||||
rootInode := fs.NewInode(ctx, rootInodeOperations, m, sattr)
|
||||
|
||||
// Ensure that the cache is fully invalidated, so that any
|
||||
// close actions actually take place before the full harness is
|
||||
@@ -207,7 +207,7 @@ func TestRevalidation(t *testing.T) {
|
||||
name := fmt.Sprintf("cachepolicy=%s", test.cachePolicy)
|
||||
rootTest(t, name, test.cachePolicy, func(ctx context.Context, h *p9test.Harness, rootFile *p9test.Mock, rootInode *fs.Inode) {
|
||||
// Wrap in a dirent object.
|
||||
rootDir := fs.NewDirent(rootInode, "root")
|
||||
rootDir := fs.NewDirent(ctx, rootInode, "root")
|
||||
|
||||
// Create a mock file a child of the root. We save when
|
||||
// this is generated, so that when the time changed, we
|
||||
|
||||
@@ -73,7 +73,7 @@ func (i *inodeOperations) Lookup(ctx context.Context, dir *fs.Inode, name string
|
||||
sattr, node := newInodeOperations(ctx, i.fileState.s, newFile, qids[0], mask, p9attr, false)
|
||||
|
||||
// Construct a positive Dirent.
|
||||
return fs.NewDirent(fs.NewInode(node, dir.MountSource, sattr), name), nil
|
||||
return fs.NewDirent(ctx, fs.NewInode(ctx, node, dir.MountSource, sattr), name), nil
|
||||
}
|
||||
|
||||
// Creates a new Inode at name and returns its File based on the session's cache policy.
|
||||
@@ -141,7 +141,7 @@ func (i *inodeOperations) Create(ctx context.Context, dir *fs.Inode, name string
|
||||
sattr, iops := newInodeOperations(ctx, i.fileState.s, unopened, qid, mask, p9attr, false)
|
||||
|
||||
// Construct the positive Dirent.
|
||||
d := fs.NewDirent(fs.NewInode(iops, dir.MountSource, sattr), name)
|
||||
d := fs.NewDirent(ctx, fs.NewInode(ctx, iops, dir.MountSource, sattr), name)
|
||||
defer d.DecRef()
|
||||
|
||||
// Construct the new file, caching the handles if allowed.
|
||||
@@ -277,7 +277,7 @@ func (i *inodeOperations) Bind(ctx context.Context, dir *fs.Inode, name string,
|
||||
sattr, iops := newInodeOperations(ctx, i.fileState.s, unopened, qid, mask, attr, true)
|
||||
|
||||
// Construct the positive Dirent.
|
||||
childDir := fs.NewDirent(fs.NewInode(iops, dir.MountSource, sattr), name)
|
||||
childDir := fs.NewDirent(ctx, fs.NewInode(ctx, iops, dir.MountSource, sattr), name)
|
||||
i.session().endpoints.add(key, childDir, ep)
|
||||
return childDir, nil
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ func Root(ctx context.Context, dev string, filesystem fs.Filesystem, superBlockF
|
||||
}
|
||||
|
||||
// Construct the MountSource with the session and superBlockFlags.
|
||||
m := fs.NewMountSource(s, filesystem, superBlockFlags)
|
||||
m := fs.NewMountSource(ctx, s, filesystem, superBlockFlags)
|
||||
|
||||
// Given that gofer files can consume host FDs, restrict the number
|
||||
// of files that can be held by the cache.
|
||||
@@ -286,7 +286,7 @@ func Root(ctx context.Context, dev string, filesystem fs.Filesystem, superBlockF
|
||||
}
|
||||
|
||||
sattr, iops := newInodeOperations(ctx, s, s.attach, qid, valid, attr, false)
|
||||
return fs.NewInode(iops, m, sattr), nil
|
||||
return fs.NewInode(ctx, iops, m, sattr), nil
|
||||
}
|
||||
|
||||
// newEndpointMaps creates a new endpointMaps.
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/abi/linux"
|
||||
"gvisor.dev/gvisor/pkg/log"
|
||||
"gvisor.dev/gvisor/pkg/p9"
|
||||
"gvisor.dev/gvisor/pkg/sentry/context"
|
||||
"gvisor.dev/gvisor/pkg/sentry/fs"
|
||||
"gvisor.dev/gvisor/pkg/sentry/fs/host"
|
||||
"gvisor.dev/gvisor/pkg/sentry/socket/unix/transport"
|
||||
@@ -75,7 +76,7 @@ func sockTypeToP9(t linux.SockType) (p9.ConnectFlags, bool) {
|
||||
}
|
||||
|
||||
// BidirectionalConnect implements ConnectableEndpoint.BidirectionalConnect.
|
||||
func (e *endpoint) BidirectionalConnect(ce transport.ConnectingEndpoint, returnConnect func(transport.Receiver, transport.ConnectedEndpoint)) *syserr.Error {
|
||||
func (e *endpoint) BidirectionalConnect(ctx context.Context, ce transport.ConnectingEndpoint, returnConnect func(transport.Receiver, transport.ConnectedEndpoint)) *syserr.Error {
|
||||
cf, ok := sockTypeToP9(ce.Type())
|
||||
if !ok {
|
||||
return syserr.ErrConnectionRefused
|
||||
@@ -100,7 +101,7 @@ func (e *endpoint) BidirectionalConnect(ce transport.ConnectingEndpoint, returnC
|
||||
return syserr.ErrConnectionRefused
|
||||
}
|
||||
|
||||
c, serr := host.NewConnectedEndpoint(hostFile, ce.WaiterQueue(), e.path)
|
||||
c, serr := host.NewConnectedEndpoint(ctx, hostFile, ce.WaiterQueue(), e.path)
|
||||
if serr != nil {
|
||||
ce.Unlock()
|
||||
log.Warningf("Gofer returned invalid host socket for BidirectionalConnect; file %+v flags %+v: %v", e.file, cf, serr)
|
||||
@@ -116,13 +117,13 @@ func (e *endpoint) BidirectionalConnect(ce transport.ConnectingEndpoint, returnC
|
||||
|
||||
// UnidirectionalConnect implements
|
||||
// transport.BoundEndpoint.UnidirectionalConnect.
|
||||
func (e *endpoint) UnidirectionalConnect() (transport.ConnectedEndpoint, *syserr.Error) {
|
||||
func (e *endpoint) UnidirectionalConnect(ctx context.Context) (transport.ConnectedEndpoint, *syserr.Error) {
|
||||
hostFile, err := e.file.Connect(p9.DgramSocket)
|
||||
if err != nil {
|
||||
return nil, syserr.ErrConnectionRefused
|
||||
}
|
||||
|
||||
c, serr := host.NewConnectedEndpoint(hostFile, &waiter.Queue{}, e.path)
|
||||
c, serr := host.NewConnectedEndpoint(ctx, hostFile, &waiter.Queue{}, e.path)
|
||||
if serr != nil {
|
||||
log.Warningf("Gofer returned invalid host socket for UnidirectionalConnect; file %+v: %v", e.file, serr)
|
||||
return nil, serr
|
||||
|
||||
@@ -109,7 +109,7 @@ func newFileFromDonatedFD(ctx context.Context, donated int, mounter fs.FileOwner
|
||||
iops := inode.InodeOperations.(*inodeOperations)
|
||||
|
||||
name := fmt.Sprintf("host:[%d]", inode.StableAttr.InodeID)
|
||||
dirent := fs.NewDirent(inode, name)
|
||||
dirent := fs.NewDirent(ctx, inode, name)
|
||||
defer dirent.DecRef()
|
||||
|
||||
if isTTY {
|
||||
|
||||
@@ -262,7 +262,7 @@ func childDentAttrs(ctx context.Context, d *fs.Dirent) map[string]fs.DentAttr {
|
||||
// newMountSource constructs a new host fs.MountSource
|
||||
// relative to a root path. The root should match the mount point.
|
||||
func newMountSource(ctx context.Context, root string, mounter fs.FileOwner, filesystem fs.Filesystem, flags fs.MountSourceFlags, dontTranslateOwnership bool) *fs.MountSource {
|
||||
return fs.NewMountSource(&superOperations{
|
||||
return fs.NewMountSource(ctx, &superOperations{
|
||||
root: root,
|
||||
inodeMappings: make(map[uint64]string),
|
||||
mounter: mounter,
|
||||
|
||||
@@ -205,7 +205,7 @@ func newInode(ctx context.Context, msrc *fs.MountSource, fd int, saveable bool,
|
||||
}
|
||||
|
||||
// Return the fs.Inode.
|
||||
return fs.NewInode(iops, msrc, fileState.sattr), nil
|
||||
return fs.NewInode(ctx, iops, msrc, fileState.sattr), nil
|
||||
}
|
||||
|
||||
// Mappable implements fs.InodeOperations.Mappable.
|
||||
@@ -245,7 +245,7 @@ func (i *inodeOperations) Lookup(ctx context.Context, dir *fs.Inode, name string
|
||||
}
|
||||
|
||||
// Return the fs.Dirent.
|
||||
return fs.NewDirent(inode, name), nil
|
||||
return fs.NewDirent(ctx, inode, name), nil
|
||||
}
|
||||
|
||||
// Create implements fs.InodeOperations.Create.
|
||||
@@ -265,7 +265,7 @@ func (i *inodeOperations) Create(ctx context.Context, dir *fs.Inode, name string
|
||||
return nil, err
|
||||
}
|
||||
|
||||
d := fs.NewDirent(inode, name)
|
||||
d := fs.NewDirent(ctx, inode, name)
|
||||
defer d.DecRef()
|
||||
return inode.GetFile(ctx, d, flags)
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ func TestMultipleReaddir(t *testing.T) {
|
||||
t.Fatalf("Failed to create inode: %v", err)
|
||||
}
|
||||
|
||||
dirent := fs.NewDirent(n, "readdir")
|
||||
dirent := fs.NewDirent(ctx, n, "readdir")
|
||||
openFile, err := n.GetFile(ctx, dirent, fs.FileFlags{Read: true})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get file: %v", err)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user