Skip to content

Commit

Permalink
feat(nexus): allow shared replica to be added as local child
Browse files Browse the repository at this point in the history
Move to a build of SPDK that allows that and change the existing
nexus_multipath cargo test to test that scenario.

This also means a bdev could be shared over multiple protocols so
disallow that for a bdev that is already claimed. Add a message for
the iSCSI Error::CreateTarget for consistency with nvmf.

Rename the cargo test that checks it to nexus_share_test for clarity.
  • Loading branch information
jonathan-teh committed Feb 24, 2021
1 parent 850dc5d commit 347d37a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
5 changes: 5 additions & 0 deletions mayastor/src/subsys/nvmf/subsystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ impl TryFrom<Bdev> for NvmfSubsystem {
type Error = Error;

fn try_from(bdev: Bdev) -> Result<Self, Self::Error> {
if bdev.is_claimed() {
return Err(Error::CreateTarget {
msg: "already shared".to_string(),
});
}
let ss = NvmfSubsystem::new(bdev.name().as_str())?;
ss.set_ana_reporting(true)?;
ss.allow_any(true);
Expand Down
11 changes: 9 additions & 2 deletions mayastor/src/target/iscsi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub enum Error {
#[snafu(display("Failed to create default initiator group"))]
CreateInitiatorGroup {},
#[snafu(display("Failed to create iscsi target"))]
CreateTarget {},
CreateTarget { msg: String },
#[snafu(display("Failed to destroy iscsi target"))]
DestroyTarget { source: Errno },
}
Expand Down Expand Up @@ -217,7 +217,9 @@ fn share_as_iscsi_target(
};
if tgt.is_null() {
error!("Failed to create iscsi target {}", bdev.name());
Err(Error::CreateTarget {})
Err(Error::CreateTarget {
msg: "tgt pointer is None".to_string(),
})
} else {
let _ = unsafe {
spdk_bdev_module_claim_bdev(
Expand All @@ -233,6 +235,11 @@ fn share_as_iscsi_target(
/// Export given bdev over iscsi. That involves creating iscsi target and
/// adding the bdev as LUN to it.
pub fn share(bdev_name: &str, bdev: &Bdev, side: Side) -> Result<String> {
if bdev.is_claimed() {
return Err(Error::CreateTarget {
msg: "already shared".to_string(),
});
}
let iqn = match side {
Side::Nexus => share_as_iscsi_target(
bdev_name,
Expand Down
17 changes: 3 additions & 14 deletions mayastor/tests/nexus_multipath.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Multipath NVMf tests
//! Create the same nexus on both nodes with a replica on 1 node their child.
//! Create the same nexus on both nodes with a replica on 1 node as their child.
use mayastor::{
bdev::{nexus_create, nexus_lookup},
core::MayastorCliArgs,
Expand All @@ -10,7 +10,6 @@ use rpc::mayastor::{
CreateReplicaRequest,
PublishNexusRequest,
ShareProtocolNexus,
ShareReplicaRequest,
};
use std::process::Command;

Expand Down Expand Up @@ -45,15 +44,15 @@ async fn nexus_multipath() {
.await
.unwrap();

// create replica, not shared
// create replica, shared over nvmf
hdls[0]
.mayastor
.create_replica(CreateReplicaRequest {
uuid: UUID.to_string(),
pool: POOL_NAME.to_string(),
size: 32 * 1024 * 1024,
thin: false,
share: 0,
share: 1,
})
.await
.unwrap();
Expand All @@ -69,16 +68,6 @@ async fn nexus_multipath() {
.await
.unwrap();

// share replica
hdls[0]
.mayastor
.share_replica(ShareReplicaRequest {
uuid: UUID.to_string(),
share: 1,
})
.await
.unwrap();

let mayastor = MayastorTest::new(MayastorCliArgs::default());
let ip0 = hdls[0].endpoint.ip();
let nexus_name = format!("nexus-{}", UUID);
Expand Down
2 changes: 1 addition & 1 deletion mayastor/tests/nexus_share.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub mod common;
use common::MayastorTest;

#[tokio::test]
async fn nexus_test() {
async fn nexus_share_test() {
let args = MayastorCliArgs {
reactor_mask: "0x3".into(),
..Default::default()
Expand Down
4 changes: 2 additions & 2 deletions nix/pkgs/libspdk/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ let
src = fetchFromGitHub {
owner = "openebs";
repo = "spdk";
rev = "37164626e403cca75afac7e8a47cd53b730bc921";
sha256 = "0gkdqqs990hgblz0rlkg8355klxnxi2cdvy5p6ws9nqz8cxwrg14";
rev = "b0768fdc07c5b0c8d7a6eb7d43499a45e55b9a9d";
sha256 = "14lx0g7701l14npjfqqrfcfp2rhba2x4545m396gqilpg838i8x4";
#sha256 = stdenv.lib.fakeSha256;
fetchSubmodules = true;
};
Expand Down

0 comments on commit 347d37a

Please sign in to comment.