diff options
Diffstat (limited to 'pkg/p9')
-rw-r--r-- | pkg/p9/BUILD | 1 | ||||
-rw-r--r-- | pkg/p9/client.go | 15 | ||||
-rw-r--r-- | pkg/p9/client_file.go | 78 | ||||
-rw-r--r-- | pkg/p9/client_test.go | 18 | ||||
-rw-r--r-- | pkg/p9/file.go | 13 | ||||
-rw-r--r-- | pkg/p9/handlers.go | 210 | ||||
-rw-r--r-- | pkg/p9/p9test/BUILD | 2 | ||||
-rw-r--r-- | pkg/p9/p9test/client_test.go | 174 | ||||
-rw-r--r-- | pkg/p9/p9test/p9test.go | 6 | ||||
-rw-r--r-- | pkg/p9/server.go | 8 | ||||
-rw-r--r-- | pkg/p9/transport.go | 6 | ||||
-rw-r--r-- | pkg/p9/transport_flipcall.go | 4 |
12 files changed, 268 insertions, 267 deletions
diff --git a/pkg/p9/BUILD b/pkg/p9/BUILD index 8904afad9..b2291ef97 100644 --- a/pkg/p9/BUILD +++ b/pkg/p9/BUILD @@ -48,5 +48,6 @@ go_test( deps = [ "//pkg/fd", "//pkg/unet", + "@org_golang_x_sys//unix:go_default_library", ], ) diff --git a/pkg/p9/client.go b/pkg/p9/client.go index 3f4324ac1..764f1f970 100644 --- a/pkg/p9/client.go +++ b/pkg/p9/client.go @@ -17,7 +17,6 @@ package p9 import ( "errors" "fmt" - "syscall" "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/flipcall" @@ -180,7 +179,7 @@ func NewClient(socket *unet.Socket, messageSize uint32, version string) (*Client }, &rversion) // The server told us to try again with a lower version. - if err == syscall.EAGAIN { + if err == unix.EAGAIN { if requested == lowestSupportedVersion { return nil, ErrVersionsExhausted } @@ -250,7 +249,7 @@ func (c *Client) watch(socket *unet.Socket) { // Wait for a shutdown event. for { n, err := unix.Ppoll(events, nil, nil) - if err == syscall.EINTR || err == syscall.EAGAIN { + if err == unix.EINTR || err == unix.EAGAIN { continue } if err != nil { @@ -437,7 +436,7 @@ func (c *Client) sendRecvLegacySyscallErr(t message, r message) error { received, err := c.sendRecvLegacy(t, r) if !received { log.Warningf("p9.Client.sendRecvChannel: %v", err) - return syscall.EIO + return unix.EIO } return err } @@ -485,7 +484,7 @@ func (c *Client) sendRecvLegacy(t message, r message) (bool, error) { // For convenience, we transform these directly // into errors. Handlers need not handle this case. if rlerr, ok := resp.r.(*Rlerror); ok { - return true, syscall.Errno(rlerr.Error) + return true, unix.Errno(rlerr.Error) } // At this point, we know it matches. @@ -524,7 +523,7 @@ func (c *Client) sendRecvChannel(t message, r message) error { // Map all transport errors to EIO, but ensure that the real error // is logged. log.Warningf("p9.Client.sendRecvChannel: flipcall.Endpoint.Connect: %v", err) - return syscall.EIO + return unix.EIO } } @@ -537,14 +536,14 @@ func (c *Client) sendRecvChannel(t message, r message) error { c.channelsMu.Unlock() c.channelsWg.Done() log.Warningf("p9.Client.sendRecvChannel: p9.channel.send: %v", err) - return syscall.EIO + return unix.EIO } // Parse the server's response. resp, retErr := ch.recv(r, rsz) if resp == nil { log.Warningf("p9.Client.sendRecvChannel: p9.channel.recv: %v", retErr) - retErr = syscall.EIO + retErr = unix.EIO } // Release the channel. diff --git a/pkg/p9/client_file.go b/pkg/p9/client_file.go index 8b46a2987..7abc82e1b 100644 --- a/pkg/p9/client_file.go +++ b/pkg/p9/client_file.go @@ -18,8 +18,8 @@ import ( "fmt" "io" "sync/atomic" - "syscall" + "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/fd" "gvisor.dev/gvisor/pkg/log" ) @@ -69,7 +69,7 @@ type clientFile struct { // Walk implements File.Walk. func (c *clientFile) Walk(names []string) ([]QID, File, error) { if atomic.LoadUint32(&c.closed) != 0 { - return nil, nil, syscall.EBADF + return nil, nil, unix.EBADF } fid, ok := c.client.fidPool.Get() @@ -90,7 +90,7 @@ func (c *clientFile) Walk(names []string) ([]QID, File, error) { // WalkGetAttr implements File.WalkGetAttr. func (c *clientFile) WalkGetAttr(components []string) ([]QID, File, AttrMask, Attr, error) { if atomic.LoadUint32(&c.closed) != 0 { - return nil, nil, AttrMask{}, Attr{}, syscall.EBADF + return nil, nil, AttrMask{}, Attr{}, unix.EBADF } if !versionSupportsTwalkgetattr(c.client.version) { @@ -124,7 +124,7 @@ func (c *clientFile) WalkGetAttr(components []string) ([]QID, File, AttrMask, At // StatFS implements File.StatFS. func (c *clientFile) StatFS() (FSStat, error) { if atomic.LoadUint32(&c.closed) != 0 { - return FSStat{}, syscall.EBADF + return FSStat{}, unix.EBADF } rstatfs := Rstatfs{} @@ -138,7 +138,7 @@ func (c *clientFile) StatFS() (FSStat, error) { // FSync implements File.FSync. func (c *clientFile) FSync() error { if atomic.LoadUint32(&c.closed) != 0 { - return syscall.EBADF + return unix.EBADF } return c.client.sendRecv(&Tfsync{FID: c.fid}, &Rfsync{}) @@ -147,7 +147,7 @@ func (c *clientFile) FSync() error { // GetAttr implements File.GetAttr. func (c *clientFile) GetAttr(req AttrMask) (QID, AttrMask, Attr, error) { if atomic.LoadUint32(&c.closed) != 0 { - return QID{}, AttrMask{}, Attr{}, syscall.EBADF + return QID{}, AttrMask{}, Attr{}, unix.EBADF } rgetattr := Rgetattr{} @@ -161,7 +161,7 @@ func (c *clientFile) GetAttr(req AttrMask) (QID, AttrMask, Attr, error) { // SetAttr implements File.SetAttr. func (c *clientFile) SetAttr(valid SetAttrMask, attr SetAttr) error { if atomic.LoadUint32(&c.closed) != 0 { - return syscall.EBADF + return unix.EBADF } return c.client.sendRecv(&Tsetattr{FID: c.fid, Valid: valid, SetAttr: attr}, &Rsetattr{}) @@ -170,10 +170,10 @@ func (c *clientFile) SetAttr(valid SetAttrMask, attr SetAttr) error { // GetXattr implements File.GetXattr. func (c *clientFile) GetXattr(name string, size uint64) (string, error) { if atomic.LoadUint32(&c.closed) != 0 { - return "", syscall.EBADF + return "", unix.EBADF } if !versionSupportsGetSetXattr(c.client.version) { - return "", syscall.EOPNOTSUPP + return "", unix.EOPNOTSUPP } rgetxattr := Rgetxattr{} @@ -187,10 +187,10 @@ func (c *clientFile) GetXattr(name string, size uint64) (string, error) { // SetXattr implements File.SetXattr. func (c *clientFile) SetXattr(name, value string, flags uint32) error { if atomic.LoadUint32(&c.closed) != 0 { - return syscall.EBADF + return unix.EBADF } if !versionSupportsGetSetXattr(c.client.version) { - return syscall.EOPNOTSUPP + return unix.EOPNOTSUPP } return c.client.sendRecv(&Tsetxattr{FID: c.fid, Name: name, Value: value, Flags: flags}, &Rsetxattr{}) @@ -199,10 +199,10 @@ func (c *clientFile) SetXattr(name, value string, flags uint32) error { // ListXattr implements File.ListXattr. func (c *clientFile) ListXattr(size uint64) (map[string]struct{}, error) { if atomic.LoadUint32(&c.closed) != 0 { - return nil, syscall.EBADF + return nil, unix.EBADF } if !versionSupportsListRemoveXattr(c.client.version) { - return nil, syscall.EOPNOTSUPP + return nil, unix.EOPNOTSUPP } rlistxattr := Rlistxattr{} @@ -220,10 +220,10 @@ func (c *clientFile) ListXattr(size uint64) (map[string]struct{}, error) { // RemoveXattr implements File.RemoveXattr. func (c *clientFile) RemoveXattr(name string) error { if atomic.LoadUint32(&c.closed) != 0 { - return syscall.EBADF + return unix.EBADF } if !versionSupportsListRemoveXattr(c.client.version) { - return syscall.EOPNOTSUPP + return unix.EOPNOTSUPP } return c.client.sendRecv(&Tremovexattr{FID: c.fid, Name: name}, &Rremovexattr{}) @@ -232,10 +232,10 @@ func (c *clientFile) RemoveXattr(name string) error { // Allocate implements File.Allocate. func (c *clientFile) Allocate(mode AllocateMode, offset, length uint64) error { if atomic.LoadUint32(&c.closed) != 0 { - return syscall.EBADF + return unix.EBADF } if !versionSupportsTallocate(c.client.version) { - return syscall.EOPNOTSUPP + return unix.EOPNOTSUPP } return c.client.sendRecv(&Tallocate{FID: c.fid, Mode: mode, Offset: offset, Length: length}, &Rallocate{}) @@ -248,7 +248,7 @@ func (c *clientFile) Allocate(mode AllocateMode, offset, length uint64) error { func (c *clientFile) Remove() error { // Avoid double close. if !atomic.CompareAndSwapUint32(&c.closed, 0, 1) { - return syscall.EBADF + return unix.EBADF } // Send the remove message. @@ -269,7 +269,7 @@ func (c *clientFile) Remove() error { func (c *clientFile) Close() error { // Avoid double close. if !atomic.CompareAndSwapUint32(&c.closed, 0, 1) { - return syscall.EBADF + return unix.EBADF } // Send the close message. @@ -302,7 +302,7 @@ func (c *clientFile) SetAttrClose(valid SetAttrMask, attr SetAttr) error { // Avoid double close. if !atomic.CompareAndSwapUint32(&c.closed, 0, 1) { - return syscall.EBADF + return unix.EBADF } // Send the message. @@ -321,7 +321,7 @@ func (c *clientFile) SetAttrClose(valid SetAttrMask, attr SetAttr) error { // Open implements File.Open. func (c *clientFile) Open(flags OpenFlags) (*fd.FD, QID, uint32, error) { if atomic.LoadUint32(&c.closed) != 0 { - return nil, QID{}, 0, syscall.EBADF + return nil, QID{}, 0, unix.EBADF } rlopen := Rlopen{} @@ -335,11 +335,11 @@ func (c *clientFile) Open(flags OpenFlags) (*fd.FD, QID, uint32, error) { // Connect implements File.Connect. func (c *clientFile) Connect(flags ConnectFlags) (*fd.FD, error) { if atomic.LoadUint32(&c.closed) != 0 { - return nil, syscall.EBADF + return nil, unix.EBADF } if !VersionSupportsConnect(c.client.version) { - return nil, syscall.ECONNREFUSED + return nil, unix.ECONNREFUSED } rlconnect := Rlconnect{} @@ -404,7 +404,7 @@ func (c *clientFile) ReadAt(p []byte, offset uint64) (int, error) { func (c *clientFile) readAt(p []byte, offset uint64) (int, error) { if atomic.LoadUint32(&c.closed) != 0 { - return 0, syscall.EBADF + return 0, unix.EBADF } rread := Rread{Data: p} @@ -435,7 +435,7 @@ func (c *clientFile) WriteAt(p []byte, offset uint64) (int, error) { func (c *clientFile) writeAt(p []byte, offset uint64) (int, error) { if atomic.LoadUint32(&c.closed) != 0 { - return 0, syscall.EBADF + return 0, unix.EBADF } rwrite := Rwrite{} @@ -500,12 +500,12 @@ func (r *ReadWriterFile) WriteAt(p []byte, offset int64) (int, error) { // Rename implements File.Rename. func (c *clientFile) Rename(dir File, name string) error { if atomic.LoadUint32(&c.closed) != 0 { - return syscall.EBADF + return unix.EBADF } clientDir, ok := dir.(*clientFile) if !ok { - return syscall.EBADF + return unix.EBADF } return c.client.sendRecv(&Trename{FID: c.fid, Directory: clientDir.fid, Name: name}, &Rrename{}) @@ -514,7 +514,7 @@ func (c *clientFile) Rename(dir File, name string) error { // Create implements File.Create. func (c *clientFile) Create(name string, openFlags OpenFlags, permissions FileMode, uid UID, gid GID) (*fd.FD, File, QID, uint32, error) { if atomic.LoadUint32(&c.closed) != 0 { - return nil, nil, QID{}, 0, syscall.EBADF + return nil, nil, QID{}, 0, unix.EBADF } msg := Tlcreate{ @@ -545,7 +545,7 @@ func (c *clientFile) Create(name string, openFlags OpenFlags, permissions FileMo // Mkdir implements File.Mkdir. func (c *clientFile) Mkdir(name string, permissions FileMode, uid UID, gid GID) (QID, error) { if atomic.LoadUint32(&c.closed) != 0 { - return QID{}, syscall.EBADF + return QID{}, unix.EBADF } msg := Tmkdir{ @@ -575,7 +575,7 @@ func (c *clientFile) Mkdir(name string, permissions FileMode, uid UID, gid GID) // Symlink implements File.Symlink. func (c *clientFile) Symlink(oldname string, newname string, uid UID, gid GID) (QID, error) { if atomic.LoadUint32(&c.closed) != 0 { - return QID{}, syscall.EBADF + return QID{}, unix.EBADF } msg := Tsymlink{ @@ -605,12 +605,12 @@ func (c *clientFile) Symlink(oldname string, newname string, uid UID, gid GID) ( // Link implements File.Link. func (c *clientFile) Link(target File, newname string) error { if atomic.LoadUint32(&c.closed) != 0 { - return syscall.EBADF + return unix.EBADF } targetFile, ok := target.(*clientFile) if !ok { - return syscall.EBADF + return unix.EBADF } return c.client.sendRecv(&Tlink{Directory: c.fid, Name: newname, Target: targetFile.fid}, &Rlink{}) @@ -619,7 +619,7 @@ func (c *clientFile) Link(target File, newname string) error { // Mknod implements File.Mknod. func (c *clientFile) Mknod(name string, mode FileMode, major uint32, minor uint32, uid UID, gid GID) (QID, error) { if atomic.LoadUint32(&c.closed) != 0 { - return QID{}, syscall.EBADF + return QID{}, unix.EBADF } msg := Tmknod{ @@ -651,12 +651,12 @@ func (c *clientFile) Mknod(name string, mode FileMode, major uint32, minor uint3 // RenameAt implements File.RenameAt. func (c *clientFile) RenameAt(oldname string, newdir File, newname string) error { if atomic.LoadUint32(&c.closed) != 0 { - return syscall.EBADF + return unix.EBADF } clientNewDir, ok := newdir.(*clientFile) if !ok { - return syscall.EBADF + return unix.EBADF } return c.client.sendRecv(&Trenameat{OldDirectory: c.fid, OldName: oldname, NewDirectory: clientNewDir.fid, NewName: newname}, &Rrenameat{}) @@ -665,7 +665,7 @@ func (c *clientFile) RenameAt(oldname string, newdir File, newname string) error // UnlinkAt implements File.UnlinkAt. func (c *clientFile) UnlinkAt(name string, flags uint32) error { if atomic.LoadUint32(&c.closed) != 0 { - return syscall.EBADF + return unix.EBADF } return c.client.sendRecv(&Tunlinkat{Directory: c.fid, Name: name, Flags: flags}, &Runlinkat{}) @@ -674,7 +674,7 @@ func (c *clientFile) UnlinkAt(name string, flags uint32) error { // Readdir implements File.Readdir. func (c *clientFile) Readdir(offset uint64, count uint32) ([]Dirent, error) { if atomic.LoadUint32(&c.closed) != 0 { - return nil, syscall.EBADF + return nil, unix.EBADF } rreaddir := Rreaddir{} @@ -688,7 +688,7 @@ func (c *clientFile) Readdir(offset uint64, count uint32) ([]Dirent, error) { // Readlink implements File.Readlink. func (c *clientFile) Readlink() (string, error) { if atomic.LoadUint32(&c.closed) != 0 { - return "", syscall.EBADF + return "", unix.EBADF } rreadlink := Rreadlink{} @@ -702,7 +702,7 @@ func (c *clientFile) Readlink() (string, error) { // Flush implements File.Flush. func (c *clientFile) Flush() error { if atomic.LoadUint32(&c.closed) != 0 { - return syscall.EBADF + return unix.EBADF } if !VersionSupportsTflushf(c.client.version) { diff --git a/pkg/p9/client_test.go b/pkg/p9/client_test.go index b78fdab7a..24e0dd7e8 100644 --- a/pkg/p9/client_test.go +++ b/pkg/p9/client_test.go @@ -15,9 +15,9 @@ package p9 import ( - "syscall" "testing" + "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/unet" ) @@ -41,23 +41,23 @@ func TestVersion(t *testing.T) { } // Check a bogus version string. - if err := c.sendRecv(&Tversion{Version: "notokay", MSize: DefaultMessageSize}, &Rversion{}); err != syscall.EINVAL { - t.Errorf("got %v expected %v", err, syscall.EINVAL) + if err := c.sendRecv(&Tversion{Version: "notokay", MSize: DefaultMessageSize}, &Rversion{}); err != unix.EINVAL { + t.Errorf("got %v expected %v", err, unix.EINVAL) } // Check a bogus version number. - if err := c.sendRecv(&Tversion{Version: "9P1000.L", MSize: DefaultMessageSize}, &Rversion{}); err != syscall.EINVAL { - t.Errorf("got %v expected %v", err, syscall.EINVAL) + if err := c.sendRecv(&Tversion{Version: "9P1000.L", MSize: DefaultMessageSize}, &Rversion{}); err != unix.EINVAL { + t.Errorf("got %v expected %v", err, unix.EINVAL) } // Check a too high version number. - if err := c.sendRecv(&Tversion{Version: versionString(highestSupportedVersion + 1), MSize: DefaultMessageSize}, &Rversion{}); err != syscall.EAGAIN { - t.Errorf("got %v expected %v", err, syscall.EAGAIN) + if err := c.sendRecv(&Tversion{Version: versionString(highestSupportedVersion + 1), MSize: DefaultMessageSize}, &Rversion{}); err != unix.EAGAIN { + t.Errorf("got %v expected %v", err, unix.EAGAIN) } // Check an invalid MSize. - if err := c.sendRecv(&Tversion{Version: versionString(highestSupportedVersion), MSize: 0}, &Rversion{}); err != syscall.EINVAL { - t.Errorf("got %v expected %v", err, syscall.EINVAL) + if err := c.sendRecv(&Tversion{Version: versionString(highestSupportedVersion), MSize: 0}, &Rversion{}); err != unix.EINVAL { + t.Errorf("got %v expected %v", err, unix.EINVAL) } } diff --git a/pkg/p9/file.go b/pkg/p9/file.go index c2e3a3f98..c59c6a65b 100644 --- a/pkg/p9/file.go +++ b/pkg/p9/file.go @@ -15,8 +15,7 @@ package p9 import ( - "syscall" - + "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/fd" ) @@ -67,7 +66,7 @@ type File interface { // WalkGetAttr walks to the next file and returns its maximal set of // attributes. // - // Server-side p9.Files may return syscall.ENOSYS to indicate that Walk + // Server-side p9.Files may return unix.ENOSYS to indicate that Walk // and GetAttr should be used separately to satisfy this request. // // On the server, WalkGetAttr has a read concurrency guarantee. @@ -160,7 +159,7 @@ type File interface { // Read reads from this file. Open must be called first. // - // This may return io.EOF in addition to syscall.Errno values. + // This may return io.EOF in addition to unix.Errno values. // // On the server, ReadAt has a read concurrency guarantee. See Open for // additional requirements regarding lazy path resolution. @@ -168,7 +167,7 @@ type File interface { // Write writes to this file. Open must be called first. // - // This may return io.EOF in addition to syscall.Errno values. + // This may return io.EOF in addition to unix.Errno values. // // On the server, WriteAt has a read concurrency guarantee. See Open // for additional requirements regarding lazy path resolution. @@ -239,7 +238,7 @@ type File interface { // Readdir reads directory entries. // - // This may return io.EOF in addition to syscall.Errno values. + // This may return io.EOF in addition to unix.Errno values. // // On the server, Readdir has a read concurrency guarantee. Readdir(offset uint64, count uint32) ([]Dirent, error) @@ -292,7 +291,7 @@ type DefaultWalkGetAttr struct{} // WalkGetAttr implements File.WalkGetAttr. func (DefaultWalkGetAttr) WalkGetAttr([]string) ([]QID, File, AttrMask, Attr, error) { - return nil, nil, AttrMask{}, Attr{}, syscall.ENOSYS + return nil, nil, AttrMask{}, Attr{}, unix.ENOSYS } // DisallowClientCalls panics if a client-only function is called. diff --git a/pkg/p9/handlers.go b/pkg/p9/handlers.go index 81ceb37c5..58312d0cc 100644 --- a/pkg/p9/handlers.go +++ b/pkg/p9/handlers.go @@ -21,28 +21,28 @@ import ( "path" "strings" "sync/atomic" - "syscall" + "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/fd" "gvisor.dev/gvisor/pkg/log" ) -// ExtractErrno extracts a syscall.Errno from a error, best effort. -func ExtractErrno(err error) syscall.Errno { +// ExtractErrno extracts a unix.Errno from a error, best effort. +func ExtractErrno(err error) unix.Errno { switch err { case os.ErrNotExist: - return syscall.ENOENT + return unix.ENOENT case os.ErrExist: - return syscall.EEXIST + return unix.EEXIST case os.ErrPermission: - return syscall.EACCES + return unix.EACCES case os.ErrInvalid: - return syscall.EINVAL + return unix.EINVAL } // Attempt to unwrap. switch e := err.(type) { - case syscall.Errno: + case unix.Errno: return e case *os.PathError: return ExtractErrno(e.Err) @@ -54,7 +54,7 @@ func ExtractErrno(err error) syscall.Errno { // Default case. log.Warningf("unknown error: %v", err) - return syscall.EIO + return unix.EIO } // newErr returns a new error message from an error. @@ -77,20 +77,20 @@ type handler interface { // handle implements handler.handle. func (t *Tversion) handle(cs *connState) message { if t.MSize == 0 { - return newErr(syscall.EINVAL) + return newErr(unix.EINVAL) } if t.MSize > maximumLength { - return newErr(syscall.EINVAL) + return newErr(unix.EINVAL) } atomic.StoreUint32(&cs.messageSize, t.MSize) requested, ok := parseVersion(t.Version) if !ok { - return newErr(syscall.EINVAL) + return newErr(unix.EINVAL) } // The server cannot support newer versions that it doesn't know about. In this // case we return EAGAIN to tell the client to try again with a lower version. if requested > highestSupportedVersion { - return newErr(syscall.EAGAIN) + return newErr(unix.EAGAIN) } // From Tversion(9P): "The server may respond with the client’s version // string, or a version string identifying an earlier defined protocol version". @@ -112,13 +112,13 @@ func checkSafeName(name string) error { if name != "" && !strings.Contains(name, "/") && name != "." && name != ".." { return nil } - return syscall.EINVAL + return unix.EINVAL } // handle implements handler.handle. func (t *Tclunk) handle(cs *connState) message { if !cs.DeleteFID(t.FID) { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } return &Rclunk{} } @@ -126,7 +126,7 @@ func (t *Tclunk) handle(cs *connState) message { func (t *Tsetattrclunk) handle(cs *connState) message { ref, ok := cs.LookupFID(t.FID) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() @@ -136,7 +136,7 @@ func (t *Tsetattrclunk) handle(cs *connState) message { // there were multiple links and you can still change the // corresponding inode information. if ref.isDeleted() { - return syscall.EINVAL + return unix.EINVAL } // Set the attributes. @@ -146,7 +146,7 @@ func (t *Tsetattrclunk) handle(cs *connState) message { // Try to delete FID even in case of failure above. Since the state of the // file is unknown to the caller, it will not attempt to close the file again. if !cs.DeleteFID(t.FID) { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } if setAttrErr != nil { return newErr(setAttrErr) @@ -158,7 +158,7 @@ func (t *Tsetattrclunk) handle(cs *connState) message { func (t *Tremove) handle(cs *connState) message { ref, ok := cs.LookupFID(t.FID) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() @@ -172,7 +172,7 @@ func (t *Tremove) handle(cs *connState) message { err := ref.safelyGlobal(func() error { // Is this a root? Can't remove that. if ref.isRoot() { - return syscall.EINVAL + return unix.EINVAL } // N.B. this remove operation is permitted, even if the file is open. @@ -180,7 +180,7 @@ func (t *Tremove) handle(cs *connState) message { // Is this file already deleted? if ref.isDeleted() { - return syscall.EINVAL + return unix.EINVAL } // Retrieve the file's proper name. @@ -204,7 +204,7 @@ func (t *Tremove) handle(cs *connState) message { // of removing the file if permissions allow." // https://swtch.com/plan9port/man/man9/remove.html if !cs.DeleteFID(t.FID) { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } if err != nil { return newErr(err) @@ -217,14 +217,14 @@ func (t *Tremove) handle(cs *connState) message { // // We don't support authentication, so this just returns ENOSYS. func (t *Tauth) handle(cs *connState) message { - return newErr(syscall.ENOSYS) + return newErr(unix.ENOSYS) } // handle implements handler.handle. func (t *Tattach) handle(cs *connState) message { // Ensure no authentication FID is provided. if t.Auth.AuthenticationFID != NoFID { - return newErr(syscall.EINVAL) + return newErr(unix.EINVAL) } // Must provide an absolute path. @@ -247,7 +247,7 @@ func (t *Tattach) handle(cs *connState) message { } if !valid.Mode { sf.Close() // Drop file. - return newErr(syscall.EINVAL) + return newErr(unix.EINVAL) } // Build a transient reference. @@ -292,7 +292,7 @@ func CanOpen(mode FileMode) bool { func (t *Tlopen) handle(cs *connState) message { ref, ok := cs.LookupFID(t.FID) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() @@ -304,22 +304,22 @@ func (t *Tlopen) handle(cs *connState) message { if err := ref.safelyRead(func() (err error) { // Has it been deleted already? if ref.isDeleted() { - return syscall.EINVAL + return unix.EINVAL } // Has it been opened already? if ref.opened || !CanOpen(ref.mode) { - return syscall.EINVAL + return unix.EINVAL } if ref.mode.IsDir() { // Directory must be opened ReadOnly. if t.Flags&OpenFlagsModeMask != ReadOnly { - return syscall.EISDIR + return unix.EISDIR } // Directory not truncatable. if t.Flags&OpenTruncate != 0 { - return syscall.EISDIR + return unix.EISDIR } } @@ -345,7 +345,7 @@ func (t *Tlcreate) do(cs *connState, uid UID) (*Rlcreate, error) { ref, ok := cs.LookupFID(t.FID) if !ok { - return nil, syscall.EBADF + return nil, unix.EBADF } defer ref.DecRef() @@ -359,12 +359,12 @@ func (t *Tlcreate) do(cs *connState, uid UID) (*Rlcreate, error) { if err := ref.safelyWrite(func() (err error) { // Don't allow creation from non-directories or deleted directories. if ref.isDeleted() || !ref.mode.IsDir() { - return syscall.EINVAL + return unix.EINVAL } // Not allowed on open directories. if ref.opened { - return syscall.EINVAL + return unix.EINVAL } // Do the create. @@ -422,7 +422,7 @@ func (t *Tsymlink) do(cs *connState, uid UID) (*Rsymlink, error) { ref, ok := cs.LookupFID(t.Directory) if !ok { - return nil, syscall.EBADF + return nil, unix.EBADF } defer ref.DecRef() @@ -430,12 +430,12 @@ func (t *Tsymlink) do(cs *connState, uid UID) (*Rsymlink, error) { if err := ref.safelyWrite(func() (err error) { // Don't allow symlinks from non-directories or deleted directories. if ref.isDeleted() || !ref.mode.IsDir() { - return syscall.EINVAL + return unix.EINVAL } // Not allowed on open directories. if ref.opened { - return syscall.EINVAL + return unix.EINVAL } // Do the symlink. @@ -456,25 +456,25 @@ func (t *Tlink) handle(cs *connState) message { ref, ok := cs.LookupFID(t.Directory) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() refTarget, ok := cs.LookupFID(t.Target) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer refTarget.DecRef() if err := ref.safelyWrite(func() (err error) { // Don't allow create links from non-directories or deleted directories. if ref.isDeleted() || !ref.mode.IsDir() { - return syscall.EINVAL + return unix.EINVAL } // Not allowed on open directories. if ref.opened { - return syscall.EINVAL + return unix.EINVAL } // Do the link. @@ -497,13 +497,13 @@ func (t *Trenameat) handle(cs *connState) message { ref, ok := cs.LookupFID(t.OldDirectory) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() refTarget, ok := cs.LookupFID(t.NewDirectory) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer refTarget.DecRef() @@ -511,12 +511,12 @@ func (t *Trenameat) handle(cs *connState) message { if err := ref.safelyGlobal(func() (err error) { // Don't allow renaming across deleted directories. if ref.isDeleted() || !ref.mode.IsDir() || refTarget.isDeleted() || !refTarget.mode.IsDir() { - return syscall.EINVAL + return unix.EINVAL } // Not allowed on open directories. if ref.opened { - return syscall.EINVAL + return unix.EINVAL } // Is this the same file? If yes, short-circuit and return success. @@ -547,19 +547,19 @@ func (t *Tunlinkat) handle(cs *connState) message { ref, ok := cs.LookupFID(t.Directory) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() if err := ref.safelyWrite(func() (err error) { // Don't allow deletion from non-directories or deleted directories. if ref.isDeleted() || !ref.mode.IsDir() { - return syscall.EINVAL + return unix.EINVAL } // Not allowed on open directories. if ref.opened { - return syscall.EINVAL + return unix.EINVAL } // Before we do the unlink itself, we need to ensure that there @@ -599,25 +599,25 @@ func (t *Trename) handle(cs *connState) message { ref, ok := cs.LookupFID(t.FID) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() refTarget, ok := cs.LookupFID(t.Directory) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer refTarget.DecRef() if err := ref.safelyGlobal(func() (err error) { // Don't allow a root rename. if ref.isRoot() { - return syscall.EINVAL + return unix.EINVAL } // Don't allow renaming deleting entries, or target non-directories. if ref.isDeleted() || refTarget.isDeleted() || !refTarget.mode.IsDir() { - return syscall.EINVAL + return unix.EINVAL } // If the parent is deleted, but we not, something is seriously wrong. @@ -656,7 +656,7 @@ func (t *Trename) handle(cs *connState) message { func (t *Treadlink) handle(cs *connState) message { ref, ok := cs.LookupFID(t.FID) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() @@ -666,7 +666,7 @@ func (t *Treadlink) handle(cs *connState) message { // check if this file is opened because symlinks cannot be // opened. if ref.isDeleted() || !ref.mode.IsSymlink() { - return syscall.EINVAL + return unix.EINVAL } // Do the read. @@ -683,13 +683,13 @@ func (t *Treadlink) handle(cs *connState) message { func (t *Tread) handle(cs *connState) message { ref, ok := cs.LookupFID(t.FID) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() // Constrain the size of the read buffer. if int(t.Count) > int(maximumLength) { - return newErr(syscall.ENOBUFS) + return newErr(unix.ENOBUFS) } var ( @@ -699,12 +699,12 @@ func (t *Tread) handle(cs *connState) message { if err := ref.safelyRead(func() (err error) { // Has it been opened already? if !ref.opened { - return syscall.EINVAL + return unix.EINVAL } // Can it be read? Check permissions. if ref.openFlags&OpenFlagsModeMask == WriteOnly { - return syscall.EPERM + return unix.EPERM } n, err = ref.file.ReadAt(data, t.Offset) @@ -720,7 +720,7 @@ func (t *Tread) handle(cs *connState) message { func (t *Twrite) handle(cs *connState) message { ref, ok := cs.LookupFID(t.FID) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() @@ -728,12 +728,12 @@ func (t *Twrite) handle(cs *connState) message { if err := ref.safelyRead(func() (err error) { // Has it been opened already? if !ref.opened { - return syscall.EINVAL + return unix.EINVAL } // Can it be written? Check permissions. if ref.openFlags&OpenFlagsModeMask == ReadOnly { - return syscall.EPERM + return unix.EPERM } n, err = ref.file.WriteAt(t.Data, t.Offset) @@ -761,7 +761,7 @@ func (t *Tmknod) do(cs *connState, uid UID) (*Rmknod, error) { ref, ok := cs.LookupFID(t.Directory) if !ok { - return nil, syscall.EBADF + return nil, unix.EBADF } defer ref.DecRef() @@ -769,12 +769,12 @@ func (t *Tmknod) do(cs *connState, uid UID) (*Rmknod, error) { if err := ref.safelyWrite(func() (err error) { // Don't allow mknod on deleted files. if ref.isDeleted() || !ref.mode.IsDir() { - return syscall.EINVAL + return unix.EINVAL } // Not allowed on open directories. if ref.opened { - return syscall.EINVAL + return unix.EINVAL } // Do the mknod. @@ -803,7 +803,7 @@ func (t *Tmkdir) do(cs *connState, uid UID) (*Rmkdir, error) { ref, ok := cs.LookupFID(t.Directory) if !ok { - return nil, syscall.EBADF + return nil, unix.EBADF } defer ref.DecRef() @@ -811,12 +811,12 @@ func (t *Tmkdir) do(cs *connState, uid UID) (*Rmkdir, error) { if err := ref.safelyWrite(func() (err error) { // Don't allow mkdir on deleted files. if ref.isDeleted() || !ref.mode.IsDir() { - return syscall.EINVAL + return unix.EINVAL } // Not allowed on open directories. if ref.opened { - return syscall.EINVAL + return unix.EINVAL } // Do the mkdir. @@ -833,7 +833,7 @@ func (t *Tmkdir) do(cs *connState, uid UID) (*Rmkdir, error) { func (t *Tgetattr) handle(cs *connState) message { ref, ok := cs.LookupFID(t.FID) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() @@ -861,7 +861,7 @@ func (t *Tgetattr) handle(cs *connState) message { func (t *Tsetattr) handle(cs *connState) message { ref, ok := cs.LookupFID(t.FID) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() @@ -871,7 +871,7 @@ func (t *Tsetattr) handle(cs *connState) message { // there were multiple links and you can still change the // corresponding inode information. if ref.isDeleted() { - return syscall.EINVAL + return unix.EINVAL } // Set the attributes. @@ -887,24 +887,24 @@ func (t *Tsetattr) handle(cs *connState) message { func (t *Tallocate) handle(cs *connState) message { ref, ok := cs.LookupFID(t.FID) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() if err := ref.safelyWrite(func() error { // Has it been opened already? if !ref.opened { - return syscall.EINVAL + return unix.EINVAL } // Can it be written? Check permissions. if ref.openFlags&OpenFlagsModeMask == ReadOnly { - return syscall.EBADF + return unix.EBADF } // We don't allow allocate on files that have been deleted. if ref.isDeleted() { - return syscall.EINVAL + return unix.EINVAL } return ref.file.Allocate(t.Mode, t.Offset, t.Length) @@ -919,31 +919,31 @@ func (t *Tallocate) handle(cs *connState) message { func (t *Txattrwalk) handle(cs *connState) message { ref, ok := cs.LookupFID(t.FID) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() // We don't support extended attributes. - return newErr(syscall.ENODATA) + return newErr(unix.ENODATA) } // handle implements handler.handle. func (t *Txattrcreate) handle(cs *connState) message { ref, ok := cs.LookupFID(t.FID) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() // We don't support extended attributes. - return newErr(syscall.ENOSYS) + return newErr(unix.ENOSYS) } // handle implements handler.handle. func (t *Tgetxattr) handle(cs *connState) message { ref, ok := cs.LookupFID(t.FID) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() @@ -951,7 +951,7 @@ func (t *Tgetxattr) handle(cs *connState) message { if err := ref.safelyRead(func() (err error) { // Don't allow getxattr on files that have been deleted. if ref.isDeleted() { - return syscall.EINVAL + return unix.EINVAL } val, err = ref.file.GetXattr(t.Name, t.Size) return err @@ -965,14 +965,14 @@ func (t *Tgetxattr) handle(cs *connState) message { func (t *Tsetxattr) handle(cs *connState) message { ref, ok := cs.LookupFID(t.FID) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() if err := ref.safelyWrite(func() error { // Don't allow setxattr on files that have been deleted. if ref.isDeleted() { - return syscall.EINVAL + return unix.EINVAL } return ref.file.SetXattr(t.Name, t.Value, t.Flags) }); err != nil { @@ -985,7 +985,7 @@ func (t *Tsetxattr) handle(cs *connState) message { func (t *Tlistxattr) handle(cs *connState) message { ref, ok := cs.LookupFID(t.FID) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() @@ -993,7 +993,7 @@ func (t *Tlistxattr) handle(cs *connState) message { if err := ref.safelyRead(func() (err error) { // Don't allow listxattr on files that have been deleted. if ref.isDeleted() { - return syscall.EINVAL + return unix.EINVAL } xattrs, err = ref.file.ListXattr(t.Size) return err @@ -1012,14 +1012,14 @@ func (t *Tlistxattr) handle(cs *connState) message { func (t *Tremovexattr) handle(cs *connState) message { ref, ok := cs.LookupFID(t.FID) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() if err := ref.safelyWrite(func() error { // Don't allow removexattr on files that have been deleted. if ref.isDeleted() { - return syscall.EINVAL + return unix.EINVAL } return ref.file.RemoveXattr(t.Name) }); err != nil { @@ -1032,7 +1032,7 @@ func (t *Tremovexattr) handle(cs *connState) message { func (t *Treaddir) handle(cs *connState) message { ref, ok := cs.LookupFID(t.Directory) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() @@ -1040,12 +1040,12 @@ func (t *Treaddir) handle(cs *connState) message { if err := ref.safelyRead(func() (err error) { // Don't allow reading deleted directories. if ref.isDeleted() || !ref.mode.IsDir() { - return syscall.EINVAL + return unix.EINVAL } // Has it been opened yet? if !ref.opened { - return syscall.EINVAL + return unix.EINVAL } // Read the entries. @@ -1065,14 +1065,14 @@ func (t *Treaddir) handle(cs *connState) message { func (t *Tfsync) handle(cs *connState) message { ref, ok := cs.LookupFID(t.FID) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() if err := ref.safelyRead(func() (err error) { // Has it been opened yet? if !ref.opened { - return syscall.EINVAL + return unix.EINVAL } // Perform the sync. @@ -1088,7 +1088,7 @@ func (t *Tfsync) handle(cs *connState) message { func (t *Tstatfs) handle(cs *connState) message { ref, ok := cs.LookupFID(t.FID) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() @@ -1104,7 +1104,7 @@ func (t *Tstatfs) handle(cs *connState) message { func (t *Tflushf) handle(cs *connState) message { ref, ok := cs.LookupFID(t.FID) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() @@ -1121,7 +1121,7 @@ func (t *Tflushf) handle(cs *connState) message { func walkOne(qids []QID, from File, names []string, getattr bool) ([]QID, File, AttrMask, Attr, error) { if len(names) > 1 { // We require exactly zero or one elements. - return nil, nil, AttrMask{}, Attr{}, syscall.EINVAL + return nil, nil, AttrMask{}, Attr{}, unix.EINVAL } var ( localQIDs []QID @@ -1134,7 +1134,7 @@ func walkOne(qids []QID, from File, names []string, getattr bool) ([]QID, File, case getattr: localQIDs, sf, valid, attr, err = from.WalkGetAttr(names) // Can't put fallthrough in the if because Go. - if err != syscall.ENOSYS { + if err != unix.ENOSYS { break } fallthrough @@ -1159,7 +1159,7 @@ func walkOne(qids []QID, from File, names []string, getattr bool) ([]QID, File, if len(localQIDs) != 1 { // Expected a single QID. sf.Close() - return nil, nil, AttrMask{}, Attr{}, syscall.EINVAL + return nil, nil, AttrMask{}, Attr{}, unix.EINVAL } return append(qids, localQIDs...), sf, valid, attr, nil } @@ -1181,7 +1181,7 @@ func doWalk(cs *connState, ref *fidRef, names []string, getattr bool) (qids []QI // Has it been opened already? err = ref.safelyRead(func() (err error) { if ref.opened { - return syscall.EBUSY + return unix.EBUSY } return nil }) @@ -1237,7 +1237,7 @@ func doWalk(cs *connState, ref *fidRef, names []string, getattr bool) (qids []QI // a proper directory and we have additional paths to walk. if !walkRef.mode.IsDir() { walkRef.DecRef() // Drop walk reference; no lock required. - return nil, nil, AttrMask{}, Attr{}, syscall.EINVAL + return nil, nil, AttrMask{}, Attr{}, unix.EINVAL } var sf File // Temporary. @@ -1283,7 +1283,7 @@ func doWalk(cs *connState, ref *fidRef, names []string, getattr bool) (qids []QI func (t *Twalk) handle(cs *connState) message { ref, ok := cs.LookupFID(t.FID) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() @@ -1303,7 +1303,7 @@ func (t *Twalk) handle(cs *connState) message { func (t *Twalkgetattr) handle(cs *connState) message { ref, ok := cs.LookupFID(t.FID) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() @@ -1359,7 +1359,7 @@ func (t *Tumknod) handle(cs *connState) message { func (t *Tlconnect) handle(cs *connState) message { ref, ok := cs.LookupFID(t.FID) if !ok { - return newErr(syscall.EBADF) + return newErr(unix.EBADF) } defer ref.DecRef() @@ -1367,7 +1367,7 @@ func (t *Tlconnect) handle(cs *connState) message { if err := ref.safelyRead(func() (err error) { // Don't allow connecting to deleted files. if ref.isDeleted() || !ref.mode.IsSocket() { - return syscall.EINVAL + return unix.EINVAL } // Do the connect. @@ -1391,7 +1391,7 @@ func (t *Tchannel) handle(cs *connState) message { ch := cs.lookupChannel(t.ID) if ch == nil { - return newErr(syscall.ENOSYS) + return newErr(unix.ENOSYS) } // Return the payload. Note that we need to duplicate the file @@ -1405,19 +1405,19 @@ func (t *Tchannel) handle(cs *connState) message { switch t.Control { case 0: // Open the main data channel. - mfd, err := syscall.Dup(int(cs.channelAlloc.FD())) + mfd, err := unix.Dup(int(cs.channelAlloc.FD())) if err != nil { return newErr(err) } rchannel.SetFilePayload(fd.New(mfd)) case 1: - cfd, err := syscall.Dup(ch.client.FD()) + cfd, err := unix.Dup(ch.client.FD()) if err != nil { return newErr(err) } rchannel.SetFilePayload(fd.New(cfd)) default: - return newErr(syscall.EINVAL) + return newErr(unix.EINVAL) } return rchannel } diff --git a/pkg/p9/p9test/BUILD b/pkg/p9/p9test/BUILD index 7ca67cb19..9c1ada0cb 100644 --- a/pkg/p9/p9test/BUILD +++ b/pkg/p9/p9test/BUILD @@ -71,6 +71,7 @@ go_library( "//pkg/sync", "//pkg/unet", "@com_github_golang_mock//gomock:go_default_library", + "@org_golang_x_sys//unix:go_default_library", ], ) @@ -84,5 +85,6 @@ go_test( "//pkg/p9", "//pkg/sync", "@com_github_golang_mock//gomock:go_default_library", + "@org_golang_x_sys//unix:go_default_library", ], ) diff --git a/pkg/p9/p9test/client_test.go b/pkg/p9/p9test/client_test.go index 2e3d427ae..bb77e8e5f 100644 --- a/pkg/p9/p9test/client_test.go +++ b/pkg/p9/p9test/client_test.go @@ -22,11 +22,11 @@ import ( "os" "reflect" "strings" - "syscall" "testing" "time" "github.com/golang/mock/gomock" + "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/fd" "gvisor.dev/gvisor/pkg/p9" "gvisor.dev/gvisor/pkg/sync" @@ -45,7 +45,7 @@ func TestPanic(t *testing.T) { }) // Attach to the client. - if _, err := c.Attach("/"); err != syscall.EFAULT { + if _, err := c.Attach("/"); err != unix.EFAULT { t.Fatalf("got attach err %v, want EFAULT", err) } } @@ -75,11 +75,11 @@ func TestBadAttach(t *testing.T) { defer h.Finish() // Return an error on attach. - h.Attacher.EXPECT().Attach().Return(nil, syscall.EINVAL).Times(1) + h.Attacher.EXPECT().Attach().Return(nil, unix.EINVAL).Times(1) // Attach to the client. - if _, err := c.Attach("/"); err != syscall.EINVAL { - t.Fatalf("got attach err %v, want syscall.EINVAL", err) + if _, err := c.Attach("/"); err != unix.EINVAL { + t.Fatalf("got attach err %v, want unix.EINVAL", err) } } @@ -201,29 +201,29 @@ func TestWalkInvalid(t *testing.T) { // construct compound paths. They should all be rejected, as // any compound that contains a / is not allowed, as well as // the singular paths of '.' and '..'. - if _, _, err := root.Walk([]string{".", name}); err != syscall.EINVAL { + if _, _, err := root.Walk([]string{".", name}); err != unix.EINVAL { t.Errorf("Walk through . %s wanted EINVAL, got %v", name, err) } - if _, _, err := root.Walk([]string{"..", name}); err != syscall.EINVAL { + if _, _, err := root.Walk([]string{"..", name}); err != unix.EINVAL { t.Errorf("Walk through . %s wanted EINVAL, got %v", name, err) } - if _, _, err := root.Walk([]string{name, "."}); err != syscall.EINVAL { + if _, _, err := root.Walk([]string{name, "."}); err != unix.EINVAL { t.Errorf("Walk through %s . wanted EINVAL, got %v", name, err) } - if _, _, err := root.Walk([]string{name, ".."}); err != syscall.EINVAL { + if _, _, err := root.Walk([]string{name, ".."}); err != unix.EINVAL { t.Errorf("Walk through %s .. wanted EINVAL, got %v", name, err) } for _, invalidName := range allInvalidNames(name) { - if _, _, err := root.Walk([]string{invalidName}); err != syscall.EINVAL { + if _, _, err := root.Walk([]string{invalidName}); err != unix.EINVAL { t.Errorf("Walk through %s wanted EINVAL, got %v", invalidName, err) } } - wantErr := syscall.EINVAL + wantErr := unix.EINVAL if name == "directory" { // We can attempt a walk through a directory. However, // we should never see a file named "other", so we // expect this to return ENOENT. - wantErr = syscall.ENOENT + wantErr = unix.ENOENT } if _, _, err := root.Walk([]string{name, "other"}); err != wantErr { t.Errorf("Walk through %s/other wanted %v, got %v", name, wantErr, err) @@ -245,10 +245,10 @@ func TestWalkInvalid(t *testing.T) { } // Ensure we can't walk backwards. - if _, _, err := f.Walk([]string{"."}); err != syscall.EINVAL { + if _, _, err := f.Walk([]string{"."}); err != unix.EINVAL { t.Errorf("Walk through %s/. wanted EINVAL, got %v", name, err) } - if _, _, err := f.Walk([]string{".."}); err != syscall.EINVAL { + if _, _, err := f.Walk([]string{".."}); err != unix.EINVAL { t.Errorf("Walk through %s/.. wanted EINVAL, got %v", name, err) } } @@ -295,7 +295,7 @@ func walkAndOpenHelper(h *Harness, name string, dir p9.File) (*Mock, *Mock, p9.F } } else { // ... or assert an error for others. - if _, _, _, err := walked.Open(p9.ReadOnly); err != syscall.EINVAL { + if _, _, _, err := walked.Open(p9.ReadOnly); err != unix.EINVAL { h.t.Errorf("got open err %v, want EINVAL", err) } } @@ -344,42 +344,42 @@ type deprecatedRemover interface { func checkDeleted(h *Harness, file p9.File) { defer file.Close() // See doc. - if _, _, _, err := file.Open(p9.ReadOnly); err != syscall.EINVAL { + if _, _, _, err := file.Open(p9.ReadOnly); err != unix.EINVAL { h.t.Errorf("open while deleted, got %v, want EINVAL", err) } - if _, _, _, _, err := file.Create("created", p9.ReadOnly, 0, 0, 0); err != syscall.EINVAL { + if _, _, _, _, err := file.Create("created", p9.ReadOnly, 0, 0, 0); err != unix.EINVAL { h.t.Errorf("create while deleted, got %v, want EINVAL", err) } - if _, err := file.Symlink("old", "new", 0, 0); err != syscall.EINVAL { + if _, err := file.Symlink("old", "new", 0, 0); err != unix.EINVAL { h.t.Errorf("symlink while deleted, got %v, want EINVAL", err) } // N.B. This link is technically invalid, but if a call to link is // actually made in the backend then the mock will panic. - if err := file.Link(file, "new"); err != syscall.EINVAL { + if err := file.Link(file, "new"); err != unix.EINVAL { h.t.Errorf("link while deleted, got %v, want EINVAL", err) } - if err := file.RenameAt("src", file, "dst"); err != syscall.EINVAL { + if err := file.RenameAt("src", file, "dst"); err != unix.EINVAL { h.t.Errorf("renameAt while deleted, got %v, want EINVAL", err) } - if err := file.UnlinkAt("file", 0); err != syscall.EINVAL { + if err := file.UnlinkAt("file", 0); err != unix.EINVAL { h.t.Errorf("unlinkAt while deleted, got %v, want EINVAL", err) } - if err := file.Rename(file, "dst"); err != syscall.EINVAL { + if err := file.Rename(file, "dst"); err != unix.EINVAL { h.t.Errorf("rename while deleted, got %v, want EINVAL", err) } - if _, err := file.Readlink(); err != syscall.EINVAL { + if _, err := file.Readlink(); err != unix.EINVAL { h.t.Errorf("readlink while deleted, got %v, want EINVAL", err) } - if _, err := file.Mkdir("dir", p9.ModeDirectory, 0, 0); err != syscall.EINVAL { + if _, err := file.Mkdir("dir", p9.ModeDirectory, 0, 0); err != unix.EINVAL { h.t.Errorf("mkdir while deleted, got %v, want EINVAL", err) } - if _, err := file.Mknod("dir", p9.ModeDirectory, 0, 0, 0, 0); err != syscall.EINVAL { + if _, err := file.Mknod("dir", p9.ModeDirectory, 0, 0, 0, 0); err != unix.EINVAL { h.t.Errorf("mknod while deleted, got %v, want EINVAL", err) } - if _, err := file.Readdir(0, 1); err != syscall.EINVAL { + if _, err := file.Readdir(0, 1); err != unix.EINVAL { h.t.Errorf("readdir while deleted, got %v, want EINVAL", err) } - if _, err := file.Connect(p9.ConnectFlags(0)); err != syscall.EINVAL { + if _, err := file.Connect(p9.ConnectFlags(0)); err != unix.EINVAL { h.t.Errorf("connect while deleted, got %v, want EINVAL", err) } @@ -387,7 +387,7 @@ func checkDeleted(h *Harness, file p9.File) { // that it still checks for deleted appropriately. We must first clone // the file because remove is equivalent to close. _, newFile, err := file.Walk(nil) - if err == syscall.EBUSY { + if err == unix.EBUSY { // We can't walk from here because this reference is open // already. Okay, we will also have unopened cases through // TestUnlink, just skip the remove operation for now. @@ -395,7 +395,7 @@ func checkDeleted(h *Harness, file p9.File) { } else if err != nil { h.t.Fatalf("clone failed, got %v, want nil", err) } - if err := newFile.(deprecatedRemover).Remove(); err != syscall.EINVAL { + if err := newFile.(deprecatedRemover).Remove(); err != unix.EINVAL { h.t.Errorf("remove while deleted, got %v, want EINVAL", err) } } @@ -428,8 +428,8 @@ func remove(parent p9.File, name string) error { } // Ensure that the remove closed the file. - if err := newFile.(deprecatedRemover).Remove(); err != syscall.EBADF { - return syscall.EBADF // Propagate this code. + if err := newFile.(deprecatedRemover).Remove(); err != unix.EBADF { + return unix.EBADF // Propagate this code. } return nil @@ -529,7 +529,7 @@ func TestUnlinkAtInvalid(t *testing.T) { for name := range newTypeMap(nil) { for _, invalidName := range allInvalidNames(name) { - if err := root.UnlinkAt(invalidName, 0); err != syscall.EINVAL { + if err := root.UnlinkAt(invalidName, 0); err != unix.EINVAL { t.Errorf("got %v for name %q, want EINVAL", err, invalidName) } } @@ -686,7 +686,7 @@ func renameHelper(h *Harness, root p9.File, srcNames []string, dstNames []string // technically allowed and a no-op, but all the // triggers will fire. if !selfRename { - expectedErr = syscall.EINVAL + expectedErr = unix.EINVAL } dst.Close() } @@ -827,7 +827,7 @@ func TestRenameInvalid(t *testing.T) { for name := range newTypeMap(nil) { for _, invalidName := range allInvalidNames(name) { - if err := root.Rename(root, invalidName); err != syscall.EINVAL { + if err := root.Rename(root, invalidName); err != unix.EINVAL { t.Errorf("got %v for name %q, want EINVAL", err, invalidName) } } @@ -843,10 +843,10 @@ func TestRenameAtInvalid(t *testing.T) { for name := range newTypeMap(nil) { for _, invalidName := range allInvalidNames(name) { - if err := root.RenameAt(invalidName, root, "okay"); err != syscall.EINVAL { + if err := root.RenameAt(invalidName, root, "okay"); err != unix.EINVAL { t.Errorf("got %v for name %q, want EINVAL", err, invalidName) } - if err := root.RenameAt("okay", root, invalidName); err != syscall.EINVAL { + if err := root.RenameAt("okay", root, invalidName); err != unix.EINVAL { t.Errorf("got %v for name %q, want EINVAL", err, invalidName) } } @@ -935,7 +935,7 @@ func TestReadlink(t *testing.T) { // Attempt a Readlink operation. target, err := f.Readlink() - if err != nil && err != syscall.EINVAL { + if err != nil && err != unix.EINVAL { t.Errorf("readlink got %v, wanted EINVAL", err) } else if err == nil && target != symlinkTarget { t.Errorf("readlink got %v, wanted %v", target, symlinkTarget) @@ -998,7 +998,7 @@ func TestConnect(t *testing.T) { // Catch all the non-socket cases. if !backend.Attr.Mode.IsSocket() { // This has been set up to fail if Connect is called. - if _, err := f.Connect(p9.ConnectFlags(0)); err != syscall.EINVAL { + if _, err := f.Connect(p9.ConnectFlags(0)); err != unix.EINVAL { t.Errorf("connect got %v, wanted EINVAL", err) } return @@ -1033,20 +1033,20 @@ func TestReaddir(t *testing.T) { // Catch all the non-directory cases. if !backend.Attr.Mode.IsDir() { // This has also been set up to fail if Readdir is called. - if _, err := f.Readdir(0, 1); err != syscall.EINVAL { + if _, err := f.Readdir(0, 1); err != unix.EINVAL { t.Errorf("readdir got %v, wanted EINVAL", err) } return } // Ensure that readdir works for directories. - if _, err := f.Readdir(0, 1); err != syscall.EINVAL { + if _, err := f.Readdir(0, 1); err != unix.EINVAL { t.Errorf("readdir got %v, wanted EINVAL", err) } - if _, _, _, err := f.Open(p9.ReadWrite); err != syscall.EISDIR { + if _, _, _, err := f.Open(p9.ReadWrite); err != unix.EISDIR { t.Errorf("readdir got %v, wanted EISDIR", err) } - if _, _, _, err := f.Open(p9.WriteOnly); err != syscall.EISDIR { + if _, _, _, err := f.Open(p9.WriteOnly); err != unix.EISDIR { t.Errorf("readdir got %v, wanted EISDIR", err) } backend.EXPECT().Open(p9.ReadOnly).Times(1) @@ -1073,19 +1073,19 @@ func TestOpen(t *testing.T) { { name: "not-openable-read-only", flags: p9.ReadOnly, - err: syscall.EINVAL, + err: unix.EINVAL, match: func(mode p9.FileMode) bool { return !p9.CanOpen(mode) }, }, { name: "not-openable-write-only", flags: p9.WriteOnly, - err: syscall.EINVAL, + err: unix.EINVAL, match: func(mode p9.FileMode) bool { return !p9.CanOpen(mode) }, }, { name: "not-openable-read-write", flags: p9.ReadWrite, - err: syscall.EINVAL, + err: unix.EINVAL, match: func(mode p9.FileMode) bool { return !p9.CanOpen(mode) }, }, { @@ -1097,13 +1097,13 @@ func TestOpen(t *testing.T) { { name: "directory-read-write", flags: p9.ReadWrite, - err: syscall.EISDIR, + err: unix.EISDIR, match: func(mode p9.FileMode) bool { return mode.IsDir() }, }, { name: "directory-write-only", flags: p9.WriteOnly, - err: syscall.EISDIR, + err: unix.EISDIR, match: func(mode p9.FileMode) bool { return mode.IsDir() }, }, { @@ -1127,7 +1127,7 @@ func TestOpen(t *testing.T) { { name: "directory-read-only-truncate", flags: p9.ReadOnly | p9.OpenTruncate, - err: syscall.EISDIR, + err: unix.EISDIR, match: func(mode p9.FileMode) bool { return mode.IsDir() }, }, { @@ -1172,16 +1172,16 @@ func TestOpen(t *testing.T) { } // Ensure open-required operations fail. - if _, err := f.ReadAt([]byte("hello"), 0); err != syscall.EINVAL { + if _, err := f.ReadAt([]byte("hello"), 0); err != unix.EINVAL { t.Errorf("readAt got %v, wanted EINVAL", err) } - if _, err := f.WriteAt(make([]byte, 6), 0); err != syscall.EINVAL { + if _, err := f.WriteAt(make([]byte, 6), 0); err != unix.EINVAL { t.Errorf("writeAt got %v, wanted EINVAL", err) } - if err := f.FSync(); err != syscall.EINVAL { + if err := f.FSync(); err != unix.EINVAL { t.Errorf("fsync got %v, wanted EINVAL", err) } - if _, err := f.Readdir(0, 1); err != syscall.EINVAL { + if _, err := f.Readdir(0, 1); err != unix.EINVAL { t.Errorf("readdir got %v, wanted EINVAL", err) } @@ -1205,15 +1205,15 @@ func TestOpen(t *testing.T) { }) // If the open was successful, attempt another one. - if _, _, _, err := f.Open(tc.flags); err != syscall.EINVAL { + if _, _, _, err := f.Open(tc.flags); err != unix.EINVAL { t.Errorf("second open with flags %v got %v, want EINVAL", tc.flags, err) } // Ensure that all illegal operations fail. - if _, _, err := f.Walk(nil); err != syscall.EINVAL && err != syscall.EBUSY { + if _, _, err := f.Walk(nil); err != unix.EINVAL && err != unix.EBUSY { t.Errorf("walk got %v, wanted EINVAL or EBUSY", err) } - if _, _, _, _, err := f.WalkGetAttr(nil); err != syscall.EINVAL && err != syscall.EBUSY { + if _, _, _, _, err := f.WalkGetAttr(nil); err != unix.EINVAL && err != unix.EBUSY { t.Errorf("walkgetattr got %v, wanted EINVAL or EBUSY", err) } }) @@ -1271,70 +1271,70 @@ func TestClose(t *testing.T) { } // Everything should fail with EBADF. - if _, _, err := f.Walk(nil); err != syscall.EBADF { + if _, _, err := f.Walk(nil); err != unix.EBADF { t.Errorf("walk got %v, wanted EBADF", err) } - if _, err := f.StatFS(); err != syscall.EBADF { + if _, err := f.StatFS(); err != unix.EBADF { t.Errorf("statfs got %v, wanted EBADF", err) } - if _, _, _, err := f.GetAttr(p9.AttrMaskAll()); err != syscall.EBADF { + if _, _, _, err := f.GetAttr(p9.AttrMaskAll()); err != unix.EBADF { t.Errorf("getattr got %v, wanted EBADF", err) } - if err := f.SetAttr(p9.SetAttrMask{}, p9.SetAttr{}); err != syscall.EBADF { + if err := f.SetAttr(p9.SetAttrMask{}, p9.SetAttr{}); err != unix.EBADF { t.Errorf("setattrk got %v, wanted EBADF", err) } - if err := f.Rename(root, "new-name"); err != syscall.EBADF { + if err := f.Rename(root, "new-name"); err != unix.EBADF { t.Errorf("rename got %v, wanted EBADF", err) } - if err := f.Close(); err != syscall.EBADF { + if err := f.Close(); err != unix.EBADF { t.Errorf("close got %v, wanted EBADF", err) } - if _, _, _, err := f.Open(p9.ReadOnly); err != syscall.EBADF { + if _, _, _, err := f.Open(p9.ReadOnly); err != unix.EBADF { t.Errorf("open got %v, wanted EBADF", err) } - if _, err := f.ReadAt([]byte("hello"), 0); err != syscall.EBADF { + if _, err := f.ReadAt([]byte("hello"), 0); err != unix.EBADF { t.Errorf("readAt got %v, wanted EBADF", err) } - if _, err := f.WriteAt(make([]byte, 6), 0); err != syscall.EBADF { + if _, err := f.WriteAt(make([]byte, 6), 0); err != unix.EBADF { t.Errorf("writeAt got %v, wanted EBADF", err) } - if err := f.FSync(); err != syscall.EBADF { + if err := f.FSync(); err != unix.EBADF { t.Errorf("fsync got %v, wanted EBADF", err) } - if _, _, _, _, err := f.Create("new-file", p9.ReadWrite, 0, 0, 0); err != syscall.EBADF { + if _, _, _, _, err := f.Create("new-file", p9.ReadWrite, 0, 0, 0); err != unix.EBADF { t.Errorf("create got %v, wanted EBADF", err) } - if _, err := f.Mkdir("new-directory", 0, 0, 0); err != syscall.EBADF { + if _, err := f.Mkdir("new-directory", 0, 0, 0); err != unix.EBADF { t.Errorf("mkdir got %v, wanted EBADF", err) } - if _, err := f.Symlink("old-name", "new-name", 0, 0); err != syscall.EBADF { + if _, err := f.Symlink("old-name", "new-name", 0, 0); err != unix.EBADF { t.Errorf("symlink got %v, wanted EBADF", err) } - if err := f.Link(root, "new-name"); err != syscall.EBADF { + if err := f.Link(root, "new-name"); err != unix.EBADF { t.Errorf("link got %v, wanted EBADF", err) } - if _, err := f.Mknod("new-block-device", 0, 0, 0, 0, 0); err != syscall.EBADF { + if _, err := f.Mknod("new-block-device", 0, 0, 0, 0, 0); err != unix.EBADF { t.Errorf("mknod got %v, wanted EBADF", err) } - if err := f.RenameAt("old-name", root, "new-name"); err != syscall.EBADF { + if err := f.RenameAt("old-name", root, "new-name"); err != unix.EBADF { t.Errorf("renameAt got %v, wanted EBADF", err) } - if err := f.UnlinkAt("name", 0); err != syscall.EBADF { + if err := f.UnlinkAt("name", 0); err != unix.EBADF { t.Errorf("unlinkAt got %v, wanted EBADF", err) } - if _, err := f.Readdir(0, 1); err != syscall.EBADF { + if _, err := f.Readdir(0, 1); err != unix.EBADF { t.Errorf("readdir got %v, wanted EBADF", err) } - if _, err := f.Readlink(); err != syscall.EBADF { + if _, err := f.Readlink(); err != unix.EBADF { t.Errorf("readlink got %v, wanted EBADF", err) } - if err := f.Flush(); err != syscall.EBADF { + if err := f.Flush(); err != unix.EBADF { t.Errorf("flush got %v, wanted EBADF", err) } - if _, _, _, _, err := f.WalkGetAttr(nil); err != syscall.EBADF { + if _, _, _, _, err := f.WalkGetAttr(nil); err != unix.EBADF { t.Errorf("walkgetattr got %v, wanted EBADF", err) } - if _, err := f.Connect(p9.ConnectFlags(0)); err != syscall.EBADF { + if _, err := f.Connect(p9.ConnectFlags(0)); err != unix.EBADF { t.Errorf("connect got %v, wanted EBADF", err) } }) @@ -1350,7 +1350,7 @@ func onlyWorksOnOpenThings(h *Harness, t *testing.T, name string, root p9.File, defer f.Close() // Does it work before opening? - if err := fn(backend, f, false); err != syscall.EINVAL { + if err := fn(backend, f, false); err != unix.EINVAL { t.Errorf("operation got %v, wanted EINVAL", err) } @@ -1397,7 +1397,7 @@ func TestRead(t *testing.T) { { name: "write-only", mode: p9.WriteOnly, - err: syscall.EPERM, + err: unix.EPERM, }, } @@ -1455,7 +1455,7 @@ func TestWrite(t *testing.T) { { name: "read-only", mode: p9.ReadOnly, - err: syscall.EPERM, + err: unix.EPERM, }, { name: "read-write", @@ -1560,7 +1560,7 @@ func onlyWorksOnDirectories(h *Harness, t *testing.T, name string, root p9.File, // Only directories support mknod. if !backend.Attr.Mode.IsDir() { - if err := fn(backend, f, false); err != syscall.EINVAL { + if err := fn(backend, f, false); err != unix.EINVAL { t.Errorf("operation got %v, wanted EINVAL", err) } return // Nothing else to do. @@ -1578,7 +1578,7 @@ func onlyWorksOnDirectories(h *Harness, t *testing.T, name string, root p9.File, } // Should not work again. - if err := fn(backend, f, false); err != syscall.EINVAL { + if err := fn(backend, f, false); err != unix.EINVAL { t.Fatalf("operation got %v, wanted EINVAL", err) } } @@ -1640,7 +1640,7 @@ func TestCreateInvalid(t *testing.T) { for name := range newTypeMap(nil) { for _, invalidName := range allInvalidNames(name) { - if _, _, _, _, err := root.Create(invalidName, p9.ReadWrite, 0, 0, 0); err != syscall.EINVAL { + if _, _, _, _, err := root.Create(invalidName, p9.ReadWrite, 0, 0, 0); err != unix.EINVAL { t.Errorf("got %v for name %q, want EINVAL", err, invalidName) } } @@ -1676,7 +1676,7 @@ func TestMkdirInvalid(t *testing.T) { for name := range newTypeMap(nil) { for _, invalidName := range allInvalidNames(name) { - if _, err := root.Mkdir(invalidName, 0, 0, 0); err != syscall.EINVAL { + if _, err := root.Mkdir(invalidName, 0, 0, 0); err != unix.EINVAL { t.Errorf("got %v for name %q, want EINVAL", err, invalidName) } } @@ -1715,7 +1715,7 @@ func TestSyminkInvalid(t *testing.T) { // We need only test for invalid names in the new name, // the target can be an arbitrary string and we don't // need to sanity check it. - if _, err := root.Symlink("old-name", invalidName, 0, 0); err != syscall.EINVAL { + if _, err := root.Symlink("old-name", invalidName, 0, 0); err != unix.EINVAL { t.Errorf("got %v for name %q, want EINVAL", err, invalidName) } } @@ -1750,7 +1750,7 @@ func TestLinkInvalid(t *testing.T) { for name := range newTypeMap(nil) { for _, invalidName := range allInvalidNames(name) { - if err := root.Link(root, invalidName); err != syscall.EINVAL { + if err := root.Link(root, invalidName); err != unix.EINVAL { t.Errorf("got %v for name %q, want EINVAL", err, invalidName) } } @@ -2049,7 +2049,7 @@ func TestConcurrency(t *testing.T) { match: func(mode p9.FileMode) bool { return mode.IsDir() }, op: func(h *Harness, backend *Mock, f p9.File, callback func()) { // Return an error for the creation operation, as this is the simplest. - backend.EXPECT().Create(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil, p9.QID{}, uint32(0), syscall.EINVAL).Do(func(string, p9.OpenFlags, p9.FileMode, p9.UID, p9.GID) { + backend.EXPECT().Create(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil, p9.QID{}, uint32(0), unix.EINVAL).Do(func(string, p9.OpenFlags, p9.FileMode, p9.UID, p9.GID) { callback() }) f.Create(randomFileName(), p9.ReadOnly, 0, 0, 0) diff --git a/pkg/p9/p9test/p9test.go b/pkg/p9/p9test/p9test.go index dd8b01b6d..fd5ac3dbe 100644 --- a/pkg/p9/p9test/p9test.go +++ b/pkg/p9/p9test/p9test.go @@ -18,10 +18,10 @@ package p9test import ( "fmt" "sync/atomic" - "syscall" "testing" "github.com/golang/mock/gomock" + "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/p9" "gvisor.dev/gvisor/pkg/sync" "gvisor.dev/gvisor/pkg/unet" @@ -118,7 +118,7 @@ func (m *Mock) Walk(names []string) ([]p9.QID, p9.File, error) { return []p9.QID{nm.QID}, nm, nil } else if len(names) != 1 { m.harness.t.Fail() // Should not happen. - return nil, nil, syscall.EINVAL + return nil, nil, unix.EINVAL } if m.Attr.Mode.IsDir() { @@ -130,7 +130,7 @@ func (m *Mock) Walk(names []string) ([]p9.QID, p9.File, error) { return []p9.QID{nm.QID}, nm, nil } // No child found. - return nil, nil, syscall.ENOENT + return nil, nil, unix.ENOENT } // Call the underlying mock. diff --git a/pkg/p9/server.go b/pkg/p9/server.go index 290d5b9ce..ff1172ed6 100644 --- a/pkg/p9/server.go +++ b/pkg/p9/server.go @@ -18,8 +18,8 @@ import ( "io" "runtime/debug" "sync/atomic" - "syscall" + "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/fd" "gvisor.dev/gvisor/pkg/fdchannel" "gvisor.dev/gvisor/pkg/flipcall" @@ -483,7 +483,7 @@ func (cs *connState) lookupChannel(id uint32) *channel { func (cs *connState) handle(m message) (r message) { if !cs.reqGate.Enter() { // connState.stop() has been called; the connection is shutting down. - r = newErr(syscall.ECONNRESET) + r = newErr(unix.ECONNRESET) return } defer func() { @@ -498,7 +498,7 @@ func (cs *connState) handle(m message) (r message) { // Wrap in an EFAULT error; we don't really have a // better way to describe this kind of error. It will // usually manifest as a result of the test framework. - r = newErr(syscall.EFAULT) + r = newErr(unix.EFAULT) } }() if handler, ok := m.(handler); ok { @@ -506,7 +506,7 @@ func (cs *connState) handle(m message) (r message) { r = handler.handle(cs) } else { // Produce an ENOSYS error. - r = newErr(syscall.ENOSYS) + r = newErr(unix.ENOSYS) } return } diff --git a/pkg/p9/transport.go b/pkg/p9/transport.go index 02e665345..add607b9d 100644 --- a/pkg/p9/transport.go +++ b/pkg/p9/transport.go @@ -19,8 +19,8 @@ import ( "fmt" "io" "io/ioutil" - "syscall" + "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/fd" "gvisor.dev/gvisor/pkg/log" "gvisor.dev/gvisor/pkg/sync" @@ -187,7 +187,7 @@ func recv(s *unet.Socket, msize uint32, lookup lookupTagAndType) (Tag, message, // fds are caught and used is handled below, // and the fds variable will be set to nil. for _, fd := range fds { - syscall.Close(fd) + unix.Close(fd) } }() r.EnableFDs(0) @@ -323,7 +323,7 @@ func recv(s *unet.Socket, msize uint32, lookup lookupTagAndType) (Tag, message, // Close the rest. We support only one. for i := 1; i < len(fds); i++ { - syscall.Close(fds[i]) + unix.Close(fds[i]) } // Don't close in the defer. diff --git a/pkg/p9/transport_flipcall.go b/pkg/p9/transport_flipcall.go index 38038abdf..802254a90 100644 --- a/pkg/p9/transport_flipcall.go +++ b/pkg/p9/transport_flipcall.go @@ -16,8 +16,8 @@ package p9 import ( "runtime" - "syscall" + "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/fd" "gvisor.dev/gvisor/pkg/fdchannel" "gvisor.dev/gvisor/pkg/flipcall" @@ -236,7 +236,7 @@ func (ch *channel) recv(r message, rsz uint32) (message, error) { // Convert errors appropriately; see above. if rlerr, ok := r.(*Rlerror); ok { - return r, syscall.Errno(rlerr.Error) + return r, unix.Errno(rlerr.Error) } return r, nil |