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

Method punch_hole

block/src/raw_async_aio.rs:135–158  ·  view source on GitHub ↗
(&mut self, offset: u64, length: u64, user_data: u64)

Source from the content-addressed store, hash-verified

133 }
134
135 fn punch_hole(&mut self, offset: u64, length: u64, user_data: u64) -> AsyncIoResult<()> {
136 // Linux AIO has no IOCB command for fallocate, so perform the operation
137 // synchronously and signal completion via the completion list, matching
138 // the pattern used by the sync backend (RawFileSync).
139 let mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
140
141 // SAFETY: FFI call with valid arguments
142 let result = unsafe {
143 libc::fallocate(
144 self.fd as libc::c_int,
145 mode,
146 offset as libc::off_t,
147 length as libc::off_t,
148 )
149 };
150 if result < 0 {
151 return Err(AsyncIoError::PunchHole(std::io::Error::last_os_error()));
152 }
153
154 self.completion_list.push_back((user_data, result));
155 self.eventfd.write(1).unwrap();
156
157 Ok(())
158 }
159
160 fn write_zeroes(&mut self, offset: u64, length: u64, user_data: u64) -> AsyncIoResult<()> {
161 // Linux AIO has no IOCB command for fallocate, so perform the operation

Callers

nothing calls this directly

Calls 1

writeMethod · 0.45

Tested by

no test coverage detected