Skip to content

Commit

Permalink
cleanup: append pointer instead of value to avoid copying lock value
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
iPraveenParihar authored and mergify[bot] committed Jul 10, 2024
1 parent 69ef70e commit d376271
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions internal/cephfs/groupcontrollerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -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)
Expand All @@ -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{}
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -355,7 +355,7 @@ func (cs *ControllerServer) createSnapshotAddToVolumeGroupJournal(
return nil, err
}

return &responses, nil
return responses, nil
}

func formatCreateSnapshotRequest(volID, groupSnapshotName,
Expand Down
2 changes: 1 addition & 1 deletion internal/util/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d376271

Please sign in to comment.