diff --git a/src/bin/nydusd/fs_cache.rs b/src/bin/nydusd/fs_cache.rs index 308299832db..52964ac49b4 100644 --- a/src/bin/nydusd/fs_cache.rs +++ b/src/bin/nydusd/fs_cache.rs @@ -604,38 +604,44 @@ impl FsCacheHandler { } } Some((FsCacheObject::Bootstrap(bs), u)) => { - // TODO: should we feed the bootstrap at together to improve performance? fd = u; - let base = unsafe { - libc::mmap( - std::ptr::null_mut(), - msg.len as usize, - libc::PROT_READ, - libc::MAP_SHARED, - bs.bootstrap_file.as_raw_fd(), - msg.off as libc::off_t, - ) - }; - if base == libc::MAP_FAILED { - warn!( - "fscache: failed to mmap bootstrap file, {}", - std::io::Error::last_os_error() - ); - } else { - let ret = unsafe { - libc::pwrite( - bs.cache_file.as_raw_fd(), - base, - msg.len as usize, - msg.off as libc::off_t, - ) - }; - let _ = unsafe { libc::munmap(base, msg.len as usize) }; - if ret < 0 { - warn!( - "fscache: failed to write bootstrap blob data to cached file, {}", - std::io::Error::last_os_error() - ); + match bs.bootstrap_file.metadata() { + Err(e) => { + warn!("fscache: get bootstrap file metadata err {}", e); + } + Ok(md) => { + let base = unsafe { + libc::mmap( + std::ptr::null_mut(), + md.len() as usize, + libc::PROT_READ, + libc::MAP_SHARED, + bs.bootstrap_file.as_raw_fd(), + 0 as libc::off_t, + ) + }; + if base == libc::MAP_FAILED { + warn!( + "fscache: failed to mmap bootstrap file, {}", + std::io::Error::last_os_error() + ); + } else { + let ret = unsafe { + libc::pwrite( + bs.cache_file.as_raw_fd(), + base, + md.len() as usize, + 0 as libc::off_t, + ) + }; + let _ = unsafe { libc::munmap(base, md.len() as usize) }; + if ret < 0 { + warn!( + "fscache: failed to write bootstrap blob data to cached file, {}", + std::io::Error::last_os_error() + ); + } + } } } }