Skip to content

Commit fe8cc56

Browse files
committed
feat: use transport specific nvmf uri scheme
Signed-off-by: Diwakar Sharma <[email protected]>
1 parent b90ec3e commit fe8cc56

File tree

9 files changed

+39
-14
lines changed

9 files changed

+39
-14
lines changed

io-engine/src/bdev/dev.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ pub(crate) mod uri {
6666
}
6767
"malloc" => Ok(Box::new(malloc::Malloc::try_from(&url)?)),
6868
"null" => Ok(Box::new(null_bdev::Null::try_from(&url)?)),
69-
"nvmf" => Ok(Box::new(nvmx::NvmfDeviceTemplate::try_from(&url)?)),
69+
// keeping nvmf scheme so existing tests(if any, setting this
70+
// scheme) work. The replicas and nexus however should
71+
// always be exposing nvmf+tcp or nvmf+rdma now.
72+
"nvmf" | "nvmf+tcp" | "nvmf+rdma+tcp" => {
73+
Ok(Box::new(nvmx::NvmfDeviceTemplate::try_from(&url)?))
74+
}
7075
"pcie" => Ok(Box::new(nvme::NVMe::try_from(&url)?)),
7176
"uring" => Ok(Box::new(uring::Uring::try_from(&url)?)),
7277
"nexus" => Ok(Box::new(nx::Nexus::try_from(&url)?)),

io-engine/src/bdev_api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ where
126126
Ok(device) if device.get_name() == bdev.name() => {
127127
bdev.driver()
128128
== match uri.scheme() {
129-
"nvmf" | "pcie" => "nvme",
129+
"nvmf" | "nvmf+tcp" | "nvmf+rdma+tcp" | "pcie" => "nvme",
130130
scheme => scheme,
131131
}
132132
}
@@ -143,7 +143,7 @@ where
143143
Ok(device) if device.get_name() == bdev.name() => {
144144
bdev.driver()
145145
== match uri.scheme() {
146-
"nvmf" | "pcie" => "nvme",
146+
"nvmf" | "nvmf+tcp" | "nvmf+rdma+tcp" | "pcie" => "nvme",
147147
scheme => scheme,
148148
}
149149
}

io-engine/src/core/bdev.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ where
203203
type Error = CoreError;
204204
type Output = String;
205205

206-
/// share the bdev over NVMe-OF TCP
206+
/// share the bdev over NVMe-OF TCP(and RDMA if enabled)
207207
async fn share_nvmf(
208208
self: Pin<&mut Self>,
209209
props: Option<NvmfShareProps>,

io-engine/src/subsys/nvmf/transport.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,18 @@ impl TransportId {
154154

155155
impl Display for TransportId {
156156
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
157+
// If an rdma transport is found in transport id, we modify the
158+
// trstring for uri scheme to explicitly indicate the tcp support
159+
// also by default when there is rdma available.
160+
let trstring = match self.0.trstring.as_str() {
161+
"RDMA" => "rdma+tcp".to_string(),
162+
_else => _else.to_lowercase(),
163+
};
164+
157165
write!(
158166
f,
159-
"nvmf://{}:{}",
167+
"nvmf+{}://{}:{}",
168+
trstring,
160169
self.0.traddr.as_str(),
161170
self.0.trsvcid.as_str()
162171
)

io-engine/src/target/nvmf.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,16 @@ pub async fn unshare(uuid: &str) -> Result<(), NvmfError> {
3535

3636
pub fn get_uri(uuid: &str) -> Option<String> {
3737
if let Some(ss) = NvmfSubsystem::nqn_lookup(uuid) {
38-
// for now we only pop the first but we can share a bdev
39-
// over multiple nqn's
40-
ss.uri_endpoints().unwrap().pop()
38+
// If there is rdma capable uri available, return that. Otherwise,
39+
// for now we only pop the most relevant, but we can share a bdev
40+
// over multiple nqn's.
41+
let mut uris = ss.uri_endpoints().expect("no uri endpoints");
42+
let rdma_uri = uris
43+
.iter()
44+
.find(|u| u.starts_with("nvmf+rdma+tcp"))
45+
.cloned();
46+
47+
rdma_uri.or(uris.pop())
4148
} else {
4249
None
4350
}

io-engine/tests/nvmf.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,10 @@ async fn nvmf_set_target_interface() {
156156
.into_inner()
157157
.uri;
158158

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

163164
hdl.bdev
164165
.unshare(CreateReply {

libnvme-rs/src/nvme_uri.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ impl Drop for NvmeStringWrapper {
4242
#[derive(Debug, PartialEq)]
4343
enum NvmeTransportType {
4444
Tcp,
45+
Rdma,
4546
}
4647

4748
impl NvmeTransportType {
4849
fn to_str(&self) -> &str {
4950
match self {
5051
NvmeTransportType::Tcp => "tcp",
52+
NvmeTransportType::Rdma => "rdma",
5153
}
5254
}
5355
}
@@ -83,6 +85,7 @@ impl TryFrom<&str> for NvmeTarget {
8385

8486
let trtype = match url.scheme() {
8587
"nvmf" | "nvmf+tcp" => Ok(NvmeTransportType::Tcp),
88+
"nvmf+rdma+tcp" => Ok(NvmeTransportType::Rdma),
8689
_ => Err(NvmeError::UrlError {
8790
source: ParseError::IdnaError,
8891
}),

test/grpc/test_common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const CSI_ID = 'test-node-id';
2121
const LOCALHOST = '127.0.0.1';
2222
const NVME_MODEL_ID = 'Mayastor NVMe controller';
2323
const NVME_NQN_PREFIX = 'nqn.2019-05.io.openebs';
24-
const NVMF_URI = /^nvmf:\/\/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):\d{1,5}\/nqn.2019-05.io.openebs:/;
24+
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:/;
2525

2626
const testPort = process.env.TEST_PORT || GRPC_PORT;
2727
const myIp = getMyIp() || LOCALHOST;

test/grpc/test_replica.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ describe('replica', function () {
290290
(err, res) => {
291291
if (err) return done(err);
292292
assert.match(res.uri, NVMF_URI);
293-
assert.equal(res.uri.match(NVMF_URI)[1], common.getMyIp());
293+
assert.equal(res.uri.match(NVMF_URI)[2], common.getMyIp());
294294

295295
client.listReplicas({}, (err, res) => {
296296
if (err) return done(err);
@@ -548,7 +548,7 @@ describe('replica', function () {
548548
assert.equal(res.size, 96 * 1024 * 1024);
549549
assert.equal(res.share, 'REPLICA_NVMF');
550550
assert.match(res.uri, NVMF_URI);
551-
assert.equal(res.uri.match(NVMF_URI)[1], common.getMyIp());
551+
assert.equal(res.uri.match(NVMF_URI)[2], common.getMyIp());
552552
uri = res.uri;
553553
done();
554554
}
@@ -635,7 +635,7 @@ describe('replica', function () {
635635
if (err) return done(err);
636636

637637
assert.match(res.uri, NVMF_URI);
638-
assert.equal(res.uri.match(NVMF_URI)[1], common.getMyIp());
638+
assert.equal(res.uri.match(NVMF_URI)[2], common.getMyIp());
639639
uri = res.uri;
640640
done();
641641
}

0 commit comments

Comments
 (0)