Skip to content

Commit

Permalink
Merge pull request #93 from openebs/trtype_str
Browse files Browse the repository at this point in the history
chore: add transport to subsystem match criteria
  • Loading branch information
avishnu authored Sep 16, 2024
2 parents c9cdc3a + 9488339 commit ec2e3b4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
15 changes: 14 additions & 1 deletion nvmeadm/src/nvmf_discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static HOST_INFO: once_cell::sync::Lazy<HostInfo> = once_cell::sync::Lazy::new(|
});

/// The TrType struct for all known transports types note: we are missing loop
#[derive(Clone, Debug, Primitive)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Primitive)]
#[allow(non_camel_case_types)]
pub enum TrType {
rdma = 1,
Expand All @@ -73,6 +73,19 @@ impl fmt::Display for TrType {
}
}

impl TryFrom<String> for TrType {
type Error = String;

fn try_from(value: String) -> Result<Self, Self::Error> {
match value.as_str() {
"rdma" => Ok(TrType::rdma),
"fc" => Ok(TrType::fc),
"tcp" => Ok(TrType::tcp),
_ => Err(format!("Invalid TrType: {}", value)),
}
}
}

impl FromStr for TrType {
type Err = String;

Expand Down
19 changes: 13 additions & 6 deletions nvmeadm/src/nvmf_subsystem.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{error, parse_value};
use crate::{error, nvmf_discovery::TrType, parse_value};
use error::{
nvme_error::{FileIoFailed, InvalidPath, SubsystemFailure},
NvmeError,
Expand Down Expand Up @@ -243,15 +243,22 @@ impl Subsystem {

/// Returns the particular subsystem based on the nqn and address.
// TODO: Optimize this code.
pub fn get(host: &str, port: &u16, nqn: &str) -> Result<Subsystem, NvmeError> {
pub fn get(
host: &str,
port: &u16,
transport: TrType,
nqn: &str,
) -> Result<Subsystem, NvmeError> {
let nvme_subsystems = NvmeSubsystems::new()?;

let host = host.to_string();
let sport = port.to_string();
match nvme_subsystems
.flatten()
.find(|subsys| subsys.nqn == *nqn && subsys.address.match_host_port(&host, &sport))
{
let trstring = transport.to_string();
match nvme_subsystems.flatten().find(|subsys| {
subsys.nqn == *nqn
&& subsys.address.match_host_port(&host, &sport)
&& subsys.transport.eq_ignore_ascii_case(trstring.as_str())
}) {
None => Err(NvmeError::SubsystemNotFound {
nqn: nqn.to_string(),
host: host.to_string(),
Expand Down

0 comments on commit ec2e3b4

Please sign in to comment.