Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion block/src/formats/raw/engine_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ impl AsyncIo for RawSync {
}

fn fsync(&mut self, user_data: Option<u64>) -> AsyncIoResult<()> {
// A guest flush needs the data and the metadata to read it back, not the timestamps.
// SAFETY: FFI call
let result = unsafe { libc::fsync(self.raw_file.as_raw_fd() as libc::c_int) };
let result = unsafe { libc::fdatasync(self.raw_file.as_raw_fd() as libc::c_int) };
if result < 0 {
return Err(AsyncIoError::Fsync(io::Error::last_os_error()));
}
Expand Down
5 changes: 3 additions & 2 deletions block/src/io/async_io/aio_data_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,16 @@ impl AioDataIo {
Ok(())
}

/// Submits an fsync operation carrying `user_data`.
/// Submits an fdatasync operation carrying `user_data`: a guest flush needs the data and the
/// metadata to read it back, not the timestamps.
pub fn submit_fsync(&mut self, fd: RawFd, user_data: u64) -> io::Result<()> {
if self.in_flight.contains_key(&user_data) {
return Err(duplicate_user_data_error(user_data));
}

let mut iocb = aio::IoControlBlock {
aio_fildes: fd.as_raw_fd() as u32,
aio_lio_opcode: aio::IOCB_CMD_FSYNC as u16,
aio_lio_opcode: aio::IOCB_CMD_FDSYNC as u16,
aio_data: user_data,
aio_flags: aio::IOCB_FLAG_RESFD,
aio_resfd: self.eventfd.as_raw_fd() as u32,
Expand Down
5 changes: 4 additions & 1 deletion block/src/io/async_io/uring_data_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,14 @@ impl UringDataIo {
self.submit_kernel_entry(user_data, &opcode::Nop::new().build().user_data(user_data))
}

/// Submits an fsync operation carrying `user_data`.
/// Submits an fdatasync operation carrying `user_data`: a guest flush needs the data and the
/// metadata to read it back, not the timestamps, and a full fsync of a file whose mtime every
/// write touches forces a host journal commit per flush.
pub fn submit_fsync(&mut self, fd: RawFd, user_data: u64) -> io::Result<()> {
self.submit_kernel_entry(
user_data,
&opcode::Fsync::new(types::Fd(fd))
.flags(types::FsyncFlags::DATASYNC)
.build()
.user_data(user_data),
)
Expand Down
Loading