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_image.go b/rw_core/core/device/agent_image.go
index 3bc91ca..0dc56bf 100644
--- a/rw_core/core/device/agent_image.go
+++ b/rw_core/core/device/agent_image.go
@@ -84,7 +84,7 @@
 	logger.Debugw(ctx, "cancelImageDownload", log.Fields{"device-id": agent.deviceID})
 
 	// Verify whether the Image is in the list of image being downloaded
-	device := agent.getDeviceReadOnly()
+	device := agent.getDeviceReadOnlyWithoutLock()
 	if !isImageRegistered(img, device) {
 		agent.requestQueue.RequestComplete()
 		return nil, status.Errorf(codes.FailedPrecondition, "device-id:%s, image-not-registered:%s", agent.deviceID, img.Name)
@@ -124,7 +124,7 @@
 	logger.Debugw(ctx, "activateImage", log.Fields{"device-id": agent.deviceID})
 
 	// Verify whether the Image is in the list of image being downloaded
-	device := agent.getDeviceReadOnly()
+	device := agent.getDeviceReadOnlyWithoutLock()
 	if !isImageRegistered(img, device) {
 		agent.requestQueue.RequestComplete()
 		return nil, status.Errorf(codes.FailedPrecondition, "device-id:%s, image-not-registered:%s", agent.deviceID, img.Name)
@@ -167,7 +167,7 @@
 	logger.Debugw(ctx, "revertImage", log.Fields{"device-id": agent.deviceID})
 
 	// Verify whether the Image is in the list of image being downloaded
-	device := agent.getDeviceReadOnly()
+	device := agent.getDeviceReadOnlyWithoutLock()
 	if !isImageRegistered(img, device) {
 		agent.requestQueue.RequestComplete()
 		return nil, status.Errorf(codes.FailedPrecondition, "deviceId:%s, image-not-registered:%s", agent.deviceID, img.Name)
@@ -205,7 +205,7 @@
 	if err := agent.requestQueue.WaitForGreenLight(ctx); err != nil {
 		return nil, err
 	}
-	device := agent.getDeviceReadOnly()
+	device := agent.getDeviceReadOnlyWithoutLock()
 	ch, err := agent.adapterProxy.GetImageDownloadStatus(ctx, device, img)
 	agent.requestQueue.RequestComplete()
 	if err != nil {
@@ -255,13 +255,12 @@
 }
 
 func (agent *Agent) getImageDownload(ctx context.Context, img *voltha.ImageDownload) (*voltha.ImageDownload, error) {
-	if err := agent.requestQueue.WaitForGreenLight(ctx); err != nil {
-		return nil, err
-	}
-	defer agent.requestQueue.RequestComplete()
 	logger.Debugw(ctx, "getImageDownload", log.Fields{"device-id": agent.deviceID})
 
-	device := agent.getDeviceReadOnly()
+	device, err := agent.getDeviceReadOnly(ctx)
+	if err != nil {
+		return nil, status.Errorf(codes.Aborted, "%s", err)
+	}
 	for _, image := range device.ImageDownloads {
 		if image.Id == img.Id && image.Name == img.Name {
 			return image, nil
@@ -271,11 +270,11 @@
 }
 
 func (agent *Agent) listImageDownloads(ctx context.Context, deviceID string) (*voltha.ImageDownloads, error) {
-	if err := agent.requestQueue.WaitForGreenLight(ctx); err != nil {
-		return nil, err
-	}
-	defer agent.requestQueue.RequestComplete()
 	logger.Debugw(ctx, "listImageDownloads", log.Fields{"device-id": agent.deviceID})
 
-	return &voltha.ImageDownloads{Items: agent.getDeviceReadOnly().ImageDownloads}, nil
+	device, err := agent.getDeviceReadOnly(ctx)
+	if err != nil {
+		return nil, status.Errorf(codes.Aborted, "%s", err)
+	}
+	return &voltha.ImageDownloads{Items: device.ImageDownloads}, nil
 }