Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: handle DmaFile::read_at called with a size larger than max_sectors_size #635

Closed
wants to merge 1 commit into from
Closed
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
24 changes: 24 additions & 0 deletions glommio/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,18 @@ pub enum GlommioError<T> {

/// Timeout variant used for reporting timed out operations
TimedOut(Duration),

/// The read/write size is bigger than allowed by the block device.
///
/// Single read/write size shouldn't exceed the value in /sys/block/.../queue/max_sectors_kb.
///
/// This only happens when doing direct IO
MaxIOSizeExceeded {
/// Size of the requested IO operation.
size: usize,
/// Single request limit of the underlying block device.
limit: usize,
},
}

impl<T> From<io::Error> for GlommioError<T> {
Expand Down Expand Up @@ -289,6 +301,9 @@ impl<T> fmt::Display for GlommioError<T> {
},
GlommioError::ReactorError(err) => write!(f, "Reactor error: {err}"),
GlommioError::TimedOut(dur) => write!(f, "Operation timed out after {dur:#?}"),
GlommioError::MaxIOSizeExceeded { size, limit } => {
write!(f, "Max IO size exceeded when doing direct IO. Expected a max size of {limit} but got {size}")
}
}
}
}
Expand Down Expand Up @@ -477,6 +492,9 @@ impl<T> Debug for GlommioError<T> {
}
},
GlommioError::TimedOut(dur) => write!(f, "TimedOut {{ dur {dur:?} }}"),
GlommioError::MaxIOSizeExceeded { size, limit } => {
write!(f, "MaxIOSizeExceeded {{ size {size:?}, limit {limit:?} }}")
}
}
}
}
Expand Down Expand Up @@ -527,6 +545,12 @@ impl<T> From<GlommioError<T>> for io::Error {
GlommioError::TimedOut(dur) => {
io::Error::new(io::ErrorKind::TimedOut, format!("timed out after {dur:#?}"))
}
GlommioError::MaxIOSizeExceeded { size, limit } => io::Error::new(
io::ErrorKind::Other,
format!(
"max IO size exceeded when doing direct IO. Limit is {limit} but got {size}"
),
),
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions glommio/src/io/dma_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::{
ScheduledSource,
},
sys::{self, sysfs, DirectIo, DmaBuffer, DmaSource, PollableStatus},
GlommioError,
};
use futures_lite::{Stream, StreamExt};
use nix::sys::statfs::*;
Expand Down Expand Up @@ -401,6 +402,14 @@ impl DmaFile {
let b = (pos - eff_pos) as usize;

let eff_size = self.align_up((size + b) as u64) as usize;

if eff_size >= self.max_sectors_size {
return Err(GlommioError::MaxIOSizeExceeded {
size: eff_size,
limit: self.max_sectors_size,
});
}

let source = self.file.reactor.upgrade().unwrap().read_dma(
self.as_raw_fd(),
eff_pos,
Expand Down
Loading