Skip to content

Commit

Permalink
Try #1726:
Browse files Browse the repository at this point in the history
  • Loading branch information
mayastor-bors committed Sep 16, 2024
2 parents b90ec3e + 64be234 commit ece9673
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 10 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+tcp" => {
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+tcp" | "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+tcp" | "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
11 changes: 10 additions & 1 deletion io-engine/src/subsys/nvmf/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,18 @@ impl TransportId {

impl Display for TransportId {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
// If an rdma transport is found in transport id, we modify the
// trstring for uri scheme to explicitly indicate the tcp support
// also by default when there is rdma available.
let trstring = match self.0.trstring.as_str() {
"RDMA" => "rdma+tcp".to_string(),
_else => _else.to_lowercase(),
};

write!(
f,
"nvmf://{}:{}",
"nvmf+{}://{}:{}",
trstring,
self.0.traddr.as_str(),
self.0.trsvcid.as_str()
)
Expand Down
13 changes: 10 additions & 3 deletions io-engine/src/target/nvmf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,16 @@ 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()
// If there is rdma capable uri available, return that. Otherwise,
// for now we only pop the most relevant, but we can share a bdev
// over multiple nqn's.
let mut uris = ss.uri_endpoints().expect("no uri endpoints");
let rdma_uri = uris
.iter()
.find(|u| u.starts_with("nvmf+rdma+tcp"))
.cloned();

rdma_uri.or(uris.pop())
} else {
None
}
Expand Down
5 changes: 3 additions & 2 deletions io-engine/tests/nvmf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ async fn nvmf_set_target_interface() {
.into_inner()
.uri;

let re = Regex::new(r"^nvmf://([0-9.]+):[0-9]+/.*$").unwrap();
let re = Regex::new(r"^nvmf(\+rdma\+tcp|\+tcp)://([0-9.]+):[0-9]+/.*$")
.unwrap();
let cap = re.captures(&bdev_uri).unwrap();
let shared_ip = cap.get(1).unwrap().as_str();
let shared_ip = cap.get(2).unwrap().as_str();

hdl.bdev
.unshare(CreateReply {
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+tcp" => Ok(NvmeTransportType::Rdma),
_ => Err(NvmeError::UrlError {
source: ParseError::IdnaError,
}),
Expand Down

0 comments on commit ece9673

Please sign in to comment.