block: fix aio backend behavior when writeback enabled

Signed-off-by: Thomas Barrett <tbarrett@crusoeenergy.com>
(cherry picked from commit d9ed281719)
This commit is contained in:
Thomas Barrett 2023-11-08 08:55:16 -08:00 committed by Bo Chen
parent f5899d15f6
commit dbf4891eb2

View File

@ -120,15 +120,20 @@ impl AsyncIo for RawFileAsyncAio {
} }
fn fsync(&mut self, user_data: Option<u64>) -> AsyncIoResult<()> { fn fsync(&mut self, user_data: Option<u64>) -> AsyncIoResult<()> {
if let Some(user_data) = user_data {
let iocbs = [&mut aio::IoControlBlock { let iocbs = [&mut aio::IoControlBlock {
aio_fildes: self.fd.as_raw_fd() as u32, aio_fildes: self.fd.as_raw_fd() as u32,
aio_lio_opcode: aio::IOCB_CMD_FSYNC as u16, aio_lio_opcode: aio::IOCB_CMD_FSYNC as u16,
aio_data: user_data.unwrap_or(0), aio_data: user_data,
aio_flags: aio::IOCB_FLAG_RESFD, aio_flags: aio::IOCB_FLAG_RESFD,
aio_resfd: self.eventfd.as_raw_fd() as u32, aio_resfd: self.eventfd.as_raw_fd() as u32,
..Default::default() ..Default::default()
}]; }];
let _ = self.ctx.submit(&iocbs[..]).map_err(AsyncIoError::Fsync)?; let _ = self.ctx.submit(&iocbs[..]).map_err(AsyncIoError::Fsync)?;
} else {
// SAFETY: FFI call with a valid fd
unsafe { libc::fsync(self.fd) };
}
Ok(()) Ok(())
} }