VOL-2867 - Removed unnescessary proto.Clone() in getDevice() and getLogicalDevice().
Also renamed getDevice() to getDeviceReadOnly(), getLogicalDevice() to getLogicalDeviceReadOnly(), and getDeviceReadOnly() to getDeviceReadOnlyWithoutLock().
Callers of *ReadOnly() functions must not modify the returned structures.
Also fixed places where lock was not acquired before calling getDevice().
Related to VOL-3356.
Change-Id: I9913a76a497c4d977457edaea3b199a24a3a5cb8
diff --git a/rw_core/core/device/agent_flow.go b/rw_core/core/device/agent_flow.go
index 09ca7ed..94376d1 100644
--- a/rw_core/core/device/agent_flow.go
+++ b/rw_core/core/device/agent_flow.go
@@ -49,7 +49,10 @@
logger.Debugw(ctx, "nothing-to-update", log.Fields{"device-id": agent.deviceID, "flows": newFlows})
return coreutils.DoneResponse(), nil
}
- device := agent.getDeviceReadOnly()
+ device, err := agent.getDeviceReadOnly(ctx)
+ if err != nil {
+ return coreutils.DoneResponse(), status.Errorf(codes.Aborted, "%s", err)
+ }
dType, err := agent.adapterMgr.GetDeviceType(ctx, &voltha.ID{Id: device.Type})
if err != nil {
return coreutils.DoneResponse(), status.Errorf(codes.FailedPrecondition, "non-existent-device-type-%s", device.Type)
@@ -127,7 +130,10 @@
return coreutils.DoneResponse(), nil
}
- device := agent.getDeviceReadOnly()
+ device, err := agent.getDeviceReadOnly(ctx)
+ if err != nil {
+ return coreutils.DoneResponse(), status.Errorf(codes.Aborted, "%s", err)
+ }
dType, err := agent.adapterMgr.GetDeviceType(ctx, &voltha.ID{Id: device.Type})
if err != nil {
return coreutils.DoneResponse(), status.Errorf(codes.FailedPrecondition, "non-existent-device-type-%s", device.Type)
@@ -183,7 +189,10 @@
return coreutils.DoneResponse(), nil
}
- device := agent.getDeviceReadOnly()
+ device, err := agent.getDeviceReadOnly(ctx)
+ if err != nil {
+ return coreutils.DoneResponse(), status.Errorf(codes.Aborted, "%s", err)
+ }
if device.OperStatus != voltha.OperStatus_ACTIVE || device.ConnectStatus != voltha.ConnectStatus_REACHABLE || device.AdminState != voltha.AdminState_ENABLED {
return coreutils.DoneResponse(), status.Errorf(codes.FailedPrecondition, "invalid device states")
}