mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Clean up vfs2 fallocate.
Move to setstat.go and add a FileDescription wrapper method. PiperOrigin-RevId: 324165277
This commit is contained in:
@@ -18,7 +18,6 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/abi/linux"
|
||||
"gvisor.dev/gvisor/pkg/sentry/arch"
|
||||
"gvisor.dev/gvisor/pkg/sentry/kernel"
|
||||
"gvisor.dev/gvisor/pkg/sentry/limits"
|
||||
"gvisor.dev/gvisor/pkg/sentry/vfs"
|
||||
"gvisor.dev/gvisor/pkg/syserror"
|
||||
"gvisor.dev/gvisor/pkg/usermem"
|
||||
@@ -245,55 +244,6 @@ func renameat(t *kernel.Task, olddirfd int32, oldpathAddr usermem.Addr, newdirfd
|
||||
})
|
||||
}
|
||||
|
||||
// Fallocate implements linux system call fallocate(2).
|
||||
func Fallocate(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) {
|
||||
fd := args[0].Int()
|
||||
mode := args[1].Uint64()
|
||||
offset := args[2].Int64()
|
||||
length := args[3].Int64()
|
||||
|
||||
file := t.GetFileVFS2(fd)
|
||||
|
||||
if file == nil {
|
||||
return 0, nil, syserror.EBADF
|
||||
}
|
||||
defer file.DecRef()
|
||||
|
||||
if !file.IsWritable() {
|
||||
return 0, nil, syserror.EBADF
|
||||
}
|
||||
|
||||
if mode != 0 {
|
||||
return 0, nil, syserror.ENOTSUP
|
||||
}
|
||||
|
||||
if offset < 0 || length <= 0 {
|
||||
return 0, nil, syserror.EINVAL
|
||||
}
|
||||
|
||||
size := offset + length
|
||||
|
||||
if size < 0 {
|
||||
return 0, nil, syserror.EFBIG
|
||||
}
|
||||
|
||||
limit := limits.FromContext(t).Get(limits.FileSize).Cur
|
||||
|
||||
if uint64(size) >= limit {
|
||||
t.SendSignal(&arch.SignalInfo{
|
||||
Signo: int32(linux.SIGXFSZ),
|
||||
Code: arch.SignalInfoUser,
|
||||
})
|
||||
return 0, nil, syserror.EFBIG
|
||||
}
|
||||
|
||||
return 0, nil, file.Impl().Allocate(t, mode, uint64(offset), uint64(length))
|
||||
|
||||
// File length modified, generate notification.
|
||||
// TODO(gvisor.dev/issue/1479): Reenable when Inotify is ported.
|
||||
// file.Dirent.InotifyEvent(linux.IN_MODIFY, 0)
|
||||
}
|
||||
|
||||
// Rmdir implements Linux syscall rmdir(2).
|
||||
func Rmdir(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) {
|
||||
pathAddr := args[0].Pointer()
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/sentry/arch"
|
||||
"gvisor.dev/gvisor/pkg/sentry/kernel"
|
||||
"gvisor.dev/gvisor/pkg/sentry/kernel/auth"
|
||||
"gvisor.dev/gvisor/pkg/sentry/limits"
|
||||
"gvisor.dev/gvisor/pkg/sentry/vfs"
|
||||
"gvisor.dev/gvisor/pkg/syserror"
|
||||
"gvisor.dev/gvisor/pkg/usermem"
|
||||
@@ -211,6 +212,55 @@ func Ftruncate(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.Sys
|
||||
return 0, nil, handleSetSizeError(t, err)
|
||||
}
|
||||
|
||||
// Fallocate implements linux system call fallocate(2).
|
||||
func Fallocate(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) {
|
||||
fd := args[0].Int()
|
||||
mode := args[1].Uint64()
|
||||
offset := args[2].Int64()
|
||||
length := args[3].Int64()
|
||||
|
||||
file := t.GetFileVFS2(fd)
|
||||
|
||||
if file == nil {
|
||||
return 0, nil, syserror.EBADF
|
||||
}
|
||||
defer file.DecRef()
|
||||
|
||||
if !file.IsWritable() {
|
||||
return 0, nil, syserror.EBADF
|
||||
}
|
||||
|
||||
if mode != 0 {
|
||||
return 0, nil, syserror.ENOTSUP
|
||||
}
|
||||
|
||||
if offset < 0 || length <= 0 {
|
||||
return 0, nil, syserror.EINVAL
|
||||
}
|
||||
|
||||
size := offset + length
|
||||
|
||||
if size < 0 {
|
||||
return 0, nil, syserror.EFBIG
|
||||
}
|
||||
|
||||
limit := limits.FromContext(t).Get(limits.FileSize).Cur
|
||||
|
||||
if uint64(size) >= limit {
|
||||
t.SendSignal(&arch.SignalInfo{
|
||||
Signo: int32(linux.SIGXFSZ),
|
||||
Code: arch.SignalInfoUser,
|
||||
})
|
||||
return 0, nil, syserror.EFBIG
|
||||
}
|
||||
|
||||
return 0, nil, file.Allocate(t, mode, uint64(offset), uint64(length))
|
||||
|
||||
// File length modified, generate notification.
|
||||
// TODO(gvisor.dev/issue/1479): Reenable when Inotify is ported.
|
||||
// file.Dirent.InotifyEvent(linux.IN_MODIFY, 0)
|
||||
}
|
||||
|
||||
// Utime implements Linux syscall utime(2).
|
||||
func Utime(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) {
|
||||
pathAddr := args[0].Pointer()
|
||||
|
||||
@@ -354,7 +354,7 @@ type FileDescriptionImpl interface {
|
||||
// represented by the FileDescription.
|
||||
StatFS(ctx context.Context) (linux.Statfs, error)
|
||||
|
||||
// Allocate grows file represented by FileDescription to offset + length bytes.
|
||||
// Allocate grows the file to offset + length bytes.
|
||||
// Only mode == 0 is supported currently.
|
||||
Allocate(ctx context.Context, mode, offset, length uint64) error
|
||||
|
||||
@@ -563,6 +563,11 @@ func (fd *FileDescription) StatFS(ctx context.Context) (linux.Statfs, error) {
|
||||
return fd.impl.StatFS(ctx)
|
||||
}
|
||||
|
||||
// Allocate grows file represented by FileDescription to offset + length bytes.
|
||||
func (fd *FileDescription) Allocate(ctx context.Context, mode, offset, length uint64) error {
|
||||
return fd.impl.Allocate(ctx, mode, offset, length)
|
||||
}
|
||||
|
||||
// Readiness implements waiter.Waitable.Readiness.
|
||||
//
|
||||
// It returns fd's I/O readiness.
|
||||
|
||||
Reference in New Issue
Block a user