mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-09-12 18:15:06 +00:00
Originally, VhostUserSetup is only used by vhost-user-fs. While vhost-user-blk and vhost-user-net have their own error messages, we rename VhostUserSetup to VhostUserFsSetup. Signed-off-by: Jiachen Zhang <zhangjiachen.jaycee@bytedance.com>
145 lines
3.7 KiB
Rust
145 lines
3.7 KiB
Rust
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
//
|
|
// Portions Copyright 2017 The Chromium OS Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE-BSD-3-Clause file.
|
|
//
|
|
// Copyright © 2019 Intel Corporation
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
|
|
|
//! Implements virtio devices, queues, and transport mechanisms.
|
|
|
|
extern crate arc_swap;
|
|
extern crate epoll;
|
|
#[macro_use]
|
|
extern crate event_monitor;
|
|
#[macro_use]
|
|
extern crate log;
|
|
extern crate pci;
|
|
extern crate serde;
|
|
#[macro_use]
|
|
extern crate serde_derive;
|
|
extern crate serde_json;
|
|
extern crate vhost;
|
|
extern crate virtio_bindings;
|
|
extern crate vm_device;
|
|
extern crate vm_memory;
|
|
|
|
use std::io;
|
|
|
|
#[macro_use]
|
|
mod device;
|
|
pub mod balloon;
|
|
pub mod block;
|
|
mod console;
|
|
pub mod epoll_helper;
|
|
mod iommu;
|
|
pub mod mem;
|
|
pub mod net;
|
|
pub mod net_util;
|
|
mod pmem;
|
|
mod rng;
|
|
pub mod seccomp_filters;
|
|
pub mod transport;
|
|
pub mod vhost_user;
|
|
pub mod vsock;
|
|
pub mod watchdog;
|
|
|
|
pub use self::balloon::*;
|
|
pub use self::block::*;
|
|
pub use self::console::*;
|
|
pub use self::device::*;
|
|
pub use self::epoll_helper::*;
|
|
pub use self::iommu::*;
|
|
pub use self::mem::*;
|
|
pub use self::net::*;
|
|
pub use self::net_util::*;
|
|
pub use self::pmem::*;
|
|
pub use self::rng::*;
|
|
pub use self::vsock::*;
|
|
pub use self::watchdog::*;
|
|
use vm_memory::{GuestAddress, GuestMemory};
|
|
use vm_virtio::{queue::*, VirtioDeviceType};
|
|
|
|
const DEVICE_INIT: u32 = 0x00;
|
|
const DEVICE_ACKNOWLEDGE: u32 = 0x01;
|
|
const DEVICE_DRIVER: u32 = 0x02;
|
|
const DEVICE_DRIVER_OK: u32 = 0x04;
|
|
const DEVICE_FEATURES_OK: u32 = 0x08;
|
|
const DEVICE_FAILED: u32 = 0x80;
|
|
|
|
const VIRTIO_F_VERSION_1: u32 = 32;
|
|
const VIRTIO_F_IOMMU_PLATFORM: u32 = 33;
|
|
const VIRTIO_F_IN_ORDER: u32 = 35;
|
|
|
|
const VIRTIO_MSI_NO_VECTOR: u16 = 0xffff;
|
|
|
|
#[derive(Debug)]
|
|
pub enum ActivateError {
|
|
EpollCtl(std::io::Error),
|
|
BadActivate,
|
|
/// Queue number is not correct
|
|
BadQueueNum,
|
|
/// Failed to clone Kill event
|
|
CloneKillEventFd,
|
|
/// Failed to create Vhost-user interrupt eventfd
|
|
VhostIrqCreate,
|
|
/// Failed to setup vhost-user-fs daemon.
|
|
VhostUserFsSetup(vhost_user::Error),
|
|
/// Failed to setup vhost-user-net daemon.
|
|
VhostUserNetSetup(vhost_user::Error),
|
|
/// Failed to setup vhost-user-blk daemon.
|
|
VhostUserBlkSetup(vhost_user::Error),
|
|
/// Failed to reset vhost-user daemon.
|
|
VhostUserReset(vhost_user::Error),
|
|
/// Cannot create seccomp filter
|
|
CreateSeccompFilter(seccomp::SeccompError),
|
|
}
|
|
|
|
pub type ActivateResult = std::result::Result<(), ActivateError>;
|
|
|
|
pub type DeviceEventT = u16;
|
|
|
|
#[derive(Debug)]
|
|
pub enum Error {
|
|
FailedReadingQueue {
|
|
event_type: &'static str,
|
|
underlying: io::Error,
|
|
},
|
|
FailedSignalingUsedQueue(io::Error),
|
|
PayloadExpected,
|
|
UnknownEvent {
|
|
device: &'static str,
|
|
event: DeviceEventT,
|
|
},
|
|
IoError(io::Error),
|
|
EpollCreateFd(io::Error),
|
|
EpollCtl(io::Error),
|
|
EpollWait(io::Error),
|
|
FailedSignalingDriver(io::Error),
|
|
VhostUserUpdateMemory(vhost_user::Error),
|
|
EventfdError(io::Error),
|
|
SetShmRegionsNotSupported,
|
|
EpollHander(String),
|
|
NoMemoryConfigured,
|
|
NetQueuePair(::net_util::NetQueuePairError),
|
|
ApplySeccompFilter(seccomp::Error),
|
|
}
|
|
|
|
/// Convert an absolute address into an address space (GuestMemory)
|
|
/// to a host pointer and verify that the provided size define a valid
|
|
/// range within a single memory region.
|
|
/// Return None if it is out of bounds or if addr+size overlaps a single region.
|
|
pub fn get_host_address_range<M: GuestMemory>(
|
|
mem: &M,
|
|
addr: GuestAddress,
|
|
size: usize,
|
|
) -> Option<*mut u8> {
|
|
if mem.check_range(addr, size) {
|
|
Some(mem.get_host_address(addr).unwrap())
|
|
} else {
|
|
None
|
|
}
|
|
}
|