Skip to content

Commit c4cbfcd

Browse files
committed
Clean up disk caching query, add more info
This should make it easier to debug why the GHA runs are failing. Signed-off-by: Colin Walters <[email protected]>
1 parent 93393e2 commit c4cbfcd

File tree

3 files changed

+40
-30
lines changed

3 files changed

+40
-30
lines changed

crates/kit/src/cache_metadata.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,26 @@ impl DiskImageMetadata {
165165
}
166166
}
167167

168+
#[derive(Debug, thiserror::Error)]
169+
pub(crate) enum ValidationError {
170+
#[error("file is missing")]
171+
MissingFile,
172+
#[error("Missing extended attribute metadata")]
173+
MissingXattr,
174+
#[error("Hash mismatch")]
175+
HashMismatch,
176+
}
177+
168178
/// Check if a cached disk image can be reused by comparing cache hashes
169179
pub fn check_cached_disk(
170180
path: &Path,
171181
image_digest: &str,
172182
install_options: &InstallOptions,
173183
kernel_args: &[String],
174-
) -> Result<bool> {
184+
) -> Result<Result<(), ValidationError>> {
175185
if !path.exists() {
176186
tracing::debug!("Disk image {:?} does not exist", path);
177-
return Ok(false);
187+
return Ok(Err(ValidationError::MissingFile));
178188
}
179189

180190
// Create metadata for the current request to compute expected hash
@@ -198,7 +208,7 @@ pub fn check_cached_disk(
198208
.to_string(),
199209
None => {
200210
tracing::debug!("No cache hash xattr found on {:?}", path);
201-
return Ok(false);
211+
return Ok(Err(ValidationError::MissingXattr));
202212
}
203213
};
204214

@@ -209,6 +219,7 @@ pub fn check_cached_disk(
209219
path,
210220
expected_hash
211221
);
222+
Ok(Ok(()))
212223
} else {
213224
tracing::debug!(
214225
"Cached disk at {:?} does not match requirements. \
@@ -217,9 +228,8 @@ pub fn check_cached_disk(
217228
expected_hash,
218229
cached_hash
219230
);
231+
Ok(Err(ValidationError::HashMismatch))
220232
}
221-
222-
Ok(matches)
223233
}
224234

225235
#[cfg(test)]

crates/kit/src/libvirt/base_disks.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
use crate::cache_metadata::DiskImageMetadata;
88
use crate::install_options::InstallOptions;
99
use camino::{Utf8Path, Utf8PathBuf};
10-
use color_eyre::{eyre::Context, Result};
10+
use color_eyre::eyre::{eyre, Context};
11+
use color_eyre::Result;
1112
use std::fs;
1213
use tracing::{debug, info};
1314

@@ -45,7 +46,9 @@ pub fn find_or_create_base_disk(
4546
image_digest,
4647
install_options,
4748
kernel_args,
48-
)? {
49+
)?
50+
.is_ok()
51+
{
4952
info!("Found cached base disk: {:?}", base_disk_path);
5053
return Ok(base_disk_path);
5154
} else {
@@ -130,10 +133,11 @@ fn create_base_disk(
130133
image_digest,
131134
install_options,
132135
kernel_args,
133-
);
136+
)
137+
.context("Querying cached disk")?;
134138

135139
match metadata_valid {
136-
Ok(true) => {
140+
Ok(()) => {
137141
// All validations passed - move to final location
138142
if let Err(e) = fs::rename(&temp_disk_path, base_disk_path) {
139143
cleanup_temp_disk();
@@ -166,15 +170,9 @@ fn create_base_disk(
166170
);
167171
Ok(())
168172
}
169-
Ok(false) => {
170-
cleanup_temp_disk();
171-
Err(color_eyre::eyre::eyre!(
172-
"Base disk created but metadata verification failed"
173-
))
174-
}
175173
Err(e) => {
176174
cleanup_temp_disk();
177-
Err(e).with_context(|| "Failed to check disk metadata")
175+
Err(eyre!("Generated disk metadata validation failed: {e}"))
178176
}
179177
}
180178
}

crates/kit/src/to_disk.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -293,24 +293,26 @@ pub fn run(opts: ToDiskOpts) -> Result<()> {
293293
let image_digest = inspect.digest.to_string();
294294

295295
// Check if cached disk matches our requirements
296-
let matches = crate::cache_metadata::check_cached_disk(
296+
match crate::cache_metadata::check_cached_disk(
297297
opts.target_disk.as_std_path(),
298298
&image_digest,
299299
&opts.install,
300300
&opts.additional.common.kernel_args,
301-
)?;
302-
303-
if matches {
304-
println!(
305-
"Reusing existing cached disk image (digest {image_digest}) at: {}",
306-
opts.target_disk
307-
);
308-
return Ok(());
309-
} else {
310-
debug!("Existing disk does not match requirements, recreating");
311-
// Remove the existing disk so we can recreate it
312-
std::fs::remove_file(&opts.target_disk)
313-
.with_context(|| format!("Failed to remove existing disk {}", opts.target_disk))?;
301+
)? {
302+
Ok(()) => {
303+
println!(
304+
"Reusing existing cached disk image (digest {image_digest}) at: {}",
305+
opts.target_disk
306+
);
307+
return Ok(());
308+
}
309+
Err(e) => {
310+
debug!("Existing disk does not match requirements, recreating: {e}");
311+
// Remove the existing disk so we can recreate it
312+
std::fs::remove_file(&opts.target_disk).with_context(|| {
313+
format!("Failed to remove existing disk {}", opts.target_disk)
314+
})?;
315+
}
314316
}
315317
}
316318

0 commit comments

Comments
 (0)