Skip to content

Commit 7639263

Browse files
committed
fix: macOS/Windows build for ttrpc TAP cfg gates
Revert TapHandle to cfg(unix) since it's just a data type carrying an OwnedFd. Use unconditional Backend::Tap match arm with cfg blocks inside the body to avoid all-diverging-arms warnings on macOS.
1 parent ee13750 commit 7639263

3 files changed

Lines changed: 27 additions & 15 deletions

File tree

  • openvmm/openvmm_entry/src/ttrpc
  • petri/burette/src/tests
  • vm/devices/net/net_backend_resources/src

openvmm/openvmm_entry/src/ttrpc/mod.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,10 @@ impl VmService {
704704
}
705705
}
706706

707+
#[cfg_attr(
708+
not(any(windows, target_os = "linux")),
709+
allow(unreachable_code, unused_variables)
710+
)]
707711
fn parse_nic_config(
708712
nic: vmservice::NicConfig,
709713
) -> anyhow::Result<(DeviceVtl, Resource<VmbusDeviceHandleKind>)> {
@@ -724,10 +728,17 @@ fn parse_nic_config(
724728
},
725729
}
726730
.into_resource(),
727-
#[cfg(target_os = "linux")]
728731
Backend::Tap(tap) => {
729-
let fd = net_tap::tap::open_tap(&tap.name).context("failed to open TAP device")?;
730-
net_backend_resources::tap::TapHandle { fd }.into_resource()
732+
#[cfg(target_os = "linux")]
733+
{
734+
let fd = net_tap::tap::open_tap(&tap.name).context("failed to open TAP device")?;
735+
net_backend_resources::tap::TapHandle { fd }.into_resource()
736+
}
737+
#[cfg(not(target_os = "linux"))]
738+
{
739+
let _ = tap;
740+
anyhow::bail!("TAP backend is only supported on Linux")
741+
}
731742
}
732743
_ => anyhow::bail!("unsupported backend"),
733744
};

petri/burette/src/tests/network.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,18 @@ impl NetworkTest {
408408
std::thread::sleep(std::time::Duration::from_millis(500));
409409

410410
// Run guest iperf3 client.
411-
run_guest_iperf3_client(&state.agent, host_ip, port, &mode, metric_name, state.use_chroot)
412-
.await?;
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?;
413420

414421
// Collect JSON from the helper.
415-
let json = json_future
416-
.await
417-
.context("iperf3 helper RPC failed")?;
422+
let json = json_future.await.context("iperf3 helper RPC failed")?;
418423

419424
if !json.is_empty() {
420425
tracing::debug!(metric = metric_name, json = %json, "raw iperf3 output");
@@ -494,8 +499,7 @@ mod tap {
494499
/// Add a VMBus synthnic backed by a TAP fd to the VM config.
495500
fn add_tap_nic(config: &mut openvmm_defs::config::Config, tap_fd: std::os::fd::OwnedFd) {
496501
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");
502+
const TAP_NETVSP_INSTANCE: guid::Guid = guid::guid!("a1b2c3d4-e5f6-7890-abcd-ef1234567890");
499503

500504
config.vmbus_devices.push((
501505
DeviceVtl::Vtl0,
@@ -510,10 +514,7 @@ mod tap {
510514
}
511515

512516
/// 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-
) {
517+
fn add_virtio_tap_nic(config: &mut openvmm_defs::config::Config, tap_fd: std::os::fd::OwnedFd) {
517518
let endpoint = net_backend_resources::tap::TapHandle { fd: tap_fd }.into_resource();
518519

519520
config.pcie_devices.push(PcieDeviceConfig {

vm/devices/net/net_backend_resources/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub mod dio {
7272
}
7373

7474
/// Linux TAP backend.
75-
#[cfg(target_os = "linux")]
75+
#[cfg(unix)]
7676
pub mod tap {
7777
use mesh::MeshPayload;
7878
use vm_resource::ResourceId;

0 commit comments

Comments
 (0)