From 55b08fb68341eb292aa8da72d1b183912a20029d Mon Sep 17 00:00:00 2001 From: Bruce Leidl Date: Wed, 30 Jan 2019 14:11:30 -0500 Subject: [PATCH] decompress images in parallel by spawning a thread for each one --- citadel-install/src/main.rs | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/citadel-install/src/main.rs b/citadel-install/src/main.rs index 545a94e..a1fa3a6 100644 --- a/citadel-install/src/main.rs +++ b/citadel-install/src/main.rs @@ -8,11 +8,13 @@ mod disks; use std::result; use std::path::Path; use std::env; -use std::thread; use std::time; use std::fs; +use std::ffi::OsStr; +use std::thread::{self,JoinHandle}; use std::process::exit; use failure::Error; +use libcitadel::ResourceImage; pub type Result = result::Result; @@ -48,14 +50,15 @@ fn live_setup() -> Result<()> { if !Path::new("/etc/initrd-release").exists() { bail!("Not running in initramfs, cannot do live-setup"); } - let installer = installer::Installer::new(); - installer.live_setup() + let installer = installer::Installer::new_livesetup(); + installer.run() } fn copy_artifacts() -> Result<()> { for _ in 0..3 { if try_copy_artifacts()? { + decompress_images()?; return Ok(()) } // Try again after waiting for more devices to be discovered @@ -131,6 +134,30 @@ fn deploy_syslinux_artifacts() -> Result<()> { Ok(()) } +fn decompress_images() -> Result<()> { + println!("decompressing images"); + let mut threads = Vec::new(); + for entry in fs::read_dir("/run/images")? { + let entry = entry?; + if entry.path().extension() == Some(OsStr::new("img")) { + if let Ok(image) = ResourceImage::from_path(&entry.path()) { + threads.push(decompress_one_image(image)); + } + } + } + for t in threads { + t.join().unwrap()?; + } + Ok(()) + +} + +fn decompress_one_image(image: ResourceImage) -> JoinHandle> { + thread::spawn(move ||{ + image.decompress() + }) +} + fn cli_install() -> Result<()> { let ok = cli::run_cli_install()?; if !ok {