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

storage: correctly setup size for compressed cache file #845

Merged
merged 1 commit into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
44 changes: 24 additions & 20 deletions storage/src/cache/filecache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,34 +189,40 @@ impl FileCacheEntry {
let digester = blob_info.digester();
let is_legacy_stargz = blob_info.is_legacy_stargz();
let is_compressed = mgr.is_compressed;
let is_zran = blob_info.meta_flags() & BLOB_META_FEATURE_ZRAN != 0;
let need_validation = (mgr.validate || !is_direct_chunkmap) && !is_legacy_stargz;
let is_get_blob_object_supported = !mgr.is_compressed && is_direct_chunkmap;

trace!(
"filecache entry: compressed {}, direct {}, legacy_stargz {}",
"filecache entry: compressed {}, direct {}, legacy_stargz {}, zran {}",
mgr.is_compressed,
is_direct_chunkmap,
is_legacy_stargz
is_legacy_stargz,
is_zran,
);

// Set cache file to its expected size.
let file_size = file.metadata()?.len();
let cached_file_size = if is_compressed {
blob_info.compressed_size()
} else {
blob_info.uncompressed_size()
};
if file_size == 0 {
file.set_len(cached_file_size)?;
} else if cached_file_size != 0 && file_size != cached_file_size {
let msg = format!(
"blob data file size doesn't match: got 0x{:x}, expect 0x{:x}",
file_size,
blob_info.uncompressed_size()
);
return Err(einval!(msg));
}
let meta = if blob_info.meta_ci_is_valid() {
// Set cache file to its expected size.
let file_size = file.metadata()?.len();
if file_size == 0 {
file.set_len(blob_info.uncompressed_size())?;
} else if file_size != blob_info.uncompressed_size() {
let msg = format!(
"blob data file size doesn't match: got 0x{:x}, expect 0x{:x}",
file_size,
blob_info.uncompressed_size()
);
return Err(einval!(msg));
}
let meta = FileCacheMeta::new(blob_file_path, blob_info.clone(), Some(reader.clone()))?;
Some(meta)
} else {
None
};
let is_zran = blob_info.meta_flags() & BLOB_META_FEATURE_ZRAN != 0;
let is_get_blob_object_supported = meta.is_some() && is_direct_chunkmap;

Ok(FileCacheEntry {
blob_info,
Expand Down Expand Up @@ -250,13 +256,11 @@ impl FileCacheEntry {
blob_info: &BlobInfo,
blob_file: &str,
) -> Result<(Arc<dyn ChunkMap>, bool)> {
let mut direct_chunkmap = true;
// The builder now records the number of chunks in the blob table, so we can
// use IndexedChunkMap as a chunk map, but for the old Nydus bootstrap, we
// need downgrade to use DigestedChunkMap as a compatible solution.

let is_v5 = !blob_info.meta_ci_is_valid();

let mut direct_chunkmap = true;
let chunk_map: Arc<dyn ChunkMap> = if (is_v5 && mgr.disable_indexed_map)
|| blob_info.has_feature(BlobFeatures::V5_NO_EXT_BLOB_TABLE)
{
Expand Down
4 changes: 3 additions & 1 deletion storage/src/cache/fscache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ impl FileCacheEntry {
let meta = FileCacheMeta::new(blob_file_path, blob_info.clone(), Some(reader.clone()))?;
Some(meta)
} else {
None
return Err(enosys!(
"fscache doesn't support blobs without blob meta information"
));
};
let is_zran = blob_info.meta_flags() & BLOB_META_FEATURE_ZRAN != 0;

Expand Down