2020-07-16 14:50:36 +00:00
|
|
|
// Copyright © 2019 Intel Corporation
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause
|
|
|
|
//
|
|
|
|
// Copyright © 2020, Microsoft Corporation
|
|
|
|
//
|
|
|
|
// Copyright 2018-2019 CrowdStrike, Inc.
|
|
|
|
//
|
|
|
|
// Copyright 2020, ARM Limited
|
|
|
|
//
|
|
|
|
|
|
|
|
use crate::DeviceAttr;
|
2020-07-21 09:56:00 +00:00
|
|
|
use std::os::unix::io::AsRawFd;
|
2020-07-16 14:50:36 +00:00
|
|
|
use thiserror::Error;
|
|
|
|
|
|
|
|
#[derive(Error, Debug)]
|
|
|
|
///
|
|
|
|
/// Enum for device error
|
|
|
|
pub enum HypervisorDeviceError {
|
|
|
|
///
|
|
|
|
/// Set device attribute error
|
|
|
|
///
|
|
|
|
#[error("Failed to set device attribute: {0}")]
|
|
|
|
SetDeviceAttribute(#[source] anyhow::Error),
|
2020-08-31 06:04:19 +00:00
|
|
|
///
|
|
|
|
/// Get device attribute error
|
|
|
|
///
|
|
|
|
#[error("Failed to get device attribute: {0}")]
|
|
|
|
GetDeviceAttribute(#[source] anyhow::Error),
|
2020-07-16 14:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Result type for returning from a function
|
|
|
|
///
|
|
|
|
pub type Result<T> = std::result::Result<T, HypervisorDeviceError>;
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Trait to represent a device
|
|
|
|
///
|
|
|
|
/// This crate provides a hypervisor-agnostic interfaces for device
|
|
|
|
///
|
2020-07-21 09:56:00 +00:00
|
|
|
pub trait Device: Send + Sync + AsRawFd {
|
2020-07-16 14:50:36 +00:00
|
|
|
/// Set device attribute.
|
|
|
|
fn set_device_attr(&self, attr: &DeviceAttr) -> Result<()>;
|
2020-08-31 06:04:19 +00:00
|
|
|
/// Get device attribute.
|
|
|
|
fn get_device_attr(&self, attr: &mut DeviceAttr) -> Result<()>;
|
2020-07-16 14:50:36 +00:00
|
|
|
}
|