Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
pb8o authored Sep 2, 2024
2 parents e74887a + 9e627a7 commit 35fa600
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/vmm/src/devices/virtio/block/vhost_user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pub const QUEUE_SIZE: u16 = 256;
pub enum VhostUserBlockError {
/// Cannot create config
Config,
/// Persistence error: {0}
Persist(crate::devices::virtio::persist::PersistError),
/// Snapshotting of vhost-user-blk devices is not supported
SnapshottingNotSupported,
/// Vhost-user error: {0}
VhostUser(VhostUserError),
/// Vhost error: {0}
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/devices/virtio/block/vhost_user/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ impl Persist<'_> for VhostUserBlock {
_constructor_args: Self::ConstructorArgs,
_state: &Self::State,
) -> Result<Self, Self::Error> {
unimplemented!("VhostUserBlock does not support snapshotting yet");
Err(VhostUserBlockError::SnapshottingNotSupported)
}
}
20 changes: 9 additions & 11 deletions src/vmm/src/dumbo/tcp/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub struct TcpIPv4Handler {
// This map holds the currently active endpoints, identified by their connection tuple.
connections: HashMap<ConnectionTuple, Endpoint>,
// Maximum number of concurrent connections we are willing to handle.
max_connections: usize,
max_connections: NonZeroUsize,
// Holds connections which are able to send segments immediately.
active_connections: HashSet<ConnectionTuple>,
// Remembers the closest timestamp into the future when one of the connections has to deal
Expand All @@ -138,7 +138,7 @@ pub struct TcpIPv4Handler {
// RST segments awaiting to be sent.
rst_queue: Vec<(ConnectionTuple, RstConfig)>,
// Maximum size of the RST queue.
max_pending_resets: usize,
max_pending_resets: NonZeroUsize,
}

// Only used locally, in the receive_packet method, to differentiate between different outcomes
Expand All @@ -164,16 +164,14 @@ impl TcpIPv4Handler {
max_connections: NonZeroUsize,
max_pending_resets: NonZeroUsize,
) -> Self {
let max_connections = max_connections.get();
let max_pending_resets = max_pending_resets.get();
TcpIPv4Handler {
local_ipv4_addr,
local_port,
connections: HashMap::with_capacity(max_connections),
connections: HashMap::with_capacity(max_connections.get()),
max_connections,
active_connections: HashSet::with_capacity(max_connections),
active_connections: HashSet::with_capacity(max_connections.get()),
next_timeout: None,
rst_queue: Vec::with_capacity(max_pending_resets),
rst_queue: Vec::with_capacity(max_pending_resets.get()),
max_pending_resets,
}
}
Expand All @@ -194,12 +192,12 @@ impl TcpIPv4Handler {
}

/// Returns the max connections of this TCP handler.
pub fn max_connections(&self) -> usize {
pub fn max_connections(&self) -> NonZeroUsize {
self.max_connections
}

/// Returns the max pending resets of this TCP handler.
pub fn max_pending_resets(&self) -> usize {
pub fn max_pending_resets(&self) -> NonZeroUsize {
self.max_pending_resets
}

Expand Down Expand Up @@ -257,7 +255,7 @@ impl TcpIPv4Handler {
Err(_) => return Ok(RecvEvent::FailedNewConnection),
};

if self.connections.len() >= self.max_connections {
if self.connections.len() >= self.max_connections.get() {
if let Some(evict_tuple) = self.find_evictable_connection() {
let rst_config = self.connections[&evict_tuple]
.connection()
Expand Down Expand Up @@ -363,7 +361,7 @@ impl TcpIPv4Handler {

fn enqueue_rst_config(&mut self, tuple: ConnectionTuple, cfg: RstConfig) {
// We simply forgo sending any RSTs if the queue is already full.
if self.rst_queue.len() < self.max_pending_resets {
if self.rst_queue.len() < self.max_pending_resets.get() {
self.rst_queue.push((tuple, cfg));
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/vmm/src/mmds/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! Defines the structures needed for saving/restoring MmdsNetworkStack.
use std::net::Ipv4Addr;
use std::num::NonZeroUsize;
use std::sync::{Arc, Mutex};

use serde::{Deserialize, Serialize};
Expand All @@ -19,8 +20,8 @@ pub struct MmdsNetworkStackState {
mac_addr: [u8; MAC_ADDR_LEN as usize],
ipv4_addr: u32,
tcp_port: u16,
max_connections: usize,
max_pending_resets: usize,
max_connections: NonZeroUsize,
max_pending_resets: NonZeroUsize,
}

impl Persist<'_> for MmdsNetworkStack {
Expand Down Expand Up @@ -49,8 +50,8 @@ impl Persist<'_> for MmdsNetworkStack {
MacAddr::from_bytes_unchecked(&state.mac_addr),
Ipv4Addr::from(state.ipv4_addr),
state.tcp_port,
std::num::NonZeroUsize::new(state.max_connections).unwrap(),
std::num::NonZeroUsize::new(state.max_pending_resets).unwrap(),
state.max_connections,
state.max_pending_resets,
mmds,
))
}
Expand Down

0 comments on commit 35fa600

Please sign in to comment.