Skip to content

Commit c213366

Browse files
relkochtagvisor-bot
authored andcommitted
New mount API: implement fsopen(2), fsconfig(2), fsmount(2), move_mount(2).
The first step in implementing the new file-descriptor based mount API in gVisor. A "filesystem creation context" is created using fsopen(). The context is then configured using fsconfig(), and the FSCONFIG_CMD_CREATE command is used to create a filesystem. A "mount object" can be obtained using fsmount(), which can be operated on directly using the *at() functions or mounted onto the real directory tree using move_mount(). For compatibility reasons, the new mount API is gated behind the runtime flag `--new-mount-api`, which is disabled by default. The current implementation has the following limitations: - Linux passes configuration options to filesystems on-the-fly as fsopen() and fsconfig() are called, allowing per-parameter error handling. gVisor currently queues up all options and passes them to the filesystem all-at-once when FSCONFIG_CMD_CREATE occurs. Lifting this will require refactoring the option parsing for all existing filesystems. - Only flag and string arguments to fsconfig() are supported. - Reconfiguration of the filesystem through fsconfig() is not supported. - move_mount(): flags MOVE_MOUNT_SET_GROUP and MOVE_MOUNT_BENEATH are not supported. - The filesystem context message retrieval interface is not supported. In the interest of review size, there is no implementation yet for open_tree(2) or fspick(2). PiperOrigin-RevId: 923640824
1 parent d1c3ea4 commit c213366

19 files changed

Lines changed: 1674 additions & 16 deletions

File tree

pkg/abi/linux/file.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,56 @@ const (
100100
UMOUNT_NOFOLLOW = 0x8
101101
)
102102

103+
// Constants for fsopen(2).
104+
const (
105+
FSOPEN_CLOEXEC = 0x1
106+
)
107+
108+
// Constants for fsconfig(2).
109+
const (
110+
FSCONFIG_SET_FLAG = 0x0
111+
FSCONFIG_SET_STRING = 0x1
112+
FSCONFIG_SET_BINARY = 0x2
113+
FSCONFIG_SET_PATH = 0x3
114+
FSCONFIG_SET_PATH_EMPTY = 0x4
115+
FSCONFIG_SET_FD = 0x5
116+
FSCONFIG_CMD_CREATE = 0x6
117+
FSCONFIG_CMD_RECONFIGURE = 0x7
118+
FSCONFIG_CMD_CREATE_EXCL = 0x8
119+
)
120+
121+
// Constants for fsmount(2).
122+
const (
123+
FSMOUNT_CLOEXEC = 0x1
124+
)
125+
126+
// Constants for move_mount(2).
127+
const (
128+
MOVE_MOUNT_F_SYMLINKS = 0x00000001
129+
MOVE_MOUNT_F_AUTOMOUNTS = 0x00000002
130+
MOVE_MOUNT_F_EMPTY_PATH = 0x00000004
131+
MOVE_MOUNT_T_SYMLINKS = 0x00000010
132+
MOVE_MOUNT_T_AUTOMOUNTS = 0x00000020
133+
MOVE_MOUNT_T_EMPTY_PATH = 0x00000040
134+
MOVE_MOUNT_SET_GROUP = 0x00000100
135+
MOVE_MOUNT_BENEATH = 0x00000200
136+
)
137+
138+
// Constants for mount_setattr(2).
139+
const (
140+
MOUNT_ATTR_RDONLY = 0x00000001
141+
MOUNT_ATTR_NOSUID = 0x00000002
142+
MOUNT_ATTR_NODEV = 0x00000004
143+
MOUNT_ATTR_NOEXEC = 0x00000008
144+
MOUNT_ATTR__ATIME = 0x00000070
145+
MOUNT_ATTR_RELATIME = 0x00000000
146+
MOUNT_ATTR_NOATIME = 0x00000010
147+
MOUNT_ATTR_STRICTATIME = 0x00000020
148+
MOUNT_ATTR_NODIRATIME = 0x00000080
149+
MOUNT_ATTR_IDMAP = 0x00100000
150+
MOUNT_ATTR_NOSYMFOLLOW = 0x00200000
151+
)
152+
103153
// Constants for unlinkat(2).
104154
const (
105155
AT_REMOVEDIR = 0x200

pkg/sentry/fsimpl/fsconfigfd/BUILD

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
load("//tools:defs.bzl", "go_library")
2+
3+
package(default_applicable_licenses = ["//:license"])
4+
5+
licenses(["notice"])
6+
7+
go_library(
8+
name = "fsconfigfd",
9+
srcs = ["fsconfigfd.go"],
10+
visibility = ["//pkg/sentry:internal"],
11+
deps = [
12+
"//pkg/abi/linux",
13+
"//pkg/context",
14+
"//pkg/errors/linuxerr",
15+
"//pkg/sentry/kernel/auth",
16+
"//pkg/sentry/vfs",
17+
"//pkg/sync",
18+
],
19+
)

0 commit comments

Comments
 (0)