Skip to content

Commit 55cb4f7

Browse files
committed
初步跑通
Signed-off-by: Wenhao Ren <wenhaoren@mail.dlut.edu.cn>
1 parent 596492b commit 55cb4f7

File tree

31 files changed

+1453
-35
lines changed

31 files changed

+1453
-35
lines changed

Cargo.lock

Lines changed: 16 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builder/src/compact.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ mod tests {
669669
use super::*;
670670
use nydus_api::ConfigV2;
671671
use nydus_rafs::metadata::RafsSuperConfig;
672+
use nydus_storage::backend::registry::StreamCallback;
672673
use nydus_storage::backend::{BackendResult, BlobReader};
673674
use nydus_storage::device::v5::BlobV5ChunkInfo;
674675
use nydus_storage::device::{BlobChunkFlags, BlobChunkInfo, BlobFeatures};
@@ -759,6 +760,16 @@ mod tests {
759760
Ok(i)
760761
}
761762

763+
fn try_read_stream(
764+
&self,
765+
_offset: u64,
766+
_size: u32,
767+
_processed: &mut u64,
768+
_f: &mut StreamCallback,
769+
) -> BackendResult<()> {
770+
unimplemented!()
771+
}
772+
762773
fn metrics(&self) -> &BackendMetrics {
763774
// Safe because nydusd must have backend attached with id, only image builder can no id
764775
// but use backend instance to upload blob.

builder/src/core/blob.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ impl Blob {
3131
match ctx.conversion_type {
3232
ConversionType::DirectoryToRafs => {
3333
let mut chunk_data_buf = vec![0u8; RAFS_MAX_CHUNK_SIZE as usize];
34-
let (inodes, prefetch_entries) = BlobLayout::layout_blob_simple(&ctx.prefetch)?;
34+
let (inodes, prefetch_entries, prefetch_idx) =
35+
BlobLayout::layout_blob_simple(&ctx.prefetch)?;
3536
for (idx, node) in inodes.iter().enumerate() {
3637
let mut node = node.lock().unwrap();
3738
let size = node
@@ -43,6 +44,13 @@ impl Blob {
4344
}
4445
}
4546
}
47+
if let Some((_, blob_ctx)) = blob_mgr.get_current_blob() {
48+
blob_ctx.blob_prefetch_index = prefetch_idx as u64;
49+
warn!(
50+
"CMDebug3456: blob_ctx.blob_prefetch_index = {}",
51+
blob_ctx.blob_prefetch_index
52+
);
53+
}
4654
Self::finalize_blob_data(ctx, blob_mgr, blob_writer)?;
4755
}
4856
ConversionType::TarToRafs

builder/src/core/context.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ pub struct BlobContext {
468468
pub blob_digester: digest::Algorithm,
469469
pub blob_cipher: crypt::Algorithm,
470470
pub blob_prefetch_size: u64,
471+
pub blob_prefetch_index: u64,
471472
/// Whether to generate blob metadata information.
472473
pub blob_meta_info_enabled: bool,
473474
/// Data chunks stored in the data blob, for v6.
@@ -536,6 +537,7 @@ impl BlobContext {
536537
blob_digester: digester,
537538
blob_cipher: cipher,
538539
blob_prefetch_size: 0,
540+
blob_prefetch_index: u32::MAX as u64,
539541
blob_meta_info_enabled: false,
540542
blob_meta_info,
541543
blob_meta_header: BlobCompressionContextHeader::default(),
@@ -698,6 +700,7 @@ impl BlobContext {
698700
cipher_ctx,
699701
);
700702
blob_ctx.blob_prefetch_size = blob.prefetch_size();
703+
blob_ctx.blob_prefetch_index = blob.prefetch_index();
701704
blob_ctx.chunk_count = blob.chunk_count();
702705
blob_ctx.uncompressed_blob_size = blob.uncompressed_size();
703706
blob_ctx.compressed_blob_size = compressed_blob_size;
@@ -735,6 +738,10 @@ impl BlobContext {
735738

736739
// TODO: check the logic to reset prefetch size
737740
pub fn set_blob_prefetch_size(&mut self, ctx: &BuildContext) {
741+
// warn!(
742+
// "CMDebug: set prefetch size from {} to xxx, prefetch policy: {:?}",
743+
// self.blob_prefetch_size, ctx.prefetch.policy
744+
// );
738745
if (self.uncompressed_blob_size > 0
739746
|| (ctx.conversion_type == ConversionType::EStargzIndexToRef
740747
&& !self.blob_id.is_empty()))
@@ -1077,6 +1084,8 @@ impl BlobManager {
10771084
for ctx in &self.blobs {
10781085
let blob_id = ctx.blob_id.clone();
10791086
let blob_prefetch_size = u32::try_from(ctx.blob_prefetch_size)?;
1087+
let blob_prefetch_index = u32::try_from(ctx.blob_prefetch_index)?;
1088+
warn!("CMDebug1111: blob_prefetch_index: {}", blob_prefetch_index);
10801089
let chunk_count = ctx.chunk_count;
10811090
let decompressed_blob_size = ctx.uncompressed_blob_size;
10821091
let compressed_blob_size = ctx.compressed_blob_size;
@@ -1091,6 +1100,7 @@ impl BlobManager {
10911100
blob_id,
10921101
0,
10931102
blob_prefetch_size,
1103+
blob_prefetch_index,
10941104
ctx.chunk_size,
10951105
chunk_count,
10961106
decompressed_blob_size,
@@ -1107,6 +1117,7 @@ impl BlobManager {
11071117
blob_id,
11081118
0,
11091119
blob_prefetch_size,
1120+
blob_prefetch_index,
11101121
ctx.chunk_size,
11111122
chunk_count,
11121123
decompressed_blob_size,

builder/src/core/layout.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use crate::{Overlay, Prefetch, TreeNode};
1212
pub struct BlobLayout {}
1313

1414
impl BlobLayout {
15-
pub fn layout_blob_simple(prefetch: &Prefetch) -> Result<(Vec<TreeNode>, usize)> {
16-
let (pre, non_pre) = prefetch.get_file_nodes();
15+
pub fn layout_blob_simple(prefetch: &Prefetch) -> Result<(Vec<TreeNode>, usize, usize)> {
16+
let (pre, non_pre, prefetch_idx) = prefetch.get_file_nodes();
1717
let mut inodes: Vec<TreeNode> = pre
1818
.into_iter()
1919
.filter(|x| Self::should_dump_node(x.lock().unwrap().deref()))
@@ -27,7 +27,7 @@ impl BlobLayout {
2727

2828
inodes.append(&mut non_prefetch_inodes);
2929

30-
Ok((inodes, prefetch_entries))
30+
Ok((inodes, prefetch_entries, prefetch_idx))
3131
}
3232

3333
#[inline]
@@ -55,7 +55,7 @@ mod tests {
5555
let mut prefetch = Prefetch::default();
5656
prefetch.insert(&tree.node, tree.node.lock().unwrap().deref());
5757

58-
let (inodes, prefetch_entries) = BlobLayout::layout_blob_simple(&prefetch).unwrap();
58+
let (inodes, prefetch_entries, _) = BlobLayout::layout_blob_simple(&prefetch).unwrap();
5959
assert_eq!(inodes.len(), 1);
6060
assert_eq!(prefetch_entries, 0);
6161
}

builder/src/core/node.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ impl Node {
229229
} else {
230230
None
231231
};
232-
233232
self.dump_node_data_with_reader(ctx, blob_mgr, blob_writer, reader.as_mut(), chunk_data_buf)
234233
}
235234

builder/src/core/prefetch.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,18 @@ impl Prefetch {
190190
/// Get node Vector of files in the prefetch list and non-prefetch list.
191191
/// The order of prefetch files is the same as the order of prefetch patterns.
192192
/// The order of non-prefetch files is the same as the order of BFS traversal of file tree.
193-
pub fn get_file_nodes(&self) -> (Vec<TreeNode>, Vec<TreeNode>) {
193+
pub fn get_file_nodes(&self) -> (Vec<TreeNode>, Vec<TreeNode>, usize) {
194194
let mut p_files = self.files_prefetch.clone();
195195
p_files.sort_by_key(|k| k.1);
196+
let prefetch_index = if p_files.is_empty() {
197+
u32::MAX as usize
198+
} else {
199+
p_files.first().unwrap().1 + 1
200+
};
196201

197202
let p_files = p_files.into_iter().map(|(s, _)| s).collect();
198203

199-
(p_files, self.files_non_prefetch.clone())
204+
(p_files, self.files_non_prefetch.clone(), prefetch_index)
200205
}
201206

202207
/// Get the number of ``valid`` prefetch rules.
@@ -368,7 +373,7 @@ mod tests {
368373
// node1, node2
369374
assert_eq!(prefetch.fs_prefetch_rule_count(), 2);
370375

371-
let (pre, non_pre) = prefetch.get_file_nodes();
376+
let (pre, non_pre, _) = prefetch.get_file_nodes();
372377
assert_eq!(pre.len(), 4);
373378
assert_eq!(non_pre.len(), 1);
374379
let pre_str: Vec<String> = pre
@@ -384,7 +389,7 @@ mod tests {
384389

385390
prefetch.clear();
386391
assert_eq!(prefetch.fs_prefetch_rule_count(), 0);
387-
let (pre, non_pre) = prefetch.get_file_nodes();
392+
let (pre, non_pre, _) = prefetch.get_file_nodes();
388393
assert_eq!(pre.len(), 0);
389394
assert_eq!(non_pre.len(), 0);
390395
}

0 commit comments

Comments
 (0)