From 5c4e1726f8fb73c5a2888f4597cc0731e33dd9d2 Mon Sep 17 00:00:00 2001 From: Yang Zhong Date: Wed, 18 Dec 2019 14:25:47 +0800 Subject: [PATCH] ci: test the vhost-user-blk readonly function This patch is to check if block device is readonly when backend set readonly=true. The lsblk command can show the RO value in the guest. Signed-off-by: Yang Zhong --- src/main.rs | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3df2f9bc9..2744acff6 100755 --- a/src/main.rs +++ b/src/main.rs @@ -1752,7 +1752,11 @@ mod tests { (child, virtiofsd_socket_path) } - fn prepare_vubd(tmp_dir: &TempDir, blk_img: &str) -> (std::process::Child, String) { + fn prepare_vubd( + tmp_dir: &TempDir, + blk_img: &str, + rdonly: bool, + ) -> (std::process::Child, String) { let mut workload_path = dirs::home_dir().unwrap(); workload_path.push("workloads"); @@ -1766,7 +1770,11 @@ mod tests { let child = Command::new("target/release/vhost_user_blk") .args(&[ "--backend", - format!("image={},sock={}", blk_file_path, vubd_socket_path).as_str(), + format!( + "image={},sock={},readonly={}", + blk_file_path, vubd_socket_path, rdonly + ) + .as_str(), ]) .spawn() .unwrap(); @@ -2523,7 +2531,8 @@ mod tests { let mut clear = ClearDiskConfig::new(); let guest = Guest::new(&mut clear); - let (mut daemon_child, vubd_socket_path) = prepare_vubd(&guest.tmp_dir, "blk.img"); + let (mut daemon_child, vubd_socket_path) = + prepare_vubd(&guest.tmp_dir, "blk.img", false); let mut cloud_child = Command::new("target/release/cloud-hypervisor") .args(&["--cpus", "boot=1"]) @@ -2600,6 +2609,83 @@ mod tests { }); } + #[cfg_attr(not(feature = "mmio"), test)] + fn test_vhost_user_blk_readonly() { + test_block!(tb, "", { + let mut clear = ClearDiskConfig::new(); + let guest = Guest::new(&mut clear); + + let (mut daemon_child, vubd_socket_path) = + prepare_vubd(&guest.tmp_dir, "blk.img", true); + + let mut cloud_child = Command::new("target/release/cloud-hypervisor") + .args(&["--cpus", "boot=1"]) + .args(&["--memory", "size=512M,file=/dev/shm"]) + .args(&["--kernel", guest.fw_path.as_str()]) + .args(&[ + "--disk", + format!( + "path={}", + guest.disk_config.disk(DiskType::OperatingSystem).unwrap() + ) + .as_str(), + format!( + "path={}", + guest.disk_config.disk(DiskType::CloudInit).unwrap() + ) + .as_str(), + ]) + .args(&["--net", guest.default_net_string().as_str()]) + .args(&[ + "--vhost-user-blk", + format!( + "sock={},num_queues=1,queue_size=128,wce=true", + vubd_socket_path + ) + .as_str(), + ]) + .spawn() + .unwrap(); + + thread::sleep(std::time::Duration::new(20, 0)); + + // Check both if /dev/vdc exists and if the block size is 16M. + aver_eq!( + tb, + guest + .ssh_command("lsblk | grep vdc | grep -c 16M") + .unwrap_or_default() + .trim() + .parse::() + .unwrap_or_default(), + 1 + ); + + // Check both if /dev/vdc exists and if this block is RO. + aver_eq!( + tb, + guest + .ssh_command("lsblk | grep vdc | awk '{print $5}'") + .unwrap_or_default() + .trim() + .parse::() + .unwrap_or_default(), + 1 + ); + + guest.ssh_command("sudo shutdown -h now")?; + thread::sleep(std::time::Duration::new(5, 0)); + let _ = cloud_child.kill(); + let _ = cloud_child.wait(); + + thread::sleep(std::time::Duration::new(5, 0)); + let _ = daemon_child.kill(); + let _ = daemon_child.wait(); + + Ok(()) + }); + } + #[cfg_attr(not(feature = "mmio"), test)] fn test_boot_from_vhost_user_blk() { test_block!(tb, "", { @@ -2613,6 +2699,7 @@ mod tests { .disk(DiskType::RawOperatingSystem) .unwrap() .as_str(), + false, ); let mut cloud_child = Command::new("target/release/cloud-hypervisor")