Skip to content

Commit

Permalink
Remove serialization from block and net
Browse files Browse the repository at this point in the history
BlockDeviceConfig and NetworkInterfaceConfig structures contain unified
data: description, state and low-level resources.
Low-level resources cannot be serialized and just ignoring them is not
the correct approach.

Serializing then deserializing an object should result in identical
objects which in this case cannot happen. Since it's not actually used,
let's just disable serialization.

Signed-off-by: Adrian Catangiu <acatan@amazon.com>
  • Loading branch information
acatangiu committed Nov 14, 2018
1 parent 1bc2c31 commit e065c03
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 20 deletions.
4 changes: 0 additions & 4 deletions api_server/src/request/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ mod tests {
let x = serde_json::from_str(jstr).expect("deserialization failed.");
assert_eq!(netif, x);

let y = serde_json::to_string(&netif).expect("serialization failed.");
let z = serde_json::from_str(y.as_ref()).expect("deserialization (2) failed.");
assert_eq!(x, z);

// Check that guest_mac and rate limiters are truly optional.
let jstr_no_mac = r#"{
"iface_id": "foo",
Expand Down
9 changes: 1 addition & 8 deletions rate_limiter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,11 @@ fn gcd(x: u64, y: u64) -> u64 {

/// TokenBucket provides a lower level interface to rate limiting with a
/// configurable capacity, refill-rate and initial burst.
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct TokenBucket {
// Bucket defining traits.
size: u64,
#[serde(skip_serializing_if = "Option::is_none")]
one_time_burst: Option<u64>,
refill_time: u64,

Expand Down Expand Up @@ -243,18 +242,12 @@ pub enum TokenType {
/// RateLimiters will generate events on the FDs provided by their `AsRawFd` trait
/// implementation. These events are meant to be consumed by the user of this struct.
/// On each such event, the user must call the `event_handler()` method.
#[derive(Serialize)]
#[serde(deny_unknown_fields)]
pub struct RateLimiter {
#[serde(skip_serializing_if = "Option::is_none")]
bandwidth: Option<TokenBucket>,
#[serde(skip_serializing_if = "Option::is_none")]
ops: Option<TokenBucket>,

#[serde(skip_serializing)]
timer_fd: Option<TimerFd>,
// Internal flag that quickly determines timer state.
#[serde(skip_serializing)]
timer_active: bool,
}

Expand Down
4 changes: 1 addition & 3 deletions vmm/src/vmm_config/drive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Display for DriveError {
}

/// Use this structure to set up the Block Device before booting the kernel.
#[derive(Debug, Deserialize, PartialEq, Serialize)]
#[derive(Debug, Deserialize, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct BlockDeviceConfig {
/// Unique identifier of the drive.
Expand All @@ -67,13 +67,11 @@ pub struct BlockDeviceConfig {
pub is_root_device: bool,
/// Part-UUID. Represents the unique id of the boot partition of this device. It is
/// optional and it will be used only if the `is_root_device` field is true.
#[serde(skip_serializing_if = "Option::is_none")]
pub partuuid: Option<String>,
/// If set to true, the drive is opened in read-only mode. Otherwise, the
/// drive is opened as read-write.
pub is_read_only: bool,
/// Rate Limiter for I/O operations.
#[serde(skip_serializing_if = "Option::is_none")]
pub rate_limiter: Option<RateLimiter>,
}

Expand Down
2 changes: 1 addition & 1 deletion vmm/src/vmm_config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub mod net;

/// Device State. TODO: This should be removed because we don't plan
/// to support hot plug-unplug in the near future.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[derive(Clone, Debug, Deserialize, PartialEq)]
pub enum DeviceState {
/// Device is attached.
Attached,
Expand Down
5 changes: 1 addition & 4 deletions vmm/src/vmm_config/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rate_limiter::RateLimiter;

/// This struct represents the strongly typed equivalent of the json body from net iface
/// related requests.
#[derive(Debug, Deserialize, PartialEq, Serialize)]
#[derive(Debug, Deserialize, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct NetworkInterfaceConfig {
/// ID of the guest network interface.
Expand All @@ -17,13 +17,10 @@ pub struct NetworkInterfaceConfig {
/// Host level path for the guest network interface.
pub host_dev_name: String,
/// Guest MAC address.
#[serde(skip_serializing_if = "Option::is_none")]
pub guest_mac: Option<MacAddr>,
/// Rate Limiter for received packages.
#[serde(skip_serializing_if = "Option::is_none")]
pub rx_rate_limiter: Option<RateLimiter>,
/// Rate Limiter for transmitted packages.
#[serde(skip_serializing_if = "Option::is_none")]
pub tx_rate_limiter: Option<RateLimiter>,
#[serde(default = "default_allow_mmds_requests")]
/// If this field is set, the device model will reply to HTTP GET
Expand Down

0 comments on commit e065c03

Please sign in to comment.