1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! # `Method::Spdk` runtime gating (1.1.0)
//!
//! `Method::Spdk` is the kernel-bypass backend selector. It is
//! **runtime-validated**, not compile-time reserved — the rejection
//! reason depends on the build and the host:
//!
//! - Without the `spdk` Cargo feature, `Builder::build` returns
//! [`Error::FeatureNotEnabled { feature: "spdk" }`](fsys::Error::FeatureNotEnabled).
//! - With the feature on but the host ineligible, it returns
//! [`Error::SpdkUnavailable { reason }`](fsys::Error::SpdkUnavailable)
//! with a specific
//! [`SpdkSkipReason`](fsys::capability::SpdkSkipReason).
//!
//! Most callers should rely on `Method::Auto`, which falls back
//! cleanly when SPDK is not selectable. This example is for the
//! diagnostic case — you want to know exactly *why* SPDK is or
//! isn't available on a host.
//!
//! Run: `cargo run --example 33_method_spdk_gating`
use fsys::{Builder, Error, Method};
fn main() {
// Print the capability probe's verdict first.
let caps = fsys::capability::capabilities();
println!("SPDK eligibility: {}", caps.spdk_eligible);
if !caps.spdk_skip_reasons.is_empty() {
println!("Skip reasons:");
for r in &caps.spdk_skip_reasons {
println!(" • {r}");
}
}
println!();
// Try to build a handle with Method::Spdk. The outcome depends
// on the `spdk` Cargo feature + the capability probe.
match Builder::new().method(Method::Spdk).build() {
Ok(_handle) => {
println!("Method::Spdk handle constructed successfully.");
println!("(this would only happen with `--features spdk` AND an");
println!("eligible host AND a future `fsys-spdk` shipping the");
println!("real backend implementation)");
}
Err(Error::FeatureNotEnabled { feature }) => {
println!("FeatureNotEnabled — rebuild with `--features {feature}`");
println!("to opt into the SPDK backend wiring. Note that with");
println!("the feature on, the eligibility probe will still gate");
println!("the actual handle construction.");
}
Err(Error::SpdkUnavailable { reason }) => {
println!("SpdkUnavailable — fix the precondition and retry:");
println!(" {reason}");
println!();
println!("See `docs/SPDK.md` for per-reason remediation steps");
println!("(hugepages allocation, IOMMU, device binding, etc.).");
}
Err(other) => {
println!("Unexpected error from Method::Spdk: {other}");
}
}
}