From b8bbe244b7d6eaa619270fdd782122d018a72695 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Thu, 17 Sep 2020 20:13:24 +0200 Subject: [PATCH] block_util: Ensure all io_uring operations are asynchronous Some operations complete directly after they have been submitted, which means they are not submitted asynchronously and therefore they don't generate any ioevent. This is the reason why we are not processing some of the completed operations, which leads to some unpredictable behaviors. Forcing all io_uring operations submitted to the SQE to be asynchronous helps simplifying the code as it ensures the completion of every operation will generate an ioevent, therefore no operation is missed. Signed-off-by: Sebastien Boeuf --- block_util/src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/block_util/src/lib.rs b/block_util/src/lib.rs index 4171e8ea1..a301672c2 100644 --- a/block_util/src/lib.rs +++ b/block_util/src/lib.rs @@ -14,7 +14,7 @@ extern crate log; extern crate serde_derive; #[cfg(feature = "io_uring")] -use io_uring::{opcode, IoUring, Probe}; +use io_uring::{opcode, squeue, IoUring, Probe}; use serde::ser::{Serialize, SerializeStruct, Serializer}; use std::cmp; use std::io::{self, Read, Seek, SeekFrom, Write}; @@ -278,7 +278,7 @@ impl Request { ) -> result::Result { let sector = self.sector; let request_type = self.request_type; - let offset = (sector as i64) << SECTOR_SHIFT; + let offset = (sector << SECTOR_SHIFT) as libc::off_t; let (submitter, sq, _) = io_uring.split(); let mut avail_sq = sq.available(); @@ -321,6 +321,7 @@ impl Request { ) .offset(offset) .build() + .flags(squeue::Flags::ASYNC) .user_data(user_data), ) }; @@ -337,6 +338,7 @@ impl Request { ) .offset(offset) .build() + .flags(squeue::Flags::ASYNC) .user_data(user_data), ) }; @@ -347,6 +349,7 @@ impl Request { avail_sq.push( opcode::Fsync::new(opcode::types::Fd(disk_image_fd)) .build() + .flags(squeue::Flags::ASYNC) .user_data(user_data), ) };