Skip to content

Commit

Permalink
Fix checks
Browse files Browse the repository at this point in the history
Signed-off-by: Zhang Tianyang <burning9699@gmail.com>
  • Loading branch information
Burning1020 committed Jul 22, 2024
1 parent f074b47 commit 9f15376
Show file tree
Hide file tree
Showing 50 changed files with 162 additions and 377 deletions.
15 changes: 4 additions & 11 deletions runc/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ use runc::{
pub const INIT_PID_FILE: &str = "init.pid";

pub struct ProcessIO {
pub uri: Option<String>,
pub io: Option<Arc<dyn Io>>,
pub copy: bool,
}
Expand All @@ -56,28 +55,22 @@ 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,
};
return Ok(pio);
}
let stdout = stdio.stdout.as_str();
let scheme_path = stdout.trim().split("://").collect::<Vec<&str>>();
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,
};
Expand Down
2 changes: 1 addition & 1 deletion runc/src/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions shim/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<TaskClient> {
Expand Down
2 changes: 1 addition & 1 deletion shim/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
2 changes: 0 additions & 2 deletions vmm/sandbox/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion vmm/sandbox/src/cloud_hypervisor/devices/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion vmm/sandbox/src/cloud_hypervisor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
37 changes: 0 additions & 37 deletions vmm/sandbox/src/container/handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,40 +40,6 @@ mod process;
mod spec;
mod storage;

pub struct HandlerNode<S> {
pub handler: Box<dyn Handler<S> + Sync + Send>,
pub next: Option<NonNull<HandlerNode<S>>>,
pub prev: Option<NonNull<HandlerNode<S>>>,
}

unsafe impl<S> Sync for HandlerNode<S> {}

unsafe impl<S> Send for HandlerNode<S> {}

impl<S> HandlerNode<S>
where
S: Sync + Send,
{
#[allow(dead_code)]
pub fn new(handler: Box<dyn Handler<S> + 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<S> {
handlers: Vec<Box<dyn Handler<S> + Sync + Send>>,
}
Expand Down Expand Up @@ -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| {
Expand Down
2 changes: 1 addition & 1 deletion vmm/sandbox/src/container/handler/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions vmm/sandbox/src/container/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
Expand Down
6 changes: 0 additions & 6 deletions vmm/sandbox/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -99,7 +96,6 @@ impl Bus {
None
}

#[allow(dead_code)]
pub fn attach<T: Device>(&mut self, device: &T) -> Result<usize> {
for (index, s) in self.slots.iter_mut().enumerate() {
if let SlotStatus::Empty = s.status {
Expand All @@ -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<usize> {
for (index, s) in self.slots.iter().enumerate() {
if index == 0 {
Expand Down Expand Up @@ -150,7 +145,6 @@ pub enum SlotStatus {
pub enum Transport {
Pci,
Ccw,
#[allow(dead_code)]
Mmio,
}

Expand Down
3 changes: 2 additions & 1 deletion vmm/sandbox/src/kata_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 4 additions & 10 deletions vmm/sandbox/src/network/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>);
Expand All @@ -131,19 +131,13 @@ impl From<MacAddress> 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(":"))
}
}

Expand Down
14 changes: 6 additions & 8 deletions vmm/sandbox/src/network/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.

use std::{
ffi::CStr,
fmt::{Display, Formatter},
os::unix::{
fs::OpenOptionsExt,
prelude::{AsRawFd, OwnedFd},
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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(),
Expand All @@ -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)
}
}

Expand Down
19 changes: 10 additions & 9 deletions vmm/sandbox/src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}
}

Expand Down
3 changes: 0 additions & 3 deletions vmm/sandbox/src/network/netlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -65,7 +63,6 @@ impl QDiscAddRequest {
}
}

#[allow(dead_code)]
pub struct TrafficFilterSetRequest {
handle: Handle,
message: TcMessage,
Expand Down
Loading

0 comments on commit 9f15376

Please sign in to comment.