From ebd7b6188404450f1cdd0a8599708ff1c18ea027 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Tue, 13 Apr 2021 14:49:42 +1000 Subject: [PATCH] runtime: Don't repeat GetDeviceByID between appendDevices() and append*() Both appendBlockDevice and appendVhostUserBlkDevice start by using GetDeviceByID to lookup the api.Device object corresponding to their ContainerDevice object. However their common caller, appendDevices() has already done this. This changes it so the looked up api.Device is passed to the individual append*Device() functions. This slightly reduces duplicated work, but more importantly it makes it clearer that append*Device() don't need to check for a nil result from GetDeviceByID, since the caller has already done that. Signed-off-by: David Gibson --- src/runtime/virtcontainers/kata_agent.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/runtime/virtcontainers/kata_agent.go b/src/runtime/virtcontainers/kata_agent.go index 698353a9e4..81c44a9fdb 100644 --- a/src/runtime/virtcontainers/kata_agent.go +++ b/src/runtime/virtcontainers/kata_agent.go @@ -1144,9 +1144,7 @@ func (k *kataAgent) handleShm(mounts []specs.Mount, sandbox *Sandbox) { } } -func (k *kataAgent) appendBlockDevice(dev ContainerDevice, c *Container) *grpc.Device { - device := c.sandbox.devManager.GetDeviceByID(dev.ID) - +func (k *kataAgent) appendBlockDevice(dev ContainerDevice, device api.Device, c *Container) *grpc.Device { d, ok := device.GetDeviceInfo().(*config.BlockDrive) if !ok || d == nil { k.Logger().WithField("device", device).Error("malformed block drive") @@ -1187,9 +1185,7 @@ func (k *kataAgent) appendBlockDevice(dev ContainerDevice, c *Container) *grpc.D return kataDevice } -func (k *kataAgent) appendVhostUserBlkDevice(dev ContainerDevice, c *Container) *grpc.Device { - device := c.sandbox.devManager.GetDeviceByID(dev.ID) - +func (k *kataAgent) appendVhostUserBlkDevice(dev ContainerDevice, device api.Device, c *Container) *grpc.Device { d, ok := device.GetDeviceInfo().(*config.VhostUserDeviceAttrs) if !ok || d == nil { k.Logger().WithField("device", device).Error("malformed vhost-user-blk drive") @@ -1217,9 +1213,9 @@ func (k *kataAgent) appendDevices(deviceList []*grpc.Device, c *Container) []*gr switch device.DeviceType() { case config.DeviceBlock: - kataDevice = k.appendBlockDevice(dev, c) + kataDevice = k.appendBlockDevice(dev, device, c) case config.VhostUserBlk: - kataDevice = k.appendVhostUserBlkDevice(dev, c) + kataDevice = k.appendVhostUserBlkDevice(dev, device, c) } if kataDevice == nil {