[syserror] Update several syserror errors to linuxerr equivalents.

Update/remove most syserror errors to linuxerr equivalents. For list
of removed errors, see //pkg/syserror/syserror.go.

PiperOrigin-RevId: 382574582
This commit is contained in:
Zach Koopmans
2021-07-01 12:05:19 -07:00
committed by gVisor bot
parent 07ffecef83
commit 590b8d3e99
116 changed files with 383 additions and 416 deletions
+2
View File
@@ -166,6 +166,8 @@ var (
EWOULDBLOCK = EAGAIN
EDEADLOCK = EDEADLK
ENONET = ENOENT
ENOATTR = ENODATA
ENOTSUP = EOPNOTSUPP
)
// A nil *errors.Error denotes no error and is placed at the 0 index of
+2 -2
View File
@@ -69,7 +69,7 @@ func BenchmarkCompareLinuxerr(b *testing.B) {
}
func BenchmarkCompareSyserror(b *testing.B) {
globalError = syserror.EAGAIN
globalError = linuxerr.EAGAIN
j := 0
for i := b.N; i > 0; i-- {
if globalError == linuxerr.EACCES {
@@ -117,7 +117,7 @@ func BenchmarkSwitchSyserror(b *testing.B) {
j++
case syserror.EINTR:
j += 2
case syserror.EAGAIN:
case linuxerr.EAGAIN:
j += 3
}
}
+1 -1
View File
@@ -12,13 +12,13 @@ go_library(
visibility = ["//:sandbox"],
deps = [
":eventchannel_go_proto",
"//pkg/errors/linuxerr",
"//pkg/log",
"//pkg/sync",
"//pkg/unet",
"@org_golang_google_protobuf//encoding/prototext:go_default_library",
"@org_golang_google_protobuf//proto:go_default_library",
"@org_golang_google_protobuf//types/known/anypb:go_default_library",
"@org_golang_x_sys//unix:go_default_library",
"@org_golang_x_time//rate:go_default_library",
],
)
+2 -2
View File
@@ -23,9 +23,9 @@ import (
"encoding/binary"
"fmt"
"golang.org/x/sys/unix"
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/proto"
"gvisor.dev/gvisor/pkg/errors/linuxerr"
pb "gvisor.dev/gvisor/pkg/eventchannel/eventchannel_go_proto"
"gvisor.dev/gvisor/pkg/log"
"gvisor.dev/gvisor/pkg/sync"
@@ -155,7 +155,7 @@ func (s *socketEmitter) Emit(msg proto.Message) (bool, error) {
for done := 0; done < len(p); {
n, err := s.socket.Write(p[done:])
if err != nil {
return (err == unix.EPIPE), err
return linuxerr.Equals(linuxerr.EPIPE, err), err
}
done += n
}
-1
View File
@@ -117,7 +117,6 @@ go_test(
"//pkg/sentry/fs/tmpfs",
"//pkg/sentry/kernel/contexttest",
"//pkg/sync",
"//pkg/syserror",
"//pkg/usermem",
],
)
+1 -1
View File
@@ -1375,7 +1375,7 @@ func (d *Dirent) mayDelete(ctx context.Context, victim *Dirent) error {
}
if victim.IsRoot() {
return syserror.EBUSY
return linuxerr.EBUSY
}
return nil
+1
View File
@@ -39,6 +39,7 @@ go_test(
library = ":fdpipe",
deps = [
"//pkg/context",
"//pkg/errors",
"//pkg/errors/linuxerr",
"//pkg/fd",
"//pkg/fdnotifier",
+3 -3
View File
@@ -25,8 +25,8 @@ import (
"github.com/google/uuid"
"golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/context"
"gvisor.dev/gvisor/pkg/errors/linuxerr"
"gvisor.dev/gvisor/pkg/fd"
"gvisor.dev/gvisor/pkg/sentry/contexttest"
"gvisor.dev/gvisor/pkg/sentry/fs"
@@ -515,8 +515,8 @@ func assertReaderHungup(t *testing.T, desc string, reader io.Reader) bool {
}
func assertWriterHungup(t *testing.T, desc string, writer io.Writer) bool {
if _, err := writer.Write([]byte("hello")); unwrapError(err) != unix.EPIPE {
t.Errorf("%s: write to self after hangup got error %v, want %v", desc, err, unix.EPIPE)
if _, err := writer.Write([]byte("hello")); !linuxerr.Equals(linuxerr.EPIPE, unwrapError(err)) {
t.Errorf("%s: write to self after hangup got error %v, want %v", desc, err, linuxerr.EPIPE)
return false
}
return true
+9 -4
View File
@@ -21,6 +21,7 @@ import (
"testing"
"golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/errors"
"gvisor.dev/gvisor/pkg/errors/linuxerr"
"gvisor.dev/gvisor/pkg/fd"
"gvisor.dev/gvisor/pkg/fdnotifier"
@@ -209,7 +210,7 @@ func TestPipeRequest(t *testing.T) {
{
desc: "ReadDir on pipe returns ENOTDIR",
context: &ReadDir{},
err: unix.ENOTDIR,
err: linuxerr.ENOTDIR,
},
{
desc: "Fsync on pipe returns EINVAL",
@@ -219,7 +220,7 @@ func TestPipeRequest(t *testing.T) {
{
desc: "Seek on pipe returns ESPIPE",
context: &Seek{},
err: unix.ESPIPE,
err: linuxerr.ESPIPE,
},
{
desc: "Readv on pipe from empty buffer returns nil",
@@ -248,7 +249,7 @@ func TestPipeRequest(t *testing.T) {
desc: "Writev on pipe from non-empty buffer and closed partner returns EPIPE",
context: &Writev{Src: usermem.BytesIOSequence([]byte("hello"))},
flags: fs.FileFlags{Write: true},
err: unix.EPIPE,
err: linuxerr.EPIPE,
},
{
desc: "Writev on pipe from non-empty buffer and open partner succeeds",
@@ -307,7 +308,11 @@ func TestPipeRequest(t *testing.T) {
t.Errorf("%s: unknown request type %T", test.desc, test.context)
}
if unwrapError(err) != test.err {
if linuxErr, ok := test.err.(*errors.Error); ok {
if !linuxerr.Equals(linuxErr, unwrapError(err)) {
t.Errorf("%s: got error %v, want %v", test.desc, err, test.err)
}
} else if test.err != unwrapError(err) {
t.Errorf("%s: got error %v, want %v", test.desc, err, test.err)
}
}
+1 -1
View File
@@ -358,7 +358,7 @@ func (*overlayFileOperations) ConfigureMMap(ctx context.Context, file *File, opt
}
if !o.isMappableLocked() {
return syserror.ENODEV
return linuxerr.ENODEV
}
// FIXME(jamieliu): This is a copy/paste of fsutil.GenericConfigureMMap,
+3 -3
View File
@@ -46,7 +46,7 @@ func SeekWithDirCursor(ctx context.Context, file *fs.File, whence fs.SeekWhence,
// Does the Inode represents a non-seekable type?
if fs.IsPipe(inode.StableAttr) || fs.IsSocket(inode.StableAttr) {
return current, syserror.ESPIPE
return current, linuxerr.ESPIPE
}
// Does the Inode represent a character device?
@@ -162,7 +162,7 @@ type FilePipeSeek struct{}
// Seek implements fs.FileOperations.Seek.
func (FilePipeSeek) Seek(context.Context, *fs.File, fs.SeekWhence, int64) (int64, error) {
return 0, syserror.ESPIPE
return 0, linuxerr.ESPIPE
}
// FileNotDirReaddir implements fs.FileOperations.Readdir for non-directories.
@@ -205,7 +205,7 @@ type FileNoMMap struct{}
// ConfigureMMap implements fs.FileOperations.ConfigureMMap.
func (FileNoMMap) ConfigureMMap(context.Context, *fs.File, *memmap.MMapOpts) error {
return syserror.ENODEV
return linuxerr.ENODEV
}
// GenericConfigureMMap implements fs.FileOperations.ConfigureMMap for most
+6 -6
View File
@@ -219,7 +219,7 @@ func (i *InodeSimpleExtendedAttributes) GetXattr(_ context.Context, _ *fs.Inode,
value, ok := i.xattrs[name]
i.mu.RUnlock()
if !ok {
return "", syserror.ENOATTR
return "", linuxerr.ENOATTR
}
return value, nil
}
@@ -230,7 +230,7 @@ func (i *InodeSimpleExtendedAttributes) SetXattr(_ context.Context, _ *fs.Inode,
defer i.mu.Unlock()
if i.xattrs == nil {
if flags&linux.XATTR_REPLACE != 0 {
return syserror.ENODATA
return linuxerr.ENODATA
}
i.xattrs = make(map[string]string)
}
@@ -240,7 +240,7 @@ func (i *InodeSimpleExtendedAttributes) SetXattr(_ context.Context, _ *fs.Inode,
return syserror.EEXIST
}
if !ok && flags&linux.XATTR_REPLACE != 0 {
return syserror.ENODATA
return linuxerr.ENODATA
}
i.xattrs[name] = value
@@ -266,7 +266,7 @@ func (i *InodeSimpleExtendedAttributes) RemoveXattr(_ context.Context, _ *fs.Ino
delete(i.xattrs, name)
return nil
}
return syserror.ENOATTR
return linuxerr.ENOATTR
}
// staticFile is a file with static contents. It is returned by
@@ -449,12 +449,12 @@ type InodeNotSymlink struct{}
// Readlink implements fs.InodeOperations.Readlink.
func (InodeNotSymlink) Readlink(context.Context, *fs.Inode) (string, error) {
return "", syserror.ENOLINK
return "", linuxerr.ENOLINK
}
// Getlink implements fs.InodeOperations.Getlink.
func (InodeNotSymlink) Getlink(context.Context, *fs.Inode) (*fs.Dirent, error) {
return nil, syserror.ENOLINK
return nil, linuxerr.ENOLINK
}
// InodeNoExtendedAttributes can be used by Inodes that do not support
+4 -3
View File
@@ -20,6 +20,7 @@ import (
"golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/abi/linux"
"gvisor.dev/gvisor/pkg/context"
"gvisor.dev/gvisor/pkg/errors/linuxerr"
"gvisor.dev/gvisor/pkg/fd"
"gvisor.dev/gvisor/pkg/log"
"gvisor.dev/gvisor/pkg/p9"
@@ -476,7 +477,7 @@ func (i *inodeOperations) GetFile(ctx context.Context, d *fs.Dirent, flags fs.Fi
switch d.Inode.StableAttr.Type {
case fs.Socket:
if i.session().overrides != nil {
return nil, syserror.ENXIO
return nil, linuxerr.ENXIO
}
return i.getFileSocket(ctx, d, flags)
case fs.Pipe:
@@ -676,7 +677,7 @@ func (i *inodeOperations) Readlink(ctx context.Context, inode *fs.Inode) (string
// Getlink implementfs fs.InodeOperations.Getlink.
func (i *inodeOperations) Getlink(context.Context, *fs.Inode) (*fs.Dirent, error) {
if !fs.IsSymlink(i.fileState.sattr) {
return nil, syserror.ENOLINK
return nil, linuxerr.ENOLINK
}
return nil, fs.ErrResolveViaReadlink
}
@@ -714,7 +715,7 @@ func (i *inodeOperations) configureMMap(file *fs.File, opts *memmap.MMapOpts) er
if i.fileState.hostMappable != nil {
return fsutil.GenericConfigureMMap(file, i.fileState.hostMappable, opts)
}
return syserror.ENODEV
return linuxerr.ENODEV
}
func init() {
+12 -12
View File
@@ -44,7 +44,7 @@ func changeType(mode p9.FileMode, newType p9.FileMode) p9.FileMode {
// policy.
func (i *inodeOperations) Lookup(ctx context.Context, dir *fs.Inode, name string) (*fs.Dirent, error) {
if len(name) > maxFilenameLen {
return nil, syserror.ENAMETOOLONG
return nil, linuxerr.ENAMETOOLONG
}
cp := i.session().cachePolicy
@@ -107,7 +107,7 @@ func (i *inodeOperations) Lookup(ctx context.Context, dir *fs.Inode, name string
// Ownership is currently ignored.
func (i *inodeOperations) Create(ctx context.Context, dir *fs.Inode, name string, flags fs.FileFlags, perm fs.FilePermissions) (*fs.File, error) {
if len(name) > maxFilenameLen {
return nil, syserror.ENAMETOOLONG
return nil, linuxerr.ENAMETOOLONG
}
// Create replaces the directory fid with the newly created/opened
@@ -196,7 +196,7 @@ func (i *inodeOperations) Create(ctx context.Context, dir *fs.Inode, name string
// CreateLink uses Create to create a symlink between oldname and newname.
func (i *inodeOperations) CreateLink(ctx context.Context, dir *fs.Inode, oldname string, newname string) error {
if len(newname) > maxFilenameLen {
return syserror.ENAMETOOLONG
return linuxerr.ENAMETOOLONG
}
owner := fs.FileOwnerFromContext(ctx)
@@ -210,12 +210,12 @@ func (i *inodeOperations) CreateLink(ctx context.Context, dir *fs.Inode, oldname
// CreateHardLink implements InodeOperations.CreateHardLink.
func (i *inodeOperations) CreateHardLink(ctx context.Context, inode *fs.Inode, target *fs.Inode, newName string) error {
if len(newName) > maxFilenameLen {
return syserror.ENAMETOOLONG
return linuxerr.ENAMETOOLONG
}
targetOpts, ok := target.InodeOperations.(*inodeOperations)
if !ok {
return syserror.EXDEV
return linuxerr.EXDEV
}
if err := i.fileState.file.link(ctx, &targetOpts.fileState.file, newName); err != nil {
@@ -232,7 +232,7 @@ func (i *inodeOperations) CreateHardLink(ctx context.Context, inode *fs.Inode, t
// CreateDirectory uses Create to create a directory named s under inodeOperations.
func (i *inodeOperations) CreateDirectory(ctx context.Context, dir *fs.Inode, s string, perm fs.FilePermissions) error {
if len(s) > maxFilenameLen {
return syserror.ENAMETOOLONG
return linuxerr.ENAMETOOLONG
}
// If the parent directory has setgid enabled, change the new directory's
@@ -266,7 +266,7 @@ func (i *inodeOperations) CreateDirectory(ctx context.Context, dir *fs.Inode, s
// Bind implements InodeOperations.Bind.
func (i *inodeOperations) Bind(ctx context.Context, dir *fs.Inode, name string, ep transport.BoundEndpoint, perm fs.FilePermissions) (*fs.Dirent, error) {
if len(name) > maxFilenameLen {
return nil, syserror.ENAMETOOLONG
return nil, linuxerr.ENAMETOOLONG
}
if i.session().overrides == nil {
@@ -291,7 +291,7 @@ func (i *inodeOperations) Bind(ctx context.Context, dir *fs.Inode, name string,
// CreateFifo implements fs.InodeOperations.CreateFifo.
func (i *inodeOperations) CreateFifo(ctx context.Context, dir *fs.Inode, name string, perm fs.FilePermissions) error {
if len(name) > maxFilenameLen {
return syserror.ENAMETOOLONG
return linuxerr.ENAMETOOLONG
}
owner := fs.FileOwnerFromContext(ctx)
@@ -383,7 +383,7 @@ func (i *inodeOperations) createEndpointFile(ctx context.Context, dir *fs.Inode,
// Remove implements InodeOperations.Remove.
func (i *inodeOperations) Remove(ctx context.Context, dir *fs.Inode, name string) error {
if len(name) > maxFilenameLen {
return syserror.ENAMETOOLONG
return linuxerr.ENAMETOOLONG
}
var key *device.MultiDeviceKey
@@ -422,7 +422,7 @@ func (i *inodeOperations) Remove(ctx context.Context, dir *fs.Inode, name string
// Remove implements InodeOperations.RemoveDirectory.
func (i *inodeOperations) RemoveDirectory(ctx context.Context, dir *fs.Inode, name string) error {
if len(name) > maxFilenameLen {
return syserror.ENAMETOOLONG
return linuxerr.ENAMETOOLONG
}
// 0x200 = AT_REMOVEDIR.
@@ -443,12 +443,12 @@ func (i *inodeOperations) RemoveDirectory(ctx context.Context, dir *fs.Inode, na
// Rename renames this node.
func (i *inodeOperations) Rename(ctx context.Context, inode *fs.Inode, oldParent *fs.Inode, oldName string, newParent *fs.Inode, newName string, replacement bool) error {
if len(newName) > maxFilenameLen {
return syserror.ENAMETOOLONG
return linuxerr.ENAMETOOLONG
}
// Don't allow renames across different mounts.
if newParent.MountSource != oldParent.MountSource {
return syserror.EXDEV
return linuxerr.EXDEV
}
// Unwrap the new parent to a *inodeOperations.
+2 -1
View File
@@ -19,6 +19,7 @@ import (
"golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/context"
"gvisor.dev/gvisor/pkg/errors/linuxerr"
"gvisor.dev/gvisor/pkg/fd"
"gvisor.dev/gvisor/pkg/fdnotifier"
"gvisor.dev/gvisor/pkg/log"
@@ -268,7 +269,7 @@ func (f *fileOperations) Flush(context.Context, *fs.File) error {
// ConfigureMMap implements fs.FileOperations.ConfigureMMap.
func (f *fileOperations) ConfigureMMap(ctx context.Context, file *fs.File, opts *memmap.MMapOpts) error {
if !canMap(file.Dirent.Inode) {
return syserror.ENODEV
return linuxerr.ENODEV
}
return fsutil.GenericConfigureMMap(file, f.iops.cachingInodeOps, opts)
}
+2 -2
View File
@@ -277,7 +277,7 @@ func (i *inodeOperations) BoundEndpoint(inode *fs.Inode, path string) transport.
// GetFile implements fs.InodeOperations.GetFile.
func (i *inodeOperations) GetFile(ctx context.Context, d *fs.Dirent, flags fs.FileFlags) (*fs.File, error) {
if fs.IsSocket(d.Inode.StableAttr) {
return nil, syserror.ENXIO
return nil, linuxerr.ENXIO
}
return newFile(ctx, d, flags, i), nil
@@ -393,7 +393,7 @@ func (i *inodeOperations) Readlink(ctx context.Context, inode *fs.Inode) (string
// Getlink implements fs.InodeOperations.Getlink.
func (i *inodeOperations) Getlink(context.Context, *fs.Inode) (*fs.Dirent, error) {
if !fs.IsSymlink(i.fileState.sattr) {
return nil, syserror.ENOLINK
return nil, linuxerr.ENOLINK
}
return nil, fs.ErrResolveViaReadlink
}
+1 -2
View File
@@ -32,7 +32,6 @@ import (
"gvisor.dev/gvisor/pkg/sentry/uniqueid"
"gvisor.dev/gvisor/pkg/sync"
"gvisor.dev/gvisor/pkg/syserr"
"gvisor.dev/gvisor/pkg/syserror"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/unet"
"gvisor.dev/gvisor/pkg/waiter"
@@ -212,7 +211,7 @@ func (c *ConnectedEndpoint) Send(ctx context.Context, data [][]byte, controlMess
if n < totalLen && err == nil {
// The host only returns a short write if it would otherwise
// block (and only for stream sockets).
err = syserror.EAGAIN
err = linuxerr.EAGAIN
}
if n > 0 && !linuxerr.Equals(linuxerr.EAGAIN, err) {
// The caller may need to block to send more data, but
+3 -3
View File
@@ -16,8 +16,8 @@ package host
import (
"golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/errors/linuxerr"
"gvisor.dev/gvisor/pkg/sentry/hostfd"
"gvisor.dev/gvisor/pkg/syserror"
)
// LINT.IfChange
@@ -66,9 +66,9 @@ func buildIovec(bufs [][]byte, maxlen int64, truncate bool) (length int64, iovec
if length > maxlen {
if truncate {
stopLen = maxlen
err = syserror.EAGAIN
err = linuxerr.EAGAIN
} else {
return 0, nil, nil, syserror.EMSGSIZE
return 0, nil, nil, linuxerr.EMSGSIZE
}
}
+2 -2
View File
@@ -299,7 +299,7 @@ func (i *Inode) RemoveXattr(ctx context.Context, d *Dirent, name string) error {
func (i *Inode) CheckPermission(ctx context.Context, p PermMask) error {
// First check the outer-most mounted filesystem.
if p.Write && i.MountSource.Flags.ReadOnly {
return syserror.EROFS
return linuxerr.EROFS
}
if i.overlay != nil {
@@ -313,7 +313,7 @@ func (i *Inode) CheckPermission(ctx context.Context, p PermMask) error {
// we should not attempt to modify the writable layer if it
// is mounted read-only.
if p.Write && overlayUpperMountSource(i.MountSource).Flags.ReadOnly {
return syserror.EROFS
return linuxerr.EROFS
}
}
+1 -1
View File
@@ -283,7 +283,7 @@ type InodeOperations interface {
//
// Any error returned from Getlink other than ErrResolveViaReadlink
// indicates the caller's inability to traverse this Inode as a link
// (e.g. syserror.ENOLINK indicates that the Inode is not a link,
// (e.g. linuxerr.ENOLINK indicates that the Inode is not a link,
// syscall.EPERM indicates that traversing the link is not allowed, etc).
Getlink(context.Context, *Inode) (*Dirent, error)

Some files were not shown because too many files have changed in this diff Show More