Skip to content

Commit

Permalink
feat: upgrade rust
Browse files Browse the repository at this point in the history
    From 1.66 to 1.70

Signed-off-by: 泰友 <cuichengxu.ccx@antgroup.com>
  • Loading branch information
泰友 authored and ccx1024cc committed Mar 28, 2024
1 parent 95a95e8 commit 4db9fd7
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 48 deletions.
2 changes: 1 addition & 1 deletion rafs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub trait RafsIoWrite: Write + Seek + 'static {

fn validate_alignment(&mut self, size: usize, alignment: usize) -> Result<usize> {
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"));
Expand Down
4 changes: 2 additions & 2 deletions rafs/src/metadata/direct_v6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,9 @@ impl OndiskInodeWrapper {
Ok(())
}

fn get_entry_count<'a>(
fn get_entry_count(
&self,
state: &'a Guard<Arc<DirectMappingState>>,
state: &Guard<Arc<DirectMappingState>>,
inode: &dyn RafsV6OndiskInode,
block_index: usize,
) -> Result<usize> {
Expand Down
18 changes: 4 additions & 14 deletions rafs/src/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32> for RafsVersion {
type Error = Error;

Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.66.1
1.70
13 changes: 10 additions & 3 deletions src/bin/nydus-image/builder/stargz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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,
});
Expand Down
20 changes: 17 additions & 3 deletions src/bin/nydus-image/builder/tarball.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/bin/nydus-image/core/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions src/bin/nydus-image/core/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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();
}
Expand All @@ -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])
Expand Down Expand Up @@ -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])
Expand Down
8 changes: 4 additions & 4 deletions src/bin/nydus-image/core/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ impl Node {
let len = c.as_bytes().len() + size_of::<RafsV6Dirent>();
// 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;
}
Expand All @@ -976,7 +976,7 @@ impl Node {
let len = child.node.name().as_bytes().len() + size_of::<RafsV6Dirent>();
// 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;
}
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/bin/nydus-image/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/bin/nydus-image/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions src/bin/nydus-image/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/nydus-image/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl BuildRootTracer {
pub fn tracer(&self, class: TraceClass) -> Option<Arc<dyn TracerClass>> {
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<serde_json::Map<String, serde_json::Value>> {
Expand Down
2 changes: 1 addition & 1 deletion src/bin/nydus-image/unpack/pax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion storage/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct BlobCacheMgrKey {
config: Arc<ConfigV2>,
}

#[allow(clippy::derive_hash_xor_eq)]
#[allow(clippy::derived_hash_with_manual_eq)]
impl Hash for BlobCacheMgrKey {
fn hash<H: Hasher>(&self, state: &mut H) {
self.config.id.hash(state);
Expand Down
2 changes: 1 addition & 1 deletion storage/src/meta/toc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl TryFrom<compress::Algorithm> 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,))),
}
}
}
Expand Down

0 comments on commit 4db9fd7

Please sign in to comment.