mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: trim qualified paths in io and lib
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:
committed by
Rob Bradford
parent
b51dfec09c
commit
e5f32e986f
@@ -13,7 +13,7 @@ mod owned_io_buffer;
|
||||
#[cfg(feature = "io_uring")]
|
||||
mod uring_data_io;
|
||||
|
||||
use std::io;
|
||||
use std::{io, result};
|
||||
|
||||
pub use aio_data_io::AioDataIo;
|
||||
pub use completion::AsyncIoCompletion;
|
||||
@@ -31,21 +31,21 @@ use crate::SECTOR_SIZE;
|
||||
pub enum DiskFileError {
|
||||
/// Failed getting disk file size.
|
||||
#[error("Failed getting disk file size")]
|
||||
Size(#[source] std::io::Error),
|
||||
Size(#[source] io::Error),
|
||||
/// Failed creating a new AsyncIo.
|
||||
#[error("Failed creating a new AsyncIo")]
|
||||
NewAsyncIo(#[source] std::io::Error),
|
||||
NewAsyncIo(#[source] io::Error),
|
||||
/// Unsupported operation.
|
||||
#[error("Unsupported operation")]
|
||||
Unsupported,
|
||||
/// Resize failed
|
||||
#[error("Resize failed")]
|
||||
ResizeError(#[source] std::io::Error),
|
||||
ResizeError(#[source] io::Error),
|
||||
#[error("Failed cloning disk file")]
|
||||
Clone(#[source] std::io::Error),
|
||||
Clone(#[source] io::Error),
|
||||
}
|
||||
|
||||
pub type DiskFileResult<T> = std::result::Result<T, DiskFileError>;
|
||||
pub type DiskFileResult<T> = result::Result<T, DiskFileError>;
|
||||
|
||||
/// A wrapper for [`RawFd`] capturing the lifetime of a corresponding disk file.
|
||||
///
|
||||
@@ -79,25 +79,25 @@ impl AsRawFd for BorrowedDiskFd<'_> {
|
||||
pub enum AsyncIoError {
|
||||
/// Failed vectored reading from file.
|
||||
#[error("Failed vectored reading from file")]
|
||||
ReadVectored(#[source] std::io::Error),
|
||||
ReadVectored(#[source] io::Error),
|
||||
/// Failed vectored writing to file.
|
||||
#[error("Failed vectored writing to file")]
|
||||
WriteVectored(#[source] std::io::Error),
|
||||
WriteVectored(#[source] io::Error),
|
||||
/// Failed synchronizing file.
|
||||
#[error("Failed synchronizing file")]
|
||||
Fsync(#[source] std::io::Error),
|
||||
Fsync(#[source] io::Error),
|
||||
/// Failed punching hole.
|
||||
#[error("Failed punching hole")]
|
||||
PunchHole(#[source] std::io::Error),
|
||||
PunchHole(#[source] io::Error),
|
||||
/// Failed writing zeroes.
|
||||
#[error("Failed writing zeroes")]
|
||||
WriteZeroes(#[source] std::io::Error),
|
||||
WriteZeroes(#[source] io::Error),
|
||||
/// Failed submitting batch requests.
|
||||
#[error("Failed submitting batch requests")]
|
||||
SubmitBatchRequests(#[source] std::io::Error),
|
||||
SubmitBatchRequests(#[source] io::Error),
|
||||
}
|
||||
|
||||
pub type AsyncIoResult<T> = std::result::Result<T, AsyncIoError>;
|
||||
pub type AsyncIoResult<T> = result::Result<T, AsyncIoError>;
|
||||
|
||||
pub trait AsyncIo: Send {
|
||||
fn notifier(&self) -> &EventFd;
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
||||
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
use std::io;
|
||||
use std::os::fd::{AsRawFd, RawFd};
|
||||
use std::{io, slice};
|
||||
|
||||
use log::warn;
|
||||
use vmm_sys_util::aio;
|
||||
@@ -66,7 +66,7 @@ impl AioDataIo {
|
||||
pub fn submit_operation(&mut self, fd: RawFd, op: AsyncIoOperation) -> io::Result<()> {
|
||||
validate_batch(
|
||||
|user_data| self.in_flight.contains_key(&user_data),
|
||||
std::slice::from_ref(&op),
|
||||
slice::from_ref(&op),
|
||||
)?;
|
||||
|
||||
let user_data = op.user_data();
|
||||
@@ -171,7 +171,7 @@ impl AioDataIo {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::io::Write;
|
||||
use std::io::{self, Write};
|
||||
use std::os::fd::AsRawFd;
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
@@ -208,7 +208,7 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
data_io.submit_fsync(fd, 7).unwrap_err().kind(),
|
||||
std::io::ErrorKind::AlreadyExists
|
||||
io::ErrorKind::AlreadyExists
|
||||
);
|
||||
|
||||
let completion = wait_for_completion(&mut data_io);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
||||
|
||||
use std::alloc::{Layout, alloc_zeroed, dealloc};
|
||||
use std::{fmt, io};
|
||||
use std::{fmt, io, slice};
|
||||
|
||||
// Storage owned by an async I/O request for host-memory buffers.
|
||||
//
|
||||
@@ -62,7 +62,7 @@ impl OwnedIoBufferStorage {
|
||||
Self::Aligned { ptr, len, .. } => {
|
||||
// SAFETY: alloc_zeroed initialized `len` bytes at `ptr` and the
|
||||
// allocation is owned by Self.
|
||||
unsafe { std::slice::from_raw_parts(*ptr, *len) }
|
||||
unsafe { slice::from_raw_parts(*ptr, *len) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ impl OwnedIoBufferStorage {
|
||||
// SAFETY: alloc_zeroed initialized `len` bytes at `ptr`,
|
||||
// &mut self ensures unique access, and the allocation is
|
||||
// owned by Self.
|
||||
unsafe { std::slice::from_raw_parts_mut(*ptr, *len) }
|
||||
unsafe { slice::from_raw_parts_mut(*ptr, *len) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,6 +272,7 @@ impl UringDataIo {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::io;
|
||||
use std::os::fd::AsRawFd;
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
@@ -308,18 +309,18 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
data_io.submit_fsync(fd, 7).unwrap_err().kind(),
|
||||
std::io::ErrorKind::AlreadyExists
|
||||
io::ErrorKind::AlreadyExists
|
||||
);
|
||||
assert_eq!(
|
||||
data_io.submit_nop(7).unwrap_err().kind(),
|
||||
std::io::ErrorKind::AlreadyExists
|
||||
io::ErrorKind::AlreadyExists
|
||||
);
|
||||
assert_eq!(
|
||||
data_io
|
||||
.submit_fallocate(fd, 0, 512, 0, 7)
|
||||
.unwrap_err()
|
||||
.kind(),
|
||||
std::io::ErrorKind::AlreadyExists
|
||||
io::ErrorKind::AlreadyExists
|
||||
);
|
||||
|
||||
let completion = wait_for_completion(&mut data_io);
|
||||
|
||||
@@ -504,7 +504,7 @@ impl Request {
|
||||
for &(data_addr, data_len) in &self.data_descriptors {
|
||||
let _: u32 = data_len;
|
||||
const _: () = assert!(
|
||||
core::mem::size_of::<u32>() <= core::mem::size_of::<usize>(),
|
||||
mem::size_of::<u32>() <= mem::size_of::<usize>(),
|
||||
"unsupported platform"
|
||||
);
|
||||
if data_len == 0 {
|
||||
|
||||
Reference in New Issue
Block a user