misc: Automatically fix cargo clippy issues added in 1.65 (stable)

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford
2022-12-14 11:41:15 +00:00
parent 8b59316718
commit 5e52729453
57 changed files with 448 additions and 574 deletions

View File

@@ -52,7 +52,7 @@ const HTTP_ROOT: &str = "/api/v1";
pub fn error_response(error: HttpError, status: StatusCode) -> Response {
let mut response = Response::new(Version::Http11, status);
response.set_body(Body::new(format!("{:?}", error)));
response.set_body(Body::new(format!("{error:?}")));
response
}

View File

@@ -209,7 +209,7 @@ impl fmt::Display for ValidationError {
write!(f, "Huge page size specified but huge pages not enabled")
}
InvalidHugePageSize(s) => {
write!(f, "Huge page size is not power of 2: {}", s)
write!(f, "Huge page size is not power of 2: {s}")
}
#[cfg(feature = "tdx")]
TdxNoCpuHotplug => {
@@ -231,56 +231,50 @@ impl fmt::Display for ValidationError {
MemoryZoneReused(s, u1, u2) => {
write!(
f,
"Memory zone: {} belongs to multiple NUMA nodes {} and {}",
s, u1, u2
"Memory zone: {s} belongs to multiple NUMA nodes {u1} and {u2}"
)
}
InvalidNumPciSegments(n) => {
write!(
f,
"Number of PCI segments ({}) not in range of 1 to {}",
n, MAX_NUM_PCI_SEGMENTS
"Number of PCI segments ({n}) not in range of 1 to {MAX_NUM_PCI_SEGMENTS}"
)
}
InvalidPciSegment(pci_segment) => {
write!(f, "Invalid PCI segment id: {}", pci_segment)
write!(f, "Invalid PCI segment id: {pci_segment}")
}
BalloonLargerThanRam(balloon_size, ram_size) => {
write!(
f,
"Ballon size ({}) greater than RAM ({})",
balloon_size, ram_size
"Ballon size ({balloon_size}) greater than RAM ({ram_size})"
)
}
OnIommuSegment(pci_segment) => {
write!(
f,
"Device is on an IOMMU PCI segment ({}) but not placed behind IOMMU",
pci_segment
"Device is on an IOMMU PCI segment ({pci_segment}) but not placed behind IOMMU"
)
}
IommuNotSupportedOnSegment(pci_segment) => {
write!(
f,
"Device is on an IOMMU PCI segment ({}) but does not support being placed behind IOMMU",
pci_segment
"Device is on an IOMMU PCI segment ({pci_segment}) but does not support being placed behind IOMMU"
)
}
IdentifierNotUnique(s) => {
write!(f, "Identifier {} is not unique", s)
write!(f, "Identifier {s} is not unique")
}
InvalidIdentifier(s) => {
write!(f, "Identifier {} is invalid", s)
write!(f, "Identifier {s} is invalid")
}
IommuNotSupported => {
write!(f, "Device does not support being placed behind IOMMU")
}
DuplicateDevicePath(p) => write!(f, "Duplicated device path: {}", p),
DuplicateDevicePath(p) => write!(f, "Duplicated device path: {p}"),
&InvalidMtu(mtu) => {
write!(
f,
"Provided MTU {} is lower than 1280 (expected by VIRTIO specification)",
mtu
"Provided MTU {mtu} is lower than 1280 (expected by VIRTIO specification)"
)
}
}
@@ -291,51 +285,51 @@ impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::Error::*;
match self {
ParseConsole(o) => write!(f, "Error parsing --console: {}", o),
ParseConsole(o) => write!(f, "Error parsing --console: {o}"),
ParseConsoleInvalidModeGiven => {
write!(f, "Error parsing --console: invalid console mode given")
}
ParseCpus(o) => write!(f, "Error parsing --cpus: {}", o),
InvalidCpuFeatures(o) => write!(f, "Invalid feature in --cpus features list: {}", o),
ParseDevice(o) => write!(f, "Error parsing --device: {}", o),
ParseCpus(o) => write!(f, "Error parsing --cpus: {o}"),
InvalidCpuFeatures(o) => write!(f, "Invalid feature in --cpus features list: {o}"),
ParseDevice(o) => write!(f, "Error parsing --device: {o}"),
ParseDevicePathMissing => write!(f, "Error parsing --device: path missing"),
ParseFileSystem(o) => write!(f, "Error parsing --fs: {}", o),
ParseFileSystem(o) => write!(f, "Error parsing --fs: {o}"),
ParseFsSockMissing => write!(f, "Error parsing --fs: socket missing"),
ParseFsTagMissing => write!(f, "Error parsing --fs: tag missing"),
ParsePersistentMemory(o) => write!(f, "Error parsing --pmem: {}", o),
ParsePersistentMemory(o) => write!(f, "Error parsing --pmem: {o}"),
ParsePmemFileMissing => write!(f, "Error parsing --pmem: file missing"),
ParseVsock(o) => write!(f, "Error parsing --vsock: {}", o),
ParseVsock(o) => write!(f, "Error parsing --vsock: {o}"),
ParseVsockCidMissing => write!(f, "Error parsing --vsock: cid missing"),
ParseVsockSockMissing => write!(f, "Error parsing --vsock: socket missing"),
ParseMemory(o) => write!(f, "Error parsing --memory: {}", o),
ParseMemoryZone(o) => write!(f, "Error parsing --memory-zone: {}", o),
ParseMemory(o) => write!(f, "Error parsing --memory: {o}"),
ParseMemoryZone(o) => write!(f, "Error parsing --memory-zone: {o}"),
ParseMemoryZoneIdMissing => write!(f, "Error parsing --memory-zone: id missing"),
ParseNetwork(o) => write!(f, "Error parsing --net: {}", o),
ParseDisk(o) => write!(f, "Error parsing --disk: {}", o),
ParseRng(o) => write!(f, "Error parsing --rng: {}", o),
ParseBalloon(o) => write!(f, "Error parsing --balloon: {}", o),
ParseRestore(o) => write!(f, "Error parsing --restore: {}", o),
ParseNetwork(o) => write!(f, "Error parsing --net: {o}"),
ParseDisk(o) => write!(f, "Error parsing --disk: {o}"),
ParseRng(o) => write!(f, "Error parsing --rng: {o}"),
ParseBalloon(o) => write!(f, "Error parsing --balloon: {o}"),
ParseRestore(o) => write!(f, "Error parsing --restore: {o}"),
#[cfg(target_arch = "x86_64")]
ParseSgxEpc(o) => write!(f, "Error parsing --sgx-epc: {}", o),
ParseSgxEpc(o) => write!(f, "Error parsing --sgx-epc: {o}"),
#[cfg(target_arch = "x86_64")]
ParseSgxEpcIdMissing => write!(f, "Error parsing --sgx-epc: id missing"),
ParseNuma(o) => write!(f, "Error parsing --numa: {}", o),
ParseNuma(o) => write!(f, "Error parsing --numa: {o}"),
ParseRestoreSourceUrlMissing => {
write!(f, "Error parsing --restore: source_url missing")
}
ParseUserDeviceSocketMissing => {
write!(f, "Error parsing --user-device: socket missing")
}
ParseUserDevice(o) => write!(f, "Error parsing --user-device: {}", o),
Validation(v) => write!(f, "Error validating configuration: {}", v),
ParseUserDevice(o) => write!(f, "Error parsing --user-device: {o}"),
Validation(v) => write!(f, "Error validating configuration: {v}"),
#[cfg(feature = "tdx")]
ParseTdx(o) => write!(f, "Error parsing --tdx: {}", o),
ParseTdx(o) => write!(f, "Error parsing --tdx: {o}"),
#[cfg(feature = "tdx")]
FirmwarePathMissing => write!(f, "TDX firmware missing"),
ParsePlatform(o) => write!(f, "Error parsing --platform: {}", o),
ParseVdpa(o) => write!(f, "Error parsing --vdpa: {}", o),
ParsePlatform(o) => write!(f, "Error parsing --platform: {o}"),
ParseVdpa(o) => write!(f, "Error parsing --vdpa: {o}"),
ParseVdpaPathMissing => write!(f, "Error parsing --vdpa: path missing"),
ParseTpm(o) => write!(f, "Error parsing --tpm: {}", o),
ParseTpm(o) => write!(f, "Error parsing --tpm: {o}"),
ParseTpmPathMissing => write!(f, "Error parsing --tpm: path missing"),
}
}

View File

@@ -848,7 +848,7 @@ impl CpuManager {
let handle = Some(
thread::Builder::new()
.name(format!("vcpu{}", vcpu_id))
.name(format!("vcpu{vcpu_id}"))
.spawn(move || {
// Schedule the thread to run on the expected CPU set
if let Some(cpuset) = cpuset.as_ref() {
@@ -1589,8 +1589,7 @@ impl CpuManager {
6 => 52,
_ => {
return Err(Error::TranslateVirtualAddress(anyhow!(format!(
"PA range not supported {}",
pa_range
"PA range not supported {pa_range}"
))))
}
};

View File

@@ -517,7 +517,7 @@ pub fn create_pty() -> io::Result<(File, File, PathBuf)> {
return vmm_sys_util::errno::errno_result().map_err(|e| e.into());
}
let proc_path = PathBuf::from(format!("/proc/self/fd/{}", sub_fd));
let proc_path = PathBuf::from(format!("/proc/self/fd/{sub_fd}"));
let path = read_link(proc_path)?;
// SAFETY: sub_fd is checked to be valid before being wrapped in File
@@ -665,15 +665,14 @@ impl DeviceRelocation for AddressManager {
return Err(io::Error::new(
io::ErrorKind::Other,
format!(
"Couldn't find a resource with base 0x{:x} for device {}",
old_base, id
"Couldn't find a resource with base 0x{old_base:x} for device {id}"
),
));
}
} else {
return Err(io::Error::new(
io::ErrorKind::Other,
format!("Couldn't find device {} from device tree", id),
format!("Couldn't find device {id} from device tree"),
));
}
}
@@ -687,7 +686,7 @@ impl DeviceRelocation for AddressManager {
self.vm.unregister_ioevent(event, &io_addr).map_err(|e| {
io::Error::new(
io::ErrorKind::Other,
format!("failed to unregister ioevent: {:?}", e),
format!("failed to unregister ioevent: {e:?}"),
)
})?;
}
@@ -698,7 +697,7 @@ impl DeviceRelocation for AddressManager {
.map_err(|e| {
io::Error::new(
io::ErrorKind::Other,
format!("failed to register ioevent: {:?}", e),
format!("failed to register ioevent: {e:?}"),
)
})?;
}
@@ -719,7 +718,7 @@ impl DeviceRelocation for AddressManager {
self.vm.remove_user_memory_region(mem_region).map_err(|e| {
io::Error::new(
io::ErrorKind::Other,
format!("failed to remove user memory region: {:?}", e),
format!("failed to remove user memory region: {e:?}"),
)
})?;
@@ -736,7 +735,7 @@ impl DeviceRelocation for AddressManager {
self.vm.create_user_memory_region(mem_region).map_err(|e| {
io::Error::new(
io::ErrorKind::Other,
format!("failed to create user memory regions: {:?}", e),
format!("failed to create user memory regions: {e:?}"),
)
})?;
@@ -745,7 +744,7 @@ impl DeviceRelocation for AddressManager {
virtio_dev.set_shm_regions(shm_regions).map_err(|e| {
io::Error::new(
io::ErrorKind::Other,
format!("failed to update shared memory regions: {:?}", e),
format!("failed to update shared memory regions: {e:?}"),
)
})?;
}
@@ -3435,7 +3434,7 @@ impl DeviceManager {
pci_segment_id: u16,
dma_handler: Option<Arc<dyn ExternalDmaMapping>>,
) -> DeviceManagerResult<PciBdf> {
let id = format!("{}-{}", VIRTIO_PCI_DEVICE_NAME_PREFIX, virtio_device_id);
let id = format!("{VIRTIO_PCI_DEVICE_NAME_PREFIX}-{virtio_device_id}");
// Add the new virtio-pci node to the device tree.
let mut node = device_node!(id);
@@ -4237,7 +4236,7 @@ impl Aml for DeviceManager {
let mut pci_scan_methods = Vec::new();
for i in 0..self.pci_segments.len() {
pci_scan_methods.push(aml::MethodCall::new(
format!("\\_SB_.PCI{:X}.PCNT", i).as_str().into(),
format!("\\_SB_.PCI{i:X}.PCNT").as_str().into(),
vec![],
));
}

View File

@@ -294,8 +294,8 @@ impl MultiThreadBase for GdbStub {
});
Ok(())
}
Ok(s) => Err(format!("Unexpected response for ActiveVcpus: {:?}", s)),
Err(e) => Err(format!("Failed to request ActiveVcpus: {:?}", e)),
Ok(s) => Err(format!("Unexpected response for ActiveVcpus: {s:?}")),
Err(e) => Err(format!("Failed to request ActiveVcpus: {e:?}")),
}
}
@@ -309,7 +309,7 @@ impl MultiThreadResume for GdbStub {
fn resume(&mut self) -> Result<(), Self::Error> {
match self.vm_request(GdbRequestPayload::Resume, 0) {
Ok(_) => Ok(()),
Err(e) => Err(format!("Failed to resume the target: {:?}", e)),
Err(e) => Err(format!("Failed to resume the target: {e:?}")),
}
}
@@ -320,7 +320,7 @@ impl MultiThreadResume for GdbStub {
self.single_step = false;
}
Err(e) => {
return Err(format!("Failed to request SetSingleStep: {:?}", e));
return Err(format!("Failed to request SetSingleStep: {e:?}"));
}
}
}
@@ -337,7 +337,7 @@ impl MultiThreadResume for GdbStub {
}
match self.vm_request(GdbRequestPayload::Resume, tid_to_cpuid(tid)) {
Ok(_) => Ok(()),
Err(e) => Err(format!("Failed to resume the target: {:?}", e)),
Err(e) => Err(format!("Failed to resume the target: {e:?}")),
}
}
@@ -363,13 +363,13 @@ impl MultiThreadSingleStep for GdbStub {
self.single_step = true;
}
Err(e) => {
return Err(format!("Failed to request SetSingleStep: {:?}", e));
return Err(format!("Failed to request SetSingleStep: {e:?}"));
}
}
}
match self.vm_request(GdbRequestPayload::Resume, tid_to_cpuid(tid)) {
Ok(_) => Ok(()),
Err(e) => Err(format!("Failed to resume the target: {:?}", e)),
Err(e) => Err(format!("Failed to resume the target: {e:?}")),
}
}
}

View File

@@ -44,7 +44,7 @@ impl InterruptRoute {
vm.register_irqfd(&self.irq_fd, self.gsi).map_err(|e| {
io::Error::new(
io::ErrorKind::Other,
format!("Failed registering irq_fd: {}", e),
format!("Failed registering irq_fd: {e}"),
)
})?;
@@ -60,7 +60,7 @@ impl InterruptRoute {
vm.unregister_irqfd(&self.irq_fd, self.gsi).map_err(|e| {
io::Error::new(
io::ErrorKind::Other,
format!("Failed unregistering irq_fd: {}", e),
format!("Failed unregistering irq_fd: {e}"),
)
})?;
@@ -109,7 +109,7 @@ impl MsiInterruptGroup {
self.vm.set_gsi_routing(&entry_vec).map_err(|e| {
io::Error::new(
io::ErrorKind::Other,
format!("Failed setting GSI routing: {}", e),
format!("Failed setting GSI routing: {e}"),
)
})
}
@@ -153,7 +153,7 @@ impl InterruptSourceGroup for MsiInterruptGroup {
Err(io::Error::new(
io::ErrorKind::Other,
format!("trigger: Invalid interrupt index {}", index),
format!("trigger: Invalid interrupt index {index}"),
))
}
@@ -188,7 +188,7 @@ impl InterruptSourceGroup for MsiInterruptGroup {
Err(io::Error::new(
io::ErrorKind::Other,
format!("update: Invalid interrupt index {}", index),
format!("update: Invalid interrupt index {index}"),
))
}
}

View File

@@ -109,8 +109,7 @@ fn sigwinch_listener_main(seccomp_filter: BpfProgram, tx: File, pty: File) -> !
let e = io::Error::last_os_error();
assert!(
matches!(e.kind(), ErrorKind::Interrupted | ErrorKind::WouldBlock),
"poll: {}",
e
"poll: {e}"
);
}

View File

@@ -862,9 +862,7 @@ impl Vm {
.map_err(|_| Error::InitramfsLoad)?
.try_into()
.unwrap();
initramfs
.seek(SeekFrom::Start(0))
.map_err(|_| Error::InitramfsLoad)?;
initramfs.rewind().map_err(|_| Error::InitramfsLoad)?;
let address =
arch::initramfs_load_addr(guest_mem, size).map_err(|_| Error::InitramfsLoad)?;
@@ -1829,9 +1827,7 @@ impl Vm {
return Err(Error::InvalidPayloadType);
}
payload_file
.seek(SeekFrom::Start(0))
.map_err(Error::LoadPayload)?;
payload_file.rewind().map_err(Error::LoadPayload)?;
mem.read_from(
GuestAddress(section.address),
payload_file,
@@ -3174,7 +3170,7 @@ pub fn test_vm() {
println!("HLT");
break;
}
r => panic!("unexpected exit reason: {:?}", r),
r => panic!("unexpected exit reason: {r:?}"),
}
}
}