Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust: bump 1.72.1 and fix errors #1532

Merged
merged 1 commit into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ jobs:
with:
cache-on-failure: true
shared-key: Linux-cargo-amd64
- uses: dsherret/rust-toolchain-file@v1
- name: Build Nydus
run: |
rustup component add rustfmt clippy
make
make release
- name: Upload Nydus Binaries
uses: actions/upload-artifact@v3
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/convert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ jobs:
with:
cache-on-failure: true
shared-key: Linux-cargo-amd64
- uses: dsherret/rust-toolchain-file@v1
- name: Build Nydus
run: |
rustup component add rustfmt clippy
make
make release
- name: Upload Nydus Binaries
uses: actions/upload-artifact@v3
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ jobs:
with:
cache-on-failure: true
shared-key: ${{ runner.os }}-cargo-${{ matrix.arch }}
- uses: dsherret/rust-toolchain-file@v1
- name: Build nydus-rs
run: |
declare -A rust_target_map=( ["amd64"]="x86_64-unknown-linux-musl" ["arm64"]="aarch64-unknown-linux-musl" ["ppc64le"]="powerpc64le-unknown-linux-gnu" ["riscv64"]="riscv64gc-unknown-linux-gnu")
RUST_TARGET=${rust_target_map[${{ matrix.arch }}]}
cargo install --locked --version 0.2.4 cross
rustup component add rustfmt clippy
make -e RUST_TARGET_STATIC=$RUST_TARGET -e CARGO=cross static-release
sudo mv target/$RUST_TARGET/release/nydusd nydusd
sudo mv target/$RUST_TARGET/release/nydus-image .
Expand Down Expand Up @@ -59,6 +59,7 @@ jobs:
with:
cache-on-failure: true
shared-key: ${{ runner.os }}-cargo-${{ matrix.arch }}
- uses: dsherret/rust-toolchain-file@v1
- name: build
run: |
if [[ "${{matrix.arch}}" == "amd64" ]]; then
Expand All @@ -68,7 +69,6 @@ jobs:
fi
cargo install --version 0.2.4 cross
rustup target add ${RUST_TARGET}
rustup component add rustfmt clippy
make -e RUST_TARGET_STATIC=$RUST_TARGET -e CARGO=cross static-release
sudo mv target/$RUST_TARGET/release/nydusd nydusd
sudo cp -r misc/configs .
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ jobs:
cache-on-failure: true
shared-key: ${{ runner.os }}-cargo-${{ matrix.arch }}
save-if: ${{ github.ref == 'refs/heads/master' }}
- uses: dsherret/rust-toolchain-file@v1
- name: Build Nydus
run: |
declare -A rust_target_map=( ["amd64"]="x86_64-unknown-linux-musl" ["arm64"]="aarch64-unknown-linux-musl" ["ppc64le"]="powerpc64le-unknown-linux-gnu" ["riscv64"]="riscv64gc-unknown-linux-gnu")
RUST_TARGET=${rust_target_map[${{ matrix.arch }}]}
cargo install --locked --version 0.2.4 cross
rustup component add rustfmt clippy
make -e RUST_TARGET_STATIC=$RUST_TARGET -e CARGO=cross static-release
sudo mv target/$RUST_TARGET/release/nydusd .
sudo mv target/$RUST_TARGET/release/nydus-image .
Expand All @@ -84,6 +84,7 @@ jobs:
cache-on-failure: true
shared-key: ${{ runner.os }}-cargo-${{ matrix.arch }}
save-if: ${{ github.ref == 'refs/heads/master' }}
- uses: dsherret/rust-toolchain-file@v1
- name: build
run: |
if [[ "${{matrix.arch}}" == "amd64" ]]; then
Expand All @@ -93,7 +94,6 @@ jobs:
fi
cargo install --version 0.2.4 cross
rustup target add ${RUST_TARGET}
rustup component add rustfmt clippy
make -e RUST_TARGET_STATIC=$RUST_TARGET -e CARGO=cross static-release

nydus-integration-test:
Expand Down
2 changes: 1 addition & 1 deletion api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn make_error(
_file: &str,
_line: u32,
) -> std::io::Error {
#[cfg(all(feature = "error-backtrace"))]
#[cfg(feature = "error-backtrace")]
{
if let Ok(val) = std::env::var("RUST_BACKTRACE") {
if val.trim() != "0" {
Expand Down
2 changes: 1 addition & 1 deletion builder/src/core/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ impl BlobManager {
let iv = crypt::Cipher::generate_random_iv()?;
let cipher_ctx = CipherContext::new(key, iv, false, ctx.cipher)?;
(
ctx.cipher.new_cipher().ok().unwrap_or(Default::default()),
ctx.cipher.new_cipher().ok().unwrap_or_default(),
Some(cipher_ctx),
)
}
Expand Down
2 changes: 1 addition & 1 deletion builder/src/core/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl Node {
chunk_data_buf: &mut [u8],
) -> Result<u64> {
let mut reader = if self.is_reg() {
let file = File::open(&self.path())
let file = File::open(self.path())
.with_context(|| format!("failed to open node file {:?}", self.path()))?;
Some(file)
} else {
Expand Down
7 changes: 4 additions & 3 deletions builder/src/core/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use std::ffi::OsString;
use std::os::unix::ffi::OsStrExt;
use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::sync::{Arc, Mutex, MutexGuard};

use anyhow::{bail, Result};
Expand All @@ -34,7 +35,7 @@ use crate::core::overlay::OVERLAYFS_WHITEOUT_OPAQUE;
use crate::{BuildContext, ChunkDict};

/// Type alias for tree internal node.
pub type TreeNode = Arc<Mutex<Node>>;
pub type TreeNode = Rc<Mutex<Node>>;

/// An in-memory tree structure to maintain information and topology of filesystem nodes.
#[derive(Clone)]
Expand All @@ -52,7 +53,7 @@ impl Tree {
pub fn new(node: Node) -> Self {
let name = node.name().as_bytes().to_vec();
Tree {
node: Arc::new(Mutex::new(node)),
node: Rc::new(Mutex::new(node)),
name,
children: Vec::new(),
}
Expand Down Expand Up @@ -81,7 +82,7 @@ impl Tree {

/// Set `Node` associated with the tree node.
pub fn set_node(&mut self, node: Node) {
self.node = Arc::new(Mutex::new(node));
self.node = Rc::new(Mutex::new(node));
}

/// Get mutex guard to access the associated `Node` object.
Expand Down
9 changes: 2 additions & 7 deletions builder/src/core/v6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,12 @@ impl Node {

/// Update whether compact mode can be used for this inode or not.
pub fn v6_set_inode_compact(&mut self) {
if self.info.v6_force_extended_inode
self.v6_compact_inode = !(self.info.v6_force_extended_inode
|| self.inode.uid() > u16::MAX as u32
|| self.inode.gid() > u16::MAX as u32
|| self.inode.nlink() > u16::MAX as u32
|| self.inode.size() > u32::MAX as u64
|| self.path().extension() == Some(OsStr::new("pyc"))
{
self.v6_compact_inode = false;
} else {
self.v6_compact_inode = true;
}
|| self.path().extension() == Some(OsStr::new("pyc")));
}

/// Layout the normal inode (except directory inode) into the meta blob.
Expand Down
2 changes: 1 addition & 1 deletion misc/musl-static/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM clux/muslrust:1.68.2
FROM clux/muslrust:1.72.1

ARG RUST_TARGET=x86_64-unknown-linux-musl

Expand Down
2 changes: 1 addition & 1 deletion rafs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ mod tests {
let bootstrap = OpenOptions::new()
.read(true)
.write(false)
.open(&path)
.open(path)
.unwrap();
let mut rs = RafsSuper {
mode: RafsMode::Direct,
Expand Down
2 changes: 1 addition & 1 deletion rafs/src/metadata/direct_v6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ impl RafsInodeExt for OndiskInodeWrapper {
/// It depends on Self::validate() to ensure valid memory layout.
fn name(&self) -> OsString {
assert!(self.name.is_some());
self.name.clone().unwrap_or_else(OsString::new)
self.name.clone().unwrap_or_default()
}

/// Get file name size of the inode.
Expand Down
4 changes: 2 additions & 2 deletions rafs/src/metadata/inode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,10 @@ impl InodeWrapper {
if let Self::Ref(i) = self {
let i = i.clone();
if self.is_v6() {
*self = Self::V6(RafsV6Inode::from(i.deref().deref()));
*self = Self::V6(RafsV6Inode::from(i.deref()));
} else {
assert!(self.is_v5());
*self = Self::V5(RafsV5Inode::from(i.deref().deref()));
*self = Self::V5(RafsV5Inode::from(i.deref()));
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions rafs/src/metadata/layout/v6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2473,8 +2473,7 @@ mod tests {

let targets = vec![target1, target2, target3, target4, target5];

let mut entries: Vec<RafsV6XattrEntry> = Vec::new();
entries.reserve(targets.len());
let mut entries: Vec<RafsV6XattrEntry> = Vec::with_capacity(targets.len());
for _i in 0..targets.len() {
let mut entry = RafsV6XattrEntry::new();
reader.read_exact(entry.as_mut()).unwrap();
Expand Down
3 changes: 2 additions & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[toolchain]
channel = "1.68.2"
channel = "1.72.1"
components = ["rustfmt", "clippy"]
4 changes: 2 additions & 2 deletions service/src/blob_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ mod tests {
fn test_blob_cache_entry() {
let tmpdir = TempDir::new().unwrap();
let path = tmpdir.as_path().join("bootstrap1");
std::fs::write(&path, "metadata").unwrap();
std::fs::write(path, "metadata").unwrap();
let cfg = create_factory_config();
let content = cfg.replace("/tmp/nydus", tmpdir.as_path().to_str().unwrap());
let mut entry: BlobCacheEntry = serde_json::from_str(&content).unwrap();
Expand Down Expand Up @@ -629,7 +629,7 @@ mod tests {
fn test_invalid_blob_id() {
let tmpdir = TempDir::new().unwrap();
let path = tmpdir.as_path().join("bootstrap1");
std::fs::write(&path, "metadata").unwrap();
std::fs::write(path, "metadata").unwrap();
let config = create_factory_config();
let content = config.replace("/tmp/nydus", tmpdir.as_path().to_str().unwrap());
let mut entry: BlobCacheEntry = serde_json::from_str(&content).unwrap();
Expand Down
24 changes: 12 additions & 12 deletions service/src/block_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::cmp::{max, min};
use std::fs::OpenOptions;
use std::io::Result;
use std::path::PathBuf;
use std::rc::Rc;
use std::sync::{Arc, Mutex};
use std::thread;
use std::thread::JoinHandle;
Expand All @@ -36,8 +37,8 @@ const BLOCK_DEVICE_EXPORT_BATCH_SIZE: usize = 0x80000;

enum BlockRange {
Hole,
MetaBlob(Arc<MetaBlob>),
DataBlob(Arc<DataBlob>),
MetaBlob(Rc<MetaBlob>),
DataBlob(Rc<DataBlob>),
}

/// A block device composed up from a RAFSv6 image.
Expand Down Expand Up @@ -93,7 +94,7 @@ impl BlockDevice {
};
let is_tarfs_mode = meta_blob_config.is_tarfs_mode();
let meta_blob = MetaBlob::new(meta_blob_config.path())?;
let meta_blob = Arc::new(meta_blob);
let meta_blob = Rc::new(meta_blob);
let blocks = if is_tarfs_mode {
meta_blob.blocks() * 8
} else {
Expand Down Expand Up @@ -171,7 +172,7 @@ impl BlockDevice {
blob_info.blob_id()
))
})?;
ranges.update(&range, BlockRange::DataBlob(Arc::new(data_blob)));
ranges.update(&range, BlockRange::DataBlob(Rc::new(data_blob)));
pos = extra_info.mapped_blkaddr + blocks as u32;
}

Expand Down Expand Up @@ -307,7 +308,7 @@ impl BlockDevice {
verity: bool,
) -> Result<()> {
let block_device = BlockDevice::new(blob_entry)?;
let block_device = Arc::new(block_device);
let block_device = Rc::new(block_device);
let blocks = block_device.blocks();
let blob_id = block_device.meta_blob_id();

Expand Down Expand Up @@ -358,7 +359,7 @@ impl BlockDevice {
e
))
})?;
let output_file = Arc::new(tokio_uring::fs::File::from_std(output_file));
let output_file = Rc::new(tokio_uring::fs::File::from_std(output_file));

let mut verity_offset = 0;
let generator = if verity {
Expand Down Expand Up @@ -420,15 +421,15 @@ impl BlockDevice {
e
))
})?;
let file = Arc::new(tokio_uring::fs::File::from_std(output_file));
let file = Rc::new(tokio_uring::fs::File::from_std(output_file));
let block_device =
BlockDevice::new_with_cache_manager(id, mgr).map_err(|e| {
eother!(format!(
"block_device: failed to create block device object, {}",
e
))
})?;
let device = Arc::new(block_device);
let device = Rc::new(block_device);

tokio_uring::start(async move {
Self::do_export(device, file, pos, count, generator).await
Expand Down Expand Up @@ -462,8 +463,7 @@ impl BlockDevice {
let root_digest: String = root_digest
.data
.iter()
.map(|v| format!("{:02x}", v))
.collect();
.fold(String::new(), |acc, v| acc + &format!("{:02x}", v));
println!(
"dm-verity options: --no-superblock --format=1 -s \"\" --hash=sha256 --data-block-size={} --hash-block-size=4096 --data-blocks {} --hash-offset {} {}",
block_device.block_size(), blocks, verity_offset, root_digest
Expand All @@ -474,8 +474,8 @@ impl BlockDevice {
}

async fn do_export(
block_device: Arc<BlockDevice>,
output_file: Arc<tokio_uring::fs::File>,
block_device: Rc<BlockDevice>,
output_file: Rc<tokio_uring::fs::File>,
start: u32,
mut blocks: u32,
generator: Option<Arc<Mutex<VerityGenerator>>>,
Expand Down
6 changes: 3 additions & 3 deletions service/src/fs_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ impl FsCacheHandler {
}
}

env::set_current_dir(&cwd_old)?;
env::set_current_dir(cwd_old)?;
if res {
Ok(())
} else {
Expand Down Expand Up @@ -879,7 +879,7 @@ impl FsCacheHandler {
}

fn inuse(&self, cookie_dir: &Path, cookie_name: &str) -> Result<bool> {
env::set_current_dir(&cookie_dir)?;
env::set_current_dir(cookie_dir)?;
let msg = format!("inuse {}", cookie_name);
let ret = unsafe {
libc::write(
Expand All @@ -902,7 +902,7 @@ impl FsCacheHandler {
}

fn cull(&self, cookie_dir: &Path, cookie_name: &str) -> Result<()> {
env::set_current_dir(&cookie_dir)?;
env::set_current_dir(cookie_dir)?;
let msg = format!("cull {}", cookie_name);
let ret = unsafe {
libc::write(
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 @@ -219,7 +219,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 @@ -233,7 +233,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
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 @@ -560,7 +560,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
Loading