From d376271376d3912b1b313c39ea644751c9490032 Mon Sep 17 00:00:00 2001 From: Praveen M Date: Wed, 10 Jul 2024 12:00:03 +0530 Subject: [PATCH] cleanup: append pointer instead of value to avoid copying lock value This commit resolves the govet issue - `copylocks: call of append copies lock value ... contains sync.Mutex` Embedding DoNotCopy in a struct is a convention to signal and prevent shallow copies, as recommended in Go's best practices. This does not rely on a language feature but is instead a special case within the vet checker. For more details, see https://golang.org/issues/8005 Signed-off-by: Praveen M --- internal/cephfs/groupcontrollerserver.go | 14 +++++++------- internal/util/topology.go | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/cephfs/groupcontrollerserver.go b/internal/cephfs/groupcontrollerserver.go index b5dfeaabb..2a38645f6 100644 --- a/internal/cephfs/groupcontrollerserver.go +++ b/internal/cephfs/groupcontrollerserver.go @@ -178,7 +178,7 @@ func (cs *ControllerServer) CreateVolumeGroupSnapshot( CreationTime: timestamppb.New(time.Now()), } - for _, r := range *resp { + for _, r := range resp { r.Snapshot.GroupSnapshotId = vgs.VolumeGroupSnapshotID response.GroupSnapshot.Snapshots = append(response.GroupSnapshot.Snapshots, r.GetSnapshot()) } @@ -260,7 +260,7 @@ func (cs *ControllerServer) releaseQuiesceAndGetVolumeGroupSnapshotResponse( } } }() - snapshotResponses := make([]csi.CreateSnapshotResponse, 0) + snapshotResponses := make([]*csi.CreateSnapshotResponse, 0) for _, volID := range req.GetSourceVolumeIds() { // Create the snapshot for the volumeID clusterID := getClusterIDForVolumeID(fsMap, volID) @@ -281,7 +281,7 @@ func (cs *ControllerServer) releaseQuiesceAndGetVolumeGroupSnapshotResponse( "failed to create snapshot and add to volume group journal: %v", err) } - snapshotResponses = append(snapshotResponses, *resp) + snapshotResponses = append(snapshotResponses, resp) } response := &csi.CreateVolumeGroupSnapshotResponse{} @@ -314,13 +314,13 @@ func (cs *ControllerServer) createSnapshotAddToVolumeGroupJournal( vgs *store.VolumeGroupSnapshotIdentifier, cr *util.Credentials, fsMap map[string]core.FSQuiesceClient) ( - *[]csi.CreateSnapshotResponse, + []*csi.CreateSnapshotResponse, error, ) { var err error var resp *csi.CreateSnapshotResponse - responses := make([]csi.CreateSnapshotResponse, 0) + responses := make([]*csi.CreateSnapshotResponse, 0) for _, volID := range req.GetSourceVolumeIds() { err = fsQuiesceWithExpireTimeout(ctx, vgo.RequestName, fsMap) if err != nil { @@ -345,7 +345,7 @@ func (cs *ControllerServer) createSnapshotAddToVolumeGroupJournal( return nil, err } - responses = append(responses, *resp) + responses = append(responses, resp) } err = releaseFSQuiesce(ctx, vgo.RequestName, fsMap) @@ -355,7 +355,7 @@ func (cs *ControllerServer) createSnapshotAddToVolumeGroupJournal( return nil, err } - return &responses, nil + return responses, nil } func formatCreateSnapshotRequest(volID, groupSnapshotName, diff --git a/internal/util/topology.go b/internal/util/topology.go index e24a05aca..42baf7db6 100644 --- a/internal/util/topology.go +++ b/internal/util/topology.go @@ -211,7 +211,7 @@ func FindPoolAndTopology(topologyPools *[]TopologyConstrainedPool, return "", "", nil, fmt.Errorf("none of the topology constrained pools matched requested "+ "topology constraints : pools (%+v) requested topology (%+v)", - *topologyPools, *accessibilityRequirements) + *topologyPools, accessibilityRequirements) } // matchPoolToTopology loops through passed in pools, and for each pool checks if all