Skip to content

Commit 2059dbc

Browse files
author
泰友
committed
feat: reuse blob cache of old version
Nydus2.2 has same format for blob cache and bitmap on disk. However, 2.2 nydusd not use blob cache of 1.6 nydusd. This pr counts ready chunk number for both 1.6 and 2.2, instead of thinking it as not filled at all. Signed-off-by: 泰友 <[email protected]>
1 parent f4fde1c commit 2059dbc

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

storage/src/cache/filecache/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::cache::{BlobCache, BlobCacheMgr};
2525
use crate::device::{BlobFeatures, BlobInfo};
2626

2727
pub const BLOB_RAW_FILE_SUFFIX: &str = ".blob.raw";
28-
pub const BLOB_DATA_FILE_SUFFIX: &str = ".blob.data";
28+
pub const BLOB_DATA_FILE_SUFFIX: &str = "";
2929

3030
/// An implementation of [BlobCacheMgr](../trait.BlobCacheMgr.html) to improve performance by
3131
/// caching uncompressed blob with local storage.

storage/src/cache/state/persist_map.rs

+24-27
Original file line numberDiff line numberDiff line change
@@ -111,36 +111,33 @@ impl PersistMap {
111111
}
112112

113113
let header = filemap.get_mut::<Header>(0)?;
114-
let mut not_ready_count = chunk_count;
115-
if header.version >= 1 {
116-
if header.magic2 != MAGIC2 {
117-
return Err(einval!(format!(
118-
"invalid blob chunk_map file header: {:?}",
119-
filename
120-
)));
114+
if header.version >= 1 && header.magic2 != MAGIC2 {
115+
return Err(einval!(format!(
116+
"invalid blob chunk_map file header: {:?}",
117+
filename
118+
)));
119+
}
120+
let not_ready_count = if new_content {
121+
chunk_count
122+
} else if header.version >= 1 && header.all_ready == MAGIC_ALL_READY {
123+
0
124+
} else {
125+
let mut ready_count = 0;
126+
for idx in HEADER_SIZE..expected_size as usize {
127+
let current = filemap.get_ref::<AtomicU8>(idx)?;
128+
let val = current.load(Ordering::Acquire);
129+
ready_count += val.count_ones() as u32;
121130
}
122-
if header.all_ready == MAGIC_ALL_READY {
123-
not_ready_count = 0;
124-
} else if new_content {
125-
not_ready_count = chunk_count;
126-
} else {
127-
let mut ready_count = 0;
128-
for idx in HEADER_SIZE..expected_size as usize {
129-
let current = filemap.get_ref::<AtomicU8>(idx)?;
130-
let val = current.load(Ordering::Acquire);
131-
ready_count += val.count_ones() as u32;
132-
}
133131

134-
if ready_count >= chunk_count {
135-
let header = filemap.get_mut::<Header>(0)?;
136-
header.all_ready = MAGIC_ALL_READY;
137-
let _ = file.sync_all();
138-
not_ready_count = 0;
139-
} else {
140-
not_ready_count = chunk_count - ready_count;
141-
}
132+
if ready_count >= chunk_count {
133+
let header = filemap.get_mut::<Header>(0)?;
134+
header.all_ready = MAGIC_ALL_READY;
135+
let _ = file.sync_all();
136+
0
137+
} else {
138+
chunk_count - ready_count
142139
}
143-
}
140+
};
144141

145142
readahead(file.as_raw_fd(), 0, expected_size);
146143
if !persist {

0 commit comments

Comments
 (0)