mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 20:24:31 +00:00
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:
parent
2029eeebca
commit
e7beed5430
@ -546,12 +546,10 @@ async fn virtio_blk_device_handler(
|
||||
sandbox: &Arc<Mutex<Sandbox>>,
|
||||
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<Mutex<Sandbox>>,
|
||||
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<Mutex<Sandbox>>,
|
||||
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]
|
||||
|
Loading…
Reference in New Issue
Block a user