vm-linux/guest/sdk: clear clippy -D warnings on Linux

The Linux CI leg runs cargo check, not clippy, so the experimental KVM
backend and the guest/sdk had accumulated lint debt that only surfaced
under a full clippy pass on the Linux hosts. All mechanical and
behavior-preserving: drop unused imports, prune no-op operations, first()
over get(0), c"" literals for nul-terminated strings, iterate slices
instead of indexing. The platform-dependent casts stay (c_char signedness
differs by arch; the FUSE protocol structs are defined whole) behind
scoped allows that explain why.

Co-authored-by: Hanzo Dev <[email protected]>
This commit is contained in:
2026-09-01 22:10:18 -07:00
co-authored by Hanzo Dev
parent e17dacb9ea
commit 405355ee56
8 changed files with 31 additions and 21 deletions
+3
View File
@@ -184,6 +184,9 @@ mod guest {
Ok(())
}
// ifr_name is c_char: unsigned on aarch64 (cast is a no-op there),
// signed on x86_64 (cast is required). Keep the cast for both arches.
#[allow(clippy::unnecessary_cast)]
fn bring_up_interface(sock: i32, name: &[u8]) {
unsafe {
let mut ifr: libc::ifreq = std::mem::zeroed();
+5 -8
View File
@@ -1120,12 +1120,8 @@ impl VirtioBackend for VhostVsockBackend {
irq: u32,
_interrupt_status: Arc<AtomicU32>,
) {
let vhost_fd = unsafe {
libc::open(
b"/dev/vhost-vsock\0".as_ptr() as *const libc::c_char,
libc::O_RDWR | libc::O_CLOEXEC,
)
};
let vhost_fd =
unsafe { libc::open(c"/dev/vhost-vsock".as_ptr(), libc::O_RDWR | libc::O_CLOEXEC) };
if vhost_fd < 0 {
eprintln!(
"hanzo-vm: failed to open /dev/vhost-vsock: {}",
@@ -1147,7 +1143,8 @@ impl VirtioBackend for VhostVsockBackend {
}
// Negotiate features — get supported, intersect, set
let get_features: u64 = (2u64 << 30) | (8u64 << 16) | (VHOST_VIRTIO << 8) | 0x00;
// _IOR(VHOST_VIRTIO, 0, u64): dir=read<<30, size=8<<16, type<<8, nr=0.
let get_features: u64 = (2u64 << 30) | (8u64 << 16) | (VHOST_VIRTIO << 8);
let mut avail_features: u64 = 0;
libc::ioctl(vhost_fd, get_features, &mut avail_features);
let features = avail_features & VIRTIO_F_VERSION_1;
@@ -1258,7 +1255,7 @@ impl VirtioBackend for VhostVsockBackend {
self.irq_running.store(true, Ordering::Release);
let irq_running = self.irq_running.clone();
let vm_fd_clone = vm_fd.clone();
let call_fd_0 = self.call_evts.get(0).map(|e| e.as_raw_fd()).unwrap_or(-1);
let call_fd_0 = self.call_evts.first().map(|e| e.as_raw_fd()).unwrap_or(-1);
let call_fd_1 = self.call_evts.get(1).map(|e| e.as_raw_fd()).unwrap_or(-1);
let shutdown_fd = self.shutdown_evt.as_raw_fd();
self.irq_thread = std::thread::Builder::new()
+4 -4
View File
@@ -1,7 +1,7 @@
/// aarch64 memory map for the KVM virtual machine.
///
/// Below DRAM_BASE is MMIO space for devices.
/// DRAM starts at 1 GiB and extends for the configured memory size.
// aarch64 memory map for the KVM virtual machine.
//
// Below DRAM_BASE is MMIO space for devices.
// DRAM starts at 1 GiB and extends for the configured memory size.
// RAM
pub const DRAM_BASE: u64 = 0x4000_0000; // 1 GiB
+3 -1
View File
@@ -28,7 +28,9 @@ use kvm_bindings::{KVM_DEV_ARM_VGIC_GRP_ADDR, KVM_DEV_ARM_VGIC_GRP_CTRL};
pub struct KvmVm {
#[allow(dead_code)]
pub kvm: Kvm,
#[allow(dead_code)]
pub vm_fd: Arc<VmFd>,
#[allow(dead_code)]
pub mem: GuestMemoryMmap,
pub bus: Arc<Mutex<MmioBus>>,
pub vcpus: Vec<VcpuFd>,
@@ -551,7 +553,7 @@ fn vcpu_run_loop(mut vcpu: VcpuFd, bus: Arc<Mutex<MmioBus>>, running: Arc<Atomic
// Install empty handler for SIGRTMIN so KVM_RUN returns EINTR on stop
unsafe {
let mut sa: libc::sigaction = std::mem::zeroed();
sa.sa_sigaction = empty_signal_handler as usize;
sa.sa_sigaction = empty_signal_handler as *const () as usize;
sa.sa_flags = libc::SA_SIGINFO;
libc::sigaction(libc::SIGRTMIN(), &sa, std::ptr::null_mut());
}
+11 -4
View File
@@ -10,17 +10,24 @@
//! OPENDIR/READDIR(PLUS), CREATE, UNLINK/MKDIR/RMDIR/RENAME, STATFS,
//! xattr ops (ENOSYS). Anything else returns ENOSYS; the kernel falls back
//! gracefully.
//!
//! FUSE wire structs and a few helpers are defined for the whole protocol
//! even where this minimal client path never constructs them, and the
//! `meta.*() as u32` conversions are written uniformly though some widths
//! already match on this target — clippy's dead-code and cast lints are
//! silenced here rather than pruning protocol definitions op by op.
#![allow(dead_code, clippy::unnecessary_cast, clippy::collapsible_if)]
use std::collections::HashMap;
use std::ffi::{CStr, CString, OsStr, OsString};
use std::os::unix::ffi::{OsStrExt, OsStringExt};
use std::ffi::{CString, OsStr};
use std::os::unix::ffi::OsStrExt;
use std::os::unix::fs::MetadataExt;
use std::path::{Component, Path, PathBuf};
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicU32, AtomicU64, Ordering};
use std::sync::{Arc, Mutex};
use kvm_ioctls::VmFd;
use vm_memory::{Address, Bytes, GuestAddress, GuestMemoryMmap};
use vm_memory::{Bytes, GuestAddress, GuestMemoryMmap};
use super::devices::{avail_idx, avail_ring_entry, write_used, VirtioBackend, VirtioQueueState};
+1 -1
View File
@@ -25,7 +25,7 @@ impl MACAddress {
/// Generate a random locally-administered MAC address.
pub fn random_local() -> Self {
let mut bytes = [0u8; 6];
let fd = unsafe { libc::open(b"/dev/urandom\0".as_ptr() as *const _, libc::O_RDONLY) };
let fd = unsafe { libc::open(c"/dev/urandom".as_ptr(), libc::O_RDONLY) };
if fd >= 0 {
unsafe {
libc::read(fd, bytes.as_mut_ptr() as *mut libc::c_void, 6);
+2 -2
View File
@@ -192,8 +192,8 @@ impl StdinRelay {
return StdinEvent::Shutdown;
}
for i in 0..n as usize {
match events[i].u64 {
for ev in &events[..n as usize] {
match ev.u64 {
EV_STDIN => return StdinEvent::Ready,
EV_PIPE => return StdinEvent::Shutdown,
EV_SIGNAL => {
+2 -1
View File
@@ -3,7 +3,7 @@ use std::io::{BufReader, Read, Write};
use std::net::TcpStream;
use std::sync::Arc;
use anyhow::{bail, Context, Result};
use anyhow::{bail, Result};
use tokio::sync::{mpsc, oneshot};
use tracing::info;
@@ -712,6 +712,7 @@ extern "C" {
#[cfg(target_os = "macos")]
fn clone_file_cow(src: &str, dst: &str) -> Result<()> {
use anyhow::Context as _;
let c_src = std::ffi::CString::new(src).context("invalid source path")?;
let c_dst = std::ffi::CString::new(dst).context("invalid destination path")?;
let ret = unsafe { clonefile(c_src.as_ptr(), c_dst.as_ptr(), 0) };