mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Include context in kernfs.Inode.Stat method
To implement stat(2) in FUSE, we have to embed credentials and pid in request header. The information should be extracted from the context passed to VFS layer. Therefore `Stat()` signature in `kernfs.Inode` interface should include context as first argument. Some other fs implementations need to be modified as well, such as devpts, host, pipefs, and proc. Fixes #3235
This commit is contained in:
@@ -67,8 +67,8 @@ func (mi *masterInode) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vf
|
||||
}
|
||||
|
||||
// Stat implements kernfs.Inode.Stat.
|
||||
func (mi *masterInode) Stat(vfsfs *vfs.Filesystem, opts vfs.StatOptions) (linux.Statx, error) {
|
||||
statx, err := mi.InodeAttrs.Stat(vfsfs, opts)
|
||||
func (mi *masterInode) Stat(ctx context.Context, vfsfs *vfs.Filesystem, opts vfs.StatOptions) (linux.Statx, error) {
|
||||
statx, err := mi.InodeAttrs.Stat(ctx, vfsfs, opts)
|
||||
if err != nil {
|
||||
return linux.Statx{}, err
|
||||
}
|
||||
@@ -186,7 +186,7 @@ func (mfd *masterFileDescription) SetStat(ctx context.Context, opts vfs.SetStatO
|
||||
// Stat implements vfs.FileDescriptionImpl.Stat.
|
||||
func (mfd *masterFileDescription) Stat(ctx context.Context, opts vfs.StatOptions) (linux.Statx, error) {
|
||||
fs := mfd.vfsfd.VirtualDentry().Mount().Filesystem()
|
||||
return mfd.inode.Stat(fs, opts)
|
||||
return mfd.inode.Stat(ctx, fs, opts)
|
||||
}
|
||||
|
||||
// LockPOSIX implements vfs.FileDescriptionImpl.LockPOSIX.
|
||||
|
||||
@@ -73,8 +73,8 @@ func (si *slaveInode) Valid(context.Context) bool {
|
||||
}
|
||||
|
||||
// Stat implements kernfs.Inode.Stat.
|
||||
func (si *slaveInode) Stat(vfsfs *vfs.Filesystem, opts vfs.StatOptions) (linux.Statx, error) {
|
||||
statx, err := si.InodeAttrs.Stat(vfsfs, opts)
|
||||
func (si *slaveInode) Stat(ctx context.Context, vfsfs *vfs.Filesystem, opts vfs.StatOptions) (linux.Statx, error) {
|
||||
statx, err := si.InodeAttrs.Stat(ctx, vfsfs, opts)
|
||||
if err != nil {
|
||||
return linux.Statx{}, err
|
||||
}
|
||||
@@ -183,7 +183,7 @@ func (sfd *slaveFileDescription) SetStat(ctx context.Context, opts vfs.SetStatOp
|
||||
// Stat implements vfs.FileDescriptionImpl.Stat.
|
||||
func (sfd *slaveFileDescription) Stat(ctx context.Context, opts vfs.StatOptions) (linux.Statx, error) {
|
||||
fs := sfd.vfsfd.VirtualDentry().Mount().Filesystem()
|
||||
return sfd.inode.Stat(fs, opts)
|
||||
return sfd.inode.Stat(ctx, fs, opts)
|
||||
}
|
||||
|
||||
// LockPOSIX implements vfs.FileDescriptionImpl.LockPOSIX.
|
||||
|
||||
@@ -259,7 +259,7 @@ func (i *inode) Mode() linux.FileMode {
|
||||
}
|
||||
|
||||
// Stat implements kernfs.Inode.
|
||||
func (i *inode) Stat(vfsfs *vfs.Filesystem, opts vfs.StatOptions) (linux.Statx, error) {
|
||||
func (i *inode) Stat(ctx context.Context, vfsfs *vfs.Filesystem, opts vfs.StatOptions) (linux.Statx, error) {
|
||||
if opts.Mask&linux.STATX__RESERVED != 0 {
|
||||
return linux.Statx{}, syserror.EINVAL
|
||||
}
|
||||
@@ -534,8 +534,8 @@ func (f *fileDescription) SetStat(ctx context.Context, opts vfs.SetStatOptions)
|
||||
}
|
||||
|
||||
// Stat implements vfs.FileDescriptionImpl.
|
||||
func (f *fileDescription) Stat(_ context.Context, opts vfs.StatOptions) (linux.Statx, error) {
|
||||
return f.inode.Stat(f.vfsfd.Mount().Filesystem(), opts)
|
||||
func (f *fileDescription) Stat(ctx context.Context, opts vfs.StatOptions) (linux.Statx, error) {
|
||||
return f.inode.Stat(ctx, f.vfsfd.Mount().Filesystem(), opts)
|
||||
}
|
||||
|
||||
// Release implements vfs.FileDescriptionImpl.
|
||||
|
||||
@@ -127,7 +127,7 @@ func (fd *DynamicBytesFD) Release() {}
|
||||
// Stat implements vfs.FileDescriptionImpl.Stat.
|
||||
func (fd *DynamicBytesFD) Stat(ctx context.Context, opts vfs.StatOptions) (linux.Statx, error) {
|
||||
fs := fd.vfsfd.VirtualDentry().Mount().Filesystem()
|
||||
return fd.inode.Stat(fs, opts)
|
||||
return fd.inode.Stat(ctx, fs, opts)
|
||||
}
|
||||
|
||||
// SetStat implements vfs.FileDescriptionImpl.SetStat.
|
||||
|
||||
@@ -132,7 +132,7 @@ func (fd *GenericDirectoryFD) IterDirents(ctx context.Context, cb vfs.IterDirent
|
||||
opts := vfs.StatOptions{Mask: linux.STATX_INO}
|
||||
// Handle ".".
|
||||
if fd.off == 0 {
|
||||
stat, err := fd.inode().Stat(fd.filesystem(), opts)
|
||||
stat, err := fd.inode().Stat(ctx, fd.filesystem(), opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -152,7 +152,7 @@ func (fd *GenericDirectoryFD) IterDirents(ctx context.Context, cb vfs.IterDirent
|
||||
if fd.off == 1 {
|
||||
vfsd := fd.vfsfd.VirtualDentry().Dentry()
|
||||
parentInode := genericParentOrSelf(vfsd.Impl().(*Dentry)).inode
|
||||
stat, err := parentInode.Stat(fd.filesystem(), opts)
|
||||
stat, err := parentInode.Stat(ctx, fd.filesystem(), opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -176,7 +176,7 @@ func (fd *GenericDirectoryFD) IterDirents(ctx context.Context, cb vfs.IterDirent
|
||||
childIdx := fd.off - 2
|
||||
for it := fd.children.nthLocked(childIdx); it != nil; it = it.Next() {
|
||||
inode := it.Dentry.Impl().(*Dentry).inode
|
||||
stat, err := inode.Stat(fd.filesystem(), opts)
|
||||
stat, err := inode.Stat(ctx, fd.filesystem(), opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -226,7 +226,7 @@ func (fd *GenericDirectoryFD) Seek(ctx context.Context, offset int64, whence int
|
||||
func (fd *GenericDirectoryFD) Stat(ctx context.Context, opts vfs.StatOptions) (linux.Statx, error) {
|
||||
fs := fd.filesystem()
|
||||
inode := fd.inode()
|
||||
return inode.Stat(fs, opts)
|
||||
return inode.Stat(ctx, fs, opts)
|
||||
}
|
||||
|
||||
// SetStat implements vfs.FileDescriptionImpl.SetStat.
|
||||
|
||||
@@ -684,7 +684,7 @@ func (fs *Filesystem) StatAt(ctx context.Context, rp *vfs.ResolvingPath, opts vf
|
||||
if err != nil {
|
||||
return linux.Statx{}, err
|
||||
}
|
||||
return inode.Stat(fs.VFSFilesystem(), opts)
|
||||
return inode.Stat(ctx, fs.VFSFilesystem(), opts)
|
||||
}
|
||||
|
||||
// StatFSAt implements vfs.FilesystemImpl.StatFSAt.
|
||||
|
||||
@@ -243,7 +243,7 @@ func (a *InodeAttrs) Mode() linux.FileMode {
|
||||
// Stat partially implements Inode.Stat. Note that this function doesn't provide
|
||||
// all the stat fields, and the embedder should consider extending the result
|
||||
// with filesystem-specific fields.
|
||||
func (a *InodeAttrs) Stat(*vfs.Filesystem, vfs.StatOptions) (linux.Statx, error) {
|
||||
func (a *InodeAttrs) Stat(context.Context, *vfs.Filesystem, vfs.StatOptions) (linux.Statx, error) {
|
||||
var stat linux.Statx
|
||||
stat.Mask = linux.STATX_TYPE | linux.STATX_MODE | linux.STATX_UID | linux.STATX_GID | linux.STATX_INO | linux.STATX_NLINK
|
||||
stat.DevMajor = a.devMajor
|
||||
|
||||
@@ -346,7 +346,7 @@ type inodeMetadata interface {
|
||||
|
||||
// Stat returns the metadata for this inode. This corresponds to
|
||||
// vfs.FilesystemImpl.StatAt.
|
||||
Stat(fs *vfs.Filesystem, opts vfs.StatOptions) (linux.Statx, error)
|
||||
Stat(ctx context.Context, fs *vfs.Filesystem, opts vfs.StatOptions) (linux.Statx, error)
|
||||
|
||||
// SetStat updates the metadata for this inode. This corresponds to
|
||||
// vfs.FilesystemImpl.SetStatAt. Implementations are responsible for checking
|
||||
|
||||
@@ -115,7 +115,7 @@ func (i *inode) Mode() linux.FileMode {
|
||||
}
|
||||
|
||||
// Stat implements kernfs.Inode.Stat.
|
||||
func (i *inode) Stat(vfsfs *vfs.Filesystem, opts vfs.StatOptions) (linux.Statx, error) {
|
||||
func (i *inode) Stat(_ context.Context, vfsfs *vfs.Filesystem, opts vfs.StatOptions) (linux.Statx, error) {
|
||||
ts := linux.NsecToStatxTimestamp(i.ctime.Nanoseconds())
|
||||
return linux.Statx{
|
||||
Mask: linux.STATX_TYPE | linux.STATX_MODE | linux.STATX_NLINK | linux.STATX_UID | linux.STATX_GID | linux.STATX_ATIME | linux.STATX_MTIME | linux.STATX_CTIME | linux.STATX_INO | linux.STATX_SIZE | linux.STATX_BLOCKS,
|
||||
|
||||
@@ -165,8 +165,8 @@ func (i *subtasksInode) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *v
|
||||
}
|
||||
|
||||
// Stat implements kernfs.Inode.
|
||||
func (i *subtasksInode) Stat(vsfs *vfs.Filesystem, opts vfs.StatOptions) (linux.Statx, error) {
|
||||
stat, err := i.InodeAttrs.Stat(vsfs, opts)
|
||||
func (i *subtasksInode) Stat(ctx context.Context, vsfs *vfs.Filesystem, opts vfs.StatOptions) (linux.Statx, error) {
|
||||
stat, err := i.InodeAttrs.Stat(ctx, vsfs, opts)
|
||||
if err != nil {
|
||||
return linux.Statx{}, err
|
||||
}
|
||||
|
||||
@@ -156,8 +156,8 @@ func (fs *filesystem) newTaskOwnedDir(task *kernel.Task, ino uint64, perm linux.
|
||||
}
|
||||
|
||||
// Stat implements kernfs.Inode.
|
||||
func (i *taskOwnedInode) Stat(fs *vfs.Filesystem, opts vfs.StatOptions) (linux.Statx, error) {
|
||||
stat, err := i.Inode.Stat(fs, opts)
|
||||
func (i *taskOwnedInode) Stat(ctx context.Context, fs *vfs.Filesystem, opts vfs.StatOptions) (linux.Statx, error) {
|
||||
stat, err := i.Inode.Stat(ctx, fs, opts)
|
||||
if err != nil {
|
||||
return linux.Statx{}, err
|
||||
}
|
||||
|
||||
@@ -876,7 +876,7 @@ var _ vfs.FileDescriptionImpl = (*namespaceFD)(nil)
|
||||
// Stat implements FileDescriptionImpl.
|
||||
func (fd *namespaceFD) Stat(ctx context.Context, opts vfs.StatOptions) (linux.Statx, error) {
|
||||
vfs := fd.vfsfd.VirtualDentry().Mount().Filesystem()
|
||||
return fd.inode.Stat(vfs, opts)
|
||||
return fd.inode.Stat(ctx, vfs, opts)
|
||||
}
|
||||
|
||||
// SetStat implements FileDescriptionImpl.
|
||||
|
||||
@@ -206,8 +206,8 @@ func (i *tasksInode) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.
|
||||
return fd.VFSFileDescription(), nil
|
||||
}
|
||||
|
||||
func (i *tasksInode) Stat(vsfs *vfs.Filesystem, opts vfs.StatOptions) (linux.Statx, error) {
|
||||
stat, err := i.InodeAttrs.Stat(vsfs, opts)
|
||||
func (i *tasksInode) Stat(ctx context.Context, vsfs *vfs.Filesystem, opts vfs.StatOptions) (linux.Statx, error) {
|
||||
stat, err := i.InodeAttrs.Stat(ctx, vsfs, opts)
|
||||
if err != nil {
|
||||
return linux.Statx{}, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user