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_pm_config.go b/rw_core/core/device/agent_pm_config.go
index 033e6f4..8677029 100644
--- a/rw_core/core/device/agent_pm_config.go
+++ b/rw_core/core/device/agent_pm_config.go
@@ -22,6 +22,8 @@
"github.com/gogo/protobuf/proto"
"github.com/opencord/voltha-lib-go/v3/pkg/log"
"github.com/opencord/voltha-protos/v3/go/voltha"
+ "google.golang.org/grpc/codes"
+ "google.golang.org/grpc/status"
)
func (agent *Agent) updatePmConfigs(ctx context.Context, pmConfigs *voltha.PmConfigs) error {
@@ -59,11 +61,11 @@
}
func (agent *Agent) listPmConfigs(ctx context.Context) (*voltha.PmConfigs, error) {
- if err := agent.requestQueue.WaitForGreenLight(ctx); err != nil {
- return nil, err
- }
- defer agent.requestQueue.RequestComplete()
logger.Debugw(ctx, "listPmConfigs", log.Fields{"device-id": agent.deviceID})
- return agent.getDeviceReadOnly().PmConfigs, nil
+ device, err := agent.getDeviceReadOnly(ctx)
+ if err != nil {
+ return nil, status.Errorf(codes.Aborted, "%s", err)
+ }
+ return device.PmConfigs, nil
}