runtime-rs: Fix needless_borrow warnings

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 <fabiano.fidencio@intel.com>
This commit is contained in:
Fabiano Fidêncio 2023-01-02 16:22:07 +01:00
parent 4d05ab8022
commit f5549de9cf
7 changed files with 25 additions and 10 deletions

View File

@ -1223,6 +1223,7 @@ dependencies = [
"seccompiler", "seccompiler",
"serde", "serde",
"serde_json", "serde_json",
"shim-interface",
"slog", "slog",
"slog-scope", "slog-scope",
"thiserror", "thiserror",
@ -1919,6 +1920,7 @@ dependencies = [
"safe-path", "safe-path",
"serde", "serde",
"serde_json", "serde_json",
"shim-interface",
] ]
[[package]] [[package]]
@ -2343,6 +2345,7 @@ dependencies = [
"logging", "logging",
"oci", "oci",
"persist", "persist",
"shim-interface",
"slog", "slog",
"slog-scope", "slog-scope",
"tokio", "tokio",
@ -2474,6 +2477,7 @@ dependencies = [
"logging", "logging",
"persist", "persist",
"runtimes", "runtimes",
"shim-interface",
"slog", "slog",
"slog-scope", "slog-scope",
"tokio", "tokio",
@ -2539,12 +2543,23 @@ dependencies = [
name = "shim-ctl" name = "shim-ctl"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow",
"common", "common",
"logging", "logging",
"runtimes", "runtimes",
"tokio", "tokio",
] ]
[[package]]
name = "shim-interface"
version = "0.1.0"
dependencies = [
"anyhow",
"hyper",
"hyperlocal",
"tokio",
]
[[package]] [[package]]
name = "signal-hook-registry" name = "signal-hook-registry"
version = "1.4.0" version = "1.4.0"

View File

@ -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)> { fn create_queue(name: &str, flags: libc::c_int) -> Result<(File, String)> {
let path = Path::new(DEVICE_PATH); 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)?; let mut req = CreateLinkReq::from_name(name)?;
unsafe { unsafe {
req.set_raw_flags(flags as libc::c_short); req.set_raw_flags(flags as libc::c_short);

View File

@ -20,7 +20,7 @@ impl NetnsGuard {
let current_netns_path = format!("/proc/{}/task/{}/ns/{}", getpid(), gettid(), "net"); let current_netns_path = format!("/proc/{}/task/{}/ns/{}", getpid(), gettid(), "net");
let old_netns = File::open(&current_netns_path) let old_netns = File::open(&current_netns_path)
.with_context(|| format!("open current netns path {}", &current_netns_path))?; .with_context(|| format!("open current netns path {}", &current_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))?; .with_context(|| format!("open new netns path {}", &new_netns_path))?;
setns(new_netns.as_raw_fd(), CloneFlags::CLONE_NEWNET) setns(new_netns.as_raw_fd(), CloneFlags::CLONE_NEWNET)
.with_context(|| "set netns to new netns")?; .with_context(|| "set netns to new netns")?;

View File

@ -38,7 +38,7 @@ pub(crate) fn share_to_guest(
// to remount the read only dir mount point directly. // to remount the read only dir mount point directly.
if readonly { if readonly {
let dst = do_get_host_path(target, sid, cid, is_volume, true); 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)) Ok(do_get_guest_path(target, cid, is_volume, is_rafs))

View File

@ -173,11 +173,11 @@ impl ShareFsMount for VirtiofsShareMount {
async fn upgrade_to_rw(&self, file_name: &str) -> Result<()> { async fn upgrade_to_rw(&self, file_name: &str) -> Result<()> {
// Remount readonly directory with readwrite permission // Remount readonly directory with readwrite permission
let host_dest = do_get_host_path(file_name, &self.id, "", true, true); 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")?; .context("remount readonly directory with readwrite permission")?;
// Remount readwrite directory with readwrite permission // Remount readwrite directory with readwrite permission
let host_dest = do_get_host_path(file_name, &self.id, "", true, false); 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")?; .context("remount readwrite directory with readwrite permission")?;
Ok(()) Ok(())
} }
@ -185,18 +185,18 @@ impl ShareFsMount for VirtiofsShareMount {
async fn downgrade_to_ro(&self, file_name: &str) -> Result<()> { async fn downgrade_to_ro(&self, file_name: &str) -> Result<()> {
// Remount readwrite directory with readonly permission // Remount readwrite directory with readonly permission
let host_dest = do_get_host_path(file_name, &self.id, "", true, false); 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")?; .context("remount readwrite directory with readonly permission")?;
// Remount readonly directory with readonly permission // Remount readonly directory with readonly permission
let host_dest = do_get_host_path(file_name, &self.id, "", true, true); 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")?; .context("remount readonly directory with readonly permission")?;
Ok(()) Ok(())
} }
async fn umount(&self, file_name: &str) -> Result<()> { async fn umount(&self, file_name: &str) -> Result<()> {
let host_dest = do_get_host_path(file_name, &self.id, "", true, true); let host_dest = do_get_host_path(file_name, &self.id, "", true, true);
umount_timeout(&host_dest, 0).context("Umount readwrite host dest")?; umount_timeout(host_dest, 0).context("Umount readwrite host dest")?;
// Umount event will be propagated to ro directory // Umount event will be propagated to ro directory
Ok(()) Ok(())
} }

View File

@ -55,7 +55,7 @@ async fn send_event(
.stdin(Stdio::piped()) .stdin(Stdio::piped())
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.stderr(Stdio::piped()) .stderr(Stdio::piped())
.args(&[ .args([
"--address", "--address",
&address, &address,
"publish", "publish",

View File

@ -40,7 +40,7 @@ impl ShimExecutor {
let trim_path = address.strip_prefix("unix://").context("trim path")?; let trim_path = address.strip_prefix("unix://").context("trim path")?;
let file_path = Path::new("/").join(trim_path); let file_path = Path::new("/").join(trim_path);
let file_path = file_path.as_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); info!(sl!(), "remote socket path: {:?}", &file_path);
fs::remove_file(file_path).ok(); fs::remove_file(file_path).ok();
} }