Skip to content

Commit b80cbcf

Browse files
fix style in code examples
Signed-off-by: Andreea Florescu <[email protected]>
1 parent a6a4b1b commit b80cbcf

File tree

7 files changed

+98
-176
lines changed

7 files changed

+98
-176
lines changed

src/cap.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use kvm_bindings::*;
1515
///
1616
/// The list of capabilities is based on the the KVM_CAP_* defines from the
1717
/// [Linux KVM header](https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/kvm.h).
18-
///
1918
#[derive(Clone, Copy, Debug)]
2019
#[repr(u32)]
2120
// We are allowing docs to be missing here because this enum is a wrapper

src/ioctls/device.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ impl DeviceFd {
2222
/// # Arguments
2323
///
2424
/// * `device_attr` - The device attribute to be tested. `addr` field is ignored.
25-
///
2625
pub fn has_device_attr(&self, device_attr: &kvm_device_attr) -> Result<()> {
2726
let ret = unsafe { ioctl_with_ref(self, KVM_HAS_DEVICE_ATTR(), device_attr) };
2827
if ret != 0 {
@@ -72,7 +71,6 @@ impl DeviceFd {
7271
/// device_fd.set_device_attr(&dist_attr).unwrap();
7372
/// }
7473
/// ```
75-
///
7674
pub fn set_device_attr(&self, device_attr: &kvm_device_attr) -> Result<()> {
7775
let ret = unsafe { ioctl_with_ref(self, KVM_SET_DEVICE_ATTR(), device_attr) };
7876
if ret != 0 {
@@ -115,8 +113,8 @@ impl DeviceFd {
115113
/// #[cfg(any(target_arch = "aarch64"))]
116114
/// {
117115
/// use kvm_bindings::{
118-
/// KVM_DEV_ARM_VGIC_GRP_NR_IRQS, kvm_device_type_KVM_DEV_TYPE_ARM_VGIC_V2,
119-
/// kvm_device_type_KVM_DEV_TYPE_ARM_VGIC_V3,
116+
/// kvm_device_type_KVM_DEV_TYPE_ARM_VGIC_V2, kvm_device_type_KVM_DEV_TYPE_ARM_VGIC_V3,
117+
/// KVM_DEV_ARM_VGIC_GRP_NR_IRQS,
120118
/// };
121119
///
122120
/// // Create a GIC device.
@@ -126,12 +124,12 @@ impl DeviceFd {
126124
/// flags: 0,
127125
/// };
128126
/// let device_fd = match vm.create_device(&mut gic_device) {
129-
/// Ok(fd) => fd,
130-
/// Err(_) => {
131-
/// gic_device.type_ = kvm_device_type_KVM_DEV_TYPE_ARM_VGIC_V2;
132-
/// vm.create_device(&mut gic_device)
133-
/// .expect("Cannot create KVM vGIC device")
134-
/// }
127+
/// Ok(fd) => fd,
128+
/// Err(_) => {
129+
/// gic_device.type_ = kvm_device_type_KVM_DEV_TYPE_ARM_VGIC_V2;
130+
/// vm.create_device(&mut gic_device)
131+
/// .expect("Cannot create KVM vGIC device")
132+
/// }
135133
/// };
136134
///
137135
/// let mut data: u32 = 0;
@@ -142,7 +140,6 @@ impl DeviceFd {
142140
/// device_fd.get_device_attr(&mut gic_attr).unwrap();
143141
/// }
144142
/// ```
145-
///
146143
pub fn get_device_attr(&self, device_attr: &mut kvm_device_attr) -> Result<()> {
147144
let ret = unsafe { ioctl_with_mut_ref(self, KVM_GET_DEVICE_ATTR(), device_attr) };
148145
if ret != 0 {

src/ioctls/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ impl KvmRunWrapper {
7373
}
7474

7575
/// Returns a mutable reference to `kvm_run`.
76-
///
7776
#[allow(clippy::mut_from_ref)]
7877
pub fn as_mut_ref(&self) -> &mut kvm_run {
7978
// Safe because we know we mapped enough memory to hold the kvm_run struct because the

src/ioctls/system.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ impl Kvm {
3636
/// use kvm_ioctls::Kvm;
3737
/// let kvm = Kvm::new().unwrap();
3838
/// ```
39-
///
4039
#[allow(clippy::new_ret_no_self)]
4140
pub fn new() -> Result<Self> {
4241
// Open `/dev/kvm` using `O_CLOEXEC` flag.
@@ -66,7 +65,6 @@ impl Kvm {
6665
/// // `from_raw_fd` for creating a `Kvm` object:
6766
/// let kvm = unsafe { Kvm::from_raw_fd(kvm_fd) };
6867
/// ```
69-
///
7068
pub fn open_with_cloexec(close_on_exec: bool) -> Result<RawFd> {
7169
let open_flags = O_RDWR | if close_on_exec { O_CLOEXEC } else { 0 };
7270
// Safe because we give a constant nul-terminated string and verify the result.
@@ -89,7 +87,6 @@ impl Kvm {
8987
/// let kvm = Kvm::new().unwrap();
9088
/// assert_eq!(kvm.get_api_version(), 12);
9189
/// ```
92-
///
9390
pub fn get_api_version(&self) -> i32 {
9491
// Safe because we know that our file is a KVM fd and that the request is one of the ones
9592
// defined by kernel.
@@ -132,7 +129,6 @@ impl Kvm {
132129
/// // Check if `KVM_CAP_USER_MEMORY` is supported.
133130
/// assert!(kvm.check_extension(Cap::UserMemory));
134131
/// ```
135-
///
136132
pub fn check_extension(&self, c: Cap) -> bool {
137133
self.check_extension_int(c) > 0
138134
}
@@ -148,7 +144,6 @@ impl Kvm {
148144
/// let kvm = Kvm::new().unwrap();
149145
/// assert!(kvm.get_vcpu_mmap_size().unwrap() > 0);
150146
/// ```
151-
///
152147
pub fn get_vcpu_mmap_size(&self) -> Result<usize> {
153148
// Safe because we know that our file is a KVM fd and we verify the return result.
154149
let res = unsafe { ioctl(self, KVM_GET_VCPU_MMAP_SIZE()) };
@@ -172,7 +167,6 @@ impl Kvm {
172167
/// // We expect the number of vCPUs to be > 0 as per KVM API documentation.
173168
/// assert!(kvm.get_nr_vcpus() > 0);
174169
/// ```
175-
///
176170
pub fn get_nr_vcpus(&self) -> usize {
177171
let x = self.check_extension_int(Cap::NrVcpus);
178172
if x > 0 {
@@ -196,7 +190,6 @@ impl Kvm {
196190
/// let kvm = Kvm::new().unwrap();
197191
/// assert!(kvm.get_nr_memslots() > 0);
198192
/// ```
199-
///
200193
pub fn get_nr_memslots(&self) -> usize {
201194
let x = self.check_extension_int(Cap::NrMemslots);
202195
if x > 0 {
@@ -219,7 +212,6 @@ impl Kvm {
219212
/// let kvm = Kvm::new().unwrap();
220213
/// assert!(kvm.get_max_vcpus() > 0);
221214
/// ```
222-
///
223215
pub fn get_max_vcpus(&self) -> usize {
224216
match self.check_extension_int(Cap::MaxVcpus) {
225217
0 => self.get_nr_vcpus(),
@@ -240,7 +232,6 @@ impl Kvm {
240232
/// let kvm = Kvm::new().unwrap();
241233
/// assert!(kvm.get_max_vcpu_id() > 0);
242234
/// ```
243-
///
244235
pub fn get_max_vcpu_id(&self) -> usize {
245236
match self.check_extension_int(Cap::MaxVcpuId) {
246237
0 => self.get_max_vcpus(),
@@ -294,7 +285,6 @@ impl Kvm {
294285
/// let cpuid_entries = cpuid.as_mut_slice();
295286
/// assert!(cpuid_entries.len() <= KVM_MAX_CPUID_ENTRIES);
296287
/// ```
297-
///
298288
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
299289
pub fn get_emulated_cpuid(&self, num_entries: usize) -> Result<CpuId> {
300290
self.get_cpuid(KVM_GET_EMULATED_CPUID(), num_entries)
@@ -324,7 +314,6 @@ impl Kvm {
324314
/// let cpuid_entries = cpuid.as_mut_slice();
325315
/// assert!(cpuid_entries.len() <= KVM_MAX_CPUID_ENTRIES);
326316
/// ```
327-
///
328317
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
329318
pub fn get_supported_cpuid(&self, num_entries: usize) -> Result<CpuId> {
330319
self.get_cpuid(KVM_GET_SUPPORTED_CPUID(), num_entries)
@@ -380,7 +369,6 @@ impl Kvm {
380369
/// // Check that the VM mmap size is the same reported by `KVM_GET_VCPU_MMAP_SIZE`.
381370
/// assert!(vm.run_size() == kvm.get_vcpu_mmap_size().unwrap());
382371
/// ```
383-
///
384372
#[cfg(not(any(target_arch = "aarch64")))]
385373
pub fn create_vm(&self) -> Result<VmFd> {
386374
self.create_vm_with_type(0) // Create using default VM type
@@ -401,7 +389,6 @@ impl Kvm {
401389
/// // Check that the VM mmap size is the same reported by `KVM_GET_VCPU_MMAP_SIZE`.
402390
/// assert!(vm.run_size() == kvm.get_vcpu_mmap_size().unwrap());
403391
/// ```
404-
///
405392
#[cfg(any(target_arch = "aarch64"))]
406393
pub fn create_vm(&self) -> Result<VmFd> {
407394
let mut ipa_size = 0; // Create using default VM type
@@ -441,7 +428,6 @@ impl Kvm {
441428
/// assert!(vm.run_size() == kvm.get_vcpu_mmap_size().unwrap());
442429
/// }
443430
/// ```
444-
///
445431
#[cfg(any(target_arch = "aarch64"))]
446432
pub fn create_vm_with_ipa_size(&self, ipa_size: u32) -> Result<VmFd> {
447433
self.create_vm_with_type((ipa_size & KVM_VM_TYPE_ARM_IPA_SIZE_MASK).into())
@@ -464,7 +450,6 @@ impl Kvm {
464450
/// // Check that the VM mmap size is the same reported by `KVM_GET_VCPU_MMAP_SIZE`.
465451
/// assert!(vm.run_size() == kvm.get_vcpu_mmap_size().unwrap());
466452
/// ```
467-
///
468453
pub fn create_vm_with_type(&self, vm_type: u64) -> Result<VmFd> {
469454
// Safe because we know `self.kvm` is a real KVM fd as this module is the only one that
470455
// create Kvm objects.
@@ -506,7 +491,6 @@ impl Kvm {
506491
/// assert!(rawfd >= 0);
507492
/// let vm = unsafe { kvm.create_vmfd_from_rawfd(rawfd).unwrap() };
508493
/// ```
509-
///
510494
pub unsafe fn create_vmfd_from_rawfd(&self, fd: RawFd) -> Result<VmFd> {
511495
let run_mmap_size = self.get_vcpu_mmap_size()?;
512496
Ok(new_vmfd(File::from_raw_fd(fd), run_mmap_size))
@@ -547,7 +531,6 @@ impl FromRawFd for Kvm {
547531
/// // Safe because we verify that the fd is valid in `open_with_cloexec` and we own the fd.
548532
/// let kvm = unsafe { Kvm::from_raw_fd(kvm_fd) };
549533
/// ```
550-
///
551534
unsafe fn from_raw_fd(fd: RawFd) -> Self {
552535
Kvm {
553536
kvm: File::from_raw_fd(fd),

0 commit comments

Comments
 (0)