Skip to content

Commit 015eb15

Browse files
author
Jonathan Woollett-Light
committed
fix: Update logging
Adds additional `std::fmt::Debug` implementations, these require removing some dynamic which involves removing the `BusDevice` trait. Signed-off-by: Jonathan Woollett-Light <[email protected]>
1 parent 9ab568b commit 015eb15

File tree

139 files changed

+1698
-1338
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+1698
-1338
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api_server/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
mod parsed_request;
1111
mod request;
1212

13+
use std::fmt::Debug;
1314
use std::path::PathBuf;
1415
use std::sync::mpsc;
1516

@@ -44,6 +45,7 @@ pub enum Error {
4445
type Result<T> = std::result::Result<T, Error>;
4546

4647
/// Structure associated with the API server implementation.
48+
#[derive(Debug)]
4749
pub struct ApiServer {
4850
/// Sender which allows passing messages to the VMM.
4951
api_request_sender: mpsc::Sender<ApiRequest>,
@@ -225,7 +227,7 @@ impl ApiServer {
225227
request: &Request,
226228
request_processing_start_us: u64,
227229
) -> Response {
228-
match ParsedRequest::try_from_request(request).map(|r| r.into_parts()) {
230+
match ParsedRequest::try_from(request).map(|r| r.into_parts()) {
229231
Ok((req_action, mut parsing_info)) => {
230232
let mut response = match req_action {
231233
RequestAction::Sync(vmm_action) => {
@@ -291,13 +293,13 @@ impl ApiServer {
291293
}
292294

293295
/// An HTTP response which also includes a body.
294-
pub(crate) fn json_response<T: Into<String>>(status: StatusCode, body: T) -> Response {
296+
pub(crate) fn json_response<T: Into<String> + Debug>(status: StatusCode, body: T) -> Response {
295297
let mut response = Response::new(Version::Http11, status);
296298
response.set_body(Body::new(body.into()));
297299
response
298300
}
299301

300-
fn json_fault_message<T: AsRef<str> + serde::Serialize>(msg: T) -> String {
302+
fn json_fault_message<T: AsRef<str> + serde::Serialize + Debug>(msg: T) -> String {
301303
json!({ "fault_message": msg }).to_string()
302304
}
303305
}

src/api_server/src/parsed_request.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
use std::fmt::Debug;
5+
46
use logger::{error, info, log_enabled, Level};
57
use micro_http::{Body, Method, Request, Response, StatusCode, Version};
68
use serde::ser::Serialize;
@@ -27,14 +29,13 @@ use crate::request::version::parse_get_version;
2729
use crate::request::vsock::parse_put_vsock;
2830
use crate::ApiServer;
2931

30-
#[cfg_attr(test, derive(Debug))]
32+
#[derive(Debug)]
3133
pub(crate) enum RequestAction {
3234
Sync(Box<VmmAction>),
3335
ShutdownInternal, // !!! not an API, used by shutdown to thread::join the API thread
3436
}
3537

36-
#[derive(Default)]
37-
#[cfg_attr(test, derive(Debug, PartialEq))]
38+
#[derive(Debug, Default, PartialEq)]
3839
pub(crate) struct ParsingInfo {
3940
deprecation_message: Option<String>,
4041
}
@@ -52,7 +53,7 @@ impl ParsingInfo {
5253
}
5354
}
5455

55-
#[cfg_attr(test, derive(Debug))]
56+
#[derive(Debug)]
5657
pub(crate) struct ParsedRequest {
5758
action: RequestAction,
5859
parsing_info: ParsingInfo,
@@ -141,7 +142,7 @@ impl ParsedRequest {
141142

142143
pub(crate) fn success_response_with_data<T>(body_data: &T) -> Response
143144
where
144-
T: ?Sized + Serialize,
145+
T: ?Sized + Serialize + Debug,
145146
{
146147
info!("The request was executed successfully. Status code: 200 OK.");
147148
let mut response = Response::new(Version::Http11, StatusCode::OK);

src/cpu-template-helper/src/fingerprint/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub mod dump;
99

1010
macro_rules! declare_fingerprint_struct_and_enum {
1111
($($field_name:ident : $field_type:ty),+) => {
12-
#[derive(Serialize, Deserialize)]
12+
#[derive(Debug, Serialize, Deserialize)]
1313
pub struct Fingerprint {
1414
$(pub $field_name: $field_type),+
1515
}

src/cpu-template-helper/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ enum Error {
3737

3838
type Result<T> = std::result::Result<T, Error>;
3939

40-
#[derive(Parser)]
40+
#[derive(Debug, Parser)]
4141
#[command(version = format!("v{}", crate::utils::CPU_TEMPLATE_HELPER_VERSION))]
4242
struct Cli {
4343
#[command(subcommand)]
4444
command: Command,
4545
}
4646

47-
#[derive(Subcommand)]
47+
#[derive(Debug, Subcommand)]
4848
enum Command {
4949
/// Template-related operations
5050
#[command(subcommand)]
@@ -54,7 +54,7 @@ enum Command {
5454
Fingerprint(FingerprintOperation),
5555
}
5656

57-
#[derive(Subcommand)]
57+
#[derive(Debug, Subcommand)]
5858
enum TemplateOperation {
5959
/// Dump guest CPU configuration in the custom CPU template format.
6060
Dump {
@@ -82,7 +82,7 @@ enum TemplateOperation {
8282
},
8383
}
8484

85-
#[derive(Subcommand)]
85+
#[derive(Debug, Subcommand)]
8686
enum FingerprintOperation {
8787
/// Dump fingerprint consisting of host-related information and guest CPU config.
8888
Dump {

src/cpu-template-helper/src/template/strip/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use std::collections::HashMap;
5+
use std::fmt::Debug;
56

67
use crate::utils::{ModifierMapKey, ModifierMapValue};
78

@@ -24,8 +25,8 @@ pub enum Error {
2425

2526
fn strip_common<K, V>(maps: &mut [HashMap<K, V>]) -> Result<(), Error>
2627
where
27-
K: ModifierMapKey,
28-
V: ModifierMapValue,
28+
K: ModifierMapKey + Debug,
29+
V: ModifierMapValue + Debug,
2930
{
3031
if maps.len() < 2 {
3132
return Err(Error::NumberOfInputs);

src/cpu-template-helper/src/template/verify/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use std::collections::HashMap;
5+
use std::fmt::Debug;
56

67
use crate::utils::{ModifierMapKey, ModifierMapValue};
78

@@ -31,8 +32,8 @@ pub enum Error {
3132
/// respectively before calling this arch-agnostic function.
3233
pub fn verify_common<K, V>(template: HashMap<K, V>, config: HashMap<K, V>) -> Result<(), Error>
3334
where
34-
K: ModifierMapKey,
35-
V: ModifierMapValue,
35+
K: ModifierMapKey + Debug,
36+
V: ModifierMapValue + Debug,
3637
{
3738
for (key, template_value_filter) in template {
3839
let config_value_filter = config

src/dumbo/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,19 @@ impl ByteBuffer for [u8] {
4848

4949
#[cfg(test)]
5050
mod tests {
51+
use std::fmt::Debug;
52+
5153
use super::*;
5254

53-
fn bb_len<T: ByteBuffer + ?Sized>(buf: &T) -> usize {
55+
fn bb_len<T: ByteBuffer + ?Sized + Debug>(buf: &T) -> usize {
5456
buf.len()
5557
}
5658

57-
fn bb_is_empty<T: ByteBuffer + ?Sized>(buf: &T) -> bool {
59+
fn bb_is_empty<T: ByteBuffer + ?Sized + Debug>(buf: &T) -> bool {
5860
buf.len() == 0
5961
}
6062

61-
fn bb_read_from_1<T: ByteBuffer + ?Sized>(src: &T, dst: &mut [u8]) {
63+
fn bb_read_from_1<T: ByteBuffer + ?Sized + Debug>(src: &T, dst: &mut [u8]) {
6264
src.read_to_slice(1, dst);
6365
}
6466

src/dumbo/src/pdu/arp.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//!
99
//! [here]: https://en.wikipedia.org/wiki/Address_Resolution_Protocol
1010
use std::convert::From;
11+
use std::fmt::Debug;
1112
use std::net::Ipv4Addr;
1213
use std::result::Result;
1314

@@ -65,12 +66,13 @@ pub enum Error {
6566
/// ARP is a generic protocol as far as data
6667
/// link layer and network layer protocols go, but this particular implementation is concerned with
6768
/// ARP frames related to IPv4 over Ethernet.
69+
#[derive(Debug)]
6870
pub struct EthIPv4ArpFrame<'a, T: 'a> {
6971
bytes: InnerBytes<'a, T>,
7072
}
7173

7274
#[allow(clippy::len_without_is_empty)]
73-
impl<'a, T: NetworkBytes> EthIPv4ArpFrame<'a, T> {
75+
impl<'a, T: NetworkBytes + Debug> EthIPv4ArpFrame<'a, T> {
7476
/// Interprets the given bytes as an ARP frame, without doing any validity checks beforehand.
7577
///
7678
/// # Panics
@@ -183,7 +185,7 @@ impl<'a, T: NetworkBytes> EthIPv4ArpFrame<'a, T> {
183185
}
184186
}
185187

186-
impl<'a, T: NetworkBytesMut> EthIPv4ArpFrame<'a, T> {
188+
impl<'a, T: NetworkBytesMut + Debug> EthIPv4ArpFrame<'a, T> {
187189
#[allow(clippy::too_many_arguments)]
188190
fn write_raw(
189191
buf: T,
@@ -338,23 +340,17 @@ pub fn test_speculative_tpa(buf: &[u8], addr: Ipv4Addr) -> bool {
338340

339341
#[cfg(test)]
340342
mod tests {
341-
use std::fmt;
343+
use std::str::FromStr;
342344

343345
use super::*;
344346

345-
impl<'a, T: NetworkBytes> fmt::Debug for EthIPv4ArpFrame<'a, T> {
346-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
347-
write!(f, "(EthIPv4ArpFrame frame)")
348-
}
349-
}
350-
351347
#[test]
352348
fn test_eth_ipv4_arp_frame() {
353349
let mut a = [0u8; 1000];
354350
let mut bad_array = [0u8; 1];
355351

356-
let sha = MacAddr::parse_str("01:23:45:67:89:ab").unwrap();
357-
let tha = MacAddr::parse_str("cd:ef:01:23:45:67").unwrap();
352+
let sha = MacAddr::from_str("01:23:45:67:89:ab").unwrap();
353+
let tha = MacAddr::from_str("cd:ef:01:23:45:67").unwrap();
358354
let spa = Ipv4Addr::new(10, 1, 2, 3);
359355
let tpa = Ipv4Addr::new(10, 4, 5, 6);
360356

src/dumbo/src/pdu/bytes.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
//! read/write goes beyond the boundaries of a slice. Callers must take the necessary precautions
6565
//! to avoid panics.
6666
67+
use std::fmt::Debug;
6768
use std::marker::PhantomData;
6869
use std::ops::{Deref, DerefMut};
6970

@@ -151,12 +152,13 @@ impl<'a> NetworkBytesMut for &'a mut [u8] {}
151152
// This struct is used as a convenience for any type which contains a generic member implementing
152153
// NetworkBytes with a lifetime, so we don't have to also add the PhantomData member each time. We
153154
// use pub(super) here because we only want this to be usable by the child modules of `pdu`.
155+
#[derive(Debug)]
154156
pub(super) struct InnerBytes<'a, T: 'a> {
155157
bytes: T,
156158
phantom: PhantomData<&'a T>,
157159
}
158160

159-
impl<'a, T> InnerBytes<'a, T> {
161+
impl<'a, T: Debug> InnerBytes<'a, T> {
160162
/// Creates a new instance as a wrapper around `bytes`.
161163
#[inline]
162164
pub fn new(bytes: T) -> Self {
@@ -167,7 +169,7 @@ impl<'a, T> InnerBytes<'a, T> {
167169
}
168170
}
169171

170-
impl<'a, T: Deref<Target = [u8]>> Deref for InnerBytes<'a, T> {
172+
impl<'a, T: Deref<Target = [u8]> + Debug> Deref for InnerBytes<'a, T> {
171173
type Target = [u8];
172174

173175
#[inline]
@@ -176,21 +178,21 @@ impl<'a, T: Deref<Target = [u8]>> Deref for InnerBytes<'a, T> {
176178
}
177179
}
178180

179-
impl<'a, T: DerefMut<Target = [u8]>> DerefMut for InnerBytes<'a, T> {
181+
impl<'a, T: DerefMut<Target = [u8]> + Debug> DerefMut for InnerBytes<'a, T> {
180182
#[inline]
181183
fn deref_mut(&mut self) -> &mut [u8] {
182184
self.bytes.deref_mut()
183185
}
184186
}
185187

186-
impl<'a, T: NetworkBytes> NetworkBytes for InnerBytes<'a, T> {
188+
impl<'a, T: NetworkBytes + Debug> NetworkBytes for InnerBytes<'a, T> {
187189
#[inline]
188190
fn shrink_unchecked(&mut self, len: usize) {
189191
self.bytes.shrink_unchecked(len);
190192
}
191193
}
192194

193-
impl<'a, T: NetworkBytesMut> NetworkBytesMut for InnerBytes<'a, T> {}
195+
impl<'a, T: NetworkBytesMut + Debug> NetworkBytesMut for InnerBytes<'a, T> {}
194196

195197
#[cfg(test)]
196198
mod tests {

0 commit comments

Comments
 (0)