Skip to content

Commit 6fe8405

Browse files
acatangiusandreim
authored andcommitted
device-manager: kick devices on snapshot restore
Signed-off-by: Adrian Catangiu <[email protected]>
1 parent 5eaab90 commit 6fe8405

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/devices/src/virtio/block/device.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,14 @@ impl Block {
196196
METRICS.block.event_fails.inc();
197197
} else if self.rate_limiter.is_blocked() {
198198
METRICS.block.rate_limiter_throttled_events.inc();
199-
} else if self.process_queue(0) {
199+
} else {
200+
self.process_virtio_queues();
201+
}
202+
}
203+
204+
/// Process device virtio queue(s).
205+
pub fn process_virtio_queues(&mut self) {
206+
if self.process_queue(0) {
200207
let _ = self.signal_used_queue();
201208
}
202209
}

src/devices/src/virtio/net/device.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,12 @@ impl Net {
704704
}
705705
}
706706
}
707+
708+
/// Process device virtio queue(s).
709+
pub fn process_virtio_queues(&mut self) {
710+
let _ = self.resume_rx();
711+
let _ = self.process_tx();
712+
}
707713
}
708714

709715
impl VirtioDevice for Net {

src/vmm/src/device_manager/persist.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,21 @@ impl<'a> Persist<'a> for MMIODeviceManager {
216216

217217
restore_helper(
218218
device.clone(),
219-
device,
219+
device.clone(),
220220
&block_state.device_id,
221221
&block_state.transport_state,
222222
&block_state.mmio_slot,
223223
constructor_args.event_manager,
224224
)?;
225+
226+
// If device is activated, kick the block queue(s) to make up for any
227+
// pending or in-flight epoll events we may have not captured in snapshot.
228+
// No need to kick Ratelimiters because they are restored 'unblocked' so
229+
// any inflight `timer_fd` events can be safely discarded.
230+
let mut dev = device.lock().expect("Poisoned lock");
231+
if dev.is_activated() {
232+
dev.process_virtio_queues();
233+
}
225234
}
226235
for net_state in &state.net_devices {
227236
let device = Arc::new(Mutex::new(
@@ -234,12 +243,21 @@ impl<'a> Persist<'a> for MMIODeviceManager {
234243

235244
restore_helper(
236245
device.clone(),
237-
device,
246+
device.clone(),
238247
&net_state.device_id,
239248
&net_state.transport_state,
240249
&net_state.mmio_slot,
241250
constructor_args.event_manager,
242251
)?;
252+
253+
// If device is activated, kick the net queue(s) to make up for any
254+
// pending or in-flight epoll events we may have not captured in snapshot.
255+
// No need to kick Ratelimiters because they are restored 'unblocked' so
256+
// any inflight `timer_fd` events can be safely discarded.
257+
let mut dev = device.lock().expect("Poisoned lock");
258+
if dev.is_activated() {
259+
dev.process_virtio_queues();
260+
}
243261
}
244262
if let Some(vsock_state) = &state.vsock_device {
245263
let ctor_args = VsockUdsConstructorArgs {
@@ -266,6 +284,10 @@ impl<'a> Persist<'a> for MMIODeviceManager {
266284
&vsock_state.mmio_slot,
267285
constructor_args.event_manager,
268286
)?;
287+
288+
// Vsock has complicated protocol that isn't resilient to any packet loss,
289+
// so for Vsock we don't support connection persistence through snapshot.
290+
// Any in-flight packets or events are simply lost. Vsock is restored 'empty'.
269291
}
270292

271293
Ok(dev_manager)

0 commit comments

Comments
 (0)