vm-virtio: trim qualified paths

Import the std modules used in the crate instead of spelling the full
paths at every use site.

Signed-off-by: Henry Hrvoje Tonkovac <htonkovac@gmail.com>
Assisted-by: Claude:Opus-4.8
This commit is contained in:
Henry Hrvoje Tonkovac
2026-06-16 12:17:05 +02:00
committed by Rob Bradford
parent 88baef1449
commit 0e2e8d332a
2 changed files with 17 additions and 14 deletions

View File

@@ -179,6 +179,8 @@ where
#[cfg(test)]
mod unit_tests {
use std::io;
use virtio_bindings::virtio_ring::{VRING_DESC_F_NEXT, VRING_DESC_F_WRITE};
use virtio_queue::{Queue, QueueT};
use vm_memory::bitmap::AtomicBitmap;
@@ -401,10 +403,10 @@ mod unit_tests {
}
impl AccessPlatform for OffsetTranslator {
fn translate_gva(&self, base: u64, _size: u64) -> std::io::Result<u64> {
fn translate_gva(&self, base: u64, _size: u64) -> io::Result<u64> {
Ok(base - self.gva_base + self.gpa_base)
}
fn translate_gpa(&self, base: u64, _size: u64) -> std::io::Result<u64> {
fn translate_gpa(&self, base: u64, _size: u64) -> io::Result<u64> {
Ok(base - self.gpa_base + self.gva_base)
}
}
@@ -436,11 +438,11 @@ mod unit_tests {
struct FailingTranslator;
impl AccessPlatform for FailingTranslator {
fn translate_gva(&self, _base: u64, _size: u64) -> std::io::Result<u64> {
Err(std::io::Error::other("translation failed"))
fn translate_gva(&self, _base: u64, _size: u64) -> io::Result<u64> {
Err(io::Error::other("translation failed"))
}
fn translate_gpa(&self, _base: u64, _size: u64) -> std::io::Result<u64> {
Err(std::io::Error::other("translation failed"))
fn translate_gpa(&self, _base: u64, _size: u64) -> io::Result<u64> {
Err(io::Error::other("translation failed"))
}
}

View File

@@ -11,6 +11,7 @@
//! Implements virtio queues
use std::fmt::{self, Debug};
use std::io;
use virtio_queue::{Queue, QueueT};
use vm_memory::GuestAddress;
@@ -97,9 +98,9 @@ impl fmt::Display for VirtioDeviceType {
/// translated.
pub trait AccessPlatform: Send + Sync + Debug {
/// Provide a way to translate GVA address ranges into GPAs.
fn translate_gva(&self, base: u64, size: u64) -> std::result::Result<u64, std::io::Error>;
fn translate_gva(&self, base: u64, size: u64) -> io::Result<u64>;
/// Provide a way to translate GPA address ranges into GVAs.
fn translate_gpa(&self, base: u64, size: u64) -> std::result::Result<u64, std::io::Error>;
fn translate_gpa(&self, base: u64, size: u64) -> io::Result<u64>;
}
pub trait Translatable {
@@ -107,14 +108,14 @@ pub trait Translatable {
&self,
access_platform: Option<&dyn AccessPlatform>,
len: usize,
) -> std::result::Result<Self, std::io::Error>
) -> io::Result<Self>
where
Self: Sized;
fn translate_gpa(
&self,
access_platform: Option<&dyn AccessPlatform>,
len: usize,
) -> std::result::Result<Self, std::io::Error>
) -> io::Result<Self>
where
Self: Sized;
}
@@ -124,14 +125,14 @@ impl Translatable for GuestAddress {
&self,
access_platform: Option<&dyn AccessPlatform>,
len: usize,
) -> std::result::Result<Self, std::io::Error> {
) -> io::Result<Self> {
Ok(GuestAddress(self.0.translate_gva(access_platform, len)?))
}
fn translate_gpa(
&self,
access_platform: Option<&dyn AccessPlatform>,
len: usize,
) -> std::result::Result<Self, std::io::Error> {
) -> io::Result<Self> {
Ok(GuestAddress(self.0.translate_gpa(access_platform, len)?))
}
}
@@ -141,7 +142,7 @@ impl Translatable for u64 {
&self,
access_platform: Option<&dyn AccessPlatform>,
len: usize,
) -> std::result::Result<Self, std::io::Error> {
) -> io::Result<Self> {
if let Some(access_platform) = access_platform {
access_platform.translate_gva(*self, len as u64)
} else {
@@ -152,7 +153,7 @@ impl Translatable for u64 {
&self,
access_platform: Option<&dyn AccessPlatform>,
len: usize,
) -> std::result::Result<Self, std::io::Error> {
) -> io::Result<Self> {
if let Some(access_platform) = access_platform {
access_platform.translate_gpa(*self, len as u64)
} else {