From e31dbc94a585fcca2a88c0b7305d9ff02cbff118 Mon Sep 17 00:00:00 2001 From: "alex.lyn" Date: Mon, 27 Nov 2023 15:11:21 +0800 Subject: [PATCH] runtime-rs: remove vhost_fd from VsockConfig and make it cloneable. Currently encounters difficulty in utilizing the clone operation on VsockConfig due to the implicit management of the vhost fd within the runtime-rs. This responsibility should be delegated to the VMM(especially QEMU) child process, as it's not runtime-rs core responsibilities. We'll remove the member vhost_fd from VsockConfig and make the VsockConfig/VsockDevice Cloneable. Fixes: #8474 Signed-off-by: alex.lyn --- .../hypervisor/src/device/driver/virtio_vsock.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) 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 76ca9dabc2..c4d4664041 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 @@ -84,16 +84,13 @@ impl Device for HybridVsockDevice { } } -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct VsockConfig { /// A 32-bit Context Identifier (CID) used to identify the guest. pub guest_cid: u32, - - /// Vhost vsock fd. Hold to ensure CID is not used by other VM. - pub vhost_fd: File, } -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct VsockDevice { /// Unique identifier of the device pub id: String, @@ -121,16 +118,13 @@ const CID_RETRY_COUNT: u32 = 50; impl VsockDevice { pub async fn new(id: String) -> Result { - let (guest_cid, vhost_fd) = generate_vhost_vsock_cid() + let (guest_cid, _vhost_fd) = generate_vhost_vsock_cid() .await .context("generate vhost vsock cid failed")?; Ok(Self { id, - config: VsockConfig { - guest_cid, - vhost_fd, - }, + config: VsockConfig { guest_cid }, }) } }