@@ -70,8 +70,6 @@ pub struct NetworkTestState {
7070 iperf_requests : mesh:: Sender < crate :: iperf_helper:: IperfRequest > ,
7171 /// Mesh instance (kept alive so the helper process stays running).
7272 _helper_mesh : mesh_process:: Mesh ,
73- /// Whether the guest uses chroot for iperf3 (Consomme with erofs).
74- use_chroot : bool ,
7573}
7674
7775fn build_firmware ( resolver : & petri:: ArtifactResolver < ' _ > ) -> petri:: Firmware {
@@ -258,7 +256,7 @@ impl crate::harness::WarmPerfTest for NetworkTest {
258256 #[ cfg( target_os = "linux" ) ]
259257 NetBackend :: Tap => {
260258 let tap_fd = tap_fd. unwrap ( ) ;
261- builder = tap:: configure_builder ( builder, tap_fd, self . nic ) ;
259+ builder = tap:: configure_builder ( builder, tap_fd, self . nic , erofs_file ) ;
262260 }
263261 #[ cfg( not( target_os = "linux" ) ) ]
264262 NetBackend :: Tap => unreachable ! ( ) ,
@@ -275,43 +273,39 @@ impl crate::harness::WarmPerfTest for NetworkTest {
275273
276274 // Guest networking and iperf3 setup depends on backend.
277275 let host_ip;
278- let use_chroot;
279276 match self . backend {
280277 NetBackend :: Consomme => {
281278 // Bring up networking on the real root (busybox in initrd).
282279 cmd ! ( sh, "ifconfig eth0 up" ) . run ( ) . await ?;
283280 cmd ! ( sh, "udhcpc eth0" ) . run ( ) . await ?;
284281
285- // Mount the erofs image and prepare chroot.
286- agent
287- . mount ( "/dev/vda" , "/perf" , "erofs" , 1 /* MS_RDONLY */ , true )
288- . await
289- . context ( "failed to mount erofs on /dev/vda" ) ?;
290- agent
291- . prepare_chroot ( "/perf" )
292- . await
293- . context ( "failed to prepare chroot at /perf" ) ?;
294-
295282 host_ip = detect_host_ip ( ) . context ( "failed to detect host IP" ) ?;
296283 tracing:: info!( host_ip = %host_ip, "detected host IP" ) ;
297- use_chroot = true ;
298284 }
299285 #[ cfg( target_os = "linux" ) ]
300286 NetBackend :: Tap => {
301287 host_ip = tap:: setup_guest_networking ( & agent) . await ?;
302- use_chroot = false ;
303288 }
304289 #[ cfg( not( target_os = "linux" ) ) ]
305290 NetBackend :: Tap => unreachable ! ( ) ,
306291 }
307292
293+ // Mount the erofs image (iperf3 pre-installed) and prepare chroot.
294+ agent
295+ . mount ( "/dev/vda" , "/perf" , "erofs" , 1 /* MS_RDONLY */ , true )
296+ . await
297+ . context ( "failed to mount erofs on /dev/vda" ) ?;
298+ agent
299+ . prepare_chroot ( "/perf" )
300+ . await
301+ . context ( "failed to prepare chroot at /perf" ) ?;
302+
308303 Ok ( NetworkTestState {
309304 vm,
310305 agent,
311306 host_ip,
312307 iperf_requests : ready. requests ,
313308 _helper_mesh : helper_mesh,
314- use_chroot,
315309 } )
316310 }
317311
@@ -408,15 +402,7 @@ impl NetworkTest {
408402 std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 500 ) ) ;
409403
410404 // Run guest iperf3 client.
411- run_guest_iperf3_client (
412- & state. agent ,
413- host_ip,
414- port,
415- & mode,
416- metric_name,
417- state. use_chroot ,
418- )
419- . await ?;
405+ run_guest_iperf3_client ( & state. agent , host_ip, port, & mode, metric_name) . await ?;
420406
421407 // Collect JSON from the helper.
422408 let json = json_future. await . context ( "iperf3 helper RPC failed" ) ?;
@@ -441,12 +427,9 @@ async fn run_guest_iperf3_client(
441427 port : u16 ,
442428 mode : & IperfMode ,
443429 metric_name : & str ,
444- use_chroot : bool ,
445430) -> anyhow:: Result < ( ) > {
446431 let mut sh = agent. unix_shell ( ) ;
447- if use_chroot {
448- sh. chroot ( "/perf" ) ;
449- }
432+ sh. chroot ( "/perf" ) ;
450433 let port_str = port. to_string ( ) ;
451434 match mode {
452435 IperfMode :: TcpTx => {
@@ -531,22 +514,47 @@ mod tap {
531514 } ) ;
532515 }
533516
534- /// Configure the VM builder to add both a Consomme NIC and a TAP NIC.
517+ /// Configure the VM builder to add both a Consomme NIC and a TAP NIC,
518+ /// plus a read-only virtio-blk device with the erofs image.
535519 pub ( super ) fn configure_builder (
536520 builder : petri:: PetriVmBuilder < petri:: openvmm:: OpenVmmPetriBackend > ,
537521 tap_fd : std:: os:: fd:: OwnedFd ,
538522 nic : super :: NicBackend ,
523+ erofs_file : fs_err:: File ,
539524 ) -> petri:: PetriVmBuilder < petri:: openvmm:: OpenVmmPetriBackend > {
540525 builder. modify_backend ( move |c| {
541- let c = match nic {
542- super :: NicBackend :: Vmbus => c. with_nic ( ) ,
543- super :: NicBackend :: VirtioNet => c
544- . with_pcie_root_topology ( 1 , 1 , 2 )
545- . with_virtio_nic ( "s0rc0rp0" ) ,
526+ let ( c, blk_port) = match nic {
527+ super :: NicBackend :: Vmbus => {
528+ ( c. with_pcie_root_topology ( 1 , 1 , 1 ) . with_nic ( ) , "s0rc0rp0" )
529+ }
530+ super :: NicBackend :: VirtioNet => (
531+ c. with_pcie_root_topology ( 1 , 1 , 3 )
532+ . with_virtio_nic ( "s0rc0rp0" ) ,
533+ "s0rc0rp2" ,
534+ ) ,
546535 } ;
547- c. with_custom_config ( |config| match nic {
548- super :: NicBackend :: Vmbus => add_tap_nic ( config, tap_fd) ,
549- super :: NicBackend :: VirtioNet => add_virtio_tap_nic ( config, tap_fd) ,
536+ c. with_custom_config ( |config| {
537+ use disk_backend_resources:: FileDiskHandle ;
538+ use vm_resource:: IntoResource ;
539+
540+ // Attach erofs image as read-only virtio-blk device.
541+ config. pcie_devices . push ( PcieDeviceConfig {
542+ port_name : blk_port. into ( ) ,
543+ resource : virtio_resources:: VirtioPciDeviceHandle (
544+ virtio_resources:: blk:: VirtioBlkHandle {
545+ disk : FileDiskHandle ( erofs_file. into ( ) ) . into_resource ( ) ,
546+ read_only : true ,
547+ }
548+ . into_resource ( ) ,
549+ )
550+ . into_resource ( ) ,
551+ } ) ;
552+
553+ // Add TAP NIC.
554+ match nic {
555+ super :: NicBackend :: Vmbus => add_tap_nic ( config, tap_fd) ,
556+ super :: NicBackend :: VirtioNet => add_virtio_tap_nic ( config, tap_fd) ,
557+ }
550558 } )
551559 } )
552560 }
@@ -575,11 +583,6 @@ mod tap {
575583 cmd ! ( sh, "ifconfig {consomme_if} up" ) . run ( ) . await ?;
576584 cmd ! ( sh, "udhcpc -i {consomme_if} -n -q" ) . run ( ) . await ?;
577585
578- cmd ! ( sh, "apk add iperf3" )
579- . run ( )
580- . await
581- . context ( "failed to install iperf3" ) ?;
582-
583586 let find_tap =
584587 "ip -o link show | grep -i 00:15:5d:12:12:13 | awk -F: '{print $2}' | tr -d ' '" ;
585588 let tap_if = cmd ! ( sh, "sh -c {find_tap}" )
0 commit comments