Skip to content

Commit fe30908

Browse files
committed
device_manager: Store the subscriber IDs returned by EventManager
So far we haven't been storing the subscriber IDs returned by the event manager because we didn't need to use it. Subsequent commits will add support for device hot-unplug for virtio-pci devices, and therefore we need to store the IDs so that we can remove the objects from the event manager. We also need to store it for virtio-mmio devices to support device reset. Signed-off-by: Ilias Stamatis <ilstam@amazon.com>
1 parent c1b16cd commit fe30908

4 files changed

Lines changed: 21 additions & 7 deletions

File tree

src/vmm/src/device_manager/mmio.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ pub struct MMIODevice<T> {
114114
pub(crate) resources: MMIODeviceInfo,
115115
/// The actual device
116116
pub(crate) inner: Arc<Mutex<T>>,
117+
/// The subscriber ID returned by the EventManager
118+
pub(crate) sub_id: Option<event_manager::SubscriberId>,
117119
}
118120

119121
/// Manages the complexities of registering a MMIO device.
@@ -175,7 +177,7 @@ impl MMIODeviceManager {
175177
&mut self,
176178
vm: &Vm,
177179
device_id: String,
178-
device: MMIODevice<MmioTransport>,
180+
mut device: MMIODevice<MmioTransport>,
179181
event_manager: &mut EventManager,
180182
) -> Result<(), MmioError> {
181183
// Our virtio devices are currently hardcoded to use a single IRQ.
@@ -204,7 +206,9 @@ impl MMIODeviceManager {
204206
device.resources.len,
205207
)?;
206208

207-
event_manager.add_subscriber(device.inner.lock().expect("Poisoned lock").device());
209+
let sub_id =
210+
event_manager.add_subscriber(device.inner.lock().expect("Poisoned lock").device());
211+
device.sub_id = Some(sub_id);
208212

209213
self.virtio_devices.insert(identifier, device);
210214

@@ -245,6 +249,7 @@ impl MMIODeviceManager {
245249
let device = MMIODevice {
246250
resources: self.allocate_mmio_resources(&mut vm.resource_allocator(), 1)?,
247251
inner: Arc::new(Mutex::new(mmio_device)),
252+
sub_id: None,
248253
};
249254

250255
#[cfg(target_arch = "x86_64")]
@@ -294,6 +299,7 @@ impl MMIODeviceManager {
294299
let device = MMIODevice {
295300
resources: device_info,
296301
inner: serial,
302+
sub_id: None,
297303
};
298304

299305
vm.common.mmio_bus.insert(
@@ -347,6 +353,7 @@ impl MMIODeviceManager {
347353
let device = MMIODevice {
348354
resources: device_info,
349355
inner: rtc,
356+
sub_id: None,
350357
};
351358

352359
vm.common.mmio_bus.insert(
@@ -374,6 +381,7 @@ impl MMIODeviceManager {
374381
let device = MMIODevice {
375382
resources: device_info,
376383
inner: boot_timer,
384+
sub_id: None,
377385
};
378386

379387
mmio_bus.insert(

src/vmm/src/device_manager/pci_mngr.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ impl PciDevices {
126126
.insert((device_type, id), virtio_device.clone());
127127

128128
Self::register_bars_with_bus(vm, &virtio_device)?;
129-
virtio_device
130-
.lock()
131-
.expect("Poisoned lock")
132-
.register_notification_ioevent(vm)?;
133129

134-
event_manager.add_subscriber(virtio_device.lock().expect("Poisoned lock").virtio_device());
130+
let mut device = virtio_device.lock().expect("Poisoned lock");
131+
device.register_notification_ioevent(vm)?;
132+
133+
let sub_id = event_manager.add_subscriber(device.virtio_device());
134+
device.sub_id = Some(sub_id);
135135

136136
Ok(())
137137
}

src/vmm/src/device_manager/persist.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ impl<'a> Persist<'a> for MMIODeviceManager {
358358
MMIODevice {
359359
resources: *device_info,
360360
inner: mmio_transport,
361+
sub_id: None,
361362
},
362363
event_manager,
363364
)?;

src/vmm/src/devices/virtio/transport/pci/device.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ pub enum VirtioPciDeviceError {
258258
pub struct VirtioPciDevice {
259259
id: String,
260260

261+
// The subscriber ID returned by the EventManager
262+
pub sub_id: Option<event_manager::SubscriberId>,
263+
261264
// BDF assigned to the device
262265
pci_device_bdf: PciBdf,
263266

@@ -398,6 +401,7 @@ impl VirtioPciDevice {
398401

399402
let virtio_pci_device = VirtioPciDevice {
400403
id,
404+
sub_id: None,
401405
pci_device_bdf: pci_device_bdf.into(),
402406
configuration: pci_config,
403407
common_config: virtio_common_config,
@@ -442,6 +446,7 @@ impl VirtioPciDevice {
442446

443447
let virtio_pci_device = VirtioPciDevice {
444448
id,
449+
sub_id: None,
445450
pci_device_bdf: state.pci_device_bdf,
446451
configuration: pci_config,
447452
common_config: virtio_common_config,

0 commit comments

Comments
 (0)