@@ -30,14 +30,8 @@ use crate::devices::legacy::RTCDevice;
30
30
use crate :: devices:: legacy:: serial:: SerialOut ;
31
31
use crate :: devices:: legacy:: { IER_RDA_BIT , IER_RDA_OFFSET , SerialDevice } ;
32
32
use crate :: devices:: pseudo:: BootTimer ;
33
- use crate :: devices:: virtio:: balloon:: Balloon ;
34
- use crate :: devices:: virtio:: block:: device:: Block ;
35
33
use crate :: devices:: virtio:: device:: VirtioDevice ;
36
- use crate :: devices:: virtio:: net:: Net ;
37
- use crate :: devices:: virtio:: rng:: Entropy ;
38
34
use crate :: devices:: virtio:: transport:: mmio:: { IrqTrigger , MmioTransport } ;
39
- use crate :: devices:: virtio:: vsock:: { TYPE_VSOCK , Vsock , VsockUnixBackend } ;
40
- use crate :: devices:: virtio:: { TYPE_BALLOON , TYPE_BLOCK , TYPE_NET , TYPE_RNG } ;
41
35
use crate :: resources:: VmResources ;
42
36
use crate :: snapshot:: Persist ;
43
37
use crate :: vstate:: memory:: GuestMemoryMmap ;
@@ -265,85 +259,28 @@ impl DeviceManager {
265
259
self . pci_devices . attach_pci_segment ( vm)
266
260
}
267
261
268
- fn do_kick_device ( virtio_device : Arc < Mutex < dyn VirtioDevice > > ) {
269
- let mut device = virtio_device. lock ( ) . expect ( "Poisoned lock" ) ;
270
- match device. device_type ( ) {
271
- TYPE_BALLOON => {
272
- let balloon = device. as_mut_any ( ) . downcast_mut :: < Balloon > ( ) . unwrap ( ) ;
273
- // If device is activated, kick the balloon queue(s) to make up for any
274
- // pending or in-flight epoll events we may have not captured in snapshot.
275
- // Stats queue doesn't need kicking as it is notified via a `timer_fd`.
276
- if balloon. is_activated ( ) {
277
- info ! ( "kick balloon {}." , balloon. id( ) ) ;
278
- balloon. process_virtio_queues ( ) ;
279
- }
280
- }
281
- TYPE_BLOCK => {
282
- // We only care about kicking virtio block.
283
- // If we need to kick vhost-user-block we can do nothing.
284
- if let Some ( block) = device. as_mut_any ( ) . downcast_mut :: < Block > ( ) {
285
- // If device is activated, kick the block queue(s) to make up for any
286
- // pending or in-flight epoll events we may have not captured in
287
- // snapshot. No need to kick Ratelimiters
288
- // because they are restored 'unblocked' so
289
- // any inflight `timer_fd` events can be safely discarded.
290
- if block. is_activated ( ) {
291
- info ! ( "kick block {}." , block. id( ) ) ;
292
- block. process_virtio_queues ( ) ;
293
- }
294
- }
295
- }
296
- TYPE_NET => {
297
- let net = device. as_mut_any ( ) . downcast_mut :: < Net > ( ) . unwrap ( ) ;
298
- // If device is activated, kick the net queue(s) to make up for any
299
- // pending or in-flight epoll events we may have not captured in snapshot.
300
- // No need to kick Ratelimiters because they are restored 'unblocked' so
301
- // any inflight `timer_fd` events can be safely discarded.
302
- if net. is_activated ( ) {
303
- info ! ( "kick net {}." , net. id( ) ) ;
304
- net. process_virtio_queues ( ) ;
305
- }
306
- }
307
- TYPE_VSOCK => {
308
- // Vsock has complicated protocol that isn't resilient to any packet loss,
309
- // so for Vsock we don't support connection persistence through snapshot.
310
- // Any in-flight packets or events are simply lost.
311
- // Vsock is restored 'empty'.
312
- // The only reason we still `kick` it is to make guest process
313
- // `TRANSPORT_RESET_EVENT` event we sent during snapshot creation.
314
- let vsock = device
315
- . as_mut_any ( )
316
- . downcast_mut :: < Vsock < VsockUnixBackend > > ( )
317
- . unwrap ( ) ;
318
- if vsock. is_activated ( ) {
319
- info ! ( "kick vsock {}." , vsock. id( ) ) ;
320
- vsock. signal_used_queue ( 0 ) . unwrap ( ) ;
321
- }
322
- }
323
- TYPE_RNG => {
324
- let entropy = device. as_mut_any ( ) . downcast_mut :: < Entropy > ( ) . unwrap ( ) ;
325
- if entropy. is_activated ( ) {
326
- info ! ( "kick entropy {}." , entropy. id( ) ) ;
327
- entropy. process_virtio_queues ( ) ;
328
- }
329
- }
330
- _ => ( ) ,
331
- }
332
- }
333
-
334
262
/// Artificially kick VirtIO devices as if they had external events.
335
263
pub fn kick_virtio_devices ( & self ) {
336
264
info ! ( "Artificially kick devices" ) ;
337
265
// Go through MMIO VirtIO devices
338
266
let _: Result < ( ) , MmioError > = self . mmio_devices . for_each_virtio_device ( |_, _, device| {
339
267
let mmio_transport_locked = device. inner . lock ( ) . expect ( "Poisoned lock" ) ;
340
- Self :: do_kick_device ( mmio_transport_locked. device ( ) ) ;
268
+ mmio_transport_locked
269
+ . device ( )
270
+ . lock ( )
271
+ . expect ( "Poisoned lock" )
272
+ . kick ( ) ;
341
273
Ok ( ( ) )
342
274
} ) ;
343
275
// Go through PCI VirtIO devices
344
- for device in self . pci_devices . virtio_devices . values ( ) {
345
- let virtio_device = device. lock ( ) . expect ( "Poisoned lock" ) . virtio_device ( ) ;
346
- Self :: do_kick_device ( virtio_device) ;
276
+ for virtio_pci_device in self . pci_devices . virtio_devices . values ( ) {
277
+ virtio_pci_device
278
+ . lock ( )
279
+ . expect ( "Poisoned lock" )
280
+ . virtio_device ( )
281
+ . lock ( )
282
+ . expect ( "Poisoned lock" )
283
+ . kick ( ) ;
347
284
}
348
285
}
349
286
0 commit comments