From 090fcebfec3a01b1b4e62cb5ef0dce133e35316f Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Thu, 13 Jun 2024 00:09:34 +0000 Subject: [PATCH] block: do not ignore failures when pushing to io_uring submission queue Instead of silently ignoring the error, return an error to the callers. This in practice should never happen, because the submission queue size (ring depth) is the same as the virtio queue size. Virtio queue won't push more requests than there are submission queue entries. Signed-off-by: Wei Liu --- block/src/raw_async.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/block/src/raw_async.rs b/block/src/raw_async.rs index 49bfe0837..395d768a5 100644 --- a/block/src/raw_async.rs +++ b/block/src/raw_async.rs @@ -3,7 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause use std::fs::File; -use std::io::{Seek, SeekFrom}; +use std::io::{Error, Seek, SeekFrom}; use std::os::unix::io::{AsRawFd, RawFd}; use io_uring::{opcode, squeue, types, IoUring}; @@ -86,7 +86,7 @@ impl AsyncIo for RawFileAsync { // SAFETY: we know the file descriptor is valid and we // relied on vm-memory to provide the buffer address. - let _ = unsafe { + unsafe { sq.push( &opcode::Readv::new(types::Fd(self.fd), iovecs.as_ptr(), iovecs.len() as u32) .offset(offset.try_into().unwrap()) @@ -94,6 +94,7 @@ impl AsyncIo for RawFileAsync { .flags(squeue::Flags::ASYNC) .user_data(user_data), ) + .map_err(|_| AsyncIoError::ReadVectored(Error::other("Submission queue is full")))? }; // Update the submission queue and submit new operations to the @@ -114,7 +115,7 @@ impl AsyncIo for RawFileAsync { // SAFETY: we know the file descriptor is valid and we // relied on vm-memory to provide the buffer address. - let _ = unsafe { + unsafe { sq.push( &opcode::Writev::new(types::Fd(self.fd), iovecs.as_ptr(), iovecs.len() as u32) .offset(offset.try_into().unwrap()) @@ -122,6 +123,7 @@ impl AsyncIo for RawFileAsync { .flags(squeue::Flags::ASYNC) .user_data(user_data), ) + .map_err(|_| AsyncIoError::WriteVectored(Error::other("Submission queue is full")))? }; // Update the submission queue and submit new operations to the @@ -137,13 +139,14 @@ impl AsyncIo for RawFileAsync { let (submitter, mut sq, _) = self.io_uring.split(); // SAFETY: we know the file descriptor is valid. - let _ = unsafe { + unsafe { sq.push( &opcode::Fsync::new(types::Fd(self.fd)) .build() .flags(squeue::Flags::ASYNC) .user_data(user_data), ) + .map_err(|_| AsyncIoError::Fsync(Error::other("Submission queue is full")))? }; // Update the submission queue and submit new operations to the