mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Resolve remaining O_PATH TODOs.
O_PATH is now implemented in vfs2. Fixes #2782. PiperOrigin-RevId: 373861410
This commit is contained in:
@@ -961,7 +961,7 @@ func (d *dentry) open(ctx context.Context, rp *vfs.ResolvingPath, opts *vfs.Open
|
||||
}
|
||||
return &fd.vfsfd, nil
|
||||
case linux.S_IFLNK:
|
||||
// Can't open symlinks without O_PATH (which is unimplemented).
|
||||
// Can't open symlinks without O_PATH, which is handled at the VFS layer.
|
||||
return nil, syserror.ELOOP
|
||||
case linux.S_IFSOCK:
|
||||
if d.isSynthetic() {
|
||||
|
||||
@@ -465,7 +465,7 @@ func (d *dentry) open(ctx context.Context, rp *vfs.ResolvingPath, opts *vfs.Open
|
||||
}
|
||||
return &fd.vfsfd, nil
|
||||
case *symlink:
|
||||
// TODO(gvisor.dev/issue/2782): Can't open symlinks without O_PATH.
|
||||
// Can't open symlinks without O_PATH, which is handled at the VFS layer.
|
||||
return nil, syserror.ELOOP
|
||||
case *namedPipe:
|
||||
return impl.pipe.Open(ctx, rp.Mount(), &d.vfsd, opts.Flags, &d.inode.locks)
|
||||
|
||||
@@ -1299,6 +1299,11 @@ func (fd *fileDescription) ConfigureMMap(ctx context.Context, opts *memmap.MMapO
|
||||
return vfs.GenericConfigureMMap(&fd.vfsfd, fd, opts)
|
||||
}
|
||||
|
||||
// SupportsLocks implements vfs.FileDescriptionImpl.SupportsLocks.
|
||||
func (fd *fileDescription) SupportsLocks() bool {
|
||||
return fd.lowerFD.SupportsLocks()
|
||||
}
|
||||
|
||||
// LockBSD implements vfs.FileDescriptionImpl.LockBSD.
|
||||
func (fd *fileDescription) LockBSD(ctx context.Context, uid fslock.UniqueID, ownerPID int32, t fslock.LockType, block fslock.Blocker) error {
|
||||
return fd.lowerFD.LockBSD(ctx, ownerPID, t, block)
|
||||
|
||||
@@ -154,9 +154,11 @@ func (f *FDTable) drop(ctx context.Context, file *fs.File) {
|
||||
// dropVFS2 drops the table reference.
|
||||
func (f *FDTable) dropVFS2(ctx context.Context, file *vfs.FileDescription) {
|
||||
// Release any POSIX lock possibly held by the FDTable.
|
||||
err := file.UnlockPOSIX(ctx, f, lock.LockRange{0, lock.LockEOF})
|
||||
if err != nil && err != syserror.ENOLCK {
|
||||
panic(fmt.Sprintf("UnlockPOSIX failed: %v", err))
|
||||
if file.SupportsLocks() {
|
||||
err := file.UnlockPOSIX(ctx, f, lock.LockRange{0, lock.LockEOF})
|
||||
if err != nil && err != syserror.ENOLCK {
|
||||
panic(fmt.Sprintf("UnlockPOSIX failed: %v", err))
|
||||
}
|
||||
}
|
||||
|
||||
// Drop the table's reference.
|
||||
|
||||
@@ -454,6 +454,9 @@ type FileDescriptionImpl interface {
|
||||
// RemoveXattr removes the given extended attribute from the file.
|
||||
RemoveXattr(ctx context.Context, name string) error
|
||||
|
||||
// SupportsLocks indicates whether file locks are supported.
|
||||
SupportsLocks() bool
|
||||
|
||||
// LockBSD tries to acquire a BSD-style advisory file lock.
|
||||
LockBSD(ctx context.Context, uid lock.UniqueID, ownerPID int32, t lock.LockType, block lock.Blocker) error
|
||||
|
||||
@@ -818,6 +821,11 @@ func (fd *FileDescription) Msync(ctx context.Context, mr memmap.MappableRange) e
|
||||
return fd.Sync(ctx)
|
||||
}
|
||||
|
||||
// SupportsLocks indicates whether file locks are supported.
|
||||
func (fd *FileDescription) SupportsLocks() bool {
|
||||
return fd.impl.SupportsLocks()
|
||||
}
|
||||
|
||||
// LockBSD tries to acquire a BSD-style advisory file lock.
|
||||
func (fd *FileDescription) LockBSD(ctx context.Context, ownerPID int32, lockType lock.LockType, blocker lock.Blocker) error {
|
||||
atomic.StoreUint32(&fd.usedLockBSD, 1)
|
||||
|
||||
@@ -413,6 +413,11 @@ type LockFD struct {
|
||||
locks *FileLocks
|
||||
}
|
||||
|
||||
// SupportsLocks implements FileDescriptionImpl.SupportsLocks.
|
||||
func (LockFD) SupportsLocks() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Init initializes fd with FileLocks to use.
|
||||
func (fd *LockFD) Init(locks *FileLocks) {
|
||||
fd.locks = locks
|
||||
@@ -423,28 +428,28 @@ func (fd *LockFD) Locks() *FileLocks {
|
||||
return fd.locks
|
||||
}
|
||||
|
||||
// LockBSD implements vfs.FileDescriptionImpl.LockBSD.
|
||||
// LockBSD implements FileDescriptionImpl.LockBSD.
|
||||
func (fd *LockFD) LockBSD(ctx context.Context, uid fslock.UniqueID, ownerPID int32, t fslock.LockType, block fslock.Blocker) error {
|
||||
return fd.locks.LockBSD(ctx, uid, ownerPID, t, block)
|
||||
}
|
||||
|
||||
// UnlockBSD implements vfs.FileDescriptionImpl.UnlockBSD.
|
||||
// UnlockBSD implements FileDescriptionImpl.UnlockBSD.
|
||||
func (fd *LockFD) UnlockBSD(ctx context.Context, uid fslock.UniqueID) error {
|
||||
fd.locks.UnlockBSD(uid)
|
||||
return nil
|
||||
}
|
||||
|
||||
// LockPOSIX implements vfs.FileDescriptionImpl.LockPOSIX.
|
||||
// LockPOSIX implements FileDescriptionImpl.LockPOSIX.
|
||||
func (fd *LockFD) LockPOSIX(ctx context.Context, uid fslock.UniqueID, ownerPID int32, t fslock.LockType, r fslock.LockRange, block fslock.Blocker) error {
|
||||
return fd.locks.LockPOSIX(ctx, uid, ownerPID, t, r, block)
|
||||
}
|
||||
|
||||
// UnlockPOSIX implements vfs.FileDescriptionImpl.UnlockPOSIX.
|
||||
// UnlockPOSIX implements FileDescriptionImpl.UnlockPOSIX.
|
||||
func (fd *LockFD) UnlockPOSIX(ctx context.Context, uid fslock.UniqueID, r fslock.LockRange) error {
|
||||
return fd.locks.UnlockPOSIX(ctx, uid, r)
|
||||
}
|
||||
|
||||
// TestPOSIX implements vfs.FileDescriptionImpl.TestPOSIX.
|
||||
// TestPOSIX implements FileDescriptionImpl.TestPOSIX.
|
||||
func (fd *LockFD) TestPOSIX(ctx context.Context, uid fslock.UniqueID, t fslock.LockType, r fslock.LockRange) (linux.Flock, error) {
|
||||
return fd.locks.TestPOSIX(ctx, uid, t, r)
|
||||
}
|
||||
@@ -455,27 +460,68 @@ func (fd *LockFD) TestPOSIX(ctx context.Context, uid fslock.UniqueID, t fslock.L
|
||||
// +stateify savable
|
||||
type NoLockFD struct{}
|
||||
|
||||
// LockBSD implements vfs.FileDescriptionImpl.LockBSD.
|
||||
// SupportsLocks implements FileDescriptionImpl.SupportsLocks.
|
||||
func (NoLockFD) SupportsLocks() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// LockBSD implements FileDescriptionImpl.LockBSD.
|
||||
func (NoLockFD) LockBSD(ctx context.Context, uid fslock.UniqueID, ownerPID int32, t fslock.LockType, block fslock.Blocker) error {
|
||||
return syserror.ENOLCK
|
||||
}
|
||||
|
||||
// UnlockBSD implements vfs.FileDescriptionImpl.UnlockBSD.
|
||||
// UnlockBSD implements FileDescriptionImpl.UnlockBSD.
|
||||
func (NoLockFD) UnlockBSD(ctx context.Context, uid fslock.UniqueID) error {
|
||||
return syserror.ENOLCK
|
||||
}
|
||||
|
||||
// LockPOSIX implements vfs.FileDescriptionImpl.LockPOSIX.
|
||||
// LockPOSIX implements FileDescriptionImpl.LockPOSIX.
|
||||
func (NoLockFD) LockPOSIX(ctx context.Context, uid fslock.UniqueID, ownerPID int32, t fslock.LockType, r fslock.LockRange, block fslock.Blocker) error {
|
||||
return syserror.ENOLCK
|
||||
}
|
||||
|
||||
// UnlockPOSIX implements vfs.FileDescriptionImpl.UnlockPOSIX.
|
||||
// UnlockPOSIX implements FileDescriptionImpl.UnlockPOSIX.
|
||||
func (NoLockFD) UnlockPOSIX(ctx context.Context, uid fslock.UniqueID, r fslock.LockRange) error {
|
||||
return syserror.ENOLCK
|
||||
}
|
||||
|
||||
// TestPOSIX implements vfs.FileDescriptionImpl.TestPOSIX.
|
||||
// TestPOSIX implements FileDescriptionImpl.TestPOSIX.
|
||||
func (NoLockFD) TestPOSIX(ctx context.Context, uid fslock.UniqueID, t fslock.LockType, r fslock.LockRange) (linux.Flock, error) {
|
||||
return linux.Flock{}, syserror.ENOLCK
|
||||
}
|
||||
|
||||
// BadLockFD implements Lock*/Unlock* portion of FileDescriptionImpl interface
|
||||
// returning EBADF.
|
||||
//
|
||||
// +stateify savable
|
||||
type BadLockFD struct{}
|
||||
|
||||
// SupportsLocks implements FileDescriptionImpl.SupportsLocks.
|
||||
func (BadLockFD) SupportsLocks() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// LockBSD implements FileDescriptionImpl.LockBSD.
|
||||
func (BadLockFD) LockBSD(ctx context.Context, uid fslock.UniqueID, ownerPID int32, t fslock.LockType, block fslock.Blocker) error {
|
||||
return syserror.EBADF
|
||||
}
|
||||
|
||||
// UnlockBSD implements FileDescriptionImpl.UnlockBSD.
|
||||
func (BadLockFD) UnlockBSD(ctx context.Context, uid fslock.UniqueID) error {
|
||||
return syserror.EBADF
|
||||
}
|
||||
|
||||
// LockPOSIX implements FileDescriptionImpl.LockPOSIX.
|
||||
func (BadLockFD) LockPOSIX(ctx context.Context, uid fslock.UniqueID, ownerPID int32, t fslock.LockType, r fslock.LockRange, block fslock.Blocker) error {
|
||||
return syserror.EBADF
|
||||
}
|
||||
|
||||
// UnlockPOSIX implements FileDescriptionImpl.UnlockPOSIX.
|
||||
func (BadLockFD) UnlockPOSIX(ctx context.Context, uid fslock.UniqueID, r fslock.LockRange) error {
|
||||
return syserror.EBADF
|
||||
}
|
||||
|
||||
// TestPOSIX implements FileDescriptionImpl.TestPOSIX.
|
||||
func (BadLockFD) TestPOSIX(ctx context.Context, uid fslock.UniqueID, t fslock.LockType, r fslock.LockRange) (linux.Flock, error) {
|
||||
return linux.Flock{}, syserror.EBADF
|
||||
}
|
||||
|
||||
+19
-19
@@ -24,96 +24,96 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/usermem"
|
||||
)
|
||||
|
||||
// opathFD implements vfs.FileDescriptionImpl for a file description opened with O_PATH.
|
||||
// opathFD implements FileDescriptionImpl for a file description opened with O_PATH.
|
||||
//
|
||||
// +stateify savable
|
||||
type opathFD struct {
|
||||
vfsfd FileDescription
|
||||
FileDescriptionDefaultImpl
|
||||
NoLockFD
|
||||
BadLockFD
|
||||
}
|
||||
|
||||
// Release implements vfs.FileDescriptionImpl.Release.
|
||||
// Release implements FileDescriptionImpl.Release.
|
||||
func (fd *opathFD) Release(context.Context) {
|
||||
// noop
|
||||
}
|
||||
|
||||
// Allocate implements vfs.FileDescriptionImpl.Allocate.
|
||||
// Allocate implements FileDescriptionImpl.Allocate.
|
||||
func (fd *opathFD) Allocate(ctx context.Context, mode, offset, length uint64) error {
|
||||
return syserror.EBADF
|
||||
}
|
||||
|
||||
// PRead implements vfs.FileDescriptionImpl.PRead.
|
||||
// PRead implements FileDescriptionImpl.PRead.
|
||||
func (fd *opathFD) PRead(ctx context.Context, dst usermem.IOSequence, offset int64, opts ReadOptions) (int64, error) {
|
||||
return 0, syserror.EBADF
|
||||
}
|
||||
|
||||
// Read implements vfs.FileDescriptionImpl.Read.
|
||||
// Read implements FileDescriptionImpl.Read.
|
||||
func (fd *opathFD) Read(ctx context.Context, dst usermem.IOSequence, opts ReadOptions) (int64, error) {
|
||||
return 0, syserror.EBADF
|
||||
}
|
||||
|
||||
// PWrite implements vfs.FileDescriptionImpl.PWrite.
|
||||
// PWrite implements FileDescriptionImpl.PWrite.
|
||||
func (fd *opathFD) PWrite(ctx context.Context, src usermem.IOSequence, offset int64, opts WriteOptions) (int64, error) {
|
||||
return 0, syserror.EBADF
|
||||
}
|
||||
|
||||
// Write implements vfs.FileDescriptionImpl.Write.
|
||||
// Write implements FileDescriptionImpl.Write.
|
||||
func (fd *opathFD) Write(ctx context.Context, src usermem.IOSequence, opts WriteOptions) (int64, error) {
|
||||
return 0, syserror.EBADF
|
||||
}
|
||||
|
||||
// Ioctl implements vfs.FileDescriptionImpl.Ioctl.
|
||||
// Ioctl implements FileDescriptionImpl.Ioctl.
|
||||
func (fd *opathFD) Ioctl(ctx context.Context, uio usermem.IO, args arch.SyscallArguments) (uintptr, error) {
|
||||
return 0, syserror.EBADF
|
||||
}
|
||||
|
||||
// IterDirents implements vfs.FileDescriptionImpl.IterDirents.
|
||||
// IterDirents implements FileDescriptionImpl.IterDirents.
|
||||
func (fd *opathFD) IterDirents(ctx context.Context, cb IterDirentsCallback) error {
|
||||
return syserror.EBADF
|
||||
}
|
||||
|
||||
// Seek implements vfs.FileDescriptionImpl.Seek.
|
||||
// Seek implements FileDescriptionImpl.Seek.
|
||||
func (fd *opathFD) Seek(ctx context.Context, offset int64, whence int32) (int64, error) {
|
||||
return 0, syserror.EBADF
|
||||
}
|
||||
|
||||
// ConfigureMMap implements vfs.FileDescriptionImpl.ConfigureMMap.
|
||||
// ConfigureMMap implements FileDescriptionImpl.ConfigureMMap.
|
||||
func (fd *opathFD) ConfigureMMap(ctx context.Context, opts *memmap.MMapOpts) error {
|
||||
return syserror.EBADF
|
||||
}
|
||||
|
||||
// ListXattr implements vfs.FileDescriptionImpl.ListXattr.
|
||||
// ListXattr implements FileDescriptionImpl.ListXattr.
|
||||
func (fd *opathFD) ListXattr(ctx context.Context, size uint64) ([]string, error) {
|
||||
return nil, syserror.EBADF
|
||||
}
|
||||
|
||||
// GetXattr implements vfs.FileDescriptionImpl.GetXattr.
|
||||
// GetXattr implements FileDescriptionImpl.GetXattr.
|
||||
func (fd *opathFD) GetXattr(ctx context.Context, opts GetXattrOptions) (string, error) {
|
||||
return "", syserror.EBADF
|
||||
}
|
||||
|
||||
// SetXattr implements vfs.FileDescriptionImpl.SetXattr.
|
||||
// SetXattr implements FileDescriptionImpl.SetXattr.
|
||||
func (fd *opathFD) SetXattr(ctx context.Context, opts SetXattrOptions) error {
|
||||
return syserror.EBADF
|
||||
}
|
||||
|
||||
// RemoveXattr implements vfs.FileDescriptionImpl.RemoveXattr.
|
||||
// RemoveXattr implements FileDescriptionImpl.RemoveXattr.
|
||||
func (fd *opathFD) RemoveXattr(ctx context.Context, name string) error {
|
||||
return syserror.EBADF
|
||||
}
|
||||
|
||||
// Sync implements vfs.FileDescriptionImpl.Sync.
|
||||
// Sync implements FileDescriptionImpl.Sync.
|
||||
func (fd *opathFD) Sync(ctx context.Context) error {
|
||||
return syserror.EBADF
|
||||
}
|
||||
|
||||
// SetStat implements vfs.FileDescriptionImpl.SetStat.
|
||||
// SetStat implements FileDescriptionImpl.SetStat.
|
||||
func (fd *opathFD) SetStat(ctx context.Context, opts SetStatOptions) error {
|
||||
return syserror.EBADF
|
||||
}
|
||||
|
||||
// Stat implements vfs.FileDescriptionImpl.Stat.
|
||||
// Stat implements FileDescriptionImpl.Stat.
|
||||
func (fd *opathFD) Stat(ctx context.Context, opts StatOptions) (linux.Statx, error) {
|
||||
vfsObj := fd.vfsfd.vd.mount.vfs
|
||||
rp := vfsObj.getResolvingPath(auth.CredentialsFromContext(ctx), &PathOperation{
|
||||
|
||||
@@ -657,7 +657,6 @@ func (c *containerMounter) mountTmpVFS2(ctx context.Context, conf *config.Config
|
||||
Start: root,
|
||||
Path: fspath.Parse("/tmp"),
|
||||
}
|
||||
// TODO(gvisor.dev/issue/2782): Use O_PATH when available.
|
||||
fd, err := c.k.VFS().OpenAt(ctx, creds, &pop, &vfs.OpenOptions{Flags: linux.O_RDONLY | linux.O_DIRECTORY})
|
||||
switch err {
|
||||
case nil:
|
||||
|
||||
@@ -390,9 +390,7 @@ TEST_F(FcntlLockTest, SetLockDir) {
|
||||
}
|
||||
|
||||
TEST_F(FcntlLockTest, SetLockSymlink) {
|
||||
// TODO(gvisor.dev/issue/2782): Replace with IsRunningWithVFS1() when O_PATH
|
||||
// is supported.
|
||||
SKIP_IF(IsRunningOnGvisor());
|
||||
SKIP_IF(IsRunningWithVFS1());
|
||||
|
||||
auto file = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFile());
|
||||
auto symlink = ASSERT_NO_ERRNO_AND_VALUE(
|
||||
|
||||
@@ -662,9 +662,7 @@ TEST(FlockTestNoFixture, FlockDir) {
|
||||
}
|
||||
|
||||
TEST(FlockTestNoFixture, FlockSymlink) {
|
||||
// TODO(gvisor.dev/issue/2782): Replace with IsRunningWithVFS1() when O_PATH
|
||||
// is supported.
|
||||
SKIP_IF(IsRunningOnGvisor());
|
||||
SKIP_IF(IsRunningWithVFS1());
|
||||
|
||||
auto file = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFile());
|
||||
auto symlink = ASSERT_NO_ERRNO_AND_VALUE(
|
||||
|
||||
Reference in New Issue
Block a user