vm-migration: 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-09 15:55:55 +02:00
committed by Rob Bradford
parent 2fc37a3235
commit 4b2a77b86e
2 changed files with 23 additions and 19 deletions
+19 -16
View File
@@ -3,6 +3,9 @@
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
// //
use std::collections::BTreeMap;
use std::{io, result};
use anyhow::anyhow; use anyhow::anyhow;
pub use context::{ pub use context::{
CompletedMigrationContext, DowntimeContext, MemoryMigrationContext, MigrationContextError, CompletedMigrationContext, DowntimeContext, MemoryMigrationContext, MigrationContextError,
@@ -23,7 +26,7 @@ pub enum UffdError {
UnalignedRanges, UnalignedRanges,
#[error("Failed to create userfaultfd")] #[error("Failed to create userfaultfd")]
Create(#[source] std::io::Error), Create(#[source] io::Error),
#[error("Cannot translate GPA {gpa:#x} to host address")] #[error("Cannot translate GPA {gpa:#x} to host address")]
GpaTranslation { GpaTranslation {
@@ -37,20 +40,20 @@ pub enum UffdError {
addr: u64, addr: u64,
len: u64, len: u64,
#[source] #[source]
source: std::io::Error, source: io::Error,
}, },
#[error("Region at {addr:#x}+{len:#x} missing COPY/WAKE support")] #[error("Region at {addr:#x}+{len:#x} missing COPY/WAKE support")]
MissingIoctlSupport { addr: u64, len: u64 }, MissingIoctlSupport { addr: u64, len: u64 },
#[error("Failed to spawn handler thread")] #[error("Failed to spawn handler thread")]
SpawnThread(#[source] std::io::Error), SpawnThread(#[source] io::Error),
#[error("Handler terminated before startup completed")] #[error("Handler terminated before startup completed")]
HandlerStartup, HandlerStartup,
#[error("Handler failed after startup")] #[error("Handler failed after startup")]
HandlerFailed(#[source] std::io::Error), HandlerFailed(#[source] io::Error),
} }
#[derive(Error, Debug)] #[derive(Error, Debug)]
@@ -77,7 +80,7 @@ pub enum MigratableError {
OnDemandRestore(#[source] UffdError), OnDemandRestore(#[source] UffdError),
#[error("Socket error")] #[error("Socket error")]
MigrateSocket(#[source] std::io::Error), MigrateSocket(#[source] io::Error),
#[error("Failed to start migration for migratable component")] #[error("Failed to start migration for migratable component")]
StartDirtyLog(#[source] anyhow::Error), StartDirtyLog(#[source] anyhow::Error),
@@ -104,12 +107,12 @@ pub enum MigratableError {
/// A Pausable component can be paused and resumed. /// A Pausable component can be paused and resumed.
pub trait Pausable { pub trait Pausable {
/// Pause the component. /// Pause the component.
fn pause(&mut self) -> std::result::Result<(), MigratableError> { fn pause(&mut self) -> result::Result<(), MigratableError> {
Ok(()) Ok(())
} }
/// Resume the component. /// Resume the component.
fn resume(&mut self) -> std::result::Result<(), MigratableError> { fn resume(&mut self) -> result::Result<(), MigratableError> {
Ok(()) Ok(())
} }
} }
@@ -163,7 +166,7 @@ impl SnapshotData {
#[derive(Clone, Default, Deserialize, Serialize)] #[derive(Clone, Default, Deserialize, Serialize)]
pub struct Snapshot { pub struct Snapshot {
/// The Snapshottable component snapshots. /// The Snapshottable component snapshots.
pub snapshots: std::collections::BTreeMap<String, Snapshot>, pub snapshots: BTreeMap<String, Snapshot>,
/// The Snapshottable component's snapshot data. /// The Snapshottable component's snapshot data.
/// A map of snapshot sections, indexed by the section ids. /// A map of snapshot sections, indexed by the section ids.
@@ -226,7 +229,7 @@ pub trait Snapshottable: Pausable {
} }
/// Take a component snapshot. /// Take a component snapshot.
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> result::Result<Snapshot, MigratableError> {
Ok(Snapshot::default()) Ok(Snapshot::default())
} }
} }
@@ -247,7 +250,7 @@ pub trait Transportable: Pausable + Snapshottable {
&self, &self,
_snapshot: &Snapshot, _snapshot: &Snapshot,
_destination_url: &str, _destination_url: &str,
) -> std::result::Result<(), MigratableError> { ) -> result::Result<(), MigratableError> {
Ok(()) Ok(())
} }
@@ -257,7 +260,7 @@ pub trait Transportable: Pausable + Snapshottable {
/// ///
/// * `source_url` - The source URL to fetch the snapshot from. This could be an HTTP /// * `source_url` - The source URL to fetch the snapshot from. This could be an HTTP
/// endpoint, a TCP address or a local file. /// endpoint, a TCP address or a local file.
fn recv(&self, _source_url: &str) -> std::result::Result<Snapshot, MigratableError> { fn recv(&self, _source_url: &str) -> result::Result<Snapshot, MigratableError> {
Ok(Snapshot::default()) Ok(Snapshot::default())
} }
} }
@@ -271,23 +274,23 @@ pub trait Transportable: Pausable + Snapshottable {
/// Moreover a migratable component can be transported to a remote or local /// Moreover a migratable component can be transported to a remote or local
/// destination and thus must be Transportable. /// destination and thus must be Transportable.
pub trait Migratable: Send + Pausable + Snapshottable + Transportable { pub trait Migratable: Send + Pausable + Snapshottable + Transportable {
fn start_dirty_log(&mut self) -> std::result::Result<(), MigratableError> { fn start_dirty_log(&mut self) -> result::Result<(), MigratableError> {
Ok(()) Ok(())
} }
fn stop_dirty_log(&mut self) -> std::result::Result<(), MigratableError> { fn stop_dirty_log(&mut self) -> result::Result<(), MigratableError> {
Ok(()) Ok(())
} }
fn dirty_log(&mut self) -> std::result::Result<MemoryRangeTable, MigratableError> { fn dirty_log(&mut self) -> result::Result<MemoryRangeTable, MigratableError> {
Ok(MemoryRangeTable::default()) Ok(MemoryRangeTable::default())
} }
fn start_migration(&mut self) -> std::result::Result<(), MigratableError> { fn start_migration(&mut self) -> result::Result<(), MigratableError> {
Ok(()) Ok(())
} }
fn complete_migration(&mut self) -> std::result::Result<(), MigratableError> { fn complete_migration(&mut self) -> result::Result<(), MigratableError> {
Ok(()) Ok(())
} }
} }
+4 -3
View File
@@ -75,6 +75,7 @@
//! ``` //! ```
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::{mem, slice};
use itertools::Itertools; use itertools::Itertools;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -440,7 +441,7 @@ impl MemoryRangeTable {
// `MemoryRange`s so the memory is valid for `length` bytes. // `MemoryRange`s so the memory is valid for `length` bytes.
// During the lifetime of the slice, neither the backing vector nor the pointed to memory are accessed. // During the lifetime of the slice, neither the backing vector nor the pointed to memory are accessed.
let data_slice_bytes = let data_slice_bytes =
unsafe { std::slice::from_raw_parts_mut(data.as_mut_ptr().cast(), length as usize) }; unsafe { slice::from_raw_parts_mut(data.as_mut_ptr().cast(), length as usize) };
fd.read_exact(data_slice_bytes) fd.read_exact(data_slice_bytes)
.map_err(MigratableError::MigrateSocket)?; .map_err(MigratableError::MigrateSocket)?;
@@ -449,13 +450,13 @@ impl MemoryRangeTable {
} }
pub fn length(&self) -> u64 { pub fn length(&self) -> u64 {
(std::mem::size_of::<MemoryRange>() * self.data.len()) as u64 (mem::size_of::<MemoryRange>() * self.data.len()) as u64
} }
pub fn write_to(&self, fd: &mut dyn Write) -> Result<(), MigratableError> { pub fn write_to(&self, fd: &mut dyn Write) -> Result<(), MigratableError> {
// SAFETY: the slice is constructed with the correct arguments // SAFETY: the slice is constructed with the correct arguments
fd.write_all(unsafe { fd.write_all(unsafe {
std::slice::from_raw_parts(self.data.as_ptr().cast(), self.length() as usize) slice::from_raw_parts(self.data.as_ptr().cast(), self.length() as usize)
}) })
.map_err(MigratableError::MigrateSocket) .map_err(MigratableError::MigrateSocket)
} }