39 Commits
Author SHA1 Message Date
Tiwei Bie eca83ac68c Add initial support for EROFS
This patch adds initial support for EROFS [1]. Below is a brief
summary of the supported features.

Both inode formats are supported:

- compact format (32 bytes);
- extended format (64 bytes);

Below data layouts are supported:

- flat file data without data inline (no extent);
- flat file data with tail packing data inline (no extent);

Below file types are supported:

- directory;
- regular file;
- symlink;

Special files (e.g. fifo) can be listed, but cannot be accessed.

With this patch, sentry will be able to mount the EROFS image
created with below command and access the files on it.

 mkfs.erofs -E noinline_data <IMAGE FILE> <SOURCE DIRECTORY>

[1] https://docs.kernel.org/filesystems/erofs.html

Updates #8956

Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
2023-10-04 18:15:30 +08:00
Ayush RanjanandgVisor bot 4c5803c47f Improve lisafs debug log messages.
- Improves Statx prints. Used by Inode, which is in turn used by many messages.
  Now mode and timestamps are much more readable.
- Print all mask fields as hex for readability.
- Made WalkStatus readable.
- Improves printing of slices. Earlier, there was a ", " suffix which was
  confusing because it could look like an empty string entry. Now we print
  slices more meticulously.
- Consistently use Stringer implementations to print things, instead of %+v. So
  future improvements are easier to make.

PiperOrigin-RevId: 516895609
2023-03-15 12:20:52 -07:00
Nicolas LacasseandgVisor bot 7a0c4b5745 Ignore AT_NO_AUTOMOUNT flag in statx() calls.
gVisor does not support automount, so this flag is a no-op.

Confirmed that this fixes recent versions of 'ls':

$ docker run -ti --runtime=fig rockylinux:8.7 /bin/bash
[root@c6c749af0a7a /]# ls /
bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

PiperOrigin-RevId: 511376385
2023-02-21 20:10:44 -08:00
Konstantin BogomolovandgVisor bot 5c95e1d39c Implement close_range.
Fixes #5500

PiperOrigin-RevId: 431454836
2022-02-28 09:37:03 -08:00
Ayush RanjanandgVisor bot 0f7cbc8ecf Add debug logging for lisafs.
This change adds debug log messages for lisafs RPC messages just like the p9
package does. This is needed to make lisafs more production ready.

Note that we can not simply call fmt.Sprintf("%+v", message) because fmt
methods accept arguments as interface{} and hence escape them to the heap.
Doing so would cause all messages (which have a temporary lifetime) to
unnecessarily escape to heap hence eroding memory performance. So the String
implementations in this change only escape the struct's fields. Like this, the
struct's fields are heap allocated only when String() is called and in the
common case where debug logging is disabled, String() is not called.

In some cases, there has also been made an effort to not let slice fields
escape because some callers use statically sized arrays as slices which are not
intended to escape.

PiperOrigin-RevId: 428255508
2022-02-12 16:23:53 -08:00
Jamie LiuandgVisor bot 5ef032d4df Implement faccessat2.
PiperOrigin-RevId: 425432076
2022-01-31 12:25:27 -08:00
Ayush RanjanandgVisor bot 0fd9b69d5c Add Checked methods to go_marshal.
This is as per proposal in #6450. I have gated this behind a tag because this
is a very sparsely used feature and otherwise will leads to a lot of unused
generated code.

Secondly, we can not generate the CheckUnmarshal method for dynamic types. So
the dynamic tag would now require its users to additionally implement
CheckUnmarshal method which is more cumbersome.

Fixes #6450

PiperOrigin-RevId: 411197734
2021-11-19 20:16:54 -08:00
Ayush RanjanandgVisor bot 6fccc18560 [lisa] Implement lisafs protocol methods in VFS2 gofer client and fsgofer.
Introduces RPC methods in lisafs. Makes that gofer client use lisafs RPCs
instead of p9 when lisafs is enabled.

Implements the handlers for those methods in fsgofer.

Fixes #5465

PiperOrigin-RevId: 398080310
2021-09-21 14:09:18 -07:00
Rahat MahmoodandgVisor bot e00bd82816 Remove uses of the binary package from the rest of the sentry.
PiperOrigin-RevId: 372020696
2021-05-04 16:41:08 -07:00
Dean DengandgVisor bot 6c099d8300 Update preadv2/pwritev2 flag handling in vfs2.
We do not support RWF_SYNC/RWF_DSYNC and probably shouldn't silently accept
them, since the user may incorrectly believe that we are synchronizing I/O.
Remove the pwritev2 test verifying that we support these flags.

gvisor.dev/issue/2601 is the tracking bug for deciding which RWF_.* flags
we need and supporting them.

Updates #2923, #2601.

PiperOrigin-RevId: 319351286
2020-07-01 22:04:42 -07:00
Fabricio VoznikaandgVisor bot de694e5484 Combine file mode and isDir arguments
Updates #1035

PiperOrigin-RevId: 303021328
2020-03-26 08:48:04 -07:00
Dean DengandgVisor bot 5e413cad10 Plumb VFS2 imported fds into virtual filesystem.
- When setting up the virtual filesystem, mount a host.filesystem to contain
  all files that need to be imported.
- Make read/preadv syscalls to the host in cases where preadv2 may not be
  supported yet (likewise for writing).
- Make save/restore functions in kernel/kernel.go return early if vfs2 is
  enabled.

PiperOrigin-RevId: 300922353
2020-03-14 07:14:33 -07:00
Jamie LiuandgVisor bot 471b15b212 Port most syscalls to VFS2.
pipe and pipe2 aren't ported, pending a slight rework of pipe FDs for VFS2.
mount and umount2 aren't ported out of temporary laziness. access and faccessat
need additional FSImpl methods to implement properly, but are stubbed to
prevent googletest from CHECK-failing. Other syscalls require additional
plumbing.

Updates #1623

PiperOrigin-RevId: 297188448
2020-02-25 13:37:34 -08:00
gVisor bot 0693fb05d1 Merge pull request #1505 from xiaobo55x:fcntl_flags
PiperOrigin-RevId: 290840484
2020-01-21 17:02:56 -08:00
Rahat MahmoodandgVisor bot ad1968ed56 Implement sysfs.
PiperOrigin-RevId: 290822487
2020-01-21 15:13:26 -08:00
Haibo Xu de0d127ae6 Make some of the fcntl flags arch specific..
Some of the flags in the file system related system call
are architecture specific(O_NOFOLLOW/O_DIRECT..). Ref to
the fcntl.h file in the Linux src codes.

Signed-off-by: Haibo Xu <haibo.xu@arm.com>
Change-Id: I354d988073bfd0c9ff5371d4e0be9da2b8fd019f
2020-01-06 06:11:07 +00:00
Rahat MahmoodandgVisor bot 007707a072 Implement kernfs.
PiperOrigin-RevId: 285231002
2019-12-12 11:20:47 -08:00
Jamie LiuandgVisor bot 46651a7d26 Add most VFS methods for syscalls.
PiperOrigin-RevId: 284892289
2019-12-10 18:21:07 -08:00
Bin Lu 7f9c391cf1 slight changes to pkg/abi
In glibc, some structures are defined differently on different
platforms.
Such as: C.struct_stat

Signed-off-by: Bin Lu <bin.lu@arm.com>
2019-10-24 09:15:29 +00:00
Kevin KrakauerandgVisor bot 7ef1c44a7f Change linux.FileMode from uint to uint16, and update VFS to use FileMode.
In Linux (include/linux/types.h), mode_t is an unsigned short.

PiperOrigin-RevId: 272956350
2019-10-04 14:20:32 -07:00
Zach KoopmansandgVisor bot 67d7864f83 Document RWF_HIPRI not implemented for preadv2/pwritev2.
Document limitation of no reasonable implementation for RWF_HIPRI
flag (High Priority Read/Write for block-based file systems).

PiperOrigin-RevId: 264237589
2019-08-19 14:07:44 -07:00
Jamie LiuandgVisor bot fdac770f31 Fix struct statx field alignment.
PiperOrigin-RevId: 259376740
2019-07-22 12:04:21 -07:00
Jamie LiuandgVisor bot 163ab5e9ba Sentry virtual filesystem, v2
Major differences from the current ("v1") sentry VFS:

- Path resolution is Filesystem-driven (FilesystemImpl methods call
vfs.ResolvingPath methods) rather than VFS-driven (fs package owns a
Dirent tree and calls fs.InodeOperations methods to populate it). This
drastically improves performance, primarily by reducing overhead from
inefficient synchronization and indirection. It also makes it possible
to implement remote filesystem protocols that translate FS system calls
into single RPCs, rather than having to make (at least) one RPC per path
component, significantly reducing the latency of remote filesystems
(especially during cold starts and for uncacheable shared filesystems).

- Mounts are correctly represented as a separate check based on
contextual state (current mount) rather than direct replacement in a
fs.Dirent tree. This makes it possible to support (non-recursive) bind
mounts and mount namespaces.

Included in this CL is fsimpl/memfs, an incomplete in-memory filesystem
that exists primarily to demonstrate intended filesystem implementation
patterns and for benchmarking:

BenchmarkVFS1TmpfsStat/1-6               3000000               497 ns/op
BenchmarkVFS1TmpfsStat/2-6               2000000               676 ns/op
BenchmarkVFS1TmpfsStat/3-6               2000000               904 ns/op
BenchmarkVFS1TmpfsStat/8-6               1000000              1944 ns/op
BenchmarkVFS1TmpfsStat/64-6               100000             14067 ns/op
BenchmarkVFS1TmpfsStat/100-6               50000             21700 ns/op
BenchmarkVFS2MemfsStat/1-6              10000000               197 ns/op
BenchmarkVFS2MemfsStat/2-6               5000000               233 ns/op
BenchmarkVFS2MemfsStat/3-6               5000000               268 ns/op
BenchmarkVFS2MemfsStat/8-6               3000000               477 ns/op
BenchmarkVFS2MemfsStat/64-6               500000              2592 ns/op
BenchmarkVFS2MemfsStat/100-6              300000              4045 ns/op
BenchmarkVFS1TmpfsMountStat/1-6          2000000               679 ns/op
BenchmarkVFS1TmpfsMountStat/2-6          2000000               912 ns/op
BenchmarkVFS1TmpfsMountStat/3-6          1000000              1113 ns/op
BenchmarkVFS1TmpfsMountStat/8-6          1000000              2118 ns/op
BenchmarkVFS1TmpfsMountStat/64-6                  100000             14251 ns/op
BenchmarkVFS1TmpfsMountStat/100-6                 100000             22397 ns/op
BenchmarkVFS2MemfsMountStat/1-6                  5000000               317 ns/op
BenchmarkVFS2MemfsMountStat/2-6                  5000000               361 ns/op
BenchmarkVFS2MemfsMountStat/3-6                  5000000               387 ns/op
BenchmarkVFS2MemfsMountStat/8-6                  3000000               582 ns/op
BenchmarkVFS2MemfsMountStat/64-6                  500000              2699 ns/op
BenchmarkVFS2MemfsMountStat/100-6                 300000              4133 ns/op

From this we can infer that, on this machine:

- Constant cost for tmpfs stat() is ~160ns in VFS2 and ~280ns in VFS1.

- Per-path-component cost is ~35ns in VFS2 and ~215ns in VFS1, a
difference of about 6x.

- The cost of crossing a mount boundary is about 80ns in VFS2
(MemfsMountStat/1 does approximately the same amount of work as
MemfsStat/2, except that it also crosses a mount boundary). This is an
inescapable cost of the separate mount lookup needed to support bind
mounts and mount namespaces.

PiperOrigin-RevId: 258853946
2019-07-18 15:10:29 -07:00
Jamie LiuandgVisor bot 2bc398bfd8 Separate O_DSYNC and O_SYNC.
PiperOrigin-RevId: 258657913
2019-07-17 15:52:38 -07:00
Adin ScannellandgVisor bot cceef9d2cf Cleanup straggling syscall dependencies.
PiperOrigin-RevId: 257293198
2019-07-09 16:18:02 -07:00