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 <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2021-11-04 15:18:04 +11:00
parent 2029eeebca
commit e7beed5430

View File

@ -546,12 +546,10 @@ async fn virtio_blk_device_handler(
sandbox: &Arc<Mutex<Sandbox>>, sandbox: &Arc<Mutex<Sandbox>>,
devidx: &DevIndex, devidx: &DevIndex,
) -> Result<()> { ) -> Result<()> {
let mut dev = device.clone();
let pcipath = pci::Path::from_str(&device.id)?; 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, &device.container_path, &vm_path, None)
update_spec_device(spec, devidx, &dev.container_path, &dev.vm_path, None)
} }
// device.id should be a CCW path string // device.id should be a CCW path string
@ -563,15 +561,14 @@ async fn virtio_blk_ccw_device_handler(
sandbox: &Arc<Mutex<Sandbox>>, sandbox: &Arc<Mutex<Sandbox>>,
devidx: &DevIndex, devidx: &DevIndex,
) -> Result<()> { ) -> Result<()> {
let mut dev = device.clone();
let ccw_device = ccw::Device::from_str(&device.id)?; 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( update_spec_device(
spec, spec,
devidx, devidx,
&dev.container_path, &device.container_path,
&dev.vm_path, &vm_path,
&dev.container_path, &device.container_path,
) )
} }
@ -594,9 +591,8 @@ async fn virtio_scsi_device_handler(
sandbox: &Arc<Mutex<Sandbox>>, sandbox: &Arc<Mutex<Sandbox>>,
devidx: &DevIndex, devidx: &DevIndex,
) -> Result<()> { ) -> Result<()> {
let mut dev = device.clone(); let vm_path = get_scsi_device_name(sandbox, &device.id).await?;
dev.vm_path = get_scsi_device_name(sandbox, &device.id).await?; update_spec_device(spec, devidx, &device.container_path, &vm_path, None)
update_spec_device(spec, devidx, &dev.container_path, &dev.vm_path, None)
} }
#[instrument] #[instrument]