build: Remove unnecessary Result<> returns

If the function can never return an error this is now a clippy failure:

error: this function's return value is unnecessarily wrapped by `Result`
   --> virtio-devices/src/watchdog.rs:215:5
    |
215 | /     fn set_state(&mut self, state: &WatchdogState) -> io::Result<()> {
216 | |         self.common.avail_features = state.avail_features;
217 | |         self.common.acked_features = state.acked_features;
218 | |         // When restoring enable the watchdog if it was previously enabled. We reset the timer
...   |
223 | |         Ok(())
224 | |     }
    | |_____^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_wraps

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2021-02-11 16:00:53 +00:00
parent 8e9a5a0dbb
commit 9c5be6f660
19 changed files with 198 additions and 334 deletions

View File

@ -516,7 +516,7 @@ fn configure_pvh(
let mut memmap: Vec<hvm_memmap_table_entry> = Vec::new();
// Create the memory map entries.
add_memmap_entry(&mut memmap, 0, layout::EBDA_START.raw_value(), E820_RAM)?;
add_memmap_entry(&mut memmap, 0, layout::EBDA_START.raw_value(), E820_RAM);
let mem_end = guest_mem.last_addr();
@ -526,21 +526,21 @@ fn configure_pvh(
layout::HIGH_RAM_START.raw_value(),
mem_end.unchecked_offset_from(layout::HIGH_RAM_START) + 1,
E820_RAM,
)?;
);
} else {
add_memmap_entry(
&mut memmap,
layout::HIGH_RAM_START.raw_value(),
layout::MEM_32BIT_RESERVED_START.unchecked_offset_from(layout::HIGH_RAM_START),
E820_RAM,
)?;
);
if mem_end > layout::RAM_64BIT_START {
add_memmap_entry(
&mut memmap,
layout::RAM_64BIT_START.raw_value(),
mem_end.unchecked_offset_from(layout::RAM_64BIT_START) + 1,
E820_RAM,
)?;
);
}
}
@ -549,7 +549,7 @@ fn configure_pvh(
layout::PCI_MMCONFIG_START.0,
layout::PCI_MMCONFIG_SIZE,
E820_RESERVED,
)?;
);
if let Some(sgx_epc_region) = sgx_epc_region {
add_memmap_entry(
@ -557,7 +557,7 @@ fn configure_pvh(
sgx_epc_region.start().raw_value(),
sgx_epc_region.size() as u64,
E820_RESERVED,
)?;
);
}
start_info.0.memmap_entries = memmap.len() as u32;
@ -602,12 +602,7 @@ fn configure_pvh(
Ok(())
}
fn add_memmap_entry(
memmap: &mut Vec<hvm_memmap_table_entry>,
addr: u64,
size: u64,
mem_type: u32,
) -> Result<(), Error> {
fn add_memmap_entry(memmap: &mut Vec<hvm_memmap_table_entry>, addr: u64, size: u64, mem_type: u32) {
// Add the table entry to the vector
memmap.push(hvm_memmap_table_entry {
addr,
@ -615,8 +610,6 @@ fn add_memmap_entry(
type_: mem_type,
reserved: 0,
});
Ok(())
}
fn configure_64bit_boot(
@ -1092,8 +1085,8 @@ mod tests {
},
];
add_memmap_entry(&mut memmap, 0, 0x1000, E820_RAM).unwrap();
add_memmap_entry(&mut memmap, 0x10000, 0xa000, E820_RESERVED).unwrap();
add_memmap_entry(&mut memmap, 0, 0x1000, E820_RAM);
add_memmap_entry(&mut memmap, 0x10000, 0xa000, E820_RESERVED);
assert_eq!(format!("{:?}", memmap), format!("{:?}", expected_memmap));
}

View File

@ -224,7 +224,7 @@ mod tests {
#[test]
// cmp ah,al
fn test_cmp_rm8_r8_1() -> MockResult {
fn test_cmp_rm8_r8_1() {
let rax: u64 = 0x0;
let ip: u64 = 0x1000;
let cpu_id = 0;
@ -234,13 +234,11 @@ mod tests {
let rflags: u64 = vmm.cpu_state(cpu_id).unwrap().flags() & FLAGS_MASK;
assert_eq!(0b1000100, rflags);
Ok(())
}
#[test]
// cmp eax,100
fn test_cmp_rm32_imm8_1() -> MockResult {
fn test_cmp_rm32_imm8_1() {
let rax: u64 = 0xabcdef;
let ip: u64 = 0x1000;
let cpu_id = 0;
@ -250,13 +248,11 @@ mod tests {
let rflags: u64 = vmm.cpu_state(cpu_id).unwrap().flags() & FLAGS_MASK;
assert_eq!(0b100, rflags);
Ok(())
}
#[test]
// cmp eax,-1
fn test_cmp_rm32_imm8_2() -> MockResult {
fn test_cmp_rm32_imm8_2() {
let rax: u64 = 0xabcdef;
let ip: u64 = 0x1000;
let cpu_id = 0;
@ -266,13 +262,11 @@ mod tests {
let rflags: u64 = vmm.cpu_state(cpu_id).unwrap().flags() & FLAGS_MASK;
assert_eq!(0b101, rflags);
Ok(())
}
#[test]
// cmp rax,rbx
fn test_cmp_rm64_r64() -> MockResult {
fn test_cmp_rm64_r64() {
let rax: u64 = 0xabcdef;
let rbx: u64 = 0x1234;
let ip: u64 = 0x1000;
@ -283,12 +277,10 @@ mod tests {
let rflags: u64 = vmm.cpu_state(cpu_id).unwrap().flags() & FLAGS_MASK;
assert_eq!(0b100, rflags);
Ok(())
}
#[test]
fn test_cmp_64() -> MockResult {
fn test_cmp_64() {
let data = [
(0xabcdef, 0x1234, 0b100),
(0x0, 0x101, 0b1001_0101),
@ -313,12 +305,10 @@ mod tests {
let rflags: u64 = vmm.cpu_state(0).unwrap().flags() & FLAGS_MASK;
assert_eq!(d.2, rflags);
}
Ok(())
}
#[test]
fn test_cmp_32() -> MockResult {
fn test_cmp_32() {
let data = [
(0xabcdef, 0x1234, 0b100),
(0x0, 0x101, 0b1001_0101),
@ -343,7 +333,5 @@ mod tests {
let rflags: u64 = vmm.cpu_state(0).unwrap().flags() & FLAGS_MASK;
assert_eq!(d.2, rflags);
}
Ok(())
}
}

View File

@ -249,7 +249,7 @@ mod tests {
#[test]
// mov rax,rbx
fn test_mov_r64_r64() -> MockResult {
fn test_mov_r64_r64() {
let rbx: u64 = 0x8899aabbccddeeff;
let ip: u64 = 0x1000;
let cpu_id = 0;
@ -263,13 +263,11 @@ mod tests {
.read_reg(Register::RAX)
.unwrap();
assert_eq!(rax, rbx);
Ok(())
}
#[test]
// mov rax,0x1122334411223344
fn test_mov_r64_imm64() -> MockResult {
fn test_mov_r64_imm64() {
let imm64: u64 = 0x1122334411223344;
let ip: u64 = 0x1000;
let cpu_id = 0;
@ -283,13 +281,11 @@ mod tests {
.read_reg(Register::RAX)
.unwrap();
assert_eq!(rax, imm64);
Ok(())
}
#[test]
// mov rax, [rax+rax]
fn test_mov_r64_m64() -> MockResult {
fn test_mov_r64_m64() {
let target_rax: u64 = 0x1234567812345678;
let mut rax: u64 = 0x100;
let ip: u64 = 0x1000;
@ -305,13 +301,11 @@ mod tests {
.read_reg(Register::RAX)
.unwrap();
assert_eq!(rax, target_rax);
Ok(())
}
#[test]
// mov al,0x11
fn test_mov_r8_imm8() -> MockResult {
fn test_mov_r8_imm8() {
let imm8: u8 = 0x11;
let ip: u64 = 0x1000;
let cpu_id = 0;
@ -325,13 +319,11 @@ mod tests {
.read_reg(Register::AL)
.unwrap();
assert_eq!(al as u8, imm8);
Ok(())
}
#[test]
// mov eax,0x11
fn test_mov_r32_imm8() -> MockResult {
fn test_mov_r32_imm8() {
let imm8: u8 = 0x11;
let ip: u64 = 0x1000;
let cpu_id = 0;
@ -345,13 +337,11 @@ mod tests {
.read_reg(Register::EAX)
.unwrap();
assert_eq!(eax as u8, imm8);
Ok(())
}
#[test]
// mov rax,0x11223344
fn test_mov_r64_imm32() -> MockResult {
fn test_mov_r64_imm32() {
let imm32: u32 = 0x11223344;
let ip: u64 = 0x1000;
let cpu_id = 0;
@ -365,13 +355,11 @@ mod tests {
.read_reg(Register::RAX)
.unwrap();
assert_eq!(rax, imm32 as u64);
Ok(())
}
#[test]
// mov byte ptr [rax],dh
fn test_mov_m8_r8() -> MockResult {
fn test_mov_m8_r8() {
let rax: u64 = 0x100;
let dh: u8 = 0x99;
let ip: u64 = 0x1000;
@ -388,13 +376,11 @@ mod tests {
vmm.read_memory(rax, &mut memory).unwrap();
assert_eq!(u8::from_le_bytes(memory), dh);
Ok(())
}
#[test]
// mov dword ptr [rax],esi
fn test_mov_m32_r32() -> MockResult {
fn test_mov_m32_r32() {
let rax: u64 = 0x100;
let esi: u32 = 0x8899;
let ip: u64 = 0x1000;
@ -411,13 +397,11 @@ mod tests {
vmm.read_memory(rax, &mut memory).unwrap();
assert_eq!(u32::from_le_bytes(memory), esi);
Ok(())
}
#[test]
// mov dword ptr [rax+0x00000001],edi
fn test_mov_m32imm32_r32() -> MockResult {
fn test_mov_m32imm32_r32() {
let rax: u64 = 0x100;
let displacement: u64 = 0x1;
let edi: u32 = 0x8899;
@ -435,13 +419,11 @@ mod tests {
vmm.read_memory(rax + displacement, &mut memory).unwrap();
assert_eq!(u32::from_le_bytes(memory), edi);
Ok(())
}
#[test]
// mov eax,dword ptr [rax+10h]
fn test_mov_r32_m32imm32() -> MockResult {
fn test_mov_r32_m32imm32() {
let rax: u64 = 0x100;
let displacement: u64 = 0x10;
let eax: u32 = 0xaabbccdd;
@ -462,13 +444,11 @@ mod tests {
.read_reg(Register::EAX)
.unwrap();
assert_eq!(new_eax, eax as u64);
Ok(())
}
#[test]
// mov al,byte ptr [rax+10h]
fn test_mov_r8_m32imm32() -> MockResult {
fn test_mov_r8_m32imm32() {
let rax: u64 = 0x100;
let displacement: u64 = 0x10;
let al: u8 = 0xaa;
@ -489,14 +469,12 @@ mod tests {
.read_reg(Register::AL)
.unwrap();
assert_eq!(new_al, al as u64);
Ok(())
}
#[test]
// mov rax, 0x100
// mov rbx, qword ptr [rax+10h]
fn test_mov_r64_imm64_and_r64_m64() -> MockResult {
fn test_mov_r64_imm64_and_r64_m64() {
let target_rax: u64 = 0x1234567812345678;
let rax: u64 = 0x100;
let displacement: u64 = 0x10;
@ -516,14 +494,12 @@ mod tests {
.read_reg(Register::RBX)
.unwrap();
assert_eq!(rbx, target_rax);
Ok(())
}
#[test]
// mov rax, 0x100
// mov rbx, qword ptr [rax+10h]
fn test_mov_r64_imm64_and_r64_m64_first_insn() -> MockResult {
fn test_mov_r64_imm64_and_r64_m64_first_insn() {
let target_rax: u64 = 0x1234567812345678;
let rax: u64 = 0x100;
let displacement: u64 = 0x10;
@ -547,15 +523,13 @@ mod tests {
.read_reg(Register::RAX)
.unwrap();
assert_eq!(rax, new_rax);
Ok(())
}
#[test]
// mov rax, 0x100
// mov rbx, qword ptr [rax+10h]
// mov rax, 0x200
fn test_mov_r64_imm64_and_r64_m64_two_insns() -> MockResult {
fn test_mov_r64_imm64_and_r64_m64_two_insns() {
let target_rax: u64 = 0x1234567812345678;
let rax: u64 = 0x100;
let displacement: u64 = 0x10;
@ -588,13 +562,11 @@ mod tests {
.read_reg(Register::RAX)
.unwrap();
assert_eq!(rax, new_rax);
Ok(())
}
#[test]
// movzx eax, bl
fn test_movzx_r32_r8l() -> MockResult {
fn test_movzx_r32_r8l() {
let bx: u16 = 0x8899;
let ip: u64 = 0x1000;
let cpu_id = 0;
@ -608,13 +580,11 @@ mod tests {
.read_reg(Register::EAX)
.unwrap();
assert_eq!(eax, (bx & 0xff) as u64);
Ok(())
}
#[test]
// movzx eax, bh
fn test_movzx_r32_r8h() -> MockResult {
fn test_movzx_r32_r8h() {
let bx: u16 = 0x8899;
let ip: u64 = 0x1000;
let cpu_id = 0;
@ -628,13 +598,11 @@ mod tests {
.read_reg(Register::EAX)
.unwrap();
assert_eq!(eax, (bx >> 8) as u64);
Ok(())
}
#[test]
// movzx eax, byte ptr [rbx]
fn test_movzx_r32_m8() -> MockResult {
fn test_movzx_r32_m8() {
let rbx: u64 = 0x100;
let value: u8 = 0xaa;
let ip: u64 = 0x1000;
@ -650,7 +618,5 @@ mod tests {
.read_reg(Register::EAX)
.unwrap();
assert_eq!(eax, value as u64);
Ok(())
}
}

View File

@ -773,7 +773,7 @@ mod tests {
//
// mov rax, 0x1000
// Test with a first instruction truncated.
fn test_fetch_first_instruction() -> MockResult {
fn test_fetch_first_instruction() {
let ip: u64 = 0x1000;
let cpu_id = 0;
let memory = [
@ -799,8 +799,6 @@ mod tests {
.read_reg(Register::RAX)
.unwrap();
assert_eq!(rax, ip);
Ok(())
}
#[test]
@ -809,7 +807,7 @@ mod tests {
// mov rax, 0x1000
// mov rbx, qword ptr [rax+10h]
// Test with a 2nd instruction truncated.
fn test_fetch_second_instruction() -> MockResult {
fn test_fetch_second_instruction() {
let target_rax: u64 = 0x1234567812345678;
let ip: u64 = 0x1000;
let cpu_id = 0;
@ -836,8 +834,6 @@ mod tests {
.read_reg(Register::RBX)
.unwrap();
assert_eq!(rbx, target_rax);
Ok(())
}
#[test]
@ -846,7 +842,7 @@ mod tests {
// mov rax, 0x1000
// Test with a first instruction truncated and a bad fetched instruction.
// Verify that the instruction emulation returns an error.
fn test_fetch_bad_insn() -> MockResult {
fn test_fetch_bad_insn() {
let ip: u64 = 0x1000;
let cpu_id = 0;
let memory = [
@ -861,7 +857,5 @@ mod tests {
let mut vmm = MockVMM::new(ip, vec![], Some((ip, &memory)));
assert!(vmm.emulate_first_insn(cpu_id, &insn).is_err());
Ok(())
}
}

View File

@ -144,9 +144,8 @@ impl SoftTLB {
}
// Adds a gva -> gpa mapping into the TLB.
fn add_mapping(&mut self, gva: u64, gpa: u64) -> Result<(), PlatformError> {
fn add_mapping(&mut self, gva: u64, gpa: u64) {
*self.addr_map.entry(gva).or_insert(gpa) = gpa;
Ok(())
}
// Do the actual gva -> gpa translation
@ -383,8 +382,7 @@ impl cpu::Vcpu for MshvVcpu {
// Add the GVA <-> GPA mapping.
context
.tlb
.add_mapping(info.guest_virtual_address, info.guest_physical_address)
.map_err(|e| cpu::HypervisorCpuError::RunVcpu(e.into()))?;
.add_mapping(info.guest_virtual_address, info.guest_physical_address);
// Create a new emulator.
let mut emul = Emulator::new(&mut context);

View File

@ -577,7 +577,7 @@ mod tests {
// Creates the path for direct kernel boot and return the path.
// For x86_64, this function returns the vmlinux kernel path.
// For AArch64, this function returns the PE kernel path.
fn direct_kernel_boot_path() -> Option<PathBuf> {
fn direct_kernel_boot_path() -> PathBuf {
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
@ -587,7 +587,7 @@ mod tests {
#[cfg(target_arch = "aarch64")]
kernel_path.push("Image");
Some(kernel_path)
kernel_path
}
fn prepare_vhost_user_net_daemon(
@ -923,7 +923,7 @@ mod tests {
format! {"{{\"cpus\":{{\"boot_vcpus\":{},\"max_vcpus\":{}}},\"kernel\":{{\"path\":\"{}\"}},\"cmdline\":{{\"args\": \"{}\"}},\"net\":[{{\"ip\":\"{}\", \"mask\":\"255.255.255.0\", \"mac\":\"{}\"}}], \"disks\":[{{\"path\":\"{}\"}}, {{\"path\":\"{}\"}}]}}",
cpu_count,
cpu_count,
direct_kernel_boot_path().unwrap().to_str().unwrap(),
direct_kernel_boot_path().to_str().unwrap(),
DIRECT_KERNEL_BOOT_CMDLINE,
self.network.host_ip,
self.network.guest_mac,
@ -1374,10 +1374,7 @@ mod tests {
),
])
.args(&["--memory", "size=512M"])
.args(&[
"--kernel",
direct_kernel_boot_path().unwrap().to_str().unwrap(),
])
.args(&["--kernel", direct_kernel_boot_path().to_str().unwrap()])
.args(&["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE])
.default_disks()
.default_net()
@ -1444,7 +1441,7 @@ mod tests {
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let host_mac = if generate_host_mac {
Some(MacAddr::local_random())
@ -1596,7 +1593,7 @@ mod tests {
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let (blk_params, daemon_child) = {
let prepare_daemon = prepare_vhost_user_blk_daemon.unwrap();
@ -1749,7 +1746,7 @@ mod tests {
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let disk_path = guest.disk_config.disk(DiskType::OperatingSystem).unwrap();
@ -1828,7 +1825,7 @@ mod tests {
let mut shared_dir = workload_path;
shared_dir.push("shared_dir");
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let (dax_vmm_param, dax_mount_param) = if dax { ("on", "-o dax") } else { ("off", "") };
let cache_size_vmm_param = if let Some(cache) = cache_size {
@ -2009,7 +2006,7 @@ mod tests {
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let mut pmem_temp_file = NamedTempFile::new().unwrap();
pmem_temp_file.as_file_mut().set_len(128 << 20).unwrap();
@ -2095,7 +2092,7 @@ mod tests {
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let socket = temp_vsock_path(&guest.tmp_dir);
let api_socket = temp_api_path(&guest.tmp_dir);
@ -2447,10 +2444,7 @@ mod tests {
let mut cmd = GuestCommand::new(&guest);
cmd.args(&["--cpus", "boot=2,max=4"])
.args(&["--memory", "size=512M"])
.args(&[
"--kernel",
direct_kernel_boot_path().unwrap().to_str().unwrap(),
])
.args(&["--kernel", direct_kernel_boot_path().to_str().unwrap()])
.args(&["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE])
.capture_output()
.default_disks()
@ -2518,10 +2512,7 @@ mod tests {
let mut child = GuestCommand::new(&guest)
.args(&["--cpus", &format!("max_phys_bits={}", max_phys_bits)])
.args(&["--memory", "size=512M"])
.args(&[
"--kernel",
direct_kernel_boot_path().unwrap().to_str().unwrap(),
])
.args(&["--kernel", direct_kernel_boot_path().to_str().unwrap()])
.args(&["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE])
.default_disks()
.default_net()
@ -2555,10 +2546,7 @@ mod tests {
let mut cmd = GuestCommand::new(&guest);
cmd.args(&["--cpus", "boot=48"])
.args(&["--memory", "size=5120M"])
.args(&[
"--kernel",
direct_kernel_boot_path().unwrap().to_str().unwrap(),
])
.args(&["--kernel", direct_kernel_boot_path().to_str().unwrap()])
.args(&["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE])
.args(&["--serial", "tty"])
.args(&["--console", "off"])
@ -2587,10 +2575,7 @@ mod tests {
let mut cmd = GuestCommand::new(&guest);
cmd.args(&["--cpus", "boot=1"])
.args(&["--memory", "size=128G"])
.args(&[
"--kernel",
direct_kernel_boot_path().unwrap().to_str().unwrap(),
])
.args(&["--kernel", direct_kernel_boot_path().to_str().unwrap()])
.args(&["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE])
.capture_output()
.default_disks()
@ -2620,10 +2605,7 @@ mod tests {
cmd.args(&["--cpus", "boot=1"])
.args(&["--memory", "size=512M"])
.args(&[
"--kernel",
direct_kernel_boot_path().unwrap().to_str().unwrap(),
])
.args(&["--kernel", direct_kernel_boot_path().to_str().unwrap()])
.args(&["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE])
.capture_output()
.default_disks()
@ -2814,10 +2796,7 @@ mod tests {
let mut cmd = GuestCommand::new(&guest);
cmd.args(&["--cpus", "boot=1"])
.args(&["--memory", "size=512M"])
.args(&[
"--kernel",
direct_kernel_boot_path().unwrap().to_str().unwrap(),
])
.args(&["--kernel", direct_kernel_boot_path().to_str().unwrap()])
.args(&["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE])
.capture_output()
.default_disks()
@ -2858,7 +2837,7 @@ mod tests {
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let mut child = GuestCommand::new(&guest)
.args(&["--cpus", "boot=1"])
@ -2912,7 +2891,7 @@ mod tests {
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let mut child = GuestCommand::new(&guest)
.args(&["--cpus", "boot=1"])
@ -3043,7 +3022,7 @@ mod tests {
let mut blk_file_path = workload_path;
blk_file_path.push("blk.img");
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let mut cloud_child = GuestCommand::new(&guest)
.args(&["--cpus", "boot=4"])
@ -3236,10 +3215,7 @@ mod tests {
let mut child = GuestCommand::new(&guest)
.args(&["--cpus", "boot=1"])
.args(&["--memory", "size=512M"])
.args(&[
"--kernel",
direct_kernel_boot_path().unwrap().to_str().unwrap(),
])
.args(&["--kernel", direct_kernel_boot_path().to_str().unwrap()])
.args(&["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE])
.default_disks()
.default_net()
@ -3361,7 +3337,7 @@ mod tests {
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let mut child = GuestCommand::new(&guest)
.args(&["--cpus", "boot=1"])
@ -3419,7 +3395,7 @@ mod tests {
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let mut child = GuestCommand::new(&guest)
.args(&["--cpus", "boot=1"])
@ -3516,10 +3492,7 @@ mod tests {
let mut cmd = GuestCommand::new(&guest);
cmd.args(&["--cpus", "boot=1"])
.args(&["--memory", "size=512M"])
.args(&[
"--kernel",
direct_kernel_boot_path().unwrap().to_str().unwrap(),
])
.args(&["--kernel", direct_kernel_boot_path().to_str().unwrap()])
.args(&[
"--cmdline",
DIRECT_KERNEL_BOOT_CMDLINE
@ -3570,7 +3543,7 @@ mod tests {
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let mut child = GuestCommand::new(&guest)
.args(&["--cpus", "boot=1"])
@ -3629,10 +3602,7 @@ mod tests {
let mut child = GuestCommand::new(&guest)
.args(&["--cpus", "boot=1"])
.args(&["--memory", "size=512M"])
.args(&[
"--kernel",
direct_kernel_boot_path().unwrap().to_str().unwrap(),
])
.args(&["--kernel", direct_kernel_boot_path().to_str().unwrap()])
.args(&[
"--cmdline",
DIRECT_KERNEL_BOOT_CMDLINE
@ -3697,10 +3667,7 @@ mod tests {
let mut child = GuestCommand::new(&guest)
.args(&["--cpus", "boot=1"])
.args(&["--memory", "size=512M"])
.args(&[
"--kernel",
direct_kernel_boot_path().unwrap().to_str().unwrap(),
])
.args(&["--kernel", direct_kernel_boot_path().to_str().unwrap()])
.args(&["--cmdline", &cmdline])
.default_disks()
.default_net()
@ -3782,7 +3749,7 @@ mod tests {
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let mut child = GuestCommand::new(&guest)
.args(&["--cpus", "boot=1"])
@ -3832,10 +3799,7 @@ mod tests {
let mut child = GuestCommand::new(&guest)
.args(&["--cpus", "boot=1"])
.args(&["--memory", "size=512M"])
.args(&[
"--kernel",
direct_kernel_boot_path().unwrap().to_str().unwrap(),
])
.args(&["--kernel", direct_kernel_boot_path().to_str().unwrap()])
.args(&["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE])
.default_disks()
.default_net()
@ -4122,7 +4086,7 @@ mod tests {
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let mut child = GuestCommand::new(&guest)
.args(&["--cpus", "boot=1"])
@ -4168,10 +4132,7 @@ mod tests {
let mut cmd = GuestCommand::new(&guest);
cmd.args(&["--cpus", "boot=1"])
.args(&["--memory", "size=512M"])
.args(&[
"--kernel",
direct_kernel_boot_path().unwrap().to_str().unwrap(),
])
.args(&["--kernel", direct_kernel_boot_path().to_str().unwrap()])
.args(&["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE])
.default_disks()
.default_net()
@ -4525,10 +4486,7 @@ mod tests {
let mut child = GuestCommand::new(&guest)
.args(&["--cpus", "boot=1"])
.args(&["--memory", "size=512M"])
.args(&[
"--kernel",
direct_kernel_boot_path().unwrap().to_str().unwrap(),
])
.args(&["--kernel", direct_kernel_boot_path().to_str().unwrap()])
.args(&["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE])
.default_disks()
.args(&[
@ -4621,7 +4579,7 @@ mod tests {
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let mut child = GuestCommand::new(&guest)
.args(&["--cpus", "boot=2,max=4"])
@ -4722,7 +4680,7 @@ mod tests {
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let mut child = GuestCommand::new(&guest)
.args(&["--cpus", "boot=2,max=4"])
@ -4839,7 +4797,7 @@ mod tests {
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let mut child = GuestCommand::new(&guest)
.args(&["--cpus", "boot=2,max=4"])
@ -4927,7 +4885,7 @@ mod tests {
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let mut child = GuestCommand::new(&guest)
.args(&["--cpus", "boot=2,max=4"])
@ -4986,7 +4944,7 @@ mod tests {
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let guest_memory_size_kb = 512 * 1024;
@ -5029,7 +4987,7 @@ mod tests {
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let api_socket = temp_api_path(&guest.tmp_dir);
@ -5208,7 +5166,7 @@ mod tests {
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let api_socket = temp_api_path(&guest.tmp_dir);
@ -5340,7 +5298,7 @@ mod tests {
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let api_socket = temp_api_path(&guest.tmp_dir);
@ -5448,7 +5406,7 @@ mod tests {
workload_path.push("workloads");
let mut kernels = vec![];
kernels.push(direct_kernel_boot_path().unwrap());
kernels.push(direct_kernel_boot_path());
#[cfg(target_arch = "x86_64")]
{
@ -5669,10 +5627,7 @@ mod tests {
let mut cmd = GuestCommand::new(&guest);
cmd.args(&["--cpus", "boot=1"])
.args(&["--memory", "size=512M"])
.args(&[
"--kernel",
direct_kernel_boot_path().unwrap().to_str().unwrap(),
])
.args(&["--kernel", direct_kernel_boot_path().to_str().unwrap()])
.args(&["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE])
.default_disks()
.args(&["--net", guest.default_net_string().as_str()])
@ -5707,7 +5662,7 @@ mod tests {
let guest = Guest::new(&mut focal);
let api_socket = temp_api_path(&guest.tmp_dir);
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let mut cmd = GuestCommand::new(&guest);
cmd.args(&["--cpus", "boot=1"])
@ -5820,7 +5775,7 @@ mod tests {
fn test_tap_from_fd() {
let mut focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string());
let guest = Guest::new(&mut focal);
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
// Create a TAP interface with multi-queue enabled
let num_queue_pairs: usize = 2;
@ -5889,7 +5844,7 @@ mod tests {
fn test_macvtap() {
let mut focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string());
let guest = Guest::new(&mut focal);
let kernel_path = direct_kernel_boot_path().unwrap();
let kernel_path = direct_kernel_boot_path();
let phy_net = "eth0";
// Create a macvtap interface for the guest VM to use

View File

@ -406,14 +406,12 @@ impl Block {
}
}
fn set_state(&mut self, state: &BlockState) -> io::Result<()> {
fn set_state(&mut self, state: &BlockState) {
self.disk_path = state.disk_path.clone();
self.disk_nsectors = state.disk_nsectors;
self.common.avail_features = state.avail_features;
self.common.acked_features = state.acked_features;
self.config = state.config;
Ok(())
}
fn update_writeback(&mut self) {
@ -641,9 +639,8 @@ impl Snapshottable for Block {
}
};
return self.set_state(&block_state).map_err(|e| {
MigratableError::Restore(anyhow!("Could not restore BLOCK state {:?}", e))
});
self.set_state(&block_state);
return Ok(());
}
Err(MigratableError::Restore(anyhow!(

View File

@ -370,13 +370,11 @@ impl Console {
}
}
fn set_state(&mut self, state: &ConsoleState) -> io::Result<()> {
fn set_state(&mut self, state: &ConsoleState) {
self.common.avail_features = state.avail_features;
self.common.acked_features = state.acked_features;
*(self.config.lock().unwrap()) = state.config;
*(self.input.in_buffer.lock().unwrap()) = state.in_buffer.clone();
Ok(())
}
}
@ -535,9 +533,8 @@ impl Snapshottable for Console {
}
};
return self.set_state(&console_state).map_err(|e| {
MigratableError::Restore(anyhow!("Could not restore CONSOLE state {:?}", e))
});
self.set_state(&console_state);
return Ok(());
}
Err(MigratableError::Restore(anyhow!(

View File

@ -796,13 +796,11 @@ impl Iommu {
}
}
fn set_state(&mut self, state: &IommuState) -> io::Result<()> {
fn set_state(&mut self, state: &IommuState) {
self.common.avail_features = state.avail_features;
self.common.acked_features = state.acked_features;
*(self.mapping.endpoints.write().unwrap()) = state.endpoints.clone();
*(self.mapping.mappings.write().unwrap()) = state.mappings.clone();
Ok(())
}
// This function lets the caller specify a list of devices attached to the
@ -998,9 +996,8 @@ impl Snapshottable for Iommu {
}
};
return self.set_state(&iommu_state).map_err(|e| {
MigratableError::Restore(anyhow!("Could not restore IOMMU state {:?}", e))
});
self.set_state(&iommu_state);
return Ok(());
}
Err(MigratableError::Restore(anyhow!(

View File

@ -333,13 +333,11 @@ impl Net {
}
}
fn set_state(&mut self, state: &NetState) -> Result<()> {
fn set_state(&mut self, state: &NetState) {
self.common.avail_features = state.avail_features;
self.common.acked_features = state.acked_features;
self.config = state.config;
self.common.queue_sizes = state.queue_size.clone();
Ok(())
}
}
@ -604,9 +602,8 @@ impl Snapshottable for Net {
}
};
return self.set_state(&net_state).map_err(|e| {
MigratableError::Restore(anyhow!("Could not restore NET state {:?}", e))
});
self.set_state(&net_state);
return Ok(());
}
Err(MigratableError::Restore(anyhow!(

View File

@ -324,12 +324,10 @@ impl Pmem {
}
}
fn set_state(&mut self, state: &PmemState) -> io::Result<()> {
fn set_state(&mut self, state: &PmemState) {
self.common.avail_features = state.avail_features;
self.common.acked_features = state.acked_features;
self.config = state.config;
Ok(())
}
}
@ -484,9 +482,8 @@ impl Snapshottable for Pmem {
}
};
return self.set_state(&pmem_state).map_err(|e| {
MigratableError::Restore(anyhow!("Could not restore PMEM state {:?}", e))
});
self.set_state(&pmem_state);
return Ok(());
}
Err(MigratableError::Restore(anyhow!(

View File

@ -174,10 +174,9 @@ impl Rng {
}
}
fn set_state(&mut self, state: &RngState) -> io::Result<()> {
fn set_state(&mut self, state: &RngState) {
self.common.avail_features = state.avail_features;
self.common.acked_features = state.acked_features;
Ok(())
}
}
@ -325,9 +324,8 @@ impl Snapshottable for Rng {
}
};
return self.set_state(&rng_state).map_err(|e| {
MigratableError::Restore(anyhow!("Could not restore RNG state {:?}", e))
});
self.set_state(&rng_state);
return Ok(());
}
Err(MigratableError::Restore(anyhow!(

View File

@ -55,8 +55,8 @@ const SYS_IO_URING_ENTER: i64 = 426;
// See include/uapi/asm-generic/ioctls.h in the kernel code.
const FIONBIO: u64 = 0x5421;
fn virtio_balloon_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
Ok(vec![
fn virtio_balloon_thread_rules() -> Vec<SyscallRuleSet> {
vec![
allow_syscall(libc::SYS_brk),
allow_syscall(libc::SYS_close),
allow_syscall(libc::SYS_dup),
@ -73,11 +73,11 @@ fn virtio_balloon_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
allow_syscall(libc::SYS_rt_sigprocmask),
allow_syscall(libc::SYS_sigaltstack),
allow_syscall(libc::SYS_write),
])
]
}
fn virtio_block_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
Ok(vec![
fn virtio_block_thread_rules() -> Vec<SyscallRuleSet> {
vec![
allow_syscall(libc::SYS_brk),
allow_syscall(libc::SYS_close),
allow_syscall(libc::SYS_dup),
@ -114,11 +114,11 @@ fn virtio_block_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
allow_syscall(libc::SYS_set_robust_list),
allow_syscall(libc::SYS_sigaltstack),
allow_syscall(libc::SYS_write),
])
]
}
fn virtio_console_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
Ok(vec![
fn virtio_console_thread_rules() -> Vec<SyscallRuleSet> {
vec![
allow_syscall(libc::SYS_brk),
allow_syscall(libc::SYS_close),
allow_syscall(libc::SYS_dup),
@ -140,11 +140,11 @@ fn virtio_console_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
allow_syscall(libc::SYS_set_robust_list),
allow_syscall(libc::SYS_sigaltstack),
allow_syscall(libc::SYS_write),
])
]
}
fn virtio_iommu_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
Ok(vec![
fn virtio_iommu_thread_rules() -> Vec<SyscallRuleSet> {
vec![
allow_syscall(libc::SYS_brk),
allow_syscall(libc::SYS_close),
allow_syscall(libc::SYS_dup),
@ -162,11 +162,11 @@ fn virtio_iommu_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
allow_syscall(libc::SYS_read),
allow_syscall(libc::SYS_sigaltstack),
allow_syscall(libc::SYS_write),
])
]
}
fn virtio_mem_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
Ok(vec![
fn virtio_mem_thread_rules() -> Vec<SyscallRuleSet> {
vec![
allow_syscall(libc::SYS_brk),
allow_syscall(libc::SYS_close),
allow_syscall(libc::SYS_dup),
@ -184,11 +184,11 @@ fn virtio_mem_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
allow_syscall(libc::SYS_rt_sigprocmask),
allow_syscall(libc::SYS_sigaltstack),
allow_syscall(libc::SYS_write),
])
]
}
fn virtio_net_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
Ok(vec![
fn virtio_net_thread_rules() -> Vec<SyscallRuleSet> {
vec![
allow_syscall(libc::SYS_brk),
allow_syscall(libc::SYS_close),
allow_syscall(libc::SYS_dup),
@ -206,11 +206,11 @@ fn virtio_net_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
allow_syscall(libc::SYS_rt_sigprocmask),
allow_syscall(libc::SYS_sigaltstack),
allow_syscall(libc::SYS_write),
])
]
}
fn virtio_net_ctl_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
Ok(vec![
fn virtio_net_ctl_thread_rules() -> Vec<SyscallRuleSet> {
vec![
allow_syscall(libc::SYS_brk),
allow_syscall(libc::SYS_close),
allow_syscall(libc::SYS_dup),
@ -227,11 +227,11 @@ fn virtio_net_ctl_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
allow_syscall(libc::SYS_rt_sigprocmask),
allow_syscall(libc::SYS_sigaltstack),
allow_syscall(libc::SYS_write),
])
]
}
fn virtio_pmem_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
Ok(vec![
fn virtio_pmem_thread_rules() -> Vec<SyscallRuleSet> {
vec![
allow_syscall(libc::SYS_brk),
allow_syscall(libc::SYS_close),
allow_syscall(libc::SYS_dup),
@ -249,11 +249,11 @@ fn virtio_pmem_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
allow_syscall(libc::SYS_rt_sigprocmask),
allow_syscall(libc::SYS_sigaltstack),
allow_syscall(libc::SYS_write),
])
]
}
fn virtio_rng_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
Ok(vec![
fn virtio_rng_thread_rules() -> Vec<SyscallRuleSet> {
vec![
allow_syscall(libc::SYS_brk),
allow_syscall(libc::SYS_close),
allow_syscall(libc::SYS_dup),
@ -275,11 +275,11 @@ fn virtio_rng_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
allow_syscall(libc::SYS_set_robust_list),
allow_syscall(libc::SYS_sigaltstack),
allow_syscall(libc::SYS_write),
])
]
}
fn virtio_vhost_blk_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
Ok(vec![
fn virtio_vhost_blk_thread_rules() -> Vec<SyscallRuleSet> {
vec![
allow_syscall(libc::SYS_brk),
allow_syscall(libc::SYS_close),
allow_syscall(libc::SYS_dup),
@ -296,11 +296,11 @@ fn virtio_vhost_blk_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
allow_syscall(libc::SYS_rt_sigprocmask),
allow_syscall(libc::SYS_sigaltstack),
allow_syscall(libc::SYS_write),
])
]
}
fn virtio_vhost_fs_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
Ok(vec![
fn virtio_vhost_fs_thread_rules() -> Vec<SyscallRuleSet> {
vec![
allow_syscall(libc::SYS_brk),
allow_syscall(libc::SYS_close),
allow_syscall(libc::SYS_dup),
@ -320,11 +320,11 @@ fn virtio_vhost_fs_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
allow_syscall(libc::SYS_sendmsg),
allow_syscall(libc::SYS_sigaltstack),
allow_syscall(libc::SYS_write),
])
]
}
fn virtio_vhost_net_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
Ok(vec![
fn virtio_vhost_net_thread_rules() -> Vec<SyscallRuleSet> {
vec![
allow_syscall(libc::SYS_brk),
allow_syscall(libc::SYS_close),
allow_syscall(libc::SYS_dup),
@ -342,11 +342,11 @@ fn virtio_vhost_net_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
allow_syscall(libc::SYS_madvise),
#[cfg(target_arch = "aarch64")]
allow_syscall(libc::SYS_exit),
])
]
}
fn virtio_vhost_net_ctl_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
Ok(vec![
fn virtio_vhost_net_ctl_thread_rules() -> Vec<SyscallRuleSet> {
vec![
allow_syscall(libc::SYS_brk),
allow_syscall(libc::SYS_close),
allow_syscall(libc::SYS_dup),
@ -365,15 +365,15 @@ fn virtio_vhost_net_ctl_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
allow_syscall(libc::SYS_madvise),
#[cfg(target_arch = "aarch64")]
allow_syscall(libc::SYS_exit),
])
]
}
fn create_vsock_ioctl_seccomp_rule() -> Result<Vec<SeccompRule>, Error> {
Ok(or![and![Cond::new(1, ArgLen::DWORD, Eq, FIONBIO,)?],])
fn create_vsock_ioctl_seccomp_rule() -> Vec<SeccompRule> {
or![and![Cond::new(1, ArgLen::DWORD, Eq, FIONBIO,).unwrap()],]
}
fn virtio_vsock_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
Ok(vec![
fn virtio_vsock_thread_rules() -> Vec<SyscallRuleSet> {
vec![
allow_syscall(libc::SYS_accept4),
allow_syscall(libc::SYS_brk),
allow_syscall(libc::SYS_close),
@ -384,7 +384,7 @@ fn virtio_vsock_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
#[cfg(target_arch = "x86_64")]
allow_syscall(libc::SYS_epoll_wait),
allow_syscall(libc::SYS_exit),
allow_syscall_if(libc::SYS_ioctl, create_vsock_ioctl_seccomp_rule()?),
allow_syscall_if(libc::SYS_ioctl, create_vsock_ioctl_seccomp_rule()),
allow_syscall(libc::SYS_futex),
allow_syscall(libc::SYS_madvise),
allow_syscall(libc::SYS_munmap),
@ -393,11 +393,11 @@ fn virtio_vsock_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
allow_syscall(libc::SYS_rt_sigprocmask),
allow_syscall(libc::SYS_sigaltstack),
allow_syscall(libc::SYS_write),
])
]
}
fn virtio_watchdog_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
Ok(vec![
fn virtio_watchdog_thread_rules() -> Vec<SyscallRuleSet> {
vec![
allow_syscall(libc::SYS_brk),
allow_syscall(libc::SYS_close),
allow_syscall(libc::SYS_dup),
@ -420,51 +420,48 @@ fn virtio_watchdog_thread_rules() -> Result<Vec<SyscallRuleSet>, Error> {
allow_syscall(libc::SYS_sigaltstack),
allow_syscall(libc::SYS_timerfd_settime),
allow_syscall(libc::SYS_write),
])
]
}
fn get_seccomp_filter_trap(thread_type: Thread) -> Result<SeccompFilter, Error> {
let rules = match thread_type {
Thread::VirtioBalloon => virtio_balloon_thread_rules()?,
Thread::VirtioBlock => virtio_block_thread_rules()?,
Thread::VirtioConsole => virtio_console_thread_rules()?,
Thread::VirtioIommu => virtio_iommu_thread_rules()?,
Thread::VirtioMem => virtio_mem_thread_rules()?,
Thread::VirtioNet => virtio_net_thread_rules()?,
Thread::VirtioNetCtl => virtio_net_ctl_thread_rules()?,
Thread::VirtioPmem => virtio_pmem_thread_rules()?,
Thread::VirtioRng => virtio_rng_thread_rules()?,
Thread::VirtioVhostBlk => virtio_vhost_blk_thread_rules()?,
Thread::VirtioVhostFs => virtio_vhost_fs_thread_rules()?,
Thread::VirtioVhostNet => virtio_vhost_net_thread_rules()?,
Thread::VirtioVhostNetCtl => virtio_vhost_net_ctl_thread_rules()?,
Thread::VirtioVsock => virtio_vsock_thread_rules()?,
Thread::VirtioWatchdog => virtio_watchdog_thread_rules()?,
Thread::VirtioBalloon => virtio_balloon_thread_rules(),
Thread::VirtioBlock => virtio_block_thread_rules(),
Thread::VirtioConsole => virtio_console_thread_rules(),
Thread::VirtioIommu => virtio_iommu_thread_rules(),
Thread::VirtioMem => virtio_mem_thread_rules(),
Thread::VirtioNet => virtio_net_thread_rules(),
Thread::VirtioNetCtl => virtio_net_ctl_thread_rules(),
Thread::VirtioPmem => virtio_pmem_thread_rules(),
Thread::VirtioRng => virtio_rng_thread_rules(),
Thread::VirtioVhostBlk => virtio_vhost_blk_thread_rules(),
Thread::VirtioVhostFs => virtio_vhost_fs_thread_rules(),
Thread::VirtioVhostNet => virtio_vhost_net_thread_rules(),
Thread::VirtioVhostNetCtl => virtio_vhost_net_ctl_thread_rules(),
Thread::VirtioVsock => virtio_vsock_thread_rules(),
Thread::VirtioWatchdog => virtio_watchdog_thread_rules(),
};
Ok(SeccompFilter::new(
rules.into_iter().collect(),
SeccompAction::Trap,
)?)
SeccompFilter::new(rules.into_iter().collect(), SeccompAction::Trap)
}
fn get_seccomp_filter_log(thread_type: Thread) -> Result<SeccompFilter, Error> {
let rules = match thread_type {
Thread::VirtioBalloon => virtio_balloon_thread_rules()?,
Thread::VirtioBlock => virtio_block_thread_rules()?,
Thread::VirtioConsole => virtio_console_thread_rules()?,
Thread::VirtioIommu => virtio_iommu_thread_rules()?,
Thread::VirtioMem => virtio_mem_thread_rules()?,
Thread::VirtioNet => virtio_net_thread_rules()?,
Thread::VirtioNetCtl => virtio_net_ctl_thread_rules()?,
Thread::VirtioPmem => virtio_pmem_thread_rules()?,
Thread::VirtioRng => virtio_rng_thread_rules()?,
Thread::VirtioVhostBlk => virtio_vhost_blk_thread_rules()?,
Thread::VirtioVhostFs => virtio_vhost_fs_thread_rules()?,
Thread::VirtioVhostNet => virtio_vhost_net_thread_rules()?,
Thread::VirtioVhostNetCtl => virtio_vhost_net_ctl_thread_rules()?,
Thread::VirtioVsock => virtio_vsock_thread_rules()?,
Thread::VirtioWatchdog => virtio_watchdog_thread_rules()?,
Thread::VirtioBalloon => virtio_balloon_thread_rules(),
Thread::VirtioBlock => virtio_block_thread_rules(),
Thread::VirtioConsole => virtio_console_thread_rules(),
Thread::VirtioIommu => virtio_iommu_thread_rules(),
Thread::VirtioMem => virtio_mem_thread_rules(),
Thread::VirtioNet => virtio_net_thread_rules(),
Thread::VirtioNetCtl => virtio_net_ctl_thread_rules(),
Thread::VirtioPmem => virtio_pmem_thread_rules(),
Thread::VirtioRng => virtio_rng_thread_rules(),
Thread::VirtioVhostBlk => virtio_vhost_blk_thread_rules(),
Thread::VirtioVhostFs => virtio_vhost_fs_thread_rules(),
Thread::VirtioVhostNet => virtio_vhost_net_thread_rules(),
Thread::VirtioVhostNetCtl => virtio_vhost_net_ctl_thread_rules(),
Thread::VirtioVsock => virtio_vsock_thread_rules(),
Thread::VirtioWatchdog => virtio_watchdog_thread_rules(),
};
Ok(SeccompFilter::new(

View File

@ -355,11 +355,9 @@ where
}
}
fn set_state(&mut self, state: &VsockState) -> io::Result<()> {
fn set_state(&mut self, state: &VsockState) {
self.common.avail_features = state.avail_features;
self.common.acked_features = state.acked_features;
Ok(())
}
}
@ -531,9 +529,8 @@ where
}
};
return self.set_state(&vsock_state).map_err(|e| {
MigratableError::Restore(anyhow!("Could not restore VSOCK state {:?}", e))
});
self.set_state(&vsock_state);
return Ok(());
}
Err(MigratableError::Restore(anyhow!(

View File

@ -212,7 +212,7 @@ impl Watchdog {
}
}
fn set_state(&mut self, state: &WatchdogState) -> io::Result<()> {
fn set_state(&mut self, state: &WatchdogState) {
self.common.avail_features = state.avail_features;
self.common.acked_features = state.acked_features;
// When restoring enable the watchdog if it was previously enabled. We reset the timer
@ -220,7 +220,6 @@ impl Watchdog {
if state.enabled {
self.last_ping_time.lock().unwrap().replace(Instant::now());
}
Ok(())
}
}
@ -418,9 +417,8 @@ impl Snapshottable for Watchdog {
}
};
return self.set_state(&watchdog_state).map_err(|e| {
MigratableError::Restore(anyhow!("Could not restore watchdog state {:?}", e))
});
self.set_state(&watchdog_state);
return Ok(());
}
Err(MigratableError::Restore(anyhow!(

View File

@ -1726,7 +1726,7 @@ mod tests {
use super::*;
#[test]
fn test_option_parser() -> std::result::Result<(), OptionParserError> {
fn test_option_parser() {
let mut parser = OptionParser::new();
parser
.add("size")
@ -1742,7 +1742,6 @@ mod tests {
assert_eq!(parser.get("size"), Some("128M".to_owned()));
assert!(!parser.is_set("mergeable"));
assert!(parser.is_set("size"));
Ok(())
}
#[test]
@ -2271,7 +2270,7 @@ mod tests {
}
#[test]
fn test_config_validation() -> Result<()> {
fn test_config_validation() {
let valid_config = VmConfig {
cpus: CpusConfig {
boot_vcpus: 1,
@ -2432,7 +2431,5 @@ mod tests {
invalid_config.memory.hugepages = true;
invalid_config.memory.hugepage_size = Some(3 << 20);
assert!(invalid_config.validate().is_err());
Ok(())
}
}

View File

@ -992,12 +992,11 @@ impl CpuManager {
Ok(())
}
fn mark_vcpus_for_removal(&mut self, desired_vcpus: u8) -> Result<()> {
fn mark_vcpus_for_removal(&mut self, desired_vcpus: u8) {
// Mark vCPUs for removal, actual removal happens on ejection
for cpu_id in desired_vcpus..self.present_vcpus() {
self.vcpu_states[usize::from(cpu_id)].removing = true;
}
Ok(())
}
fn remove_vcpu(&mut self, cpu_id: u8) -> Result<()> {
@ -1049,7 +1048,10 @@ impl CpuManager {
self.activate_vcpus(desired_vcpus, true)?;
Ok(true)
}
cmp::Ordering::Less => self.mark_vcpus_for_removal(desired_vcpus).and(Ok(true)),
cmp::Ordering::Less => {
self.mark_vcpus_for_removal(desired_vcpus);
Ok(true)
}
_ => Ok(false),
}
}

View File

@ -1097,11 +1097,9 @@ impl DeviceManager {
}
}
fn set_state(&mut self, state: &DeviceManagerState) -> DeviceManagerResult<()> {
fn set_state(&mut self, state: &DeviceManagerState) {
self.device_tree = Arc::new(Mutex::new(state.device_tree.clone()));
self.device_id_cnt = state.device_id_cnt;
Ok(())
}
#[cfg(target_arch = "aarch64")]
@ -3726,9 +3724,7 @@ impl Snapshottable for DeviceManager {
MigratableError::Restore(anyhow!("Could not deserialize DeviceManager {}", e))
})?;
self.set_state(&device_manager_state).map_err(|e| {
MigratableError::Restore(anyhow!("Could not restore DeviceManager state {:?}", e))
})?;
self.set_state(&device_manager_state);
} else {
return Err(MigratableError::Restore(anyhow!(
"Could not find DeviceManager snapshot section"

View File

@ -539,10 +539,10 @@ impl Vmm {
}
}
fn vmm_ping(&self) -> result::Result<VmmPingResponse, ApiError> {
Ok(VmmPingResponse {
fn vmm_ping(&self) -> VmmPingResponse {
VmmPingResponse {
version: self.version.clone(),
})
}
}
fn vm_delete(&mut self) -> result::Result<(), VmError> {
@ -1205,9 +1205,9 @@ impl Vmm {
sender.send(response).map_err(Error::ApiResponseSend)?;
}
ApiRequest::VmmPing(sender) => {
let response = self.vmm_ping().map(ApiResponsePayload::VmmPing);
let response = ApiResponsePayload::VmmPing(self.vmm_ping());
sender.send(response).map_err(Error::ApiResponseSend)?;
sender.send(Ok(response)).map_err(Error::ApiResponseSend)?;
}
ApiRequest::VmPause(sender) => {
let response = self