diff --git a/service/src/daemon.rs b/service/src/daemon.rs index 3170f41cab9..c858e05ceb8 100644 --- a/service/src/daemon.rs +++ b/service/src/daemon.rs @@ -422,13 +422,16 @@ impl DaemonController { self.fs_service.lock().unwrap().clone() } - /// Shutdown all services managed by the controller. - pub fn shutdown(&self) { + /// Notify controller shutdown + pub fn notify_shutdown(&self) { // Marking exiting state. self.active.store(false, Ordering::Release); // Signal the `run_loop()` working thread to exit. let _ = self.waker.wake(); + } + /// Shutdown all services managed by the controller. + pub fn shutdown(&self) { let daemon = self.daemon.lock().unwrap().take(); if let Some(d) = daemon { if let Err(e) = d.trigger_stop() { diff --git a/smoke/tests/blobcache_test.go b/smoke/tests/blobcache_test.go index 5dd10a25f88..ca5a44eabd3 100644 --- a/smoke/tests/blobcache_test.go +++ b/smoke/tests/blobcache_test.go @@ -212,7 +212,7 @@ func (a *BlobCacheTestSuite) TestGenerateBlobcache(t *testing.T) { ctx.Binary.Builder, ctx.Env.BootstrapPath, blobcacheDir, filepath.Join(ctx.Env.BlobDir, ociBlobDigest.Hex()))) - a.compareTwoFiles(t, filepath.Join(blobcacheDir, fmt.Sprintf("%s.blob.data", ociBlobDigest.Hex())), filepath.Join(ctx.Env.CacheDir, fmt.Sprintf("%s.blob.data", ociBlobDigest.Hex()))) + a.compareTwoFiles(t, filepath.Join(blobcacheDir, fmt.Sprintf("%s.blob.data", ociBlobDigest.Hex())), filepath.Join(ctx.Env.CacheDir, ociBlobDigest.Hex())) a.compareTwoFiles(t, filepath.Join(blobcacheDir, fmt.Sprintf("%s.blob.meta", ociBlobDigest.Hex())), filepath.Join(ctx.Env.CacheDir, fmt.Sprintf("%s.blob.meta", ociBlobDigest.Hex()))) } diff --git a/src/bin/nydusd/main.rs b/src/bin/nydusd/main.rs index e06693e7a55..fc5e4b7a6b8 100644 --- a/src/bin/nydusd/main.rs +++ b/src/bin/nydusd/main.rs @@ -720,7 +720,7 @@ mod nbd { } extern "C" fn sig_exit(_sig: std::os::raw::c_int) { - DAEMON_CONTROLLER.shutdown(); + DAEMON_CONTROLLER.notify_shutdown(); } fn main() -> Result<()> { diff --git a/storage/src/cache/cachedfile.rs b/storage/src/cache/cachedfile.rs index 4122384a250..d30bcb1762b 100644 --- a/storage/src/cache/cachedfile.rs +++ b/storage/src/cache/cachedfile.rs @@ -1662,6 +1662,20 @@ impl FileIoMergeState { tag: BlobIoTag, chunk: Option>, ) -> Result<()> { + // Make sure user io of same region continuous + if !self.regions.is_empty() && self.joinable(region_type) { + let region = &self.regions[self.regions.len() - 1]; + if !region.seg.is_empty() && tag.is_user_io() { + if let BlobIoTag::User(ref seg) = tag { + if seg.offset as u64 + start + != region.blob_address + region.seg.offset as u64 + region.seg.len as u64 + { + self.commit(); + } + } + } + } + if self.regions.is_empty() || !self.joinable(region_type) { self.regions.push(Region::new(region_type)); self.last_region_joinable = true; @@ -1793,7 +1807,7 @@ mod tests { let tag = BlobIoTag::User(BlobIoSegment { offset: 0x1800, - len: 0x1800, + len: 0x800, }); state .push(RegionType::CacheFast, 0x1000, 0x2000, tag, None) @@ -1810,8 +1824,8 @@ mod tests { assert_eq!(state.regions.len(), 1); let tag = BlobIoTag::User(BlobIoSegment { - offset: 0x0000, - len: 0x2000, + offset: 0x0001, + len: 0x1fff, }); state .push(RegionType::CacheSlow, 0x5000, 0x2000, tag, None) diff --git a/storage/src/cache/filecache/mod.rs b/storage/src/cache/filecache/mod.rs index 1e38f3b3072..88485c32036 100644 --- a/storage/src/cache/filecache/mod.rs +++ b/storage/src/cache/filecache/mod.rs @@ -25,7 +25,7 @@ use crate::cache::{BlobCache, BlobCacheMgr}; use crate::device::{BlobFeatures, BlobInfo}; pub const BLOB_RAW_FILE_SUFFIX: &str = ".blob.raw"; -pub const BLOB_DATA_FILE_SUFFIX: &str = ".blob.data"; +pub const BLOB_DATA_FILE_SUFFIX: &str = ""; /// An implementation of [BlobCacheMgr](../trait.BlobCacheMgr.html) to improve performance by /// caching uncompressed blob with local storage. @@ -257,7 +257,7 @@ impl FileCacheEntry { } else { blob_info.uncompressed_size() }; - if file_size == 0 { + if file_size == 0 || file_size < cached_file_size { file.set_len(cached_file_size)?; } else if cached_file_size != 0 && file_size != cached_file_size { let msg = format!( diff --git a/storage/src/cache/state/persist_map.rs b/storage/src/cache/state/persist_map.rs index bf434174607..bfe39734d0f 100644 --- a/storage/src/cache/state/persist_map.rs +++ b/storage/src/cache/state/persist_map.rs @@ -111,36 +111,33 @@ impl PersistMap { } let header = filemap.get_mut::
(0)?; - let mut not_ready_count = chunk_count; - if header.version >= 1 { - if header.magic2 != MAGIC2 { - return Err(einval!(format!( - "invalid blob chunk_map file header: {:?}", - filename - ))); + if header.version >= 1 && header.magic2 != MAGIC2 { + return Err(einval!(format!( + "invalid blob chunk_map file header: {:?}", + filename + ))); + } + let not_ready_count = if new_content { + chunk_count + } else if header.version >= 1 && header.all_ready == MAGIC_ALL_READY { + 0 + } else { + let mut ready_count = 0; + for idx in HEADER_SIZE..expected_size as usize { + let current = filemap.get_ref::(idx)?; + let val = current.load(Ordering::Acquire); + ready_count += val.count_ones() as u32; } - if header.all_ready == MAGIC_ALL_READY { - not_ready_count = 0; - } else if new_content { - not_ready_count = chunk_count; - } else { - let mut ready_count = 0; - for idx in HEADER_SIZE..expected_size as usize { - let current = filemap.get_ref::(idx)?; - let val = current.load(Ordering::Acquire); - ready_count += val.count_ones() as u32; - } - if ready_count >= chunk_count { - let header = filemap.get_mut::
(0)?; - header.all_ready = MAGIC_ALL_READY; - let _ = file.sync_all(); - not_ready_count = 0; - } else { - not_ready_count = chunk_count - ready_count; - } + if ready_count >= chunk_count { + let header = filemap.get_mut::
(0)?; + header.all_ready = MAGIC_ALL_READY; + let _ = file.sync_all(); + 0 + } else { + chunk_count - ready_count } - } + }; readahead(file.as_raw_fd(), 0, expected_size); if !persist {