diff --git a/src/runtime-rs/crates/hypervisor/src/device/device_manager.rs b/src/runtime-rs/crates/hypervisor/src/device/device_manager.rs index 31602a01f..2b5ef6df5 100644 --- a/src/runtime-rs/crates/hypervisor/src/device/device_manager.rs +++ b/src/runtime-rs/crates/hypervisor/src/device/device_manager.rs @@ -330,9 +330,11 @@ impl DeviceManager { // No need to do find device for hybrid vsock device. Arc::new(Mutex::new(HybridVsockDevice::new(&device_id, hvconfig))) } - DeviceConfig::VsockCfg(_vconfig) => { + DeviceConfig::VsockCfg(vconfig) => { // No need to do find device for vsock device. - Arc::new(Mutex::new(VsockDevice::new(device_id.clone()).await?)) + Arc::new(Mutex::new( + VsockDevice::new(device_id.clone(), vconfig).await?, + )) } DeviceConfig::ShareFsCfg(config) => { // Try to find the sharefs device. If found, just return matched device id. diff --git a/src/runtime-rs/crates/hypervisor/src/device/driver/virtio_vsock.rs b/src/runtime-rs/crates/hypervisor/src/device/driver/virtio_vsock.rs index f3ef545a9..0c37fb18d 100644 --- a/src/runtime-rs/crates/hypervisor/src/device/driver/virtio_vsock.rs +++ b/src/runtime-rs/crates/hypervisor/src/device/driver/virtio_vsock.rs @@ -117,16 +117,20 @@ nix::ioctl_write_ptr!( const CID_RETRY_COUNT: u32 = 50; impl VsockDevice { - pub async fn new(id: String) -> Result { - let (guest_cid, _vhost_fd) = generate_vhost_vsock_cid() - .await - .context("generate vhost vsock cid failed")?; - + pub async fn new(id: String, config: &VsockConfig) -> Result { Ok(Self { id, - config: VsockConfig { guest_cid }, + config: config.clone(), }) } + + pub async fn init_config(&mut self) -> Result { + let (guest_cid, vhost_fd) = generate_vhost_vsock_cid() + .await + .context("generate vhost vsock cid failed")?; + self.config.guest_cid = guest_cid; + Ok(vhost_fd) + } } #[async_trait]