From 544cb6bcda8654747e2de3d67c25182f3850ab2c Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Fri, 12 Jun 2020 10:11:06 +0000 Subject: Make lots of things Debug --- devices/src/proxy.rs | 2 +- devices/src/virtio/balloon.rs | 3 ++- devices/src/virtio/block.rs | 1 + devices/src/virtio/console.rs | 6 ++++++ devices/src/virtio/controller.rs | 1 + devices/src/virtio/fs/mod.rs | 7 +++++++ devices/src/virtio/fs/multikey.rs | 1 + devices/src/virtio/fs/passthrough.rs | 5 ++++- devices/src/virtio/input/event_source.rs | 3 +++ devices/src/virtio/input/mod.rs | 10 ++++++++-- devices/src/virtio/net.rs | 3 ++- devices/src/virtio/p9.rs | 1 + devices/src/virtio/pmem.rs | 1 + devices/src/virtio/resource_bridge.rs | 2 +- devices/src/virtio/rng.rs | 1 + devices/src/virtio/vhost/net.rs | 5 +++-- devices/src/virtio/vhost/vsock.rs | 1 + devices/src/virtio/virtio_device.rs | 2 +- devices/src/virtio/virtio_pci_common_config.rs | 1 + devices/src/virtio/wl.rs | 1 + net_util/src/lib.rs | 1 + p9/src/server.rs | 2 ++ sys_util/src/guest_memory.rs | 3 ++- vhost/src/net.rs | 2 ++ vhost/src/vsock.rs | 1 + 25 files changed, 55 insertions(+), 11 deletions(-) diff --git a/devices/src/proxy.rs b/devices/src/proxy.rs index cc31550..344a789 100644 --- a/devices/src/proxy.rs +++ b/devices/src/proxy.rs @@ -30,7 +30,7 @@ pub enum Command { Shutdown, } -#[derive(MsgOnSocket)] +#[derive(Debug, MsgOnSocket)] pub enum CommandResult { Ok, ReadResult([u8; 8]), diff --git a/devices/src/virtio/balloon.rs b/devices/src/virtio/balloon.rs index d115377..dfefcf4 100644 --- a/devices/src/virtio/balloon.rs +++ b/devices/src/virtio/balloon.rs @@ -64,7 +64,7 @@ struct virtio_balloon_config { unsafe impl DataInit for virtio_balloon_config {} // BalloonConfig is modified by the worker and read from the device thread. -#[derive(Default)] +#[derive(Debug, Default)] struct BalloonConfig { num_pages: AtomicUsize, actual_pages: AtomicUsize, @@ -323,6 +323,7 @@ impl Worker { } /// Virtio device for memory balloon inflation/deflation. +#[derive(Debug)] pub struct Balloon { command_socket: Option, config: Arc, diff --git a/devices/src/virtio/block.rs b/devices/src/virtio/block.rs index 57a243b..73b1f1f 100644 --- a/devices/src/virtio/block.rs +++ b/devices/src/virtio/block.rs @@ -459,6 +459,7 @@ impl Worker { } /// Virtio device for exposing block level read/write operations on a host file. +#[derive(Debug)] pub struct Block { kill_evt: Option, worker_thread: Option>, diff --git a/devices/src/virtio/console.rs b/devices/src/virtio/console.rs index e22f91d..10389bd 100644 --- a/devices/src/virtio/console.rs +++ b/devices/src/virtio/console.rs @@ -304,6 +304,12 @@ pub struct Console { keep_fds: Vec, } +impl std::fmt::Debug for Console { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "Console {{ .. }}") + } +} + impl SerialDevice for Console { fn new( _evt_fd: EventFd, diff --git a/devices/src/virtio/controller.rs b/devices/src/virtio/controller.rs index dbb14e6..42e8a1d 100644 --- a/devices/src/virtio/controller.rs +++ b/devices/src/virtio/controller.rs @@ -145,6 +145,7 @@ impl Worker { } } +#[derive(Debug)] pub struct Controller { kill_evt: Option, worker_thread: Option>, diff --git a/devices/src/virtio/fs/mod.rs b/devices/src/virtio/fs/mod.rs index 63b2a04..21cda40 100644 --- a/devices/src/virtio/fs/mod.rs +++ b/devices/src/virtio/fs/mod.rs @@ -47,6 +47,12 @@ struct Config { num_queues: Le32, } +impl std::fmt::Debug for Config { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "Config {{ .. }}") + } +} + // Safe because all members are plain old data and any value is valid. unsafe impl DataInit for Config {} @@ -129,6 +135,7 @@ impl fmt::Display for Error { pub type Result = ::std::result::Result; +#[derive(Debug)] pub struct Fs { cfg: Config, fs: Option, diff --git a/devices/src/virtio/fs/multikey.rs b/devices/src/virtio/fs/multikey.rs index b1e22f4..9bf355e 100644 --- a/devices/src/virtio/fs/multikey.rs +++ b/devices/src/virtio/fs/multikey.rs @@ -9,6 +9,7 @@ use std::collections::BTreeMap; /// `std::collections::BTreeMap` also apply to this struct. Additionally, there is a 1:1 /// relationship between the 2 key types. In other words, for each `K1` in the map, there is exactly /// one `K2` in the map and vice versa. +#[derive(Debug)] pub struct MultikeyBTreeMap { // We need to keep a copy of the second key in the main map so that we can remove entries using // just the main key. Otherwise we would require the caller to provide both keys when calling diff --git a/devices/src/virtio/fs/passthrough.rs b/devices/src/virtio/fs/passthrough.rs index 4833bb7..f3d3fd0 100644 --- a/devices/src/virtio/fs/passthrough.rs +++ b/devices/src/virtio/fs/passthrough.rs @@ -49,12 +49,13 @@ ioctl_iow_nr!(FS_IOC_GET_ENCRYPTION_POLICY, 0x66, 21, fscrypt_policy_v1); type Inode = u64; type Handle = u64; -#[derive(Clone, Copy, PartialOrd, Ord, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq)] struct InodeAltKey { ino: libc::ino64_t, dev: libc::dev_t, } +#[derive(Debug)] struct InodeData { inode: Inode, // Most of these aren't actually files but ¯\_(ツ)_/¯. @@ -62,6 +63,7 @@ struct InodeData { refcount: AtomicU64, } +#[derive(Debug)] struct HandleData { inode: Inode, file: Mutex, @@ -304,6 +306,7 @@ impl Default for Config { /// that wish to serve only a specific directory should set up the environment so that that /// directory ends up as the root of the file system process. One way to accomplish this is via a /// combination of mount namespaces and the pivot_root system call. +#[derive(Debug)] pub struct PassthroughFs { // File descriptors for various points in the file system tree. These fds are always opened with // the `O_PATH` option so they cannot be used for reading or writing any data. See the diff --git a/devices/src/virtio/input/event_source.rs b/devices/src/virtio/input/event_source.rs index 392c121..25e6e74 100644 --- a/devices/src/virtio/input/event_source.rs +++ b/devices/src/virtio/input/event_source.rs @@ -42,6 +42,7 @@ pub trait EventSource: AsRawFd { } /// Encapsulates implementation details common to all kinds of event sources. +#[derive(Debug)] pub struct EventSourceImpl { source: T, queue: VecDeque, @@ -135,6 +136,7 @@ enum EventType { } /// Encapsulates a (unix) socket as an event source. +#[derive(Debug)] pub struct SocketEventSource { evt_source_impl: EventSourceImpl, } @@ -187,6 +189,7 @@ where } /// Encapsulates an event device node as an event source +#[derive(Debug)] pub struct EvdevEventSource { evt_source_impl: EventSourceImpl, } diff --git a/devices/src/virtio/input/mod.rs b/devices/src/virtio/input/mod.rs index 7c9418c..7d5b91a 100644 --- a/devices/src/virtio/input/mod.rs +++ b/devices/src/virtio/input/mod.rs @@ -243,6 +243,12 @@ pub struct VirtioInputConfig { axis_info: BTreeMap, } +impl std::fmt::Debug for VirtioInputConfig { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "VirtioInputConfig {{ .. }}") + } +} + impl VirtioInputConfig { fn new( device_ids: virtio_input_device_ids, @@ -534,7 +540,7 @@ impl Worker { } /// Virtio input device - +#[derive(Debug)] pub struct Input { kill_evt: Option, worker_thread: Option>>, @@ -557,7 +563,7 @@ impl Drop for Input { impl VirtioDevice for Input where - T: 'static + EventSource + Send, + T: 'static + EventSource + Send + std::fmt::Debug, { fn keep_fds(&self) -> Vec { if let Some(source) = &self.source { diff --git a/devices/src/virtio/net.rs b/devices/src/virtio/net.rs index c15bd3d..dca2b06 100644 --- a/devices/src/virtio/net.rs +++ b/devices/src/virtio/net.rs @@ -418,6 +418,7 @@ where } } +#[derive(Debug)] pub struct Net { queue_sizes: Box<[u16]>, workers_kill_evt: Vec, @@ -575,7 +576,7 @@ where impl VirtioDevice for Net where - T: 'static + TapT, + T: 'static + TapT + std::fmt::Debug, { fn keep_fds(&self) -> Vec { let mut keep_fds = Vec::new(); diff --git a/devices/src/virtio/p9.rs b/devices/src/virtio/p9.rs index c139c53..8a4f85e 100644 --- a/devices/src/virtio/p9.rs +++ b/devices/src/virtio/p9.rs @@ -147,6 +147,7 @@ impl Worker { } /// Virtio device for sharing specific directories on the host system with the guest VM. +#[derive(Debug)] pub struct P9 { config: Vec, server: Option, diff --git a/devices/src/virtio/pmem.rs b/devices/src/virtio/pmem.rs index 72d47c4..296b90c 100644 --- a/devices/src/virtio/pmem.rs +++ b/devices/src/virtio/pmem.rs @@ -219,6 +219,7 @@ impl Worker { } } +#[derive(Debug)] pub struct Pmem { kill_event: Option, worker_thread: Option>, diff --git a/devices/src/virtio/resource_bridge.rs b/devices/src/virtio/resource_bridge.rs index 2a2343f..68491d6 100644 --- a/devices/src/virtio/resource_bridge.rs +++ b/devices/src/virtio/resource_bridge.rs @@ -11,7 +11,7 @@ use std::fs::File; use msg_on_socket_derive::MsgOnSocket; use msg_socket::{MsgError, MsgReceiver, MsgSender, MsgSocket}; -#[derive(MsgOnSocket)] +#[derive(Debug, MsgOnSocket)] pub enum ResourceRequest { GetResource { id: u32 }, } diff --git a/devices/src/virtio/rng.rs b/devices/src/virtio/rng.rs index ec1eb64..28bda81 100644 --- a/devices/src/virtio/rng.rs +++ b/devices/src/virtio/rng.rs @@ -118,6 +118,7 @@ impl Worker { } /// Virtio device for exposing entropy to the guest OS through virtio. +#[derive(Debug)] pub struct Rng { kill_evt: Option, worker_thread: Option>, diff --git a/devices/src/virtio/vhost/net.rs b/devices/src/virtio/vhost/net.rs index 49fe14d..cf6d262 100644 --- a/devices/src/virtio/vhost/net.rs +++ b/devices/src/virtio/vhost/net.rs @@ -24,6 +24,7 @@ const QUEUE_SIZE: u16 = 256; const NUM_QUEUES: usize = 2; const QUEUE_SIZES: &[u16] = &[QUEUE_SIZE; NUM_QUEUES]; +#[derive(Debug)] pub struct Net> { workers_kill_evt: Option, kill_evt: EventFd, @@ -126,8 +127,8 @@ where impl VirtioDevice for Net where - T: TapT + 'static, - U: VhostNetT + 'static, + T: TapT + 'static + std::fmt::Debug, + U: VhostNetT + 'static + std::fmt::Debug, { fn keep_fds(&self) -> Vec { let mut keep_fds = Vec::new(); diff --git a/devices/src/virtio/vhost/vsock.rs b/devices/src/virtio/vhost/vsock.rs index 70d2f2e..d0b2c0c 100644 --- a/devices/src/virtio/vhost/vsock.rs +++ b/devices/src/virtio/vhost/vsock.rs @@ -19,6 +19,7 @@ const QUEUE_SIZE: u16 = 256; const NUM_QUEUES: usize = 3; const QUEUE_SIZES: &[u16] = &[QUEUE_SIZE; NUM_QUEUES]; +#[derive(Debug)] pub struct Vsock { worker_kill_evt: Option, kill_evt: Option, diff --git a/devices/src/virtio/virtio_device.rs b/devices/src/virtio/virtio_device.rs index 1d6e4bc..645a59b 100644 --- a/devices/src/virtio/virtio_device.rs +++ b/devices/src/virtio/virtio_device.rs @@ -24,7 +24,7 @@ pub trait VirtioDeviceNew: Sized { /// and all the events, memory, and queues for device operation will be moved into the device. /// Optionally, a virtio device can implement device reset in which it returns said resources and /// resets its internal. -pub trait VirtioDevice: Send { +pub trait VirtioDevice: Send + Debug { /// Returns a label suitable for debug output. fn debug_label(&self) -> String { match type_to_str(self.device_type()) { diff --git a/devices/src/virtio/virtio_pci_common_config.rs b/devices/src/virtio/virtio_pci_common_config.rs index 14aefcb..56266c6 100644 --- a/devices/src/virtio/virtio_pci_common_config.rs +++ b/devices/src/virtio/virtio_pci_common_config.rs @@ -245,6 +245,7 @@ mod tests { use std::os::unix::io::RawFd; use sys_util::{EventFd, GuestMemory}; + #[derive(Debug)] struct DummyDevice(u32); const QUEUE_SIZE: u16 = 256; const QUEUE_SIZES: &'static [u16] = &[QUEUE_SIZE]; diff --git a/devices/src/virtio/wl.rs b/devices/src/virtio/wl.rs index 0ebb4ef..fd11839 100644 --- a/devices/src/virtio/wl.rs +++ b/devices/src/virtio/wl.rs @@ -1576,6 +1576,7 @@ impl Worker { } } +#[derive(Debug)] pub struct Wl { kill_evt: Option, worker_thread: Option>, diff --git a/net_util/src/lib.rs b/net_util/src/lib.rs index a91a116..8c2ffdb 100644 --- a/net_util/src/lib.rs +++ b/net_util/src/lib.rs @@ -527,6 +527,7 @@ pub mod fakes { const TMP_FILE: &str = "/tmp/crosvm_tap_test_file"; + #[derive(Debug)] pub struct FakeTap { tap_file: File, } diff --git a/p9/src/server.rs b/p9/src/server.rs index 957923d..3574619 100644 --- a/p9/src/server.rs +++ b/p9/src/server.rs @@ -101,6 +101,7 @@ const MAX_MESSAGE_SIZE: u32 = ::std::u16::MAX as u32; // 32-bit number chosen by the client. Most messages sent by clients include a fid on which to // operate. The fid in a Tattach message represents the root of the file system tree that the client // is allowed to access. A client can create more fids by walking the directory tree from that fid. +#[derive(Debug)] struct Fid { path: Box, metadata: fs::Metadata, @@ -200,6 +201,7 @@ fn join_path, R: AsRef>( Ok(buf) } +#[derive(Debug)] pub struct Server { root: Box, msize: u32, diff --git a/sys_util/src/guest_memory.rs b/sys_util/src/guest_memory.rs index 0728b77..c47f626 100644 --- a/sys_util/src/guest_memory.rs +++ b/sys_util/src/guest_memory.rs @@ -84,6 +84,7 @@ impl Display for Error { } } +#[derive(Debug)] struct MemoryRegion { mapping: MemoryMapping, guest_base: GuestAddress, @@ -107,7 +108,7 @@ impl MemoryRegion { /// Tracks a memory region and where it is mapped in the guest, along with a shm /// fd of the underlying memory regions. -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct GuestMemory { regions: Arc>, memfd: Arc, diff --git a/vhost/src/net.rs b/vhost/src/net.rs index 9b59cf2..0e87056 100644 --- a/vhost/src/net.rs +++ b/vhost/src/net.rs @@ -18,6 +18,7 @@ static DEVICE: &str = "/dev/vhost-net"; /// /// This provides a simple wrapper around a VHOST_NET file descriptor and /// methods that safely run ioctls on that file descriptor. +#[derive(Debug)] pub struct Net { // fd must be dropped first, which will stop and tear down the // vhost-net worker before GuestMemory can potentially be unmapped. @@ -96,6 +97,7 @@ pub mod fakes { const TMP_FILE: &str = "/tmp/crosvm_vhost_test_file"; + #[derive(Debug)] pub struct FakeNet { fd: File, mem: GuestMemory, diff --git a/vhost/src/vsock.rs b/vhost/src/vsock.rs index 8bd27e7..9ac5c77 100644 --- a/vhost/src/vsock.rs +++ b/vhost/src/vsock.rs @@ -14,6 +14,7 @@ use super::{ioctl_result, Error, Result, Vhost}; static DEVICE: &str = "/dev/vhost-vsock"; /// Handle for running VHOST_VSOCK ioctls. +#[derive(Debug)] pub struct Vsock { fd: File, mem: GuestMemory, -- cgit 1.4.1