Skip to content

Commit

Permalink
feat(builder): add CRC32 support for RAFS V6.
Browse files Browse the repository at this point in the history
To enable CRC checksum validation for the V6 version, the following changes were made:
- Removed the `HAS_CRC` flag from `BlobFeature`, as it is no longer needed.
- Added support for setting the crc32 field in `BlobChunkInfoV2Ondisk`.

Signed-off-by: Yang Kaiyong <[email protected]>
  • Loading branch information
Yang Kaiyong committed Feb 24, 2025
1 parent dd89618 commit b93aae6
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 24 deletions.
2 changes: 1 addition & 1 deletion api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ struct CacheConfig {
#[serde(default, rename = "config")]
pub cache_config: Value,
/// Whether to validate data read from the cache.
#[serde(skip_serializing, skip_deserializing)]
#[serde(default, rename = "validate")]
pub cache_validate: bool,
/// Configuration for blob data prefetching.
#[serde(skip_serializing, skip_deserializing)]
Expand Down
9 changes: 5 additions & 4 deletions builder/src/core/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,9 +602,6 @@ impl BlobContext {
blob_ctx
.blob_meta_header
.set_encrypted(features.contains(BlobFeatures::ENCRYPTED));
blob_ctx
.blob_meta_header
.set_has_crc(features.contains(BlobFeatures::HAS_CRC));
blob_ctx
.blob_meta_header
.set_is_chunkdict_generated(features.contains(BlobFeatures::IS_CHUNKDICT_GENERATED));
Expand Down Expand Up @@ -790,6 +787,10 @@ impl BlobContext {
info.set_uncompressed_offset(chunk.uncompressed_offset());
self.blob_meta_info.add_v2_info(info);
} else {
let mut data: u64 = 0;
if chunk.has_crc() {
data = chunk.crc32() as u64;
}
self.blob_meta_info.add_v2(
chunk.compressed_offset(),
chunk.compressed_size(),
Expand All @@ -799,7 +800,7 @@ impl BlobContext {
chunk.is_encrypted(),
chunk.has_crc(),
chunk.is_batch(),
0,
data,
);
}
self.blob_chunk_digest.push(chunk.id().data);
Expand Down
9 changes: 9 additions & 0 deletions rafs/src/metadata/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,15 @@ impl ChunkWrapper {
}
}

/// Get crc32 of chunk data.
pub fn crc32(&self) -> u32 {
match self {
ChunkWrapper::V5(c) => c.crc32,
ChunkWrapper::V6(c) => c.crc32,
ChunkWrapper::Ref(c) => as_blob_v5_chunk_info(c.deref()).crc32(),
}
}

/// Check whether the chunk has CRC or not.
pub fn has_crc(&self) -> bool {
match self {
Expand Down
2 changes: 1 addition & 1 deletion rafs/src/metadata/direct_v6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,7 @@ impl BlobChunkInfo for DirectChunkInfoV6 {
}

fn crc32(&self) -> u32 {
0
self.v5_chunk(&self.state()).crc32
}
fn as_any(&self) -> &dyn Any {
self
Expand Down
1 change: 0 additions & 1 deletion rafs/src/metadata/layout/v6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,6 @@ impl RafsV6Blob {
} else if blob_features.contains(BlobFeatures::BATCH)
|| blob_features.contains(BlobFeatures::ZRAN)
|| blob_features.contains(BlobFeatures::ENCRYPTED)
|| blob_features.contains(BlobFeatures::HAS_CRC)
{
error!(
"RafsV6Blob: idx {} invalid feature bits {}",
Expand Down
1 change: 0 additions & 1 deletion src/bin/nydus-image/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,6 @@ impl Command {
}
if crc_enable {
build_ctx.blob_features.insert(BlobFeatures::CHUNK_INFO_V2);
build_ctx.blob_features.insert(BlobFeatures::HAS_CRC);
}
Box::new(DirectoryBuilder::new())
}
Expand Down
4 changes: 2 additions & 2 deletions src/bin/nydusd/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,8 @@ fn process_fs_service(
.value_of("failover-policy")
.unwrap_or(&"flush".to_string())
.try_into()
.inspect(|_e| {
error!("Invalid failover policy");
.inspect_err(|e| {
error!("Invalid failover policy: {}", e);
})?;

// mountpoint means fuse device only
Expand Down
2 changes: 0 additions & 2 deletions storage/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ bitflags! {
const BATCH = 0x0000_0080;
/// Whether the Blob is encrypted.
const ENCRYPTED = 0x0000_0100;
/// Whether the Chunk has CRC checksum.
const HAS_CRC = 0x0000_0200;
/// Blob has TAR headers to separate contents.
const HAS_TAR_HEADER = 0x1000_0000;
/// Blob has Table of Content (ToC) at the tail.
Expand Down
12 changes: 0 additions & 12 deletions storage/src/meta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,6 @@ impl BlobCompressionContextHeader {
}
}

/// Set flag indicating whether the blob's chunk has crc checksum.
pub fn set_has_crc(&mut self, enable: bool) {
if enable {
self.s_features |= BlobFeatures::HAS_CRC.bits();
} else {
self.s_features &= !BlobFeatures::HAS_CRC.bits();
}
}

/// Get blob meta feature flags.
pub fn features(&self) -> u32 {
self.s_features
Expand Down Expand Up @@ -2067,9 +2058,6 @@ pub fn format_blob_features(features: BlobFeatures) -> String {
if features.contains(BlobFeatures::ENCRYPTED) {
output += "encrypted ";
}
if features.contains(BlobFeatures::HAS_CRC) {
output += "crc-checksumed ";
}
if features.contains(BlobFeatures::IS_CHUNKDICT_GENERATED) {
output += "is-chunkdict-generated ";
}
Expand Down

0 comments on commit b93aae6

Please sign in to comment.