Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try to optimize getting all controllers #1659

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions rust/agama-lib/src/storage/client/zfcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ pub async fn get_luns(controller_id: String, wwpn: String) -> Result<Vec<String>
///
/// `controller_id`: controller id
pub async fn get_luns_map(
controller_id: &str,
controller_id: String,
) -> Result<HashMap<String, Vec<String>>, ServiceError> {
let wwpns = get_wwpns(controller_id).await?;
let wwpns = get_wwpns(controller_id.as_str()).await?;
let mut tasks = vec![];
for wwpn in wwpns {
tasks.push((
Expand All @@ -90,6 +90,15 @@ pub async fn get_luns_map(

const ZFCP_CONTROLLER_PREFIX: &'static str = "/org/opensuse/Agama/Storage1/zfcp_controllers";

/// Partial zfcp controller data used for thread processing
/// TODO: for final version move all those thread related methods to this struct to procude final result
struct PartialZFCPController {
pub id: String,
pub channel: String,
pub lun_scan: bool,
pub active: bool
}

/// Client to connect to Agama's D-Bus API for zFCP management.
#[derive(Clone)]
pub struct ZFCPClient<'a> {
Expand Down Expand Up @@ -153,25 +162,40 @@ impl<'a> ZFCPClient<'a> {
) -> Result<Vec<(OwnedObjectPath, ZFCPController)>, ServiceError> {
let managed_objects = self.object_manager_proxy.get_managed_objects().await?;

let mut devices: Vec<(OwnedObjectPath, ZFCPController)> = vec![];
let mut devices: Vec<(OwnedObjectPath, PartialZFCPController)> = vec![];
for (path, ifaces) in managed_objects {
if let Some(properties) = ifaces.get("org.opensuse.Agama.Storage1.ZFCP.Controller") {
let id = extract_id_from_path(&path)?.to_string();
let channel: String = get_property(properties, "Channel")?;
let luns_map = get_luns_map(id.as_str()).await?;
devices.push((
path,
ZFCPController {
PartialZFCPController {
id: id,
channel: channel,
lun_scan: get_property(properties, "LUNScan")?,
active: get_property(properties, "Active")?,
luns_map: luns_map, // try to use optimized thred version here
},
))
}
}
Ok(devices)
let mut tasks = vec![];
for (_path, partial_controller) in &devices {
tasks.push(
tokio::spawn(get_luns_map(partial_controller.channel.clone()))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this additional paralellization time is reduced to 5.3 seconds. So basically for two controllers with 3 LUNS in total it is gets to half of time. I expect that for bigger systems it will be even more significant.

)
}
let mut result = Vec::with_capacity(devices.len());
for (index, task) in tasks.into_iter().enumerate() {
let (path, partial) = devices.get(index).unwrap();
result.push((path.clone(), ZFCPController {
id: partial.id.clone(),
channel: partial.channel.clone(),
lun_scan: partial.lun_scan,
active: partial.active,
luns_map: task.await.expect("thread join failed")?,
}));
}
Ok(result)
}

async fn get_controller_proxy(
Expand Down
Loading