Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
44 changes: 44 additions & 0 deletions glommio/src/io/dma_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ use futures_lite::{Stream, StreamExt};
use nix::sys::statfs::*;
use std::{
cell::Ref,
future::Future,
io,
os::unix::io::{AsRawFd, RawFd},
path::Path,
pin::Pin,
rc::Rc,
task::{Context, Poll},
};

pub(super) type Result<T> = crate::Result<T, ()>;
Expand Down Expand Up @@ -283,6 +286,21 @@ impl DmaFile {
))
}

/// Poll-based version of [`Self::read_at_aligned`]
pub fn poll_read_at_aligned(&self, pos: u64, size: usize) -> PollDmaReadAligned<'_> {
let source = self.file.reactor.upgrade().unwrap().read_dma(
self.as_raw_fd(),
pos,
size,
self.pollable,
self.file.scheduler.borrow().as_ref(),
);
PollDmaReadAligned {
source: Some(source),
file: &self.file,
}
}

/// Submit many reads and process the results in a stream-like fashion via a
/// [`ReadManyResult`].
///
Expand Down Expand Up @@ -424,6 +442,32 @@ impl DmaFile {
}
}

#[doc(hidden)]
Comment thread
waynexia marked this conversation as resolved.
Outdated
#[derive(Debug)]
#[must_use = "future has no effect unless you .await or poll it"]
pub struct PollDmaReadAligned<'a> {
source: Option<ScheduledSource>,
file: &'a GlommioFile,
}

impl Future for PollDmaReadAligned<'_> {
type Output = Result<ReadResult>;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let read_size = self
.source
.as_ref()
.expect("Polling a finished task")
.poll_collect_rw(cx)
.map(|read_size| enhanced_try!(read_size, "Reading", self.file))?;

read_size.map(|size| {
let source = self.get_mut().source.take().unwrap();
Ok(ReadResult::from_sliced_buffer(source, 0, size))
})
}
}

#[cfg(test)]
pub(crate) mod test {
use super::*;
Expand Down
11 changes: 10 additions & 1 deletion glommio/src/sys/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use std::{
os::unix::io::RawFd,
path::PathBuf,
rc::Rc,
task::{Poll, Waker},
task::{Context, Poll, Waker},
time::Duration,
};

Expand Down Expand Up @@ -267,6 +267,15 @@ impl Source {
})
.await
}

pub(crate) fn poll_collect_rw(&self, cx: &mut Context<'_>) -> Poll<io::Result<usize>> {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering whether we can make more use of this, like dma write or other files/resources' operation. Maybe we can track the progress in #445.

if let Some(result) = self.result() {
return Poll::Ready(result);
}

self.add_waiter_many(cx.waker().clone());
Poll::Pending
}
}

impl Drop for Source {
Expand Down