-
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
Open
acj
wants to merge
3
commits into
firecracker-microvm:main
Choose a base branch
from
acj:net-reset
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
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] | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We definitely need to reset the
acked_features
here, too.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.