From dbf4891eb227d89c91c817dc8c2fb1dd4ab6f87d Mon Sep 17 00:00:00 2001 From: Thomas Barrett Date: Wed, 8 Nov 2023 08:55:16 -0800 Subject: [PATCH] block: fix aio backend behavior when writeback enabled Signed-off-by: Thomas Barrett (cherry picked from commit d9ed28171987ce4b78a365a789ef1176b4e816b5) --- block/src/raw_async_aio.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/block/src/raw_async_aio.rs b/block/src/raw_async_aio.rs index dc092f4cb..d0304fbaf 100644 --- a/block/src/raw_async_aio.rs +++ b/block/src/raw_async_aio.rs @@ -120,15 +120,20 @@ impl AsyncIo for RawFileAsyncAio { } fn fsync(&mut self, user_data: Option) -> AsyncIoResult<()> { - let iocbs = [&mut aio::IoControlBlock { - aio_fildes: self.fd.as_raw_fd() as u32, - aio_lio_opcode: aio::IOCB_CMD_FSYNC as u16, - aio_data: user_data.unwrap_or(0), - aio_flags: aio::IOCB_FLAG_RESFD, - aio_resfd: self.eventfd.as_raw_fd() as u32, - ..Default::default() - }]; - let _ = self.ctx.submit(&iocbs[..]).map_err(AsyncIoError::Fsync)?; + if let Some(user_data) = user_data { + let iocbs = [&mut aio::IoControlBlock { + aio_fildes: self.fd.as_raw_fd() as u32, + aio_lio_opcode: aio::IOCB_CMD_FSYNC as u16, + aio_data: user_data, + aio_flags: aio::IOCB_FLAG_RESFD, + aio_resfd: self.eventfd.as_raw_fd() as u32, + ..Default::default() + }]; + let _ = self.ctx.submit(&iocbs[..]).map_err(AsyncIoError::Fsync)?; + } else { + // SAFETY: FFI call with a valid fd + unsafe { libc::fsync(self.fd) }; + } Ok(()) }