-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Add support for virtio device reset #5891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
36223f5
31abcb9
9d058aa
f2e233a
77ed1c2
82b3d5f
20cd54f
3d106c7
2a21987
da90c82
3029da9
6c585ba
95f58ad
696bb5a
cb5f9fb
e1d4372
44fea5a
492afa5
2cc1972
8bd7395
72da556
f5e6911
406c9bd
5b400f6
df8a0e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -674,6 +674,15 @@ impl VirtioDevice for VirtioBlock { | |
| fn is_activated(&self) -> bool { | ||
| self.device_state.is_activated() | ||
| } | ||
|
|
||
| fn deactivate(&mut self) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about the rate limiters? are we assuming we want to preserve the state across reset?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we not? |
||
| self.device_state = DeviceState::Inactive; | ||
| } | ||
|
|
||
| fn _reset(&mut self) -> bool { | ||
| self.is_io_engine_throttled = false; | ||
| true | ||
| } | ||
| } | ||
|
|
||
| impl Drop for VirtioBlock { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -178,12 +178,24 @@ pub trait VirtioDevice: AsAny + MutEventSubscriber + Send { | |
| /// Checks if the resources of this device are activated. | ||
| fn is_activated(&self) -> bool; | ||
|
|
||
| /// Optionally deactivates this device and returns ownership of the guest memory map, interrupt | ||
| /// event, and queue events. | ||
| fn reset(&mut self) -> Option<(Arc<dyn VirtioInterrupt>, Vec<EventFd>)> { | ||
| None | ||
| /// Set the device state to Inactive | ||
| fn deactivate(&mut self); | ||
|
|
||
| /// Reset the device. Returns true on success, false otherwise. | ||
| /// It must not be overridden. | ||
| fn reset(&mut self) -> bool { | ||
| self.deactivate(); | ||
| self.set_acked_features(0); | ||
| for queue in self.queues_mut() { | ||
| *queue = Queue::new(queue.max_size); | ||
| } | ||
| self._reset() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be called before the rest? This is a semantic change from the old code where a failed reset left the device activated.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It left it activated in Firecracker but set the state as FAILED so in theory the guest shouldn't continue using it. But does it matter much since we'll support reset for all devices except for vhost-user-block (for now)? |
||
| } | ||
|
|
||
| /// Backend-specific reset logic. Returns true on success, false if the | ||
| /// backend does not support reset. | ||
| fn _reset(&mut self) -> bool; | ||
|
|
||
| /// Mark pages used by queues as dirty. | ||
| fn mark_queue_memory_dirty(&mut self, mem: &GuestMemoryMmap) -> Result<(), QueueError> { | ||
| for queue in self.queues_mut() { | ||
|
|
@@ -310,6 +322,14 @@ pub(crate) mod tests { | |
| fn is_activated(&self) -> bool { | ||
| todo!() | ||
| } | ||
|
|
||
| fn deactivate(&mut self) { | ||
| todo!() | ||
| } | ||
|
|
||
| fn _reset(&mut self) -> bool { | ||
| todo!() | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we check if we need to upated other documentation files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What other documentation files did you have in mind?