Skip to content
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
1 change: 1 addition & 0 deletions .github/scripts/build-cuobject-client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ export LIBRARY_PATH="$CUOBJCLIENT_ROOT/lib${LIBRARY_PATH:+:$LIBRARY_PATH}"
export NIXL_PLUGIN_DIR="$NIXL_PREFIX/lib/plugins"
./scripts/build-rdma.sh --features cuobject
cargo test --locked --manifest-path nixl/Cargo.toml --features cuobject
cargo test --locked --manifest-path nixl/Cargo.toml -p rustfs-rdma-client --no-default-features --features cuobject
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ cd cli
cargo build --release
```

To use RustFS native NIXL/UCX for object transfers, build the [Linux RDMA client](docs/rdma-build.md#rustfs-native-nixlucx).
For native NIXL/UCX and NVIDIA cuObject transfers, [build the Linux CLI](docs/rdma-build.md#build-the-native-client) or [use the RDMA client in a Rust application](docs/rdma-build.md#embed-the-rust-client).

## Quick Start

Expand Down
25 changes: 22 additions & 3 deletions crates/s3/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1806,7 +1806,26 @@ impl Intercept for CustomHeaderInterceptor {
impl S3Client {
/// Create a new S3 client from an alias configuration
pub async fn new(alias: Alias) -> Result<Self> {
let request_headers = global_request_headers();
let mode = rc_core::global_data_transport_mode();
let factory = data_transport::installed_factory();
Self::build(alias, global_request_headers(), mode, factory.as_deref()).await
}

/// Create a client with an explicit transport policy, independent of CLI defaults.
pub async fn new_with_transport_factory(
alias: Alias,
mode: rc_core::DataTransportMode,
factory: &dyn data_transport::ObjectDataTransportFactory,
) -> Result<Self> {
Self::build(alias, Vec::new(), mode, Some(factory)).await
}

async fn build(
alias: Alias,
request_headers: Vec<RequestHeader>,
mode: rc_core::DataTransportMode,
factory: Option<&dyn data_transport::ObjectDataTransportFactory>,
) -> Result<Self> {
for header in &request_headers {
header.validate_transport_name()?;
}
Expand Down Expand Up @@ -1900,11 +1919,11 @@ impl S3Client {
alias,
session_token,
request_headers,
data_transport_mode: rc_core::global_data_transport_mode(),
data_transport_mode: mode,
data_transport: None,
};
if client.data_transport_mode != rc_core::DataTransportMode::Http
&& let Some(factory) = data_transport::installed_factory()
&& let Some(factory) = factory
{
client.data_transport = Some(factory.create(Arc::new(client.clone()))?);
}
Expand Down
9 changes: 9 additions & 0 deletions docs/ADR/0001-object-data-transport.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ checksum verification and receipt handling.
The common launcher preserves command dispatch, output, exit codes, and the
existing worker-thread configuration.

The separate native workspace contains the reusable `rustfs-rdma-client`
library. It implements the provider ports from `rc-s3`; only the launcher
depends on `rustfs-cli`. Applications use `RdmaProvider::client` with an
explicit alias and transfer mode. This constructor bypasses the CLI provider
registry and CLI request headers. Reusing a provider shares endpoint capability
probes across its clients. Each client creates its window pools on demand.
The library keeps registered buffers, token ownership and wire fields private.
Cargo features select the NIXL and NVIDIA native dependencies independently.

The NIXL backend supplies agent metadata and a registered buffer description.
The NVIDIA backend uses `rustfs-cuobject-client` for registered windows and transfer tokens. Its dependency `rustfs-cuobject-client-sys` builds the C++ bridge and links the NVIDIA client SDK. The window can be reused after
a verified receipt or proof that DMA never started. An uncertain transfer retains both resources
Expand Down
34 changes: 33 additions & 1 deletion docs/rdma-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ to the same executable, install the NVIDIA cuObject **client** SDK,
cuFile development libraries, libibverbs development headers and CUDA headers
for the target architecture.
Set `CUOBJCLIENT_ROOT` to the SDK prefix and `CUDA_HOME` to the CUDA toolkit.
The `rustfs-cuobject-client-sys` crate builds the C++17 adapter against `cuobjclient.h` and links the NVIDIA SDK. The CLI accesses registered windows and tokens through `rustfs-cuobject-client`.
The `rustfs-cuobject-client-sys` crate builds the C++17 adapter against `cuobjclient.h` and links the NVIDIA SDK. The RDMA provider accesses registered windows and tokens through `rustfs-cuobject-client`.
The SDK's `libcuobjclient`, `libcufile` and RDMA plugin must be available
at runtime. Set `CUOBJ_ENV_PATH_JSON` to the NVIDIA client configuration
that selects the application RDMA device.
Expand Down Expand Up @@ -122,3 +122,35 @@ c++ -std=c++17 -fPIC -shared -I"$CUOBJCLIENT_ROOT/include" -I"$CUDA_HOME/include
LD_PRELOAD=/tmp/rc-test-failed-deregistration.so cargo test --manifest-path nixl/Cargo.toml \
-p rustfs-cuobject-client --features client --test registration_budget -- --ignored
```

## Embed the Rust client

Add the SDK from the CLI repository to your application's `Cargo.toml`.
Choose `nixl`, `cuobject`, or both. Each feature requires
the corresponding native libraries described above. The default is `nixl`.

```toml
[dependencies]
rustfs-rdma-client = { git = "https://github.com/rustfs/cli", default-features = false, features = ["cuobject"] }
```

For a local checkout, replace the `git` key with `path = "../cli/nixl/rdma-client"`.

The following function accepts the endpoint configuration and object key from
the application. Run it on a Tokio runtime. Reuse a provider for clients that
should share endpoint capability probes, and reuse each client across transfers.

```rust
use rustfs_rdma_client::{Alias, DataTransportMode, ObjectStore, RdmaBackend, RdmaProvider, RemotePath, Result};

async fn download(alias: Alias, path: &RemotePath) -> Result<Vec<u8>> {
let provider = RdmaProvider::new(RdmaBackend::CuObject)?;
let client = provider.client(alias, DataTransportMode::Rdma).await?;
client.get_object(path).await
}
```

`RdmaProvider::new` returns `Error::UnsupportedFeature` for a backend
omitted from the build. Native memory registration happens on demand during
transfer. Use `DataTransportMode::Auto` to permit safe HTTP fallback.
Both backends transfer through SDK-managed host memory.
24 changes: 16 additions & 8 deletions nixl/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 6 additions & 11 deletions nixl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,19 @@ publish = false

[workspace]
resolver = "3"
members = ["cuobject-client", "cuobject-client-sys"]
default-members = ["."]
members = ["rdma-client", "cuobject-client", "cuobject-client-sys"]
default-members = [".", "rdma-client"]

[[bin]]
name = "rc"
path = "src/main.rs"

[features]
cuobject = ["dep:rustfs-cuobject-client"]
default = ["nixl"]
nixl = ["rustfs-rdma-client/nixl"]
cuobject = ["rustfs-rdma-client/cuobject"]

[dependencies]
rustfs-cuobject-client = { path = "cuobject-client", features = ["client"], optional = true }
rustfs-rdma-client = { path = "rdma-client", default-features = false }
rustfs-cli = { path = "../crates/cli" }
rc-core = { path = "../crates/core" }
rc-s3 = { path = "../crates/s3" }
rustfs-nixl = { git = "https://github.com/rustfs/rustfs", rev = "b86624520c99de06d9e36b971520a7071ca54b4c", features = ["sys"] }
async-trait = "0.1"
base64 = "0.22"
getrandom = "0.4"
http = "1"
tokio = { version = "1", features = ["io-util", "sync", "time"] }
24 changes: 24 additions & 0 deletions nixl/rdma-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "rustfs-rdma-client"
version = "0.1.0"
edition = "2024"
rust-version = "1.99.0"
license = "MIT OR Apache-2.0"
description = "Native S3 object transfers over NIXL/UCX and NVIDIA cuObject"
publish = false

[features]
default = ["nixl"]
nixl = ["dep:rustfs-nixl", "dep:base64", "dep:getrandom"]
cuobject = ["dep:rustfs-cuobject-client"]

[dependencies]
rustfs-cuobject-client = { path = "../cuobject-client", features = ["client"], optional = true }
rc-core = { path = "../../crates/core" }
rc-s3 = { path = "../../crates/s3" }
rustfs-nixl = { git = "https://github.com/rustfs/rustfs", rev = "b86624520c99de06d9e36b971520a7071ca54b4c", features = ["sys"], optional = true }
async-trait = "0.1"
base64 = { version = "0.22", optional = true }
getrandom = { version = "0.4", optional = true }
http = "1"
tokio = { version = "1", features = ["io-util", "macros", "rt", "sync", "time"] }
24 changes: 18 additions & 6 deletions nixl/src/buffer.rs → nixl/rdma-client/src/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
//! Backend registrations used by the shared object transfer pipeline.

#[cfg(feature = "nixl")]
use base64::{Engine, engine::general_purpose::STANDARD};
#[cfg(feature = "nixl")]
use http::HeaderValue;
use rc_core::{Error, RdmaBackend, Result};
#[cfg(feature = "nixl")]
use rustfs_nixl::{NixlConfig, NixlServer, StagingChunk};

pub(super) enum Buffer {
#[cfg(feature = "nixl")]
Nixl {
chunk: StagingChunk,
agent: HeaderValue,
Expand All @@ -21,14 +25,20 @@ pub(super) fn register(
count: usize,
_budget: &crate::pool::Budget,
) -> Result<Vec<Buffer>> {
if backend == RdmaBackend::CuObject {
match backend {
#[cfg(feature = "cuobject")]
return crate::nvidia::register(size, count, _budget);
#[cfg(not(feature = "cuobject"))]
return Err(Error::UnsupportedFeature(
"The cuObject backend is not installed".into(),
));
RdmaBackend::CuObject => crate::nvidia::register(size, count, _budget),
#[cfg(feature = "nixl")]
RdmaBackend::Nixl => register_nixl(size, count),
#[cfg(not(all(feature = "cuobject", feature = "nixl")))]
_ => Err(Error::UnsupportedFeature(format!(
"RDMA backend {backend:?} is not enabled"
))),
}
}

#[cfg(feature = "nixl")]
fn register_nixl(size: usize, count: usize) -> Result<Vec<Buffer>> {
let id = getrandom::u64()
.map_err(|_| Error::General("Could not generate a NIXL agent ID".into()))?;
let name = format!("rc-{}-{id:016x}", std::process::id());
Expand Down Expand Up @@ -58,13 +68,15 @@ pub(super) fn register(
.collect()
}

#[cfg(feature = "nixl")]
fn nixl_error(error: rustfs_nixl::NixlError) -> Error {
Error::General(format!("NIXL/UCX: {error}"))
}

impl Buffer {
pub(super) fn writable(&mut self) -> Result<&mut [u8]> {
match self {
#[cfg(feature = "nixl")]
Self::Nixl { chunk, .. } => chunk.spare_mut().map_err(nixl_error),
#[cfg(feature = "cuobject")]
Self::CuObject(buffer) => buffer.writable(),
Expand Down
29 changes: 29 additions & 0 deletions nixl/rdma-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! Linux S3 object transfers using NIXL/UCX or NVIDIA cuObject host memory.
//!
//! Select a backend when creating a provider and a transfer policy per client.
//! The S3 client handles credentials, TLS, signing and multipart publication.
//!
//! ```no_run
//! use rustfs_rdma_client::{Alias, DataTransportMode, ObjectStore, RdmaBackend, RdmaProvider, RemotePath, Result};
//!
//! async fn download(alias: Alias, backend: RdmaBackend, path: &RemotePath) -> Result<Vec<u8>> {
//! let provider = RdmaProvider::new(backend)?;
//! let client = provider.client(alias, DataTransportMode::Rdma).await?;
//! client.get_object(path).await
//! }
//! ```
#![forbid(unsafe_code)]

#[cfg(not(any(feature = "nixl", feature = "cuobject")))]
compile_error!("Enable the nixl or cuobject feature to select a native transport");

mod buffer;
#[cfg(feature = "cuobject")]
mod nvidia;
mod pool;
mod transport;
mod wire;

pub use rc_core::{Alias, DataTransportMode, Error, ObjectStore, RdmaBackend, RemotePath, Result};
pub use rc_s3::S3Client;
pub use transport::RdmaProvider;
File renamed without changes.
7 changes: 7 additions & 0 deletions nixl/src/pool.rs → nixl/rdma-client/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ pub(crate) const WINDOW: usize = rc_s3::multipart::DEFAULT_PART_SIZE as usize;
const SMALL_WINDOW: usize = 1024 * 1024;
const WINDOWS_PER_POOL: usize = 2;
static AGENTS: Semaphore = Semaphore::const_new(8);
// Several tests intentionally quarantine registrations for the life of the process.
// Run independent native scenarios one at a time against the shared registration budget.
#[cfg(test)]
pub(crate) static NATIVE_TEST_LOCK: AsyncMutex<()> = AsyncMutex::const_new(());
// Keep the exposed registration and its budget, so the retired pool can free its idle buffers.
pub(super) type Budget = Arc<SemaphorePermit<'static>>;
static QUARANTINE: Mutex<Vec<(Buffer, Budget)>> = Mutex::new(Vec::new());
Expand Down Expand Up @@ -139,6 +143,7 @@ impl Window {
let mut exposed = Exposed(Some(self));
let buffer = exposed.window_mut().buffer.as_mut().expect("owned window");
let result = match buffer {
#[cfg(feature = "nixl")]
Buffer::Nixl {
chunk,
agent,
Expand Down Expand Up @@ -208,6 +213,7 @@ mod tests {
assert_eq!(window_size(u64::MAX), WINDOW);
}

#[cfg(feature = "nixl")]
#[tokio::test]
async fn uncertain_windows_wake_waiters_and_cannot_be_reissued() {
check_window_lifetime(RdmaBackend::Nixl).await;
Expand Down Expand Up @@ -242,6 +248,7 @@ mod tests {
}

async fn check_window_lifetime(backend: RdmaBackend) {
let _guard = NATIVE_TEST_LOCK.lock().await;
let pools = Pools::new(backend);
let first = pools.reserve(32).await.unwrap();
let second = pools.reserve(32).await.unwrap();
Expand Down
Loading