Commit Graph

73 Commits

Author SHA1 Message Date
Zach Koopmans 02370bbd31 [syserror] Convert remaining syserror definitions to linuxerr.
Convert remaining public errors (e.g. EINTR) from syserror to linuxerr.

PiperOrigin-RevId: 390471763
2021-08-12 15:19:12 -07:00
Zach Koopmans 1f2ce9f461 [syserror] Change p9 server to use linuxerr.
Change the p9 server to use *errors.Error defined in pkg linuxerr. Done
separate from the client so that we ensure different p9 server/client versions
work with each other.

PiperOrigin-RevId: 380084491
2021-06-17 17:54:11 -07:00
Fabricio Voznika 26adb3c474 Automated rollback of changelist 369686285
PiperOrigin-RevId: 371015541
2021-04-28 17:02:33 -07:00
Michael Pratt c2955339d8 Automated rollback of changelist 369325957
PiperOrigin-RevId: 369686285
2021-04-21 10:41:28 -07:00
Fabricio Voznika 276ff149a4 Add MultiGetAttr message to 9P
While using remote-validation, the vast majority of time spent during
FS operations is re-walking the path to check for modifications and
then closing the file given that in most cases it has not been
modified externally.

This change introduces a new 9P message called MultiGetAttr which bulks
query attributes of several files in one shot. The returned attributes are
then used to update cached dentries before they are walked. File attributes
are updated for files that still exist. Dentries that have been deleted are
removed from the cache. And negative cache entries are removed if a new
file/directory was created externally. Similarly, synthetic dentries are
replaced if a file/directory is created externally.

The bulk update needs to be carefull not to follow symlinks, cross mount
points, because the gofer doesn't know how to resolve symlinks and where
mounts points are located. It also doesn't walk to the parent ("..") to
avoid deadlocks.

Here are the results:

Workload        VFS1       VFS2     Change
bazel action     115s       70s	     28.8s
Stat/100      11,043us   7,623us      974us

Updates #1638

PiperOrigin-RevId: 369325957
2021-04-19 16:25:01 -07:00
Kevin Krakauer 92374e5197 setgid directory support in goferfs
Also adds support for clearing the setuid bit when appropriate (writing,
truncating, changing size, changing UID, or changing GID).

VFS2 only.

PiperOrigin-RevId: 364661835
2021-03-23 15:42:12 -07:00
Ayush Ranjan a9441aea27 [op] Replace syscall package usage with golang.org/x/sys/unix in pkg/.
The syscall package has been deprecated in favor of golang.org/x/sys.

Note that syscall is still used in the following places:
- pkg/sentry/socket/hostinet/stack.go: some netlink related functionalities
  are not yet available in golang.org/x/sys.
- syscall.Stat_t is still used in some places because os.FileInfo.Sys() still
  returns it and not unix.Stat_t.

Updates #214

PiperOrigin-RevId: 360701387
2021-03-03 10:25:58 -08:00
Jamie Liu 0462dfe9f8 Use sync.Gate in p9.connState.
sync.WaitGroup.Add(positive delta) is illegal if the WaitGroup counter is zero
and WaitGroup.Wait() may be called concurrently. This is problematic for
p9.connState.pendingWg, which counts inflight requests (so transitions from
zero are normal) and is waited-upon when receiving from the underlying Unix
domain socket returns an error, e.g. during connection shutdown. (Even if the
socket has been closed, new requests can still be concurrently received via
flipcall channels.)

PiperOrigin-RevId: 359416057
2021-02-24 18:16:51 -08:00
Adin Scannell 4e03e87547 Fix simple mistakes identified by goreportcard.
These are primarily simplification and lint mistakes. However, minor
fixes are also included and tests added where appropriate.

PiperOrigin-RevId: 351425971
2021-01-12 12:38:22 -08:00
Adin Scannell 4cba3904f4 Remove existing nogo exceptions.
PiperOrigin-RevId: 347047550
2020-12-11 12:06:49 -08:00
Michael Pratt b28dc25aea Remove p9.fidRef.openedMu
openedMu has lock ordering violations. Most locks go through OpenedFlag(),
which is usually taken after renameMu and opMu. On the other hand, Tlopen takes
openedMu before renameMu and opMu (via safelyRead).

Resolving this violation is simple: just drop openedMu. The opened and
openFlags fields are already protected by opMu in most cases, renameMu (for
write) in one case (via safelyGlobal), and only in doWalk by neither.

This is a bit ugly because opMu is supposed to be a "semantic" lock, but it
works. I'm open to other suggestions.

Note that doWalk has a race condition where a FID may open after the open check
but before actually walking. This race existed before this change as well; it
is not clear if it is problematic.

PiperOrigin-RevId: 346108483
2020-12-07 09:23:17 -08:00
Nicolas Lacasse 949742be88 Allow short writes from gofers.
They were returning io.ErrShortWrite, but that is not handled at higher levels
and resulted in a panic.

We can just return the short write directly from the p9 call without
ErrShortWrite.

PiperOrigin-RevId: 342960441
2020-11-17 15:39:48 -08:00
Fabricio Voznika e2d9a68eef Add support for TTY in multi-container
Fixes #2714

PiperOrigin-RevId: 342950412
2020-11-17 14:51:24 -08:00
Fabricio Voznika 37a217aca4 Implement setattr+clunk in 9P
This is to cover the common pattern: open->read/write->close,
where SetAttr needs to be called to update atime/mtime before
the file is closed.

Benchmark results:

BM_OpenReadClose/10240 CPU
setattr+clunk: 63783 ns
VFS2:          68109 ns
VFS1:          72507 ns

Updates #1198

PiperOrigin-RevId: 329628461
2020-09-01 19:22:12 -07:00
Jamie Liu 3fd4b83fa3 Remove use of channels from p9.connState legacy transport.
- Remove sendDone, which currently does nothing whatsoever (errors sent to the
  channel are completely unused). Instead, have request handlers log errors
  they get from p9.send() inline.

- Replace recvOkay and recvDone with recvMu/recvIdle/recvShutdown. In addition
  to being slightly clearer (IMO), this eliminates the p9.connState.service()
  goroutine, significantly reducing the overhead involved in passing connection
  receive access between goroutines (from buffered chan send/recv + unbuffered
  chan send/recv to just a mutex unlock/lock).

PiperOrigin-RevId: 327476755
2020-08-19 11:58:59 -07:00
Jamie Liu b3141b680f Wait for all p9 handlers to complete before server shutdown.
... including those invoked via flipcall.

PiperOrigin-RevId: 327283194
2020-08-18 12:32:14 -07:00
Fazlul Shahriar 49947d2eb9 Eliminate one allocation per send/recv for non-flipcall transport.
Ported from https://github.com/hugelgupf/p9/pull/44.

name               old time/op    new time/op    delta
SendRecvLegacy-6     61.5µs ± 6%    60.1µs ±11%     ~     (p=0.063 n=9+9)
SendRecv-6           40.7µs ± 2%    39.8µs ± 5%   -2.27%  (p=0.035 n=10+10)

name               old alloc/op   new alloc/op   delta
SendRecvLegacy-6       769B ± 0%      705B ± 0%   -8.37%  (p=0.000 n=8+10)
SendRecv-6             320B ± 0%      256B ± 0%  -20.00%  (p=0.000 n=10+10)

name               old allocs/op  new allocs/op  delta
SendRecvLegacy-6       25.0 ± 0%      23.0 ± 0%   -8.00%  (p=0.000 n=10+10)
SendRecv-6             14.0 ± 0%      12.0 ± 0%  -14.29%  (p=0.000 n=10+10)

PiperOrigin-RevId: 326127979
2020-08-11 16:43:23 -07:00
Sevki 033fe6d70a p9: fix `registry.get` ob1 bug 2020-07-21 22:42:18 +01:00
Zach Koopmans 6a90c88b97 Port fallocate to VFS2.
PiperOrigin-RevId: 319283715
2020-07-01 13:14:44 -07:00
Michael Pratt fadbfd83d9 Include panic message in log
PiperOrigin-RevId: 315745386
2020-06-10 12:38:20 -07:00
Dean Deng 8bb8027d55 Return EIO from p9 if sending/receiving fails.
Continues the modifications in cl/272963663. This prevents non-syscall errors
from being propogated to kernel/task_syscall.go:ExtractErrno(), which causes a
sentry panic.

PiperOrigin-RevId: 305913127
2020-04-10 11:36:57 -07:00
Dean Deng 2b4687a46b Handle os.LinkError in p9/handlers.go.
PiperOrigin-RevId: 305721329
2020-04-09 11:17:11 -07:00
Dean Deng 51e461cf9c Add concurrency guarantees to p9 extended attribute methods.
PiperOrigin-RevId: 305171772
2020-04-06 20:08:51 -07:00
Uros Prestor d151693530 Avoid sending a partial dirent when the Rreaddir response exceeds message limit.
PiperOrigin-RevId: 304542967
2020-04-02 22:03:20 -07:00
gVisor bot 50c493193b Un-export p9 message encode/decode functions.
These are not used outside of the p9 package.

PiperOrigin-RevId: 295200052
2020-02-14 12:23:10 -08:00
Dean Deng 17b9f5e662 Support listxattr and removexattr syscalls.
Note that these are only implemented for tmpfs, and other impls will still
return EOPNOTSUPP.

PiperOrigin-RevId: 293899385
2020-02-07 14:47:13 -08:00
Andrei Vagin 5ff780891e Move p9.pool to a separate package
PiperOrigin-RevId: 293617493
2020-02-06 10:07:45 -08:00
Adin Scannell d29e59af9f Standardize on tools directory.
PiperOrigin-RevId: 291745021
2020-01-27 12:21:00 -08:00
Dean Deng 1e7f0c822b Bump p9 version, adding corresponding checks to client_file.go.
PiperOrigin-RevId: 290145451
2020-01-16 15:39:19 -08:00
Dean Deng 07f2584979 Plumb getting/setting xattrs through InodeOperations and 9p gofer interfaces.
There was a very bare get/setxattr in the InodeOperations interface. Add
context.Context to both, size to getxattr, and flags to setxattr.
Note that extended attributes are passed around as strings in this
implementation, so size is automatically encoded into the value. Size is
added in getxattr so that implementations can return ERANGE if a value is larger
than can fit in the user-allocated buffer. This prevents us from unnecessarily
passing around an arbitrarily large xattr when the user buffer is actually too
small.

Don't use the existing xattrwalk and xattrcreate messages and define our
own, mainly for the sake of simplicity.

Extended attributes will be implemented in future commits.

PiperOrigin-RevId: 290121300
2020-01-16 12:56:33 -08:00
Ian Gudger 27500d529f New sync package.
* Rename syncutil to sync.
* Add aliases to sync types.
* Replace existing usage of standard library sync package.

This will make it easier to swap out synchronization primitives. For example,
this will allow us to use primitives from github.com/sasha-s/go-deadlock to
check for lock ordering violations.

Updates #1472

PiperOrigin-RevId: 289033387
2020-01-09 22:02:24 -08:00
Nicolas Lacasse 0881abdfdd Remove useless comments from p9/handlers.go.
These comments provided nothing, and have been copy-pasted into all
implementations. The code is clear without them.

I considered also removing the "handle implements handler.handle" comments, but
will let those stay for now.

PiperOrigin-RevId: 285876428
2019-12-16 16:32:59 -08:00
Nicolas Lacasse 012102eefd Pass OpenTruncate to gofer in Open call when opening file with O_TRUNC.
Note that the Sentry still calls Truncate() on the file before calling Open.

A new p9 version check was added to ensure that the p9 server can handle the
the OpenTruncate flag. If not, then the flag is stripped before sending.

PiperOrigin-RevId: 281609112
2019-11-20 15:07:16 -08:00
Jamie Liu 76039f8959 Do not set finalizer on p9.ClientFile.
Aside from the performance hit, there is no guarantee that p9.ClientFile's
finalizer runs before the associated p9.Client is closed.

PiperOrigin-RevId: 280702509
2019-11-15 11:40:52 -08:00
Jamie Liu f8ffadddb3 Add p9.OpenTruncate.
This is required to implement O_TRUNC correctly on filesystems backed by
gofers.

9P2000.L: "lopen prepares fid for file I/O. flags contains Linux open(2) flags
bits, e.g. O_RDONLY, O_RDWR, O_WRONLY."

open(2): "The argument flags must include one of the following access modes:
O_RDONLY, O_WRONLY, or O_RDWR. ... In addition, zero or more file creation
flags and file status flags can be bitwise-or'd in flags."

The reference 9P2000.L implementation also appears to expect arbitrary flags,
not just access modes, in Tlopen.flags:
https://github.com/chaos/diod/blob/master/diod/ops.c#L703

PiperOrigin-RevId: 278972683
2019-11-06 17:11:58 -08:00
Jamie Liu 5694bd080e Don't log "p9.channel.service: flipcall connection shutdown".
This gets quite spammy, especially in tests.

PiperOrigin-RevId: 277970468
2019-11-01 11:45:02 -07:00
Haibo Xu dec831b493 Cast the Stat_t.Nlink to uint64 on arm64.
Since the syscall.Stat_t.Nlink is defined as different types on
amd64 and arm64(uint64 and uint32 respectively), we need to cast
them to a unified uint64 type in gVisor code.

Signed-off-by: Haibo Xu <haibo.xu@arm.com>
Change-Id: I7542b99b195c708f3fc49b1cbe6adebdd2f6e96b
2019-10-28 05:56:03 +00:00
Jamie Liu b941e35761 Return EIO from p9 if flipcall.Endpoint.Connect() fails.
Also ensure that all flipcall transport errors not returned by p9 (converted to
EIO by the client, or dropped on the floor by channel server goroutines) are
logged.

PiperOrigin-RevId: 272963663
2019-10-04 14:56:53 -07:00
Adin Scannell 6c88f674af Add test for concurrent reads and writes.
PiperOrigin-RevId: 270789146
2019-09-23 16:44:30 -07:00
Jamie Liu e9af227a61 Fix p9 integration of flipcall.
- Do not call Rread.SetPayload(flipcall packet window) in p9.channel.recv().

- Ignore EINTR from ppoll() in p9.Client.watch().

- Clean up handling of client socket FD lifetimes so that p9.Client.watch()
  never ppoll()s a closed FD.

- Make p9test.Harness.Finish() call clientSocket.Shutdown() instead of
  clientSocket.Close() for the same reason.

- Rework channel reuse to avoid leaking channels in the following case (suppose
  we have two channels):

  sendRecvChannel
    len(channels) == 2 => idx = 1
    inuse[1] = ch0
                                        sendRecvChannel
                                          len(channels) == 1 => idx = 0
                                          inuse[0] = ch1
    inuse[1] = nil
  sendRecvChannel
    len(channels) == 1 => idx = 0
    inuse[0] = ch0
                                          inuse[0] = nil
    inuse[0] == nil => ch0 leaked

- Avoid deadlocking p9.Client.watch() by calling channelsWg.Wait() without
  holding channelsMu.

- Bump p9test:client_test size to medium.

PiperOrigin-RevId: 270200314
2019-09-19 22:52:56 -07:00
Adin Scannell a8834fc555 Update p9 to support flipcall.
PiperOrigin-RevId: 268845090
2019-09-12 23:37:31 -07:00
Michael Pratt df5d377521 Remove go_test from go_stateify and go_marshal
They are no-ops, so the standard rule works fine.

PiperOrigin-RevId: 268776264
2019-09-12 15:10:17 -07:00
Adin Scannell 6d204f6a34 Drop local_server support.
PiperOrigin-RevId: 255713414
2019-06-28 20:35:10 -07:00
Michael Pratt 5b41ba5d0e Fix various spelling issues in the documentation
Addresses obvious typos, in the documentation only.

COPYBARA_INTEGRATE_REVIEW=https://github.com/google/gvisor/pull/443 from Pixep:fix/documentation-spelling 4d0688164eafaf0b3010e5f4824b35d1e7176d65
PiperOrigin-RevId: 255477779
2019-06-27 14:25:50 -07:00
Michael Pratt 6f933a934f Remove O(n) lookup on unlink/rename
Currently, the path tracking in the gofer involves an O(n) lookup of
child fidRefs. This causes a significant overhead on unlinks in
directories with lots of child fidRefs (<4k).

In this transition, pathNode moves from sync.Map to normal synchronized
maps. There is a small chance of contention in walk, but the lock is
held for a very short time (and sync.Map also had a chance of requiring
locking).

OTOH, sync.Map makes it very difficult to add a fidRef reverse map.

PiperOrigin-RevId: 254489952
2019-06-21 16:27:26 -07:00
Michael Pratt c0317b28cb Update pathNode documentation to reflect reality
Neither fidRefs or children are (directly) synchronized by mu. Remove
the preconditions that say so.

That said, the surrounding does enforce some synchronization guarantees
(e.g., fidRef.renameChildTo does not atomically replace the child in the
maps). I've tried to note the need for callers to do this
synchronization.

I've also renamed the maps to what are (IMO) clearer names. As is, it is
not obvious that pathNode.fidRefs is a map of *child* fidRefs rather
than self fidRefs.

PiperOrigin-RevId: 254446965
2019-06-21 12:26:42 -07:00
Michael Pratt 9d2efaac5a Add renamed children pathNodes to target parent
Otherwise future renames may miss Renamed calls.

PiperOrigin-RevId: 254060946
2019-06-19 13:41:07 -07:00
Adin Scannell add40fd6ad Update canonical repository.
This can be merged after:
https://github.com/google/gvisor-website/pull/77
  or
https://github.com/google/gvisor-website/pull/78

PiperOrigin-RevId: 253132620
2019-06-13 16:50:15 -07:00
Jamie Liu 0c8603084d Add p9 and unet benchmarks.
PiperOrigin-RevId: 253122166
2019-06-13 15:53:43 -07:00
Michael Pratt 80cc2c78e5 Forward named pipe creation to the gofer
The backing 9p server must allow named pipe creation, which the runsc
fsgofer currently does not.

There are small changes to the overlay here. GetFile may block when
opening a named pipe, which can cause a deadlock:

1. open(O_RDONLY) -> copyMu.Lock() -> GetFile()
2. open(O_WRONLY) -> copyMu.Lock() -> Deadlock

A named pipe usable for writing must already be on the upper filesystem,
but we are still taking copyMu for write when checking for upper. That
can be changed to a read lock to fix the common case.

However, a named pipe on the lower filesystem would still deadlock in
open(O_WRONLY) when it tries to actually perform copy up (which would
simply return EINVAL). Move the copy up type check before taking copyMu
for write to avoid this.

p9 must be modified, as it was incorrectly removing the file mode when
sending messages on the wire.

PiperOrigin-RevId: 249154033
Change-Id: Id6637130e567b03758130eb6c7cdbc976384b7d6
2019-05-20 16:53:08 -07:00