Skip to content

Commit

Permalink
Merge pull request #104 from payes/fix-race
Browse files Browse the repository at this point in the history
fix(stats): concurrent map iteration and map write
  • Loading branch information
carmark authored Dec 8, 2020
2 parents f4d57be + e5e3c09 commit 8b433a8
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions pkg/port/iscsit/iscsid.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,13 +653,6 @@ func (s *ISCSITargetDriver) scsiCommandHandler(conn *iscsiConnection) (err error
switch req.OpCode {
case OpSCSICmd:
log.Debugf("SCSI Command processing...")
if s.enableStats {
if _, ok := s.TargetStats.SCSIIOCount[(int)(req.CDB[0])]; ok != false {
s.TargetStats.SCSIIOCount[(int)(req.CDB[0])] += 1
} else {
s.TargetStats.SCSIIOCount[(int)(req.CDB[0])] = 1
}
}
scmd := &api.SCSICommand{
ITNexusID: conn.session.ITNexus.ID,
SCB: req.CDB,
Expand Down Expand Up @@ -931,10 +924,18 @@ func (s *ISCSITargetDriver) iscsiExecTask(task *iscsiTask) error {
}

func (s *ISCSITargetDriver) Stats() scsi.Stats {
return s.TargetStats
s.mu.RLock()
stats := s.TargetStats
stats.SCSIIOCount = map[int]int64{}
for key, value := range s.TargetStats.SCSIIOCount {
stats.SCSIIOCount[key] = value
}
s.mu.RUnlock()
return stats
}

func (s *ISCSITargetDriver) UpdateStats(conn *iscsiConnection) {
s.mu.Lock()
s.TargetStats.IsClientConnected = s.isClientConnected
switch api.SCSICommandType(conn.resp.SCSIOpCode) {
case api.READ_6, api.READ_10, api.READ_12, api.READ_16:
Expand All @@ -948,4 +949,6 @@ func (s *ISCSITargetDriver) UpdateStats(conn *iscsiConnection) {
s.TargetStats.TotalWriteBlockCount += int64(conn.resp.ExpectedDataLen)
break
}
s.TargetStats.SCSIIOCount[(int)(conn.resp.SCSIOpCode)] += 1
s.mu.Unlock()
}

0 comments on commit 8b433a8

Please sign in to comment.