From e7beed543066619b3ae2eebe4c4b16f6a6622479 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Thu, 4 Nov 2021 15:18:04 +1100 Subject: [PATCH] agent/device: Remove unneeded clone() from several device handlers virtio_blk_device_handler(), virtio_blk_ccw_device_handler() and virtio_scsi_device_handler() all take a clone of their 'device' parameter. They appear to do this in order to get a mutable copy in which they can update the vm_path field. However, the copy is dropped at the end of the function, so the only thing that's used in it is the vm_path field passed to update_spec_device() afterwards. We can avoid the clone by just using a local variable for the vm_path. Signed-off-by: David Gibson --- src/agent/src/device.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/agent/src/device.rs b/src/agent/src/device.rs index 238d55640..afae70dd9 100644 --- a/src/agent/src/device.rs +++ b/src/agent/src/device.rs @@ -546,12 +546,10 @@ async fn virtio_blk_device_handler( sandbox: &Arc>, devidx: &DevIndex, ) -> Result<()> { - let mut dev = device.clone(); let pcipath = pci::Path::from_str(&device.id)?; + let vm_path = get_virtio_blk_pci_device_name(sandbox, &pcipath).await?; - dev.vm_path = get_virtio_blk_pci_device_name(sandbox, &pcipath).await?; - - update_spec_device(spec, devidx, &dev.container_path, &dev.vm_path, None) + update_spec_device(spec, devidx, &device.container_path, &vm_path, None) } // device.id should be a CCW path string @@ -563,15 +561,14 @@ async fn virtio_blk_ccw_device_handler( sandbox: &Arc>, devidx: &DevIndex, ) -> Result<()> { - let mut dev = device.clone(); let ccw_device = ccw::Device::from_str(&device.id)?; - dev.vm_path = get_virtio_blk_ccw_device_name(sandbox, &ccw_device).await?; + let vm_path = get_virtio_blk_ccw_device_name(sandbox, &ccw_device).await?; update_spec_device( spec, devidx, - &dev.container_path, - &dev.vm_path, - &dev.container_path, + &device.container_path, + &vm_path, + &device.container_path, ) } @@ -594,9 +591,8 @@ async fn virtio_scsi_device_handler( sandbox: &Arc>, devidx: &DevIndex, ) -> Result<()> { - let mut dev = device.clone(); - dev.vm_path = get_scsi_device_name(sandbox, &device.id).await?; - update_spec_device(spec, devidx, &dev.container_path, &dev.vm_path, None) + let vm_path = get_scsi_device_name(sandbox, &device.id).await?; + update_spec_device(spec, devidx, &device.container_path, &vm_path, None) } #[instrument]