mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: clippy: add needless_pass_by_value
This is a follow-up of [0].
# Advantages
- This saves dozens of unneeded clone()s across the whole code base
- Makes it much easier to reason about how parameters are used
(often we passed owned Arc/Rc versions without actually needing
ownership)
# Exceptions
For certain code paths, the alternatives would require awkward or overly
complex code, and in some cases the functions are the logical owners of
the values they take. In those cases, I've added
#[allow(clippy::needless_pass_by_value)].
This does not mean that one should not improve this in the future.
[0] 6a86c157af
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
This commit is contained in:
committed by
Rob Bradford
parent
ed4af3a005
commit
c53781bf5f
@@ -105,6 +105,7 @@ struct ProcessorGiccAffinity {
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct MemAffinityFlags: u32 {
|
||||
const NOFLAGS = 0;
|
||||
const ENABLE = 0b1;
|
||||
|
||||
@@ -76,6 +76,7 @@ const HTTP_ROOT: &str = "/api/v1";
|
||||
/// The error message contained in the response is supposed to be user-facing,
|
||||
/// thus insightful and helpful while balancing technical accuracy and
|
||||
/// simplicity.
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
pub fn error_response(error: HttpError, status: StatusCode) -> Response {
|
||||
let mut response = Response::new(Version::Http11, status);
|
||||
|
||||
|
||||
@@ -369,6 +369,7 @@ pub trait RequestHandler {
|
||||
pub type ApiRequest =
|
||||
Box<dyn FnOnce(&mut dyn RequestHandler) -> Result<bool, VmmError> + Send + 'static>;
|
||||
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
fn get_response<Action: ApiAction>(
|
||||
action: &Action,
|
||||
api_evt: EventFd,
|
||||
|
||||
@@ -811,6 +811,7 @@ impl PlatformConfig {
|
||||
}
|
||||
|
||||
impl MemoryConfig {
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
pub fn parse(memory: &str, memory_zones: Option<Vec<&str>>) -> Result<Self> {
|
||||
let mut parser = OptionParser::new();
|
||||
parser
|
||||
|
||||
@@ -76,7 +76,7 @@ pub struct ConsoleInfo {
|
||||
fn modify_mode<F: FnOnce(&mut termios)>(
|
||||
fd: RawFd,
|
||||
f: F,
|
||||
original_termios_opt: Arc<Mutex<Option<termios>>>,
|
||||
original_termios_opt: &Mutex<Option<termios>>,
|
||||
) -> vmm_sys_util::errno::Result<()> {
|
||||
// SAFETY: safe because we check the return value of isatty.
|
||||
if unsafe { isatty(fd) } != 1 {
|
||||
@@ -109,7 +109,7 @@ fn modify_mode<F: FnOnce(&mut termios)>(
|
||||
|
||||
fn set_raw_mode(
|
||||
f: &dyn AsRawFd,
|
||||
original_termios_opt: Arc<Mutex<Option<termios>>>,
|
||||
original_termios_opt: &Mutex<Option<termios>>,
|
||||
) -> ConsoleDeviceResult<()> {
|
||||
modify_mode(
|
||||
f.as_raw_fd(),
|
||||
@@ -190,7 +190,7 @@ pub(crate) fn pre_create_console_devices(vmm: &mut Vmm) -> ConsoleDeviceResult<C
|
||||
ConsoleOutputMode::Pty => {
|
||||
let (main_fd, sub_fd, path) =
|
||||
create_pty().map_err(ConsoleDeviceError::CreateConsoleDevice)?;
|
||||
set_raw_mode(&sub_fd.as_raw_fd(), vmm.original_termios_opt.clone())?;
|
||||
set_raw_mode(&sub_fd.as_raw_fd(), &vmm.original_termios_opt)?;
|
||||
vmconfig.console.file = Some(path.clone());
|
||||
vmm.console_resize_pipe = Some(Arc::new(
|
||||
listen_for_sigwinch_on_tty(
|
||||
@@ -221,7 +221,7 @@ pub(crate) fn pre_create_console_devices(vmm: &mut Vmm) -> ConsoleDeviceResult<C
|
||||
}
|
||||
|
||||
// Make sure stdout is in raw mode, if it's a terminal.
|
||||
set_raw_mode(&stdout, vmm.original_termios_opt.clone())?;
|
||||
set_raw_mode(&stdout, &vmm.original_termios_opt)?;
|
||||
ConsoleOutput::Tty(Arc::new(stdout))
|
||||
}
|
||||
ConsoleOutputMode::Socket => {
|
||||
@@ -239,7 +239,7 @@ pub(crate) fn pre_create_console_devices(vmm: &mut Vmm) -> ConsoleDeviceResult<C
|
||||
ConsoleOutputMode::Pty => {
|
||||
let (main_fd, sub_fd, path) =
|
||||
create_pty().map_err(ConsoleDeviceError::CreateConsoleDevice)?;
|
||||
set_raw_mode(&sub_fd.as_raw_fd(), vmm.original_termios_opt.clone())?;
|
||||
set_raw_mode(&sub_fd.as_raw_fd(), &vmm.original_termios_opt)?;
|
||||
vmconfig.serial.file = Some(path.clone());
|
||||
ConsoleOutput::Pty(Arc::new(main_fd))
|
||||
}
|
||||
@@ -255,7 +255,7 @@ pub(crate) fn pre_create_console_devices(vmm: &mut Vmm) -> ConsoleDeviceResult<C
|
||||
let stdout = dup_stdout().map_err(ConsoleDeviceError::DupFd)?;
|
||||
|
||||
// Make sure stdout is in raw mode, if it's a terminal.
|
||||
set_raw_mode(&stdout, vmm.original_termios_opt.clone())?;
|
||||
set_raw_mode(&stdout, &vmm.original_termios_opt)?;
|
||||
|
||||
ConsoleOutput::Tty(Arc::new(stdout))
|
||||
}
|
||||
@@ -277,14 +277,14 @@ pub(crate) fn pre_create_console_devices(vmm: &mut Vmm) -> ConsoleDeviceResult<C
|
||||
ConsoleOutputMode::Pty => {
|
||||
let (main_fd, sub_fd, path) =
|
||||
create_pty().map_err(ConsoleDeviceError::CreateConsoleDevice)?;
|
||||
set_raw_mode(&sub_fd.as_raw_fd(), vmm.original_termios_opt.clone())?;
|
||||
set_raw_mode(&sub_fd.as_raw_fd(), &vmm.original_termios_opt)?;
|
||||
vmconfig.debug_console.file = Some(path.clone());
|
||||
ConsoleOutput::Pty(Arc::new(main_fd))
|
||||
}
|
||||
ConsoleOutputMode::Tty => {
|
||||
let out =
|
||||
dup_stdout().map_err(|e| ConsoleDeviceError::CreateConsoleDevice(e.into()))?;
|
||||
set_raw_mode(&out, vmm.original_termios_opt.clone())?;
|
||||
set_raw_mode(&out, &vmm.original_termios_opt)?;
|
||||
ConsoleOutput::Tty(Arc::new(out))
|
||||
}
|
||||
ConsoleOutputMode::Socket => {
|
||||
|
||||
@@ -949,7 +949,7 @@ impl CpuManager {
|
||||
|
||||
pub fn configure_vcpu(
|
||||
&self,
|
||||
vcpu: Arc<Mutex<Vcpu>>,
|
||||
vcpu: &Mutex<Vcpu>,
|
||||
boot_setup: Option<(EntryPoint, &GuestMemoryAtomic<GuestMemoryMmap>)>,
|
||||
) -> Result<()> {
|
||||
let mut vcpu = vcpu.lock().unwrap();
|
||||
@@ -1432,7 +1432,7 @@ impl CpuManager {
|
||||
cmp::Ordering::Greater => {
|
||||
let vcpus = self.create_vcpus(desired_vcpus, None)?;
|
||||
for vcpu in vcpus {
|
||||
self.configure_vcpu(vcpu, None)?;
|
||||
self.configure_vcpu(&vcpu, None)?;
|
||||
}
|
||||
self.activate_vcpus(desired_vcpus, true, None)?;
|
||||
Ok(true)
|
||||
@@ -1543,6 +1543,7 @@ impl CpuManager {
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
pub fn create_madt(&self, #[cfg(target_arch = "aarch64")] vgic: Arc<Mutex<dyn Vgic>>) -> Sdt {
|
||||
use crate::acpi;
|
||||
// This is also checked in the commandline parsing.
|
||||
|
||||
@@ -15,7 +15,7 @@ use std::io::{self, IsTerminal, Seek, SeekFrom, stdout};
|
||||
use std::num::Wrapping;
|
||||
use std::os::unix::fs::OpenOptionsExt;
|
||||
use std::os::unix::io::{AsRawFd, FromRawFd};
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::result;
|
||||
use std::sync::{Arc, Mutex};
|
||||
#[cfg(not(target_arch = "riscv64"))]
|
||||
@@ -1114,7 +1114,7 @@ fn create_mmio_allocators(
|
||||
start: u64,
|
||||
end: u64,
|
||||
num_pci_segments: u16,
|
||||
weights: Vec<u32>,
|
||||
weights: &[u32],
|
||||
alignment: u64,
|
||||
) -> Vec<Arc<Mutex<AddressAllocator>>> {
|
||||
let total_weight: u32 = weights.iter().sum();
|
||||
@@ -1193,7 +1193,7 @@ impl DeviceManager {
|
||||
start_of_mmio32_area,
|
||||
end_of_mmio32_area,
|
||||
num_pci_segments,
|
||||
mmio32_aperture_weights,
|
||||
&mmio32_aperture_weights,
|
||||
4 << 10,
|
||||
);
|
||||
|
||||
@@ -1213,7 +1213,7 @@ impl DeviceManager {
|
||||
start_of_mmio64_area,
|
||||
end_of_mmio64_area,
|
||||
num_pci_segments,
|
||||
mmio64_aperture_weights,
|
||||
&mmio64_aperture_weights,
|
||||
4 << 30,
|
||||
);
|
||||
|
||||
@@ -1400,6 +1400,7 @@ impl DeviceManager {
|
||||
self.add_interrupt_controller()
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
pub fn create_devices(
|
||||
&mut self,
|
||||
console_info: Option<ConsoleInfo>,
|
||||
@@ -1470,7 +1471,7 @@ impl DeviceManager {
|
||||
|
||||
#[cfg(not(target_arch = "riscv64"))]
|
||||
if let Some(tpm) = self.config.clone().lock().unwrap().tpm.as_ref() {
|
||||
let tpm_dev = self.add_tpm_device(tpm.socket.clone())?;
|
||||
let tpm_dev = self.add_tpm_device(&tpm.socket)?;
|
||||
self.bus_devices
|
||||
.push(Arc::clone(&tpm_dev) as Arc<dyn BusDeviceSync>);
|
||||
}
|
||||
@@ -1644,7 +1645,7 @@ impl DeviceManager {
|
||||
let dev_id = self.add_virtio_pci_device(
|
||||
handle.virtio_device,
|
||||
&mapping,
|
||||
handle.id,
|
||||
&handle.id,
|
||||
handle.pci_segment,
|
||||
handle.dma_handler,
|
||||
)?;
|
||||
@@ -1675,7 +1676,7 @@ impl DeviceManager {
|
||||
}
|
||||
|
||||
if let Some(iommu_device) = iommu_device {
|
||||
let dev_id = self.add_virtio_pci_device(iommu_device, &None, iommu_id, 0, None)?;
|
||||
let dev_id = self.add_virtio_pci_device(iommu_device, &None, &iommu_id, 0, None)?;
|
||||
self.iommu_attached_devices = Some((dev_id, iommu_attached_devices));
|
||||
}
|
||||
}
|
||||
@@ -1790,14 +1791,15 @@ impl DeviceManager {
|
||||
) -> DeviceManagerResult<Arc<Mutex<dyn InterruptController>>> {
|
||||
let id = String::from(IOAPIC_DEVICE_NAME);
|
||||
|
||||
let state = state_from_id(self.snapshot.as_ref(), id.as_str())
|
||||
.map_err(DeviceManagerError::RestoreGetState)?;
|
||||
// Create IOAPIC
|
||||
let interrupt_controller = Arc::new(Mutex::new(
|
||||
ioapic::Ioapic::new(
|
||||
id.clone(),
|
||||
APIC_START,
|
||||
self.msi_interrupt_manager.as_ref(),
|
||||
state_from_id(self.snapshot.as_ref(), id.as_str())
|
||||
.map_err(DeviceManagerError::RestoreGetState)?,
|
||||
state.as_ref(),
|
||||
)
|
||||
.map_err(DeviceManagerError::CreateInterruptController)?,
|
||||
));
|
||||
@@ -2486,7 +2488,7 @@ impl DeviceManager {
|
||||
#[cfg(not(target_arch = "riscv64"))]
|
||||
fn add_tpm_device(
|
||||
&mut self,
|
||||
tpm_path: PathBuf,
|
||||
tpm_path: &Path,
|
||||
) -> DeviceManagerResult<Arc<Mutex<devices::tpm::Tpm>>> {
|
||||
// Create TPM Device
|
||||
let tpm = devices::tpm::Tpm::new(tpm_path.to_str().unwrap()).map_err(|e| {
|
||||
@@ -4057,7 +4059,7 @@ impl DeviceManager {
|
||||
&mut self,
|
||||
virtio_device: Arc<Mutex<dyn virtio_devices::VirtioDevice>>,
|
||||
iommu_mapping: &Option<Arc<IommuMapping>>,
|
||||
virtio_device_id: String,
|
||||
virtio_device_id: &str,
|
||||
pci_segment_id: u16,
|
||||
dma_handler: Option<Arc<dyn ExternalDmaMapping>>,
|
||||
) -> DeviceManagerResult<PciBdf> {
|
||||
@@ -4065,13 +4067,13 @@ impl DeviceManager {
|
||||
|
||||
// Add the new virtio-pci node to the device tree.
|
||||
let mut node = device_node!(id);
|
||||
node.children = vec![virtio_device_id.clone()];
|
||||
node.children = vec![virtio_device_id.to_string()];
|
||||
|
||||
let (pci_segment_id, pci_device_bdf, resources) =
|
||||
self.pci_resources(&id, pci_segment_id)?;
|
||||
|
||||
// Update the existing virtio node by setting the parent.
|
||||
if let Some(node) = self.device_tree.lock().unwrap().get_mut(&virtio_device_id) {
|
||||
if let Some(node) = self.device_tree.lock().unwrap().get_mut(virtio_device_id) {
|
||||
node.parent = Some(id.clone());
|
||||
} else {
|
||||
return Err(DeviceManagerError::MissingNode);
|
||||
@@ -4472,15 +4474,15 @@ impl DeviceManager {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn remove_device(&mut self, id: String) -> DeviceManagerResult<()> {
|
||||
pub fn remove_device(&mut self, id: &str) -> DeviceManagerResult<()> {
|
||||
// The node can be directly a PCI node in case the 'id' refers to a
|
||||
// VFIO device or a virtio-pci one.
|
||||
// In case the 'id' refers to a virtio device, we must find the PCI
|
||||
// node by looking at the parent.
|
||||
let device_tree = self.device_tree.lock().unwrap();
|
||||
let node = device_tree
|
||||
.get(&id)
|
||||
.ok_or(DeviceManagerError::UnknownDeviceId(id.clone()))?;
|
||||
.get(id)
|
||||
.ok_or_else(|| DeviceManagerError::UnknownDeviceId(id.to_string()))?;
|
||||
|
||||
// Release advisory locks by dropping all references.
|
||||
// Linux automatically releases all locks of that file if the last open FD is closed.
|
||||
@@ -4545,7 +4547,7 @@ impl DeviceManager {
|
||||
let nets = config.net.as_deref_mut().unwrap();
|
||||
let net_dev_cfg = nets
|
||||
.iter_mut()
|
||||
.find(|net| net.id.as_ref() == Some(&id))
|
||||
.find(|net| net.id.as_deref() == Some(id))
|
||||
// unwrap: the device could not have been removed without an ID
|
||||
.unwrap();
|
||||
let fds = net_dev_cfg.fds.take().unwrap_or(Vec::new());
|
||||
@@ -4692,12 +4694,11 @@ impl DeviceManager {
|
||||
|
||||
if remove_dma_handler {
|
||||
for virtio_mem_device in self.virtio_mem_devices.iter() {
|
||||
let source = VirtioMemMappingSource::Device(pci_device_bdf.into());
|
||||
virtio_mem_device
|
||||
.lock()
|
||||
.unwrap()
|
||||
.remove_dma_mapping_handler(VirtioMemMappingSource::Device(
|
||||
pci_device_bdf.into(),
|
||||
))
|
||||
.remove_dma_mapping_handler(&source)
|
||||
.map_err(DeviceManagerError::RemoveDmaMappingHandlerVirtioMem)?;
|
||||
}
|
||||
}
|
||||
@@ -4804,7 +4805,7 @@ impl DeviceManager {
|
||||
let bdf = self.add_virtio_pci_device(
|
||||
handle.virtio_device,
|
||||
&mapping,
|
||||
handle.id.clone(),
|
||||
&handle.id,
|
||||
handle.pci_segment,
|
||||
handle.dma_handler,
|
||||
)?;
|
||||
@@ -5532,7 +5533,7 @@ mod unit_tests {
|
||||
|
||||
#[test]
|
||||
fn test_create_mmio_allocators() {
|
||||
let res = create_mmio_allocators(0x100000, 0x400000, 1, vec![1], 4 << 10);
|
||||
let res = create_mmio_allocators(0x100000, 0x400000, 1, &[1], 4 << 10);
|
||||
assert_eq!(res.len(), 1);
|
||||
assert_eq!(
|
||||
res[0].lock().unwrap().base(),
|
||||
@@ -5543,7 +5544,7 @@ mod unit_tests {
|
||||
vm_memory::GuestAddress(0x3fffff)
|
||||
);
|
||||
|
||||
let res = create_mmio_allocators(0x100000, 0x400000, 2, vec![1, 1], 4 << 10);
|
||||
let res = create_mmio_allocators(0x100000, 0x400000, 2, &[1, 1], 4 << 10);
|
||||
assert_eq!(res.len(), 2);
|
||||
assert_eq!(
|
||||
res[0].lock().unwrap().base(),
|
||||
@@ -5562,7 +5563,7 @@ mod unit_tests {
|
||||
vm_memory::GuestAddress(0x3fffff)
|
||||
);
|
||||
|
||||
let res = create_mmio_allocators(0x100000, 0x400000, 2, vec![2, 1], 4 << 10);
|
||||
let res = create_mmio_allocators(0x100000, 0x400000, 2, &[2, 1], 4 << 10);
|
||||
assert_eq!(res.len(), 2);
|
||||
assert_eq!(
|
||||
res[0].lock().unwrap().base(),
|
||||
|
||||
@@ -131,7 +131,7 @@ fn import_parameter(
|
||||
/// Right now it only supports SNP based isolation.
|
||||
/// We can boot legacy VM with an igvm file without
|
||||
/// any isolation.
|
||||
///
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
pub fn load_igvm(
|
||||
mut file: &std::fs::File,
|
||||
memory_manager: Arc<Mutex<MemoryManager>>,
|
||||
|
||||
@@ -74,7 +74,7 @@ pub enum BootPageAcceptance {
|
||||
/// The startup memory type used to notify a well behaved host that memory should be present before attempting to
|
||||
/// start the guest.
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum StartupMemoryType {
|
||||
/// The range is normal memory.
|
||||
Ram,
|
||||
|
||||
@@ -11,7 +11,6 @@ use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
|
||||
use std::os::unix::net::{UnixListener, UnixStream};
|
||||
use std::panic::AssertUnwindSafe;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::{Receiver, RecvError, SendError, Sender};
|
||||
use std::sync::{Arc, Mutex};
|
||||
#[cfg(not(target_arch = "riscv64"))]
|
||||
@@ -545,9 +544,9 @@ pub fn start_vmm_thread(
|
||||
vmm.setup_signal_handler(landlock_enable)?;
|
||||
|
||||
vmm.control_loop(
|
||||
Rc::new(api_receiver),
|
||||
&api_receiver,
|
||||
#[cfg(feature = "guest_debug")]
|
||||
Rc::new(gdb_receiver),
|
||||
&gdb_receiver,
|
||||
)
|
||||
})
|
||||
.map_err(Error::VmmThreadSpawn)?
|
||||
@@ -674,7 +673,7 @@ impl Vmm {
|
||||
|
||||
fn signal_handler(
|
||||
mut signals: Signals,
|
||||
original_termios_opt: Arc<Mutex<Option<termios>>>,
|
||||
original_termios_opt: &Mutex<Option<termios>>,
|
||||
exit_evt: &EventFd,
|
||||
) {
|
||||
for sig in &Self::HANDLED_SIGNALS {
|
||||
@@ -747,7 +746,7 @@ impl Vmm {
|
||||
}
|
||||
|
||||
std::panic::catch_unwind(AssertUnwindSafe(|| {
|
||||
Vmm::signal_handler(signals, original_termios_opt, &exit_evt);
|
||||
Vmm::signal_handler(signals, original_termios_opt.as_ref(), &exit_evt);
|
||||
}))
|
||||
.map_err(|_| {
|
||||
error!("vmm signal_handler thread panicked");
|
||||
@@ -862,7 +861,7 @@ impl Vmm {
|
||||
.unwrap()
|
||||
.landlock_enable
|
||||
{
|
||||
apply_landlock(self.vm_config.as_ref().unwrap().clone()).map_err(|e| {
|
||||
apply_landlock(self.vm_config.as_ref().unwrap().as_ref()).map_err(|e| {
|
||||
MigratableError::MigrateReceive(anyhow!("Error applying landlock: {e:?}"))
|
||||
})?;
|
||||
}
|
||||
@@ -1097,12 +1096,13 @@ impl Vmm {
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
fn send_migration(
|
||||
vm: &mut Vm,
|
||||
#[cfg(all(feature = "kvm", target_arch = "x86_64"))] hypervisor: Arc<
|
||||
dyn hypervisor::Hypervisor,
|
||||
>,
|
||||
send_data_migration: VmSendMigrationData,
|
||||
send_data_migration: &VmSendMigrationData,
|
||||
) -> result::Result<(), MigratableError> {
|
||||
// Set up the socket connection
|
||||
let mut socket = Self::send_migration_socket(&send_data_migration.destination_url)?;
|
||||
@@ -1348,7 +1348,7 @@ impl Vmm {
|
||||
.unwrap()
|
||||
.landlock_enable
|
||||
{
|
||||
apply_landlock(self.vm_config.as_ref().unwrap().clone())
|
||||
apply_landlock(self.vm_config.as_ref().unwrap().as_ref())
|
||||
.map_err(VmError::ApplyLandlock)?;
|
||||
}
|
||||
|
||||
@@ -1362,8 +1362,8 @@ impl Vmm {
|
||||
|
||||
fn control_loop(
|
||||
&mut self,
|
||||
api_receiver: Rc<Receiver<ApiRequest>>,
|
||||
#[cfg(feature = "guest_debug")] gdb_receiver: Rc<Receiver<gdb::GdbRequest>>,
|
||||
api_receiver: &Receiver<ApiRequest>,
|
||||
#[cfg(feature = "guest_debug")] gdb_receiver: &Receiver<gdb::GdbRequest>,
|
||||
) -> Result<()> {
|
||||
const EPOLL_EVENTS_LEN: usize = 100;
|
||||
|
||||
@@ -1468,7 +1468,7 @@ impl Vmm {
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_landlock(vm_config: Arc<Mutex<VmConfig>>) -> result::Result<(), LandlockError> {
|
||||
fn apply_landlock(vm_config: &Mutex<VmConfig>) -> result::Result<(), LandlockError> {
|
||||
vm_config.lock().unwrap().apply_landlock()?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -1490,7 +1490,7 @@ impl RequestHandler for Vmm {
|
||||
.unwrap()
|
||||
.landlock_enable
|
||||
{
|
||||
apply_landlock(self.vm_config.as_ref().unwrap().clone())
|
||||
apply_landlock(self.vm_config.as_ref().unwrap().as_ref())
|
||||
.map_err(VmError::ApplyLandlock)?;
|
||||
}
|
||||
Ok(())
|
||||
@@ -1834,7 +1834,7 @@ impl RequestHandler for Vmm {
|
||||
self.vm_config.as_ref().ok_or(VmError::VmNotCreated)?;
|
||||
|
||||
if let Some(ref mut vm) = self.vm {
|
||||
vm.resize_zone(id, desired_ram)
|
||||
vm.resize_zone(&id, desired_ram)
|
||||
.inspect_err(|e| error!("Error when resizing zone: {e:?}"))?;
|
||||
Ok(())
|
||||
} else {
|
||||
@@ -1913,7 +1913,7 @@ impl RequestHandler for Vmm {
|
||||
|
||||
fn vm_remove_device(&mut self, id: String) -> result::Result<(), VmError> {
|
||||
if let Some(ref mut vm) = self.vm {
|
||||
vm.remove_device(id)
|
||||
vm.remove_device(&id)
|
||||
.inspect_err(|e| error!("Error when removing device from the VM: {e:?}"))?;
|
||||
Ok(())
|
||||
} else if let Some(ref config) = self.vm_config {
|
||||
@@ -2271,7 +2271,7 @@ impl RequestHandler for Vmm {
|
||||
vm,
|
||||
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
|
||||
self.hypervisor.clone(),
|
||||
send_data_migration.clone(),
|
||||
&send_data_migration,
|
||||
)
|
||||
.map_err(|migration_err| {
|
||||
error!("Migration failed: {migration_err:?}");
|
||||
|
||||
@@ -721,7 +721,7 @@ impl MemoryManager {
|
||||
fn fill_saved_regions(
|
||||
&mut self,
|
||||
file_path: PathBuf,
|
||||
saved_regions: MemoryRangeTable,
|
||||
saved_regions: &MemoryRangeTable,
|
||||
) -> Result<(), Error> {
|
||||
if saved_regions.is_empty() {
|
||||
return Ok(());
|
||||
@@ -1268,7 +1268,7 @@ impl MemoryManager {
|
||||
|
||||
mm.lock()
|
||||
.unwrap()
|
||||
.fill_saved_regions(memory_file_path, mem_snapshot.memory_ranges)?;
|
||||
.fill_saved_regions(memory_file_path, &mem_snapshot.memory_ranges)?;
|
||||
|
||||
Ok(mm)
|
||||
} else {
|
||||
@@ -1291,7 +1291,7 @@ impl MemoryManager {
|
||||
addr: *mut u8,
|
||||
len: u64,
|
||||
mode: u32,
|
||||
nodemask: Vec<u64>,
|
||||
nodemask: &[u64],
|
||||
maxnode: u64,
|
||||
flags: u32,
|
||||
) -> Result<(), io::Error> {
|
||||
@@ -1438,7 +1438,7 @@ impl MemoryManager {
|
||||
// MPOL_BIND is the selected mode as it specifies a strict policy
|
||||
// that restricts memory allocation to the nodes specified in the
|
||||
// nodemask.
|
||||
Self::mbind(addr, len, mode, nodemask, maxnode, flags)
|
||||
Self::mbind(addr, len, mode, &nodemask, maxnode, flags)
|
||||
.map_err(Error::ApplyNumaPolicy)?;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ use vhost::vhost_kern::vhost_binding::{
|
||||
VHOST_VDPA_SET_STATUS, VHOST_VDPA_SET_VRING_ENABLE, VHOST_VDPA_SUSPEND,
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum Thread {
|
||||
HttpApi,
|
||||
#[cfg(feature = "dbus_api")]
|
||||
|
||||
@@ -19,7 +19,7 @@ use libc::{
|
||||
poll, pollfd, setsid, sigemptyset, siginfo_t, signal, sigprocmask, syscall, tcgetpgrp,
|
||||
tcsetpgrp,
|
||||
};
|
||||
use seccompiler::{BpfProgram, SeccompAction, apply_filter};
|
||||
use seccompiler::{BpfProgramRef, SeccompAction, apply_filter};
|
||||
use vmm_sys_util::signal::register_signal_handler;
|
||||
|
||||
use crate::clone3::{CLONE_CLEAR_SIGHAND, clone_args, clone3};
|
||||
@@ -162,7 +162,7 @@ fn set_foreground_process_group(tty: &File) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn sigwinch_listener_main(seccomp_filter: BpfProgram, tx: File, tty: File) -> ! {
|
||||
fn sigwinch_listener_main(seccomp_filter: BpfProgramRef, tx: File, tty: File) -> ! {
|
||||
// SAFETY: any references to these file descriptors are
|
||||
// unreachable, because this function never returns.
|
||||
unsafe {
|
||||
@@ -174,7 +174,7 @@ fn sigwinch_listener_main(seccomp_filter: BpfProgram, tx: File, tty: File) -> !
|
||||
unblock_all_signals().unwrap();
|
||||
|
||||
if !seccomp_filter.is_empty() {
|
||||
apply_filter(&seccomp_filter).unwrap();
|
||||
apply_filter(seccomp_filter).unwrap();
|
||||
}
|
||||
|
||||
register_signal_handler(SIGWINCH, sigwinch_handler).unwrap();
|
||||
@@ -242,7 +242,7 @@ unsafe fn clone_clear_sighand() -> io::Result<u64> {
|
||||
Ok(r.try_into().unwrap())
|
||||
}
|
||||
|
||||
pub fn start_sigwinch_listener(seccomp_filter: BpfProgram, tty_sub: File) -> io::Result<File> {
|
||||
pub fn start_sigwinch_listener(seccomp_filter: BpfProgramRef, tty_sub: File) -> io::Result<File> {
|
||||
let mut pipe = [-1; 2];
|
||||
// SAFETY: FFI call with valid arguments
|
||||
if unsafe { pipe2(pipe.as_mut_ptr(), O_CLOEXEC) } == -1 {
|
||||
@@ -275,7 +275,7 @@ pub fn listen_for_sigwinch_on_tty(
|
||||
let seccomp_filter =
|
||||
get_seccomp_filter(seccomp_action, Thread::PtyForeground, hypervisor_type).unwrap();
|
||||
|
||||
let console_resize_pipe = start_sigwinch_listener(seccomp_filter, pty_sub)?;
|
||||
let console_resize_pipe = start_sigwinch_listener(&seccomp_filter, pty_sub)?;
|
||||
|
||||
Ok(console_resize_pipe)
|
||||
}
|
||||
|
||||
@@ -528,6 +528,7 @@ pub struct Vm {
|
||||
impl Vm {
|
||||
pub const HANDLED_SIGNALS: [i32; 1] = [SIGWINCH];
|
||||
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new_from_memory_manager(
|
||||
config: Arc<Mutex<VmConfig>>,
|
||||
@@ -557,7 +558,7 @@ impl Vm {
|
||||
|
||||
// Create NUMA nodes based on NumaConfig.
|
||||
let numa_nodes =
|
||||
Self::create_numa_nodes(config.lock().unwrap().numa.clone(), &memory_manager)?;
|
||||
Self::create_numa_nodes(config.lock().unwrap().numa.as_deref(), &memory_manager)?;
|
||||
|
||||
#[cfg(feature = "tdx")]
|
||||
let tdx_enabled = config.lock().unwrap().is_tdx_enabled();
|
||||
@@ -915,7 +916,7 @@ impl Vm {
|
||||
}
|
||||
|
||||
fn create_numa_nodes(
|
||||
configs: Option<Vec<NumaConfig>>,
|
||||
configs: Option<&[NumaConfig]>,
|
||||
memory_manager: &Arc<Mutex<MemoryManager>>,
|
||||
) -> Result<NumaNodes> {
|
||||
let mm = memory_manager.lock().unwrap();
|
||||
@@ -1148,6 +1149,7 @@ impl Vm {
|
||||
Ok(cmdline)
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
|
||||
fn load_firmware(
|
||||
mut firmware: &File,
|
||||
@@ -1162,6 +1164,7 @@ impl Vm {
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
|
||||
fn load_kernel(
|
||||
mut kernel: File,
|
||||
@@ -1197,6 +1200,7 @@ impl Vm {
|
||||
}
|
||||
|
||||
#[cfg(feature = "igvm")]
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
fn load_igvm(
|
||||
igvm: File,
|
||||
memory_manager: Arc<Mutex<MemoryManager>>,
|
||||
@@ -1231,6 +1235,7 @@ impl Vm {
|
||||
///
|
||||
/// For x86_64, the boot path is the same.
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
fn load_kernel(
|
||||
mut kernel: File,
|
||||
cmdline: Option<Cmdline>,
|
||||
@@ -1324,6 +1329,7 @@ impl Vm {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
|
||||
fn load_payload(
|
||||
payload: &PayloadConfig,
|
||||
@@ -1521,7 +1527,7 @@ impl Vm {
|
||||
arch::configure_system(
|
||||
&mem,
|
||||
cmdline.as_cstring().unwrap().to_str().unwrap(),
|
||||
vcpu_mpidrs,
|
||||
&vcpu_mpidrs,
|
||||
vcpu_topology,
|
||||
device_info,
|
||||
&initramfs_config,
|
||||
@@ -1722,7 +1728,7 @@ impl Vm {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn resize_zone(&mut self, id: String, desired_memory: u64) -> Result<()> {
|
||||
pub fn resize_zone(&mut self, id: &str, desired_memory: u64) -> Result<()> {
|
||||
let memory_config = &mut self.config.lock().unwrap().memory;
|
||||
|
||||
if let Some(zones) = &mut memory_config.zones {
|
||||
@@ -1733,7 +1739,7 @@ impl Vm {
|
||||
self.memory_manager
|
||||
.lock()
|
||||
.unwrap()
|
||||
.resize_zone(&id, desired_memory - zone.size)
|
||||
.resize_zone(id, desired_memory - zone.size)
|
||||
.map_err(Error::MemoryManager)?;
|
||||
// We update the memory zone config regardless of the
|
||||
// actual 'resize-zone' operation result (happened or
|
||||
@@ -1805,16 +1811,16 @@ impl Vm {
|
||||
Ok(pci_device_info)
|
||||
}
|
||||
|
||||
pub fn remove_device(&mut self, id: String) -> Result<()> {
|
||||
pub fn remove_device(&mut self, id: &str) -> Result<()> {
|
||||
self.device_manager
|
||||
.lock()
|
||||
.unwrap()
|
||||
.remove_device(id.clone())
|
||||
.remove_device(id)
|
||||
.map_err(Error::DeviceManager)?;
|
||||
|
||||
// Update VmConfig by removing the device. This is important to
|
||||
// ensure the device would not be created in case of a reboot.
|
||||
self.config.lock().unwrap().remove_device(&id);
|
||||
self.config.lock().unwrap().remove_device(id);
|
||||
|
||||
self.device_manager
|
||||
.lock()
|
||||
@@ -2409,7 +2415,7 @@ impl Vm {
|
||||
self.cpu_manager
|
||||
.lock()
|
||||
.unwrap()
|
||||
.configure_vcpu(vcpu.clone(), boot_setup)
|
||||
.configure_vcpu(&vcpu, boot_setup)
|
||||
.map_err(Error::CpuManager)?;
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
@@ -3562,13 +3568,12 @@ mod unit_tests {
|
||||
|
||||
let hv = hypervisor::new().unwrap();
|
||||
let vm = hv.create_vm(HypervisorVmConfig::default()).unwrap();
|
||||
let gic = vm
|
||||
.create_vgic(Gic::create_default_config(1))
|
||||
.expect("Cannot create gic");
|
||||
let vgic_config = Gic::create_default_config(1);
|
||||
let gic = vm.create_vgic(&vgic_config).expect("Cannot create gic");
|
||||
create_fdt(
|
||||
&mem,
|
||||
"console=tty0",
|
||||
vec![0],
|
||||
&[0],
|
||||
Some((0, 0, 0, 0)),
|
||||
&dev_info,
|
||||
&gic,
|
||||
|
||||
Reference in New Issue
Block a user