Skip to content

Commit

Permalink
fix(map access): Synchronize TransistionVolList(map) access (#168)
Browse files Browse the repository at this point in the history
This commit does the following changes:
* Fix concurrent access to TransistionVolList
* This commit bumps the Go version to 1.16.5 and also address review comments

Signed-off-by: mittachaitu <[email protected]>
  • Loading branch information
sai chaithanya authored Dec 2, 2021
1 parent e8cc59f commit ec7c842
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ func (ns *node) NodeStageVolume(
// automatically changed to allow Reads and writes.
// And as soon as it is unmounted permissions change
// back to what we are setting over here.
utils.TransitionVolListLock.Lock()
utils.TransitionVolList[volumeID] = apis.CStorVolumeAttachmentStatusMountUnderProgress
utils.TransitionVolListLock.Unlock()
// Login to the volume and attempt mount operation on the requested path
devicePath, err := ns.attachDisk(vol)
if err != nil {
Expand Down Expand Up @@ -218,7 +220,9 @@ func (ns *node) NodeStageVolume(
return nil, status.Error(codes.Internal, err.Error())
}

utils.TransitionVolListLock.Lock()
utils.TransitionVolList[volumeID] = apis.CStorVolumeAttachmentStatusMounted
utils.TransitionVolListLock.Unlock()
}

return &csi.NodeStageVolumeResponse{}, nil
Expand Down Expand Up @@ -275,13 +279,17 @@ func (ns *node) NodeUnstageVolume(
// immediately other node deleted this node's CR, in that case iSCSI
// target(istgt) will pick up the new one and allow only that node to login,
// so all the cases are handled
utils.TransitionVolListLock.Lock()
utils.TransitionVolList[volumeID] = apis.CStorVolumeAttachmentStatusUnmountUnderProgress
utils.TransitionVolListLock.Unlock()

if err = iscsiutils.UnmountAndDetachDisk(vol, stagingTargetPath); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

utils.TransitionVolListLock.Lock()
utils.TransitionVolList[volumeID] = apis.CStorVolumeAttachmentStatusUnmounted
// It is safe to delete the CStorVolumeAttachment CR now since the volume has already
// been unmounted and logged out
utils.TransitionVolListLock.Unlock()

vol.Finalizers = nil
vol.Spec.Volume.StagingTargetPath = ""
Expand All @@ -291,6 +299,8 @@ func (ns *node) NodeUnstageVolume(
logrus.Infof("cstor-csi: volume %s path: %s has been unmounted.",
volumeID, stagingTargetPath)

// It is safe to delete the CStorVolumeAttachment CR now since the volume has already
// been unmounted and logged out
if err := utils.DeleteCStorVolumeAttachmentCR(req.GetVolumeId() + "-" + ns.driver.config.NodeID); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/driver/node_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,9 @@ func (ns *node) prepareVolumeForNode(
if isCVCBound, err := utils.IsCVCBound(volumeID); err != nil {
return status.Error(codes.Internal, err.Error())
} else if !isCVCBound {
utils.TransitionVolListLock.Lock()
utils.TransitionVolList[volumeID] = apis.CStorVolumeAttachmentStatusWaitingForCVCBound
utils.TransitionVolListLock.Unlock()
time.Sleep(10 * time.Second)
return errors.Errorf("Waiting for %s's CVC to be bound", volumeID)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ checkVolumeStatus:
volumeID,
)
} else {
TransitionVolListLock.Lock()
TransitionVolList[volumeID] = apis.CStorVolumeAttachmentStatusWaitingForVolumeToBeReady
TransitionVolListLock.Unlock()
time.Sleep(VolumeWaitTimeout * time.Second)
retries++
goto checkVolumeStatus
Expand Down

0 comments on commit ec7c842

Please sign in to comment.