881 lines
30 KiB
Diff
881 lines
30 KiB
Diff
From ed34a5a14129691ff62122405071192e7ce9180e Mon Sep 17 00:00:00 2001
|
|
From: Fei Xu <xufei30@huawei.com>
|
|
Date: Tue, 25 May 2021 09:13:30 +0800
|
|
Subject: [PATCH] StratoVirt: clear clippy warnings for updating rust 1.51.0
|
|
|
|
Signed-off-by: Fei Xu <xufei30@huawei.com>
|
|
---
|
|
address_space/src/region.rs | 1 +
|
|
boot_loader/src/lib.rs | 1 +
|
|
boot_loader/src/x86_64/mptable.rs | 2 +
|
|
cpu/src/aarch64/mod.rs | 34 ++++++++--------
|
|
cpu/src/lib.rs | 8 +++-
|
|
cpu/src/x86_64/mod.rs | 2 +
|
|
devices/src/interrupt_controller/mod.rs | 2 +
|
|
devices/src/legacy/pl031.rs | 3 +-
|
|
machine_manager/src/qmp/mod.rs | 27 ++++++-------
|
|
machine_manager/src/qmp/qmp_schema.rs | 52 +++++++++++++------------
|
|
machine_manager/src/socket.rs | 1 +
|
|
micro_vm/src/lib.rs | 22 ++++++-----
|
|
util/src/aio/libaio.rs | 14 +++----
|
|
util/src/aio/mod.rs | 8 ++--
|
|
util/src/arg_parser.rs | 20 +++++-----
|
|
util/src/device_tree.rs | 1 +
|
|
util/src/logger.rs | 6 +--
|
|
virtio/src/balloon.rs | 4 +-
|
|
virtio/src/block.rs | 11 +++---
|
|
virtio/src/net.rs | 2 +-
|
|
virtio/src/vhost/kernel/net.rs | 2 +-
|
|
virtio/src/vhost/kernel/vsock.rs | 3 +-
|
|
22 files changed, 119 insertions(+), 107 deletions(-)
|
|
|
|
diff --git a/address_space/src/region.rs b/address_space/src/region.rs
|
|
index 86f807c..235b195 100644
|
|
--- a/address_space/src/region.rs
|
|
+++ b/address_space/src/region.rs
|
|
@@ -18,6 +18,7 @@ use crate::errors::{ErrorKind, Result, ResultExt};
|
|
use crate::{AddressRange, AddressSpace, FileBackend, GuestAddress, HostMemMapping, RegionOps};
|
|
|
|
/// Types of Region.
|
|
+#[allow(clippy::upper_case_acronyms)]
|
|
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
|
pub enum RegionType {
|
|
/// Ram type.
|
|
diff --git a/boot_loader/src/lib.rs b/boot_loader/src/lib.rs
|
|
index 2687377..4be04be 100644
|
|
--- a/boot_loader/src/lib.rs
|
|
+++ b/boot_loader/src/lib.rs
|
|
@@ -78,6 +78,7 @@ extern crate log;
|
|
#[macro_use]
|
|
extern crate error_chain;
|
|
|
|
+#[allow(clippy::upper_case_acronyms)]
|
|
#[cfg(target_arch = "aarch64")]
|
|
mod aarch64;
|
|
#[cfg(target_arch = "x86_64")]
|
|
diff --git a/boot_loader/src/x86_64/mptable.rs b/boot_loader/src/x86_64/mptable.rs
|
|
index b8b7bf6..9d0d3f0 100644
|
|
--- a/boot_loader/src/x86_64/mptable.rs
|
|
+++ b/boot_loader/src/x86_64/mptable.rs
|
|
@@ -163,6 +163,7 @@ impl BusEntry {
|
|
}
|
|
|
|
#[repr(C)]
|
|
+#[allow(clippy::upper_case_acronyms)]
|
|
#[derive(Debug, Default, Copy, Clone)]
|
|
pub struct IOApicEntry {
|
|
type_: u8,
|
|
@@ -189,6 +190,7 @@ impl IOApicEntry {
|
|
}
|
|
|
|
#[repr(C)]
|
|
+#[allow(clippy::upper_case_acronyms)]
|
|
#[derive(Debug, Default, Copy, Clone)]
|
|
pub struct IOInterruptEntry {
|
|
type_: u8,
|
|
diff --git a/cpu/src/aarch64/mod.rs b/cpu/src/aarch64/mod.rs
|
|
index ef4c912..d717912 100644
|
|
--- a/cpu/src/aarch64/mod.rs
|
|
+++ b/cpu/src/aarch64/mod.rs
|
|
@@ -62,62 +62,62 @@ pub enum Arm64CoreRegs {
|
|
USER_FPSIMD_STATE_RES(usize),
|
|
}
|
|
|
|
-#[allow(clippy::zero_ptr)]
|
|
-impl Into<u64> for Arm64CoreRegs {
|
|
- fn into(self) -> u64 {
|
|
+impl From<Arm64CoreRegs> for u64 {
|
|
+ fn from(elem: Arm64CoreRegs) -> u64 {
|
|
let register_size;
|
|
- let regid = match self {
|
|
+ let regid;
|
|
+ match elem {
|
|
Arm64CoreRegs::KVM_USER_PT_REGS => {
|
|
register_size = KVM_REG_SIZE_U64;
|
|
- offset_of!(kvm_regs, regs)
|
|
+ regid = offset_of!(kvm_regs, regs)
|
|
}
|
|
Arm64CoreRegs::KVM_SP_EL1 => {
|
|
register_size = KVM_REG_SIZE_U64;
|
|
- offset_of!(kvm_regs, sp_el1)
|
|
+ regid = offset_of!(kvm_regs, sp_el1)
|
|
}
|
|
Arm64CoreRegs::KVM_ELR_EL1 => {
|
|
register_size = KVM_REG_SIZE_U64;
|
|
- offset_of!(kvm_regs, elr_el1)
|
|
+ regid = offset_of!(kvm_regs, elr_el1)
|
|
}
|
|
Arm64CoreRegs::KVM_SPSR(idx) if idx < KVM_NR_SPSR as usize => {
|
|
register_size = KVM_REG_SIZE_U64;
|
|
- offset_of!(kvm_regs, spsr) + idx * 8
|
|
+ regid = offset_of!(kvm_regs, spsr) + idx * 8
|
|
}
|
|
Arm64CoreRegs::KVM_USER_FPSIMD_STATE => {
|
|
register_size = KVM_REG_SIZE_U64;
|
|
- offset_of!(kvm_regs, fp_regs)
|
|
+ regid = offset_of!(kvm_regs, fp_regs)
|
|
}
|
|
Arm64CoreRegs::USER_PT_REG_REGS(idx) if idx < 31 => {
|
|
register_size = KVM_REG_SIZE_U64;
|
|
- offset_of!(kvm_regs, regs, user_pt_regs, regs) + idx * 8
|
|
+ regid = offset_of!(kvm_regs, regs, user_pt_regs, regs) + idx * 8
|
|
}
|
|
Arm64CoreRegs::USER_PT_REG_SP => {
|
|
register_size = KVM_REG_SIZE_U64;
|
|
- offset_of!(kvm_regs, regs, user_pt_regs, sp)
|
|
+ regid = offset_of!(kvm_regs, regs, user_pt_regs, sp)
|
|
}
|
|
Arm64CoreRegs::USER_PT_REG_PC => {
|
|
register_size = KVM_REG_SIZE_U64;
|
|
- offset_of!(kvm_regs, regs, user_pt_regs, pc)
|
|
+ regid = offset_of!(kvm_regs, regs, user_pt_regs, pc)
|
|
}
|
|
Arm64CoreRegs::USER_PT_REG_PSTATE => {
|
|
register_size = KVM_REG_SIZE_U64;
|
|
- offset_of!(kvm_regs, regs, user_pt_regs, pstate)
|
|
+ regid = offset_of!(kvm_regs, regs, user_pt_regs, pstate)
|
|
}
|
|
Arm64CoreRegs::USER_FPSIMD_STATE_VREGS(idx) if idx < 32 => {
|
|
register_size = KVM_REG_SIZE_U128;
|
|
- offset_of!(kvm_regs, fp_regs, user_fpsimd_state, vregs) + idx * 16
|
|
+ regid = offset_of!(kvm_regs, fp_regs, user_fpsimd_state, vregs) + idx * 16
|
|
}
|
|
Arm64CoreRegs::USER_FPSIMD_STATE_FPSR => {
|
|
register_size = KVM_REG_SIZE_U32;
|
|
- offset_of!(kvm_regs, fp_regs, user_fpsimd_state, fpsr)
|
|
+ regid = offset_of!(kvm_regs, fp_regs, user_fpsimd_state, fpsr)
|
|
}
|
|
Arm64CoreRegs::USER_FPSIMD_STATE_FPCR => {
|
|
register_size = KVM_REG_SIZE_U32;
|
|
- offset_of!(kvm_regs, fp_regs, user_fpsimd_state, fpcr)
|
|
+ regid = offset_of!(kvm_regs, fp_regs, user_fpsimd_state, fpcr)
|
|
}
|
|
Arm64CoreRegs::USER_FPSIMD_STATE_RES(idx) if idx < 2 => {
|
|
register_size = 128;
|
|
- offset_of!(kvm_regs, fp_regs, user_fpsimd_state, __reserved) + idx * 8
|
|
+ regid = offset_of!(kvm_regs, fp_regs, user_fpsimd_state, __reserved) + idx * 8
|
|
}
|
|
_ => panic!("No such Register"),
|
|
};
|
|
diff --git a/cpu/src/lib.rs b/cpu/src/lib.rs
|
|
index b32c709..eb489dc 100644
|
|
--- a/cpu/src/lib.rs
|
|
+++ b/cpu/src/lib.rs
|
|
@@ -37,6 +37,7 @@ extern crate machine_manager;
|
|
#[macro_use]
|
|
extern crate util;
|
|
|
|
+#[allow(clippy::upper_case_acronyms)]
|
|
#[cfg(target_arch = "aarch64")]
|
|
mod aarch64;
|
|
#[cfg(target_arch = "x86_64")]
|
|
@@ -164,6 +165,7 @@ thread_local! {
|
|
}
|
|
|
|
/// Trait to handle `CPU` lifetime.
|
|
+#[allow(clippy::upper_case_acronyms)]
|
|
pub trait CPUInterface {
|
|
/// Realize `CPU` structure, set registers value for `CPU`.
|
|
fn realize(&self, vm_fd: &Arc<VmFd>, boot: &CPUBootConfig) -> Result<()>;
|
|
@@ -198,6 +200,7 @@ pub trait CPUInterface {
|
|
}
|
|
|
|
/// `CPU` is a wrapper around creating and using a kvm-based VCPU.
|
|
+#[allow(clippy::upper_case_acronyms)]
|
|
pub struct CPU {
|
|
/// ID of this virtual CPU, `0` means this cpu is primary `CPU`.
|
|
id: u8,
|
|
@@ -417,11 +420,11 @@ impl CPUInterface for CPU {
|
|
}
|
|
|
|
if QmpChannel::is_connected() {
|
|
- let shutdown_msg = schema::SHUTDOWN {
|
|
+ let shutdown_msg = schema::Shutdown {
|
|
guest: true,
|
|
reason: "guest-shutdown".to_string(),
|
|
};
|
|
- event!(SHUTDOWN; shutdown_msg);
|
|
+ event!(Shutdown; shutdown_msg);
|
|
}
|
|
|
|
Ok(())
|
|
@@ -513,6 +516,7 @@ impl CPUInterface for CPU {
|
|
}
|
|
|
|
/// The struct to handle events in cpu thread.
|
|
+#[allow(clippy::upper_case_acronyms)]
|
|
struct CPUThreadWorker {
|
|
thread_cpu: Arc<CPU>,
|
|
}
|
|
diff --git a/cpu/src/x86_64/mod.rs b/cpu/src/x86_64/mod.rs
|
|
index 2880778..83635d4 100644
|
|
--- a/cpu/src/x86_64/mod.rs
|
|
+++ b/cpu/src/x86_64/mod.rs
|
|
@@ -42,6 +42,7 @@ const MSR_LIST: &[u32] = &[
|
|
const MSR_IA32_MISC_ENABLE: u32 = 0x01a0;
|
|
const MSR_IA32_MISC_ENABLE_FAST_STRING: u64 = 0x1;
|
|
|
|
+#[allow(clippy::upper_case_acronyms)]
|
|
#[derive(Default)]
|
|
/// X86 CPU booting configure information
|
|
pub struct X86CPUBootConfig {
|
|
@@ -61,6 +62,7 @@ pub struct X86CPUBootConfig {
|
|
pub pml4_start: u64,
|
|
}
|
|
|
|
+#[allow(clippy::upper_case_acronyms)]
|
|
#[derive(Default, Copy, Clone)]
|
|
pub struct X86CPU {
|
|
id: u32,
|
|
diff --git a/devices/src/interrupt_controller/mod.rs b/devices/src/interrupt_controller/mod.rs
|
|
index 2a00aa8..123c552 100644
|
|
--- a/devices/src/interrupt_controller/mod.rs
|
|
+++ b/devices/src/interrupt_controller/mod.rs
|
|
@@ -23,6 +23,8 @@
|
|
//! ## Platform Support
|
|
//!
|
|
//! - `aarch64`
|
|
+
|
|
+#[allow(clippy::upper_case_acronyms)]
|
|
#[cfg(target_arch = "aarch64")]
|
|
mod aarch64;
|
|
|
|
diff --git a/devices/src/legacy/pl031.rs b/devices/src/legacy/pl031.rs
|
|
index 9eefa2b..023c04a 100644
|
|
--- a/devices/src/legacy/pl031.rs
|
|
+++ b/devices/src/legacy/pl031.rs
|
|
@@ -51,6 +51,7 @@ const RTC_ICR: u64 = 0x1c;
|
|
const RTC_PERIPHERAL_ID: [u8; 8] = [0x31, 0x10, 0x14, 0x00, 0x0d, 0xf0, 0x05, 0xb1];
|
|
|
|
/// Pl031 structure.
|
|
+#[allow(clippy::upper_case_acronyms)]
|
|
pub struct PL031 {
|
|
/// Match register value.
|
|
mr: u32,
|
|
@@ -131,7 +132,7 @@ impl PL031 {
|
|
impl SysBusDevOps for PL031 {
|
|
/// Read data from registers by guest.
|
|
fn read(&mut self, data: &mut [u8], _base: GuestAddress, offset: u64) -> bool {
|
|
- if offset >= 0xFE0 && offset < 0x1000 {
|
|
+ if (0xFE0..0x1000).contains(&offset) {
|
|
let value = u32::from(RTC_PERIPHERAL_ID[((offset - 0xFE0) >> 2) as usize]);
|
|
match data.len() {
|
|
1 => data[0] = value as u8,
|
|
diff --git a/machine_manager/src/qmp/mod.rs b/machine_manager/src/qmp/mod.rs
|
|
index a680512..d86c3b4 100644
|
|
--- a/machine_manager/src/qmp/mod.rs
|
|
+++ b/machine_manager/src/qmp/mod.rs
|
|
@@ -70,9 +70,9 @@ static mut QMP_CHANNEL: Option<Arc<QmpChannel>> = None;
|
|
/// #[macro_use]
|
|
/// use machine_manager::qmp::*;
|
|
///
|
|
-/// event!(SHUTDOWN; shutdown_msg);
|
|
-/// event!(STOP);
|
|
-/// event!(RESUME);
|
|
+/// event!(Shutdown; shutdown_msg);
|
|
+/// event!(Stop);
|
|
+/// event!(Resume);
|
|
/// ```
|
|
#[macro_export]
|
|
macro_rules! event {
|
|
@@ -364,11 +364,11 @@ pub fn handle_qmp(
|
|
|
|
// handle shutdown command
|
|
if shutdown_flag {
|
|
- let shutdown_msg = schema::SHUTDOWN {
|
|
+ let shutdown_msg = schema::Shutdown {
|
|
guest: false,
|
|
reason: "host-qmp-quit".to_string(),
|
|
};
|
|
- event!(SHUTDOWN; shutdown_msg);
|
|
+ event!(Shutdown; shutdown_msg);
|
|
TempCleaner::clean();
|
|
|
|
std::io::stdin()
|
|
@@ -497,10 +497,7 @@ impl QmpChannel {
|
|
///
|
|
/// * `name` - Name of file descriptor.
|
|
pub fn get_fd(name: &str) -> Option<RawFd> {
|
|
- match Self::inner().fds.read().unwrap().get(name) {
|
|
- Some(fd) => Some(*fd),
|
|
- None => None,
|
|
- }
|
|
+ Self::inner().fds.read().unwrap().get(name).copied()
|
|
}
|
|
|
|
/// Send a `QmpEvent` to client.
|
|
@@ -603,7 +600,7 @@ mod tests {
|
|
r#"{"event":"STOP","data":{},"timestamp":{"seconds":1575531524,"microseconds":91519}}"#;
|
|
let qmp_event: schema::QmpEvent = serde_json::from_str(&event_json).unwrap();
|
|
match qmp_event {
|
|
- schema::QmpEvent::STOP {
|
|
+ schema::QmpEvent::Stop {
|
|
data: _,
|
|
timestamp: _,
|
|
} => {
|
|
@@ -646,12 +643,12 @@ mod tests {
|
|
QmpChannel::bind_writer(SocketRWHandler::new(socket.get_stream_fd()));
|
|
|
|
// 1.send no-content event
|
|
- event!(STOP);
|
|
+ event!(Stop);
|
|
let length = client.read(&mut buffer).unwrap();
|
|
let qmp_event: schema::QmpEvent =
|
|
serde_json::from_str(&(String::from_utf8_lossy(&buffer[..length]))).unwrap();
|
|
match qmp_event {
|
|
- schema::QmpEvent::STOP {
|
|
+ schema::QmpEvent::Stop {
|
|
data: _,
|
|
timestamp: _,
|
|
} => {
|
|
@@ -661,16 +658,16 @@ mod tests {
|
|
}
|
|
|
|
// 2.send with-content event
|
|
- let shutdown_event = schema::SHUTDOWN {
|
|
+ let shutdown_event = schema::Shutdown {
|
|
guest: true,
|
|
reason: "guest-shutdown".to_string(),
|
|
};
|
|
- event!(SHUTDOWN; shutdown_event);
|
|
+ event!(Shutdown; shutdown_event);
|
|
let length = client.read(&mut buffer).unwrap();
|
|
let qmp_event: schema::QmpEvent =
|
|
serde_json::from_str(&(String::from_utf8_lossy(&buffer[..length]))).unwrap();
|
|
match qmp_event {
|
|
- schema::QmpEvent::SHUTDOWN { data, timestamp: _ } => {
|
|
+ schema::QmpEvent::Shutdown { data, timestamp: _ } => {
|
|
assert_eq!(data.guest, true);
|
|
assert_eq!(data.reason, "guest-shutdown".to_string());
|
|
}
|
|
diff --git a/machine_manager/src/qmp/qmp_schema.rs b/machine_manager/src/qmp/qmp_schema.rs
|
|
index 340945e..c02ecbf 100644
|
|
--- a/machine_manager/src/qmp/qmp_schema.rs
|
|
+++ b/machine_manager/src/qmp/qmp_schema.rs
|
|
@@ -19,6 +19,7 @@ pub use serde_json::Value as Any;
|
|
use crate::qmp::{Command, Empty, Event, TimeStamp};
|
|
|
|
/// A error enum for qmp
|
|
+#[allow(clippy::upper_case_acronyms)]
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub enum QmpErrorClass {
|
|
#[serde(rename = "GenericError")]
|
|
@@ -538,6 +539,7 @@ impl Command for query_hotpluggable_cpus {
|
|
}
|
|
}
|
|
|
|
+#[allow(clippy::upper_case_acronyms)]
|
|
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
|
pub struct HotpluggableCPU {
|
|
#[serde(rename = "type")]
|
|
@@ -772,7 +774,7 @@ impl Command for getfd {
|
|
}
|
|
}
|
|
|
|
-/// SHUTDOWN
|
|
+/// Shutdown
|
|
///
|
|
/// Emitted when the virtual machine has shut down, indicating that StratoVirt is
|
|
/// about to exit.
|
|
@@ -783,7 +785,7 @@ impl Command for getfd {
|
|
/// will not exit, and a STOP event will eventually follow the SHUTDOWN event
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
#[serde(deny_unknown_fields)]
|
|
-pub struct SHUTDOWN {
|
|
+pub struct Shutdown {
|
|
/// If true, the shutdown was triggered by a guest request (such as
|
|
/// a guest-initiated ACPI shutdown request or other hardware-specific
|
|
/// action) rather than a host request (such as sending StratoVirt a SIGINT).
|
|
@@ -792,16 +794,16 @@ pub struct SHUTDOWN {
|
|
pub reason: String,
|
|
}
|
|
|
|
-impl Event for SHUTDOWN {
|
|
+impl Event for Shutdown {
|
|
const NAME: &'static str = "SHUTDOWN";
|
|
}
|
|
|
|
-/// RESET
|
|
+/// Reset
|
|
///
|
|
/// Emitted when the virtual machine is reset
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
#[serde(deny_unknown_fields)]
|
|
-pub struct RESET {
|
|
+pub struct Reset {
|
|
/// If true, the reset was triggered by a guest request (such as
|
|
/// a guest-initiated ACPI reboot request or other hardware-specific action
|
|
/// ) rather than a host request (such as the QMP command system_reset).
|
|
@@ -809,33 +811,33 @@ pub struct RESET {
|
|
pub guest: bool,
|
|
}
|
|
|
|
-impl Event for RESET {
|
|
+impl Event for Reset {
|
|
const NAME: &'static str = "RESET";
|
|
}
|
|
|
|
-/// STOP
|
|
+/// Stop
|
|
///
|
|
/// Emitted when the virtual machine is stopped
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
|
#[serde(deny_unknown_fields)]
|
|
-pub struct STOP {}
|
|
+pub struct Stop {}
|
|
|
|
-impl Event for STOP {
|
|
+impl Event for Stop {
|
|
const NAME: &'static str = "STOP";
|
|
}
|
|
|
|
-/// RESUME
|
|
+/// Resume
|
|
///
|
|
/// Emitted when the virtual machine resumes execution
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
|
#[serde(deny_unknown_fields)]
|
|
-pub struct RESUME {}
|
|
+pub struct Resume {}
|
|
|
|
-impl Event for RESUME {
|
|
+impl Event for Resume {
|
|
const NAME: &'static str = "RESUME";
|
|
}
|
|
|
|
-/// DEVICE_DELETED
|
|
+/// DeviceDeleted
|
|
///
|
|
/// Emitted whenever the device removal completion is acknowledged by the guest.
|
|
/// At this point, it's safe to reuse the specified device ID. Device removal can
|
|
@@ -851,7 +853,7 @@ impl Event for RESUME {
|
|
/// ```
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
#[serde(deny_unknown_fields)]
|
|
-pub struct DEVICE_DELETED {
|
|
+pub struct DeviceDeleted {
|
|
/// Device name.
|
|
#[serde(rename = "device", default, skip_serializing_if = "Option::is_none")]
|
|
pub device: Option<String>,
|
|
@@ -860,7 +862,7 @@ pub struct DEVICE_DELETED {
|
|
pub path: String,
|
|
}
|
|
|
|
-impl Event for DEVICE_DELETED {
|
|
+impl Event for DeviceDeleted {
|
|
const NAME: &'static str = "DEVICE_DELETED";
|
|
}
|
|
|
|
@@ -868,31 +870,31 @@ impl Event for DEVICE_DELETED {
|
|
#[serde(tag = "event")]
|
|
pub enum QmpEvent {
|
|
#[serde(rename = "SHUTDOWN")]
|
|
- SHUTDOWN {
|
|
- data: SHUTDOWN,
|
|
+ Shutdown {
|
|
+ data: Shutdown,
|
|
timestamp: TimeStamp,
|
|
},
|
|
#[serde(rename = "RESET")]
|
|
- RESET { data: RESET, timestamp: TimeStamp },
|
|
+ Reset { data: Reset, timestamp: TimeStamp },
|
|
#[serde(rename = "STOP")]
|
|
- STOP {
|
|
+ Stop {
|
|
#[serde(default)]
|
|
- data: STOP,
|
|
+ data: Stop,
|
|
timestamp: TimeStamp,
|
|
},
|
|
#[serde(rename = "RESUME")]
|
|
- RESUME {
|
|
+ Resume {
|
|
#[serde(default)]
|
|
- data: RESUME,
|
|
+ data: Resume,
|
|
timestamp: TimeStamp,
|
|
},
|
|
#[serde(rename = "DEVICE_DELETED")]
|
|
- DEVICE_DELETED {
|
|
- data: DEVICE_DELETED,
|
|
+ DeviceDeleted {
|
|
+ data: DeviceDeleted,
|
|
timestamp: TimeStamp,
|
|
},
|
|
#[serde(rename = "BALLOON_CHANGED")]
|
|
- BALLOON_CHANGED {
|
|
+ BalloonChanged {
|
|
data: BalloonInfo,
|
|
timestamp: TimeStamp,
|
|
},
|
|
diff --git a/machine_manager/src/socket.rs b/machine_manager/src/socket.rs
|
|
index 37dd176..d7b1205 100644
|
|
--- a/machine_manager/src/socket.rs
|
|
+++ b/machine_manager/src/socket.rs
|
|
@@ -330,6 +330,7 @@ impl SocketStream {
|
|
/// Ok(())
|
|
/// }
|
|
/// ```
|
|
+#[allow(clippy::upper_case_acronyms)]
|
|
pub struct SocketRWHandler {
|
|
/// Socket fd to read and write message
|
|
socket_fd: RawFd,
|
|
diff --git a/micro_vm/src/lib.rs b/micro_vm/src/lib.rs
|
|
index 6380e43..7188f21 100644
|
|
--- a/micro_vm/src/lib.rs
|
|
+++ b/micro_vm/src/lib.rs
|
|
@@ -270,16 +270,19 @@ impl LightMachine {
|
|
/// On x86_64, there is a gap ranged from (4G - 768M) to 4G, which will be skipped.
|
|
fn arch_ram_ranges(mem_size: u64) -> Vec<(u64, u64)> {
|
|
// ranges is the vector of (start_addr, size)
|
|
- let mut ranges = Vec::<(u64, u64)>::new();
|
|
+ #[allow(unused_mut)]
|
|
+ let mut ranges;
|
|
|
|
#[cfg(target_arch = "aarch64")]
|
|
- ranges.push((MEM_LAYOUT[LayoutEntryType::Mem as usize].0, mem_size));
|
|
-
|
|
+ {
|
|
+ let mem_start = MEM_LAYOUT[LayoutEntryType::Mem as usize].0;
|
|
+ ranges = vec![(mem_start, mem_size)];
|
|
+ }
|
|
#[cfg(target_arch = "x86_64")]
|
|
{
|
|
let gap_start = MEM_LAYOUT[LayoutEntryType::MemBelow4g as usize].0
|
|
+ MEM_LAYOUT[LayoutEntryType::MemBelow4g as usize].1;
|
|
- ranges.push((0, std::cmp::min(gap_start, mem_size)));
|
|
+ ranges = vec![(0, std::cmp::min(gap_start, mem_size))];
|
|
if mem_size > gap_start {
|
|
let gap_end = MEM_LAYOUT[LayoutEntryType::MemAbove4g as usize].0;
|
|
ranges.push((gap_end, mem_size - gap_start));
|
|
@@ -976,7 +979,7 @@ impl LightMachine {
|
|
impl MachineLifecycle for LightMachine {
|
|
fn pause(&self) -> bool {
|
|
if self.notify_lifecycle(KvmVmState::Running, KvmVmState::Paused) {
|
|
- event!(STOP);
|
|
+ event!(Stop);
|
|
|
|
true
|
|
} else {
|
|
@@ -989,7 +992,7 @@ impl MachineLifecycle for LightMachine {
|
|
return false;
|
|
}
|
|
|
|
- event!(RESUME);
|
|
+ event!(Resume);
|
|
|
|
true
|
|
}
|
|
@@ -1268,11 +1271,11 @@ impl DeviceInterface for LightMachine {
|
|
fn device_del(&self, device_id: String) -> Response {
|
|
match self.del_replaceable_device(&device_id) {
|
|
Ok(path) => {
|
|
- let block_del_event = qmp_schema::DEVICE_DELETED {
|
|
+ let block_del_event = qmp_schema::DeviceDeleted {
|
|
device: Some(device_id),
|
|
path,
|
|
};
|
|
- event!(DEVICE_DELETED; block_del_event);
|
|
+ event!(DeviceDeleted; block_del_event);
|
|
|
|
Response::create_empty_response()
|
|
}
|
|
@@ -1548,6 +1551,7 @@ fn generate_virtio_devices_node(fdt: &mut Vec<u8>, res: &SysRes) -> util::errors
|
|
}
|
|
|
|
/// Trait that helps to generate all nodes in device-tree.
|
|
+#[allow(clippy::upper_case_acronyms)]
|
|
#[cfg(target_arch = "aarch64")]
|
|
trait CompileFDTHelper {
|
|
/// Function that helps to generate cpu nodes.
|
|
@@ -1578,7 +1582,7 @@ impl CompileFDTHelper for LightMachine {
|
|
let clster = format!("/cpus/cpu-map/cluster{}", cluster);
|
|
device_tree::add_sub_node(fdt, &clster)?;
|
|
|
|
- for i in 0..2 as u32 {
|
|
+ for i in 0..2_u32 {
|
|
let sub_cluster = format!("{}/cluster{}", clster, i);
|
|
device_tree::add_sub_node(fdt, &sub_cluster)?;
|
|
|
|
diff --git a/util/src/aio/libaio.rs b/util/src/aio/libaio.rs
|
|
index b07a699..b7e4d33 100644
|
|
--- a/util/src/aio/libaio.rs
|
|
+++ b/util/src/aio/libaio.rs
|
|
@@ -43,13 +43,13 @@ pub struct IoCb {
|
|
#[allow(non_camel_case_types)]
|
|
#[derive(Copy, Clone)]
|
|
pub enum IoCmd {
|
|
- PREAD = 0,
|
|
- PWRITE = 1,
|
|
- FSYNC = 2,
|
|
- FDSYNC = 3,
|
|
- NOOP = 6,
|
|
- PREADV = 7,
|
|
- PWRITEV = 8,
|
|
+ Pread = 0,
|
|
+ Pwrite = 1,
|
|
+ Fsync = 2,
|
|
+ Fdsync = 3,
|
|
+ Noop = 6,
|
|
+ Preadv = 7,
|
|
+ Pwritev = 8,
|
|
}
|
|
|
|
#[repr(C)]
|
|
diff --git a/util/src/aio/mod.rs b/util/src/aio/mod.rs
|
|
index f0b0401..e5b5e01 100644
|
|
--- a/util/src/aio/mod.rs
|
|
+++ b/util/src/aio/mod.rs
|
|
@@ -46,7 +46,7 @@ impl<T: Clone> AioCb<T> {
|
|
AioCb {
|
|
last_aio: true,
|
|
file_fd: 0,
|
|
- opcode: IoCmd::NOOP,
|
|
+ opcode: IoCmd::Noop,
|
|
iovec: Vec::new(),
|
|
offset: 0,
|
|
process: false,
|
|
@@ -155,7 +155,7 @@ impl<T: Clone + 'static> Aio<T> {
|
|
|
|
pub fn rw_sync(&mut self, cb: AioCb<T>) -> Result<()> {
|
|
let ret = match cb.opcode {
|
|
- IoCmd::PREADV => {
|
|
+ IoCmd::Preadv => {
|
|
let mut r = 0;
|
|
let mut off = cb.offset;
|
|
for iov in cb.iovec.iter() {
|
|
@@ -164,7 +164,7 @@ impl<T: Clone + 'static> Aio<T> {
|
|
}
|
|
r
|
|
}
|
|
- IoCmd::PWRITEV => {
|
|
+ IoCmd::Pwritev => {
|
|
let mut r = 0;
|
|
let mut off = cb.offset;
|
|
for iov in cb.iovec.iter() {
|
|
@@ -173,7 +173,7 @@ impl<T: Clone + 'static> Aio<T> {
|
|
}
|
|
r
|
|
}
|
|
- IoCmd::FDSYNC => raw_datasync(cb.file_fd)?,
|
|
+ IoCmd::Fdsync => raw_datasync(cb.file_fd)?,
|
|
_ => -1,
|
|
};
|
|
(self.complete_func)(&cb, ret);
|
|
diff --git a/util/src/arg_parser.rs b/util/src/arg_parser.rs
|
|
index 9240a22..de051ae 100644
|
|
--- a/util/src/arg_parser.rs
|
|
+++ b/util/src/arg_parser.rs
|
|
@@ -34,11 +34,11 @@ type ArgsMap = BTreeMap<String, Vec<String>>;
|
|
#[derive(PartialEq, Debug)]
|
|
pub enum HelpType {
|
|
/// Argument as a Flag.
|
|
- FLAGS,
|
|
+ Flags,
|
|
/// Argument as a Option.
|
|
- OPTION,
|
|
+ Optional,
|
|
/// Argument will not output in help message.
|
|
- HIDDEN,
|
|
+ Hidden,
|
|
}
|
|
|
|
/// Structure to store `ArgParser` information, which contains a command line
|
|
@@ -222,13 +222,13 @@ impl<'a> ArgParser<'a> {
|
|
for arg in self.args.values() {
|
|
let (help_str, help_type) = (*arg).help_message();
|
|
match help_type {
|
|
- HelpType::FLAGS => {
|
|
+ HelpType::Flags => {
|
|
output_flags.push(help_str);
|
|
}
|
|
- HelpType::OPTION => {
|
|
+ HelpType::Optional => {
|
|
output_options.push(help_str);
|
|
}
|
|
- HelpType::HIDDEN => {}
|
|
+ HelpType::Hidden => {}
|
|
}
|
|
}
|
|
|
|
@@ -452,7 +452,7 @@ impl<'a> Arg<'a> {
|
|
/// Produce help message for argument.
|
|
fn help_message(&self) -> (String, HelpType) {
|
|
if self.hiddable {
|
|
- (String::new(), HelpType::HIDDEN)
|
|
+ (String::new(), HelpType::Hidden)
|
|
} else if self.short.is_some() {
|
|
let font_str = format!(
|
|
"{}{}{}, {}{}",
|
|
@@ -465,7 +465,7 @@ impl<'a> Arg<'a> {
|
|
let mut help_str = format!("{}{}", TWENTY_FOUT_BLANK, self.help.unwrap_or(""));
|
|
let font_offset = font_str.len();
|
|
help_str.replace_range(..font_offset, &font_str);
|
|
- (help_str, HelpType::FLAGS)
|
|
+ (help_str, HelpType::Flags)
|
|
} else {
|
|
let font_str = if self.values.is_some() {
|
|
format!(
|
|
@@ -497,7 +497,7 @@ impl<'a> Arg<'a> {
|
|
} else {
|
|
help_str.replace_range(..font_offset, &font_str);
|
|
}
|
|
- (help_str, HelpType::OPTION)
|
|
+ (help_str, HelpType::Optional)
|
|
}
|
|
}
|
|
|
|
@@ -766,7 +766,7 @@ mod tests {
|
|
assert_eq!(arg.value.as_ref().unwrap(), "vm1");
|
|
|
|
let (help_msg, help_type) = arg.help_message();
|
|
- assert_eq!(help_type, HelpType::FLAGS);
|
|
+ assert_eq!(help_type, HelpType::Flags);
|
|
assert_eq!(
|
|
help_msg,
|
|
format!(
|
|
diff --git a/util/src/device_tree.rs b/util/src/device_tree.rs
|
|
index 59f9642..120fd7c 100644
|
|
--- a/util/src/device_tree.rs
|
|
+++ b/util/src/device_tree.rs
|
|
@@ -209,6 +209,7 @@ pub fn dump_dtb(fdt: &[u8], file_path: &str) {
|
|
}
|
|
|
|
/// Trait for devices to be added to the Flattened Device Tree.
|
|
+#[allow(clippy::upper_case_acronyms)]
|
|
pub trait CompileFDT {
|
|
/// function to generate fdt node
|
|
///
|
|
diff --git a/util/src/logger.rs b/util/src/logger.rs
|
|
index 015c9ab..da155b4 100644
|
|
--- a/util/src/logger.rs
|
|
+++ b/util/src/logger.rs
|
|
@@ -89,11 +89,7 @@ pub fn init_vm_logger(
|
|
level: Option<Level>,
|
|
logfile: Option<Box<dyn Write + Send>>,
|
|
) -> Result<(), log::SetLoggerError> {
|
|
- let buffer = match logfile {
|
|
- Some(x) => Some(Mutex::new(x)),
|
|
- None => None,
|
|
- };
|
|
-
|
|
+ let buffer = logfile.map(Mutex::new);
|
|
let logger = VmLogger {
|
|
level: level.unwrap_or(Level::Info),
|
|
handler: buffer,
|
|
diff --git a/virtio/src/balloon.rs b/virtio/src/balloon.rs
|
|
index 167cbe0..86af9b1 100644
|
|
--- a/virtio/src/balloon.rs
|
|
+++ b/virtio/src/balloon.rs
|
|
@@ -511,7 +511,7 @@ impl BalloonIoHandler {
|
|
let msg = BalloonInfo {
|
|
actual: ram_size - balloon_size,
|
|
};
|
|
- event!(BALLOON_CHANGED; msg);
|
|
+ event!(BalloonChanged; msg);
|
|
}
|
|
|
|
/// Get the memory size of balloon.
|
|
@@ -687,7 +687,7 @@ impl Balloon {
|
|
let msg = BalloonInfo {
|
|
actual: self.get_guest_memory_size(),
|
|
};
|
|
- event!(BALLOON_CHANGED; msg);
|
|
+ event!(BalloonChanged; msg);
|
|
Ok(())
|
|
}
|
|
|
|
diff --git a/virtio/src/block.rs b/virtio/src/block.rs
|
|
index 70f50c6..4377fda 100644
|
|
--- a/virtio/src/block.rs
|
|
+++ b/virtio/src/block.rs
|
|
@@ -258,7 +258,7 @@ impl Request {
|
|
let mut aiocb = AioCb {
|
|
last_aio,
|
|
file_fd: disk.as_raw_fd(),
|
|
- opcode: IoCmd::NOOP,
|
|
+ opcode: IoCmd::Noop,
|
|
iovec: Vec::new(),
|
|
offset: (self.out_header.sector << SECTOR_SHIFT) as usize,
|
|
process: true,
|
|
@@ -276,7 +276,7 @@ impl Request {
|
|
|
|
match self.out_header.request_type {
|
|
VIRTIO_BLK_T_IN => {
|
|
- aiocb.opcode = IoCmd::PREADV;
|
|
+ aiocb.opcode = IoCmd::Preadv;
|
|
if direct {
|
|
(*aio).as_mut().rw_aio(aiocb).chain_err(|| {
|
|
"Failed to process block request for reading asynchronously"
|
|
@@ -288,7 +288,7 @@ impl Request {
|
|
}
|
|
}
|
|
VIRTIO_BLK_T_OUT => {
|
|
- aiocb.opcode = IoCmd::PWRITEV;
|
|
+ aiocb.opcode = IoCmd::Pwritev;
|
|
if direct {
|
|
(*aio).as_mut().rw_aio(aiocb).chain_err(|| {
|
|
"Failed to process block request for writing asynchronously"
|
|
@@ -300,7 +300,7 @@ impl Request {
|
|
}
|
|
}
|
|
VIRTIO_BLK_T_FLUSH => {
|
|
- aiocb.opcode = IoCmd::FDSYNC;
|
|
+ aiocb.opcode = IoCmd::Fdsync;
|
|
(*aio)
|
|
.as_mut()
|
|
.rw_sync(aiocb)
|
|
@@ -843,8 +843,7 @@ impl VirtioDevice for Block {
|
|
return Err(ErrorKind::DevConfigOverflow(offset, config_len as u64).into());
|
|
}
|
|
|
|
- self.config_space[(offset as usize)..(offset as usize + data_len)]
|
|
- .copy_from_slice(&data[..]);
|
|
+ self.config_space[(offset as usize)..(offset as usize + data_len)].copy_from_slice(data);
|
|
|
|
Ok(())
|
|
}
|
|
diff --git a/virtio/src/net.rs b/virtio/src/net.rs
|
|
index 41b68cd..43545f5 100644
|
|
--- a/virtio/src/net.rs
|
|
+++ b/virtio/src/net.rs
|
|
@@ -638,7 +638,7 @@ impl VirtioDevice for Net {
|
|
return Err(ErrorKind::DevConfigOverflow(offset, config_len as u64).into());
|
|
}
|
|
|
|
- config_slice[(offset as usize)..(offset as usize + data_len)].copy_from_slice(&data[..]);
|
|
+ config_slice[(offset as usize)..(offset as usize + data_len)].copy_from_slice(data);
|
|
|
|
Ok(())
|
|
}
|
|
diff --git a/virtio/src/vhost/kernel/net.rs b/virtio/src/vhost/kernel/net.rs
|
|
index 1251ede..45221b9 100644
|
|
--- a/virtio/src/vhost/kernel/net.rs
|
|
+++ b/virtio/src/vhost/kernel/net.rs
|
|
@@ -205,7 +205,7 @@ impl VirtioDevice for Net {
|
|
return Err(ErrorKind::DevConfigOverflow(offset, config_len as u64).into());
|
|
}
|
|
|
|
- config_slice[(offset as usize)..(offset as usize + data_len)].copy_from_slice(&data[..]);
|
|
+ config_slice[(offset as usize)..(offset as usize + data_len)].copy_from_slice(data);
|
|
|
|
Ok(())
|
|
}
|
|
diff --git a/virtio/src/vhost/kernel/vsock.rs b/virtio/src/vhost/kernel/vsock.rs
|
|
index c464149..979670f 100644
|
|
--- a/virtio/src/vhost/kernel/vsock.rs
|
|
+++ b/virtio/src/vhost/kernel/vsock.rs
|
|
@@ -162,8 +162,7 @@ impl VirtioDevice for Vsock {
|
|
return Err(ErrorKind::DevConfigOverflow(offset, config_len as u64).into());
|
|
}
|
|
|
|
- self.config_space[(offset as usize)..(offset as usize + data_len)]
|
|
- .copy_from_slice(&data[..]);
|
|
+ self.config_space[(offset as usize)..(offset as usize + data_len)].copy_from_slice(data);
|
|
|
|
Ok(())
|
|
}
|
|
--
|
|
2.25.1
|
|
|