-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Support reset for net
device
#4389
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -34,7 +34,7 @@ use crate::devices::virtio::net::{ | |
gen, NetError, NetQueue, MAX_BUFFER_SIZE, NET_QUEUE_SIZES, RX_INDEX, TX_INDEX, | ||
}; | ||
use crate::devices::virtio::queue::{DescriptorChain, Queue}; | ||
use crate::devices::virtio::{ActivateError, TYPE_NET}; | ||
use crate::devices::virtio::{ActivateError, ResetError, TYPE_NET}; | ||
use crate::devices::{report_net_event_fail, DeviceError}; | ||
use crate::dumbo::pdu::arp::ETH_IPV4_FRAME_LEN; | ||
use crate::dumbo::pdu::ethernet::{EthernetFrame, PAYLOAD_OFFSET}; | ||
|
@@ -870,6 +870,15 @@ impl VirtioDevice for Net { | |
fn is_activated(&self) -> bool { | ||
self.device_state.is_activated() | ||
} | ||
|
||
fn reset(&mut self) -> Result<(), ResetError> { | ||
self.device_state = DeviceState::Inactive; | ||
self.rx_bytes_read = 0; | ||
self.rx_deferred_frame = false; | ||
self.rx_frame_buf = [0u8; MAX_BUFFER_SIZE]; | ||
self.metrics = NetMetricsPerDevice::alloc(self.id.clone()); | ||
Comment on lines
+875
to
+879
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. We definitely need to reset the Also, @sudanl0 do you think it is ok to reset the metrics here? I think it's more of a philosophical question, on whether we want our metrics to reflect the fact that the device has been reset by zeroing them out. Maybe, it would make sense to add a reset counter metric as well. |
||
Ok(()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
|
@@ -2015,17 +2024,29 @@ pub mod tests { | |
th.activate_net(); | ||
let net = th.net.lock().unwrap(); | ||
|
||
// Test queues count (TX and RX). | ||
let queues = net.queues(); | ||
assert_eq!(queues.len(), NET_QUEUE_SIZES.len()); | ||
assert_eq!(queues[RX_INDEX].size, th.rxq.size()); | ||
assert_eq!(queues[TX_INDEX].size, th.txq.size()); | ||
let validate = |net: &Net| { | ||
// Test queues count (TX and RX). | ||
let queues = net.queues(); | ||
assert_eq!(queues.len(), NET_QUEUE_SIZES.len()); | ||
assert_eq!(queues[RX_INDEX].size, th.rxq.size()); | ||
assert_eq!(queues[TX_INDEX].size, th.txq.size()); | ||
|
||
// Test corresponding queues events. | ||
assert_eq!(net.queue_events().len(), NET_QUEUE_SIZES.len()); | ||
|
||
// Test interrupts. | ||
assert!(!&net.irq_trigger.has_pending_irq(IrqType::Vring)); | ||
}; | ||
|
||
validate(&net); | ||
|
||
// Test corresponding queues events. | ||
assert_eq!(net.queue_events().len(), NET_QUEUE_SIZES.len()); | ||
// Test reset. | ||
let mut net = net; | ||
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. I guess you can just mark as |
||
assert!(net.device_state.is_activated()); | ||
net.reset().unwrap(); | ||
assert!(!net.device_state.is_activated()); | ||
|
||
// Test interrupts. | ||
assert!(!&net.irq_trigger.has_pending_irq(IrqType::Vring)); | ||
validate(&net); | ||
} | ||
|
||
#[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.
Yes, that's what I had in mind honestly. I assume the initial idea of giving back the
EventFd
s was to "ensure" through the type system that they can't be used, but that is a very dubious choice, IMHO.