Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Prerequisite for proper device manager. #4509

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(mmio): move MMIODeviceManager into separate module
MMIODeviceManager's implementation was spread across 2 modules:
mmio.rs and persist.rs. By moving all implementation into mmio
module we wil have an easir time when it comes to add more
device managers (e.g. ACPI device_manager).

Signed-off-by: Egor Lazarchuk <[email protected]>
  • Loading branch information
ShadowCurse committed Mar 16, 2024
commit e7a4972c0dace196b51e8c9c9650dbeba4eb4156
2 changes: 1 addition & 1 deletion src/vmm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 34,8 @@ use crate::cpu_config::templates::{
};
#[cfg(target_arch = "x86_64")]
use crate::device_manager::legacy::PortIODeviceManager;
use crate::device_manager::mmio::persist::MMIODevManagerConstructorArgs;
use crate::device_manager::mmio::MMIODeviceManager;
use crate::device_manager::persist::MMIODevManagerConstructorArgs;
use crate::device_manager::DeviceManager;
#[cfg(target_arch = "aarch64")]
use crate::devices::legacy::RTCDevice;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 29,9 @@ use crate::devices::virtio::vsock::TYPE_VSOCK;
use crate::devices::virtio::{TYPE_BALLOON, TYPE_BLOCK, TYPE_NET, TYPE_RNG};
use crate::devices::BusDevice;

/// Persis logic for MMIODeviceManager.
pub mod persist;

/// Errors for MMIO device manager.
#[derive(Debug, thiserror::Error, displaydoc::Display)]
pub enum MmioError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 12,9 @@ use log::{error, warn};
use serde::{Deserialize, Serialize};
use vm_allocator::AllocPolicy;

use super::mmio::*;
#[cfg(target_arch = "aarch64")]
use crate::arch::DeviceType;
use crate::device_manager::mmio::*;
#[cfg(target_arch = "aarch64")]
use crate::devices::legacy::SerialDevice;
use crate::devices::virtio::balloon::persist::{BalloonConstructorArgs, BalloonState};
Expand Down Expand Up @@ -57,7 57,7 @@ pub enum DevicePersistError {
/// Block: {0}
Block(#[from] BlockError),
/// Device manager: {0}
DeviceManager(#[from] super::mmio::MmioError),
DeviceManager(#[from] MmioError),
/// Mmio transport
MmioTransport,
#[cfg(target_arch = "aarch64")]
Expand Down Expand Up @@ -383,9 383,7 @@ impl<'a> Persist<'a> for MMIODeviceManager {
MMIO_LEN,
AllocPolicy::ExactMatch(state.device_info.addr),
)
.map_err(|e| {
DevicePersistError::DeviceManager(super::mmio::MmioError::Allocator(e))
})?;
.map_err(|e| DevicePersistError::DeviceManager(MmioError::Allocator(e)))?;

state
.device_info
Expand Down Expand Up @@ -414,9 412,7 @@ impl<'a> Persist<'a> for MMIODeviceManager {
MMIO_LEN,
AllocPolicy::ExactMatch(state.device_info.addr),
)
.map_err(|e| {
DevicePersistError::DeviceManager(super::mmio::MmioError::Allocator(e))
})?;
.map_err(|e| DevicePersistError::DeviceManager(MmioError::Allocator(e)))?;
let identifier = (DeviceType::Rtc, DeviceType::Rtc.to_string());
dev_manager.add_bus_device_with_info(
identifier,
Expand Down Expand Up @@ -460,9 456,7 @@ impl<'a> Persist<'a> for MMIODeviceManager {
MMIO_LEN,
AllocPolicy::ExactMatch(device_info.addr),
)
.map_err(|e| {
DevicePersistError::DeviceManager(super::mmio::MmioError::Allocator(e))
})?;
.map_err(|e| DevicePersistError::DeviceManager(MmioError::Allocator(e)))?;

dev_manager.register_mmio_virtio(vm, id.clone(), mmio_transport, device_info)?;

Expand Down
2 changes: 0 additions & 2 deletions src/vmm/src/device_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 13,6 @@ use self::mmio::MMIODeviceManager;
pub mod legacy;
/// Memory Mapped I/O Manager.
pub mod mmio;
/// Device managers (de)serialization support.
pub mod persist;

#[derive(Debug)]
pub struct DeviceManager {
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 26,7 @@ use crate::cpu_config::templates::StaticCpuTemplate;
use crate::cpu_config::x86_64::cpuid::common::get_vendor_id_from_host;
#[cfg(target_arch = "x86_64")]
use crate::cpu_config::x86_64::cpuid::CpuidTrait;
use crate::device_manager::persist::{DevicePersistError, DeviceStates};
use crate::device_manager::mmio::persist::{DevicePersistError, DeviceStates};
use crate::logger::{info, warn};
use crate::resources::VmResources;
use crate::snapshot::Snapshot;
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 9,7 @@ use serde::{Deserialize, Serialize};
use utils::net::ipv4addr::is_link_local_valid;

use crate::cpu_config::templates::CustomCpuTemplate;
use crate::device_manager::persist::SharedDeviceType;
use crate::device_manager::mmio::persist::SharedDeviceType;
use crate::logger::{info, log_dev_preview_warning};
use crate::mmds;
use crate::mmds::data_store::{Mmds, MmdsVersion};
Expand Down