runtime-rs: Remove unneeded mut from new_hypervisor()

`set_hypervisor_config()` and `set_passfd_listener_port()` acquire inner
lock, so that `mut` for `hypervisor` is unneeded.

Fixes: #10682

Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
This commit is contained in:
Xuewei Niu 2024-12-20 15:57:18 +08:00
parent 372346baed
commit ecf98e4db8
8 changed files with 13 additions and 15 deletions

View File

@ -46,7 +46,7 @@ impl CloudHypervisor {
}
}
pub async fn set_hypervisor_config(&mut self, config: HypervisorConfig) {
pub async fn set_hypervisor_config(&self, config: HypervisorConfig) {
let mut inner = self.inner.write().await;
inner.set_hypervisor_config(config)
}

View File

@ -629,7 +629,7 @@ mod tests {
.get(hypervisor_name)
.ok_or_else(|| anyhow!("failed to get hypervisor for {}", &hypervisor_name))?;
let mut hypervisor = Qemu::new();
let hypervisor = Qemu::new();
hypervisor
.set_hypervisor_config(hypervisor_config.clone())
.await;

View File

@ -56,12 +56,12 @@ impl Dragonball {
}
}
pub async fn set_hypervisor_config(&mut self, config: HypervisorConfig) {
pub async fn set_hypervisor_config(&self, config: HypervisorConfig) {
let mut inner = self.inner.write().await;
inner.set_hypervisor_config(config)
}
pub async fn set_passfd_listener_port(&mut self, port: u32) {
pub async fn set_passfd_listener_port(&self, port: u32) {
let mut inner = self.inner.write().await;
inner.set_passfd_listener_port(port)
}

View File

@ -51,7 +51,7 @@ impl Firecracker {
}
}
pub async fn set_hypervisor_config(&mut self, config: HypervisorConfig) {
pub async fn set_hypervisor_config(&self, config: HypervisorConfig) {
let mut inner = self.inner.write().await;
inner.set_hypervisor_config(config)
}

View File

@ -45,7 +45,7 @@ impl Qemu {
}
}
pub async fn set_hypervisor_config(&mut self, config: HypervisorConfig) {
pub async fn set_hypervisor_config(&self, config: HypervisorConfig) {
let mut inner = self.inner.write().await;
inner.set_hypervisor_config(config)
}

View File

@ -35,7 +35,7 @@ impl Remote {
}
}
pub async fn set_hypervisor_config(&mut self, config: HypervisorConfig) {
pub async fn set_hypervisor_config(&self, config: HypervisorConfig) {
let mut inner = self.inner.write().await;
inner.set_hypervisor_config(config)
}

View File

@ -36,7 +36,7 @@ mod tests {
.get(hypervisor_name)
.ok_or_else(|| anyhow!("failed to get hypervisor for {}", &hypervisor_name))?;
let mut hypervisor = Qemu::new();
let hypervisor = Qemu::new();
hypervisor
.set_hypervisor_config(hypervisor_config.clone())
.await;

View File

@ -158,7 +158,7 @@ async fn new_hypervisor(toml_config: &TomlConfig) -> Result<Arc<dyn Hypervisor>>
match hypervisor_name.as_str() {
#[cfg(all(feature = "dragonball", not(target_arch = "s390x")))]
HYPERVISOR_DRAGONBALL => {
let mut hypervisor = Dragonball::new();
let hypervisor = Dragonball::new();
hypervisor
.set_hypervisor_config(hypervisor_config.clone())
.await;
@ -170,7 +170,7 @@ async fn new_hypervisor(toml_config: &TomlConfig) -> Result<Arc<dyn Hypervisor>>
Ok(Arc::new(hypervisor))
}
HYPERVISOR_QEMU => {
let mut hypervisor = Qemu::new();
let hypervisor = Qemu::new();
hypervisor
.set_hypervisor_config(hypervisor_config.clone())
.await;
@ -178,7 +178,7 @@ async fn new_hypervisor(toml_config: &TomlConfig) -> Result<Arc<dyn Hypervisor>>
}
#[cfg(not(target_arch = "s390x"))]
HYPERVISOR_FIRECRACKER => {
let mut hypervisor = Firecracker::new();
let hypervisor = Firecracker::new();
hypervisor
.set_hypervisor_config(hypervisor_config.clone())
.await;
@ -186,16 +186,14 @@ async fn new_hypervisor(toml_config: &TomlConfig) -> Result<Arc<dyn Hypervisor>>
}
#[cfg(all(feature = "cloud-hypervisor", not(target_arch = "s390x")))]
HYPERVISOR_NAME_CH => {
let mut hypervisor = CloudHypervisor::new();
let hypervisor = CloudHypervisor::new();
hypervisor
.set_hypervisor_config(hypervisor_config.clone())
.await;
Ok(Arc::new(hypervisor))
}
HYPERVISOR_REMOTE => {
let mut hypervisor = Remote::new();
let hypervisor = Remote::new();
hypervisor
.set_hypervisor_config(hypervisor_config.clone())
.await;