Skip to content

Commit

Permalink
[sled-agent][package] Make zone uninstallation concurrent (#1178)
Browse files Browse the repository at this point in the history
  • Loading branch information
smklein authored Jun 15, 2022
1 parent 84390f8 commit 0b11803
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
5 changes: 3 additions & 2 deletions package/src/bin/omicron-package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,10 @@ fn do_install(
}

fn uninstall_all_omicron_zones() -> Result<()> {
for zone in zone::Zones::get()? {
zone::Zones::get()?.into_par_iter().try_for_each(|zone| -> Result<()> {
zone::Zones::halt_and_remove(zone.name())?;
}
Ok(())
})?;
Ok(())
}

Expand Down
44 changes: 31 additions & 13 deletions sled-agent/src/sled_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::params::{
};
use crate::services::ServiceManager;
use crate::storage_manager::StorageManager;
use futures::stream::{self, StreamExt, TryStreamExt};
use omicron_common::api::{
internal::nexus::DiskRuntimeState, internal::nexus::InstanceRuntimeState,
internal::nexus::UpdateArtifact,
Expand Down Expand Up @@ -169,10 +170,18 @@ impl SledAgent {
// re-establish contact (i.e., if the Sled Agent crashed, but we wanted
// to leave the running Zones intact).
let zones = Zones::get()?;
for z in zones {
warn!(log, "Deleting existing zone"; "zone_name" => z.name());
Zones::halt_and_remove_logged(&log, z.name())?;
}
stream::iter(zones)
.zip(stream::iter(std::iter::repeat(log.clone())))
.map(Ok::<_, crate::zone::AdmError>)
.try_for_each_concurrent(
None,
|(zone, log)| async {
tokio::task::spawn_blocking(move || {
warn!(log, "Deleting existing zone"; "zone_name" => zone.name());
Zones::halt_and_remove_logged(&log, zone.name())
}).await.unwrap()
}
).await?;

// Identify all VNICs which should be managed by the Sled Agent.
//
Expand All @@ -187,15 +196,24 @@ impl SledAgent {
// Note that we don't currently delete the VNICs in any particular
// order. That should be OK, since we're definitely deleting the guest
// VNICs before the xde devices, which is the main constraint.
for vnic in Dladm::get_vnics()? {
warn!(
log,
"Deleting existing VNIC";
"vnic_name" => &vnic,
"vnic_kind" => ?VnicKind::from_name(&vnic).unwrap(),
);
Dladm::delete_vnic(&vnic)?;
}
let vnics = Dladm::get_vnics()?;
stream::iter(vnics)
.zip(stream::iter(std::iter::repeat(log.clone())))
.map(Ok::<_, crate::illumos::dladm::DeleteVnicError>)
.try_for_each_concurrent(None, |(vnic, log)| async {
tokio::task::spawn_blocking(move || {
warn!(
log,
"Deleting existing VNIC";
"vnic_name" => &vnic,
"vnic_kind" => ?VnicKind::from_name(&vnic).unwrap(),
);
Dladm::delete_vnic(&vnic)
})
.await
.unwrap()
})
.await?;

// Also delete any extant xde devices. These should also eventually be
// recovered / tracked, to avoid interruption of any guests that are
Expand Down

0 comments on commit 0b11803

Please sign in to comment.