Skip to content

Commit

Permalink
fix: use check_extension instead of enable_cap in doctests
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
  • Loading branch information
roypat committed Oct 31, 2024
1 parent 7053ea6 commit 9f17761
Showing 1 changed file with 14 additions and 40 deletions.
54 changes: 14 additions & 40 deletions src/ioctls/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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();
Expand All @@ -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;
/// }
///
Expand Down Expand Up @@ -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;
///
Expand All @@ -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,
Expand Down

0 comments on commit 9f17761

Please sign in to comment.