vmm: cleanup &Mutex parameters

In [0] we refactored some Arc<Mutex<T>> parameters to &Mutex<T>> to
satisfy clippy's needless_pass_by_value lint. Nevertheless, this is also
not so idiomatic, so as a follow-up, we put the responsibility to lock
objects to the caller side (only where this is not strictly needed by
the callee).

While on it, I also tried to pass vm_config directly into
pre_create_console_devices() which would clean up some code, but then
we have interleaving mutable and immutable borrows of the Vmm, which
are denied by the borrow checker.

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
This commit is contained in:
Philipp Schuster
2025-12-10 06:48:50 +01:00
committed by Rob Bradford
parent 4592f37bcf
commit 6bda6541be
4 changed files with 24 additions and 25 deletions
+8 -7
View File
@@ -1014,7 +1014,8 @@ impl Vmm {
.unwrap()
.landlock_enable
{
apply_landlock(self.vm_config.as_ref().unwrap().as_ref()).map_err(|e| {
let mut config = self.vm_config.as_ref().unwrap().lock().unwrap();
apply_landlock(&mut config).map_err(|e| {
MigratableError::MigrateReceive(anyhow!("Error applying landlock: {e:?}"))
})?;
}
@@ -1486,8 +1487,8 @@ impl Vmm {
.unwrap()
.landlock_enable
{
apply_landlock(self.vm_config.as_ref().unwrap().as_ref())
.map_err(VmError::ApplyLandlock)?;
let mut config = self.vm_config.as_ref().unwrap().lock().unwrap();
apply_landlock(&mut config).map_err(VmError::ApplyLandlock)?;
}
// Now we can restore the rest of the VM.
@@ -1606,8 +1607,8 @@ impl Vmm {
}
}
fn apply_landlock(vm_config: &Mutex<VmConfig>) -> result::Result<(), LandlockError> {
vm_config.lock().unwrap().apply_landlock()?;
fn apply_landlock(vm_config: &mut VmConfig) -> result::Result<(), LandlockError> {
vm_config.apply_landlock()?;
Ok(())
}
@@ -1628,8 +1629,8 @@ impl RequestHandler for Vmm {
.as_ref()
.is_some_and(|config| config.lock().unwrap().landlock_enable)
{
apply_landlock(self.vm_config.as_ref().unwrap().as_ref())
.map_err(VmError::ApplyLandlock)?;
let mut config = self.vm_config.as_ref().unwrap().lock().unwrap();
apply_landlock(&mut config).map_err(VmError::ApplyLandlock)?;
}
Ok(())
}