From 63b4f6e296a8f131ec969a685f0e31663be58385 Mon Sep 17 00:00:00 2001 From: Zach Koopmans Date: Wed, 16 Jun 2021 14:06:01 -0700 Subject: [syserror] Refactor linuxerr and error package. Move Error struct to pkg/errors package for use in multiple places. Move linuxerr static definitions under pkg/errors/linuxerr. Add a lookup list for quick lookup of *errors.Error by errno. This is useful when converting syserror errors and unix.Errno/syscall.Errrno values to *errors.Error. Update benchmarks routines to include conversions. The below benchmarks show *errors.Error usage to be comparable to using unix.Errno. BenchmarkAssignUnix BenchmarkAssignUnix-32 787875022 1.284 ns/op BenchmarkAssignLinuxerr BenchmarkAssignLinuxerr-32 1000000000 1.209 ns/op BenchmarkAssignSyserror BenchmarkAssignSyserror-32 759269229 1.429 ns/op BenchmarkCompareUnix BenchmarkCompareUnix-32 1000000000 1.310 ns/op BenchmarkCompareLinuxerr BenchmarkCompareLinuxerr-32 1000000000 1.241 ns/op BenchmarkCompareSyserror BenchmarkCompareSyserror-32 147196165 8.248 ns/op BenchmarkSwitchUnix BenchmarkSwitchUnix-32 373233556 3.664 ns/op BenchmarkSwitchLinuxerr BenchmarkSwitchLinuxerr-32 476323929 3.294 ns/op BenchmarkSwitchSyserror BenchmarkSwitchSyserror-32 39293408 29.62 ns/op BenchmarkReturnUnix BenchmarkReturnUnix-32 1000000000 0.5042 ns/op BenchmarkReturnLinuxerr BenchmarkReturnLinuxerr-32 1000000000 0.8152 ns/op BenchmarkConvertUnixLinuxerr BenchmarkConvertUnixLinuxerr-32 739948875 1.547 ns/op BenchmarkConvertUnixLinuxerrZero BenchmarkConvertUnixLinuxerrZero-32 977733974 1.489 ns/op PiperOrigin-RevId: 379806801 --- pkg/abi/linux/BUILD | 1 - pkg/abi/linux/errno/BUILD | 9 +++ pkg/abi/linux/errno/errno.go | 165 +++++++++++++++++++++++++++++++++++++++++++ pkg/abi/linux/errors.go | 163 ------------------------------------------ 4 files changed, 174 insertions(+), 164 deletions(-) create mode 100644 pkg/abi/linux/errno/BUILD create mode 100644 pkg/abi/linux/errno/errno.go delete mode 100644 pkg/abi/linux/errors.go (limited to 'pkg/abi/linux') diff --git a/pkg/abi/linux/BUILD b/pkg/abi/linux/BUILD index 38288bdb7..eb004a7f6 100644 --- a/pkg/abi/linux/BUILD +++ b/pkg/abi/linux/BUILD @@ -21,7 +21,6 @@ go_library( "epoll.go", "epoll_amd64.go", "epoll_arm64.go", - "errors.go", "errqueue.go", "eventfd.go", "exec.go", diff --git a/pkg/abi/linux/errno/BUILD b/pkg/abi/linux/errno/BUILD new file mode 100644 index 000000000..d003342d5 --- /dev/null +++ b/pkg/abi/linux/errno/BUILD @@ -0,0 +1,9 @@ +load("//tools:defs.bzl", "go_library") + +package(licenses = ["notice"]) + +go_library( + name = "errno", + srcs = ["errno.go"], + visibility = ["//visibility:public"], +) diff --git a/pkg/abi/linux/errno/errno.go b/pkg/abi/linux/errno/errno.go new file mode 100644 index 000000000..5a09c6605 --- /dev/null +++ b/pkg/abi/linux/errno/errno.go @@ -0,0 +1,165 @@ +// Copyright 2018 The gVisor Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package errno holds errno codes for abi/linux. +package errno + +// Errno represents a Linux errno value. +type Errno uint32 + +// Errno values from include/uapi/asm-generic/errno-base.h. +const ( + NOERRNO = iota + EPERM + ENOENT + ESRCH + EINTR + EIO + ENXIO + E2BIG + ENOEXEC + EBADF + ECHILD // 10 + EAGAIN + ENOMEM + EACCES + EFAULT + ENOTBLK + EBUSY + EEXIST + EXDEV + ENODEV + ENOTDIR // 20 + EISDIR + EINVAL + ENFILE + EMFILE + ENOTTY + ETXTBSY + EFBIG + ENOSPC + ESPIPE + EROFS // 30 + EMLINK + EPIPE + EDOM + ERANGE + // Errno values from include/uapi/asm-generic/errno.h. + EDEADLK + ENAMETOOLONG + ENOLCK + ENOSYS + ENOTEMPTY + ELOOP // 40 + _ // Skip for EWOULDBLOCK = EAGAIN. + ENOMSG //42 + EIDRM + ECHRNG + EL2NSYNC + EL3HLT + EL3RST + ELNRNG + EUNATCH + ENOCSI + EL2HLT // 50 + EBADE + EBADR + EXFULL + ENOANO + EBADRQC + EBADSLT + _ // Skip for EDEADLOCK = EDEADLK. + EBFONT + ENOSTR // 60 + ENODATA + ETIME + ENOSR + _ // Skip for ENOENT = ENONET. + ENOPKG + EREMOTE + ENOLINK + EADV + ESRMNT + ECOMM // 70 + EPROTO + EMULTIHOP + EDOTDOT + EBADMSG + EOVERFLOW + ENOTUNIQ + EBADFD + EREMCHG + ELIBACC + ELIBBAD // 80 + ELIBSCN + ELIBMAX + ELIBEXEC + EILSEQ + ERESTART + ESTRPIPE + EUSERS + ENOTSOCK + EDESTADDRREQ + EMSGSIZE // 90 + EPROTOTYPE + ENOPROTOOPT + EPROTONOSUPPORT + ESOCKTNOSUPPORT + EOPNOTSUPP + EPFNOSUPPORT + EAFNOSUPPORT + EADDRINUSE + EADDRNOTAVAIL + ENETDOWN // 100 + ENETUNREACH + ENETRESET + ECONNABORTED + ECONNRESET + ENOBUFS + EISCONN + ENOTCONN + ESHUTDOWN + ETOOMANYREFS + ETIMEDOUT // 110 + ECONNREFUSED + EHOSTDOWN + EHOSTUNREACH + EALREADY + EINPROGRESS + ESTALE + EUCLEAN + ENOTNAM + ENAVAIL + EISNAM // 120 + EREMOTEIO + EDQUOT + ENOMEDIUM + EMEDIUMTYPE + ECANCELED + ENOKEY + EKEYEXPIRED + EKEYREVOKED + EKEYREJECTED + EOWNERDEAD // 130 + ENOTRECOVERABLE + ERFKILL + EHWPOISON +) + +// errnos derived from other errnos +const ( + EWOULDBLOCK = EAGAIN + EDEADLOCK = EDEADLK + ENONET = ENOENT +) diff --git a/pkg/abi/linux/errors.go b/pkg/abi/linux/errors.go deleted file mode 100644 index b08b2687e..000000000 --- a/pkg/abi/linux/errors.go +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright 2018 The gVisor Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package linux - -// Errno represents a Linux errno value. -type Errno int - -// Errno values from include/uapi/asm-generic/errno-base.h. -const ( - NOERRNO = iota - EPERM - ENOENT - ESRCH - EINTR - EIO - ENXIO - E2BIG - ENOEXEC - EBADF - ECHILD // 10 - EAGAIN - ENOMEM - EACCES - EFAULT - ENOTBLK - EBUSY - EEXIST - EXDEV - ENODEV - ENOTDIR // 20 - EISDIR - EINVAL - ENFILE - EMFILE - ENOTTY - ETXTBSY - EFBIG - ENOSPC - ESPIPE - EROFS // 30 - EMLINK - EPIPE - EDOM - ERANGE - // Errno values from include/uapi/asm-generic/errno.h. - EDEADLK - ENAMETOOLONG - ENOLCK - ENOSYS - ENOTEMPTY - ELOOP //40 - _ // Skip for EWOULDBLOCK = EAGAIN - ENOMSG //42 - EIDRM - ECHRNG - EL2NSYNC - EL3HLT - EL3RST - ELNRNG - EUNATCH - ENOCSI - EL2HLT // 50 - EBADE - EBADR - EXFULL - ENOANO - EBADRQC - EBADSLT - _ // Skip for EDEADLOCK = EDEADLK - EBFONT - ENOSTR // 60 - ENODATA - ETIME - ENOSR - ENONET - ENOPKG - EREMOTE - ENOLINK - EADV - ESRMNT - ECOMM // 70 - EPROTO - EMULTIHOP - EDOTDOT - EBADMSG - EOVERFLOW - ENOTUNIQ - EBADFD - EREMCHG - ELIBACC - ELIBBAD // 80 - ELIBSCN - ELIBMAX - ELIBEXEC - EILSEQ - ERESTART - ESTRPIPE - EUSERS - ENOTSOCK - EDESTADDRREQ - EMSGSIZE // 90 - EPROTOTYPE - ENOPROTOOPT - EPROTONOSUPPORT - ESOCKTNOSUPPORT - EOPNOTSUPP - EPFNOSUPPORT - EAFNOSUPPORT - EADDRINUSE - EADDRNOTAVAIL - ENETDOWN // 100 - ENETUNREACH - ENETRESET - ECONNABORTED - ECONNRESET - ENOBUFS - EISCONN - ENOTCONN - ESHUTDOWN - ETOOMANYREFS - ETIMEDOUT // 110 - ECONNREFUSED - EHOSTDOWN - EHOSTUNREACH - EALREADY - EINPROGRESS - ESTALE - EUCLEAN - ENOTNAM - ENAVAIL - EISNAM // 120 - EREMOTEIO - EDQUOT - ENOMEDIUM - EMEDIUMTYPE - ECANCELED - ENOKEY - EKEYEXPIRED - EKEYREVOKED - EKEYREJECTED - EOWNERDEAD // 130 - ENOTRECOVERABLE - ERFKILL - EHWPOISON -) - -// errnos derived from other errnos -const ( - EWOULDBLOCK = EAGAIN - EDEADLOCK = EDEADLK -) -- cgit v1.2.3