Skip to content

Commit

Permalink
runtime-rs: Add Hybrid VSOCK device handling for CH
Browse files Browse the repository at this point in the history
Update cloud hypervisor implementation to allow hybrid vsock devices to
be handled.

Fixes #6692

Signed-off-by: Chelsea Mafrica <chelsea.e.mafrica@intel.com>
  • Loading branch information
cmaf committed Nov 21, 2023
1 parent 358f32e commit 2c37bd9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
20 changes: 19 additions & 1 deletion src/runtime-rs/crates/hypervisor/ch-config/src/ch_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: Apache-2.0

use crate::{DeviceConfig, DiskConfig, FsConfig, VmConfig};
use crate::{DeviceConfig, DiskConfig, FsConfig, VmConfig, VsockConfig};
use anyhow::{anyhow, Result};
use api_client::simple_api_full_command_and_response;

Expand Down Expand Up @@ -154,3 +154,21 @@ pub async fn cloud_hypervisor_vm_fs_add(
})
.await?
}

pub async fn cloud_hypervisor_vm_vsock_add(
mut socket: UnixStream,
vsock_config: VsockConfig,
) -> Result<Option<String>> {
task::spawn_blocking(move || -> Result<Option<String>> {
let response = simple_api_full_command_and_response(
&mut socket,
"PUT",
"vm.add-vsock",
Some(&serde_json::to_string(&vsock_config)?),
)
.map_err(|e| anyhow!(e))?;

Ok(response)
})
.await?
}
35 changes: 29 additions & 6 deletions src/runtime-rs/crates/hypervisor/src/ch/inner_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ 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, PciDeviceInfo, VmRemoveDeviceData,
cloud_hypervisor_vm_fs_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;
use ch_config::{net_util::MacAddr, DeviceConfig, FsConfig, NetConfig};
use ch_config::{net_util::MacAddr, DeviceConfig, FsConfig, NetConfig, VsockConfig};
use safe_path::scoped_join;
use std::convert::TryFrom;
use std::path::PathBuf;
Expand Down Expand Up @@ -168,10 +168,6 @@ impl CloudHypervisorInner {
Ok(DeviceType::ShareFs(sharefs))
}

async fn handle_hvsock_device(&mut self, device: HybridVsockDevice) -> Result<DeviceType> {
Ok(DeviceType::HybridVsock(device))
}

async fn handle_vfio_device(&mut self, device: VfioDevice) -> Result<DeviceType> {
let mut vfio_device: VfioDevice = device.clone();

Expand Down Expand Up @@ -281,6 +277,33 @@ impl CloudHypervisorInner {
PciPath::convert_from_string(toks[0])
}

async fn handle_hvsock_device(&mut self, device: HybridVsockDevice) -> Result<DeviceType> {
let hvsock_dev = device.clone();
let socket = self
.api_socket
.as_ref()
.ok_or("missing socket")
.map_err(|e| anyhow!(e))?;

let vsock_config = VsockConfig {
cid: hvsock_dev.config.guest_cid.clone().into(),
socket: hvsock_dev.config.uds_path.clone().into(),
..Default::default()
};

let response = cloud_hypervisor_vm_vsock_add(
socket.try_clone().context("failed to clone socket")?,
vsock_config,
)
.await?;

if let Some(detail) = response {
debug!(sl!(), "hvsock add response: {:?}", detail);
}

Ok(DeviceType::HybridVsock(hvsock_dev))
}

async fn handle_block_device(&mut self, device: BlockDevice) -> Result<DeviceType> {
let mut block_dev = device.clone();
let socket = self
Expand Down

0 comments on commit 2c37bd9

Please sign in to comment.