aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/kvm.rs
diff options
context:
space:
mode:
authorjohannst <johannes.stoelp@gmail.com>2021-06-02 00:11:49 +0200
committerjohannst <johannes.stoelp@gmail.com>2021-06-02 00:11:49 +0200
commit50bd6e37219fd6dabee4f661ed3530c0331c7b06 (patch)
tree27a62c40cbda59b58efc3d83f1bf9751c28cd394 /src/kvm.rs
parent7e278dcb3df79f8c8b87d8147deca7280eefb7ec (diff)
downloadmini-kvm-rs-50bd6e37219fd6dabee4f661ed3530c0331c7b06.tar.gz
mini-kvm-rs-50bd6e37219fd6dabee4f661ed3530c0331c7b06.zip
added doc
Diffstat (limited to 'src/kvm.rs')
-rw-r--r--src/kvm.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/kvm.rs b/src/kvm.rs
index 3522adc..23112aa 100644
--- a/src/kvm.rs
+++ b/src/kvm.rs
@@ -1,3 +1,5 @@
+//! KVM system ioctls.
+
use std::fs;
use std::io;
use std::os::unix::io::FromRawFd;
@@ -5,11 +7,18 @@ use std::os::unix::io::FromRawFd;
use crate::{libcret, ioctl, kvm_sys};
use crate::vm::Vm;
+/// Wrapper for `/dev/kvm` ioctls.
+///
+/// Representation of the file descriptor obtained by opening `/dev/kvm`.
+/// This wrapper provides access to the `system ioctls` as described in [KVM API][kvm].
+///
+/// [kvm]: https://www.kernel.org/doc/html/latest/virt/kvm/api.html#general-description
pub struct Kvm {
kvm: fs::File,
}
impl Kvm {
+ /// Open the `/dev/kvm` device.
pub fn new() -> io::Result<Kvm> {
let kvm = libcret(unsafe {
libc::open("/dev/kvm\0".as_ptr().cast(), libc::O_RDWR | libc::O_CLOEXEC)
@@ -28,6 +37,10 @@ impl Kvm {
ioctl(&self.kvm, kvm_sys::KVM_GET_VCPU_MMAP_SIZE, 0).map(|size| size as usize)
}
+ /// Create a new virtual machine with the [`KVM_CREATE_VM`][kvm-create-vm] ioctl.
+ /// Returns a wrapper [`vm::Vm`][crate::vm::Vm] representing the VM.
+ ///
+ /// [kvm-create-vm]: https://www.kernel.org/doc/html/latest/virt/kvm/api.html#kvm-create-vm
pub fn create_vm(&self) -> io::Result<Vm> {
let vm = ioctl(&self.kvm, kvm_sys::KVM_CREATE_VM, 0 /* machine id */)
.map(|fd| unsafe { fs::File::from_raw_fd(fd) })?;