diff --git a/io-engine/src/bdev/nexus/nexus_share.rs b/io-engine/src/bdev/nexus/nexus_share.rs index 3f36c9c3f..71b48b60f 100644 --- a/io-engine/src/bdev/nexus/nexus_share.rs +++ b/io-engine/src/bdev/nexus/nexus_share.rs @@ -94,12 +94,12 @@ impl<'n> Share for Nexus<'n> { } /// TODO - fn bdev_uri(&self) -> Option { + fn bdev_uri(&self) -> Option { unsafe { self.bdev().bdev_uri() } } /// TODO - fn bdev_uri_original(&self) -> Option { + fn bdev_uri_original(&self) -> Option { unsafe { self.bdev().bdev_uri_original() } } } diff --git a/io-engine/src/bdev_api.rs b/io-engine/src/bdev_api.rs index 1cb7390d9..eed216444 100644 --- a/io-engine/src/bdev_api.rs +++ b/io-engine/src/bdev_api.rs @@ -4,7 +4,10 @@ use snafu::Snafu; use std::{convert::TryFrom, num::ParseIntError, str::ParseBoolError}; use url::ParseError; -use crate::{bdev::uri, core::Bdev}; +use crate::{ + bdev::uri, + core::{Bdev, Share}, +}; // parse URI and bdev create/destroy errors common for all types of bdevs #[derive(Debug, Snafu, Clone)] @@ -152,19 +155,7 @@ where type Error = BdevError; fn try_from(bdev: Bdev) -> Result { - for alias in bdev.aliases().iter() { - if let Ok(mut uri) = url::Url::parse(alias) { - if bdev_uri_eq(&bdev, &uri) { - if !uri.query_pairs().any(|e| e.0 == "uuid") { - uri.query_pairs_mut() - .append_pair("uuid", &bdev.uuid_as_string()); - } - return Ok(uri); - } - } - } - - Err(BdevError::BdevNoMatchingUri { + bdev.bdev_uri().ok_or(BdevError::BdevNoMatchingUri { name: bdev.name().to_string(), aliases: bdev.aliases(), }) diff --git a/io-engine/src/core/bdev.rs b/io-engine/src/core/bdev.rs index af4721f0d..b027df613 100644 --- a/io-engine/src/core/bdev.rs +++ b/io-engine/src/core/bdev.rs @@ -279,27 +279,24 @@ where } /// return the URI that was used to construct the bdev - fn bdev_uri(&self) -> Option { - for alias in self.aliases().iter() { - if let Ok(mut uri) = url::Url::parse(alias) { - if bdev_uri_eq(self, &uri) { - if !uri.query_pairs().any(|e| e.0 == "uuid") { - uri.query_pairs_mut() - .append_pair("uuid", &self.uuid_as_string()); - } - return Some(uri.to_string()); - } + fn bdev_uri(&self) -> Option { + self.bdev_uri_original().map(|mut uri| { + if !uri.query_pairs().any(|e| e.0 == "uuid") + && !self.uuid().is_nil() + { + uri.query_pairs_mut() + .append_pair("uuid", &self.uuid_as_string()); } - } - None + uri + }) } /// return the URI that was used to construct the bdev, without uuid - fn bdev_uri_original(&self) -> Option { + fn bdev_uri_original(&self) -> Option { for alias in self.aliases().iter() { if let Ok(uri) = url::Url::parse(alias) { if bdev_uri_eq(self, &uri) { - return Some(uri.to_string()); + return Some(uri); } } } diff --git a/io-engine/src/core/share.rs b/io-engine/src/core/share.rs index 11222a148..e80a0613a 100644 --- a/io-engine/src/core/share.rs +++ b/io-engine/src/core/share.rs @@ -192,8 +192,14 @@ pub trait Share: std::fmt::Debug { fn allowed_hosts(&self) -> Vec; /// TODO - fn bdev_uri(&self) -> Option; + fn bdev_uri(&self) -> Option; + fn bdev_uri_str(&self) -> Option { + self.bdev_uri().map(|uri| uri.to_string()) + } /// TODO - fn bdev_uri_original(&self) -> Option; + fn bdev_uri_original(&self) -> Option; + fn bdev_uri_original_str(&self) -> Option { + self.bdev_uri_original().map(|uri| uri.to_string()) + } } diff --git a/io-engine/src/grpc/v0/mayastor_grpc.rs b/io-engine/src/grpc/v0/mayastor_grpc.rs index 1dafd10fd..91b358cbb 100644 --- a/io-engine/src/grpc/v0/mayastor_grpc.rs +++ b/io-engine/src/grpc/v0/mayastor_grpc.rs @@ -297,7 +297,10 @@ impl From for Pool { fn from(l: Lvs) -> Self { Self { name: l.name().into(), - disks: vec![l.base_bdev().bdev_uri().unwrap_or_else(|| "".into())], + disks: vec![l + .base_bdev() + .bdev_uri_str() + .unwrap_or_else(|| "".into())], state: PoolState::PoolOnline.into(), capacity: l.capacity(), used: l.used(), diff --git a/io-engine/src/grpc/v1/pool.rs b/io-engine/src/grpc/v1/pool.rs index 4f01ebc2e..9c8eea76f 100644 --- a/io-engine/src/grpc/v1/pool.rs +++ b/io-engine/src/grpc/v1/pool.rs @@ -140,7 +140,10 @@ impl From for Pool { Self { uuid: l.uuid(), name: l.name().into(), - disks: vec![l.base_bdev().bdev_uri().unwrap_or_else(|| "".into())], + disks: vec![l + .base_bdev() + .bdev_uri_str() + .unwrap_or_else(|| "".into())], state: PoolState::PoolOnline.into(), capacity: l.capacity(), used: l.used(), diff --git a/io-engine/src/lvs/lvs_lvol.rs b/io-engine/src/lvs/lvs_lvol.rs index 3ae17c655..d00d327a6 100644 --- a/io-engine/src/lvs/lvs_lvol.rs +++ b/io-engine/src/lvs/lvs_lvol.rs @@ -248,11 +248,11 @@ impl Share for Lvol { /// returns the URI that is used to construct the bdev. This is always None /// as lvols can not be created by URIs directly, but only through the /// ['Lvs'] interface. - fn bdev_uri(&self) -> Option { + fn bdev_uri(&self) -> Option { None } - fn bdev_uri_original(&self) -> Option { + fn bdev_uri_original(&self) -> Option { None } } diff --git a/io-engine/src/lvs/lvs_store.rs b/io-engine/src/lvs/lvs_store.rs index e96fbe3a2..7d62a5b9d 100644 --- a/io-engine/src/lvs/lvs_store.rs +++ b/io-engine/src/lvs/lvs_store.rs @@ -539,7 +539,7 @@ impl Lvs { info!("{}: lvs exported successfully", self_str); - bdev_destroy(&base_bdev.bdev_uri_original().unwrap()) + bdev_destroy(&base_bdev.bdev_uri_original_str().unwrap()) .await .map_err(|e| Error::Destroy { source: e, @@ -633,7 +633,7 @@ impl Lvs { info!("{}: lvs destroyed successfully", self_str); - bdev_destroy(&base_bdev.bdev_uri_original().unwrap()) + bdev_destroy(&base_bdev.bdev_uri_original_str().unwrap()) .await .map_err(|e| Error::Destroy { source: e, diff --git a/io-engine/src/subsys/config/pool.rs b/io-engine/src/subsys/config/pool.rs index 015f00fcf..1e5a1993c 100644 --- a/io-engine/src/subsys/config/pool.rs +++ b/io-engine/src/subsys/config/pool.rs @@ -185,7 +185,7 @@ impl From for Pool { Self { name: lvs_bdev.name(), disks: vec![base - .bdev_uri() + .bdev_uri_str() .unwrap_or_else(|| base.name().to_string())], replicas: None, }