mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
[syserror] Convert remaining syserror definitions to linuxerr.
Convert remaining public errors (e.g. EINTR) from syserror to linuxerr. PiperOrigin-RevId: 390471763
This commit is contained in:
committed by
gVisor bot
parent
5f132ae1f8
commit
02370bbd31
@@ -157,7 +157,7 @@ const (
|
||||
EHWPOISON
|
||||
)
|
||||
|
||||
// errnos derived from other errnos
|
||||
// errnos derived from other errnos.
|
||||
const (
|
||||
EWOULDBLOCK = EAGAIN
|
||||
EDEADLOCK = EDEADLK
|
||||
|
||||
@@ -4,7 +4,9 @@ package(licenses = ["notice"])
|
||||
|
||||
go_library(
|
||||
name = "linuxerr",
|
||||
srcs = ["linuxerr.go"],
|
||||
srcs = [
|
||||
"linuxerr.go",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//pkg/abi/linux/errno",
|
||||
|
||||
@@ -27,6 +27,12 @@ import (
|
||||
|
||||
const maxErrno uint32 = errno.EHWPOISON + 1
|
||||
|
||||
// The following errors are semantically identical to Errno of type unix.Errno
|
||||
// or sycall.Errno. However, since the type are distinct ( these are
|
||||
// *errors.Error), they are not directly comperable. However, the Errno method
|
||||
// returns an Errno number such that the error can be compared to unix/syscall.Errno
|
||||
// (e.g. unix.Errno(EPERM.Errno()) == unix.EPERM is true). Converting unix/syscall.Errno
|
||||
// to the errors should be done via the lookup methods provided.
|
||||
var (
|
||||
NOERROR = errors.New(errno.NOERRNO, "not an error")
|
||||
EPERM = errors.New(errno.EPERM, "operation not permitted")
|
||||
@@ -177,7 +183,7 @@ var (
|
||||
var errNotValidError = errors.New(errno.Errno(maxErrno), "not a valid error")
|
||||
|
||||
// The following errorSlice holds errors by errno for fast translation between
|
||||
// errnos (especially uint32(sycall.Errno)) and *Error.
|
||||
// errnos (especially uint32(sycall.Errno)) and *errors.Error.
|
||||
var errorSlice = []*errors.Error{
|
||||
// Errno values from include/uapi/asm-generic/errno-base.h.
|
||||
errno.NOERRNO: NOERROR,
|
||||
|
||||
@@ -115,7 +115,7 @@ func BenchmarkSwitchSyserror(b *testing.B) {
|
||||
switch globalError {
|
||||
case linuxerr.EACCES:
|
||||
j++
|
||||
case syserror.EINTR:
|
||||
case linuxerr.EINTR:
|
||||
j += 2
|
||||
case linuxerr.EAGAIN:
|
||||
j += 3
|
||||
|
||||
@@ -45,6 +45,8 @@ func ExtractErrno(err error) unix.Errno {
|
||||
|
||||
// Attempt to unwrap.
|
||||
switch e := err.(type) {
|
||||
case *errors.Error:
|
||||
return unix.Errno(e.Errno())
|
||||
case unix.Errno:
|
||||
return e
|
||||
case *os.PathError:
|
||||
|
||||
@@ -15,6 +15,7 @@ go_library(
|
||||
deps = [
|
||||
"//pkg/abi/linux",
|
||||
"//pkg/context",
|
||||
"//pkg/errors/linuxerr",
|
||||
"//pkg/rand",
|
||||
"//pkg/safemem",
|
||||
"//pkg/sentry/fsimpl/devtmpfs",
|
||||
@@ -23,7 +24,6 @@ go_library(
|
||||
"//pkg/sentry/kernel/auth",
|
||||
"//pkg/sentry/memmap",
|
||||
"//pkg/sentry/vfs",
|
||||
"//pkg/syserror",
|
||||
"//pkg/usermem",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -16,8 +16,8 @@ package memdev
|
||||
|
||||
import (
|
||||
"gvisor.dev/gvisor/pkg/context"
|
||||
"gvisor.dev/gvisor/pkg/errors/linuxerr"
|
||||
"gvisor.dev/gvisor/pkg/sentry/vfs"
|
||||
"gvisor.dev/gvisor/pkg/syserror"
|
||||
"gvisor.dev/gvisor/pkg/usermem"
|
||||
)
|
||||
|
||||
@@ -66,12 +66,12 @@ func (fd *fullFD) Read(ctx context.Context, dst usermem.IOSequence, opts vfs.Rea
|
||||
|
||||
// PWrite implements vfs.FileDescriptionImpl.PWrite.
|
||||
func (fd *fullFD) PWrite(ctx context.Context, src usermem.IOSequence, offset int64, opts vfs.WriteOptions) (int64, error) {
|
||||
return 0, syserror.ENOSPC
|
||||
return 0, linuxerr.ENOSPC
|
||||
}
|
||||
|
||||
// Write implements vfs.FileDescriptionImpl.Write.
|
||||
func (fd *fullFD) Write(ctx context.Context, src usermem.IOSequence, opts vfs.WriteOptions) (int64, error) {
|
||||
return 0, syserror.ENOSPC
|
||||
return 0, linuxerr.ENOSPC
|
||||
}
|
||||
|
||||
// Seek implements vfs.FileDescriptionImpl.Seek.
|
||||
|
||||
@@ -9,8 +9,8 @@ go_library(
|
||||
deps = [
|
||||
"//pkg/abi/linux",
|
||||
"//pkg/context",
|
||||
"//pkg/errors/linuxerr",
|
||||
"//pkg/sentry/fsimpl/devtmpfs",
|
||||
"//pkg/sentry/vfs",
|
||||
"//pkg/syserror",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -18,9 +18,9 @@ package quotedev
|
||||
import (
|
||||
"gvisor.dev/gvisor/pkg/abi/linux"
|
||||
"gvisor.dev/gvisor/pkg/context"
|
||||
"gvisor.dev/gvisor/pkg/errors/linuxerr"
|
||||
"gvisor.dev/gvisor/pkg/sentry/fsimpl/devtmpfs"
|
||||
"gvisor.dev/gvisor/pkg/sentry/vfs"
|
||||
"gvisor.dev/gvisor/pkg/syserror"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -35,7 +35,7 @@ type quoteDevice struct{}
|
||||
// Open implements vfs.Device.Open.
|
||||
// TODO(b/157161182): Add support for attestation ioctls.
|
||||
func (quoteDevice) Open(ctx context.Context, mnt *vfs.Mount, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
return nil, syserror.EIO
|
||||
return nil, linuxerr.EIO
|
||||
}
|
||||
|
||||
// Register registers all devices implemented by this package in vfsObj.
|
||||
|
||||
@@ -9,8 +9,8 @@ go_library(
|
||||
deps = [
|
||||
"//pkg/abi/linux",
|
||||
"//pkg/context",
|
||||
"//pkg/errors/linuxerr",
|
||||
"//pkg/sentry/fsimpl/devtmpfs",
|
||||
"//pkg/sentry/vfs",
|
||||
"//pkg/syserror",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -18,9 +18,9 @@ package ttydev
|
||||
import (
|
||||
"gvisor.dev/gvisor/pkg/abi/linux"
|
||||
"gvisor.dev/gvisor/pkg/context"
|
||||
"gvisor.dev/gvisor/pkg/errors/linuxerr"
|
||||
"gvisor.dev/gvisor/pkg/sentry/fsimpl/devtmpfs"
|
||||
"gvisor.dev/gvisor/pkg/sentry/vfs"
|
||||
"gvisor.dev/gvisor/pkg/syserror"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -36,7 +36,7 @@ type ttyDevice struct{}
|
||||
|
||||
// Open implements vfs.Device.Open.
|
||||
func (ttyDevice) Open(ctx context.Context, mnt *vfs.Mount, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
|
||||
return nil, syserror.EIO
|
||||
return nil, linuxerr.EIO
|
||||
}
|
||||
|
||||
// Register registers all devices implemented by this package in vfsObj.
|
||||
|
||||
+10
-11
@@ -25,7 +25,6 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/log"
|
||||
"gvisor.dev/gvisor/pkg/sentry/memmap"
|
||||
"gvisor.dev/gvisor/pkg/sync"
|
||||
"gvisor.dev/gvisor/pkg/syserror"
|
||||
"gvisor.dev/gvisor/pkg/usermem"
|
||||
)
|
||||
|
||||
@@ -195,7 +194,7 @@ func copyUpLocked(ctx context.Context, parent *Dirent, next *Dirent) error {
|
||||
attrs, err := next.Inode.overlay.lower.UnstableAttr(ctx)
|
||||
if err != nil {
|
||||
log.Warningf("copy up failed to get lower attributes: %v", err)
|
||||
return syserror.EIO
|
||||
return linuxerr.EIO
|
||||
}
|
||||
|
||||
var childUpperInode *Inode
|
||||
@@ -211,7 +210,7 @@ func copyUpLocked(ctx context.Context, parent *Dirent, next *Dirent) error {
|
||||
childFile, err := parentUpper.Create(ctx, root, next.name, FileFlags{Read: true, Write: true}, attrs.Perms)
|
||||
if err != nil {
|
||||
log.Warningf("copy up failed to create file: %v", err)
|
||||
return syserror.EIO
|
||||
return linuxerr.EIO
|
||||
}
|
||||
defer childFile.DecRef(ctx)
|
||||
childUpperInode = childFile.Dirent.Inode
|
||||
@@ -219,13 +218,13 @@ func copyUpLocked(ctx context.Context, parent *Dirent, next *Dirent) error {
|
||||
case Directory:
|
||||
if err := parentUpper.CreateDirectory(ctx, root, next.name, attrs.Perms); err != nil {
|
||||
log.Warningf("copy up failed to create directory: %v", err)
|
||||
return syserror.EIO
|
||||
return linuxerr.EIO
|
||||
}
|
||||
childUpper, err := parentUpper.Lookup(ctx, next.name)
|
||||
if err != nil {
|
||||
werr := fmt.Errorf("copy up failed to lookup directory: %v", err)
|
||||
cleanupUpper(ctx, parentUpper, next.name, werr)
|
||||
return syserror.EIO
|
||||
return linuxerr.EIO
|
||||
}
|
||||
defer childUpper.DecRef(ctx)
|
||||
childUpperInode = childUpper.Inode
|
||||
@@ -235,17 +234,17 @@ func copyUpLocked(ctx context.Context, parent *Dirent, next *Dirent) error {
|
||||
link, err := childLower.Readlink(ctx)
|
||||
if err != nil {
|
||||
log.Warningf("copy up failed to read symlink value: %v", err)
|
||||
return syserror.EIO
|
||||
return linuxerr.EIO
|
||||
}
|
||||
if err := parentUpper.CreateLink(ctx, root, link, next.name); err != nil {
|
||||
log.Warningf("copy up failed to create symlink: %v", err)
|
||||
return syserror.EIO
|
||||
return linuxerr.EIO
|
||||
}
|
||||
childUpper, err := parentUpper.Lookup(ctx, next.name)
|
||||
if err != nil {
|
||||
werr := fmt.Errorf("copy up failed to lookup symlink: %v", err)
|
||||
cleanupUpper(ctx, parentUpper, next.name, werr)
|
||||
return syserror.EIO
|
||||
return linuxerr.EIO
|
||||
}
|
||||
defer childUpper.DecRef(ctx)
|
||||
childUpperInode = childUpper.Inode
|
||||
@@ -259,14 +258,14 @@ func copyUpLocked(ctx context.Context, parent *Dirent, next *Dirent) error {
|
||||
if err := copyAttributesLocked(ctx, childUpperInode, next.Inode.overlay.lower); err != nil {
|
||||
werr := fmt.Errorf("copy up failed to copy up attributes: %v", err)
|
||||
cleanupUpper(ctx, parentUpper, next.name, werr)
|
||||
return syserror.EIO
|
||||
return linuxerr.EIO
|
||||
}
|
||||
|
||||
// Copy the entire file.
|
||||
if err := copyContentsLocked(ctx, childUpperInode, next.Inode.overlay.lower, attrs.Size); err != nil {
|
||||
werr := fmt.Errorf("copy up failed to copy up contents: %v", err)
|
||||
cleanupUpper(ctx, parentUpper, next.name, werr)
|
||||
return syserror.EIO
|
||||
return linuxerr.EIO
|
||||
}
|
||||
|
||||
lowerMappable := next.Inode.overlay.lower.Mappable()
|
||||
@@ -274,7 +273,7 @@ func copyUpLocked(ctx context.Context, parent *Dirent, next *Dirent) error {
|
||||
if lowerMappable != nil && upperMappable == nil {
|
||||
werr := fmt.Errorf("copy up failed: cannot ensure memory mapping coherence")
|
||||
cleanupUpper(ctx, parentUpper, next.name, werr)
|
||||
return syserror.EIO
|
||||
return linuxerr.EIO
|
||||
}
|
||||
|
||||
// Propagate memory mappings to the upper Inode.
|
||||
|
||||
@@ -34,7 +34,6 @@ go_library(
|
||||
"//pkg/sentry/mm",
|
||||
"//pkg/sentry/pgalloc",
|
||||
"//pkg/sentry/socket/netstack",
|
||||
"//pkg/syserror",
|
||||
"//pkg/tcpip/link/tun",
|
||||
"//pkg/usermem",
|
||||
"//pkg/waiter",
|
||||
|
||||
@@ -17,9 +17,9 @@ package dev
|
||||
import (
|
||||
"gvisor.dev/gvisor/pkg/abi/linux"
|
||||
"gvisor.dev/gvisor/pkg/context"
|
||||
"gvisor.dev/gvisor/pkg/errors/linuxerr"
|
||||
"gvisor.dev/gvisor/pkg/sentry/fs"
|
||||
"gvisor.dev/gvisor/pkg/sentry/fs/fsutil"
|
||||
"gvisor.dev/gvisor/pkg/syserror"
|
||||
"gvisor.dev/gvisor/pkg/usermem"
|
||||
"gvisor.dev/gvisor/pkg/waiter"
|
||||
)
|
||||
@@ -77,5 +77,5 @@ var _ fs.FileOperations = (*fullFileOperations)(nil)
|
||||
|
||||
// Write implements FileOperations.Write.
|
||||
func (*fullFileOperations) Write(context.Context, *fs.File, usermem.IOSequence, int64) (int64, error) {
|
||||
return 0, syserror.ENOSPC
|
||||
return 0, linuxerr.ENOSPC
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/sentry/socket/unix/transport"
|
||||
"gvisor.dev/gvisor/pkg/sentry/uniqueid"
|
||||
"gvisor.dev/gvisor/pkg/sync"
|
||||
"gvisor.dev/gvisor/pkg/syserror"
|
||||
)
|
||||
|
||||
type globalDirentMap struct {
|
||||
@@ -963,7 +962,7 @@ func (d *Dirent) isMountPointLocked() bool {
|
||||
func (d *Dirent) mount(ctx context.Context, inode *Inode) (newChild *Dirent, err error) {
|
||||
// Did we race with deletion?
|
||||
if atomic.LoadInt32(&d.deleted) != 0 {
|
||||
return nil, syserror.ENOENT
|
||||
return nil, linuxerr.ENOENT
|
||||
}
|
||||
|
||||
// Refuse to mount a symlink.
|
||||
@@ -998,7 +997,7 @@ func (d *Dirent) mount(ctx context.Context, inode *Inode) (newChild *Dirent, err
|
||||
func (d *Dirent) unmount(ctx context.Context, replacement *Dirent) error {
|
||||
// Did we race with deletion?
|
||||
if atomic.LoadInt32(&d.deleted) != 0 {
|
||||
return syserror.ENOENT
|
||||
return linuxerr.ENOENT
|
||||
}
|
||||
|
||||
// Remount our former child in its place.
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
|
||||
"gvisor.dev/gvisor/pkg/amutex"
|
||||
"gvisor.dev/gvisor/pkg/context"
|
||||
"gvisor.dev/gvisor/pkg/errors/linuxerr"
|
||||
"gvisor.dev/gvisor/pkg/refs"
|
||||
"gvisor.dev/gvisor/pkg/sentry/fs/lock"
|
||||
"gvisor.dev/gvisor/pkg/sentry/fsmetric"
|
||||
@@ -352,7 +353,7 @@ func (f *File) offsetForAppend(ctx context.Context, offset *int64) error {
|
||||
if err != nil {
|
||||
// This is an odd error, we treat it as evidence that
|
||||
// something is terribly wrong with the filesystem.
|
||||
return syserror.EIO
|
||||
return linuxerr.EIO
|
||||
}
|
||||
|
||||
// Update the offset.
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/sentry/arch"
|
||||
"gvisor.dev/gvisor/pkg/sentry/memmap"
|
||||
"gvisor.dev/gvisor/pkg/sync"
|
||||
"gvisor.dev/gvisor/pkg/syserror"
|
||||
"gvisor.dev/gvisor/pkg/usermem"
|
||||
"gvisor.dev/gvisor/pkg/waiter"
|
||||
)
|
||||
@@ -246,7 +245,7 @@ func (f *overlayFileOperations) onTop(ctx context.Context, file *File, fn func(*
|
||||
// Something very wrong; return a generic filesystem
|
||||
// error to avoid propagating internals.
|
||||
f.upperMu.Unlock()
|
||||
return syserror.EIO
|
||||
return linuxerr.EIO
|
||||
}
|
||||
|
||||
// Save upper file.
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/sentry/arch"
|
||||
"gvisor.dev/gvisor/pkg/sentry/fs"
|
||||
"gvisor.dev/gvisor/pkg/sentry/memmap"
|
||||
"gvisor.dev/gvisor/pkg/syserror"
|
||||
"gvisor.dev/gvisor/pkg/usermem"
|
||||
"gvisor.dev/gvisor/pkg/waiter"
|
||||
)
|
||||
@@ -232,12 +231,12 @@ type FileNoSplice struct{}
|
||||
|
||||
// WriteTo implements fs.FileOperations.WriteTo.
|
||||
func (FileNoSplice) WriteTo(context.Context, *fs.File, io.Writer, int64, bool) (int64, error) {
|
||||
return 0, syserror.ENOSYS
|
||||
return 0, linuxerr.ENOSYS
|
||||
}
|
||||
|
||||
// ReadFrom implements fs.FileOperations.ReadFrom.
|
||||
func (FileNoSplice) ReadFrom(context.Context, *fs.File, io.Reader, int64) (int64, error) {
|
||||
return 0, syserror.ENOSYS
|
||||
return 0, linuxerr.ENOSYS
|
||||
}
|
||||
|
||||
// DirFileOperations implements most of fs.FileOperations for directories,
|
||||
@@ -255,12 +254,12 @@ type DirFileOperations struct {
|
||||
|
||||
// Read implements fs.FileOperations.Read
|
||||
func (*DirFileOperations) Read(context.Context, *fs.File, usermem.IOSequence, int64) (int64, error) {
|
||||
return 0, syserror.EISDIR
|
||||
return 0, linuxerr.EISDIR
|
||||
}
|
||||
|
||||
// Write implements fs.FileOperations.Write.
|
||||
func (*DirFileOperations) Write(context.Context, *fs.File, usermem.IOSequence, int64) (int64, error) {
|
||||
return 0, syserror.EISDIR
|
||||
return 0, linuxerr.EISDIR
|
||||
}
|
||||
|
||||
// StaticDirFileOperations implements fs.FileOperations for directories with
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/sentry/memmap"
|
||||
"gvisor.dev/gvisor/pkg/sentry/socket/unix/transport"
|
||||
"gvisor.dev/gvisor/pkg/sync"
|
||||
"gvisor.dev/gvisor/pkg/syserror"
|
||||
"gvisor.dev/gvisor/pkg/waiter"
|
||||
)
|
||||
|
||||
@@ -167,7 +166,7 @@ func (i *InodeSimpleAttributes) DropLink() {
|
||||
// StatFS implements fs.InodeOperations.StatFS.
|
||||
func (i *InodeSimpleAttributes) StatFS(context.Context) (fs.Info, error) {
|
||||
if i.fsType == 0 {
|
||||
return fs.Info{}, syserror.ENOSYS
|
||||
return fs.Info{}, linuxerr.ENOSYS
|
||||
}
|
||||
return fs.Info{Type: i.fsType}, nil
|
||||
}
|
||||
@@ -294,7 +293,7 @@ type InodeNoStatFS struct{}
|
||||
|
||||
// StatFS implements fs.InodeOperations.StatFS.
|
||||
func (InodeNoStatFS) StatFS(context.Context) (fs.Info, error) {
|
||||
return fs.Info{}, syserror.ENOSYS
|
||||
return fs.Info{}, linuxerr.ENOSYS
|
||||
}
|
||||
|
||||
// InodeStaticFileGetter implements GetFile for a file with static contents.
|
||||
@@ -401,7 +400,7 @@ type InodeIsDirTruncate struct{}
|
||||
|
||||
// Truncate implements fs.InodeOperations.Truncate.
|
||||
func (InodeIsDirTruncate) Truncate(context.Context, *fs.Inode, int64) error {
|
||||
return syserror.EISDIR
|
||||
return linuxerr.EISDIR
|
||||
}
|
||||
|
||||
// InodeNoopTruncate implements fs.InodeOperations.Truncate as a noop.
|
||||
@@ -425,7 +424,7 @@ type InodeNotOpenable struct{}
|
||||
|
||||
// GetFile implements fs.InodeOperations.GetFile.
|
||||
func (InodeNotOpenable) GetFile(context.Context, *fs.Dirent, fs.FileFlags) (*fs.File, error) {
|
||||
return nil, syserror.EIO
|
||||
return nil, linuxerr.EIO
|
||||
}
|
||||
|
||||
// InodeNotVirtual can be used by Inodes that are not virtual.
|
||||
@@ -529,5 +528,5 @@ type InodeIsDirAllocate struct{}
|
||||
|
||||
// Allocate implements fs.InodeOperations.Allocate.
|
||||
func (InodeIsDirAllocate) Allocate(_ context.Context, _ *fs.Inode, _, _ int64) error {
|
||||
return syserror.EISDIR
|
||||
return linuxerr.EISDIR
|
||||
}
|
||||
|
||||
@@ -63,10 +63,10 @@ go_test(
|
||||
library = ":gofer",
|
||||
deps = [
|
||||
"//pkg/context",
|
||||
"//pkg/errors/linuxerr",
|
||||
"//pkg/p9",
|
||||
"//pkg/p9/p9test",
|
||||
"//pkg/sentry/contexttest",
|
||||
"//pkg/sentry/fs",
|
||||
"@org_golang_x_sys//unix:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user