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 Sep 16, 2024
1 parent b90ec3e commit fe8cc56
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 14 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
2 changes: 1 addition & 1 deletion test/grpc/test_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const CSI_ID = 'test-node-id';
const LOCALHOST = '127.0.0.1';
const NVME_MODEL_ID = 'Mayastor NVMe controller';
const NVME_NQN_PREFIX = 'nqn.2019-05.io.openebs';
const NVMF_URI = /^nvmf:\/\/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):\d{1,5}\/nqn.2019-05.io.openebs:/;
const NVMF_URI = /^nvmf\+(tcp|rdma\+tcp):\/\/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):\d{1,5}\/nqn.2019-05.io.openebs:/;

const testPort = process.env.TEST_PORT || GRPC_PORT;
const myIp = getMyIp() || LOCALHOST;
Expand Down
6 changes: 3 additions & 3 deletions test/grpc/test_replica.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ describe('replica', function () {
(err, res) => {
if (err) return done(err);
assert.match(res.uri, NVMF_URI);
assert.equal(res.uri.match(NVMF_URI)[1], common.getMyIp());
assert.equal(res.uri.match(NVMF_URI)[2], common.getMyIp());

client.listReplicas({}, (err, res) => {
if (err) return done(err);
Expand Down Expand Up @@ -548,7 +548,7 @@ describe('replica', function () {
assert.equal(res.size, 96 * 1024 * 1024);
assert.equal(res.share, 'REPLICA_NVMF');
assert.match(res.uri, NVMF_URI);
assert.equal(res.uri.match(NVMF_URI)[1], common.getMyIp());
assert.equal(res.uri.match(NVMF_URI)[2], common.getMyIp());
uri = res.uri;
done();
}
Expand Down Expand Up @@ -635,7 +635,7 @@ describe('replica', function () {
if (err) return done(err);

assert.match(res.uri, NVMF_URI);
assert.equal(res.uri.match(NVMF_URI)[1], common.getMyIp());
assert.equal(res.uri.match(NVMF_URI)[2], common.getMyIp());
uri = res.uri;
done();
}
Expand Down

0 comments on commit fe8cc56

Please sign in to comment.