From 49fc71e1e1fb5387402ead7a327fcb652f8b2540 Mon Sep 17 00:00:00 2001 From: Jiang Liu Date: Tue, 21 Mar 2023 14:46:54 +0800 Subject: [PATCH] rafs: fix a assertion failure in prefetch list generation Fix a assertion failure in prefetch list generation. Fixes: https://github.com/dragonflyoss/image-service/issues/1154 Signed-off-by: Jiang Liu --- rafs/src/builder/core/v6.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/rafs/src/builder/core/v6.rs b/rafs/src/builder/core/v6.rs index 793865570cc..2a9fc803648 100644 --- a/rafs/src/builder/core/v6.rs +++ b/rafs/src/builder/core/v6.rs @@ -708,19 +708,21 @@ impl Bootstrap { Self::v6_align_to_4k(bootstrap_ctx)?; // `Node` offset might be updated during above inodes dumping. So `get_prefetch_table` after it. - let prefetch_table = ctx - .prefetch - .get_v6_prefetch_table(&bootstrap_ctx.nodes, meta_addr); - if let Some(mut pt) = prefetch_table { - assert!(pt.len() * size_of::() <= prefetch_table_size as usize); - // Device slots are very close to extended super block. - ext_sb.set_prefetch_table_offset(prefetch_table_offset); - ext_sb.set_prefetch_table_size(prefetch_table_size); - bootstrap_ctx - .writer - .seek_offset(prefetch_table_offset as u64) - .context("failed seek prefetch table offset")?; - pt.store(bootstrap_ctx.writer.as_mut()).unwrap(); + if prefetch_table_size > 0 { + let prefetch_table = ctx + .prefetch + .get_v6_prefetch_table(&bootstrap_ctx.nodes, meta_addr); + if let Some(mut pt) = prefetch_table { + assert!(pt.len() * size_of::() <= prefetch_table_size as usize); + // Device slots are very close to extended super block. + ext_sb.set_prefetch_table_offset(prefetch_table_offset); + ext_sb.set_prefetch_table_size(prefetch_table_size); + bootstrap_ctx + .writer + .seek_offset(prefetch_table_offset as u64) + .context("failed seek prefetch table offset")?; + pt.store(bootstrap_ctx.writer.as_mut()).unwrap(); + } } // TODO: get rid of the chunk info array.