From dfea6c7d217f0d11eb85d50abf3928145651bc91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 10:21:59 +0100 Subject: [PATCH 01/23] versions: Update the rust toolchain to 1.66.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We're doing the bump on main, as we'll need this as part of the CCv0 branch due to the dependencies we have there. Link to the 1.66.0 release: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1660-2022-12-15 Fixes: #5966 Signed-off-by: Fabiano Fidêncio --- versions.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/versions.yaml b/versions.yaml index 8c0b2bf6d..ea79869a3 100644 --- a/versions.yaml +++ b/versions.yaml @@ -316,12 +316,12 @@ languages: rust: description: "Rust language" notes: "'version' is the default minimum version used by this project." - version: "1.62.0" + version: "1.66.0" meta: description: | 'newest-version' is the latest version known to work when building Kata - newest-version: "1.62.0" + newest-version: "1.66.0" golangci-lint: description: "golangci-lint" From 0bbeb34b4cd02317eacbd858f70ea01c42cc26bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 12:31:54 +0100 Subject: [PATCH 02/23] protocols: Fix needless_borrow warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we bumped the rust toolchain to 1.66.0, some new warnings have been raised due to needless_borrow. Let's fix them all here. For more info about the warnings, please, take a look at: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow Signed-off-by: Fabiano Fidêncio --- src/libs/protocols/build.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/protocols/build.rs b/src/libs/protocols/build.rs index ebb6ef126..8c0341762 100644 --- a/src/libs/protocols/build.rs +++ b/src/libs/protocols/build.rs @@ -17,7 +17,7 @@ fn replace_text_in_file(file_name: &str, from: &str, to: &str) -> Result<(), std let new_contents = contents.replace(from, to); - let mut dst = File::create(&file_name)?; + let mut dst = File::create(file_name)?; dst.write_all(new_contents.as_bytes())?; Ok(()) @@ -67,7 +67,7 @@ fn handle_file(autogen_comment: &str, rust_filename: &str) -> Result<(), std::io let pattern = "//! Generated file from"; - if line.starts_with(&pattern) { + if line.starts_with(pattern) { new_contents.push(autogen_comment.into()); } @@ -76,14 +76,14 @@ fn handle_file(autogen_comment: &str, rust_filename: &str) -> Result<(), std::io // Although we've requested serde support via `Customize`, to // allow the `kata-agent-ctl` tool to partially deserialise structures // specified in JSON, we need this bit of additional magic. - if line.starts_with(&struct_pattern) { + if line.starts_with(struct_pattern) { new_contents.insert(new_contents.len() - 1, serde_default_code.trim().into()); } } let data = new_contents.join("\n"); - let mut dst = File::create(&rust_filename)?; + let mut dst = File::create(rust_filename)?; dst.write_all(data.as_bytes())?; From 60df30015bf48a6e5575050828958b78128609c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 14:17:11 +0100 Subject: [PATCH 03/23] protocols: Fix unnecessary_cast warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we bumped the rust toolchain to 1.66.0, some new warnings have been raised due to unnecessary_cast. Let's fix them all here. For more info about the warnings, please, take a look at: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast Signed-off-by: Fabiano Fidêncio --- src/libs/protocols/src/trans.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libs/protocols/src/trans.rs b/src/libs/protocols/src/trans.rs index e9ecfe785..c6f0c64f0 100644 --- a/src/libs/protocols/src/trans.rs +++ b/src/libs/protocols/src/trans.rs @@ -106,8 +106,8 @@ impl From for crate::oci::LinuxDeviceCgroup { crate::oci::LinuxDeviceCgroup { Allow: from.allow, Type: from.r#type, - Major: from.major.map_or(0, |t| t as i64), - Minor: from.minor.map_or(0, |t| t as i64), + Major: from.major.map_or(0, |t| t), + Minor: from.minor.map_or(0, |t| t), Access: from.access, unknown_fields: Default::default(), cached_size: Default::default(), @@ -123,7 +123,7 @@ impl From for crate::oci::LinuxMemory { Swap: from.swap.map_or(0, |t| t), Kernel: from.kernel.map_or(0, |t| t), KernelTCP: from.kernel_tcp.map_or(0, |t| t), - Swappiness: from.swappiness.map_or(0, |t| t as u64), + Swappiness: from.swappiness.map_or(0, |t| t), DisableOOMKiller: from.disable_oom_killer.map_or(false, |t| t), unknown_fields: Default::default(), cached_size: Default::default(), @@ -332,7 +332,7 @@ impl From for crate::oci::LinuxDevice { Type: from.r#type, Major: from.major, Minor: from.minor, - FileMode: from.file_mode.map_or(0, |v| v as u32), + FileMode: from.file_mode.map_or(0, |v| v), UID: from.uid.map_or(0, |v| v), GID: from.gid.map_or(0, |v| v), unknown_fields: Default::default(), @@ -468,12 +468,12 @@ impl From for oci::LinuxDeviceCgroup { fn from(mut from: crate::oci::LinuxDeviceCgroup) -> Self { let mut major = None; if from.get_Major() > 0 { - major = Some(from.get_Major() as i64); + major = Some(from.get_Major()); } let mut minor = None; if from.get_Minor() > 0 { - minor = Some(from.get_Minor() as i64) + minor = Some(from.get_Minor()) } oci::LinuxDeviceCgroup { From ffd6fbb6b65340c95e0654ffad2adb63cab57aad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 13:21:27 +0100 Subject: [PATCH 04/23] logging: Fix needless_borrow warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we bumped the rust toolchain to 1.66.0, some new warnings have been raised due to needless_borrow. Let's fix them all here. For more info about the warnings, please, take a look at: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow Signed-off-by: Fabiano Fidêncio --- src/libs/logging/src/file_rotate.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/logging/src/file_rotate.rs b/src/libs/logging/src/file_rotate.rs index 444297e53..3cc8f5715 100644 --- a/src/libs/logging/src/file_rotate.rs +++ b/src/libs/logging/src/file_rotate.rs @@ -168,12 +168,12 @@ impl FileRotator { #[cfg(test)] if !self.fail_rename && self.path.exists() { let rotated_path = self.rotated_path(1); - let _ = fs::rename(&self.path, &rotated_path); + let _ = fs::rename(&self.path, rotated_path); } #[cfg(not(test))] if self.path.exists() { let rotated_path = self.rotated_path(1); - let _ = fs::rename(&self.path, &rotated_path); + let _ = fs::rename(&self.path, rotated_path); } let delete_path = self.rotated_path(self.rotate_keep + 1); From c9c38e6d01178bd464418d8b191cb43f6b772c18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 14:25:47 +0100 Subject: [PATCH 05/23] logging: Allow clippy::type-complexity warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As the rust toolchain version bump to its 1.66.0 release raised a warning about the type complexity used for the closure, and that's something we don't want to change, let's ignore such warning in this very specific case. See: https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity Signed-off-by: Fabiano Fidêncio --- src/libs/logging/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/logging/src/lib.rs b/src/libs/logging/src/lib.rs index d72292a2c..29325c6bd 100644 --- a/src/libs/logging/src/lib.rs +++ b/src/libs/logging/src/lib.rs @@ -499,6 +499,7 @@ mod tests { let error_closure = |logger: &Logger, msg: String| error!(logger, "{}", msg); let critical_closure = |logger: &Logger, msg: String| crit!(logger, "{}", msg); + #[allow(clippy::type_complexity)] struct TestData<'a> { slog_level: slog::Level, slog_level_tag: &'a str, From c1a8d89a72aab69abe59dd2fd547c78ea0d37505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 13:25:14 +0100 Subject: [PATCH 06/23] kata-sys-util: Fix needless_borrow warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we bumped the rust toolchain to 1.66.0, some new warnings have been raised due to needless_borrow. Let's fix them all here. For more info about the warnings, please, take a look at: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow Signed-off-by: Fabiano Fidêncio --- src/libs/kata-sys-util/src/fs.rs | 2 +- src/libs/kata-sys-util/src/mount.rs | 6 +++--- src/libs/kata-sys-util/src/numa.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libs/kata-sys-util/src/fs.rs b/src/libs/kata-sys-util/src/fs.rs index 32bfafee9..bec806c46 100644 --- a/src/libs/kata-sys-util/src/fs.rs +++ b/src/libs/kata-sys-util/src/fs.rs @@ -145,7 +145,7 @@ pub fn reflink_copy, D: AsRef>(src: S, dst: D) -> Result<() // Copy file using cp command, which handles sparse file copy. fn do_regular_copy(src: &str, dst: &str) -> Result<()> { let mut cmd = Command::new("/bin/cp"); - cmd.args(&["--sparse=auto", src, dst]); + cmd.args(["--sparse=auto", src, dst]); match cmd.output() { Ok(output) => match output.status.success() { diff --git a/src/libs/kata-sys-util/src/mount.rs b/src/libs/kata-sys-util/src/mount.rs index 58613f3a7..efbcf6a4f 100644 --- a/src/libs/kata-sys-util/src/mount.rs +++ b/src/libs/kata-sys-util/src/mount.rs @@ -820,11 +820,11 @@ mod tests { let tmpdir2 = tempfile::tempdir().unwrap(); assert!(matches!( - bind_remount(&PathBuf::from(""), true), + bind_remount(PathBuf::from(""), true), Err(Error::NullMountPointPath) )); assert!(matches!( - bind_remount(&PathBuf::from("../______doesn't____exist____nnn"), true), + bind_remount(PathBuf::from("../______doesn't____exist____nnn"), true), Err(Error::InvalidPath(_)) )); @@ -1066,7 +1066,7 @@ mod tests { .unwrap_err(); let src = path.join("src"); - fs::write(&src, "test").unwrap(); + fs::write(src, "test").unwrap(); let dst = path.join("dst"); fs::write(&dst, "test1").unwrap(); mount_at( diff --git a/src/libs/kata-sys-util/src/numa.rs b/src/libs/kata-sys-util/src/numa.rs index ece5cd8e7..4a6b2e576 100644 --- a/src/libs/kata-sys-util/src/numa.rs +++ b/src/libs/kata-sys-util/src/numa.rs @@ -37,9 +37,9 @@ pub type Result = std::result::Result; lazy_static! { static ref SYS_FS_PREFIX: PathBuf = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("test/texture"); // numa node file for UT, we can mock data - static ref NUMA_NODE_PATH: PathBuf = (&*SYS_FS_PREFIX).join("sys/devices/system/node"); + static ref NUMA_NODE_PATH: PathBuf = (*SYS_FS_PREFIX).join("sys/devices/system/node"); // sysfs directory for CPU devices - static ref NUMA_CPU_PATH: PathBuf = (&*SYS_FS_PREFIX).join("sys/devices/system/cpu"); + static ref NUMA_CPU_PATH: PathBuf = (*SYS_FS_PREFIX).join("sys/devices/system/cpu"); } // global config in release From 668e6524010e034ad99a7f0846207b5c1151227a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 13:27:57 +0100 Subject: [PATCH 07/23] kata-sys-util: Fix unnecessary_cast warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we bumped the rust toolchain to 1.66.0, some new warnings have been raised due to unnecessary_cast. Let's fix them all here. For more info about the warnings, please, take a look at: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast Signed-off-by: Fabiano Fidêncio --- src/libs/kata-sys-util/src/mount.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/kata-sys-util/src/mount.rs b/src/libs/kata-sys-util/src/mount.rs index efbcf6a4f..3c6f5f261 100644 --- a/src/libs/kata-sys-util/src/mount.rs +++ b/src/libs/kata-sys-util/src/mount.rs @@ -592,7 +592,7 @@ fn compact_lowerdir_option(opts: &[String]) -> (Option, Vec) { } }; - let idx = idx as usize; + let idx = idx; let common_dir = match get_longest_common_prefix(&lower_opts) { None => return (None, n_opts), Some(v) => { @@ -620,7 +620,7 @@ fn compact_lowerdir_option(opts: &[String]) -> (Option, Vec) { .iter() .map(|c| c.replace(&common_prefix, "")) .collect(); - n_opts[idx as usize] = format!("lowerdir={}", lower.join(":")); + n_opts[idx] = format!("lowerdir={}", lower.join(":")); (Some(common_dir), n_opts) } From bb78d35db8f29fd46055e178ce17e0348dc1f96c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 13:31:06 +0100 Subject: [PATCH 08/23] kata-sys-util: Fix "match-like-matches-macro" warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we bumped the rust toolchain to 1.66.0, some new warnings have been raised due to "match-like-matches-macro". Let's fix them all here. For more info about the warnings, please, take a look at: https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro Signed-off-by: Fabiano Fidêncio --- src/libs/kata-sys-util/src/validate.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/libs/kata-sys-util/src/validate.rs b/src/libs/kata-sys-util/src/validate.rs index 0847398ce..13902a674 100644 --- a/src/libs/kata-sys-util/src/validate.rs +++ b/src/libs/kata-sys-util/src/validate.rs @@ -17,16 +17,9 @@ pub enum Error { pub fn verify_id(id: &str) -> Result<(), Error> { let mut chars = id.chars(); - let valid = match chars.next() { - Some(first) - if first.is_alphanumeric() + let valid = matches!(chars.next(), Some(first) if first.is_alphanumeric() && id.len() > 1 - && chars.all(|c| c.is_alphanumeric() || ['.', '-', '_'].contains(&c)) => - { - true - } - _ => false, - }; + && chars.all(|c| c.is_alphanumeric() || ['.', '-', '_'].contains(&c))); match valid { true => Ok(()), From 126187e8145a70b642ca18fe062756bbd5741aef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 14:07:42 +0100 Subject: [PATCH 09/23] safe-path: Fix needless_borrow warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we bumped the rust toolchain to 1.66.0, some new warnings have been raised due to needless_borrow. Let's fix them all here. For more info about the warnings, please, take a look at: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow Signed-off-by: Fabiano Fidêncio --- src/libs/safe-path/src/pinned_path_buf.rs | 4 +-- src/libs/safe-path/src/scoped_dir_builder.rs | 8 ++--- .../safe-path/src/scoped_path_resolver.rs | 32 +++++++++---------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/libs/safe-path/src/pinned_path_buf.rs b/src/libs/safe-path/src/pinned_path_buf.rs index d1816f450..15c80f4ce 100644 --- a/src/libs/safe-path/src/pinned_path_buf.rs +++ b/src/libs/safe-path/src/pinned_path_buf.rs @@ -295,7 +295,7 @@ mod tests { barrier2.wait(); }); - let path = scoped_join(&root_path, "s").unwrap(); + let path = scoped_join(root_path, "s").unwrap(); let data = fs::read_to_string(&path).unwrap(); assert_eq!(&data, "a"); assert!(path.is_file()); @@ -306,7 +306,7 @@ mod tests { assert_eq!(&data, "b"); PinnedPathBuf::from_path(&path).unwrap_err(); - let pinned_path = PinnedPathBuf::new(&root_path, "s").unwrap(); + let pinned_path = PinnedPathBuf::new(root_path, "s").unwrap(); let data = fs::read_to_string(&pinned_path).unwrap(); assert_eq!(&data, "b"); diff --git a/src/libs/safe-path/src/scoped_dir_builder.rs b/src/libs/safe-path/src/scoped_dir_builder.rs index 1a4ba189f..2d231c62f 100644 --- a/src/libs/safe-path/src/scoped_dir_builder.rs +++ b/src/libs/safe-path/src/scoped_dir_builder.rs @@ -173,7 +173,7 @@ mod tests { fs::write(rootfs_path.join("txt"), "test").unwrap(); ScopedDirBuilder::new(rootfs_path.join("txt")).unwrap_err(); - let mut builder = ScopedDirBuilder::new(&rootfs_path).unwrap(); + let mut builder = ScopedDirBuilder::new(rootfs_path).unwrap(); // file with the same name already exists. builder @@ -268,7 +268,7 @@ mod tests { symlink(rootfs_dir.path().join("b"), rootfs_dir.path().join("a")).unwrap(); let rootfs_path = &rootfs_dir.path().join("a"); - let mut builder = ScopedDirBuilder::new(&rootfs_path).unwrap(); + let mut builder = ScopedDirBuilder::new(rootfs_path).unwrap(); builder.create_with_unscoped_path("/").unwrap_err(); builder .create_with_unscoped_path(rootfs_path.join("../__xxxx___xxx__")) @@ -278,13 +278,13 @@ mod tests { .unwrap_err(); // Return `AlreadyExist` when recursive is false - builder.create_with_unscoped_path(&rootfs_path).unwrap_err(); + builder.create_with_unscoped_path(rootfs_path).unwrap_err(); builder .create_with_unscoped_path(rootfs_path.join(".")) .unwrap_err(); builder.recursive(true); - builder.create_with_unscoped_path(&rootfs_path).unwrap(); + builder.create_with_unscoped_path(rootfs_path).unwrap(); builder .create_with_unscoped_path(rootfs_path.join(".")) .unwrap(); diff --git a/src/libs/safe-path/src/scoped_path_resolver.rs b/src/libs/safe-path/src/scoped_path_resolver.rs index 59b06bfe7..4d06f0062 100644 --- a/src/libs/safe-path/src/scoped_path_resolver.rs +++ b/src/libs/safe-path/src/scoped_path_resolver.rs @@ -329,31 +329,31 @@ mod tests { let rootfs_path = &rootfs_dir.path(); assert_eq!( - scoped_join(&rootfs_path, "a").unwrap(), + scoped_join(rootfs_path, "a").unwrap(), rootfs_path.join("a") ); assert_eq!( - scoped_join(&rootfs_path, "./a").unwrap(), + scoped_join(rootfs_path, "./a").unwrap(), rootfs_path.join("a") ); assert_eq!( - scoped_join(&rootfs_path, "././a").unwrap(), + scoped_join(rootfs_path, "././a").unwrap(), rootfs_path.join("a") ); assert_eq!( - scoped_join(&rootfs_path, "c/d/../../a").unwrap(), + scoped_join(rootfs_path, "c/d/../../a").unwrap(), rootfs_path.join("a") ); assert_eq!( - scoped_join(&rootfs_path, "c/d/../../../.././a").unwrap(), + scoped_join(rootfs_path, "c/d/../../../.././a").unwrap(), rootfs_path.join("a") ); assert_eq!( - scoped_join(&rootfs_path, "../../a").unwrap(), + scoped_join(rootfs_path, "../../a").unwrap(), rootfs_path.join("a") ); assert_eq!( - scoped_join(&rootfs_path, "./../a").unwrap(), + scoped_join(rootfs_path, "./../a").unwrap(), rootfs_path.join("a") ); } @@ -370,18 +370,18 @@ mod tests { fs::symlink("b/c", rootfs_dir.path().join("a")).unwrap(); let target = rootfs_path.join("b/c"); - assert_eq!(scoped_join(&rootfs_path, "a").unwrap(), target); - assert_eq!(scoped_join(&rootfs_path, "./a").unwrap(), target); - assert_eq!(scoped_join(&rootfs_path, "././a").unwrap(), target); - assert_eq!(scoped_join(&rootfs_path, "b/c/../../a").unwrap(), target); + assert_eq!(scoped_join(rootfs_path, "a").unwrap(), target); + assert_eq!(scoped_join(rootfs_path, "./a").unwrap(), target); + assert_eq!(scoped_join(rootfs_path, "././a").unwrap(), target); + assert_eq!(scoped_join(rootfs_path, "b/c/../../a").unwrap(), target); assert_eq!( - scoped_join(&rootfs_path, "b/c/../../../.././a").unwrap(), + scoped_join(rootfs_path, "b/c/../../../.././a").unwrap(), target ); - assert_eq!(scoped_join(&rootfs_path, "../../a").unwrap(), target); - assert_eq!(scoped_join(&rootfs_path, "./../a").unwrap(), target); - assert_eq!(scoped_join(&rootfs_path, "a/../../../a").unwrap(), target); - assert_eq!(scoped_join(&rootfs_path, "a/../../../b/c").unwrap(), target); + assert_eq!(scoped_join(rootfs_path, "../../a").unwrap(), target); + assert_eq!(scoped_join(rootfs_path, "./../a").unwrap(), target); + assert_eq!(scoped_join(rootfs_path, "a/../../../a").unwrap(), target); + assert_eq!(scoped_join(rootfs_path, "a/../../../b/c").unwrap(), target); } #[test] From cf9ef1833cf9897a17c7749827c4dad49960a3fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 12:54:51 +0100 Subject: [PATCH 10/23] kata-types: Fix needless_borrow warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we bumped the rust toolchain to 1.66.0, some new warnings have been raised due to needless_borrow. Let's fix them all here. For more info about the warnings, please, take a look at: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow Signed-off-by: Fabiano Fidêncio --- src/libs/kata-types/src/config/drop_in.rs | 6 +++--- src/libs/kata-types/tests/test_config.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/kata-types/src/config/drop_in.rs b/src/libs/kata-types/src/config/drop_in.rs index 015e284b6..208ea72fd 100644 --- a/src/libs/kata-types/src/config/drop_in.rs +++ b/src/libs/kata-types/src/config/drop_in.rs @@ -240,7 +240,7 @@ mod drop_in_directory_handling { "drop-in cfg file can only be a regular file or a symlink", )); } - let dropin_contents = fs::read_to_string(&dropin_file.path())?; + let dropin_contents = fs::read_to_string(dropin_file.path())?; let dropin_config: toml::Value = toml::from_str(&dropin_contents)?; super::toml_tree_ops::merge(base_config, dropin_config); Ok(()) @@ -267,7 +267,7 @@ mod drop_in_directory_handling { } pub fn load(base_cfg_file_path: &Path) -> Result { - let base_toml_str = fs::read_to_string(&base_cfg_file_path)?; + let base_toml_str = fs::read_to_string(base_cfg_file_path)?; let mut base_config: toml::Value = toml::from_str(&base_toml_str)?; let dropin_dir = get_dropin_dir_path(base_cfg_file_path)?; @@ -324,7 +324,7 @@ mod drop_in_directory_handling { create_file(&config_path, BASE_CONFIG_DATA.as_bytes()).unwrap(); let dropin_dir = tmpdir.path().join("config.d"); - fs::create_dir(&dropin_dir).unwrap(); + fs::create_dir(dropin_dir).unwrap(); let config = load(&config_path).unwrap(); check_base_config(&config); diff --git a/src/libs/kata-types/tests/test_config.rs b/src/libs/kata-types/tests/test_config.rs index b7d5f953b..800a05f70 100644 --- a/src/libs/kata-types/tests/test_config.rs +++ b/src/libs/kata-types/tests/test_config.rs @@ -340,7 +340,7 @@ mod tests { let path = env!("CARGO_MANIFEST_DIR"); let path = Path::new(path).join("tests/texture/configuration-anno-0.toml"); - let content = fs::read_to_string(&path).unwrap(); + let content = fs::read_to_string(path).unwrap(); let mut config = TomlConfig::load(&content).unwrap(); assert!(anno.update_config_by_annotation(&mut config).is_err()); } @@ -349,7 +349,7 @@ mod tests { fn test_fail_to_change_kernel_path_because_of_invalid_path() { let path = env!("CARGO_MANIFEST_DIR"); let path = Path::new(path).join("tests/texture/configuration-anno-0.toml"); - let content = fs::read_to_string(&path).unwrap(); + let content = fs::read_to_string(path).unwrap(); let qemu = QemuConfig::new(); qemu.register(); From 2a73e057db017db04a3759bd1325bbecd6c6accc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 14:17:47 +0100 Subject: [PATCH 11/23] kata-types: Fix unnecessary_cast warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we bumped the rust toolchain to 1.66.0, some new warnings have been raised due to unnecessary_cast. Let's fix them all here. For more info about the warnings, please, take a look at: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast Signed-off-by: Fabiano Fidêncio --- src/libs/kata-types/src/config/hypervisor/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/kata-types/src/config/hypervisor/mod.rs b/src/libs/kata-types/src/config/hypervisor/mod.rs index d87916938..b7dd9f68c 100644 --- a/src/libs/kata-types/src/config/hypervisor/mod.rs +++ b/src/libs/kata-types/src/config/hypervisor/mod.rs @@ -1133,7 +1133,7 @@ mod tests { }, output: CpuInfo { cpu_features: "".to_string(), - default_vcpus: default_vcpus as i32, + default_vcpus, default_maxvcpus: node_cpus, }, }, From 41d7dbaaea797aa3696d6a7e06136f125b45e7e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 14:42:25 +0100 Subject: [PATCH 12/23] rustjail: Fix needless_borrow warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we bumped the rust toolchain to 1.66.0, some new warnings have been raised due to needless_borrow. Let's fix them all here. For more info about the warnings, please, take a look at: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow Signed-off-by: Fabiano Fidêncio --- src/agent/rustjail/src/mount.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/agent/rustjail/src/mount.rs b/src/agent/rustjail/src/mount.rs index a6418a343..76922024d 100644 --- a/src/agent/rustjail/src/mount.rs +++ b/src/agent/rustjail/src/mount.rs @@ -782,7 +782,7 @@ fn mount_from( Path::new(&dest).parent().unwrap() }; - fs::create_dir_all(&dir).map_err(|e| { + fs::create_dir_all(dir).map_err(|e| { log_child!( cfd_log, "create dir {}: {}", From 7bcdc9049a24d3d7b0e7c13da373ffe18c5500e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 14:42:58 +0100 Subject: [PATCH 13/23] rustjail: Fix unnecessary_cast warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we bumped the rust toolchain to 1.66.0, some new warnings have been raised due to unnecessary_cast. Let's fix them all here. For more info about the warnings, please, take a look at: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast Signed-off-by: Fabiano Fidêncio --- src/agent/rustjail/src/seccomp.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/agent/rustjail/src/seccomp.rs b/src/agent/rustjail/src/seccomp.rs index d8edbcd00..4b0c89515 100644 --- a/src/agent/rustjail/src/seccomp.rs +++ b/src/agent/rustjail/src/seccomp.rs @@ -63,7 +63,7 @@ pub fn get_unknown_syscalls(scmp: &LinuxSeccomp) -> Option> { // init_seccomp creates a seccomp filter and loads it for the current process // including all the child processes. pub fn init_seccomp(scmp: &LinuxSeccomp) -> Result<()> { - let def_action = ScmpAction::from_str(scmp.default_action.as_str(), Some(libc::EPERM as i32))?; + let def_action = ScmpAction::from_str(scmp.default_action.as_str(), Some(libc::EPERM))?; // Create a new filter context let mut filter = ScmpFilterContext::new_filter(def_action)?; From f77220490e70aaadacd55655a84ab630d4368c16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 14:49:10 +0100 Subject: [PATCH 14/23] agent: Fix needless_borrow warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we bumped the rust toolchain to 1.66.0, some new warnings have been raised due to needless_borrow. Let's fix them all here. For more info about the warnings, please, take a look at: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow Signed-off-by: Fabiano Fidêncio --- src/agent/src/device.rs | 12 ++++++------ src/agent/src/mount.rs | 6 +++--- src/agent/src/namespace.rs | 4 ++-- src/agent/src/netlink.rs | 12 ++++++------ src/agent/src/network.rs | 2 +- src/agent/src/sandbox.rs | 2 +- src/agent/src/watcher.rs | 10 +++++----- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/agent/src/device.rs b/src/agent/src/device.rs index 7d89d0124..ec277f78e 100644 --- a/src/agent/src/device.rs +++ b/src/agent/src/device.rs @@ -414,7 +414,7 @@ fn scan_scsi_bus(scsi_addr: &str) -> Result<()> { // Scan scsi host passing in the channel, SCSI id and LUN. // Channel is always 0 because we have only one SCSI controller. - let scan_data = format!("0 {} {}", tokens[0], tokens[1]); + let scan_data = &format!("0 {} {}", tokens[0], tokens[1]); for entry in fs::read_dir(SYSFS_SCSI_HOST_PATH)? { let host = entry?.file_name(); @@ -428,7 +428,7 @@ fn scan_scsi_bus(scsi_addr: &str) -> Result<()> { let scan_path = PathBuf::from(&format!("{}/{}/{}", SYSFS_SCSI_HOST_PATH, host_str, "scan")); - fs::write(scan_path, &scan_data)?; + fs::write(scan_path, scan_data)?; } Ok(()) @@ -1531,7 +1531,7 @@ mod tests { pci_driver_override(syspci, dev0, "drv_b").unwrap(); assert_eq!(fs::read_to_string(&dev0override).unwrap(), "drv_b"); assert_eq!(fs::read_to_string(&probepath).unwrap(), dev0.to_string()); - assert_eq!(fs::read_to_string(&drvaunbind).unwrap(), dev0.to_string()); + assert_eq!(fs::read_to_string(drvaunbind).unwrap(), dev0.to_string()); } #[test] @@ -1543,7 +1543,7 @@ mod tests { let dev0 = pci::Address::new(0, 0, pci::SlotFn::new(0, 0).unwrap()); let dev0path = syspci.join("devices").join(dev0.to_string()); - fs::create_dir_all(&dev0path).unwrap(); + fs::create_dir_all(dev0path).unwrap(); // Test dev0 assert!(pci_iommu_group(&syspci, dev0).unwrap().is_none()); @@ -1554,7 +1554,7 @@ mod tests { let dev1group = dev1path.join("iommu_group"); fs::create_dir_all(&dev1path).unwrap(); - std::os::unix::fs::symlink("../../../kernel/iommu_groups/12", &dev1group).unwrap(); + std::os::unix::fs::symlink("../../../kernel/iommu_groups/12", dev1group).unwrap(); // Test dev1 assert_eq!( @@ -1567,7 +1567,7 @@ mod tests { let dev2path = syspci.join("devices").join(dev2.to_string()); let dev2group = dev2path.join("iommu_group"); - fs::create_dir_all(&dev2group).unwrap(); + fs::create_dir_all(dev2group).unwrap(); // Test dev2 assert!(pci_iommu_group(&syspci, dev2).is_err()); diff --git a/src/agent/src/mount.rs b/src/agent/src/mount.rs index 1db16343e..17ea3859c 100644 --- a/src/agent/src/mount.rs +++ b/src/agent/src/mount.rs @@ -648,7 +648,7 @@ pub fn recursive_ownership_change( ) -> Result<()> { let mut mask = if read_only { RO_MASK } else { RW_MASK }; if path.is_dir() { - for entry in fs::read_dir(&path)? { + for entry in fs::read_dir(path)? { recursive_ownership_change(entry?.path().as_path(), uid, gid, read_only)?; } mask |= EXEC_MASK; @@ -894,7 +894,7 @@ pub fn get_cgroup_mounts( }]); } - let file = File::open(&cg_path)?; + let file = File::open(cg_path)?; let reader = BufReader::new(file); let mut has_device_cgroup = false; @@ -1777,7 +1777,7 @@ mod tests { let tempdir = tempdir().unwrap(); let src = if d.mask_src { - tempdir.path().join(&d.src) + tempdir.path().join(d.src) } else { Path::new(d.src).to_path_buf() }; diff --git a/src/agent/src/namespace.rs b/src/agent/src/namespace.rs index 876e3d6fd..70fa519fa 100644 --- a/src/agent/src/namespace.rs +++ b/src/agent/src/namespace.rs @@ -88,7 +88,7 @@ impl Namespace { } let logger = self.logger.clone(); - let new_ns_path = ns_path.join(&ns_type.get()); + let new_ns_path = ns_path.join(ns_type.get()); File::create(new_ns_path.as_path())?; @@ -102,7 +102,7 @@ impl Namespace { let source = Path::new(&origin_ns_path); let destination = new_ns_path.as_path(); - File::open(&source)?; + File::open(source)?; // Create a new netns on the current thread. let cf = ns_type.get_flags(); diff --git a/src/agent/src/netlink.rs b/src/agent/src/netlink.rs index ef926f515..29785fc43 100644 --- a/src/agent/src/netlink.rs +++ b/src/agent/src/netlink.rs @@ -946,13 +946,13 @@ mod tests { fn clean_env_for_test_add_one_arp_neighbor(dummy_name: &str, ip: &str) { // ip link delete dummy Command::new("ip") - .args(&["link", "delete", dummy_name]) + .args(["link", "delete", dummy_name]) .output() .expect("prepare: failed to delete dummy"); // ip neigh del dev dummy ip Command::new("ip") - .args(&["neigh", "del", dummy_name, ip]) + .args(["neigh", "del", dummy_name, ip]) .output() .expect("prepare: failed to delete neigh"); } @@ -967,19 +967,19 @@ mod tests { // ip link add dummy type dummy Command::new("ip") - .args(&["link", "add", dummy_name, "type", "dummy"]) + .args(["link", "add", dummy_name, "type", "dummy"]) .output() .expect("failed to add dummy interface"); // ip addr add 192.168.0.2/16 dev dummy Command::new("ip") - .args(&["addr", "add", "192.168.0.2/16", "dev", dummy_name]) + .args(["addr", "add", "192.168.0.2/16", "dev", dummy_name]) .output() .expect("failed to add ip for dummy"); // ip link set dummy up; Command::new("ip") - .args(&["link", "set", dummy_name, "up"]) + .args(["link", "set", dummy_name, "up"]) .output() .expect("failed to up dummy"); } @@ -1011,7 +1011,7 @@ mod tests { // ip neigh show dev dummy ip let stdout = Command::new("ip") - .args(&["neigh", "show", "dev", dummy_name, to_ip]) + .args(["neigh", "show", "dev", dummy_name, to_ip]) .output() .expect("failed to show neigh") .stdout; diff --git a/src/agent/src/network.rs b/src/agent/src/network.rs index 194795a6f..451b5064d 100644 --- a/src/agent/src/network.rs +++ b/src/agent/src/network.rs @@ -64,7 +64,7 @@ fn do_setup_guest_dns(logger: Logger, dns_list: Vec, src: &str, dst: &st .map(|x| x.trim()) .collect::>() .join("\n"); - fs::write(src, &content)?; + fs::write(src, content)?; // bind mount to /etc/resolv.conf mount::mount(Some(src), dst, Some("bind"), MsFlags::MS_BIND, None::<&str>) diff --git a/src/agent/src/sandbox.rs b/src/agent/src/sandbox.rs index 384a8e523..34275cc41 100644 --- a/src/agent/src/sandbox.rs +++ b/src/agent/src/sandbox.rs @@ -1072,7 +1072,7 @@ mod tests { fs::create_dir(&subdir_path).unwrap(); for file in j.files { let subfile_path = format!("{}/{}", subdir_path, file.name); - let mut subfile = File::create(&subfile_path).unwrap(); + let mut subfile = File::create(subfile_path).unwrap(); subfile.write_all(file.content.as_bytes()).unwrap(); } } diff --git a/src/agent/src/watcher.rs b/src/agent/src/watcher.rs index dd944d812..468684a43 100644 --- a/src/agent/src/watcher.rs +++ b/src/agent/src/watcher.rs @@ -124,7 +124,7 @@ impl Storage { // if we are creating a directory: just create it, nothing more to do if metadata.file_type().is_dir() { - let dest_file_path = self.make_target_path(&source_file_path)?; + let dest_file_path = self.make_target_path(source_file_path)?; fs::create_dir_all(&dest_file_path) .await @@ -152,7 +152,7 @@ impl Storage { // Assume target mount is a file path self.target_mount_point.clone() } else { - let dest_file_path = self.make_target_path(&source_file_path)?; + let dest_file_path = self.make_target_path(source_file_path)?; if let Some(path) = dest_file_path.parent() { debug!(logger, "Creating destination directory: {}", path.display()); @@ -778,7 +778,7 @@ mod tests { 22 ); assert_eq!( - fs::read_to_string(&entries.0[0].target_mount_point.as_path().join("1.txt")).unwrap(), + fs::read_to_string(entries.0[0].target_mount_point.as_path().join("1.txt")).unwrap(), "updated" ); @@ -823,7 +823,7 @@ mod tests { 2 ); assert_eq!( - fs::read_to_string(&entries.0[1].target_mount_point.as_path().join("foo.txt")).unwrap(), + fs::read_to_string(entries.0[1].target_mount_point.as_path().join("foo.txt")).unwrap(), "updated" ); @@ -1000,7 +1000,7 @@ mod tests { // create a path we'll remove later fs::create_dir_all(source_dir.path().join("tmp")).unwrap(); - fs::write(&source_dir.path().join("tmp/test-file"), "foo").unwrap(); + fs::write(source_dir.path().join("tmp/test-file"), "foo").unwrap(); assert_eq!(entry.scan(&logger).await.unwrap(), 3); // root, ./tmp, test-file // Verify expected directory, file: From 9ced34dd225fd1811e732925f71144e7c67608c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 14:59:50 +0100 Subject: [PATCH 15/23] agent: Fix explicit_auto_deref warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we bumped the rust toolchain to 1.66.0, some new warnings have been raised due to explicit_auto_deref. Let's fix them all here. For more info about the warnings, please, take a look at: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_auto_deref Signed-off-by: Fabiano Fidêncio --- src/agent/src/rpc.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/agent/src/rpc.rs b/src/agent/src/rpc.rs index 3b0b0ab65..c52d866d6 100644 --- a/src/agent/src/rpc.rs +++ b/src/agent/src/rpc.rs @@ -2903,7 +2903,7 @@ COMMIT .unwrap(); assert!(!result.data.is_empty(), "we should have non-zero output:"); assert!( - std::str::from_utf8(&*result.data).unwrap().contains( + std::str::from_utf8(&result.data).unwrap().contains( "PREROUTING -d 192.168.103.153/32 -j DNAT --to-destination 192.168.188.153" ), "We should see the resulting rule" @@ -2941,7 +2941,7 @@ COMMIT .unwrap(); assert!(!result.data.is_empty(), "we should have non-zero output:"); assert!( - std::str::from_utf8(&*result.data) + std::str::from_utf8(&result.data) .unwrap() .contains("INPUT -s 2001:db8:100::1/128 -i sit+ -p tcp -m tcp --sport 512:65535"), "We should see the resulting rule" From a545a65934bf217d909995c0012ba98ab79269c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 15:22:20 +0100 Subject: [PATCH 16/23] agent: Allow clippy::question_mark warning in Namespace{} MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As the rust toolchain version bump to its 1.66.0 release raised a warning about the code being able to be refactored to use `?`. For now that's something we don't need to change, so let's ignore such warning in this very specific case. See: https://rust-lang.github.io/rust-clippy/master/index.html#question_mark Signed-off-by: Fabiano Fidêncio --- src/agent/src/namespace.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/agent/src/namespace.rs b/src/agent/src/namespace.rs index 70fa519fa..a3ad26616 100644 --- a/src/agent/src/namespace.rs +++ b/src/agent/src/namespace.rs @@ -78,6 +78,7 @@ impl Namespace { // setup creates persistent namespace without switching to it. // Note, pid namespaces cannot be persisted. #[instrument] + #[allow(clippy::question_mark)] pub async fn setup(mut self) -> Result { fs::create_dir_all(&self.persistent_ns_dir)?; From 0b2f060bf3ab5f7aff5db18558ea60e5a2b8213e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 15:53:35 +0100 Subject: [PATCH 17/23] dragonball: Fix unnecessary_cast warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we bumped the rust toolchain to 1.66.0, some new warnings have been raised due to unnecessary_cast. Let's fix them all here. For more info about the warnings, please, take a look at: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast Signed-off-by: Fabiano Fidêncio --- src/dragonball/src/address_space_manager.rs | 6 +++--- src/dragonball/src/resource_manager.rs | 5 +---- src/dragonball/src/signal_handler.rs | 2 +- src/dragonball/src/vcpu/x86_64.rs | 6 +++--- src/dragonball/src/vm/x86_64.rs | 6 +++--- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/dragonball/src/address_space_manager.rs b/src/dragonball/src/address_space_manager.rs index 6e4144618..0e9ac91d7 100644 --- a/src/dragonball/src/address_space_manager.rs +++ b/src/dragonball/src/address_space_manager.rs @@ -401,9 +401,9 @@ impl AddressSpaceMgr { let flags = 0u32; let mem_region = kvm_userspace_memory_region { - slot: slot as u32, + slot, guest_phys_addr: reg.start_addr().raw_value(), - memory_size: reg.len() as u64, + memory_size: reg.len(), userspace_addr: host_addr as u64, flags, }; @@ -421,7 +421,7 @@ impl AddressSpaceMgr { self.base_to_slot .lock() .unwrap() - .insert(reg.start_addr().raw_value(), slot as u32); + .insert(reg.start_addr().raw_value(), slot); Ok(()) } diff --git a/src/dragonball/src/resource_manager.rs b/src/dragonball/src/resource_manager.rs index 456534482..ce199918b 100644 --- a/src/dragonball/src/resource_manager.rs +++ b/src/dragonball/src/resource_manager.rs @@ -435,10 +435,7 @@ impl ResourceManager { constraint.max = r.1 as u64; } match self.allocate_pio_address(&constraint) { - Some(base) => Resource::PioAddressRange { - base: base as u16, - size: *size, - }, + Some(base) => Resource::PioAddressRange { base, size: *size }, None => { if let Err(e) = self.free_device_resources(&resources) { return Err(e); diff --git a/src/dragonball/src/signal_handler.rs b/src/dragonball/src/signal_handler.rs index 23e9ff397..f6b7bfe46 100644 --- a/src/dragonball/src/signal_handler.rs +++ b/src/dragonball/src/signal_handler.rs @@ -41,7 +41,7 @@ extern "C" fn sigsys_handler(num: c_int, info: *mut siginfo_t, _unused: *mut c_v let si_code = unsafe { (*info).si_code }; // Sanity check. The condition should never be true. - if num != si_signo || num != SIGSYS || si_code != SYS_SECCOMP_CODE as i32 { + if num != si_signo || num != SIGSYS || si_code != SYS_SECCOMP_CODE { // Safe because we're terminating the process anyway. unsafe { _exit(i32::from(super::EXIT_CODE_UNEXPECTED_ERROR)) }; } diff --git a/src/dragonball/src/vcpu/x86_64.rs b/src/dragonball/src/vcpu/x86_64.rs index 738d574bb..f5616066c 100644 --- a/src/dragonball/src/vcpu/x86_64.rs +++ b/src/dragonball/src/vcpu/x86_64.rs @@ -96,14 +96,14 @@ impl Vcpu { if let Some(start_addr) = kernel_start_addr { dbs_arch::regs::setup_regs( &self.fd, - start_addr.raw_value() as u64, + start_addr.raw_value(), dbs_boot::layout::BOOT_STACK_POINTER, dbs_boot::layout::BOOT_STACK_POINTER, dbs_boot::layout::ZERO_PAGE_START, ) .map_err(VcpuError::REGSConfiguration)?; dbs_arch::regs::setup_fpu(&self.fd).map_err(VcpuError::FPUConfiguration)?; - let gdt_table: [u64; dbs_boot::layout::BOOT_GDT_MAX as usize] = [ + let gdt_table: [u64; dbs_boot::layout::BOOT_GDT_MAX] = [ gdt_entry(0, 0, 0), // NULL gdt_entry(0xa09b, 0, 0xfffff), // CODE gdt_entry(0xc093, 0, 0xfffff), // DATA @@ -129,7 +129,7 @@ impl Vcpu { fn set_cpuid(&mut self, vcpu_config: &VcpuConfig) -> Result<()> { let cpuid_vm_spec = VmSpec::new( self.id, - vcpu_config.max_vcpu_count as u8, + vcpu_config.max_vcpu_count, vcpu_config.threads_per_core, vcpu_config.cores_per_die, vcpu_config.dies_per_socket, diff --git a/src/dragonball/src/vm/x86_64.rs b/src/dragonball/src/vm/x86_64.rs index d2e084947..04cf4605c 100644 --- a/src/dragonball/src/vm/x86_64.rs +++ b/src/dragonball/src/vm/x86_64.rs @@ -81,10 +81,10 @@ fn configure_system( if mem_end < mmio_start { add_e820_entry( &mut params.0, - himem_start.raw_value() as u64, + himem_start.raw_value(), // it's safe to use unchecked_offset_from because // mem_end > himem_start - mem_end.unchecked_offset_from(himem_start) as u64 + 1, + mem_end.unchecked_offset_from(himem_start) + 1, bootparam::E820_RAM, ) .map_err(Error::BootSystem)?; @@ -103,7 +103,7 @@ fn configure_system( &mut params.0, mmio_end.raw_value() + 1, // it's safe to use unchecked_offset_from because mem_end > mmio_end - mem_end.unchecked_offset_from(mmio_end) as u64, + mem_end.unchecked_offset_from(mmio_end), bootparam::E820_RAM, ) .map_err(Error::BootSystem)?; From b95364a1401aeea959ebc2d4825b59ad7df2ebee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 15:55:49 +0100 Subject: [PATCH 18/23] dragonball: Allow question_mark warning in allocate_device_resources() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As the rust toolchain version bump to its 1.66.0 release raised a warning about the code being able to be refactored to use `?`. For now that's something we don't need to change, so let's ignore such warning in this very specific case. See: https://rust-lang.github.io/rust-clippy/master/index.html#question_mark Signed-off-by: Fabiano Fidêncio --- src/dragonball/src/resource_manager.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dragonball/src/resource_manager.rs b/src/dragonball/src/resource_manager.rs index ce199918b..b0f96e252 100644 --- a/src/dragonball/src/resource_manager.rs +++ b/src/dragonball/src/resource_manager.rs @@ -420,6 +420,7 @@ impl ResourceManager { } /// Allocate requested resources for a device. + #[allow(clippy::question_mark)] pub fn allocate_device_resources( &self, requests: &[ResourceConstraint], From 20121fcda7ec431d736ad369af9883c0b36bcc7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 16:16:39 +0100 Subject: [PATCH 19/23] runtime-rs: Fix unnecessary_cast warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we bumped the rust toolchain to 1.66.0, some new warnings have been raised due to unnecessary_cast. Let's fix them all here. For more info about the warnings, please, take a look at: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast Signed-off-by: Fabiano Fidêncio --- .../crates/hypervisor/src/dragonball/inner_hypervisor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime-rs/crates/hypervisor/src/dragonball/inner_hypervisor.rs b/src/runtime-rs/crates/hypervisor/src/dragonball/inner_hypervisor.rs index f3cb4d587..d4d75e6ef 100644 --- a/src/runtime-rs/crates/hypervisor/src/dragonball/inner_hypervisor.rs +++ b/src/runtime-rs/crates/hypervisor/src/dragonball/inner_hypervisor.rs @@ -98,7 +98,7 @@ impl DragonballInner { }; for tid in self.vmm_instance.get_vcpu_tids() { - vcpu_thread_ids.vcpus.insert(tid.0 as u32, tid.1 as u32); + vcpu_thread_ids.vcpus.insert(tid.0 as u32, tid.1); } info!(sl!(), "get thread ids {:?}", vcpu_thread_ids); Ok(vcpu_thread_ids) From 4fb163d570fac9fef0bbbf6866337d8bc593ef0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 16:18:54 +0100 Subject: [PATCH 20/23] runtime-rs: Allow clippy:box_default warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As the rust toolchain version bump to its 1.66.0 release raised a warning about using Box::default() instead of specifying a type. For now that's something we don't need to change, so let's ignore such warning in this very specific case. See: https://rust-lang.github.io/rust-clippy/master/index.html#box_default Signed-off-by: Fabiano Fidêncio --- .../crates/resource/src/network/utils/link/manager.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/runtime-rs/crates/resource/src/network/utils/link/manager.rs b/src/runtime-rs/crates/resource/src/network/utils/link/manager.rs index 6e8850cc0..f628ec03f 100644 --- a/src/runtime-rs/crates/resource/src/network/utils/link/manager.rs +++ b/src/runtime-rs/crates/resource/src/network/utils/link/manager.rs @@ -11,6 +11,7 @@ use netlink_packet_route::{ use super::{Link, LinkAttrs}; +#[allow(clippy::box_default)] pub fn get_link_from_message(mut msg: LinkMessage) -> Box { let mut base = LinkAttrs { index: msg.header.index, @@ -83,6 +84,7 @@ pub fn get_link_from_message(mut msg: LinkMessage) -> Box { ret } +#[allow(clippy::box_default)] fn link_info(mut infos: Vec) -> Box { let mut link: Option> = None; while let Some(info) = infos.pop() { From 025e78341e1d43df638e3b5109893e6cb190d0da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 16:22:07 +0100 Subject: [PATCH 21/23] runtime-rs: Fix needless_borrow warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we bumped the rust toolchain to 1.66.0, some new warnings have been raised due to needless_borrow. Let's fix them all here. For more info about the warnings, please, take a look at: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow Signed-off-by: Fabiano Fidêncio --- .../crates/resource/src/network/utils/link/create.rs | 2 +- src/runtime-rs/crates/resource/src/network/utils/netns.rs | 2 +- src/runtime-rs/crates/resource/src/share_fs/utils.rs | 2 +- .../crates/resource/src/share_fs/virtio_fs_share_mount.rs | 8 ++++---- src/runtime-rs/crates/service/src/manager.rs | 2 +- src/runtime-rs/crates/shim/src/shim_delete.rs | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/runtime-rs/crates/resource/src/network/utils/link/create.rs b/src/runtime-rs/crates/resource/src/network/utils/link/create.rs index 58b2016aa..10c7c7942 100644 --- a/src/runtime-rs/crates/resource/src/network/utils/link/create.rs +++ b/src/runtime-rs/crates/resource/src/network/utils/link/create.rs @@ -119,7 +119,7 @@ pub fn create_link(name: &str, link_type: LinkType, queues: usize) -> Result<()> fn create_queue(name: &str, flags: libc::c_int) -> Result<(File, String)> { let path = Path::new(DEVICE_PATH); - let file = OpenOptions::new().read(true).write(true).open(&path)?; + let file = OpenOptions::new().read(true).write(true).open(path)?; let mut req = CreateLinkReq::from_name(name)?; unsafe { req.set_raw_flags(flags as libc::c_short); diff --git a/src/runtime-rs/crates/resource/src/network/utils/netns.rs b/src/runtime-rs/crates/resource/src/network/utils/netns.rs index c0d0306fe..07584c641 100644 --- a/src/runtime-rs/crates/resource/src/network/utils/netns.rs +++ b/src/runtime-rs/crates/resource/src/network/utils/netns.rs @@ -20,7 +20,7 @@ impl NetnsGuard { let current_netns_path = format!("/proc/{}/task/{}/ns/{}", getpid(), gettid(), "net"); let old_netns = File::open(¤t_netns_path) .with_context(|| format!("open current netns path {}", ¤t_netns_path))?; - let new_netns = File::open(&new_netns_path) + let new_netns = File::open(new_netns_path) .with_context(|| format!("open new netns path {}", &new_netns_path))?; setns(new_netns.as_raw_fd(), CloneFlags::CLONE_NEWNET) .with_context(|| "set netns to new netns")?; diff --git a/src/runtime-rs/crates/resource/src/share_fs/utils.rs b/src/runtime-rs/crates/resource/src/share_fs/utils.rs index 115bdd146..6288e860e 100644 --- a/src/runtime-rs/crates/resource/src/share_fs/utils.rs +++ b/src/runtime-rs/crates/resource/src/share_fs/utils.rs @@ -38,7 +38,7 @@ pub(crate) fn share_to_guest( // to remount the read only dir mount point directly. if readonly { let dst = do_get_host_path(target, sid, cid, is_volume, true); - mount::bind_remount(&dst, readonly).context("bind remount readonly")?; + mount::bind_remount(dst, readonly).context("bind remount readonly")?; } Ok(do_get_guest_path(target, cid, is_volume, is_rafs)) diff --git a/src/runtime-rs/crates/resource/src/share_fs/virtio_fs_share_mount.rs b/src/runtime-rs/crates/resource/src/share_fs/virtio_fs_share_mount.rs index c29fee31f..27fb47972 100644 --- a/src/runtime-rs/crates/resource/src/share_fs/virtio_fs_share_mount.rs +++ b/src/runtime-rs/crates/resource/src/share_fs/virtio_fs_share_mount.rs @@ -173,11 +173,11 @@ impl ShareFsMount for VirtiofsShareMount { async fn upgrade_to_rw(&self, file_name: &str) -> Result<()> { // Remount readonly directory with readwrite permission let host_dest = do_get_host_path(file_name, &self.id, "", true, true); - bind_remount(&host_dest, false) + bind_remount(host_dest, false) .context("remount readonly directory with readwrite permission")?; // Remount readwrite directory with readwrite permission let host_dest = do_get_host_path(file_name, &self.id, "", true, false); - bind_remount(&host_dest, false) + bind_remount(host_dest, false) .context("remount readwrite directory with readwrite permission")?; Ok(()) } @@ -185,11 +185,11 @@ impl ShareFsMount for VirtiofsShareMount { async fn downgrade_to_ro(&self, file_name: &str) -> Result<()> { // Remount readwrite directory with readonly permission let host_dest = do_get_host_path(file_name, &self.id, "", true, false); - bind_remount(&host_dest, true) + bind_remount(host_dest, true) .context("remount readwrite directory with readonly permission")?; // Remount readonly directory with readonly permission let host_dest = do_get_host_path(file_name, &self.id, "", true, true); - bind_remount(&host_dest, true) + bind_remount(host_dest, true) .context("remount readonly directory with readonly permission")?; Ok(()) } diff --git a/src/runtime-rs/crates/service/src/manager.rs b/src/runtime-rs/crates/service/src/manager.rs index a8ca80fa5..fe31c179b 100644 --- a/src/runtime-rs/crates/service/src/manager.rs +++ b/src/runtime-rs/crates/service/src/manager.rs @@ -55,7 +55,7 @@ async fn send_event( .stdin(Stdio::piped()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) - .args(&[ + .args([ "--address", &address, "publish", diff --git a/src/runtime-rs/crates/shim/src/shim_delete.rs b/src/runtime-rs/crates/shim/src/shim_delete.rs index 89d65b610..e1053927f 100644 --- a/src/runtime-rs/crates/shim/src/shim_delete.rs +++ b/src/runtime-rs/crates/shim/src/shim_delete.rs @@ -40,7 +40,7 @@ impl ShimExecutor { let trim_path = address.strip_prefix("unix://").context("trim path")?; let file_path = Path::new("/").join(trim_path); let file_path = file_path.as_path(); - if std::fs::metadata(&file_path).is_ok() { + if std::fs::metadata(file_path).is_ok() { info!(sl!(), "remote socket path: {:?}", &file_path); fs::remove_file(file_path).ok(); } From 2c24fcf34c69bd54b8d069f75ae1e250ace70852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 16:25:43 +0100 Subject: [PATCH 22/23] runtime-rs: Fix clippy::bool-to-int-with-if warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we bumped the rust toolchain to 1.66.0, some new warnings have been raised due to boolean to int conversion using if. Let's fix them all here. For more info about the warnings, please, take a look at: https://rust-lang.github.io/rust-clippy/master/index.html#bool_to_int_with_if Signed-off-by: Fabiano Fidêncio --- src/runtime-rs/crates/resource/src/share_fs/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime-rs/crates/resource/src/share_fs/mod.rs b/src/runtime-rs/crates/resource/src/share_fs/mod.rs index 5dc1d9358..739fa0459 100644 --- a/src/runtime-rs/crates/resource/src/share_fs/mod.rs +++ b/src/runtime-rs/crates/resource/src/share_fs/mod.rs @@ -89,8 +89,8 @@ impl MountedInfo { pub fn new(guest_path: PathBuf, readonly: bool) -> Self { Self { guest_path, - ro_ref_count: if readonly { 1 } else { 0 }, - rw_ref_count: if readonly { 0 } else { 1 }, + ro_ref_count: readonly.into(), + rw_ref_count: (!readonly).into(), } } From 079462d2eb509b4777d6a92e12b64fd1d13334d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 2 Jan 2023 17:10:25 +0100 Subject: [PATCH 23/23] runk: Fix needless_borrow warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we bumped the rust toolchain to 1.66.0, some new warnings have been raised due to needless_borrow. Let's fix them all here. For more info about the warnings, please, take a look at: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow Signed-off-by: Fabiano Fidêncio --- src/tools/runk/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/runk/src/main.rs b/src/tools/runk/src/main.rs index ce300ca69..6b282ed0b 100644 --- a/src/tools/runk/src/main.rs +++ b/src/tools/runk/src/main.rs @@ -105,7 +105,7 @@ fn setup_logger( .read(true) .create(true) .truncate(true) - .open(&file)?; + .open(file)?; // TODO: Support 'text' log format. let (logger_local, logger_async_guard_local) =