Skip to content

Commit

Permalink
vmm:fix stratovirt lightweight vm sandbox start failed when cni enabled
Browse files Browse the repository at this point in the history
net device bus and addr should not be set, transport should be mmio
when starting stratovirt lightweight vm sandbox

Signed-off-by: Vanient <xiadanni1@huawei.com>
  • Loading branch information
Vanient committed Dec 26, 2023
1 parent f4ab00f commit e226c0f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
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")]
#[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

0 comments on commit e226c0f

Please sign in to comment.