diff options
author | johannst <johannes.stoelp@gmail.com> | 2021-07-01 23:11:14 +0200 |
---|---|---|
committer | johannst <johannes.stoelp@gmail.com> | 2021-07-01 23:11:14 +0200 |
commit | 9f025e829ab6ed468cfb51d72ac105624afc3851 (patch) | |
tree | 2aaa2efdd2aced5ace9fedd8e04c020e1a96d575 /src/kvm.rs | |
parent | 4e1887f91c3f763fc8cd0797e8d96901139daf60 (diff) | |
download | mini-kvm-rs-9f025e829ab6ed468cfb51d72ac105624afc3851.tar.gz mini-kvm-rs-9f025e829ab6ed468cfb51d72ac105624afc3851.zip |
added support to query caps on kvm fd + few caps
Diffstat (limited to 'src/kvm.rs')
-rw-r--r-- | src/kvm.rs | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -4,8 +4,9 @@ use std::fs; use std::io; use std::os::unix::io::FromRawFd; -use crate::{libcret, ioctl, kvm_sys}; +use crate::cap::{CapBool, CapInt}; use crate::vm::Vm; +use crate::{ioctl, kvm_sys, libcret}; /// Wrapper for `/dev/kvm` ioctls. /// @@ -49,4 +50,24 @@ impl Kvm { Ok(Vm::new(vm, vcpu_mmap_size)) } + + /// Check availability of an extension with the [`KVM_CHECK_EXTENSION`][kvm-check-extension] + /// ioctl. + /// + /// [kvm-check-extension]: https://www.kernel.org/doc/html/latest/virt/kvm/api.html#kvm-check-extension + pub fn check_extenstion(&self, cap: CapBool) -> bool { + let ret = ioctl(&self.kvm, kvm_sys::KVM_CHECK_EXTENSION, cap.into()); + + matches!(ret, Ok(ret) if ret > 0) + } + + /// Check availability of an extension with the [`KVM_CHECK_EXTENSION`][kvm-check-extension] + /// ioctl. + /// + /// [kvm-check-extension]: https://www.kernel.org/doc/html/latest/virt/kvm/api.html#kvm-check-extension + pub fn check_extenstion_int(&self, cap: CapInt) -> i32 { + let ret = ioctl(&self.kvm, kvm_sys::KVM_CHECK_EXTENSION, cap.into()); + + ret.unwrap_or(0) + } } |