Skip to content

Commit 1c664e1

Browse files
committed
refactor: simplify creating RTCDevice
We were always constructing RTCDevice using a set of metrics that were defined in the RTC module itself. Don't leak the metrics to other modules. Instead, create a new() function that always constructs it the correct way. Signed-off-by: Babis Chalios <bchalios@amazon.es>
1 parent d79c9a2 commit 1c664e1

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

src/vmm/src/builder.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ use event_manager::{MutEventSubscriber, SubscriberOps};
1313
use linux_loader::cmdline::Cmdline as LoaderKernelCmdline;
1414
use userfaultfd::Uffd;
1515
use utils::time::TimestampUs;
16-
#[cfg(target_arch = "aarch64")]
17-
use vm_superio::Rtc;
1816

1917
use crate::arch::{ConfigurationError, configure_system_for_boot, load_kernel};
2018
#[cfg(target_arch = "aarch64")]
@@ -568,9 +566,7 @@ fn attach_legacy_devices_aarch64(
568566
.map_err(VmmError::RegisterMMIODevice)?;
569567
}
570568

571-
let rtc = RTCDevice(Rtc::with_events(
572-
&crate::devices::legacy::rtc_pl031::METRICS,
573-
));
569+
let rtc = RTCDevice::new();
574570
vmm.mmio_device_manager
575571
.register_mmio_rtc(&mut vmm.resource_allocator, rtc, None)
576572
.map_err(VmmError::RegisterMMIODevice)

src/vmm/src/device_manager/persist.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,7 @@ impl<'a> Persist<'a> for MMIODeviceManager {
449449
)?;
450450
}
451451
if state.type_ == DeviceType::Rtc {
452-
let rtc = RTCDevice(vm_superio::Rtc::with_events(
453-
&crate::devices::legacy::rtc_pl031::METRICS,
454-
));
452+
let rtc = RTCDevice::new();
455453
constructor_args
456454
.resource_allocator
457455
.allocate_mmio_memory(

src/vmm/src/devices/legacy/rtc_pl031.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use std::convert::TryInto;
55

66
use serde::Serialize;
7+
use vm_superio::Rtc;
78
use vm_superio::rtc_pl031::RtcEvents;
89

910
use crate::logger::{IncMetric, SharedIncMetric, warn};
@@ -59,7 +60,19 @@ pub static METRICS: RTCDeviceMetrics = RTCDeviceMetrics::new();
5960

6061
/// Wrapper over vm_superio's RTC implementation.
6162
#[derive(Debug)]
62-
pub struct RTCDevice(pub vm_superio::Rtc<&'static RTCDeviceMetrics>);
63+
pub struct RTCDevice(vm_superio::Rtc<&'static RTCDeviceMetrics>);
64+
65+
impl Default for RTCDevice {
66+
fn default() -> Self {
67+
Self::new()
68+
}
69+
}
70+
71+
impl RTCDevice {
72+
pub fn new() -> RTCDevice {
73+
RTCDevice(Rtc::with_events(&METRICS))
74+
}
75+
}
6376

6477
impl std::ops::Deref for RTCDevice {
6578
type Target = vm_superio::Rtc<&'static RTCDeviceMetrics>;

0 commit comments

Comments
 (0)