Skip to content

Commit

Permalink
refactor: Re-export logging macros
Browse files Browse the repository at this point in the history
Re-exports logging macros from `logger` to allow more atomic changes
in `logger`.

Signed-off-by: Jonathan Woollett-Light <jcawl@amazon.co.uk>
  • Loading branch information
Jonathan Woollett-Light authored and JonathanWoollett-Light committed Oct 6, 2023
1 parent 9ea964c commit 6fe29a1
Show file tree
Hide file tree
Showing 19 changed files with 31 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/vmm/src/arch/aarch64/cache_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use std::path::{Path, PathBuf};
use std::{fs, io};

use log::warn;
use crate::logger::warn;

// Based on https://elixir.free-electrons.com/linux/v4.9.62/source/arch/arm64/kernel/cacheinfo.c#L29.
const MAX_CACHE_LEVEL: u8 = 7;
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use linux_loader::loader::elf::Elf as Loader;
#[cfg(target_arch = "aarch64")]
use linux_loader::loader::pe::PE as Loader;
use linux_loader::loader::KernelLoader;
use log::error;
use seccompiler::BpfThreadMap;
use snapshot::Persist;
use userfaultfd::Uffd;
Expand Down Expand Up @@ -49,6 +48,7 @@ use crate::devices::virtio::{
use crate::devices::BusDevice;
#[cfg(target_arch = "aarch64")]
use crate::logger;
use crate::logger::error;
use crate::persist::{MicrovmState, MicrovmStateError};
use crate::resources::VmResources;
use crate::vmm_config::boot_source::BootConfig;
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/cpu_config/x86_64/cpuid/amd/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub enum ExtendedApicIdError {
#[allow(clippy::multiple_inherent_impl)]
impl super::AmdCpuid {
/// We always use this brand string.
const DEFAULT_BRAND_STRING: &[u8; BRAND_STRING_LENGTH] =
const DEFAULT_BRAND_STRING: &'static [u8; BRAND_STRING_LENGTH] =
b"AMD EPYC\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";

/// Applies required modifications to CPUID respective of a vCPU.
Expand Down
3 changes: 2 additions & 1 deletion src/vmm/src/cpu_config/x86_64/custom_cpu_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::cpu_config::templates_serde::*;
use crate::cpu_config::x86_64::cpuid::common::get_vendor_id_from_host;
use crate::cpu_config::x86_64::cpuid::{KvmCpuidFlags, VENDOR_ID_AMD, VENDOR_ID_INTEL};
use crate::cpu_config::x86_64::static_cpu_templates::{c3, t2, t2a, t2cl, t2s, StaticCpuTemplate};
use crate::logger::warn;

impl GetCpuTemplate for Option<CpuTemplateType> {
fn get_cpu_template(&self) -> Result<Cow<CustomCpuTemplate>, GetCpuTemplateError> {
Expand All @@ -32,7 +33,7 @@ impl GetCpuTemplate for Option<CpuTemplateType> {
return Err(CpuVendorMismatched);
}
if !CpuModel::get_cpu_model().is_at_least_cascade_lake() {
log::warn!(
warn!(
"On processors that do not enumerate FBSDP_NO, PSDP_NO and \
SBDR_SSDP_NO on IA32_ARCH_CAPABILITIES MSR, the guest kernel \
does not apply the mitigation against MMIO stale data \
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/device_manager/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::sync::{Arc, Mutex};

use kvm_ioctls::{IoEventAddress, VmFd};
use linux_loader::cmdline as kernel_cmdline;
use log::info;
#[cfg(target_arch = "x86_64")]
use utils::vm_memory::GuestAddress;
use versionize::{VersionMap, Versionize, VersionizeResult};
Expand All @@ -30,6 +29,7 @@ use crate::devices::virtio::{
TYPE_RNG, TYPE_VSOCK,
};
use crate::devices::BusDevice;
use crate::logger::info;

/// Errors for MMIO device manager.
#[derive(Debug, thiserror::Error, displaydoc::Display)]
Expand Down
4 changes: 2 additions & 2 deletions src/vmm/src/devices/legacy/i8042.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::num::Wrapping;
use log::warn;
use utils::eventfd::EventFd;

use crate::logger::{IncMetric, METRICS};
use crate::logger::{error, IncMetric, METRICS};

/// Errors thrown by the i8042 device.
#[derive(Debug, thiserror::Error, displaydoc::Display)]
Expand Down Expand Up @@ -226,7 +226,7 @@ impl I8042Device {
// our exit event fd. Meaning Firecracker will be exiting as soon as the VMM
// thread wakes up to handle this event.
if let Err(err) = self.reset_evt.write(1) {
log::error!("Failed to trigger i8042 reset event: {:?}", err);
error!("Failed to trigger i8042 reset event: {:?}", err);
METRICS.i8042.error_count.inc();
}
METRICS.i8042.reset_count.inc();
Expand Down
4 changes: 3 additions & 1 deletion src/vmm/src/devices/pseudo/boot_timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

use utils::time::TimestampUs;

use crate::logger::info;

const MAGIC_VALUE_SIGNAL_GUEST_BOOT_COMPLETE: u8 = 123;

/// Pseudo device to record the kernel boot time.
Expand All @@ -23,7 +25,7 @@ impl BootTimer {

let boot_time_us = now_tm_us.time_us - self.start_ts.time_us;
let boot_time_cpu_us = now_tm_us.cputime_us - self.start_ts.cputime_us;
log::info!(
info!(
"Guest-boot-time = {:>6} us {} ms, {:>6} CPU us {} CPU ms",
boot_time_us,
boot_time_us / 1000,
Expand Down
4 changes: 2 additions & 2 deletions src/vmm/src/devices/virtio/balloon/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
use std::os::unix::io::AsRawFd;

use event_manager::{EventOps, Events, MutEventSubscriber};
use log::{error, warn};
use utils::epoll::EventSet;

use crate::devices::report_balloon_event_fail;
use crate::devices::virtio::balloon::device::Balloon;
use crate::devices::virtio::{VirtioDevice, DEFLATE_INDEX, INFLATE_INDEX, STATS_INDEX};
use crate::logger::{debug, error, warn};

impl Balloon {
fn register_runtime_events(&self, ops: &mut EventOps) {
Expand All @@ -36,7 +36,7 @@ impl Balloon {
}

fn process_activate_event(&self, ops: &mut EventOps) {
log::debug!("balloon: activate event");
debug!("balloon: activate event");
if let Err(err) = self.activate_evt.read() {
error!("Failed to consume balloon activate event: {:?}", err);
}
Expand Down
3 changes: 2 additions & 1 deletion src/vmm/src/devices/virtio/balloon/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::io;
use utils::vm_memory::{GuestAddress, GuestMemory, GuestMemoryMmap, GuestMemoryRegion};

use super::{RemoveRegionError, MAX_PAGE_COMPACT_BUFFER};
use crate::logger::error;

/// This takes a vector of page frame numbers, and compacts them
/// into ranges of consecutive pages. The result is a vector
Expand Down Expand Up @@ -35,7 +36,7 @@ pub(crate) fn compact_page_frame_numbers(v: &mut [u32]) -> Vec<(u32, u32)> {
// Skip duplicate pages. This will ensure we only consider
// distinct PFNs.
if page_frame_number == v[pfn_index - 1] {
log::error!("Skipping duplicate PFN {}.", page_frame_number);
error!("Skipping duplicate PFN {}.", page_frame_number);
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions src/vmm/src/devices/virtio/block/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
use std::os::unix::io::AsRawFd;

use event_manager::{EventOps, Events, MutEventSubscriber};
use log::{error, warn};
use utils::epoll::EventSet;

use super::io::FileEngine;
use crate::devices::virtio::block::device::Block;
use crate::devices::virtio::VirtioDevice;
use crate::logger::{debug, error, warn};

impl Block {
fn register_runtime_events(&self, ops: &mut EventOps) {
Expand All @@ -32,7 +32,7 @@ impl Block {
}

fn process_activate_event(&self, ops: &mut EventOps) {
log::debug!("block: activate event");
debug!("block: activate event");
if let Err(err) = self.activate_evt.read() {
error!("Failed to consume block activate event: {:?}", err);
}
Expand Down
4 changes: 2 additions & 2 deletions src/vmm/src/devices/virtio/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use std::fmt;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;

use log::warn;
use utils::eventfd::EventFd;
use utils::vm_memory::GuestMemoryMmap;

use super::{ActivateError, Queue};
use crate::devices::virtio::{AsAny, VIRTIO_MMIO_INT_CONFIG, VIRTIO_MMIO_INT_VRING};
use crate::logger::{error, warn};

/// Enum that indicates if a VirtioDevice is inactive or has been activated
/// and memory attached to it.
Expand Down Expand Up @@ -74,7 +74,7 @@ impl IrqTrigger {
self.irq_status.fetch_or(irq as usize, Ordering::SeqCst);

self.irq_evt.write(1).map_err(|err| {
log::error!("Failed to send irq to the guest: {:?}", err);
error!("Failed to send irq to the guest: {:?}", err);
err
})?;

Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/devices/virtio/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use std::fmt::Debug;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, Mutex, MutexGuard};

use log::warn;
use utils::byte_order;
use utils::vm_memory::{GuestAddress, GuestMemoryMmap};

use super::{device_status, *};
use crate::logger::warn;

// TODO crosvm uses 0 here, but IIRC virtio specified some other vendor id that should be used
const VENDOR_ID: u32 = 0;
Expand Down
5 changes: 2 additions & 3 deletions src/vmm/src/devices/virtio/net/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
use std::os::unix::io::AsRawFd;

use event_manager::{EventOps, Events, MutEventSubscriber};
use log::{error, warn};
use utils::epoll::EventSet;

use crate::devices::virtio::net::device::Net;
use crate::devices::virtio::{VirtioDevice, RX_INDEX, TX_INDEX};
use crate::logger::{IncMetric, METRICS};
use crate::logger::{debug, error, warn, IncMetric, METRICS};

impl Net {
fn register_runtime_events(&self, ops: &mut EventOps) {
Expand Down Expand Up @@ -40,7 +39,7 @@ impl Net {
}

fn process_activate_event(&self, ops: &mut EventOps) {
log::debug!("net: activate event");
debug!("net: activate event");
if let Err(err) = self.activate_evt.read() {
error!("Failed to consume net activate event: {:?}", err);
}
Expand Down
3 changes: 2 additions & 1 deletion src/vmm/src/devices/virtio/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ use std::cmp::min;
use std::num::Wrapping;
use std::sync::atomic::{fence, Ordering};

use log::error;
use utils::vm_memory::{
Address, ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryError, GuestMemoryMmap,
};

use crate::logger::error;

pub(super) const VIRTQ_DESC_F_NEXT: u16 = 0x1;
pub(super) const VIRTQ_DESC_F_WRITE: u16 = 0x2;

Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/devices/virtio/rng/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
use std::os::unix::io::AsRawFd;

use event_manager::{EventOps, Events, MutEventSubscriber};
use log::{error, warn};
use utils::epoll::EventSet;

use super::{Entropy, RNG_QUEUE};
use crate::devices::virtio::VirtioDevice;
use crate::logger::{error, warn};

impl Entropy {
fn register_runtime_events(&self, ops: &mut EventOps) {
Expand Down
4 changes: 2 additions & 2 deletions src/vmm/src/logger/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ use std::ops::Deref;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Mutex, OnceLock};

#[cfg(target_arch = "aarch64")]
use log::warn;
use serde::{Serialize, Serializer};
#[cfg(target_arch = "aarch64")]
use vm_superio::rtc_pl031::RtcEvents;

use super::FcLineWriter;
#[cfg(target_arch = "aarch64")]
use crate::warn;

/// Static instance used for handling metrics.
pub static METRICS: Metrics<FirecrackerMetrics, FcLineWriter> =
Expand Down
3 changes: 1 addition & 2 deletions src/vmm/src/logger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ mod metrics;

use std::sync::LockResult;

pub use log::Level::*;
pub use log::{warn, *};
pub use log::{debug, error, info, log_enabled, trace, warn, Level, LevelFilter};

pub use crate::logger::logging::{LoggerError, LOGGER};
#[cfg(target_arch = "aarch64")]
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::os::unix::net::UnixStream;
use std::path::Path;
use std::sync::{Arc, Mutex};

use log::{info, warn};
use seccompiler::BpfThreadMap;
use semver::Version;
use serde::Serialize;
Expand All @@ -33,6 +32,7 @@ use crate::cpu_config::x86_64::cpuid::common::get_vendor_id_from_host;
use crate::cpu_config::x86_64::cpuid::CpuidTrait;
use crate::device_manager::persist::{DevicePersistError, DeviceStates};
use crate::devices::virtio::TYPE_NET;
use crate::logger::{info, warn};
use crate::memory_snapshot::{GuestMemoryState, SnapshotMemory};
use crate::resources::VmResources;
#[cfg(target_arch = "x86_64")]
Expand Down
3 changes: 2 additions & 1 deletion src/vmm/src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use utils::net::ipv4addr::is_link_local_valid;

use crate::cpu_config::templates::CustomCpuTemplate;
use crate::device_manager::persist::SharedDeviceType;
use crate::logger::info;
use crate::mmds;
use crate::mmds::data_store::{Mmds, MmdsVersion};
use crate::mmds::ns::MmdsNetworkStack;
Expand Down Expand Up @@ -172,7 +173,7 @@ impl VmResources {
resources.locked_mmds_or_default().put_data(
serde_json::from_str(data).expect("MMDS error: metadata provided not valid json"),
)?;
log::info!("Successfully added metadata to mmds from file");
info!("Successfully added metadata to mmds from file");
}

if let Some(mmds_config) = vmm_config.mmds_config {
Expand Down

0 comments on commit 6fe29a1

Please sign in to comment.