From eb5c5f2c7f8c8917dd9e0b9b055d30bd6f0459eb Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Wed, 19 Jan 2022 17:21:54 +0100 Subject: [PATCH] tests: Add integration test for O_DIRECT Both OVMF and RHF firmwares triggered an error when O_DIRECT was used because they didn't align the buffers to the block sector size. In order to prevent regressions, we're adding a new test validating the VM can properly boot when the OS disk is opened with O_DIRECT and booted from the rust-hypervisor-fw. Signed-off-by: Sebastien Boeuf --- tests/integration.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/integration.rs b/tests/integration.rs index ff91f8f00..9b5ec405f 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -3109,6 +3109,53 @@ mod parallel { .unwrap() } + #[test] + fn test_virtio_block_direct_and_firmware() { + let focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string()); + let guest = Guest::new(Box::new(focal)); + + // The OS disk must be copied to a location that is not backed by + // tmpfs, otherwise the syscall openat(2) with O_DIRECT simply fails + // with EINVAL because tmpfs doesn't support this flag. + let mut workloads_path = dirs::home_dir().unwrap(); + workloads_path.push("workloads"); + let os_dir = TempDir::new_in(workloads_path.as_path()).unwrap(); + let mut os_path = os_dir.as_path().to_path_buf(); + os_path.push("osdisk.img"); + rate_limited_copy( + &guest.disk_config.disk(DiskType::OperatingSystem).unwrap(), + os_path.as_path(), + ) + .expect("copying of OS disk failed"); + + let mut child = GuestCommand::new(&guest) + .args(&["--cpus", "boot=1"]) + .args(&["--memory", "size=512M"]) + .args(&["--kernel", guest.fw_path.as_str()]) + .args(&[ + "--disk", + format!("path={},direct=on", os_path.as_path().to_str().unwrap()).as_str(), + format!( + "path={}", + guest.disk_config.disk(DiskType::CloudInit).unwrap() + ) + .as_str(), + ]) + .default_net() + .capture_output() + .spawn() + .unwrap(); + + let r = std::panic::catch_unwind(|| { + guest.wait_vm_boot(None).unwrap(); + }); + + let _ = child.kill(); + let output = child.wait_with_output().unwrap(); + + handle_child_output(r, &output); + } + #[test] fn test_vhost_user_net_default() { test_vhost_user_net(None, 2, &prepare_vhost_user_net_daemon, false, false)