Skip to main content

DeviceFd

Struct DeviceFd 

Source
pub struct DeviceFd { /* private fields */ }
Expand description

Wrapper over the file descriptor obtained when creating an emulated device in the kernel.

Implementations§

Source§

impl DeviceFd

Source

pub fn has_device_attr( &self, device_attr: &mshv_device_attr, ) -> Result<(), MshvError>

Tests whether a device supports a particular attribute.

See the documentation for MSHV_HAS_DEVICE_ATTR.

§Arguments
  • device_attr - The device attribute to be tested. addr field is ignored.
Source

pub fn set_device_attr( &self, device_attr: &mshv_device_attr, ) -> Result<(), MshvError>

Sets a specified piece of device configuration and/or state.

See the documentation for MSHV_SET_DEVICE_ATTR.

§Arguments
  • device_attr - The device attribute to be set.
§Example
   MSHV_DEV_TYPE_VFIO,
   MSHV_DEV_VFIO_FILE, MSHV_DEV_VFIO_FILE_ADD, MSHV_CREATE_DEVICE_TEST
};
let mshv = Mshv::new().unwrap();
let vm = mshv.create_vm().unwrap();

let mut device = mshv_bindings::mshv_create_device {
    type_: MSHV_DEV_TYPE_VFIO,
    fd: 0,
    flags: MSHV_CREATE_DEVICE_TEST,
};

let device_fd = vm
    .create_device(&mut device)
    .expect("Cannot create MSHV device");

let dist_attr = mshv_bindings::mshv_device_attr {
    group: MSHV_DEV_VFIO_FILE,
    attr: u64::from(MSHV_DEV_VFIO_FILE_ADD),
    addr: 0,
    flags: 0,
};

if (device_fd.has_device_attr(&dist_attr).is_ok()) {
    device_fd.set_device_attr(&dist_attr).unwrap();
}
Source

pub fn get_device_attr( &self, device_attr: &mut mshv_device_attr, ) -> Result<(), MshvError>

Gets a specified piece of device configuration and/or state.

See the documentation for MSHV_GET_DEVICE_ATTR.

§Arguments
  • device_attr - The device attribute to be get. Note: This argument serves as both input and output. When calling this function, the user should explicitly provide valid values for the group and the attr field of the mshv_device_attr structure, and a valid userspace address (i.e. the addr field) to access the returned device attribute data.
§Returns
  • Returns the last occured errno wrapped in an Err.
  • device_attr - The addr field of the device_attr structure will point to the device attribute data.

Trait Implementations§

Source§

impl AsRawFd for DeviceFd

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl Debug for DeviceFd

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromRawFd for DeviceFd

Source§

unsafe fn from_raw_fd(fd: RawFd) -> Self

This function is also unsafe as the primitives currently returned have the contract that they are the sole owner of the file descriptor they are wrapping. Usage of this function could accidentally allow violating this contract which can cause memory unsafety in code that relies on it being true.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.