From 9f17761ac799109044d2c8af4e4f86edf156ca25 Mon Sep 17 00:00:00 2001 From: Patrick Roy Date: Thu, 31 Oct 2024 11:35:48 +0000 Subject: [PATCH] fix: use check_extension instead of enable_cap in doctests Signed-off-by: Patrick Roy --- src/ioctls/vm.rs | 54 +++++++++++++----------------------------------- 1 file changed, 14 insertions(+), 40 deletions(-) diff --git a/src/ioctls/vm.rs b/src/ioctls/vm.rs index a3cbb881..92e2f736 100644 --- a/src/ioctls/vm.rs +++ b/src/ioctls/vm.rs @@ -145,10 +145,10 @@ impl VmFd { /// extern crate kvm_bindings; /// /// use kvm_bindings::{ - /// kvm_create_guest_memfd, kvm_enable_cap, kvm_userspace_memory_region2, KVM_CAP_GUEST_MEMFD, + /// kvm_create_guest_memfd, kvm_userspace_memory_region2, KVM_CAP_GUEST_MEMFD, /// KVM_CAP_USER_MEMORY2, KVM_MEM_GUEST_MEMFD, /// }; - /// use kvm_ioctls::Kvm; + /// use kvm_ioctls::{Cap, Kvm}; /// use std::os::fd::RawFd; /// /// let kvm = Kvm::new().unwrap(); @@ -162,14 +162,10 @@ impl VmFd { /// let address_space = unsafe { libc::mmap(0 as _, 10000, 3, 34, -1, 0) }; /// let userspace_addr = address_space as *const u8 as u64; /// - /// let mut config = kvm_enable_cap { - /// cap: KVM_CAP_GUEST_MEMFD, - /// ..Default::default() - /// }; - /// - /// if vm.enable_cap(&config).is_err() { + /// if !vm.check_extension(Cap::GuestMemfd) || !vm.check_extension(Cap::UserMemory2) { /// return; /// } + /// /// let gmem = kvm_create_guest_memfd { /// size: 0x10000, /// flags: 0, @@ -178,12 +174,6 @@ impl VmFd { /// /// let fd: RawFd = unsafe { vm.create_guest_memfd(gmem).unwrap() }; /// - /// config.cap = KVM_CAP_USER_MEMORY2; - /// - /// if vm.enable_cap(&config).is_err() { - /// return; - /// } - /// /// let mem_region = kvm_userspace_memory_region2 { /// slot: 0, /// flags: KVM_MEM_GUEST_MEMFD, @@ -1460,8 +1450,8 @@ impl VmFd { /// # extern crate kvm_ioctls; /// extern crate kvm_bindings; /// - /// # use kvm_ioctls::Kvm; - /// use kvm_bindings::{kvm_create_guest_memfd, kvm_enable_cap, KVM_CAP_GUEST_MEMFD}; + /// # use kvm_ioctls::{Cap, Kvm}; + /// use kvm_bindings::{kvm_create_guest_memfd, KVM_CAP_GUEST_MEMFD}; /// use std::os::fd::RawFd; /// /// let kvm = Kvm::new().unwrap(); @@ -1472,12 +1462,7 @@ impl VmFd { /// #[cfg(target_arch = "aarch64")] /// let vm = kvm.create_vm().unwrap(); /* ARM does not yet have a vm type that supports gmem */ /// - /// let config = kvm_enable_cap { - /// cap: KVM_CAP_GUEST_MEMFD, - /// ..Default::default() - /// }; - /// - /// if vm.enable_cap(&config).is_err() { + /// if !vm.check_extension(Cap::GuestMemfd) { /// return; /// } /// @@ -1520,9 +1505,9 @@ impl VmFd { /// /// # use kvm_ioctls::Kvm; /// use kvm_bindings::{ - /// kvm_create_guest_memfd, kvm_enable_cap, kvm_memory_attributes, - /// kvm_userspace_memory_region2, KVM_CAP_GUEST_MEMFD, KVM_CAP_MEMORY_ATTRIBUTES, - /// KVM_CAP_USER_MEMORY2, KVM_MEMORY_ATTRIBUTE_PRIVATE, KVM_MEM_GUEST_MEMFD, + /// kvm_create_guest_memfd, kvm_memory_attributes, kvm_userspace_memory_region2, + /// KVM_CAP_GUEST_MEMFD, KVM_CAP_MEMORY_ATTRIBUTES, KVM_CAP_USER_MEMORY2, + /// KVM_MEMORY_ATTRIBUTE_PRIVATE, KVM_MEM_GUEST_MEMFD, /// }; /// use std::os::fd::RawFd; /// @@ -1541,25 +1526,14 @@ impl VmFd { /// /// let address_space = unsafe { libc::mmap(0 as _, 10000, 3, 34, -1, 0) }; /// let userspace_addr = address_space as *const u8 as u64; - /// let mut config = kvm_enable_cap { - /// cap: KVM_CAP_GUEST_MEMFD, - /// ..Default::default() - /// }; /// - /// if vm.enable_cap(&config).is_err() { - /// return; - /// } - /// - /// config.cap = KVM_CAP_USER_MEMORY2; - /// - /// if vm.enable_cap(&config).is_err() { + /// if !vm.check_extension(Cap::GuestMemfd) + /// || !vm.check_extension(Cap::UserMemory2) + /// || !vm.check_extension(Cap::MemoryAttributes) + /// { /// return; /// } - /// config.cap = KVM_CAP_MEMORY_ATTRIBUTES; /// - /// if vm.enable_cap(&config).is_err() { - /// return; - /// } /// let fd: RawFd = unsafe { vm.create_guest_memfd(gmem).unwrap() }; /// let mem_region = kvm_userspace_memory_region2 { /// slot: 0,