Skip to content

Commit

Permalink
Crudely address libnvpair linking issues for now
Browse files Browse the repository at this point in the history
  • Loading branch information
pfmooney committed Nov 18, 2024
1 parent 09da109 commit 861d270
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
4 changes: 4 additions & 0 deletions crates/viona-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ doctest = false
[dependencies]
libc.workspace = true
viona_api_sys.workspace = true

# nvpair dependency only enabled when building on illumos to avoid any attempts
# to link to an absent libnvpair
[target.'cfg(target_os = "illumos")'.dependencies]
nvpair.workspace = true

[features]
Expand Down
8 changes: 7 additions & 1 deletion crates/viona-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ use std::io::{Error, ErrorKind, Result};
use std::os::fd::*;
use std::os::unix::fs::MetadataExt;

pub use nvpair::NvList;
pub use viona_api_sys::*;

// Hide libnvpair usage when not building on illumos to avoid linking errors
#[cfg(target_os = "illumos")]
pub use nvpair::NvList;

pub const VIONA_DEV_PATH: &str = "/dev/viona";

pub struct VionaFd(File);
Expand All @@ -32,6 +35,7 @@ impl VionaFd {
Ok(Self(fp))
}

#[cfg(target_os = "illumos")]
pub fn set_parameters(
&self,
params: &mut NvList,
Expand Down Expand Up @@ -62,6 +66,7 @@ impl VionaFd {
}
}

#[cfg(target_os = "illumos")]
pub fn get_parameters(&self) -> Result<NvList> {
let mut buf: Vec<u8> = Vec::with_capacity(VIONA_MAX_PARAM_NVLIST_SZ);

Expand Down Expand Up @@ -145,6 +150,7 @@ impl AsRawFd for VionaFd {
}
}

#[cfg(target_os = "illumos")]
pub enum ParamError {
Io(std::io::Error),
Detailed(NvList),
Expand Down
39 changes: 26 additions & 13 deletions lib/propolis/src/hw/virtio/viona.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,31 @@ pub struct DeviceParams {
/// larger header.
pub header_pad: u16,
}
impl DeviceParams {
#[cfg(target_os = "illumos")]
fn set(&self, hdl: &VionaHdl) -> io::Result<()> {
// Set parameters assuming an ApiVersion::V3 device
let mut params = viona_api::NvList::new();
params.add(c"tx_copy_data", self.copy_data);
params.add(c"tx_header_pad", self.header_pad);
if let Err(e) = hdl.0.set_parameters(&mut params) {
match e {
viona_api::ParamError::Io(io) => Err(io),
viona_api::ParamError::Detailed(_) => Err(Error::new(
ErrorKind::InvalidInput,
"unsupported viona parameters",
)),
}
} else {
Ok(())
}
}

#[cfg(not(target_os = "illumos"))]
fn set(&self, _hdl: &VionaHdl) -> io::Result<()> {
panic!("viona and libnvpair not present on non-illumos")
}
}
impl Default for DeviceParams {
fn default() -> Self {
// Viona (as of V3) allocs/copies entire packet by default, with no
Expand Down Expand Up @@ -150,19 +175,7 @@ impl PciVirtioViona {
}

if let Some(vp) = viona_params {
// Set parameters assuming an ApiVersion::V3 device
let mut params = viona_api::NvList::new();
params.add(c"tx_copy_data", vp.copy_data);
params.add(c"tx_header_pad", vp.header_pad);
if let Err(e) = hdl.0.set_parameters(&mut params) {
return match e {
viona_api::ParamError::Io(io) => Err(io),
viona_api::ParamError::Detailed(_) => Err(Error::new(
ErrorKind::InvalidInput,
"unsupported viona parameters",
)),
};
}
vp.set(&hdl)?;
}

// TX and RX
Expand Down

0 comments on commit 861d270

Please sign in to comment.