vmm/devices/mod.rs
1// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Portions Copyright 2017 The Chromium OS Authors. All rights reserved.
5// Use of this source code is governed by a BSD-style license that can be
6// found in the THIRD-PARTY file.
7
8//! Emulates virtual and hardware devices.
9
10#![allow(unused)]
11
12use std::io;
13
14pub mod acpi;
15pub mod legacy;
16pub mod pci;
17pub mod pseudo;
18pub mod virtio;
19
20use log::error;
21
22use crate::devices::virtio::net::metrics::NetDeviceMetrics;
23use crate::devices::virtio::queue::{InvalidAvailIdx, QueueError};
24use crate::devices::virtio::vsock::VsockError;
25use crate::logger::IncMetric;
26use crate::vstate::interrupts::InterruptError;
27
28// Function used for reporting error in terms of logging
29// but also in terms of metrics of net event fails.
30// network metrics is reported per device so we need a handle to each net device's
31// metrics `net_iface_metrics` to report metrics for that device.
32pub(crate) fn report_net_event_fail(net_iface_metrics: &NetDeviceMetrics, err: DeviceError) {
33 if let DeviceError::InvalidAvailIdx(err) = err {
34 panic!("{}", err);
35 }
36 error!("{:?}", err);
37 net_iface_metrics.event_fails.inc();
38}
39
40#[derive(Debug, thiserror::Error, displaydoc::Display)]
41pub enum DeviceError {
42 /// Failed to read from the TAP device.
43 FailedReadTap,
44 /// Failed to signal irq: {0}
45 FailedSignalingIrq(#[from] InterruptError),
46 /// IO error: {0}
47 IoError(io::Error),
48 /// Device received malformed payload.
49 MalformedPayload,
50 /// Device received malformed descriptor.
51 MalformedDescriptor,
52 /// Error during queue processing: {0}
53 QueueError(#[from] QueueError),
54 /// {0}
55 InvalidAvailIdx(#[from] InvalidAvailIdx),
56 /// Vsock device error: {0}
57 VsockError(#[from] VsockError),
58}