mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Merge pull request #3972 from btw616:fix/comments
PiperOrigin-RevId: 332486111
This commit is contained in:
@@ -139,12 +139,12 @@ func ImportFD(ctx context.Context, mnt *vfs.Mount, hostFD int, isTTY bool) (*vfs
|
||||
// filesystemType implements vfs.FilesystemType.
|
||||
type filesystemType struct{}
|
||||
|
||||
// GetFilesystem implements FilesystemType.GetFilesystem.
|
||||
// GetFilesystem implements vfs.FilesystemType.GetFilesystem.
|
||||
func (filesystemType) GetFilesystem(context.Context, *vfs.VirtualFilesystem, *auth.Credentials, string, vfs.GetFilesystemOptions) (*vfs.Filesystem, *vfs.Dentry, error) {
|
||||
panic("host.filesystemType.GetFilesystem should never be called")
|
||||
}
|
||||
|
||||
// Name implements FilesystemType.Name.
|
||||
// Name implements vfs.FilesystemType.Name.
|
||||
func (filesystemType) Name() string {
|
||||
return "none"
|
||||
}
|
||||
@@ -243,7 +243,7 @@ type inode struct {
|
||||
pf inodePlatformFile
|
||||
}
|
||||
|
||||
// CheckPermissions implements kernfs.Inode.
|
||||
// CheckPermissions implements kernfs.Inode.CheckPermissions.
|
||||
func (i *inode) CheckPermissions(ctx context.Context, creds *auth.Credentials, ats vfs.AccessTypes) error {
|
||||
var s syscall.Stat_t
|
||||
if err := syscall.Fstat(i.hostFD, &s); err != nil {
|
||||
@@ -252,7 +252,7 @@ func (i *inode) CheckPermissions(ctx context.Context, creds *auth.Credentials, a
|
||||
return vfs.GenericCheckPermissions(creds, ats, linux.FileMode(s.Mode), auth.KUID(s.Uid), auth.KGID(s.Gid))
|
||||
}
|
||||
|
||||
// Mode implements kernfs.Inode.
|
||||
// Mode implements kernfs.Inode.Mode.
|
||||
func (i *inode) Mode() linux.FileMode {
|
||||
var s syscall.Stat_t
|
||||
if err := syscall.Fstat(i.hostFD, &s); err != nil {
|
||||
@@ -263,7 +263,7 @@ func (i *inode) Mode() linux.FileMode {
|
||||
return linux.FileMode(s.Mode)
|
||||
}
|
||||
|
||||
// Stat implements kernfs.Inode.
|
||||
// Stat implements kernfs.Inode.Stat.
|
||||
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
|
||||
@@ -376,7 +376,7 @@ func (i *inode) fstat(fs *filesystem) (linux.Statx, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// SetStat implements kernfs.Inode.
|
||||
// SetStat implements kernfs.Inode.SetStat.
|
||||
func (i *inode) SetStat(ctx context.Context, fs *vfs.Filesystem, creds *auth.Credentials, opts vfs.SetStatOptions) error {
|
||||
s := &opts.Stat
|
||||
|
||||
@@ -435,17 +435,17 @@ func (i *inode) SetStat(ctx context.Context, fs *vfs.Filesystem, creds *auth.Cre
|
||||
return nil
|
||||
}
|
||||
|
||||
// IncRef implements kernfs.Inode.
|
||||
// IncRef implements kernfs.Inode.IncRef.
|
||||
func (i *inode) IncRef() {
|
||||
i.refs.IncRef()
|
||||
}
|
||||
|
||||
// TryIncRef implements kernfs.Inode.
|
||||
// TryIncRef implements kernfs.Inode.TryIncRef.
|
||||
func (i *inode) TryIncRef() bool {
|
||||
return i.refs.TryIncRef()
|
||||
}
|
||||
|
||||
// DecRef implements kernfs.Inode.
|
||||
// DecRef implements kernfs.Inode.DecRef.
|
||||
func (i *inode) DecRef(ctx context.Context) {
|
||||
i.refs.DecRef(func() {
|
||||
if i.wouldBlock {
|
||||
@@ -457,7 +457,7 @@ func (i *inode) DecRef(ctx context.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// Open implements kernfs.Inode.
|
||||
// Open implements kernfs.Inode.Open.
|
||||
func (i *inode) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
// Once created, we cannot re-open a socket fd through /proc/[pid]/fd/.
|
||||
if i.Mode().FileType() == linux.S_IFSOCK {
|
||||
@@ -542,28 +542,28 @@ type fileDescription struct {
|
||||
offset int64
|
||||
}
|
||||
|
||||
// SetStat implements vfs.FileDescriptionImpl.
|
||||
// SetStat implements vfs.FileDescriptionImpl.SetStat.
|
||||
func (f *fileDescription) SetStat(ctx context.Context, opts vfs.SetStatOptions) error {
|
||||
creds := auth.CredentialsFromContext(ctx)
|
||||
return f.inode.SetStat(ctx, f.vfsfd.Mount().Filesystem(), creds, opts)
|
||||
}
|
||||
|
||||
// Stat implements vfs.FileDescriptionImpl.
|
||||
// Stat implements vfs.FileDescriptionImpl.Stat.
|
||||
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.
|
||||
// Release implements vfs.FileDescriptionImpl.Release.
|
||||
func (f *fileDescription) Release(context.Context) {
|
||||
// noop
|
||||
}
|
||||
|
||||
// Allocate implements vfs.FileDescriptionImpl.
|
||||
// Allocate implements vfs.FileDescriptionImpl.Allocate.
|
||||
func (f *fileDescription) Allocate(ctx context.Context, mode, offset, length uint64) error {
|
||||
return unix.Fallocate(f.inode.hostFD, uint32(mode), int64(offset), int64(length))
|
||||
}
|
||||
|
||||
// PRead implements FileDescriptionImpl.
|
||||
// PRead implements vfs.FileDescriptionImpl.PRead.
|
||||
func (f *fileDescription) PRead(ctx context.Context, dst usermem.IOSequence, offset int64, opts vfs.ReadOptions) (int64, error) {
|
||||
i := f.inode
|
||||
if !i.seekable {
|
||||
@@ -573,7 +573,7 @@ func (f *fileDescription) PRead(ctx context.Context, dst usermem.IOSequence, off
|
||||
return readFromHostFD(ctx, i.hostFD, dst, offset, opts.Flags)
|
||||
}
|
||||
|
||||
// Read implements FileDescriptionImpl.
|
||||
// Read implements vfs.FileDescriptionImpl.Read.
|
||||
func (f *fileDescription) Read(ctx context.Context, dst usermem.IOSequence, opts vfs.ReadOptions) (int64, error) {
|
||||
i := f.inode
|
||||
if !i.seekable {
|
||||
@@ -610,7 +610,7 @@ func readFromHostFD(ctx context.Context, hostFD int, dst usermem.IOSequence, off
|
||||
return int64(n), err
|
||||
}
|
||||
|
||||
// PWrite implements FileDescriptionImpl.
|
||||
// PWrite implements vfs.FileDescriptionImpl.PWrite.
|
||||
func (f *fileDescription) PWrite(ctx context.Context, src usermem.IOSequence, offset int64, opts vfs.WriteOptions) (int64, error) {
|
||||
if !f.inode.seekable {
|
||||
return 0, syserror.ESPIPE
|
||||
@@ -619,7 +619,7 @@ func (f *fileDescription) PWrite(ctx context.Context, src usermem.IOSequence, of
|
||||
return f.writeToHostFD(ctx, src, offset, opts.Flags)
|
||||
}
|
||||
|
||||
// Write implements FileDescriptionImpl.
|
||||
// Write implements vfs.FileDescriptionImpl.Write.
|
||||
func (f *fileDescription) Write(ctx context.Context, src usermem.IOSequence, opts vfs.WriteOptions) (int64, error) {
|
||||
i := f.inode
|
||||
if !i.seekable {
|
||||
@@ -667,7 +667,7 @@ func (f *fileDescription) writeToHostFD(ctx context.Context, src usermem.IOSeque
|
||||
return int64(n), err
|
||||
}
|
||||
|
||||
// Seek implements FileDescriptionImpl.
|
||||
// Seek implements vfs.FileDescriptionImpl.Seek.
|
||||
//
|
||||
// Note that we do not support seeking on directories, since we do not even
|
||||
// allow directory fds to be imported at all.
|
||||
@@ -732,13 +732,13 @@ func (f *fileDescription) Seek(_ context.Context, offset int64, whence int32) (i
|
||||
return f.offset, nil
|
||||
}
|
||||
|
||||
// Sync implements FileDescriptionImpl.
|
||||
// Sync implements vfs.FileDescriptionImpl.Sync.
|
||||
func (f *fileDescription) Sync(context.Context) error {
|
||||
// TODO(gvisor.dev/issue/1897): Currently, we always sync everything.
|
||||
return unix.Fsync(f.inode.hostFD)
|
||||
}
|
||||
|
||||
// ConfigureMMap implements FileDescriptionImpl.
|
||||
// ConfigureMMap implements vfs.FileDescriptionImpl.ConfigureMMap.
|
||||
func (f *fileDescription) ConfigureMMap(_ context.Context, opts *memmap.MMapOpts) error {
|
||||
if !f.inode.canMap {
|
||||
return syserror.ENODEV
|
||||
|
||||
@@ -76,7 +76,7 @@ func (t *TTYFileDescription) Release(ctx context.Context) {
|
||||
t.fileDescription.Release(ctx)
|
||||
}
|
||||
|
||||
// PRead implements vfs.FileDescriptionImpl.
|
||||
// PRead implements vfs.FileDescriptionImpl.PRead.
|
||||
//
|
||||
// Reading from a TTY is only allowed for foreground process groups. Background
|
||||
// process groups will either get EIO or a SIGTTIN.
|
||||
@@ -94,7 +94,7 @@ func (t *TTYFileDescription) PRead(ctx context.Context, dst usermem.IOSequence,
|
||||
return t.fileDescription.PRead(ctx, dst, offset, opts)
|
||||
}
|
||||
|
||||
// Read implements vfs.FileDescriptionImpl.
|
||||
// Read implements vfs.FileDescriptionImpl.Read.
|
||||
//
|
||||
// Reading from a TTY is only allowed for foreground process groups. Background
|
||||
// process groups will either get EIO or a SIGTTIN.
|
||||
@@ -112,7 +112,7 @@ func (t *TTYFileDescription) Read(ctx context.Context, dst usermem.IOSequence, o
|
||||
return t.fileDescription.Read(ctx, dst, opts)
|
||||
}
|
||||
|
||||
// PWrite implements vfs.FileDescriptionImpl.
|
||||
// PWrite implements vfs.FileDescriptionImpl.PWrite.
|
||||
func (t *TTYFileDescription) PWrite(ctx context.Context, src usermem.IOSequence, offset int64, opts vfs.WriteOptions) (int64, error) {
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
@@ -127,7 +127,7 @@ func (t *TTYFileDescription) PWrite(ctx context.Context, src usermem.IOSequence,
|
||||
return t.fileDescription.PWrite(ctx, src, offset, opts)
|
||||
}
|
||||
|
||||
// Write implements vfs.FileDescriptionImpl.
|
||||
// Write implements vfs.FileDescriptionImpl.Write.
|
||||
func (t *TTYFileDescription) Write(ctx context.Context, src usermem.IOSequence, opts vfs.WriteOptions) (int64, error) {
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
@@ -142,7 +142,7 @@ func (t *TTYFileDescription) Write(ctx context.Context, src usermem.IOSequence,
|
||||
return t.fileDescription.Write(ctx, src, opts)
|
||||
}
|
||||
|
||||
// Ioctl implements vfs.FileDescriptionImpl.
|
||||
// Ioctl implements vfs.FileDescriptionImpl.Ioctl.
|
||||
func (t *TTYFileDescription) Ioctl(ctx context.Context, io usermem.IO, args arch.SyscallArguments) (uintptr, error) {
|
||||
task := kernel.TaskFromContext(ctx)
|
||||
if task == nil {
|
||||
|
||||
Reference in New Issue
Block a user