@@ -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,13 +402,10 @@ impl NetworkTest {
408402 std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 500 ) ) ;
409403
410404 // Run guest iperf3 client.
411- run_guest_iperf3_client ( & state. agent , host_ip, port, & mode, metric_name, state. use_chroot )
412- . await ?;
405+ run_guest_iperf3_client ( & state. agent , host_ip, port, & mode, metric_name) . await ?;
413406
414407 // Collect JSON from the helper.
415- let json = json_future
416- . await
417- . context ( "iperf3 helper RPC failed" ) ?;
408+ let json = json_future. await . context ( "iperf3 helper RPC failed" ) ?;
418409
419410 if !json. is_empty ( ) {
420411 tracing:: debug!( metric = metric_name, json = %json, "raw iperf3 output" ) ;
@@ -436,12 +427,9 @@ async fn run_guest_iperf3_client(
436427 port : u16 ,
437428 mode : & IperfMode ,
438429 metric_name : & str ,
439- use_chroot : bool ,
440430) -> anyhow:: Result < ( ) > {
441431 let mut sh = agent. unix_shell ( ) ;
442- if use_chroot {
443- sh. chroot ( "/perf" ) ;
444- }
432+ sh. chroot ( "/perf" ) ;
445433 let port_str = port. to_string ( ) ;
446434 match mode {
447435 IperfMode :: TcpTx => {
@@ -494,8 +482,7 @@ mod tap {
494482 /// Add a VMBus synthnic backed by a TAP fd to the VM config.
495483 fn add_tap_nic ( config : & mut openvmm_defs:: config:: Config , tap_fd : std:: os:: fd:: OwnedFd ) {
496484 let endpoint = net_backend_resources:: tap:: TapHandle { fd : tap_fd } . into_resource ( ) ;
497- const TAP_NETVSP_INSTANCE : guid:: Guid =
498- guid:: guid!( "a1b2c3d4-e5f6-7890-abcd-ef1234567890" ) ;
485+ const TAP_NETVSP_INSTANCE : guid:: Guid = guid:: guid!( "a1b2c3d4-e5f6-7890-abcd-ef1234567890" ) ;
499486
500487 config. vmbus_devices . push ( (
501488 DeviceVtl :: Vtl0 ,
@@ -510,10 +497,7 @@ mod tap {
510497 }
511498
512499 /// Add a virtio-net NIC backed by a TAP fd to the VM config (PCIe).
513- fn add_virtio_tap_nic (
514- config : & mut openvmm_defs:: config:: Config ,
515- tap_fd : std:: os:: fd:: OwnedFd ,
516- ) {
500+ fn add_virtio_tap_nic ( config : & mut openvmm_defs:: config:: Config , tap_fd : std:: os:: fd:: OwnedFd ) {
517501 let endpoint = net_backend_resources:: tap:: TapHandle { fd : tap_fd } . into_resource ( ) ;
518502
519503 config. pcie_devices . push ( PcieDeviceConfig {
@@ -530,22 +514,47 @@ mod tap {
530514 } ) ;
531515 }
532516
533- /// 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.
534519 pub ( super ) fn configure_builder (
535520 builder : petri:: PetriVmBuilder < petri:: openvmm:: OpenVmmPetriBackend > ,
536521 tap_fd : std:: os:: fd:: OwnedFd ,
537522 nic : super :: NicBackend ,
523+ erofs_file : fs_err:: File ,
538524 ) -> petri:: PetriVmBuilder < petri:: openvmm:: OpenVmmPetriBackend > {
539525 builder. modify_backend ( move |c| {
540- let c = match nic {
541- super :: NicBackend :: Vmbus => c. with_nic ( ) ,
542- super :: NicBackend :: VirtioNet => c
543- . with_pcie_root_topology ( 1 , 1 , 2 )
544- . 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+ ) ,
545535 } ;
546- c. with_custom_config ( |config| match nic {
547- super :: NicBackend :: Vmbus => add_tap_nic ( config, tap_fd) ,
548- 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+ }
549558 } )
550559 } )
551560 }
@@ -574,11 +583,6 @@ mod tap {
574583 cmd ! ( sh, "ifconfig {consomme_if} up" ) . run ( ) . await ?;
575584 cmd ! ( sh, "udhcpc -i {consomme_if} -n -q" ) . run ( ) . await ?;
576585
577- cmd ! ( sh, "apk add iperf3" )
578- . run ( )
579- . await
580- . context ( "failed to install iperf3" ) ?;
581-
582586 let find_tap =
583587 "ip -o link show | grep -i 00:15:5d:12:12:13 | awk -F: '{print $2}' | tr -d ' '" ;
584588 let tap_if = cmd ! ( sh, "sh -c {find_tap}" )
0 commit comments