Skip to content

Commit 08190a2

Browse files
committed
refactor(acpi): Make ACPIDeviceManager fields private
Thanks to the last commit introducing immutable accessors, the internal fields of ACPIDeviceManager no longer need to be public. Make the fields private to prevent external code from mutating them. Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
1 parent d0c14df commit 08190a2

3 files changed

Lines changed: 17 additions & 17 deletions

File tree

src/vmm/src/device_manager/acpi.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ pub enum ACPIDeviceError {
2020
NotifyGuest(#[from] std::io::Error),
2121
}
2222

23-
#[derive(Debug)]
23+
// Although both VMGenID and VMClock devices are always present, they should be instantiated when
24+
// they are attached to preserve the existing ordering of GSI allocation.
25+
#[derive(Debug, Default)]
2426
pub struct ACPIDeviceManager {
2527
/// VMGenID device
26-
pub vmgenid: Option<VmGenId>,
28+
vmgenid: Option<VmGenId>,
2729
/// VMclock device
28-
pub vmclock: Option<VmClock>,
30+
vmclock: Option<VmClock>,
2931
}
3032

3133
impl ACPIDeviceManager {
3234
/// Create a new ACPIDeviceManager object
33-
pub fn new() -> Self {
34-
// Although both VMGenID and VMClock devices are always present, they should be instantiated
35-
// when they are attached to preserve the existing ordering of GSI allocation.
35+
pub fn new(vmgenid: VmGenId, vmclock: VmClock) -> Self {
3636
ACPIDeviceManager {
37-
vmgenid: None,
38-
vmclock: None,
37+
vmgenid: Some(vmgenid),
38+
vmclock: Some(vmclock),
3939
}
4040
}
4141

src/vmm/src/device_manager/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl DeviceManager {
174174
mmio_devices: MMIODeviceManager::new(),
175175
#[cfg(target_arch = "x86_64")]
176176
legacy_devices,
177-
acpi_devices: ACPIDeviceManager::new(),
177+
acpi_devices: ACPIDeviceManager::default(),
178178
pci_devices: PciDevices::new(),
179179
})
180180
}
@@ -559,10 +559,10 @@ pub(crate) mod tests {
559559
pub(crate) fn default_device_manager() -> DeviceManager {
560560
let mut resource_allocator = ResourceAllocator::new();
561561
let mmio_devices = MMIODeviceManager::new();
562-
let acpi_devices = ACPIDeviceManager {
563-
vmgenid: Some(VmGenId::new(&mut resource_allocator)),
564-
vmclock: Some(VmClock::new(&mut resource_allocator)),
565-
};
562+
let acpi_devices = ACPIDeviceManager::new(
563+
VmGenId::new(&mut resource_allocator),
564+
VmClock::new(&mut resource_allocator),
565+
);
566566
let pci_devices = PciDevices::new();
567567

568568
#[cfg(target_arch = "x86_64")]

src/vmm/src/device_manager/persist.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,12 @@ impl<'a> Persist<'a> for ACPIDeviceManager {
183183
}
184184

185185
fn restore(vm: Self::ConstructorArgs, state: &Self::State) -> Result<Self, Self::Error> {
186-
let mut acpi_devices = ACPIDeviceManager {
186+
let mut acpi_devices = ACPIDeviceManager::new(
187187
// Safe to unwrap() here, this will never return an error.
188-
vmgenid: Some(VmGenId::restore((), &state.vmgenid).unwrap()),
188+
VmGenId::restore((), &state.vmgenid).unwrap(),
189189
// Safe to unwrap() here, this will never return an error.
190-
vmclock: Some(VmClock::restore((), &state.vmclock).unwrap()),
191-
};
190+
VmClock::restore((), &state.vmclock).unwrap(),
191+
);
192192

193193
acpi_devices.activate_vmgenid(vm)?;
194194
acpi_devices.do_post_restore_vmgenid()?;

0 commit comments

Comments
 (0)