diff --git a/runc/src/common.rs b/runc/src/common.rs index fa1011f7..b3fe0bc6 100644 --- a/runc/src/common.rs +++ b/runc/src/common.rs @@ -42,7 +42,6 @@ use runc::{ pub const INIT_PID_FILE: &str = "init.pid"; pub struct ProcessIO { - pub uri: Option, pub io: Option>, pub copy: bool, } @@ -56,7 +55,6 @@ pub fn create_io( if stdio.is_null() { let nio = NullIo::new().map_err(io_error!(e, "new Null Io"))?; let pio = ProcessIO { - uri: None, io: Some(Arc::new(nio)), copy: false, }; @@ -64,20 +62,15 @@ pub fn create_io( } let stdout = stdio.stdout.as_str(); let scheme_path = stdout.trim().split("://").collect::>(); - let scheme: &str; - let uri: String; - if scheme_path.len() <= 1 { + let scheme = if scheme_path.len() <= 1 { // no scheme specified // default schema to fifo - uri = format!("fifo://{}", stdout); - scheme = "fifo" + "fifo" } else { - uri = stdout.to_string(); - scheme = scheme_path[0]; - } + scheme_path[0] + }; let mut pio = ProcessIO { - uri: Some(uri), io: None, copy: false, }; diff --git a/runc/src/sandbox.rs b/runc/src/sandbox.rs index a10a7172..e1032662 100644 --- a/runc/src/sandbox.rs +++ b/runc/src/sandbox.rs @@ -181,7 +181,7 @@ impl Sandboxer for RuncSandboxer { e })?; - sandbox.data.task_address = self.task_address.clone(); + sandbox.data.task_address.clone_from(&self.task_address); sandbox.dump().await.map_err(|e| { kill(Pid::from_raw(sandbox_pid), Signal::SIGKILL).unwrap_or_default(); e diff --git a/shim/src/io.rs b/shim/src/io.rs index e5f7f5f3..13d7545c 100644 --- a/shim/src/io.rs +++ b/shim/src/io.rs @@ -129,10 +129,8 @@ impl VsockIO { } Err(other!("timeout connect to port {}", self.port)) } -} -impl ToString for VsockIO { - fn to_string(&self) -> String { + fn convert_to_string(&self) -> String { if self.sock_path.is_empty() { String::new() } else { @@ -336,15 +334,15 @@ impl ContainerIoTransport for VSockTransport { } fn container_in(&self) -> String { - self.stdin.clone().unwrap_or_default().to_string() + self.stdin.clone().unwrap_or_default().convert_to_string() } fn container_out(&self) -> String { - self.stdout.clone().unwrap_or_default().to_string() + self.stdout.clone().unwrap_or_default().convert_to_string() } fn container_err(&self) -> String { - self.stderr.clone().unwrap_or_default().to_string() + self.stderr.clone().unwrap_or_default().convert_to_string() } async fn new_task_client(address: &str) -> Result { diff --git a/shim/src/task.rs b/shim/src/task.rs index 8f07ebaf..c481b5fb 100644 --- a/shim/src/task.rs +++ b/shim/src/task.rs @@ -255,7 +255,7 @@ where req_new.stderr = shim_io.container_err(); if !prepare_res.bundle.is_empty() { - req_new.bundle = prepare_res.bundle.clone(); + req_new.bundle.clone_from(&prepare_res.bundle); } let res = self.task.create(ctx, req_new).await?; diff --git a/vmm/sandbox/derive/src/lib.rs b/vmm/sandbox/derive/src/lib.rs index c11ca719..1702d2f4 100644 --- a/vmm/sandbox/derive/src/lib.rs +++ b/vmm/sandbox/derive/src/lib.rs @@ -14,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -#![allow(dead_code)] - #[macro_use] extern crate quote; diff --git a/vmm/sandbox/src/cloud_hypervisor/devices/device.rs b/vmm/sandbox/src/cloud_hypervisor/devices/device.rs index fd297604..2554c587 100644 --- a/vmm/sandbox/src/cloud_hypervisor/devices/device.rs +++ b/vmm/sandbox/src/cloud_hypervisor/devices/device.rs @@ -26,7 +26,6 @@ pub struct PhysicalDevice { impl_device_no_bus!(PhysicalDevice); -#[allow(dead_code)] impl PhysicalDevice { pub fn new(path: &str, id: &str) -> Self { Self { diff --git a/vmm/sandbox/src/cloud_hypervisor/mod.rs b/vmm/sandbox/src/cloud_hypervisor/mod.rs index a5f9b352..53ae16d9 100644 --- a/vmm/sandbox/src/cloud_hypervisor/mod.rs +++ b/vmm/sandbox/src/cloud_hypervisor/mod.rs @@ -98,7 +98,7 @@ impl CloudHypervisorVM { } } - pub fn add_device(&mut self, device: impl CloudHypervisorDevice + Sync + Send + 'static) { + pub fn add_device(&mut self, device: impl CloudHypervisorDevice + 'static) { self.devices.push(Box::new(device)); } diff --git a/vmm/sandbox/src/container/handler/mod.rs b/vmm/sandbox/src/container/handler/mod.rs index 28a41c3f..576505ae 100644 --- a/vmm/sandbox/src/container/handler/mod.rs +++ b/vmm/sandbox/src/container/handler/mod.rs @@ -14,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -use std::ptr::NonNull; - use async_trait::async_trait; use containerd_sandbox::{error::Result, ContainerOption, Sandbox}; use log::warn; @@ -42,40 +40,6 @@ mod process; mod spec; mod storage; -pub struct HandlerNode { - pub handler: Box + Sync + Send>, - pub next: Option>>, - pub prev: Option>>, -} - -unsafe impl Sync for HandlerNode {} - -unsafe impl Send for HandlerNode {} - -impl HandlerNode -where - S: Sync + Send, -{ - #[allow(dead_code)] - pub fn new(handler: Box + Sync + Send>) -> Self { - Self { - handler, - next: None, - prev: None, - } - } - - #[allow(dead_code)] - pub async fn handle(&self, sandbox: &mut S) -> Result<()> { - self.handler.handle(sandbox).await - } - - #[allow(dead_code)] - pub async fn rollback(&self, sandbox: &mut S) -> Result<()> { - self.handler.rollback(sandbox).await - } -} - pub struct HandlerChain { handlers: Vec + Sync + Send>>, } @@ -123,7 +87,6 @@ where Ok(()) } - #[allow(dead_code)] pub async fn rollback(&self, sandbox: &mut S) -> Result<()> { for handler in self.handlers.iter().rev() { handler.rollback(sandbox).await.unwrap_or_else(|e| { diff --git a/vmm/sandbox/src/container/handler/storage.rs b/vmm/sandbox/src/container/handler/storage.rs index 2a77d982..a3276848 100644 --- a/vmm/sandbox/src/container/handler/storage.rs +++ b/vmm/sandbox/src/container/handler/storage.rs @@ -60,7 +60,7 @@ where for mut m in mounts { if let Some(storage) = sandbox.storages.iter().find(|x| x.is_for_mount(&m)) { debug!("found storage {:?} for mount {:?}", storage, m); - m.source = storage.mount_point.clone(); + m.source.clone_from(&storage.mount_point); m.options = vec!["bind".to_string()]; if storage.need_guest_handle { storages.push(storage); diff --git a/vmm/sandbox/src/container/mod.rs b/vmm/sandbox/src/container/mod.rs index f7040ab3..c565b136 100644 --- a/vmm/sandbox/src/container/mod.rs +++ b/vmm/sandbox/src/container/mod.rs @@ -22,12 +22,8 @@ use serde::{Deserialize, Serialize}; mod handler; -#[allow(dead_code)] -const NULL_DEVICE: &str = "/dev/null"; - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct KuasarContainer { - #[allow(dead_code)] pub(crate) id: String, pub(crate) data: ContainerData, pub(crate) io_devices: Vec, diff --git a/vmm/sandbox/src/device.rs b/vmm/sandbox/src/device.rs index 38fd8a3e..8be20562 100644 --- a/vmm/sandbox/src/device.rs +++ b/vmm/sandbox/src/device.rs @@ -55,12 +55,9 @@ pub trait Device { #[allow(clippy::upper_case_acronyms)] pub enum BusType { PCI, - #[allow(dead_code)] PCIE, - #[allow(dead_code)] CCW, SCSI, - #[allow(dead_code)] MMIO, SERIAL, NULL, @@ -99,7 +96,6 @@ impl Bus { None } - #[allow(dead_code)] pub fn attach(&mut self, device: &T) -> Result { for (index, s) in self.slots.iter_mut().enumerate() { if let SlotStatus::Empty = s.status { @@ -110,7 +106,6 @@ impl Bus { Err(Error::ResourceExhausted("bus is full".to_string())) } - #[allow(dead_code)] pub fn device_slot(&self, id: &str) -> Option { for (index, s) in self.slots.iter().enumerate() { if index == 0 { @@ -150,7 +145,6 @@ pub enum SlotStatus { pub enum Transport { Pci, Ccw, - #[allow(dead_code)] Mmio, } diff --git a/vmm/sandbox/src/kata_config.rs b/vmm/sandbox/src/kata_config.rs index 892ea652..d90ef3ab 100644 --- a/vmm/sandbox/src/kata_config.rs +++ b/vmm/sandbox/src/kata_config.rs @@ -250,7 +250,8 @@ impl Hypervisor { res.virtiofs_cache = self.virtio_fs_cache.to_string(); res.virtiofs_cache_size = self.virtio_fs_cache_size; res.virtiofs_daemon_path = self.virtio_fs_daemon.to_string(); - res.virtiofs_extra_args = self.virtio_fs_extra_args.clone(); + res.virtiofs_extra_args + .clone_from(&self.virtio_fs_extra_args); res.virtio_9p_direct_io = self.virtio_9p_direct_io; if !self.virtio_9p_multidevs.is_empty() { res.virtio_9p_multidevs = self.virtio_9p_multidevs.to_string(); diff --git a/vmm/sandbox/src/network/address.rs b/vmm/sandbox/src/network/address.rs index 4ecd313b..a223ee14 100644 --- a/vmm/sandbox/src/network/address.rs +++ b/vmm/sandbox/src/network/address.rs @@ -110,7 +110,7 @@ impl IpNet { } } -#[derive(Default, Clone, Deserialize, Serialize)] +#[derive(Default, Debug, Clone, Deserialize, Serialize)] #[serde(from = "String")] #[serde(into = "String")] pub struct MacAddress(pub(crate) Vec); @@ -131,19 +131,13 @@ impl From for String { } } -impl ToString for MacAddress { - fn to_string(&self) -> String { +impl std::fmt::Display for MacAddress { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let mut segs = vec![]; for u in self.0.as_slice() { segs.push(format!("{:02x}", u)); } - segs.join(":") - } -} - -impl Debug for MacAddress { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.to_string()) + write!(f, "{}", segs.join(":")) } } diff --git a/vmm/sandbox/src/network/link.rs b/vmm/sandbox/src/network/link.rs index c33cdad2..55be0a63 100644 --- a/vmm/sandbox/src/network/link.rs +++ b/vmm/sandbox/src/network/link.rs @@ -16,6 +16,7 @@ limitations under the License. use std::{ ffi::CStr, + fmt::{Display, Formatter}, os::unix::{ fs::OpenOptionsExt, prelude::{AsRawFd, OwnedFd}, @@ -53,9 +54,7 @@ use crate::{ const DEVICE_DRIVER_VFIO: &str = "vfio-pci"; -#[allow(dead_code)] const SIOCETHTOOL: u64 = 0x8946; -#[allow(dead_code)] const ETHTOOL_GDRVINFO: u32 = 0x00000003; const TUNSETIFF: u64 = 0x400454ca; @@ -64,14 +63,12 @@ const TUNSETPERSIST: u64 = 0x400454cb; ioctl_write_ptr_bad!(ioctl_tun_set_iff, TUNSETIFF, ifreq); ioctl_write_ptr_bad!(ioctl_tun_set_persist, TUNSETPERSIST, u64); -#[allow(dead_code)] #[repr(C)] pub struct Ifreq { ifr_name: [u8; 16], ifr_data: *mut libc::c_void, } -#[allow(dead_code)] #[repr(C)] pub struct EthtoolDrvInfo { cmd: u32, @@ -115,9 +112,9 @@ impl Default for LinkType { } } -impl ToString for LinkType { - fn to_string(&self) -> String { - match &self { +impl Display for LinkType { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let s = match &self { LinkType::Unkonwn => "".to_string(), LinkType::Bridge => "bridge".to_string(), LinkType::Veth => "veth".to_string(), @@ -133,7 +130,8 @@ impl ToString for LinkType { LinkType::Physical(_, _) => "physical".to_string(), LinkType::Tap => "tap".to_string(), LinkType::Loopback => "loopback".to_string(), - } + }; + write!(f, "{}", s) } } diff --git a/vmm/sandbox/src/network/mod.rs b/vmm/sandbox/src/network/mod.rs index a34f030b..721f88ee 100644 --- a/vmm/sandbox/src/network/mod.rs +++ b/vmm/sandbox/src/network/mod.rs @@ -14,7 +14,11 @@ See the License for the specific language governing permissions and limitations under the License. */ -use std::{fmt::Debug, os::unix::prelude::AsRawFd, path::Path}; +use std::{ + fmt::{Debug, Display, Formatter}, + os::unix::prelude::AsRawFd, + path::Path, +}; use anyhow::anyhow; use containerd_sandbox::error::Result; @@ -220,25 +224,22 @@ pub async fn execute_in_netns(netns: &str, mut cmd: std::process::Command) -> Re #[derive(Debug, Clone, Serialize, Deserialize)] pub enum NetType { Tap, - #[allow(dead_code)] MacVtap, - #[allow(dead_code)] IpVtap, - #[allow(dead_code)] VethTap, - #[allow(dead_code)] VhostUser, } -impl ToString for NetType { - fn to_string(&self) -> String { - match self { +impl Display for NetType { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let s = match &self { NetType::Tap => "tap".to_string(), NetType::MacVtap => "tap".to_string(), NetType::IpVtap => "tap".to_string(), NetType::VethTap => "tap".to_string(), NetType::VhostUser => "vhost-user".to_string(), - } + }; + write!(f, "{}", s) } } diff --git a/vmm/sandbox/src/network/netlink.rs b/vmm/sandbox/src/network/netlink.rs index 0b517114..04dce2a3 100644 --- a/vmm/sandbox/src/network/netlink.rs +++ b/vmm/sandbox/src/network/netlink.rs @@ -19,9 +19,7 @@ use netlink_packet_core::{NetlinkMessage, NLM_F_ACK, NLM_F_CREATE, NLM_F_EXCL, N use netlink_packet_route::{RtnlMessage, TcMessage}; use rtnetlink::{try_nl, Error, Handle}; -#[allow(dead_code)] const HANDLE_INGRESS: u32 = 0xfffffff1; -#[allow(dead_code)] const HANDLE_TC_FILTER: u32 = 0xffff0000; pub struct QDiscAddRequest { @@ -65,7 +63,6 @@ impl QDiscAddRequest { } } -#[allow(dead_code)] pub struct TrafficFilterSetRequest { handle: Handle, message: TcMessage, diff --git a/vmm/sandbox/src/param.rs b/vmm/sandbox/src/param.rs index efa93196..3932439f 100644 --- a/vmm/sandbox/src/param.rs +++ b/vmm/sandbox/src/param.rs @@ -56,7 +56,6 @@ impl Param { } } - #[allow(dead_code)] pub fn get(&self, key: &str) -> Option { self.properties .iter() @@ -126,7 +125,6 @@ impl ToCmdLineParams for BoolParam { } } -#[allow(dead_code)] impl BoolParam { pub fn new(key: &str, value: bool) -> Self { Self(key.to_string(), value) @@ -135,7 +133,6 @@ impl BoolParam { pub struct VecParam(String, Vec); -#[allow(dead_code)] impl VecParam { pub fn new(key: &str, val: Vec) -> Self { Self(key.to_string(), val) diff --git a/vmm/sandbox/src/qemu/config.rs b/vmm/sandbox/src/qemu/config.rs index fdcdb938..354b23b5 100644 --- a/vmm/sandbox/src/qemu/config.rs +++ b/vmm/sandbox/src/qemu/config.rs @@ -14,7 +14,11 @@ See the License for the specific language governing permissions and limitations under the License. */ -use std::{collections::HashMap, os::unix::io::RawFd}; +use std::{ + collections::HashMap, + fmt::{Display, Formatter}, + os::unix::io::RawFd, +}; use containerd_sandbox::error::{Error, Result}; #[cfg(target_arch = "x86_64")] @@ -28,16 +32,8 @@ use crate::{ vm::{BlockDriver, HypervisorCommonConfig, ShareFsType}, }; -#[allow(dead_code)] -pub(crate) const MACHINE_TYPE_Q35: &str = "q35"; -#[allow(dead_code)] -pub(crate) const MACHINE_TYPE_PC: &str = "pc"; pub(crate) const MACHINE_TYPE_MICROVM_PCI: &str = "microvm-pci"; pub(crate) const MACHINE_TYPE_VIRT: &str = "virt"; -#[allow(dead_code)] -pub(crate) const MACHINE_TYPE_PSERIES: &str = "pseries"; -#[allow(dead_code)] -pub(crate) const MACHINE_TYPE_CCW_VIRTIO: &str = "s390-ccw-virtio"; #[cfg(target_arch = "x86_64")] const DEFAULT_QEMU_PATH: &str = "/usr/bin/qemu-system-x86_64"; @@ -416,23 +412,21 @@ impl Default for Incoming { #[derive(Debug, Clone, Serialize, Deserialize)] pub enum MigrationType { - #[allow(dead_code)] FD(RawFd), - #[allow(dead_code)] Exec(String), - #[allow(dead_code)] Tcp(String), Defer, } -impl ToString for MigrationType { - fn to_string(&self) -> String { - match self { +impl Display for MigrationType { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let s = match &self { MigrationType::FD(fd) => format!("fd:{}", fd), MigrationType::Exec(cmd) => format!("exec:{}", cmd), MigrationType::Tcp(endpoint) => format!("tcp:{}", endpoint), MigrationType::Defer => "defer".to_string(), - } + }; + write!(f, "{}", s) } } diff --git a/vmm/sandbox/src/qemu/devices/block.rs b/vmm/sandbox/src/qemu/devices/block.rs index 9e72b144..829b8116 100644 --- a/vmm/sandbox/src/qemu/devices/block.rs +++ b/vmm/sandbox/src/qemu/devices/block.rs @@ -19,7 +19,7 @@ use containerd_sandbox::error::Result; use log::{debug, error}; use qapi::{ qmp::{ - blockdev_add, blockdev_del, device_add, device_del, BlockdevOptions, BlockdevOptionsBase, + blockdev_add, blockdev_del, device_add, BlockdevOptions, BlockdevOptionsBase, BlockdevOptionsFile, }, Dictionary, @@ -199,13 +199,6 @@ impl VirtioBlockDevice { } } - #[allow(dead_code)] - fn to_device_del(&self) -> device_del { - device_del { - id: format!("virtio-{}", self.id()), - } - } - fn to_blockdev_del(&self) -> blockdev_del { blockdev_del { node_name: self.id.to_string(), diff --git a/vmm/sandbox/src/qemu/devices/char.rs b/vmm/sandbox/src/qemu/devices/char.rs index 57c10089..b266f193 100644 --- a/vmm/sandbox/src/qemu/devices/char.rs +++ b/vmm/sandbox/src/qemu/devices/char.rs @@ -19,10 +19,7 @@ use async_trait::async_trait; use containerd_sandbox::error::Result; use log::{debug, error}; use qapi::{ - qmp::{ - chardev_add, chardev_remove, device_add, device_del, ChardevBackend, ChardevCommon, - ChardevHostdev, - }, + qmp::{chardev_add, chardev_remove, device_add, ChardevBackend, ChardevCommon, ChardevHostdev}, Dictionary, }; use sandbox_derive::CmdLineParams; @@ -209,11 +206,4 @@ impl CharDevice { id: self.chardev_id.to_string(), } } - - #[allow(dead_code)] - fn to_device_del(&self) -> device_del { - device_del { - id: self.id.to_string(), - } - } } diff --git a/vmm/sandbox/src/qemu/devices/serial.rs b/vmm/sandbox/src/qemu/devices/serial.rs index 01d20892..2a47f664 100644 --- a/vmm/sandbox/src/qemu/devices/serial.rs +++ b/vmm/sandbox/src/qemu/devices/serial.rs @@ -31,9 +31,6 @@ pub struct SerialBridge { pub romfile: Option, #[property(key = "max_ports")] pub max_ports: Option, - #[property(ignore)] - pub transport: Transport, - #[property(ignore)] pub(crate) bus: Bus, } @@ -46,7 +43,6 @@ impl SerialBridge { disable_modern: transport.disable_modern(false), romfile: None, max_ports: None, - transport, bus: Bus { r#type: BusType::SERIAL, id: id.to_string(), diff --git a/vmm/sandbox/src/qemu/devices/vhost_user.rs b/vmm/sandbox/src/qemu/devices/vhost_user.rs index 27baa03a..0e8ffedd 100644 --- a/vmm/sandbox/src/qemu/devices/vhost_user.rs +++ b/vmm/sandbox/src/qemu/devices/vhost_user.rs @@ -14,22 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ +use std::fmt::{Display, Formatter}; + use sandbox_derive::CmdLineParams; #[derive(Debug, Clone)] pub enum VhostUserType { VhostUserNet(String), - // TODO: support virtiofs - #[allow(dead_code)] - VhostUserFS(String), } -impl ToString for VhostUserType { - fn to_string(&self) -> String { - match &self { +impl Display for VhostUserType { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let s = match &self { VhostUserType::VhostUserNet(r#type) => r#type.to_string(), - VhostUserType::VhostUserFS(r#type) => r#type.to_string(), - } + }; + write!(f, "{}", s) } } @@ -76,9 +75,6 @@ impl VhostUserDevice { VhostUserType::VhostUserNet(_) => { format!("{}-{}", "net", id) } - VhostUserType::VhostUserFS(_) => { - format!("{}-{}", "fs", id) - } }; Self { id: id.to_string(), diff --git a/vmm/sandbox/src/qemu/qmp_client.rs b/vmm/sandbox/src/qemu/qmp_client.rs index d2eb3e17..ec3421bf 100644 --- a/vmm/sandbox/src/qemu/qmp_client.rs +++ b/vmm/sandbox/src/qemu/qmp_client.rs @@ -31,14 +31,11 @@ use tokio::{ oneshot::{channel, Sender}, Mutex, }, - task::JoinHandle, }; pub struct QmpClient { qmp: QapiService>>, watchers: Arc>>, - #[allow(dead_code)] - handle: JoinHandle<()>, } pub struct QmpEventWatcher { @@ -54,7 +51,7 @@ impl QmpClient { let event_watchers = Arc::new(Mutex::new(Vec::::new())); let w_clone = event_watchers.clone(); - let handle = tokio::spawn(async move { + tokio::spawn(async move { while let Some(Ok(event)) = events.next().await { let mut ws = w_clone.lock().await; let mut retained = vec![]; @@ -76,7 +73,6 @@ impl QmpClient { let client = Self { qmp: service, watchers: event_watchers, - handle, }; Ok(client) } diff --git a/vmm/sandbox/src/sandbox.rs b/vmm/sandbox/src/sandbox.rs index e887f9b3..41c5af30 100644 --- a/vmm/sandbox/src/sandbox.rs +++ b/vmm/sandbox/src/sandbox.rs @@ -686,10 +686,6 @@ pub struct StaticDeviceSpec { pub(crate) _host_path: Vec, #[serde(default)] pub(crate) _bdf: Vec, - #[allow(dead_code)] - #[deprecated] - #[serde(default)] - pub(crate) gpu_group_id: i32, } fn monitor(sandbox_mutex: Arc>>) { diff --git a/vmm/sandbox/src/storage/mod.rs b/vmm/sandbox/src/storage/mod.rs index 83915b10..566b3829 100644 --- a/vmm/sandbox/src/storage/mod.rs +++ b/vmm/sandbox/src/storage/mod.rs @@ -317,8 +317,6 @@ where } pub struct MountInfo { - pub device: String, - pub mount_point: String, pub fs_type: String, pub options: Vec, } diff --git a/vmm/sandbox/src/storage/mount.rs b/vmm/sandbox/src/storage/mount.rs index ee0cf5fd..cd959709 100644 --- a/vmm/sandbox/src/storage/mount.rs +++ b/vmm/sandbox/src/storage/mount.rs @@ -45,15 +45,9 @@ pub async fn get_mount_info(mount_point: &str) -> Result> { // format: "/dev/sdc /mnt ext4 rw,relatime,stripe=64 0 0" let mp = fields[1].to_string(); if mp == mount_point { - let device = fields[0].to_string(); let fs_type = fields[2].to_string(); let options = fields[3].split(',').map(|x| x.to_string()).collect(); - return Ok(Some(MountInfo { - device, - mount_point: mp, - fs_type, - options, - })); + return Ok(Some(MountInfo { fs_type, options })); } } Ok(None) diff --git a/vmm/sandbox/src/stratovirt/config.rs b/vmm/sandbox/src/stratovirt/config.rs index 4a438b2a..a4a25717 100644 --- a/vmm/sandbox/src/stratovirt/config.rs +++ b/vmm/sandbox/src/stratovirt/config.rs @@ -24,18 +24,8 @@ use crate::{ stratovirt::virtiofs::DEFAULT_VHOST_USER_FS_BIN_PATH, vm::HypervisorCommonConfig, }; -#[allow(dead_code)] -pub(crate) const MACHINE_TYPE_Q35: &str = "q35"; -#[allow(dead_code)] -pub(crate) const MACHINE_TYPE_PC: &str = "pc"; -#[allow(dead_code)] pub(crate) const MACHINE_TYPE_VIRT: &str = "virt"; -#[allow(dead_code)] pub(crate) const MACHINE_TYPE_MICROVM: &str = "microvm"; -#[allow(dead_code)] -pub(crate) const MACHINE_TYPE_PSERIES: &str = "pseries"; -#[allow(dead_code)] -pub(crate) const MACHINE_TYPE_CCW_VIRTIO: &str = "s390-ccw-virtio"; const DEFAULT_STRATOVIRT_PATH: &str = "/usr/bin/stratovirt"; const DEFAULT_KERNEL_PARAMS: &str = "console=hvc0 console=hvc1 iommu=off panic=1 pcie_ports=native"; diff --git a/vmm/sandbox/src/stratovirt/devices/block.rs b/vmm/sandbox/src/stratovirt/devices/block.rs index f1288d83..b3d9c038 100644 --- a/vmm/sandbox/src/stratovirt/devices/block.rs +++ b/vmm/sandbox/src/stratovirt/devices/block.rs @@ -19,7 +19,7 @@ use containerd_sandbox::error::Result; use log::{debug, error}; use qapi::{ qmp::{ - blockdev_add, blockdev_del, device_add, device_del, BlockdevCacheOptions, BlockdevOptions, + blockdev_add, blockdev_del, device_add, BlockdevCacheOptions, BlockdevOptions, BlockdevOptionsBase, BlockdevOptionsFile, BlockdevOptionsGenericFormat, BlockdevOptionsRaw, BlockdevRef, }, @@ -33,7 +33,6 @@ use crate::{ stratovirt::{devices::HotAttachable, qmp_client::QmpClient}, }; -#[allow(dead_code)] pub const VIRTIO_BLK_DRIVER: &str = "virtio-blk"; #[derive(CmdLineParams, Debug, Clone)] @@ -61,7 +60,7 @@ pub struct VirtioBlockDevice { } impl_device_no_bus!(VirtioBlockDevice); -impl_set_get_device_addr!(VirtioBlockDevice); +impl_set_device_addr!(VirtioBlockDevice); impl VirtioBlockDevice { pub fn new( @@ -174,13 +173,6 @@ impl VirtioBlockDevice { } } - #[allow(dead_code)] - fn to_device_del(&self) -> device_del { - device_del { - id: format!("virtio-{}", self.id()), - } - } - fn to_blockdev_del(&self) -> blockdev_del { blockdev_del { node_name: self.id.to_string(), @@ -222,7 +214,7 @@ mod tests { assert!(compare_json_strings( &blockdev_add_qmp_json_str, - expected_params_str + expected_params_str, )); } @@ -246,7 +238,7 @@ mod tests { let expected_params_str = r#"{"driver":"virtio-blk-pci","id":"virtio-drive-0","bus":"pcie.1","addr":"0x0","drive":"drive-0"}"#; assert!(compare_json_strings( &device_add_qmp_json_str, - expected_params_str + expected_params_str, )); } @@ -270,25 +262,4 @@ mod tests { let expected_params_str = r#"{"node-name":"drive-0"}"#; assert_eq!(expected_params_str, blockdev_del_qmp_json_str); } - - #[test] - fn test_device_del_qmp_commands() { - let virtio_blk_device = VirtioBlockDevice::new( - VIRTIO_BLK_DRIVER, - "drive-0", - "", - Some("/dev/dm-8".to_string()), - Some(false), - ); - - let device_del_qmp_cmd = virtio_blk_device.to_device_del(); - let device_del_qmp_json_str = serde_json::to_string(&device_del_qmp_cmd).unwrap(); - println!( - "device_del qmp cmd json string: {}", - device_del_qmp_json_str - ); - - let expected_params_str = r#"{"id":"virtio-drive-0"}"#; - assert_eq!(expected_params_str, device_del_qmp_json_str); - } } diff --git a/vmm/sandbox/src/stratovirt/devices/char.rs b/vmm/sandbox/src/stratovirt/devices/char.rs index 075d7ba1..62704952 100644 --- a/vmm/sandbox/src/stratovirt/devices/char.rs +++ b/vmm/sandbox/src/stratovirt/devices/char.rs @@ -42,7 +42,7 @@ pub struct CharDevice { } impl_device_no_bus!(CharDevice); -impl_set_get_device_addr!(CharDevice); +impl_set_device_addr!(CharDevice); impl CharDevice { pub fn new(backend: &str, chardev_id: &str, path: &str) -> Self { @@ -57,10 +57,9 @@ impl CharDevice { } } +#[cfg(test)] mod tests { - #[allow(unused_imports)] use super::CharDevice; - #[allow(unused_imports)] use crate::param::ToCmdLineParams; #[test] diff --git a/vmm/sandbox/src/stratovirt/devices/console.rs b/vmm/sandbox/src/stratovirt/devices/console.rs index 126a2e1d..c2901680 100644 --- a/vmm/sandbox/src/stratovirt/devices/console.rs +++ b/vmm/sandbox/src/stratovirt/devices/console.rs @@ -30,7 +30,7 @@ pub struct VirtConsole { } impl_device_no_bus!(VirtConsole); -impl_set_get_device_addr!(VirtConsole); +impl_set_device_addr!(VirtConsole); impl VirtConsole { pub fn new(id: &str, chardev_id: &str) -> Self { @@ -43,16 +43,15 @@ impl VirtConsole { } } +#[cfg(test)] mod tests { - #[allow(unused_imports)] use super::VirtConsole; - #[allow(unused_imports)] use crate::{ device::Transport, param::ToCmdLineParams, stratovirt::devices::{ - char::CharDevice, device::GetAndSetDeviceAddr, serial::SerialDevice, DEFAULT_PCIE_BUS, - VIRTIO_SERIAL_CONSOLE_ADDR, + char::CharDevice, device::SetDeviceAddr, serial::SerialDevice, + tests::VIRTIO_SERIAL_CONSOLE_ADDR, DEFAULT_PCIE_BUS, }, }; diff --git a/vmm/sandbox/src/stratovirt/devices/device.rs b/vmm/sandbox/src/stratovirt/devices/device.rs index 6a22496f..bdd6b2d9 100644 --- a/vmm/sandbox/src/stratovirt/devices/device.rs +++ b/vmm/sandbox/src/stratovirt/devices/device.rs @@ -14,18 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -pub trait GetAndSetDeviceAddr { - fn get_device_addr(&self) -> String; +pub trait SetDeviceAddr { fn set_device_addr(&mut self, addr: usize); } -macro_rules! impl_set_get_device_addr { +macro_rules! impl_set_device_addr { ($ty:ty) => { - impl crate::stratovirt::devices::device::GetAndSetDeviceAddr for $ty { - fn get_device_addr(&self) -> String { - self.addr.clone() - } - + impl crate::stratovirt::devices::device::SetDeviceAddr for $ty { fn set_device_addr(&mut self, addr: usize) { self.addr = format!("{:#02x}", addr); } diff --git a/vmm/sandbox/src/stratovirt/devices/mod.rs b/vmm/sandbox/src/stratovirt/devices/mod.rs index 41f57167..168ad0f4 100644 --- a/vmm/sandbox/src/stratovirt/devices/mod.rs +++ b/vmm/sandbox/src/stratovirt/devices/mod.rs @@ -17,11 +17,11 @@ limitations under the License. use async_trait::async_trait; use containerd_sandbox::error::Result; -use self::{device::GetAndSetDeviceAddr, pcie_rootbus::PcieRootBus}; +use self::pcie_rootbus::PcieRootBus; use crate::{ device::{Bus, BusType, Device, Slot, SlotStatus}, param::ToCmdLineParams, - stratovirt::qmp_client::QmpClient, + stratovirt::{devices::device::SetDeviceAddr, qmp_client::QmpClient}, }; #[macro_use] @@ -47,20 +47,9 @@ pub(crate) const DEFAULT_SERIAL_DEVICE_ID: &str = "virtio-serial0"; pub(crate) const DEFAULT_CONSOLE_DEVICE_ID: &str = "virtio-console0"; pub(crate) const DEFAULT_CONSOLE_CHARDEV_ID: &str = "charconsole0"; -#[allow(dead_code)] -pub(crate) const VIRTIO_RND_DEVICE_ADDR: usize = 1; -#[allow(dead_code)] -pub(crate) const VIRTIO_SERIAL_CONSOLE_ADDR: usize = 2; -#[allow(dead_code)] -pub(crate) const VHOST_VSOCK_ADDR: usize = 3; -#[allow(dead_code)] -pub(crate) const VHOST_USER_FS_ADDR: usize = 4; -#[allow(dead_code)] -pub(crate) const ROOTPORT_PCI_START_ADDR: usize = 5; +pub trait StratoVirtDevice: Device + ToCmdLineParams + SetDeviceAddr {} -pub trait StratoVirtDevice: Device + ToCmdLineParams + GetAndSetDeviceAddr {} - -impl StratoVirtDevice for T where T: Device + ToCmdLineParams + GetAndSetDeviceAddr {} +impl StratoVirtDevice for T where T: Device + ToCmdLineParams + SetDeviceAddr {} #[async_trait] pub trait HotAttachable { @@ -90,6 +79,12 @@ pub fn create_pcie_root_bus() -> Option { #[cfg(test)] mod tests { + pub(crate) const VIRTIO_RND_DEVICE_ADDR: usize = 1; + pub(crate) const VIRTIO_SERIAL_CONSOLE_ADDR: usize = 2; + pub(crate) const VHOST_VSOCK_ADDR: usize = 3; + pub(crate) const VHOST_USER_FS_ADDR: usize = 4; + pub(crate) const ROOTPORT_PCI_START_ADDR: usize = 5; + use super::create_pcie_root_bus; use crate::device::SlotStatus; diff --git a/vmm/sandbox/src/stratovirt/devices/rng.rs b/vmm/sandbox/src/stratovirt/devices/rng.rs index 3e9f9881..956cb128 100644 --- a/vmm/sandbox/src/stratovirt/devices/rng.rs +++ b/vmm/sandbox/src/stratovirt/devices/rng.rs @@ -45,7 +45,7 @@ pub struct VirtioRngDevice { } impl_device_no_bus!(VirtioRngDevice); -impl_set_get_device_addr!(VirtioRngDevice); +impl_set_device_addr!(VirtioRngDevice); impl VirtioRngDevice { pub fn new(id: &str, filename: &str, transport: Transport, bus: &str) -> Self { @@ -70,7 +70,7 @@ mod tests { device::Transport, param::ToCmdLineParams, stratovirt::devices::{ - device::GetAndSetDeviceAddr, DEFAULT_PCIE_BUS, VIRTIO_RND_DEVICE_ADDR, + device::SetDeviceAddr, tests::VIRTIO_RND_DEVICE_ADDR, DEFAULT_PCIE_BUS, }, }; diff --git a/vmm/sandbox/src/stratovirt/devices/rootport.rs b/vmm/sandbox/src/stratovirt/devices/rootport.rs index 9df8377b..19bc7581 100644 --- a/vmm/sandbox/src/stratovirt/devices/rootport.rs +++ b/vmm/sandbox/src/stratovirt/devices/rootport.rs @@ -54,7 +54,7 @@ impl RootPort { } impl_device_no_bus!(RootPort); -impl_set_get_device_addr!(RootPort); +impl_set_device_addr!(RootPort); #[derive(Debug, Clone, Default)] pub struct PCIERootPorts { @@ -71,7 +71,7 @@ mod tests { use crate::{ param::ToCmdLineParams, stratovirt::devices::{ - device::GetAndSetDeviceAddr, DEFAULT_PCIE_BUS, ROOTPORT_PCI_START_ADDR, + device::SetDeviceAddr, tests::ROOTPORT_PCI_START_ADDR, DEFAULT_PCIE_BUS, }, }; diff --git a/vmm/sandbox/src/stratovirt/devices/serial.rs b/vmm/sandbox/src/stratovirt/devices/serial.rs index b117b0f6..8306fa62 100644 --- a/vmm/sandbox/src/stratovirt/devices/serial.rs +++ b/vmm/sandbox/src/stratovirt/devices/serial.rs @@ -30,8 +30,6 @@ pub struct SerialDevice { pub bus: String, #[property(param = "device", predicate = "self.addr.len()>0")] pub addr: String, - #[property(ignore)] - pub transport: Transport, } impl SerialDevice { @@ -41,13 +39,12 @@ impl SerialDevice { id: id.to_string(), bus: bus.to_string(), addr: "".to_string(), - transport, } } } impl_device_no_bus!(SerialDevice); -impl_set_get_device_addr!(SerialDevice); +impl_set_device_addr!(SerialDevice); #[cfg(test)] mod tests { @@ -56,7 +53,7 @@ mod tests { device::Transport, param::ToCmdLineParams, stratovirt::devices::{ - device::GetAndSetDeviceAddr, DEFAULT_PCIE_BUS, VIRTIO_SERIAL_CONSOLE_ADDR, + device::SetDeviceAddr, tests::VIRTIO_SERIAL_CONSOLE_ADDR, DEFAULT_PCIE_BUS, }, }; diff --git a/vmm/sandbox/src/stratovirt/devices/vhost_user_fs.rs b/vmm/sandbox/src/stratovirt/devices/vhost_user_fs.rs index 89e012c4..fe0ddd19 100644 --- a/vmm/sandbox/src/stratovirt/devices/vhost_user_fs.rs +++ b/vmm/sandbox/src/stratovirt/devices/vhost_user_fs.rs @@ -37,7 +37,7 @@ pub struct VhostUserFs { } impl_device_no_bus!(VhostUserFs); -impl_set_get_device_addr!(VhostUserFs); +impl_set_device_addr!(VhostUserFs); impl VhostUserFs { pub fn new(id: &str, transport: Transport, chardev: &str, mount_tag: &str, bus: &str) -> Self { @@ -59,7 +59,7 @@ mod tests { device::Transport, param::ToCmdLineParams, stratovirt::devices::{ - char::CharDevice, device::GetAndSetDeviceAddr, DEFAULT_PCIE_BUS, VHOST_USER_FS_ADDR, + char::CharDevice, device::SetDeviceAddr, tests::VHOST_USER_FS_ADDR, DEFAULT_PCIE_BUS, }, }; @@ -93,12 +93,12 @@ mod tests { let expected_params: Vec = vec![ "-chardev", "socket,id=virtio-fs-test,path=/path/to/virtiofs.sock,server,nowait", - "-device", + "-device", "vhost-user-fs-pci,id=vhost-user-fs-test,chardev=virtio-fs-test,tag=myfs,bus=pcie.0,addr=0x4", - ] - .iter() - .map(|s| s.to_string()) - .collect(); + ] + .iter() + .map(|s| s.to_string()) + .collect(); assert_eq!(expected_params, result_params); } } diff --git a/vmm/sandbox/src/stratovirt/devices/virtio_net.rs b/vmm/sandbox/src/stratovirt/devices/virtio_net.rs index 3a8ed7d9..ffe676b9 100644 --- a/vmm/sandbox/src/stratovirt/devices/virtio_net.rs +++ b/vmm/sandbox/src/stratovirt/devices/virtio_net.rs @@ -93,7 +93,7 @@ impl VirtioNetDevice { } impl_device_no_bus!(VirtioNetDevice); -impl_set_get_device_addr!(VirtioNetDevice); +impl_set_device_addr!(VirtioNetDevice); impl VirtioNetDevice { pub fn new() -> Self { diff --git a/vmm/sandbox/src/stratovirt/devices/vsock.rs b/vmm/sandbox/src/stratovirt/devices/vsock.rs index f441fc9f..d0fff11f 100644 --- a/vmm/sandbox/src/stratovirt/devices/vsock.rs +++ b/vmm/sandbox/src/stratovirt/devices/vsock.rs @@ -47,7 +47,7 @@ pub struct VSockDevice { } impl_device_no_bus!(VSockDevice); -impl_set_get_device_addr!(VSockDevice); +impl_set_device_addr!(VSockDevice); impl VSockDevice { pub fn new(context_id: u64, transport: Transport, bus: &str, vhost_fd: i32) -> Self { @@ -88,7 +88,7 @@ mod tests { use crate::{ device::Transport, param::ToCmdLineParams, - stratovirt::devices::{device::GetAndSetDeviceAddr, DEFAULT_PCIE_BUS, VHOST_VSOCK_ADDR}, + stratovirt::devices::{device::SetDeviceAddr, tests::VHOST_VSOCK_ADDR, DEFAULT_PCIE_BUS}, }; #[test] @@ -106,9 +106,9 @@ mod tests { "-device", "vhost-vsock-pci,id=vsock-1224150961,guest-cid=1224150961,bus=pcie.0,addr=0x3,vhostfd=100", ] - .iter() - .map(|s| s.to_string()) - .collect(); + .iter() + .map(|s| s.to_string()) + .collect(); assert_eq!(expected_params, vhost_vsock_device_cmd_params); } } diff --git a/vmm/sandbox/src/stratovirt/mod.rs b/vmm/sandbox/src/stratovirt/mod.rs index 57404203..724a93c2 100644 --- a/vmm/sandbox/src/stratovirt/mod.rs +++ b/vmm/sandbox/src/stratovirt/mod.rs @@ -242,7 +242,30 @@ impl VM for StratoVirtVM { } } - async fn hot_detach(&mut self, _id: &str) -> Result<()> { + async fn hot_detach(&mut self, id: &str) -> Result<()> { + let index = self.hot_attached_devices.iter().position(|x| x.id() == id); + let device = match index { + None => { + return Ok(()); + } + Some(index) => self.hot_attached_devices.remove(index), + }; + + let client = match self.get_client() { + Ok(c) => c, + Err(e) => { + // rollback, add it back to the list + self.hot_attached_devices.push(device); + return Err(e); + } + }; + + if let Err(e) = device.execute_hot_detach(client).await { + // rollback, add it back to the list + self.hot_attached_devices.push(device); + return Err(e); + } + self.detach_from_bus(id); Ok(()) } @@ -262,12 +285,12 @@ impl VM for StratoVirtVM { async fn vcpus(&self) -> Result { let client = self.get_client()?; - let result = client.execute(qmp::query_cpus {}).await?; + let result = client.execute(qmp::QueryCpus {}).await?; let mut vcpu_threads_map: HashMap = HashMap::new(); for vcpu_info in result.iter() { match vcpu_info { - CpuInfo::Arm { base, .. } | CpuInfo::x86 { base, .. } => { - vcpu_threads_map.insert(base.CPU, base.thread_id); + CpuInfo::Arm { base, .. } | CpuInfo::X86 { base, .. } => { + vcpu_threads_map.insert(base.cpu, base.thread_id); } } } @@ -544,6 +567,24 @@ impl StratoVirtVM { .start() .map_err(|e| Error::Other(anyhow!("start virtiofs daemon process failed: {}", e))) } + + fn detach_from_bus(&mut self, device_id: &str) { + self.devices + .iter_mut() + .filter_map(|x| x.bus()) + .for_each(|b| { + if let Some(x) = b.slots.iter_mut().find(|s| { + if let SlotStatus::Occupied(id) = &s.status { + if id == device_id { + return true; + } + } + false + }) { + x.status = SlotStatus::Empty; + } + }); + } } impl_recoverable!(StratoVirtVM); diff --git a/vmm/sandbox/src/stratovirt/qmp.rs b/vmm/sandbox/src/stratovirt/qmp.rs index 135cf4e5..0c1c008e 100644 --- a/vmm/sandbox/src/stratovirt/qmp.rs +++ b/vmm/sandbox/src/stratovirt/qmp.rs @@ -14,16 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. */ -#![allow(warnings)] - use qapi::qmp::QmpCommand; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] -pub struct query_cpus {} +pub struct QueryCpus {} -impl QmpCommand for query_cpus {} -impl ::qapi_spec::Command for query_cpus { +impl QmpCommand for QueryCpus {} +impl ::qapi_spec::Command for QueryCpus { const NAME: &'static str = "query-cpus"; const ALLOW_OOB: bool = false; @@ -33,7 +31,7 @@ impl ::qapi_spec::Command for query_cpus { #[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum CpuInfoArch { #[serde(rename = "x86")] - x86, + X86, #[serde(rename = "Arm")] Arm, } @@ -52,7 +50,7 @@ unsafe impl ::qapi_spec::Enum for CpuInfoArch { } const COUNT: usize = 2; - const VARIANTS: &'static [Self] = &[CpuInfoArch::x86, CpuInfoArch::Arm]; + const VARIANTS: &'static [Self] = &[CpuInfoArch::X86, CpuInfoArch::Arm]; const NAMES: &'static [&'static str] = &["x86", "Arm"]; } @@ -66,10 +64,10 @@ pub enum CpuInfo { base: CpuInfoBase, #[serde(flatten)] #[serde(rename = "Arm")] - Arm: CpuInfoArm, + arm: CpuInfoArm, }, #[serde(rename = "x86")] - x86 { + X86 { #[serde(flatten)] #[serde(rename = "base")] base: CpuInfoBase, @@ -82,31 +80,21 @@ pub enum CpuInfo { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct CpuInfoBase { #[serde(rename = "CPU")] - pub CPU: i64, + pub cpu: i64, #[serde(rename = "current")] pub current: bool, #[serde(rename = "halted")] pub halted: bool, #[serde(rename = "qom_path")] - pub qom_path: ::std::string::String, + pub qom_path: String, #[serde(rename = "thread_id")] pub thread_id: i64, } -impl CpuInfo { - pub fn arch(&self) -> CpuInfoArch { - match *self { - CpuInfo::Arm { .. } => CpuInfoArch::Arm, - - CpuInfo::x86 { .. } => CpuInfoArch::x86, - } - } -} - impl From<(CpuInfoArm, CpuInfoBase)> for CpuInfo { fn from(val: (CpuInfoArm, CpuInfoBase)) -> Self { Self::Arm { - Arm: val.0, + arm: val.0, base: val.1, } } @@ -114,7 +102,7 @@ impl From<(CpuInfoArm, CpuInfoBase)> for CpuInfo { impl From<(CpuInfoX86, CpuInfoBase)> for CpuInfo { fn from(val: (CpuInfoX86, CpuInfoBase)) -> Self { - Self::x86 { + Self::X86 { x86: val.0, base: val.1, } diff --git a/vmm/sandbox/src/stratovirt/qmp_client.rs b/vmm/sandbox/src/stratovirt/qmp_client.rs index d2eb3e17..ec3421bf 100644 --- a/vmm/sandbox/src/stratovirt/qmp_client.rs +++ b/vmm/sandbox/src/stratovirt/qmp_client.rs @@ -31,14 +31,11 @@ use tokio::{ oneshot::{channel, Sender}, Mutex, }, - task::JoinHandle, }; pub struct QmpClient { qmp: QapiService>>, watchers: Arc>>, - #[allow(dead_code)] - handle: JoinHandle<()>, } pub struct QmpEventWatcher { @@ -54,7 +51,7 @@ impl QmpClient { let event_watchers = Arc::new(Mutex::new(Vec::::new())); let w_clone = event_watchers.clone(); - let handle = tokio::spawn(async move { + tokio::spawn(async move { while let Some(Ok(event)) = events.next().await { let mut ws = w_clone.lock().await; let mut retained = vec![]; @@ -76,7 +73,6 @@ impl QmpClient { let client = Self { qmp: service, watchers: event_watchers, - handle, }; Ok(client) } diff --git a/vmm/sandbox/src/utils.rs b/vmm/sandbox/src/utils.rs index 729473bf..0cb754fd 100644 --- a/vmm/sandbox/src/utils.rs +++ b/vmm/sandbox/src/utils.rs @@ -67,7 +67,7 @@ pub fn get_netns(data: &SandboxData) -> String { if let Some(l) = &spec.linux { for ns in &l.namespaces { if ns.r#type == NET_NAMESPACE { - netns = ns.path.clone(); + netns.clone_from(&ns.path); } } } diff --git a/vmm/task/src/container.rs b/vmm/task/src/container.rs index 0499affb..e9c53bb7 100644 --- a/vmm/task/src/container.rs +++ b/vmm/task/src/container.rs @@ -62,11 +62,6 @@ use crate::{ util::{read_io, read_storages, wait_pid}, }; -#[allow(dead_code)] -pub const GROUP_LABELS: [&str; 2] = [ - "io.containerd.runc.v2.group", - "io.kubernetes.cri.sandbox-id", -]; pub const INIT_PID_FILE: &str = "init.pid"; const STORAGE_ANNOTATION: &str = "io.kuasar.storages"; diff --git a/vmm/task/src/device.rs b/vmm/task/src/device.rs index bf78a060..d271fbcc 100644 --- a/vmm/task/src/device.rs +++ b/vmm/task/src/device.rs @@ -61,14 +61,11 @@ pub trait DeviceMatcher: Sync + Send + 'static { pub type DeviceConverter = fn(&Uevent) -> Option; pub struct DeviceSubscriber { - #[allow(dead_code)] - pub(crate) id: u64, pub(crate) tx: Sender, pub(crate) matcher: Box, } pub struct DeviceSubscription { - #[allow(dead_code)] pub(crate) id: u64, pub(crate) rx: Receiver, } @@ -106,7 +103,6 @@ impl DeviceMonitor { ss.insert( id, DeviceSubscriber { - id, tx, matcher: Box::new(matcher), }, @@ -115,7 +111,6 @@ impl DeviceMonitor { DeviceSubscription { id, rx } } - #[allow(dead_code)] pub async fn unsubscribe(&self, id: u64) { let mut internal = self.internal.lock().await; let ss = &mut internal.subscribers; @@ -296,24 +291,17 @@ impl Uevent { } } -#[allow(dead_code)] -pub const SCSI_HOST_CHANNEL: &str = "0:0:"; pub const SCSI_BLOCK_SUFFIX: &str = "block"; pub const SYSFS_SCSI_HOST_PATH: &str = "/sys/class/scsi_host"; pub const SYSFS_SCSI_DEVICE_PATH: &str = "/sys/class/scsi_device"; pub const SYSFS_BLK_DEVICE_PATH: &str = "/sys/class/block"; pub const SYSFS_PCI_BUS_RESCAN_FILE: &str = "/sys/bus/pci/rescan"; -#[allow(dead_code)] -pub const SYSFS_PCI_BUS_PREFIX: &str = "/sys/bus/pci/devices"; pub const SYSTEM_DEV_PATH: &str = "/dev"; #[derive(Clone, PartialEq, Eq, Debug)] pub enum DeviceType { - #[allow(dead_code)] Blk, Scsi, - #[allow(dead_code)] - Ephemeral, } #[derive(Clone, Debug)] diff --git a/vmm/task/src/io.rs b/vmm/task/src/io.rs index f943e8db..6401d994 100644 --- a/vmm/task/src/io.rs +++ b/vmm/task/src/io.rs @@ -49,7 +49,6 @@ use tokio_vsock::{VsockListener, VsockStream}; use crate::{device::SYSTEM_DEV_PATH, vsock}; pub struct ProcessIO { - pub uri: Option, pub io: Option>, pub copy: bool, } @@ -65,7 +64,6 @@ pub fn create_io( if stdio.is_null() { let nio = NullIo::new().map_err(io_error!(e, "new Null Io"))?; let pio = ProcessIO { - uri: None, io: Some(Arc::new(nio)), copy: false, }; @@ -73,20 +71,15 @@ pub fn create_io( } let stdout = stdio.stdout.as_str(); let scheme_path = stdout.trim().split("://").collect::>(); - let scheme: &str; - let uri: String; - if scheme_path.len() <= 1 { + let scheme = if scheme_path.len() <= 1 { // no scheme specified // default schema to fifo - uri = format!("fifo://{}", stdout); - scheme = "fifo" + "fifo" } else { - uri = stdout.to_string(); - scheme = scheme_path[0]; - } + scheme_path[0] + }; let mut pio = ProcessIO { - uri: Some(uri), io: None, copy: false, }; diff --git a/vmm/task/src/mount.rs b/vmm/task/src/mount.rs index 262bed26..8d63afa7 100644 --- a/vmm/task/src/mount.rs +++ b/vmm/task/src/mount.rs @@ -16,11 +16,7 @@ use tokio::{ use crate::StaticMount; pub const SYSFS_CGROUPPATH: &str = "/sys/fs/cgroup"; -#[allow(dead_code)] -pub const SYSFS_ONLINE_FILE: &str = "online"; -#[allow(dead_code)] -pub const PROC_MOUNTSTATS: &str = "/proc/self/mountstats"; pub const PROC_CGROUPS: &str = "/proc/cgroups"; lazy_static! { diff --git a/vmm/task/src/netlink.rs b/vmm/task/src/netlink.rs index 70ad5240..31429ea5 100644 --- a/vmm/task/src/netlink.rs +++ b/vmm/task/src/netlink.rs @@ -47,9 +47,6 @@ impl fmt::Display for LinkFilter<'_> { pub enum AddressFilter { /// Return addresses that belong to the given interface. LinkIndex(u32), - /// Get addresses with the given prefix. - #[allow(dead_code)] - IpAddress(IpAddr), } /// A high level wrapper for netlink (and `rtnetlink` crate) for use by the Agent's RPC. @@ -204,7 +201,6 @@ impl Handle { if let Some(filter) = filter.into() { request = match filter { AddressFilter::LinkIndex(index) => request.set_link_index_filter(index), - AddressFilter::IpAddress(addr) => request.set_address_filter(addr), }; }; @@ -491,22 +487,6 @@ impl Link { .unwrap_or_default() } - /// Extract Mac address. - #[allow(dead_code)] - fn address(&self) -> String { - use packet::nlas::link::Nla; - self.nlas - .iter() - .find_map(|n| { - if let Nla::Address(data) = n { - format_address(data).ok() - } else { - None - } - }) - .unwrap_or_default() - } - /// Returns whether the link is UP fn is_up(&self) -> bool { self.header.flags & packet::rtnl::constants::IFF_UP > 0 @@ -515,18 +495,6 @@ impl Link { fn index(&self) -> u32 { self.header.index } - - #[allow(dead_code)] - fn mtu(&self) -> Option { - use packet::nlas::link::Nla; - self.nlas.iter().find_map(|n| { - if let Nla::Mtu(mtu) = n { - Some(*mtu as u64) - } else { - None - } - }) - } } impl From for Link { @@ -576,11 +544,6 @@ impl Address { self.0.header.family == packet::constants::AF_INET6 as u8 } - #[allow(dead_code)] - fn prefix(&self) -> u8 { - self.0.header.prefix_len - } - fn address(&self) -> String { use packet::nlas::address::Nla; self.0 diff --git a/vmm/task/src/sandbox.rs b/vmm/task/src/sandbox.rs index 8321a15b..1c8e0da9 100644 --- a/vmm/task/src/sandbox.rs +++ b/vmm/task/src/sandbox.rs @@ -135,6 +135,7 @@ impl SandboxResources { e, format!("timeout waiting for device with addr {} ready", addr) ))?; + self.device_monitor.unsubscribe(s.id).await; res.ok_or_else(|| other!("can not get device with addr {}", addr)) } } diff --git a/wasm/src/sandbox.rs b/wasm/src/sandbox.rs index ddc13742..84354869 100644 --- a/wasm/src/sandbox.rs +++ b/wasm/src/sandbox.rs @@ -134,7 +134,7 @@ impl WasmSandbox { async fn start(&mut self) -> Result<()> { let task = self.start_task_service().await?; let task_address = format!("unix://{}/task.sock", self.base_dir); - self.data.task_address = task_address.clone(); + self.data.task_address.clone_from(&task_address); let task_service = create_task(Arc::new(Box::new(task))); let mut server = Server::new().register_service(task_service); server = server @@ -155,7 +155,7 @@ impl WasmSandbox { ) -> Result> { let (tx, mut rx) = channel(128); let mut factory = WasmEdgeContainerFactory::default(); - factory.netns = self.data.netns.clone(); + factory.netns.clone_from(&self.data.netns); let task = TaskService { factory, containers: Arc::new(Default::default()), diff --git a/wasm/src/wasmedge.rs b/wasm/src/wasmedge.rs index 392a388b..1249a502 100644 --- a/wasm/src/wasmedge.rs +++ b/wasm/src/wasmedge.rs @@ -14,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -#![cfg(feature = "wasmedge")] - use std::{ fs::OpenOptions, os::unix::prelude::{IntoRawFd, RawFd},