From 1bd0f98fe03932d5d900311382e04b6f18ce9788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Stein?= Date: Wed, 19 Oct 2022 14:09:47 +0200 Subject: [PATCH 1/3] Add new flag --disable-compression/-D that allows writing ZIP file uncompressed. Also rewrite coredump piping code to use io::copy which prevents core dump corruption in large core dumps. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Stein --- core-dump-composer/src/config.rs | 14 ++++++++++++-- core-dump-composer/src/main.rs | 25 ++++++++++++------------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/core-dump-composer/src/config.rs b/core-dump-composer/src/config.rs index 5711600..2be0f7e 100644 --- a/core-dump-composer/src/config.rs +++ b/core-dump-composer/src/config.rs @@ -26,6 +26,7 @@ pub struct CoreConfig { pub os_hostname: String, pub filename_template: String, pub params: CoreParams, + pub disable_compression: bool, } #[derive(Serialize)] @@ -62,6 +63,7 @@ impl CoreConfig { .unwrap_or("120") .parse::() .unwrap(); + let disable_compression = matches.contains_id("disable-compression"); let uuid = Uuid::new_v4(); @@ -144,6 +146,7 @@ impl CoreConfig { filename_template, log_length, params, + disable_compression, }) } @@ -208,11 +211,11 @@ impl CoreConfig { format!("{}-ps-info.json", self.get_templated_name()) } - pub fn get_image_filename(&self, counter: u32) -> String { + pub fn get_image_filename(&self, counter: usize) -> String { format!("{}-{}-image-info.json", self.get_templated_name(), counter) } - pub fn get_log_filename(&self, counter: u32) -> String { + pub fn get_log_filename(&self, counter: usize) -> String { format!("{}-{}.log", self.get_templated_name(), counter) } pub fn get_zip_full_path(&self) -> String { @@ -315,6 +318,13 @@ pub fn try_get_matches() -> clap::Result { .takes_value(true) .help("test-threads mapped to support the test scenarios"), ) + .arg( + Arg::new("disable-compression") + .short('D') + .long("disable-compression") + .takes_value(false) + .help("Disables deflate compression in resulting zip file and stores data uncompressed."), + ) .try_get_matches() } diff --git a/core-dump-composer/src/main.rs b/core-dump-composer/src/main.rs index bb5e8a9..0393088 100644 --- a/core-dump-composer/src/main.rs +++ b/core-dump-composer/src/main.rs @@ -111,8 +111,13 @@ fn handle(mut cc: config::CoreConfig) -> Result<(), anyhow::Error> { cc.set_podname(podname.to_string()); // Create the base zip file that we are going to put everything into + let compression_method = if cc.disable_compression { + zip::CompressionMethod::Stored + } else { + zip::CompressionMethod::Deflated + }; let options = FileOptions::default() - .compression_method(zip::CompressionMethod::Deflated) + .compression_method(compression_method) .unix_permissions(0o444) .large_file(true); @@ -159,20 +164,14 @@ fn handle(mut cc: config::CoreConfig) -> Result<(), anyhow::Error> { let stdin = io::stdin(); let mut stdin = stdin.lock(); - let mut data = [0u8; 8192]; - while let Ok(n) = stdin.read(&mut data) { - if n == 0 { - break; + match io::copy(&mut stdin, &mut zip) { + Ok(v) => v, + Err(e) => { + error!("Error writing core file \n{}", e); + process::exit(1); } - match zip.write_all(&data) { - Ok(v) => v, - Err(e) => { - error!("Error writing core file \n{}", e); - process::exit(1); - } - }; - } + }; zip.flush()?; if cc.ignore_crio { From 5b400088ef696875f891023e3dca35463d2cd64c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Stein?= Date: Wed, 19 Oct 2022 14:11:15 +0200 Subject: [PATCH 2/3] Make sure to not overwrite information files if POD contains multiple containers. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Stein --- core-dump-composer/src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core-dump-composer/src/main.rs b/core-dump-composer/src/main.rs index 0393088..74d1f3a 100644 --- a/core-dump-composer/src/main.rs +++ b/core-dump-composer/src/main.rs @@ -305,8 +305,7 @@ fn handle(mut cc: config::CoreConfig) -> Result<(), anyhow::Error> { debug!("Successfully got the process details {}", ps_object); if let Some(containers) = ps_object["containers"].as_array() { - for container in containers { - let counter = 0; + for (counter, container) in containers.iter().enumerate() { let img_ref = match container["imageRef"].as_str() { Some(v) => v, None => { From 02f29c88a360b379f56ac1fc6e3d3417f0338be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Stein?= Date: Fri, 4 Nov 2022 10:27:47 +0100 Subject: [PATCH 3/3] Change default timeout to 600 i.e. 10 minutes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Stein --- core-dump-composer/src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-dump-composer/src/config.rs b/core-dump-composer/src/config.rs index 2be0f7e..f555ecb 100644 --- a/core-dump-composer/src/config.rs +++ b/core-dump-composer/src/config.rs @@ -60,7 +60,7 @@ impl CoreConfig { let pathname = matches.value_of("pathname").unwrap_or("").to_string(); let timeout = matches .value_of("timeout") - .unwrap_or("120") + .unwrap_or("600") .parse::() .unwrap(); let disable_compression = matches.contains_id("disable-compression");