Skip to content

Commit

Permalink
feat: use transport specific nvmf uri scheme
Browse files Browse the repository at this point in the history
Signed-off-by: Diwakar Sharma <[email protected]>
  • Loading branch information
dsharma-dc committed Aug 26, 2024
1 parent d09082c commit bdc45cc
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
7 changes: 6 additions & 1 deletion io-engine/src/bdev/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ pub(crate) mod uri {
}
"malloc" => Ok(Box::new(malloc::Malloc::try_from(&url)?)),
"null" => Ok(Box::new(null_bdev::Null::try_from(&url)?)),
"nvmf" => Ok(Box::new(nvmx::NvmfDeviceTemplate::try_from(&url)?)),
// keeping nvmf scheme so existing tests(if any, setting this
// scheme) work. The replicas and nexus however should
// always be exposing nvmf+tcp or nvmf+rdma now.
"nvmf" | "nvmf+tcp" | "nvmf+rdma" => {
Ok(Box::new(nvmx::NvmfDeviceTemplate::try_from(&url)?))
}
"pcie" => Ok(Box::new(nvme::NVMe::try_from(&url)?)),
"uring" => Ok(Box::new(uring::Uring::try_from(&url)?)),
"nexus" => Ok(Box::new(nx::Nexus::try_from(&url)?)),
Expand Down
4 changes: 2 additions & 2 deletions io-engine/src/bdev_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ where
Ok(device) if device.get_name() == bdev.name() => {
bdev.driver()
== match uri.scheme() {
"nvmf" | "pcie" => "nvme",
"nvmf" | "nvmf+tcp" | "nvmf+rdma" | "pcie" => "nvme",
scheme => scheme,
}
}
Expand All @@ -143,7 +143,7 @@ where
Ok(device) if device.get_name() == bdev.name() => {
bdev.driver()
== match uri.scheme() {
"nvmf" | "pcie" => "nvme",
"nvmf" | "nvmf+tcp" | "nvmf+rdma" | "pcie" => "nvme",
scheme => scheme,
}
}
Expand Down
2 changes: 1 addition & 1 deletion io-engine/src/core/bdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ where
type Error = CoreError;
type Output = String;

/// share the bdev over NVMe-OF TCP
/// share the bdev over NVMe-OF TCP(and RDMA if enabled)
async fn share_nvmf(
self: Pin<&mut Self>,
props: Option<NvmfShareProps>,
Expand Down
3 changes: 2 additions & 1 deletion io-engine/src/subsys/nvmf/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ impl Display for TransportId {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"nvmf://{}:{}",
"nvmf+{}://{}:{}",
self.0.trstring.as_str(),
self.0.traddr.as_str(),
self.0.trsvcid.as_str()
)
Expand Down
11 changes: 8 additions & 3 deletions io-engine/src/target/nvmf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ pub async fn unshare(uuid: &str) -> Result<(), NvmfError> {

pub fn get_uri(uuid: &str) -> Option<String> {
if let Some(ss) = NvmfSubsystem::nqn_lookup(uuid) {
// for now we only pop the first but we can share a bdev
// over multiple nqn's
ss.uri_endpoints().unwrap().pop()
// for now we only pop the most relevant but we can share a bdev
// over multiple nqn's. An nvmf+rdma uri will be prioritised for
// returning from here. If not present, then nvmf+tcp will be returned.
let mut uris = ss.uri_endpoints().expect("no uri endpoints");
let rdma_uri =
uris.iter().find(|u| u.starts_with("nvmf+RDMA")).cloned();

rdma_uri.or(uris.pop())
} else {
None
}
Expand Down
3 changes: 3 additions & 0 deletions libnvme-rs/src/nvme_uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ impl Drop for NvmeStringWrapper {
#[derive(Debug, PartialEq)]
enum NvmeTransportType {
Tcp,
Rdma,
}

impl NvmeTransportType {
fn to_str(&self) -> &str {
match self {
NvmeTransportType::Tcp => "tcp",
NvmeTransportType::Rdma => "rdma",
}
}
}
Expand Down Expand Up @@ -83,6 +85,7 @@ impl TryFrom<&str> for NvmeTarget {

let trtype = match url.scheme() {
"nvmf" | "nvmf+tcp" => Ok(NvmeTransportType::Tcp),
"nvmf+rdma" => Ok(NvmeTransportType::Rdma),
_ => Err(NvmeError::UrlError {
source: ParseError::IdnaError,
}),
Expand Down

0 comments on commit bdc45cc

Please sign in to comment.