Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vmm:fix stratovirt lightweight vm sandbox start failed when cni enabled #103

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 41 additions & 6 deletions vmm/sandbox/src/stratovirt/devices/virtio_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ pub struct VirtioNetDevice {
pub(crate) fds: Vec<i32>,
#[property(param = "netdev", predicate = "self.fds.len()<=0")]
pub(crate) ifname: Option<String>,
#[property(param = "device", key = "bus")]
#[property(param = "device", key = "bus", predicate = "self.addr.len()>0")]
pub(crate) pci_bus: Option<String>,
#[property(param = "device", key = "addr")]
flyflypeng marked this conversation as resolved.
Show resolved Hide resolved
#[property(param = "device", predicate = "self.addr.len()>0")]
pub(crate) addr: String,
#[property(param = "netdev")]
pub(crate) script: Option<String>,
Expand Down Expand Up @@ -170,12 +170,10 @@ impl VirtioNetDevice {
#[cfg(test)]
mod tests {
use crate::{
device::Transport,
network::NetType,
param::ToCmdLineParams,
stratovirt::{
devices::{virtio_net::VirtioNetDevice, DEFAULT_PCIE_BUS},
Transport,
},
stratovirt::devices::{virtio_net::VirtioNetDevice, DEFAULT_PCIE_BUS},
};

#[test]
Expand Down Expand Up @@ -213,4 +211,41 @@ mod tests {
.position(|x| x == "virtio-net-pci,netdev=intf-tap0,id=virtio-net-intf-tap0,bus=pcie.0,addr=0x0f,mac=a1:b2:c3:d5:f4,mq=on")
.is_some());
}

#[test]
fn test_virtio_net_params_microvm() {
let device = VirtioNetDevice {
r#type: NetType::Tap,
transport: Transport::Mmio,
driver: "virtio-net-device".to_string(),
id: "intf-tap0".to_string(),
device_id: "virtio-net-intf-tap0".to_string(),
vhost: false,
vhostfds: vec![],
fds: vec![],
ifname: Some("tap0".to_string()),
pci_bus: Some(DEFAULT_PCIE_BUS.to_string()),
addr: "".to_string(),
script: None,
down_script: None,
mac_address: "a1:b2:c3:d5:f4".to_string(),
multi_queue: false,
disable_modern: None,
romfile: None,
queues: None,
};
let params = device.to_cmdline_params("-");

println!("params: {:?}", params);

assert!(params
.iter()
.position(|x| x == "tap,id=intf-tap0,ifname=tap0")
.is_some());
assert!(params
.iter()
.position(|x| x
== "virtio-net-device,netdev=intf-tap0,id=virtio-net-intf-tap0,mac=a1:b2:c3:d5:f4,mq=off")
.is_some());
}
}
4 changes: 2 additions & 2 deletions vmm/sandbox/src/stratovirt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use self::{
hooks::StratoVirtHooks,
};
use crate::{
device::{Bus, BusType, DeviceInfo, Slot, SlotStatus, Transport},
device::{Bus, BusType, DeviceInfo, Slot, SlotStatus},
impl_recoverable, load_config,
param::ToCmdLineParams,
sandbox::KuasarSandboxer,
Expand Down Expand Up @@ -200,7 +200,7 @@ impl VM for StratoVirtVM {
.id(&tap_info.id)
.name(&tap_info.name)
.mac_address(&tap_info.mac_address)
.transport(Transport::Pci)
.transport(self.config.machine.transport())
.fds(fd_ints)
.vhost(false)
.vhostfds(vec![])
Expand Down
Loading