mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Plumb context.Context into kernfs.Inode.Open().
PiperOrigin-RevId: 308304793
This commit is contained in:
@@ -160,7 +160,7 @@ func (i *rootInode) masterClose(t *Terminal) {
|
||||
}
|
||||
|
||||
// Open implements kernfs.Inode.Open.
|
||||
func (i *rootInode) Open(rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
func (i *rootInode) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
fd, err := kernfs.NewGenericDirectoryFD(rp.Mount(), vfsd, &i.OrderedChildren, &opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -46,7 +46,7 @@ type masterInode struct {
|
||||
var _ kernfs.Inode = (*masterInode)(nil)
|
||||
|
||||
// Open implements kernfs.Inode.Open.
|
||||
func (mi *masterInode) Open(rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
func (mi *masterInode) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
t, err := mi.root.allocateTerminal(rp.Credentials())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -48,7 +48,7 @@ type slaveInode struct {
|
||||
var _ kernfs.Inode = (*slaveInode)(nil)
|
||||
|
||||
// Open implements kernfs.Inode.Open.
|
||||
func (si *slaveInode) Open(rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
func (si *slaveInode) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
si.IncRef()
|
||||
fd := &slaveFileDescription{
|
||||
inode: si,
|
||||
|
||||
@@ -66,7 +66,7 @@ func NewFilesystem(vfsObj *vfs.VirtualFilesystem) *vfs.Filesystem {
|
||||
}
|
||||
|
||||
// ImportFD sets up and returns a vfs.FileDescription from a donated fd.
|
||||
func ImportFD(mnt *vfs.Mount, hostFD int, isTTY bool) (*vfs.FileDescription, error) {
|
||||
func ImportFD(ctx context.Context, mnt *vfs.Mount, hostFD int, isTTY bool) (*vfs.FileDescription, error) {
|
||||
fs, ok := mnt.Filesystem().Impl().(*kernfs.Filesystem)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("can't import host FDs into filesystems of type %T", mnt.Filesystem().Impl())
|
||||
@@ -108,7 +108,7 @@ func ImportFD(mnt *vfs.Mount, hostFD int, isTTY bool) (*vfs.FileDescription, err
|
||||
// i.open will take a reference on d.
|
||||
defer d.DecRef()
|
||||
|
||||
return i.open(d.VFSDentry(), mnt)
|
||||
return i.open(ctx, d.VFSDentry(), mnt)
|
||||
}
|
||||
|
||||
// inode implements kernfs.Inode.
|
||||
@@ -360,11 +360,11 @@ func (i *inode) Destroy() {
|
||||
}
|
||||
|
||||
// Open implements kernfs.Inode.
|
||||
func (i *inode) Open(rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
return i.open(vfsd, rp.Mount())
|
||||
func (i *inode) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
return i.open(ctx, vfsd, rp.Mount())
|
||||
}
|
||||
|
||||
func (i *inode) open(d *vfs.Dentry, mnt *vfs.Mount) (*vfs.FileDescription, error) {
|
||||
func (i *inode) open(ctx context.Context, d *vfs.Dentry, mnt *vfs.Mount) (*vfs.FileDescription, error) {
|
||||
var s syscall.Stat_t
|
||||
if err := syscall.Fstat(i.hostFD, &s); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -53,7 +53,7 @@ func (f *DynamicBytesFile) Init(creds *auth.Credentials, ino uint64, data vfs.Dy
|
||||
}
|
||||
|
||||
// Open implements Inode.Open.
|
||||
func (f *DynamicBytesFile) Open(rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
func (f *DynamicBytesFile) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
fd := &DynamicBytesFD{}
|
||||
if err := fd.Init(rp.Mount(), vfsd, f.data, opts.Flags); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -406,7 +406,7 @@ func (fs *Filesystem) OpenAt(ctx context.Context, rp *vfs.ResolvingPath, opts vf
|
||||
if err := inode.CheckPermissions(ctx, rp.Credentials(), ats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return inode.Open(rp, vfsd, opts)
|
||||
return inode.Open(ctx, rp, vfsd, opts)
|
||||
}
|
||||
|
||||
// May create new file.
|
||||
@@ -425,7 +425,7 @@ func (fs *Filesystem) OpenAt(ctx context.Context, rp *vfs.ResolvingPath, opts vf
|
||||
if err := inode.CheckPermissions(ctx, rp.Credentials(), ats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return inode.Open(rp, vfsd, opts)
|
||||
return inode.Open(ctx, rp, vfsd, opts)
|
||||
}
|
||||
afterTrailingSymlink:
|
||||
parentVFSD, parentInode, err := fs.walkParentDirLocked(ctx, rp)
|
||||
@@ -466,7 +466,7 @@ afterTrailingSymlink:
|
||||
}
|
||||
child := childVFSD.Impl().(*Dentry)
|
||||
parentVFSD.Impl().(*Dentry).InsertChild(pc, child)
|
||||
return child.inode.Open(rp, childVFSD, opts)
|
||||
return child.inode.Open(ctx, rp, childVFSD, opts)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -499,7 +499,7 @@ afterTrailingSymlink:
|
||||
if err := child.inode.CheckPermissions(ctx, rp.Credentials(), ats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return child.inode.Open(rp, &child.vfsd, opts)
|
||||
return child.inode.Open(ctx, rp, &child.vfsd, opts)
|
||||
}
|
||||
|
||||
// ReadlinkAt implements vfs.FilesystemImpl.ReadlinkAt.
|
||||
|
||||
@@ -525,7 +525,7 @@ type InodeSymlink struct {
|
||||
}
|
||||
|
||||
// Open implements Inode.Open.
|
||||
func (InodeSymlink) Open(rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
func (InodeSymlink) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
return nil, syserror.ELOOP
|
||||
}
|
||||
|
||||
@@ -567,7 +567,7 @@ func (s *StaticDirectory) Init(creds *auth.Credentials, ino uint64, perm linux.F
|
||||
}
|
||||
|
||||
// Open implements kernfs.Inode.
|
||||
func (s *StaticDirectory) Open(rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
func (s *StaticDirectory) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
fd, err := NewGenericDirectoryFD(rp.Mount(), vfsd, &s.OrderedChildren, &opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -308,7 +308,7 @@ type Inode interface {
|
||||
//
|
||||
// Precondition: rp.Done(). vfsd.Impl() must be the kernfs Dentry containing
|
||||
// the inode on which Open() is being called.
|
||||
Open(rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error)
|
||||
Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error)
|
||||
}
|
||||
|
||||
type inodeRefs interface {
|
||||
|
||||
@@ -116,7 +116,7 @@ func (fs *filesystem) newReadonlyDir(creds *auth.Credentials, mode linux.FileMod
|
||||
return &dir.dentry
|
||||
}
|
||||
|
||||
func (d *readonlyDir) Open(rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
func (d *readonlyDir) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
fd, err := kernfs.NewGenericDirectoryFD(rp.Mount(), vfsd, &d.OrderedChildren, &opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -146,7 +146,7 @@ func (fs *filesystem) newDir(creds *auth.Credentials, mode linux.FileMode, conte
|
||||
return &dir.dentry
|
||||
}
|
||||
|
||||
func (d *dir) Open(rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
func (d *dir) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
fd, err := kernfs.NewGenericDirectoryFD(rp.Mount(), vfsd, &d.OrderedChildren, &opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -129,9 +129,8 @@ func (i *inode) SetStat(ctx context.Context, vfsfs *vfs.Filesystem, creds *auth.
|
||||
}
|
||||
|
||||
// Open implements kernfs.Inode.Open.
|
||||
func (i *inode) Open(rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
// FIXME(b/38173783): kernfs does not plumb Context here.
|
||||
return i.pipe.Open(context.Background(), rp.Mount(), vfsd, opts.Flags)
|
||||
func (i *inode) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
return i.pipe.Open(ctx, rp.Mount(), vfsd, opts.Flags)
|
||||
}
|
||||
|
||||
// NewConnectedPipeFDs returns a pair of FileDescriptions representing the read
|
||||
|
||||
@@ -151,7 +151,7 @@ func (fd *subtasksFD) SetStat(ctx context.Context, opts vfs.SetStatOptions) erro
|
||||
}
|
||||
|
||||
// Open implements kernfs.Inode.
|
||||
func (i *subtasksInode) Open(rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
func (i *subtasksInode) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
fd := &subtasksFD{task: i.task}
|
||||
if err := fd.Init(&i.OrderedChildren, &opts); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -102,7 +102,7 @@ func (i *taskInode) Valid(ctx context.Context) bool {
|
||||
}
|
||||
|
||||
// Open implements kernfs.Inode.
|
||||
func (i *taskInode) Open(rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
func (i *taskInode) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
fd, err := kernfs.NewGenericDirectoryFD(rp.Mount(), vfsd, &i.OrderedChildren, &opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -142,7 +142,7 @@ func (i *fdDirInode) Lookup(ctx context.Context, name string) (*vfs.Dentry, erro
|
||||
}
|
||||
|
||||
// Open implements kernfs.Inode.
|
||||
func (i *fdDirInode) Open(rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
func (i *fdDirInode) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
fd, err := kernfs.NewGenericDirectoryFD(rp.Mount(), vfsd, &i.OrderedChildren, &opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -269,7 +269,7 @@ func (i *fdInfoDirInode) Lookup(ctx context.Context, name string) (*vfs.Dentry,
|
||||
}
|
||||
|
||||
// Open implements kernfs.Inode.
|
||||
func (i *fdInfoDirInode) Open(rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
func (i *fdInfoDirInode) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
fd, err := kernfs.NewGenericDirectoryFD(rp.Mount(), vfsd, &i.OrderedChildren, &opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -788,7 +788,7 @@ func (i *namespaceInode) Init(creds *auth.Credentials, ino uint64, perm linux.Fi
|
||||
}
|
||||
|
||||
// Open implements Inode.Open.
|
||||
func (i *namespaceInode) Open(rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
func (i *namespaceInode) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
fd := &namespaceFD{inode: i}
|
||||
i.IncRef()
|
||||
if err := fd.vfsfd.Init(fd, opts.Flags, rp.Mount(), vfsd, &vfs.FileDescriptionOptions{}); err != nil {
|
||||
|
||||
@@ -201,7 +201,7 @@ func (i *tasksInode) IterDirents(ctx context.Context, cb vfs.IterDirentsCallback
|
||||
}
|
||||
|
||||
// Open implements kernfs.Inode.
|
||||
func (i *tasksInode) Open(rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
func (i *tasksInode) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
fd, err := kernfs.NewGenericDirectoryFD(rp.Mount(), vfsd, &i.OrderedChildren, &opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -69,7 +69,7 @@ type inode struct {
|
||||
}
|
||||
|
||||
// Open implements kernfs.Inode.Open.
|
||||
func (i *inode) Open(rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
func (i *inode) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
return nil, syserror.ENXIO
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ func (*dir) SetStat(context.Context, *vfs.Filesystem, *auth.Credentials, vfs.Set
|
||||
}
|
||||
|
||||
// Open implements kernfs.Inode.Open.
|
||||
func (d *dir) Open(rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
func (d *dir) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
fd, err := kernfs.NewGenericDirectoryFD(rp.Mount(), vfsd, &d.OrderedChildren, &opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ func createFDTableVFS2(ctx context.Context, console bool, stdioFDs []int) (*kern
|
||||
|
||||
for appFD, hostFD := range stdioFDs {
|
||||
// TODO(gvisor.dev/issue/1482): Add TTY support.
|
||||
appFile, err := vfshost.ImportFD(k.HostMount(), hostFD, false)
|
||||
appFile, err := vfshost.ImportFD(ctx, k.HostMount(), hostFD, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user