device_manager: assert passthrough_device has the correct type

There is a lot of unsafe code in such a small function. Add an assert
to help detect issues earlier.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu 2022-07-09 12:13:44 +00:00 committed by Rob Bradford
parent 47b5581c50
commit 0e8769d76a

View File

@ -2959,6 +2959,8 @@ impl DeviceManager {
return vmm_sys_util::errno::errno_result().map_err(DeviceManagerError::DupFd);
}
assert!(passthrough_device.as_any().is::<DeviceFd>());
// SAFETY the raw fd conversion here is safe because:
// 1. When running on KVM or MSHV, passthrough_device wraps around DeviceFd.
// 2. The conversion here extracts the raw fd and then turns the raw fd into a DeviceFd