mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-16 16:32:03 +00:00
runtime-rs: add network hotplug for clh
This is required for clh to work with nerdtcl and docker. This fixes the issues seen with nerdctl while starting a container. Hoewever, container exit with docker is still broken due to an unrelated issue. Fixes: #8579 Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
parent
2cd003156e
commit
955dec06da
@ -2,7 +2,7 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::{DeviceConfig, DiskConfig, FsConfig, VmConfig, VsockConfig};
|
||||
use crate::{DeviceConfig, DiskConfig, FsConfig, NetConfig, VmConfig, VsockConfig};
|
||||
use anyhow::{anyhow, Result};
|
||||
use api_client::simple_api_full_command_and_response;
|
||||
|
||||
@ -100,6 +100,24 @@ pub async fn cloud_hypervisor_vm_blockdev_add(
|
||||
.await?
|
||||
}
|
||||
|
||||
pub async fn cloud_hypervisor_vm_netdev_add(
|
||||
mut socket: UnixStream,
|
||||
net_config: NetConfig,
|
||||
) -> Result<Option<String>> {
|
||||
task::spawn_blocking(move || -> Result<Option<String>> {
|
||||
let response = simple_api_full_command_and_response(
|
||||
&mut socket,
|
||||
"PUT",
|
||||
"vm.add-net",
|
||||
Some(&serde_json::to_string(&net_config)?),
|
||||
)
|
||||
.map_err(|e| anyhow!(e))?;
|
||||
|
||||
Ok(response)
|
||||
})
|
||||
.await?
|
||||
}
|
||||
|
||||
pub async fn cloud_hypervisor_vm_device_add(
|
||||
mut socket: UnixStream,
|
||||
device_config: DeviceConfig,
|
||||
|
@ -9,6 +9,7 @@ use crate::device::DeviceType;
|
||||
use crate::BlockDevice;
|
||||
use crate::HybridVsockDevice;
|
||||
use crate::NetworkConfig;
|
||||
use crate::NetworkDevice;
|
||||
use crate::PciPath;
|
||||
use crate::ShareFsConfig;
|
||||
use crate::ShareFsDevice;
|
||||
@ -18,7 +19,8 @@ use anyhow::{anyhow, Context, Result};
|
||||
use ch_config::ch_api::cloud_hypervisor_vm_device_add;
|
||||
use ch_config::ch_api::{
|
||||
cloud_hypervisor_vm_blockdev_add, cloud_hypervisor_vm_device_remove,
|
||||
cloud_hypervisor_vm_fs_add, cloud_hypervisor_vm_vsock_add, PciDeviceInfo, VmRemoveDeviceData,
|
||||
cloud_hypervisor_vm_fs_add, cloud_hypervisor_vm_netdev_add, cloud_hypervisor_vm_vsock_add,
|
||||
PciDeviceInfo, VmRemoveDeviceData,
|
||||
};
|
||||
use ch_config::convert::{DEFAULT_DISK_QUEUES, DEFAULT_DISK_QUEUE_SIZE, DEFAULT_NUM_PCI_SEGMENTS};
|
||||
use ch_config::DiskConfig;
|
||||
@ -79,6 +81,7 @@ impl CloudHypervisorInner {
|
||||
DeviceType::HybridVsock(hvsock) => self.handle_hvsock_device(hvsock).await,
|
||||
DeviceType::Block(block) => self.handle_block_device(block).await,
|
||||
DeviceType::Vfio(vfiodev) => self.handle_vfio_device(vfiodev).await,
|
||||
DeviceType::Network(netdev) => self.handle_network_device(netdev).await,
|
||||
_ => Err(anyhow!("unhandled device: {:?}", device)),
|
||||
}
|
||||
}
|
||||
@ -341,6 +344,30 @@ impl CloudHypervisorInner {
|
||||
Ok(DeviceType::Block(block_dev))
|
||||
}
|
||||
|
||||
async fn handle_network_device(&mut self, device: NetworkDevice) -> Result<DeviceType> {
|
||||
let netdev = device.clone();
|
||||
|
||||
let socket = self
|
||||
.api_socket
|
||||
.as_ref()
|
||||
.ok_or("missing socket")
|
||||
.map_err(|e| anyhow!(e))?;
|
||||
|
||||
let clh_net_config = NetConfig::try_from(device.config)?;
|
||||
|
||||
let response = cloud_hypervisor_vm_netdev_add(
|
||||
socket.try_clone().context("failed to clone socket")?,
|
||||
clh_net_config,
|
||||
)
|
||||
.await?;
|
||||
|
||||
if let Some(detail) = response {
|
||||
debug!(sl!(), "netdev add response: {:?}", detail);
|
||||
}
|
||||
|
||||
Ok(DeviceType::Network(netdev))
|
||||
}
|
||||
|
||||
pub(crate) async fn get_shared_devices(
|
||||
&mut self,
|
||||
) -> Result<(Option<Vec<FsConfig>>, Option<Vec<NetConfig>>)> {
|
||||
|
Loading…
Reference in New Issue
Block a user