Skip to content

Commit 2deee03

Browse files
andreeaflorescujiangliu
authored andcommitted
run cargo fmt with new rust version
Signed-off-by: Andreea Florescu <[email protected]>
1 parent 346d472 commit 2deee03

File tree

3 files changed

+26
-75
lines changed

3 files changed

+26
-75
lines changed

src/ioctls/system.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,7 @@ impl Kvm {
283283
// SAFETY: The kernel is trusted not to write beyond the bounds of the memory
284284
// allocated for the struct. The limit is read from nent, which is set to the allocated
285285
// size(num_entries) above.
286-
let ret = unsafe {
287-
ioctl_with_mut_ptr(self, kind, cpuid.as_mut_fam_struct_ptr())
288-
};
286+
let ret = unsafe { ioctl_with_mut_ptr(self, kind, cpuid.as_mut_fam_struct_ptr()) };
289287
if ret < 0 {
290288
return Err(errno::Error::last());
291289
}

src/ioctls/vcpu.rs

Lines changed: 19 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,7 @@ impl VcpuFd {
357357
pub fn get_fpu(&self) -> Result<kvm_fpu> {
358358
let mut fpu = kvm_fpu::default();
359359
// SAFETY: Here we trust the kernel not to read past the end of the kvm_fpu struct.
360-
let ret = unsafe {
361-
ioctl_with_mut_ref(self, KVM_GET_FPU(), &mut fpu)
362-
};
360+
let ret = unsafe { ioctl_with_mut_ref(self, KVM_GET_FPU(), &mut fpu) };
363361
if ret != 0 {
364362
return Err(errno::Error::last());
365363
}
@@ -396,9 +394,7 @@ impl VcpuFd {
396394
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
397395
pub fn set_fpu(&self, fpu: &kvm_fpu) -> Result<()> {
398396
// SAFETY: Here we trust the kernel not to read past the end of the kvm_fpu struct.
399-
let ret = unsafe {
400-
ioctl_with_ref(self, KVM_SET_FPU(), fpu)
401-
};
397+
let ret = unsafe { ioctl_with_ref(self, KVM_SET_FPU(), fpu) };
402398
if ret < 0 {
403399
return Err(errno::Error::last());
404400
}
@@ -443,9 +439,7 @@ impl VcpuFd {
443439
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
444440
pub fn set_cpuid2(&self, cpuid: &CpuId) -> Result<()> {
445441
// SAFETY: Here we trust the kernel not to read past the end of the kvm_cpuid2 struct.
446-
let ret = unsafe {
447-
ioctl_with_ptr(self, KVM_SET_CPUID2(), cpuid.as_fam_struct_ptr())
448-
};
442+
let ret = unsafe { ioctl_with_ptr(self, KVM_SET_CPUID2(), cpuid.as_fam_struct_ptr()) };
449443
if ret < 0 {
450444
return Err(errno::Error::last());
451445
}
@@ -484,9 +478,8 @@ impl VcpuFd {
484478

485479
let mut cpuid = CpuId::new(num_entries).map_err(|_| errno::Error::new(libc::ENOMEM))?;
486480
// SAFETY: Here we trust the kernel not to read past the end of the kvm_cpuid2 struct.
487-
let ret = unsafe {
488-
ioctl_with_mut_ptr(self, KVM_GET_CPUID2(), cpuid.as_mut_fam_struct_ptr())
489-
};
481+
let ret =
482+
unsafe { ioctl_with_mut_ptr(self, KVM_GET_CPUID2(), cpuid.as_mut_fam_struct_ptr()) };
490483
if ret != 0 {
491484
return Err(errno::Error::last());
492485
}
@@ -563,9 +556,7 @@ impl VcpuFd {
563556

564557
// SAFETY: The ioctl is unsafe unless you trust the kernel not to write past the end of the
565558
// local_apic struct.
566-
let ret = unsafe {
567-
ioctl_with_mut_ref(self, KVM_GET_LAPIC(), &mut klapic)
568-
};
559+
let ret = unsafe { ioctl_with_mut_ref(self, KVM_GET_LAPIC(), &mut klapic) };
569560
if ret < 0 {
570561
return Err(errno::Error::last());
571562
}
@@ -607,9 +598,7 @@ impl VcpuFd {
607598
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
608599
pub fn set_lapic(&self, klapic: &kvm_lapic_state) -> Result<()> {
609600
// SAFETY: The ioctl is safe because the kernel will only read from the klapic struct.
610-
let ret = unsafe {
611-
ioctl_with_ref(self, KVM_SET_LAPIC(), klapic)
612-
};
601+
let ret = unsafe { ioctl_with_ref(self, KVM_SET_LAPIC(), klapic) };
613602
if ret < 0 {
614603
return Err(errno::Error::last());
615604
}
@@ -655,9 +644,7 @@ impl VcpuFd {
655644
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
656645
pub fn get_msrs(&self, msrs: &mut Msrs) -> Result<usize> {
657646
// SAFETY: Here we trust the kernel not to read past the end of the kvm_msrs struct.
658-
let ret = unsafe {
659-
ioctl_with_mut_ptr(self, KVM_GET_MSRS(), msrs.as_mut_fam_struct_ptr())
660-
};
647+
let ret = unsafe { ioctl_with_mut_ptr(self, KVM_GET_MSRS(), msrs.as_mut_fam_struct_ptr()) };
661648
if ret < 0 {
662649
return Err(errno::Error::last());
663650
}
@@ -696,9 +683,7 @@ impl VcpuFd {
696683
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
697684
pub fn set_msrs(&self, msrs: &Msrs) -> Result<usize> {
698685
// SAFETY: Here we trust the kernel not to read past the end of the kvm_msrs struct.
699-
let ret = unsafe {
700-
ioctl_with_ptr(self, KVM_SET_MSRS(), msrs.as_fam_struct_ptr())
701-
};
686+
let ret = unsafe { ioctl_with_ptr(self, KVM_SET_MSRS(), msrs.as_fam_struct_ptr()) };
702687
// KVM_SET_MSRS actually returns the number of msr entries written.
703688
if ret < 0 {
704689
return Err(errno::Error::last());
@@ -735,9 +720,7 @@ impl VcpuFd {
735720
pub fn get_mp_state(&self) -> Result<kvm_mp_state> {
736721
let mut mp_state = Default::default();
737722
// SAFETY: Here we trust the kernel not to read past the end of the kvm_mp_state struct.
738-
let ret = unsafe {
739-
ioctl_with_mut_ref(self, KVM_GET_MP_STATE(), &mut mp_state)
740-
};
723+
let ret = unsafe { ioctl_with_mut_ref(self, KVM_GET_MP_STATE(), &mut mp_state) };
741724
if ret != 0 {
742725
return Err(errno::Error::last());
743726
}
@@ -774,9 +757,7 @@ impl VcpuFd {
774757
))]
775758
pub fn set_mp_state(&self, mp_state: kvm_mp_state) -> Result<()> {
776759
// SAFETY: Here we trust the kernel not to read past the end of the kvm_mp_state struct.
777-
let ret = unsafe {
778-
ioctl_with_ref(self, KVM_SET_MP_STATE(), &mp_state)
779-
};
760+
let ret = unsafe { ioctl_with_ref(self, KVM_SET_MP_STATE(), &mp_state) };
780761
if ret != 0 {
781762
return Err(errno::Error::last());
782763
}
@@ -806,9 +787,7 @@ impl VcpuFd {
806787
pub fn get_xsave(&self) -> Result<kvm_xsave> {
807788
let mut xsave = Default::default();
808789
// SAFETY: Here we trust the kernel not to read past the end of the kvm_xsave struct.
809-
let ret = unsafe {
810-
ioctl_with_mut_ref(self, KVM_GET_XSAVE(), &mut xsave)
811-
};
790+
let ret = unsafe { ioctl_with_mut_ref(self, KVM_GET_XSAVE(), &mut xsave) };
812791
if ret != 0 {
813792
return Err(errno::Error::last());
814793
}
@@ -839,9 +818,7 @@ impl VcpuFd {
839818
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
840819
pub fn set_xsave(&self, xsave: &kvm_xsave) -> Result<()> {
841820
// SAFETY: Here we trust the kernel not to read past the end of the kvm_xsave struct.
842-
let ret = unsafe {
843-
ioctl_with_ref(self, KVM_SET_XSAVE(), xsave)
844-
};
821+
let ret = unsafe { ioctl_with_ref(self, KVM_SET_XSAVE(), xsave) };
845822
if ret != 0 {
846823
return Err(errno::Error::last());
847824
}
@@ -871,9 +848,7 @@ impl VcpuFd {
871848
pub fn get_xcrs(&self) -> Result<kvm_xcrs> {
872849
let mut xcrs = Default::default();
873850
// SAFETY: Here we trust the kernel not to read past the end of the kvm_xcrs struct.
874-
let ret = unsafe {
875-
ioctl_with_mut_ref(self, KVM_GET_XCRS(), &mut xcrs)
876-
};
851+
let ret = unsafe { ioctl_with_mut_ref(self, KVM_GET_XCRS(), &mut xcrs) };
877852
if ret != 0 {
878853
return Err(errno::Error::last());
879854
}
@@ -904,9 +879,7 @@ impl VcpuFd {
904879
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
905880
pub fn set_xcrs(&self, xcrs: &kvm_xcrs) -> Result<()> {
906881
// SAFETY: Here we trust the kernel not to read past the end of the kvm_xcrs struct.
907-
let ret = unsafe {
908-
ioctl_with_ref(self, KVM_SET_XCRS(), xcrs)
909-
};
882+
let ret = unsafe { ioctl_with_ref(self, KVM_SET_XCRS(), xcrs) };
910883
if ret != 0 {
911884
return Err(errno::Error::last());
912885
}
@@ -936,9 +909,7 @@ impl VcpuFd {
936909
pub fn get_debug_regs(&self) -> Result<kvm_debugregs> {
937910
let mut debug_regs = Default::default();
938911
// SAFETY: Here we trust the kernel not to read past the end of the kvm_debugregs struct.
939-
let ret = unsafe {
940-
ioctl_with_mut_ref(self, KVM_GET_DEBUGREGS(), &mut debug_regs)
941-
};
912+
let ret = unsafe { ioctl_with_mut_ref(self, KVM_GET_DEBUGREGS(), &mut debug_regs) };
942913
if ret != 0 {
943914
return Err(errno::Error::last());
944915
}
@@ -969,9 +940,7 @@ impl VcpuFd {
969940
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
970941
pub fn set_debug_regs(&self, debug_regs: &kvm_debugregs) -> Result<()> {
971942
// SAFETY: Here we trust the kernel not to read past the end of the kvm_debugregs struct.
972-
let ret = unsafe {
973-
ioctl_with_ref(self, KVM_SET_DEBUGREGS(), debug_regs)
974-
};
943+
let ret = unsafe { ioctl_with_ref(self, KVM_SET_DEBUGREGS(), debug_regs) };
975944
if ret != 0 {
976945
return Err(errno::Error::last());
977946
}
@@ -1009,9 +978,7 @@ impl VcpuFd {
1009978
pub fn get_vcpu_events(&self) -> Result<kvm_vcpu_events> {
1010979
let mut vcpu_events = Default::default();
1011980
// SAFETY: Here we trust the kernel not to read past the end of the kvm_vcpu_events struct.
1012-
let ret = unsafe {
1013-
ioctl_with_mut_ref(self, KVM_GET_VCPU_EVENTS(), &mut vcpu_events)
1014-
};
981+
let ret = unsafe { ioctl_with_mut_ref(self, KVM_GET_VCPU_EVENTS(), &mut vcpu_events) };
1015982
if ret != 0 {
1016983
return Err(errno::Error::last());
1017984
}
@@ -1050,9 +1017,7 @@ impl VcpuFd {
10501017

10511018
pub fn set_vcpu_events(&self, vcpu_events: &kvm_vcpu_events) -> Result<()> {
10521019
// SAFETY: Here we trust the kernel not to read past the end of the kvm_vcpu_events struct.
1053-
let ret = unsafe {
1054-
ioctl_with_ref(self, KVM_SET_VCPU_EVENTS(), vcpu_events)
1055-
};
1020+
let ret = unsafe { ioctl_with_ref(self, KVM_SET_VCPU_EVENTS(), vcpu_events) };
10561021
if ret != 0 {
10571022
return Err(errno::Error::last());
10581023
}

src/ioctls/vm.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,7 @@ impl VmFd {
240240
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
241241
pub fn get_irqchip(&self, irqchip: &mut kvm_irqchip) -> Result<()> {
242242
// SAFETY: Here we trust the kernel not to read past the end of the kvm_irqchip struct.
243-
let ret = unsafe {
244-
ioctl_with_mut_ref(self, KVM_GET_IRQCHIP(), irqchip)
245-
};
243+
let ret = unsafe { ioctl_with_mut_ref(self, KVM_GET_IRQCHIP(), irqchip) };
246244
if ret == 0 {
247245
Ok(())
248246
} else {
@@ -278,9 +276,7 @@ impl VmFd {
278276
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
279277
pub fn set_irqchip(&self, irqchip: &kvm_irqchip) -> Result<()> {
280278
// SAFETY: Here we trust the kernel not to read past the end of the kvm_irqchip struct.
281-
let ret = unsafe {
282-
ioctl_with_ref(self, KVM_SET_IRQCHIP(), irqchip)
283-
};
279+
let ret = unsafe { ioctl_with_ref(self, KVM_SET_IRQCHIP(), irqchip) };
284280
if ret == 0 {
285281
Ok(())
286282
} else {
@@ -346,9 +342,7 @@ impl VmFd {
346342
pub fn get_pit2(&self) -> Result<kvm_pit_state2> {
347343
let mut pitstate = Default::default();
348344
// SAFETY: Here we trust the kernel not to read past the end of the kvm_pit_state2 struct.
349-
let ret = unsafe {
350-
ioctl_with_mut_ref(self, KVM_GET_PIT2(), &mut pitstate)
351-
};
345+
let ret = unsafe { ioctl_with_mut_ref(self, KVM_GET_PIT2(), &mut pitstate) };
352346
if ret == 0 {
353347
Ok(pitstate)
354348
} else {
@@ -384,9 +378,7 @@ impl VmFd {
384378
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
385379
pub fn set_pit2(&self, pitstate: &kvm_pit_state2) -> Result<()> {
386380
// SAFETY: Here we trust the kernel not to read past the end of the kvm_pit_state2 struct.
387-
let ret = unsafe {
388-
ioctl_with_ref(self, KVM_SET_PIT2(), pitstate)
389-
};
381+
let ret = unsafe { ioctl_with_ref(self, KVM_SET_PIT2(), pitstate) };
390382
if ret == 0 {
391383
Ok(())
392384
} else {
@@ -416,9 +408,7 @@ impl VmFd {
416408
pub fn get_clock(&self) -> Result<kvm_clock_data> {
417409
let mut clock = Default::default();
418410
// SAFETY: Here we trust the kernel not to read past the end of the kvm_clock_data struct.
419-
let ret = unsafe {
420-
ioctl_with_mut_ref(self, KVM_GET_CLOCK(), &mut clock)
421-
};
411+
let ret = unsafe { ioctl_with_mut_ref(self, KVM_GET_CLOCK(), &mut clock) };
422412
if ret == 0 {
423413
Ok(clock)
424414
} else {
@@ -450,9 +440,7 @@ impl VmFd {
450440
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
451441
pub fn set_clock(&self, clock: &kvm_clock_data) -> Result<()> {
452442
// SAFETY: Here we trust the kernel not to read past the end of the kvm_clock_data struct.
453-
let ret = unsafe {
454-
ioctl_with_ref(self, KVM_SET_CLOCK(), clock)
455-
};
443+
let ret = unsafe { ioctl_with_ref(self, KVM_SET_CLOCK(), clock) };
456444
if ret == 0 {
457445
Ok(())
458446
} else {

0 commit comments

Comments
 (0)