diff --git a/rafs/src/lib.rs b/rafs/src/lib.rs index 02ccf465619..3597f9d24cf 100644 --- a/rafs/src/lib.rs +++ b/rafs/src/lib.rs @@ -112,7 +112,7 @@ pub trait RafsIoWrite: Write + Seek + 'static { fn validate_alignment(&mut self, size: usize, alignment: usize) -> Result { if alignment != 0 { - let cur = self.seek(SeekFrom::Current(0))?; + let cur = self.stream_position()?; if (size & (alignment - 1) != 0) || (cur & (alignment as u64 - 1) != 0) { return Err(einval!("unaligned data")); diff --git a/rafs/src/metadata/direct_v6.rs b/rafs/src/metadata/direct_v6.rs index caa12b343b4..d69ccebbe8d 100644 --- a/rafs/src/metadata/direct_v6.rs +++ b/rafs/src/metadata/direct_v6.rs @@ -652,9 +652,9 @@ impl OndiskInodeWrapper { Ok(()) } - fn get_entry_count<'a>( + fn get_entry_count( &self, - state: &'a Guard>, + state: &Guard>, inode: &dyn RafsV6OndiskInode, block_index: usize, ) -> Result { diff --git a/rafs/src/metadata/mod.rs b/rafs/src/metadata/mod.rs index 7ba097d0507..bf1e2efeddd 100644 --- a/rafs/src/metadata/mod.rs +++ b/rafs/src/metadata/mod.rs @@ -534,20 +534,15 @@ impl Default for RafsSuperMeta { } /// RAFS filesystem versions. -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, Default)] pub enum RafsVersion { /// RAFS v5 + #[default] V5, /// RAFS v6 V6, } -impl Default for RafsVersion { - fn default() -> Self { - RafsVersion::V5 - } -} - impl TryFrom for RafsVersion { type Error = Error; @@ -583,20 +578,15 @@ impl RafsVersion { } /// Rafs metadata working mode. -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq, Default)] pub enum RafsMode { /// Directly mapping and accessing metadata into process by mmap(). + #[default] Direct, /// Read metadata into memory before using, for RAFS v5. Cached, } -impl Default for RafsMode { - fn default() -> Self { - RafsMode::Direct - } -} - impl FromStr for RafsMode { type Err = Error; diff --git a/rust-toolchain b/rust-toolchain index 0403bed10c3..bfe79d0bddb 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.66.1 +1.70 diff --git a/src/bin/nydus-image/builder/stargz.rs b/src/bin/nydus-image/builder/stargz.rs index 844cee27fa6..15f7965d353 100644 --- a/src/bin/nydus-image/builder/stargz.rs +++ b/src/bin/nydus-image/builder/stargz.rs @@ -218,7 +218,14 @@ impl TocEntry { mode |= libc::S_IFIFO; } - self.mode | mode as u32 + #[cfg(target_os = "macos")] + { + self.mode | mode as u32 + } + #[cfg(not(target_os = "macos"))] + { + self.mode | mode + } } /// Get real device id associated with the `TocEntry`. @@ -379,9 +386,9 @@ impl StargzTreeBuilder { flags: BlobChunkFlags::COMPRESSED, compressed_size: 0, uncompressed_size: uncompress_size as u32, - compressed_offset: entry.offset as u64, + compressed_offset: entry.offset, uncompressed_offset: uncompress_offset, - file_offset: entry.chunk_offset as u64, + file_offset: entry.chunk_offset, index: 0, reserved: 0, }); diff --git a/src/bin/nydus-image/builder/tarball.rs b/src/bin/nydus-image/builder/tarball.rs index 86741c0f200..2c5eb6930c8 100644 --- a/src/bin/nydus-image/builder/tarball.rs +++ b/src/bin/nydus-image/builder/tarball.rs @@ -164,7 +164,7 @@ impl<'a> TarballTreeBuilder<'a> { let path = PathBuf::from("/").join(path); let path = path.components().as_path(); if !self.is_special_files(path) { - self.make_lost_dirs(&path, &mut nodes)?; + self.make_lost_dirs(path, &mut nodes)?; let node = self.parse_entry(&nodes, &mut entry, path)?; nodes.push(node); } @@ -428,7 +428,14 @@ impl<'a> TarballTreeBuilder<'a> { EntryType::Fifo => libc::S_IFIFO, _ => bail!("unsupported tar entry type"), }; - Ok((mode & !libc::S_IFMT as u32) | ty as u32) + #[cfg(target_os = "macos")] + { + Ok((mode & !libc::S_IFMT as u32) | ty as u32) + } + #[cfg(not(target_os = "macos"))] + { + Ok((mode & !libc::S_IFMT) | ty) + } } fn get_file_name(path: &Path) -> Result<&OsStr> { @@ -468,7 +475,14 @@ impl<'a> TarballTreeBuilder<'a> { let name = Self::get_file_name(path)?; let mut inode = InodeWrapper::new(self.ctx.fs_version); inode.set_ino(ino); - inode.set_mode(0o755 | libc::S_IFDIR as u32); + #[cfg(target_os = "macos")] + { + inode.set_mode(0o755 | libc::S_IFDIR as u32); + } + #[cfg(not(target_os = "macos"))] + { + inode.set_mode(0o755 | libc::S_IFDIR); + } inode.set_nlink(2); inode.set_name_size(name.len()); inode.set_rdev(u32::MAX); diff --git a/src/bin/nydus-image/core/blob.rs b/src/bin/nydus-image/core/blob.rs index 0b8e32582bb..a3f07873b62 100644 --- a/src/bin/nydus-image/core/blob.rs +++ b/src/bin/nydus-image/core/blob.rs @@ -176,8 +176,8 @@ impl Blob { header.set_ci_compressor(compressor); header.set_ci_entries(blob_meta_info.len() as u32); header.set_ci_compressed_offset(compressed_offset); - header.set_ci_compressed_size(compressed_size as u64); - header.set_ci_uncompressed_size(uncompressed_size as u64); + header.set_ci_compressed_size(compressed_size); + header.set_ci_uncompressed_size(uncompressed_size); header.set_4k_aligned(true); match blob_meta_info { BlobMetaChunkArray::V1(_) => header.set_chunk_info_v2(false), @@ -223,8 +223,8 @@ impl Blob { compressor, hasher.digest_finalize(), compressed_offset, - compressed_size as u64, - uncompressed_size as u64, + compressed_size, + uncompressed_size, )?; let mut hasher = RafsDigest::hasher(digest::Algorithm::Sha256); diff --git a/src/bin/nydus-image/core/bootstrap.rs b/src/bin/nydus-image/core/bootstrap.rs index e97ce7fbe0f..791d37ad848 100644 --- a/src/bin/nydus-image/core/bootstrap.rs +++ b/src/bin/nydus-image/core/bootstrap.rs @@ -580,7 +580,7 @@ impl Bootstrap { let blob_table_size = blob_table.size() as u64; let blob_table_offset = align_offset( (EROFS_DEVTABLE_OFFSET as u64) + devtable_len as u64, - EROFS_BLOCK_SIZE as u64, + EROFS_BLOCK_SIZE, ); let blob_table_entries = blobs.len(); assert!(blob_table_entries < u16::MAX as usize); @@ -614,7 +614,7 @@ impl Bootstrap { let meta_addr = if blob_table_size > 0 { align_offset( blob_table_offset + blob_table_size + prefetch_table_size as u64, - EROFS_BLOCK_SIZE as u64, + EROFS_BLOCK_SIZE, ) } else { orig_meta_addr @@ -664,7 +664,7 @@ impl Bootstrap { // Dump blob table bootstrap_ctx .writer - .seek_offset(blob_table_offset as u64) + .seek_offset(blob_table_offset) .context("failed seek for extended blob table offset")?; blob_table .store(bootstrap_ctx.writer.as_mut()) @@ -707,7 +707,7 @@ impl Bootstrap { ext_sb.set_prefetch_table_size(prefetch_table_size); bootstrap_ctx .writer - .seek_offset(prefetch_table_offset as u64) + .seek_offset(prefetch_table_offset) .context("failed seek prefetch table offset")?; pt.store(bootstrap_ctx.writer.as_mut()).unwrap(); } @@ -718,7 +718,7 @@ impl Bootstrap { .writer .seek_to_end() .context("failed to seek to bootstrap's end for chunk table")?; - let padding = align_offset(pos, EROFS_BLOCK_SIZE as u64) - pos; + let padding = align_offset(pos, EROFS_BLOCK_SIZE) - pos; bootstrap_ctx .writer .write_all(&WRITE_PADDING_DATA[0..padding as usize]) @@ -758,9 +758,9 @@ impl Bootstrap { .context("failed to seek to bootstrap's end")?; debug!( "align bootstrap to 4k {}", - align_offset(pos, EROFS_BLOCK_SIZE as u64) + align_offset(pos, EROFS_BLOCK_SIZE) ); - let padding = align_offset(pos, EROFS_BLOCK_SIZE as u64) - pos; + let padding = align_offset(pos, EROFS_BLOCK_SIZE) - pos; bootstrap_ctx .writer .write_all(&WRITE_PADDING_DATA[0..padding as usize]) diff --git a/src/bin/nydus-image/core/node.rs b/src/bin/nydus-image/core/node.rs index 3394d8956bb..9209eb3839e 100644 --- a/src/bin/nydus-image/core/node.rs +++ b/src/bin/nydus-image/core/node.rs @@ -961,7 +961,7 @@ impl Node { let len = c.as_bytes().len() + size_of::(); // erofs disk format requires dirent to be aligned to block size. if (d_size % EROFS_BLOCK_SIZE) + len as u64 > EROFS_BLOCK_SIZE { - d_size = round_up(d_size as u64, EROFS_BLOCK_SIZE); + d_size = round_up(d_size, EROFS_BLOCK_SIZE); } d_size += len as u64; } @@ -976,7 +976,7 @@ impl Node { let len = child.node.name().as_bytes().len() + size_of::(); // erofs disk format requires dirent to be aligned to block size. if (d_size % EROFS_BLOCK_SIZE) + len as u64 > EROFS_BLOCK_SIZE { - d_size = round_up(d_size as u64, EROFS_BLOCK_SIZE); + d_size = round_up(d_size, EROFS_BLOCK_SIZE); } d_size += len as u64; } @@ -1227,7 +1227,7 @@ impl Node { } f_bootstrap - .seek(SeekFrom::Start(dirent_off as u64)) + .seek(SeekFrom::Start(dirent_off)) .context("failed seek for dir inode")?; f_bootstrap .write(dir_data.as_slice()) @@ -1284,7 +1284,7 @@ impl Node { _ => bail!("unsupported RAFS v6 inode layout for directory"), }; f_bootstrap - .seek(SeekFrom::Start(tail_off as u64)) + .seek(SeekFrom::Start(tail_off)) .context("failed seek for dir inode")?; f_bootstrap .write(dir_data.as_slice()) diff --git a/src/bin/nydus-image/inspect.rs b/src/bin/nydus-image/inspect.rs index 7e348da81ef..73db42b4e1f 100644 --- a/src/bin/nydus-image/inspect.rs +++ b/src/bin/nydus-image/inspect.rs @@ -381,7 +381,7 @@ RAFS Blob Size: {rafs_size} } } } else { - let file_path = self.rafs_meta.path_from_ino(ino as u64)?; + let file_path = self.rafs_meta.path_from_ino(ino)?; file_paths.push(file_path); }; Ok(file_paths) diff --git a/src/bin/nydus-image/main.rs b/src/bin/nydus-image/main.rs index 70aa84e5097..1355f85965d 100644 --- a/src/bin/nydus-image/main.rs +++ b/src/bin/nydus-image/main.rs @@ -200,7 +200,7 @@ fn prepare_cmd_args(bti_string: &'static str) -> App { .long("bootstrap") .short('B') .help("File path to save the generated RAFS metadata blob") - .required_unless_present_any(&["blob-dir", "blob-inline-meta"]) + .required_unless_present_any(["blob-dir", "blob-inline-meta"]) .conflicts_with("blob-inline-meta"), ) .arg( @@ -214,7 +214,7 @@ fn prepare_cmd_args(bti_string: &'static str) -> App { .long("blob") .short('b') .help("File path to save the generated RAFS data blob") - .required_unless_present_any(&["type", "blob-dir"]), + .required_unless_present_any(["type", "blob-dir"]), ) .arg( Arg::new("blob-inline-meta") diff --git a/src/bin/nydus-image/merge.rs b/src/bin/nydus-image/merge.rs index 6e4be8f1ab7..73018f5b2ed 100644 --- a/src/bin/nydus-image/merge.rs +++ b/src/bin/nydus-image/merge.rs @@ -152,7 +152,7 @@ impl Merger { tree = Some(Tree::from_bootstrap(&rs, &mut ())?); let blobs = rs.superblock.get_blob_infos(); for blob in &blobs { - let blob_ctx = BlobContext::from(ctx, &blob, ChunkSource::Parent)?; + let blob_ctx = BlobContext::from(ctx, blob, ChunkSource::Parent)?; blob_idx_map.insert(blob_ctx.blob_id.clone(), blob_mgr.len()); blob_mgr.add(blob_ctx); } @@ -190,7 +190,7 @@ impl Merger { let mut parent_blob_added = false; let blobs = &rs.superblock.get_blob_infos(); for blob in blobs { - let mut blob_ctx = BlobContext::from(ctx, &blob, ChunkSource::Parent)?; + let mut blob_ctx = BlobContext::from(ctx, blob, ChunkSource::Parent)?; if let Some(chunk_size) = chunk_size { ensure!( chunk_size == blob_ctx.chunk_size, diff --git a/src/bin/nydus-image/trace.rs b/src/bin/nydus-image/trace.rs index dde82b0dce2..d54f23d940a 100644 --- a/src/bin/nydus-image/trace.rs +++ b/src/bin/nydus-image/trace.rs @@ -122,7 +122,7 @@ impl BuildRootTracer { pub fn tracer(&self, class: TraceClass) -> Option> { let g = self.tracers.read().unwrap(); // Safe to unwrap because tracers should always be enabled - (&g).get(&class).cloned() + g.get(&class).cloned() } pub fn dump_summary_map(&self) -> Result> { diff --git a/src/bin/nydus-image/unpack/pax.rs b/src/bin/nydus-image/unpack/pax.rs index 932d2e27f4b..2126a1c8d6b 100644 --- a/src/bin/nydus-image/unpack/pax.rs +++ b/src/bin/nydus-image/unpack/pax.rs @@ -562,7 +562,7 @@ impl PAXUtil { let max_len = header.as_old().linkname.len(); if path.as_os_str().len() <= max_len { return header - .set_link_name(&path) + .set_link_name(path) .with_context(|| "fail to set short link for pax header") .map(|_| None); } diff --git a/storage/src/factory.rs b/storage/src/factory.rs index 288e53bbb97..cc37a4e913c 100644 --- a/storage/src/factory.rs +++ b/storage/src/factory.rs @@ -58,7 +58,7 @@ struct BlobCacheMgrKey { config: Arc, } -#[allow(clippy::derive_hash_xor_eq)] +#[allow(clippy::derived_hash_with_manual_eq)] impl Hash for BlobCacheMgrKey { fn hash(&self, state: &mut H) { self.config.id.hash(state); diff --git a/storage/src/meta/toc.rs b/storage/src/meta/toc.rs index e759bd95f8c..b678dcc17f4 100644 --- a/storage/src/meta/toc.rs +++ b/storage/src/meta/toc.rs @@ -56,7 +56,7 @@ impl TryFrom for TocEntryFlags { compress::Algorithm::None => Ok(Self::COMPRESSION_NONE), compress::Algorithm::Zstd => Ok(Self::COMPRESSION_ZSTD), compress::Algorithm::Lz4Block => Ok(Self::COMPRESSION_LZ4_BLOCK), - _ => return Err(eother!(format!("unsupported compressor {}", c,))), + _ => Err(eother!(format!("unsupported compressor {}", c,))), } } }