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

[WIP] impl uring cmd feature #8

Draft
wants to merge 1 commit into
base: fork
Choose a base branch
from
Draft
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
7 changes: 7 additions & 0 deletions src/fs/file.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::buf::fixed::FixedBuf;
use crate::buf::{BoundedBuf, BoundedBufMut, IoBuf, IoBufMut, Slice};
use crate::fs::OpenOptions;
use crate::io::cmd::UnsubmittedCmd;
use crate::io::SharedFd;

use crate::runtime::driver::op::{Op, Submit};
Expand All @@ -11,6 +12,7 @@ use std::fmt;
use std::io;
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
use std::path::Path;
use std::pin::Pin;

/// A reference to an open file on the filesystem.
///
Expand Down Expand Up @@ -879,6 +881,11 @@ impl File {
pub async fn close(mut self) -> io::Result<()> {
self.fd.close().await
}

#[allow(missing_docs)]
pub fn cmd<T>(&self, op: u32, cmd: [u8; 16], data: Pin<Box<T>>) -> UnsubmittedCmd<T> {
UnsubmittedCmd::cmd(&self.fd, op, cmd, data)
}
}

impl FromRawFd for File {
Expand Down
45 changes: 45 additions & 0 deletions src/io/cmd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use std::marker::PhantomData;
use std::pin::Pin;

use io_uring::cqueue::Entry;
use io_uring::{opcode, types};

use crate::io::SharedFd;

use crate::{OneshotOutputTransform, UnsubmittedOneshot};

/// An unsubmitted read operation.
pub type UnsubmittedCmd<T> = UnsubmittedOneshot<CmdData<T>, CmdTransform<T>>;

impl<T> UnsubmittedCmd<T> {
pub(crate) fn cmd(fd: &SharedFd, op: u32, cmd: [u8; 16], data: Pin<Box<T>>) -> Self {
Self::new(
CmdData { data },
CmdTransform {
_phantom: PhantomData,
},
opcode::UringCmd16::new(types::Fd(fd.raw_fd()), op)
.cmd(cmd)
.build(),
)
}
}

#[allow(missing_docs)]
pub struct CmdData<T> {
data: Pin<Box<T>>,
}

#[allow(missing_docs)]
pub struct CmdTransform<B> {
_phantom: PhantomData<B>,
}

impl<T> OneshotOutputTransform for CmdTransform<T> {
type Output = (i32, Pin<Box<T>>);
type StoredData = CmdData<T>;

fn transform_oneshot_output(self, data: Self::StoredData, cqe: Entry) -> Self::Output {
(cqe.result(), data.data)
}
}
2 changes: 2 additions & 0 deletions src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ pub(crate) mod writev;

mod writev_all;
pub(crate) use writev_all::writev_at_all;

pub(crate) mod cmd;
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub mod buf;
pub mod fs;
pub mod net;

pub use io::cmd::*;
pub use io::read::*;
pub use io::readv::*;
pub use io::write::*;
Expand Down