diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a24d8916..5f0104fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: include: - directories: wasm features: --features=wasmedge - wasmEdge: 0.11.2 + wasmEdge: 0.13.5 - directories: wasm features: --features=wasmtime runs-on: ubuntu-latest @@ -54,7 +54,7 @@ jobs: include: - directories: wasm features: --features=wasmedge - wasmEdge: 0.11.2 + wasmEdge: 0.13.5 - directories: wasm features: --features=wasmtime runs-on: ubuntu-latest diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 8d32f39e..979d1134 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -79,7 +79,7 @@ jobs: features: ["wasmedge"] include: - features: wasmedge - version: 0.11.2 + version: 0.13.5 runs-on: ubuntu-22.04 timeout-minutes: 10 steps: diff --git a/README.md b/README.md index 62be0408..126c41a8 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ Please also note that Quark requires a Linux kernel version >= 5.15. + It is recommended to install Cloud Hypervisor by default. You can find Cloud Hypervisor installation instructions [here](https://github.com/cloud-hypervisor/cloud-hypervisor/blob/main/docs/building.md). + If you want to run kuasar with iSulad container engine and StratoVirt hypervisor, you can refer to this guide [how-to-run-kuasar-with-isulad-and-stratovirt](docs/vmm/how-to-run-kuasar-with-isulad-and-stratovirt.md). + Quark: To use Quark, please refer to the installation instructions [here](docs/quark/README.md). -+ WasmEdge: To start WebAssembly sandboxes, you need to install WasmEdge v0.11.2. Instructions for installing WasmEdge can be found in [install.html](https://wasmedge.org/book/en/quick_start/install.html). ++ WasmEdge: To start WebAssembly sandboxes, you need to install WasmEdge v0.13.5. Instructions for installing WasmEdge can be found in [install.html](https://wasmedge.org/book/en/quick_start/install.html). ### 3. containerd 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/Cargo.lock b/wasm/Cargo.lock index 3bb265fb..5281c1e9 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -8,9 +8,24 @@ version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" dependencies = [ - "gimli", + "gimli 0.27.3", ] +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli 0.28.1", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "ahash" version = "0.8.3" @@ -138,6 +153,21 @@ dependencies = [ "tower-service", ] +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line 0.21.0", + "cc", + "cfg-if 1.0.0", + "libc", + "miniz_oxide", + "object 0.32.2", + "rustc-demangle", +] + [[package]] name = "base64" version = "0.13.1" @@ -161,22 +191,22 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.61.0" +version = "0.69.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a022e58a142a46fea340d68012b9201c094e93ec3d033a944a24f8fd4a4f09a" +checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.3.3", "cexpr", "clang-sys", + "itertools", "lazy_static", "lazycell", - "peeking_take_while", "proc-macro2", "quote", "regex", "rustc-hash", "shlex", - "syn 1.0.109", + "syn 2.0.13", ] [[package]] @@ -293,11 +323,12 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.79" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f" dependencies = [ "jobserver", + "libc", ] [[package]] @@ -446,6 +477,22 @@ dependencies = [ "ttrpc-codegen", ] +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + [[package]] name = "cpp_demangle" version = "0.3.5" @@ -485,7 +532,7 @@ dependencies = [ "cranelift-codegen-shared", "cranelift-entity", "cranelift-isle", - "gimli", + "gimli 0.27.3", "hashbrown 0.13.2", "log", "regalloc2", @@ -758,6 +805,15 @@ version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "env_logger" version = "0.9.3" @@ -841,6 +897,18 @@ dependencies = [ "log", ] +[[package]] +name = "filetime" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "redox_syscall 0.4.1", + "windows-sys 0.52.0", +] + [[package]] name = "fixedbitset" version = "0.2.0" @@ -853,6 +921,16 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" +[[package]] +name = "flate2" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + [[package]] name = "fnv" version = "1.0.7" @@ -1032,6 +1110,12 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + [[package]] name = "glob" version = "0.3.1" @@ -1120,6 +1204,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + [[package]] name = "http" version = "0.2.9" @@ -1190,6 +1280,20 @@ dependencies = [ "want", ] +[[package]] +name = "hyper-rustls" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" +dependencies = [ + "futures-util", + "http", + "hyper", + "rustls", + "tokio", + "tokio-rustls", +] + [[package]] name = "hyper-timeout" version = "0.4.1" @@ -1344,13 +1448,22 @@ dependencies = [ [[package]] name = "jobserver" -version = "0.1.26" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +checksum = "d2b099aaa34a9751c5bf0878add70444e1ed2dd73f347be99003d4577277de6e" dependencies = [ "libc", ] +[[package]] +name = "js-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -1506,6 +1619,15 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + [[package]] name = "mio" version = "0.8.6" @@ -1641,6 +1763,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + [[package]] name = "oci-spec" version = "0.5.8" @@ -1699,12 +1830,6 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" -[[package]] -name = "peeking_take_while" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" - [[package]] name = "percent-encoding" version = "2.2.0" @@ -1731,6 +1856,48 @@ dependencies = [ "indexmap", ] +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro2", + "quote", + "syn 2.0.13", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + [[package]] name = "pin-project" version = "1.0.12" @@ -2099,6 +2266,15 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "redox_users" version = "0.4.3" @@ -2139,6 +2315,61 @@ version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" +[[package]] +name = "reqwest" +version = "0.11.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" +dependencies = [ + "base64 0.21.2", + "bytes 1.4.0", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-rustls", + "ipnet", + "js-sys", + "log", + "mime", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-rustls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", + "winreg", +] + +[[package]] +name = "ring" +version = "0.17.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9babe80d5c16becf6594aa32ad2be8fe08498e7ae60b77de8df700e67f191d7e" +dependencies = [ + "cc", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.48.0", +] + [[package]] name = "rustc-demangle" version = "0.1.23" @@ -2194,18 +2425,65 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "rustls" +version = "0.21.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" +dependencies = [ + "log", + "ring", + "rustls-webpki", + "sct", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +dependencies = [ + "base64 0.21.2", +] + +[[package]] +name = "rustls-webpki" +version = "0.101.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "ryu" version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "sct" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "serde" version = "1.0.159" @@ -2237,6 +2515,27 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "setjmp" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57a4a1d465f5de0833aed8a7c76b1c01606bc8160c5a7d2c0108867dfffdfef3" +dependencies = [ + "libc", +] + [[package]] name = "sha2" version = "0.10.7" @@ -2248,6 +2547,19 @@ dependencies = [ "digest", ] +[[package]] +name = "sha256" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18278f6a914fa3070aa316493f7d2ddfb9ac86ebc06fa3b83bffda487e9065b0" +dependencies = [ + "async-trait", + "bytes 1.4.0", + "hex", + "sha2", + "tokio", +] + [[package]] name = "shellexpand" version = "2.1.2" @@ -2294,6 +2606,12 @@ dependencies = [ "tokio", ] +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + [[package]] name = "slab" version = "0.4.8" @@ -2325,6 +2643,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -2371,6 +2695,27 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "system-interface" version = "0.25.8" @@ -2387,6 +2732,17 @@ dependencies = [ "winx", ] +[[package]] +name = "tar" +version = "0.4.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b16afcea1f22891c49a00c751c7b63b2233284064f11a200fc624137c51e2ddb" +dependencies = [ + "filetime", + "libc", + "xattr", +] + [[package]] name = "target-lexicon" version = "0.12.8" @@ -2478,11 +2834,12 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.27.0" +version = "1.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001" +checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da" dependencies = [ "autocfg", + "backtrace", "bytes 1.4.0", "libc", "mio", @@ -2492,7 +2849,7 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -2507,15 +2864,25 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", "syn 2.0.13", ] +[[package]] +name = "tokio-rustls" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" +dependencies = [ + "rustls", + "tokio", +] + [[package]] name = "tokio-stream" version = "0.1.12" @@ -2808,6 +3175,12 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "url" version = "2.3.1" @@ -2921,6 +3294,72 @@ dependencies = [ "wiggle", ] +[[package]] +name = "wasm-bindgen" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.13", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.13", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" + [[package]] name = "wasm-encoder" version = "0.25.0" @@ -2956,44 +3395,52 @@ dependencies = [ [[package]] name = "wasmedge-macro" -version = "0.3.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f159a9a7d3d2301de2fc9cb88ad3459af9e95cbd5a0f57437efccc2b572a027" +checksum = "dbe80d95a88e9ac87b6aaf7bc9acd1fdfcd92045db2bf41a2262f623e2406a92" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.13", ] [[package]] name = "wasmedge-sdk" -version = "0.7.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6b7678a024c25fbe7168dedbca6958b6baf5412a998c697bf40dbf359efc54e" +checksum = "2f477f3b515760c6f7fa734dae5b97c030ee443969f1c30ed12d3a09bea783a2" dependencies = [ "anyhow", + "cfg-if 1.0.0", "num-derive", "num-traits", "thiserror", "wasmedge-macro", "wasmedge-sys", "wasmedge-types", - "wat", ] [[package]] name = "wasmedge-sys" -version = "0.12.2" +version = "0.17.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00ab1f78c1d3de17fd0deff054de96e337cf8cf02d13651748bdfa1f1b219369" +checksum = "32d8e2276d63bb6f0c36871218643d193d2da6da3db36c1c1227547da465ed58" dependencies = [ "bindgen", + "cfg-if 1.0.0", "cmake", + "flate2", "lazy_static", "libc", "parking_lot", "paste", + "phf", "rand", + "reqwest", + "scoped-tls", + "setjmp", + "sha256", + "tar", "thiserror", "wasmedge-macro", "wasmedge-types", @@ -3002,9 +3449,9 @@ dependencies = [ [[package]] name = "wasmedge-types" -version = "0.3.1" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3323fe75a4e65476b33a041092aac22a1065a7ba0bfecbedc8135e8efb6c522d" +checksum = "2d4e7c8aebe2c513bb389beebc148253eb6f5904a6f9327179bbf2014c0efd52" dependencies = [ "thiserror", "wat", @@ -3033,7 +3480,7 @@ dependencies = [ "indexmap", "libc", "log", - "object", + "object 0.30.4", "once_cell", "paste", "psm", @@ -3114,9 +3561,9 @@ dependencies = [ "cranelift-frontend", "cranelift-native", "cranelift-wasm", - "gimli", + "gimli 0.27.3", "log", - "object", + "object 0.30.4", "target-lexicon", "thiserror", "wasmparser", @@ -3133,8 +3580,8 @@ dependencies = [ "anyhow", "cranelift-codegen", "cranelift-native", - "gimli", - "object", + "gimli 0.27.3", + "object 0.30.4", "target-lexicon", "wasmtime-environ", ] @@ -3147,10 +3594,10 @@ checksum = "a990198cee4197423045235bf89d3359e69bd2ea031005f4c2d901125955c949" dependencies = [ "anyhow", "cranelift-entity", - "gimli", + "gimli 0.27.3", "indexmap", "log", - "object", + "object 0.30.4", "serde", "target-lexicon", "thiserror", @@ -3177,15 +3624,15 @@ version = "8.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0de48df552cfca1c9b750002d3e07b45772dd033b0b206d5c0968496abf31244" dependencies = [ - "addr2line", + "addr2line 0.19.0", "anyhow", "bincode", "cfg-if 1.0.0", "cpp_demangle", - "gimli", + "gimli 0.27.3", "ittapi", "log", - "object", + "object 0.30.4", "rustc-demangle", "serde", "target-lexicon", @@ -3202,7 +3649,7 @@ version = "8.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e0554b84c15a27d76281d06838aed94e13a77d7bf604bbbaf548aa20eb93846" dependencies = [ - "object", + "object 0.30.4", "once_cell", "rustix 0.36.14", ] @@ -3310,6 +3757,22 @@ dependencies = [ "wast 55.0.0", ] +[[package]] +name = "web-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "0.25.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" + [[package]] name = "which" version = "4.4.0" @@ -3412,6 +3875,15 @@ dependencies = [ "windows-targets 0.48.1", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-targets" version = "0.42.2" @@ -3442,6 +3914,22 @@ dependencies = [ "windows_x86_64_msvc 0.48.0", ] +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.42.2" @@ -3454,6 +3942,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + [[package]] name = "windows_aarch64_msvc" version = "0.42.2" @@ -3466,6 +3960,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + [[package]] name = "windows_i686_gnu" version = "0.42.2" @@ -3478,6 +3978,18 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + [[package]] name = "windows_i686_msvc" version = "0.42.2" @@ -3490,6 +4002,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + [[package]] name = "windows_x86_64_gnu" version = "0.42.2" @@ -3502,6 +4020,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" @@ -3514,6 +4038,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + [[package]] name = "windows_x86_64_msvc" version = "0.42.2" @@ -3526,6 +4056,22 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winreg" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +dependencies = [ + "cfg-if 1.0.0", + "windows-sys 0.48.0", +] + [[package]] name = "winx" version = "0.36.1" @@ -3563,6 +4109,15 @@ dependencies = [ "wast 35.0.2", ] +[[package]] +name = "xattr" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbc6ab6ec1907d1a901cdbcd2bd4cb9e7d64ce5c9739cbb97d3c391acd8c7fae" +dependencies = [ + "libc", +] + [[package]] name = "zstd" version = "0.11.2+zstd.1.5.2" diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index 9ed6c230..6842506d 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -24,7 +24,7 @@ log = { version = "0.4.17", features = ["std"] } time = "0.3.5" cgroups-rs = "0.3.2" -wasmedge-sdk = { version = "0.7.1", optional = true } +wasmedge-sdk = { version = "0.13.2", optional = true } cap-std = { version = "1.0.14", optional = true } wasi-cap-std-sync = { version = "8.0.1", optional = true } 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 cff8911f..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}, @@ -53,7 +51,10 @@ use oci_spec::runtime::Spec; use wasmedge_sdk::{ config::{CommonConfigOptions, ConfigBuilder, HostRegistrationConfigOptions}, error::WasmEdgeError, - params, PluginManager, Vm, + params, + plugin::PluginManager, + wasi::WasiInstance, + Vm, VmBuilder, }; use crate::utils::{get_args, get_cgroup_path, get_envs, get_preopens, get_rootfs}; @@ -83,7 +84,7 @@ pub struct WasmEdgeContainerFactory { impl Default for WasmEdgeContainerFactory { fn default() -> Self { - PluginManager::load_from_default_paths(); + PluginManager::load(None).unwrap(); let mut host_options = HostRegistrationConfigOptions::default(); host_options = host_options.wasi(true); #[cfg(all( @@ -98,7 +99,11 @@ impl Default for WasmEdgeContainerFactory { .with_host_registration_config(host_options) .build() .unwrap(); - let vm = Vm::new(Some(config)).map_err(anyhow::Error::msg).unwrap(); + let vm = VmBuilder::new() + .with_config(config) + .build() + .map_err(anyhow::Error::msg) + .unwrap(); Self { prototype_vm: vm, netns: "".to_string(), @@ -341,15 +346,17 @@ pub enum RunError { WasmEdge(Box), IO(std::io::Error), NoRootInSpec, + NoModule, Sys(Errno), } impl RunError { pub fn to_exit_code(&self) -> i32 { match &self { - RunError::WasmEdge(_) => -100, - RunError::IO(_) => -101, + RunError::WasmEdge(_e) => -100, + RunError::IO(_e) => -101, RunError::NoRootInSpec => -102, + RunError::NoModule => -103, RunError::Sys(e) => -(*e as i32), } } @@ -368,7 +375,7 @@ fn run_wasi_func( nix::fcntl::open(netns, OFlag::O_CLOEXEC, Mode::empty()).map_err(RunError::Sys)?; setns(netns_fd, CloneFlags::CLONE_NEWNET).map_err(RunError::Sys)?; } - let mut wasi_instance = vm.wasi_module().map_err(RunError::WasmEdge)?; + let wasi_instance: &mut WasiInstance = vm.wasi_module_mut().ok_or(RunError::NoModule)?; wasi_instance.initialize( Some(args.iter().map(|s| s as &str).collect()), Some(envs.iter().map(|s| s as &str).collect()),