Merge pull request #8672 from BbolroC/introduce-vsock-device-init

runtime-rs: Separate init_config() from new() for struct VsockDevice
This commit is contained in:
Hyounggyu Choi
2023-12-18 22:04:37 +01:00
committed by GitHub
2 changed files with 14 additions and 8 deletions

View File

@@ -330,9 +330,11 @@ impl DeviceManager {
// No need to do find device for hybrid vsock device. // No need to do find device for hybrid vsock device.
Arc::new(Mutex::new(HybridVsockDevice::new(&device_id, hvconfig))) Arc::new(Mutex::new(HybridVsockDevice::new(&device_id, hvconfig)))
} }
DeviceConfig::VsockCfg(_vconfig) => { DeviceConfig::VsockCfg(vconfig) => {
// No need to do find device for vsock device. // 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) => { DeviceConfig::ShareFsCfg(config) => {
// Try to find the sharefs device. If found, just return matched device id. // Try to find the sharefs device. If found, just return matched device id.

View File

@@ -117,16 +117,20 @@ nix::ioctl_write_ptr!(
const CID_RETRY_COUNT: u32 = 50; const CID_RETRY_COUNT: u32 = 50;
impl VsockDevice { impl VsockDevice {
pub async fn new(id: String) -> Result<Self> { pub async fn new(id: String, config: &VsockConfig) -> Result<Self> {
let (guest_cid, _vhost_fd) = generate_vhost_vsock_cid()
.await
.context("generate vhost vsock cid failed")?;
Ok(Self { Ok(Self {
id, id,
config: VsockConfig { guest_cid }, config: config.clone(),
}) })
} }
pub async fn init_config(&mut self) -> Result<File> {
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] #[async_trait]