MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / punch_hole

Function punch_hole

vmm/src/memory_manager.rs:3351–3368  ·  view source on GitHub ↗

Punch an explicit hole into `f`. Tests use this instead of relying on "didn't write here" to mean "is a hole": modern shmem/tmpfs may allocate a multi-page folio on the first write and report the whole folio as data, so per-page hole tracking after a partial write is not portable. `fallocate(PUNCH_HOLE)` is the explicit "deallocate these pages" syscall and is honored on every Linux filesystem we r

(f: &std::fs::File, off: u64, len: u64)

Source from the content-addressed store, hash-verified

3349 /// these pages" syscall and is honored on every Linux filesystem we
3350 /// run tests on (tmpfs, ext4, xfs, btrfs).
3351 fn punch_hole(f: &std::fs::File, off: u64, len: u64) {
3352 // SAFETY: FFI call; f is a valid open fd for the duration of the
3353 // call.
3354 let r = unsafe {
3355 libc::fallocate(
3356 f.as_raw_fd(),
3357 libc::FALLOC_FL_PUNCH_HOLE | libc::FALLOC_FL_KEEP_SIZE,
3358 off as libc::off_t,
3359 len as libc::off_t,
3360 )
3361 };
3362 assert_eq!(
3363 r,
3364 0,
3365 "fallocate PUNCH_HOLE off={off} len={len}: {}",
3366 std::io::Error::last_os_error(),
3367 );
3368 }
3369
3370 /// Build a file with a deterministic sparse layout: write each `(off,
3371 /// len, byte)` data extent, then punch every gap into a real hole.

Callers 1

sparse_layoutFunction · 0.85

Calls 1

as_raw_fdMethod · 0.45

Tested by

no test coverage detected