Commit f1dad30
[kernel][zcrx] vmtest: add extra_mounts support for sharing host directories into VM
Summary:
Add first-class support for mounting arbitrary host directories into
vmtest VMs. This enables Use Case #3 from the Zero Copy Receive testing
plan (https://fburl.com/gdoc/msf9i6y0): local rapid iteration on a
devserver.
At the very least we'd need the kernel source mounted in, but having the ability to specify any directory makes it fit any use case.
Before this change, only a single directory was shared - fbcode. Which is not enough for the kernel use case.
Now, adding `extra_mounts = [("/path/to/dir", True)]` to a vm.host()
target does everything automatically:
- **Container level**: bind-mounts the path into the isolation container
using the existing antlir2_isolate inputs/outputs mechanism (read-only
or read-write based on the boolean flag).
- **VM level**: feeds the path into the existing virtiofs share machinery,
which starts virtiofsd, generates QEMU device args, and creates systemd
.mount unit files so the directory appears at the same path inside the
VM on boot.
For the ZCRX test, local development is now:
buck run -c zcrx.extra_share=/path/to/linux \
-c zcrx.prebuilt_vmlinux=/path/to/bzImage \
':fbnic-zcrx-vm[container]'
Design decisions:
- Each mount carries a read_only flag (Buck attr is a tuple of
(path, bool)), routed to inputs() for RO or outputs() for RW at
the container level, and to ShareOpts.read_only at the VM level.
- No canonicalize() on mount paths. Symlink resolution is left to the
nspawn --bind-ro mechanism, avoiding path mismatches when /home is
a symlink to /data/users (common on devservers).
Test Plan:
1. Built machine_json sub-target with extra_share config, verified JSON serialization:
```
buck2 build fbcode//kernel/vmtest/iouring_zcrx:fbnic-zcrx-vm[machine_json] -c zcrx.extra_share=/tmp/test_extra_mount
```
Produces correct `{"path": ["/tmp/test_extra_mount"], "read_only": true}`.
2. Ran the VM with extra_share and verified RO enforcement:
```
buck2 run fbcode//kernel/vmtest/iouring_zcrx:fbnic-zcrx-vm \
-c zcrx.extra_share=/tmp/test_extra_mount \
-c zcrx.prebuilt_vmlinux=.../bzImage \
-- --timeout-secs 30 -- sh -c \
'if touch /tmp/test_extra_mount/write_test 2>/dev/null; then echo FAIL; else echo PASS; fi'
```
Output: `PASS: write denied on RO mount`
3. Verified symlinked paths work correctly (no canonicalize mismatch).
4. Confirmed nspawn backend routes inputs->--bind-ro and outputs->--bind (isolate_nspawn/src/lib.rs).;
5. Confirmed working RW in `buck run -c zcrx.extra_share=/home/mkutsevol/linux ':iouring-zcrx-test[shell]'`
Reviewed By: wujj123456
Differential Revision: D95386284
fbshipit-source-id: 6031019e294a8f4150fab2a3496250c8fd00c0271 parent 9ba751d commit f1dad30
File tree
5 files changed
+115
-33
lines changed- antlir/antlir2/antlir2_vm
- bzl
- src
5 files changed
+115
-33
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| |||
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| 65 | + | |
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
| |||
154 | 156 | | |
155 | 157 | | |
156 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
157 | 165 | | |
158 | 166 | | |
159 | 167 | | |
| |||
168 | 176 | | |
169 | 177 | | |
170 | 178 | | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
171 | 185 | | |
172 | 186 | | |
173 | 187 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| 90 | + | |
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
| 95 | + | |
94 | 96 | | |
95 | 97 | | |
96 | 98 | | |
| |||
103 | 105 | | |
104 | 106 | | |
105 | 107 | | |
| 108 | + | |
106 | 109 | | |
107 | 110 | | |
108 | 111 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | 99 | | |
103 | 100 | | |
104 | 101 | | |
| |||
190 | 187 | | |
191 | 188 | | |
192 | 189 | | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | 190 | | |
197 | 191 | | |
198 | 192 | | |
| |||
205 | 199 | | |
206 | 200 | | |
207 | 201 | | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
217 | 218 | | |
218 | 219 | | |
219 | 220 | | |
| |||
357 | 358 | | |
358 | 359 | | |
359 | 360 | | |
360 | | - | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
361 | 371 | | |
362 | 372 | | |
363 | 373 | | |
364 | | - | |
| 374 | + | |
| 375 | + | |
365 | 376 | | |
366 | 377 | | |
367 | 378 | | |
| |||
376 | 387 | | |
377 | 388 | | |
378 | 389 | | |
379 | | - | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
380 | 400 | | |
381 | 401 | | |
382 | 402 | | |
383 | | - | |
| 403 | + | |
| 404 | + | |
384 | 405 | | |
385 | 406 | | |
386 | 407 | | |
| |||
405 | 426 | | |
406 | 427 | | |
407 | 428 | | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
408 | 436 | | |
409 | 437 | | |
410 | 438 | | |
| |||
415 | 443 | | |
416 | 444 | | |
417 | 445 | | |
418 | | - | |
| 446 | + | |
419 | 447 | | |
420 | | - | |
| 448 | + | |
421 | 449 | | |
422 | 450 | | |
423 | 451 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
297 | 297 | | |
298 | 298 | | |
299 | 299 | | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
300 | 310 | | |
301 | 311 | | |
302 | 312 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
133 | 142 | | |
134 | | - | |
| 143 | + | |
135 | 144 | | |
136 | 145 | | |
137 | 146 | | |
| |||
197 | 206 | | |
198 | 207 | | |
199 | 208 | | |
200 | | - | |
201 | | - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
202 | 214 | | |
203 | 215 | | |
204 | 216 | | |
205 | 217 | | |
206 | 218 | | |
207 | 219 | | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
212 | 226 | | |
213 | 227 | | |
214 | 228 | | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
| 229 | + | |
| 230 | + | |
219 | 231 | | |
220 | 232 | | |
221 | 233 | | |
| |||
1151 | 1163 | | |
1152 | 1164 | | |
1153 | 1165 | | |
1154 | | - | |
| 1166 | + | |
1155 | 1167 | | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
1156 | 1183 | | |
1157 | 1184 | | |
1158 | 1185 | | |
| |||
0 commit comments