mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 13:45:20 +00:00
misc: Fix various clippy issues
Signed-off-by: Bo Chen <chen.bo@intel.com> Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
parent
3d3693699b
commit
b665aa19f4
@ -1083,7 +1083,7 @@ impl<'a, T> CreateField<'a, T> {
|
||||
buffer,
|
||||
offset,
|
||||
field,
|
||||
phantom: PhantomData::default(),
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ impl QcowRawFile {
|
||||
non_zero_flags: u64,
|
||||
) -> io::Result<()> {
|
||||
self.file.seek(SeekFrom::Start(offset))?;
|
||||
let mut buffer = BufWriter::with_capacity(table.len() * size_of::<u64>(), &mut self.file);
|
||||
let mut buffer = BufWriter::with_capacity(std::mem::size_of_val(table), &mut self.file);
|
||||
for addr in table {
|
||||
let val = if *addr == 0 {
|
||||
0
|
||||
@ -91,7 +91,7 @@ impl QcowRawFile {
|
||||
/// Writes a refcount block to the file.
|
||||
pub fn write_refcount_block(&mut self, offset: u64, table: &[u16]) -> io::Result<()> {
|
||||
self.file.seek(SeekFrom::Start(offset))?;
|
||||
let mut buffer = BufWriter::with_capacity(table.len() * size_of::<u16>(), &mut self.file);
|
||||
let mut buffer = BufWriter::with_capacity(std::mem::size_of_val(table), &mut self.file);
|
||||
for count in table {
|
||||
buffer.write_u16::<BigEndian>(*count)?;
|
||||
}
|
||||
|
26
src/main.rs
26
src/main.rs
@ -730,7 +730,7 @@ mod unit_tests {
|
||||
|
||||
#[test]
|
||||
fn test_valid_vm_config_cpus() {
|
||||
vec![
|
||||
[
|
||||
(
|
||||
vec![
|
||||
"cloud-hypervisor",
|
||||
@ -848,7 +848,7 @@ mod unit_tests {
|
||||
|
||||
#[test]
|
||||
fn test_valid_vm_config_kernel() {
|
||||
vec![(
|
||||
[(
|
||||
vec!["cloud-hypervisor", "--kernel", "/path/to/kernel"],
|
||||
r#"{
|
||||
"payload": {"kernel": "/path/to/kernel"}
|
||||
@ -863,7 +863,7 @@ mod unit_tests {
|
||||
|
||||
#[test]
|
||||
fn test_valid_vm_config_cmdline() {
|
||||
vec![(
|
||||
[(
|
||||
vec![
|
||||
"cloud-hypervisor",
|
||||
"--kernel",
|
||||
@ -884,7 +884,7 @@ mod unit_tests {
|
||||
|
||||
#[test]
|
||||
fn test_valid_vm_config_disks() {
|
||||
vec![
|
||||
[
|
||||
(
|
||||
vec![
|
||||
"cloud-hypervisor",
|
||||
@ -1156,7 +1156,7 @@ mod unit_tests {
|
||||
|
||||
#[test]
|
||||
fn test_valid_vm_config_rng() {
|
||||
vec![(
|
||||
[(
|
||||
vec![
|
||||
"cloud-hypervisor",
|
||||
"--kernel",
|
||||
@ -1178,8 +1178,7 @@ mod unit_tests {
|
||||
|
||||
#[test]
|
||||
fn test_valid_vm_config_fs() {
|
||||
vec![
|
||||
(
|
||||
[(
|
||||
vec![
|
||||
"cloud-hypervisor", "--kernel", "/path/to/kernel",
|
||||
"--memory", "shared=true",
|
||||
@ -1247,8 +1246,7 @@ mod unit_tests {
|
||||
]
|
||||
}"#,
|
||||
true,
|
||||
),
|
||||
]
|
||||
)]
|
||||
.iter()
|
||||
.for_each(|(cli, openapi, equal)| {
|
||||
compare_vm_config_cli_vs_json(cli, openapi, *equal);
|
||||
@ -1257,7 +1255,7 @@ mod unit_tests {
|
||||
|
||||
#[test]
|
||||
fn test_valid_vm_config_pmem() {
|
||||
vec![
|
||||
[
|
||||
(
|
||||
vec![
|
||||
"cloud-hypervisor",
|
||||
@ -1320,7 +1318,7 @@ mod unit_tests {
|
||||
|
||||
#[test]
|
||||
fn test_valid_vm_config_serial_console() {
|
||||
vec![
|
||||
[
|
||||
(
|
||||
vec!["cloud-hypervisor", "--kernel", "/path/to/kernel"],
|
||||
r#"{
|
||||
@ -1371,7 +1369,7 @@ mod unit_tests {
|
||||
|
||||
#[test]
|
||||
fn test_valid_vm_config_serial_pty_console_pty() {
|
||||
vec![
|
||||
[
|
||||
(
|
||||
vec!["cloud-hypervisor", "--kernel", "/path/to/kernel"],
|
||||
r#"{
|
||||
@ -1517,7 +1515,7 @@ mod unit_tests {
|
||||
|
||||
#[test]
|
||||
fn test_valid_vm_config_vdpa() {
|
||||
vec![
|
||||
[
|
||||
(
|
||||
vec![
|
||||
"cloud-hypervisor",
|
||||
@ -1645,7 +1643,7 @@ mod unit_tests {
|
||||
|
||||
#[test]
|
||||
fn test_valid_vm_config_tpm_socket() {
|
||||
vec![(
|
||||
[(
|
||||
vec![
|
||||
"cloud-hypervisor",
|
||||
"--kernel",
|
||||
|
@ -106,7 +106,7 @@ impl GuestNetworkConfig {
|
||||
epoll::Event::new(epoll::Events::EPOLLIN, 0),
|
||||
)
|
||||
.expect("Cannot add 'tcp_listener' event to epoll");
|
||||
let mut events = vec![epoll::Event::new(epoll::Events::empty(), 0); 1];
|
||||
let mut events = [epoll::Event::new(epoll::Events::empty(), 0); 1];
|
||||
loop {
|
||||
let num_events = match epoll::wait(epoll_fd, timeout * 1000_i32, &mut events[..]) {
|
||||
Ok(num_events) => Ok(num_events),
|
||||
@ -251,7 +251,7 @@ impl DiskConfig for UbuntuDiskConfig {
|
||||
.join("cloud-init")
|
||||
.join("ubuntu");
|
||||
|
||||
vec!["meta-data"].iter().for_each(|x| {
|
||||
["meta-data"].iter().for_each(|x| {
|
||||
rate_limited_copy(source_file_dir.join(x), cloud_init_directory.join(x))
|
||||
.expect("Expect copying cloud-init meta-data to succeed");
|
||||
});
|
||||
@ -307,7 +307,7 @@ impl DiskConfig for UbuntuDiskConfig {
|
||||
.output()
|
||||
.expect("Expect creating disk image to succeed");
|
||||
|
||||
vec!["user-data", "meta-data", "network-config"]
|
||||
["user-data", "meta-data", "network-config"]
|
||||
.iter()
|
||||
.for_each(|x| {
|
||||
std::process::Command::new("mcopy")
|
||||
|
@ -277,11 +277,7 @@ impl Emulator {
|
||||
}
|
||||
|
||||
self.established_flag_cached = true;
|
||||
if est.resp.bit != 0 {
|
||||
self.established_flag = false;
|
||||
} else {
|
||||
self.established_flag = true;
|
||||
}
|
||||
self.established_flag = est.resp.bit == 0;
|
||||
|
||||
self.established_flag
|
||||
}
|
||||
|
@ -321,11 +321,8 @@ impl Client {
|
||||
|
||||
debug!("Reply: {:?}", server_version);
|
||||
|
||||
let mut server_version_data = Vec::new();
|
||||
server_version_data.resize(
|
||||
server_version.header.message_size as usize - size_of::<Version>(),
|
||||
0,
|
||||
);
|
||||
let mut server_version_data =
|
||||
vec![0; server_version.header.message_size as usize - size_of::<Version>()];
|
||||
self.stream
|
||||
.read_exact(server_version_data.as_mut_slice())
|
||||
.map_err(Error::StreamRead)?;
|
||||
@ -566,7 +563,7 @@ impl Client {
|
||||
let mmap_cap_size = size_of::<vfio_region_info_cap_sparse_mmap>() as u32;
|
||||
let mmap_area_size = size_of::<vfio_region_sparse_mmap_area>() as u32;
|
||||
|
||||
let cap_data_ptr = cap_data.as_ptr() as *const u8;
|
||||
let cap_data_ptr = cap_data.as_ptr();
|
||||
let mut region_info_offset = region_info.cap_offset;
|
||||
while region_info_offset != 0 {
|
||||
// calculate the offset from the begining of the cap_data based on the offset
|
||||
|
@ -145,11 +145,7 @@ impl DiskSpec {
|
||||
let bits = f
|
||||
.read_u32::<LittleEndian>()
|
||||
.map_err(VhdxMetadataError::ReadMetadata)?;
|
||||
if bits & BLOCK_HAS_PARENT != 0 {
|
||||
disk_spec.has_parent = true;
|
||||
} else {
|
||||
disk_spec.has_parent = false;
|
||||
}
|
||||
disk_spec.has_parent = bits & BLOCK_HAS_PARENT != 0;
|
||||
|
||||
metadata_presence |= METADATA_FILE_PARAMETER_PRESENT;
|
||||
} else if metadata_entry.item_id
|
||||
|
@ -594,7 +594,7 @@ impl VirtioDevice for Fs {
|
||||
&mut self,
|
||||
shm_regions: VirtioSharedMemoryList,
|
||||
) -> std::result::Result<(), crate::Error> {
|
||||
if let Some(mut cache) = self.cache.as_mut() {
|
||||
if let Some(cache) = self.cache.as_mut() {
|
||||
cache.0 = shm_regions;
|
||||
Ok(())
|
||||
} else {
|
||||
|
@ -7,7 +7,7 @@ use crate::{
|
||||
get_host_address_range, GuestMemoryMmap, GuestRegionMmap, MmapRegion, VirtioInterrupt,
|
||||
VirtioInterruptType,
|
||||
};
|
||||
use std::convert::TryInto;
|
||||
|
||||
use std::ffi;
|
||||
use std::fs::File;
|
||||
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
|
||||
@ -201,7 +201,7 @@ impl VhostUserHandle {
|
||||
|
||||
let mut vrings_info = Vec::new();
|
||||
for (queue_index, queue, queue_evt) in queues.iter() {
|
||||
let actual_size: usize = queue.size().try_into().unwrap();
|
||||
let actual_size: usize = queue.size().into();
|
||||
|
||||
let config_data = VringConfigData {
|
||||
queue_max_size: queue.max_size(),
|
||||
|
@ -963,7 +963,7 @@ mod tests {
|
||||
self.init_pkt(local_port, peer_port, uapi::VSOCK_OP_RESPONSE);
|
||||
self.send();
|
||||
|
||||
let mut buf = vec![0u8; 32];
|
||||
let mut buf = [0u8; 32];
|
||||
let len = stream.read(&mut buf[..]).unwrap();
|
||||
assert_eq!(&buf[..len], format!("OK {local_port}\n").as_bytes());
|
||||
|
||||
|
@ -110,8 +110,7 @@ impl Bus {
|
||||
let devices = self.devices.read().unwrap();
|
||||
let (range, dev) = devices
|
||||
.range(..=BusRange { base: addr, len: 1 })
|
||||
.rev()
|
||||
.next()?;
|
||||
.next_back()?;
|
||||
dev.upgrade().map(|d| (*range, d.clone()))
|
||||
}
|
||||
|
||||
|
@ -1148,7 +1148,7 @@ impl CpuManager {
|
||||
|
||||
fn remove_vcpu(&mut self, cpu_id: u8) -> Result<()> {
|
||||
info!("Removing vCPU: cpu_id = {}", cpu_id);
|
||||
let mut state = &mut self.vcpu_states[usize::from(cpu_id)];
|
||||
let state = &mut self.vcpu_states[usize::from(cpu_id)];
|
||||
state.kill.store(true, Ordering::SeqCst);
|
||||
state.signal_thread();
|
||||
state.join_thread()?;
|
||||
|
@ -1506,7 +1506,7 @@ impl MemoryManager {
|
||||
.ok_or(Error::MemoryRangeAllocation)?;
|
||||
|
||||
// Update the slot so that it can be queried via the I/O port
|
||||
let mut slot = &mut self.hotplug_slots[self.next_hotplug_slot];
|
||||
let slot = &mut self.hotplug_slots[self.next_hotplug_slot];
|
||||
slot.active = true;
|
||||
slot.inserting = true;
|
||||
slot.base = region.start_addr().0;
|
||||
|
@ -225,7 +225,7 @@ impl SerialManager {
|
||||
const EPOLL_EVENTS_LEN: usize = 3;
|
||||
|
||||
let mut events =
|
||||
vec![epoll::Event::new(epoll::Events::empty(), 0); EPOLL_EVENTS_LEN];
|
||||
[epoll::Event::new(epoll::Events::empty(), 0); EPOLL_EVENTS_LEN];
|
||||
|
||||
loop {
|
||||
let num_events = match epoll::wait(epoll_fd, timeout, &mut events[..]) {
|
||||
|
@ -1319,7 +1319,7 @@ impl Vm {
|
||||
.resize(desired_memory)
|
||||
.map_err(Error::MemoryManager)?;
|
||||
|
||||
let mut memory_config = &mut self.config.lock().unwrap().memory;
|
||||
let memory_config = &mut self.config.lock().unwrap().memory;
|
||||
|
||||
if let Some(new_region) = &new_region {
|
||||
self.device_manager
|
||||
|
Loading…
Reference in New Issue
Block a user