-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vendor (and add ext trait for) IoBuf/IoBufMut from
tokio-uring
For [`open_at` support](#21) we need an `OpenOptions` struct. Sadly we can't re-use the one from `tokio-uring` because it doesn't have a public API for the conversion of OpenOptions into the relevant libc flags. We created [a PR asking for such an API](neondatabase/tokio-uring#1), but, in the meantime, let's unblock ourselves by vendoring the pieces of `tokio-uring` that we need, and cusotmize them as needed. This PR starts that effort by vendoring the `IoBuf`/`IoBufMut` traits. `OpenOptions` will follow in a later PR. The files that reproduce the `tokio-uring` LICENSE text at the top are copied from `tokio-uring.git:d5e90539bd6d1c518e848298564a098c300866bc`. Files without it were written by myself.
- Loading branch information
Showing
18 changed files
with
277 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
members = [ | ||
"tokio-epoll-uring", | ||
"benchmark", | ||
"uring-common", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
use uring_common::io_uring; | ||
|
||
use crate::system::submission::op_fut::Op; | ||
|
||
pub struct Nop {} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "uring-common" | ||
version = "0.1.0" | ||
edition = "2021" | ||
description = "a subset of types from the `tokio-uring` crate" | ||
license = "MIT" # the same as tokio-uring at the time we forked it | ||
|
||
[dependencies] | ||
libc = "0.2.80" | ||
io-uring = "0.6.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod io_buf; | ||
mod io_buf_mut; | ||
|
||
pub use io_buf::IoBuf; | ||
pub use io_buf_mut::IoBufMut; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
// Copyright (c) 2021 Carl Lerche | ||
// | ||
// Permission is hereby granted, free of charge, to any | ||
// person obtaining a copy of this software and associated | ||
// documentation files (the "Software"), to deal in the | ||
// Software without restriction, including without | ||
// limitation the rights to use, copy, modify, merge, | ||
// publish, distribute, sublicense, and/or sell copies of | ||
// the Software, and to permit persons to whom the Software | ||
// is furnished to do so, subject to the following | ||
// conditions: | ||
// | ||
// The above copyright notice and this permission notice | ||
// shall be included in all copies or substantial portions | ||
// of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF | ||
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED | ||
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | ||
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR | ||
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
// DEALINGS IN THE SOFTWARE. | ||
// | ||
// | ||
// Based on tokio-uring.git:d5e90539bd6d1c518e848298564a098c300866bc | ||
|
||
/// An `io-uring` compatible buffer. | ||
/// | ||
/// The `IoBuf` trait is implemented by buffer types that can be used with | ||
/// io-uring operations. Users will not need to use this trait directly. | ||
/// The [`BoundedBuf`] trait provides some useful methods including `slice`. | ||
/// | ||
/// # Safety | ||
/// | ||
/// Buffers passed to `io-uring` operations must reference a stable memory | ||
/// region. While the runtime holds ownership to a buffer, the pointer returned | ||
/// by `stable_ptr` must remain valid even if the `IoBuf` value is moved. | ||
/// | ||
/// [`BoundedBuf`]: crate::buf::BoundedBuf | ||
pub unsafe trait IoBuf: Unpin + 'static { | ||
/// Returns a raw pointer to the vector’s buffer. | ||
/// | ||
/// This method is to be used by the `tokio-uring` runtime and it is not | ||
/// expected for users to call it directly. | ||
/// | ||
/// The implementation must ensure that, while the `tokio-uring` runtime | ||
/// owns the value, the pointer returned by `stable_ptr` **does not** | ||
/// change. | ||
fn stable_ptr(&self) -> *const u8; | ||
|
||
/// Number of initialized bytes. | ||
/// | ||
/// This method is to be used by the `tokio-uring` runtime and it is not | ||
/// expected for users to call it directly. | ||
/// | ||
/// For `Vec`, this is identical to `len()`. | ||
fn bytes_init(&self) -> usize; | ||
|
||
/// Total size of the buffer, including uninitialized memory, if any. | ||
/// | ||
/// This method is to be used by the `tokio-uring` runtime and it is not | ||
/// expected for users to call it directly. | ||
/// | ||
/// For `Vec`, this is identical to `capacity()`. | ||
fn bytes_total(&self) -> usize; | ||
} | ||
|
||
unsafe impl IoBuf for Vec<u8> { | ||
fn stable_ptr(&self) -> *const u8 { | ||
self.as_ptr() | ||
} | ||
|
||
fn bytes_init(&self) -> usize { | ||
self.len() | ||
} | ||
|
||
fn bytes_total(&self) -> usize { | ||
self.capacity() | ||
} | ||
} | ||
|
||
unsafe impl IoBuf for &'static [u8] { | ||
fn stable_ptr(&self) -> *const u8 { | ||
self.as_ptr() | ||
} | ||
|
||
fn bytes_init(&self) -> usize { | ||
<[u8]>::len(self) | ||
} | ||
|
||
fn bytes_total(&self) -> usize { | ||
self.bytes_init() | ||
} | ||
} | ||
|
||
unsafe impl IoBuf for &'static str { | ||
fn stable_ptr(&self) -> *const u8 { | ||
self.as_ptr() | ||
} | ||
|
||
fn bytes_init(&self) -> usize { | ||
<str>::len(self) | ||
} | ||
|
||
fn bytes_total(&self) -> usize { | ||
self.bytes_init() | ||
} | ||
} | ||
|
||
#[cfg(feature = "bytes")] | ||
unsafe impl IoBuf for bytes::Bytes { | ||
fn stable_ptr(&self) -> *const u8 { | ||
self.as_ptr() | ||
} | ||
|
||
fn bytes_init(&self) -> usize { | ||
self.len() | ||
} | ||
|
||
fn bytes_total(&self) -> usize { | ||
self.len() | ||
} | ||
} | ||
|
||
#[cfg(feature = "bytes")] | ||
unsafe impl IoBuf for bytes::BytesMut { | ||
fn stable_ptr(&self) -> *const u8 { | ||
self.as_ptr() | ||
} | ||
|
||
fn bytes_init(&self) -> usize { | ||
self.len() | ||
} | ||
|
||
fn bytes_total(&self) -> usize { | ||
self.capacity() | ||
} | ||
} |
Oops, something went wrong.