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

remove temporarily tokio-uring #96

Merged
merged 8 commits into from
Nov 14, 2022
Merged
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
17 changes: 14 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,39 @@ on:

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1

jobs:
CI:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: build and check
run: make check
- name: smoke
run: make docker-smoke

Macos-CI:
runs-on: macos-latest
steps:
- name: Install macfuse
run: brew install --cask macfuse
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: build and check
run: make check-macos

deny:
name: Cargo Deny
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@v1
14 changes: 6 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,25 @@ build = "build.rs"
arc-swap = "1.5"
async-trait = { version = "0.1.42", optional = true }
bitflags = "1.1"
io-uring = { version = "0.5.8", optional = true }
libc = "0.2.68"
log = "0.4.6"
mio = { version = "0.8", features = ["os-poll", "os-ext"]}
nix = "0.24"
lazy_static = "1.4"
tokio = { version = "1", optional = true }
tokio-uring = { version = "0.4.0", optional = true }
vmm-sys-util = { version = "0.10", optional = true }
vm-memory = { version = "0.9", features = ["backend-mmap"] }
virtio-queue = { version = "0.4", optional = true }
vhost = { version = "0.4", features = ["vhost-user-slave"], optional = true }
virtio-queue = { version = "0.6", optional = true }
vhost = { version = "0.5", features = ["vhost-user-slave"], optional = true }

[target.'cfg(target_os = "macos")'.dependencies]
core-foundation-sys = { version = ">=0.8", optional = true }

[target.'cfg(target_os = "linux")'.dependencies]
caps = { version = "0.5", optional = true }
tokio-uring = "0.3"
io-uring = { version = "0.5", features = ["unstable"] }
socket2 = { version = "0.4.4", features = ["all"] }
scoped-tls = "1.0.0"
slab = "0.4.6"
tokio-uring = "0.4"

[dev-dependencies]
tokio-test = "0.4.2"
Expand All @@ -49,7 +47,7 @@ vm-memory = { version = "0.9", features = ["backend-mmap", "backend-bitmap"] }

[features]
default = ["fusedev"]
async-io = ["async-trait", "tokio/fs", "tokio/net", "tokio/sync", "tokio/rt", "tokio/macros"]
async-io = ["async-trait", "tokio-uring", "tokio/fs", "tokio/net", "tokio/sync", "tokio/rt", "tokio/macros", "io-uring"]
fusedev = ["vmm-sys-util", "caps", "core-foundation-sys"]
virtiofs = ["virtio-queue", "caps"]
vhost-user-fs = ["virtiofs", "vhost", "caps"]
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ smoke-macos: check-macos
cargo test --features="fusedev" -- --nocapture

docker-smoke:
docker run --rm --privileged -v ${current_dir}:/fuse-rs rust:1.58.1 sh -c "rustup component add clippy rustfmt; cd /fuse-rs; make smoke-all"
docker run --rm --privileged -v ${current_dir}:/fuse-rs rust:1.59 sh -c "rustup component add clippy rustfmt; cd /fuse-rs; make smoke-all"
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,3 @@ impl FuseServer {
This project is licensed under
- [Apache License](http://www.apache.org/licenses/LICENSE-2.0), Version 2.0
- [BSD-3-Clause License](https://opensource.org/licenses/BSD-3-Clause)

Source code under [src/tokio-uring] is temporarily copied from [tokio-uring](https://github.com/tokio-rs/tokio-uring)
with modifications, which is licensed under [MIT](https://github.com/tokio-rs/tokio-uring/blob/master/LICENSE).

We will use `crate.io` directly instead of this temporary copy when the pendding PRs is merged.
https://github.com/tokio-rs/tokio-uring/pull/87
https://github.com/tokio-rs/tokio-uring/pull/88
84 changes: 17 additions & 67 deletions src/common/async_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::io::{ErrorKind, IoSlice, IoSliceMut};
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
use std::path::Path;

use crate::async_runtime::{Runtime, CURRENT_RUNTIME};
use crate::async_runtime::{RuntimeType, RUNTIME_TYPE};
use crate::file_buf::FileVolatileBuf;
use crate::{off64_t, preadv64, pwritev64};

Expand All @@ -19,7 +19,7 @@ pub enum File {
Tokio(tokio::fs::File),
#[cfg(target_os = "linux")]
/// Tokio-uring asynchronous `File`.
Uring(RawFd),
Uring(tokio_uring::fs::File),
}

impl File {
Expand All @@ -29,34 +29,22 @@ impl File {
write: bool,
create: bool,
) -> std::io::Result<Self> {
let ty = CURRENT_RUNTIME.with(|rt| match rt {
Runtime::Tokio(_) => 1,
#[cfg(target_os = "linux")]
Runtime::Uring(_) => 2,
});

match ty {
1 => tokio::fs::OpenOptions::new()
match *RUNTIME_TYPE {
RuntimeType::Tokio => tokio::fs::OpenOptions::new()
.read(true)
.write(write)
.create(create)
.open(path)
.await
.map(File::Tokio),
#[cfg(target_os = "linux")]
2 => crate::tokio_uring::fs::OpenOptions::new()
RuntimeType::Uring => tokio_uring::fs::OpenOptions::new()
.read(true)
.write(write)
.create(create)
.open(path)
.await
.map(|v| {
// Convert the tokio_uring::fs::File object into RawFd(): v.into_raw_fd().
let file = File::Uring(v.as_raw_fd());
std::mem::forget(v);
file
}),
_ => panic!("should not happen"),
.map(File::Uring),
}
}

Expand All @@ -75,15 +63,7 @@ impl File {
(res, bufs[0])
}
#[cfg(target_os = "linux")]
File::Uring(fd) => {
// Safety: we rely on tokio_uring::fs::File internal implementation details.
// It should be implemented as self.async_try_clone().await.unwrap().read_at,
// but that causes two more syscalls.
let file = unsafe { crate::tokio_uring::fs::File::from_raw_fd(*fd) };
let res = file.read_at(buf, offset).await;
std::mem::forget(file);
res
}
File::Uring(f) => f.read_at(buf, offset).await,
}
}

Expand All @@ -101,15 +81,7 @@ impl File {
(res, bufs)
}
#[cfg(target_os = "linux")]
File::Uring(fd) => {
// Safety: we rely on tokio_uring::fs::File internal implementation details.
// It should be implemented as self.async_try_clone().await.unwrap().readv_at,
// but that causes two more syscalls.
let file = unsafe { crate::tokio_uring::fs::File::from_raw_fd(*fd) };
let res = file.readv_at(bufs, offset).await;
std::mem::forget(file);
res
}
File::Uring(f) => f.readv_at(bufs, offset).await,
}
}

Expand All @@ -128,15 +100,7 @@ impl File {
(res, bufs[0])
}
#[cfg(target_os = "linux")]
File::Uring(fd) => {
// Safety: we rely on tokio_uring::fs::File internal implementation details.
// It should be implemented as self.async_try_clone().await.unwrap().write_at,
// but that causes two more syscalls.
let file = unsafe { crate::tokio_uring::fs::File::from_raw_fd(*fd) };
let res = file.write_at(buf, offset).await;
std::mem::forget(file);
res
}
File::Uring(f) => f.write_at(buf, offset).await,
}
}

Expand All @@ -154,15 +118,7 @@ impl File {
(res, bufs)
}
#[cfg(target_os = "linux")]
File::Uring(fd) => {
// Safety: we rely on tokio_uring::fs::File internal implementation details.
// It should be implemented as self.async_try_clone().await.unwrap().writev_at,
// but that causes two more syscalls.
let file = unsafe { crate::tokio_uring::fs::File::from_raw_fd(*fd) };
let res = file.writev_at(bufs, offset).await;
std::mem::forget(file);
res
}
File::Uring(f) => f.writev_at(bufs, offset).await,
}
}

Expand All @@ -180,13 +136,16 @@ impl File {
match self {
File::Tokio(f) => f.try_clone().await.map(File::Tokio),
#[cfg(target_os = "linux")]
File::Uring(fd) => {
File::Uring(f) => {
// Safe because file.as_raw_fd() is valid RawFd and we have checked the result.
let fd = unsafe { libc::dup(*fd) };
let fd = unsafe { libc::dup(f.as_raw_fd()) };
if fd < 0 {
Err(std::io::Error::last_os_error())
} else {
Ok(File::Uring(fd))
// Safe because we dup a new raw fd.
Ok(File::Uring(unsafe {
tokio_uring::fs::File::from_raw_fd(fd)
}))
}
}
}
Expand All @@ -198,7 +157,7 @@ impl AsRawFd for File {
match self {
File::Tokio(f) => f.as_raw_fd(),
#[cfg(target_os = "linux")]
File::Uring(fd) => *fd,
File::Uring(f) => f.as_raw_fd(),
}
}
}
Expand All @@ -210,15 +169,6 @@ impl Debug for File {
}
}

impl Drop for File {
fn drop(&mut self) {
#[cfg(target_os = "linux")]
if let File::Uring(fd) = self {
let _ = unsafe { crate::tokio_uring::fs::File::from_raw_fd(*fd) };
}
}
}

/// A simple wrapper over posix `preadv` to deal with `FileVolatileBuf`.
pub fn preadv(fd: RawFd, bufs: &mut [FileVolatileBuf], offset: u64) -> std::io::Result<usize> {
let iov: Vec<IoSliceMut> = bufs.iter().map(|v| v.io_slice_mut()).collect();
Expand Down
Loading