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
impl DeviceFd
Sourcepub fn has_device_attr(
&self,
device_attr: &mshv_device_attr,
) -> Result<(), MshvError>
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.addrfield is ignored.
Sourcepub fn set_device_attr(
&self,
device_attr: &mshv_device_attr,
) -> Result<(), MshvError>
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();
}Sourcepub fn get_device_attr(
&self,
device_attr: &mut mshv_device_attr,
) -> Result<(), MshvError>
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 thegroupand theattrfield of themshv_device_attrstructure, and a valid userspace address (i.e. theaddrfield) to access the returned device attribute data.
§Returns
- Returns the last occured
errnowrapped in anErr. device_attr- Theaddrfield of thedevice_attrstructure will point to the device attribute data.
Trait Implementations§
Source§impl FromRawFd for DeviceFd
impl FromRawFd for DeviceFd
Source§unsafe fn from_raw_fd(fd: RawFd) -> Self
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§
impl Freeze for DeviceFd
impl RefUnwindSafe for DeviceFd
impl Send for DeviceFd
impl Sync for DeviceFd
impl Unpin for DeviceFd
impl UnsafeUnpin for DeviceFd
impl UnwindSafe for DeviceFd
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more