iSCSI target fixes for iSCSIResiduals tests causing libiscsi test suite to hang

Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
This commit is contained in:
Utkarsh Mani Tripathi
2019-11-18 15:16:41 +05:30
parent f3ef8c973d
commit 1dbc82435f
4 changed files with 30 additions and 1 deletions
+1
View File
@@ -166,6 +166,7 @@ var (
) )
type SCSICommand struct { type SCSICommand struct {
OpCode byte
Target *SCSITarget Target *SCSITarget
DeviceID uint64 DeviceID uint64
Device *SCSILu Device *SCSILu
+15
View File
@@ -20,7 +20,9 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"strings" "strings"
"time"
"github.com/gostor/gotgt/pkg/api"
"github.com/gostor/gotgt/pkg/util" "github.com/gostor/gotgt/pkg/util"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@@ -93,6 +95,7 @@ type ISCSICommand struct {
FinalInSeq bool FinalInSeq bool
Immediate bool Immediate bool
TaskTag uint32 TaskTag uint32
StartTime time.Time
ExpCmdSN, MaxCmdSN uint32 ExpCmdSN, MaxCmdSN uint32
AHSLen int AHSLen int
Resid uint32 Resid uint32
@@ -124,6 +127,7 @@ type ISCSICommand struct {
StatusDetail uint8 StatusDetail uint8
// SCSI commands // SCSI commands
SCSIOpCode byte
ExpectedDataLen uint32 ExpectedDataLen uint32
CDB []byte CDB []byte
Status byte Status byte
@@ -225,6 +229,7 @@ func parseHeader(data []byte) (*ISCSICommand, error) {
m.AHSLen = int(data[4]) * 4 m.AHSLen = int(data[4]) * 4
m.DataLen = int(ParseUint(data[5:8])) m.DataLen = int(ParseUint(data[5:8]))
m.TaskTag = uint32(ParseUint(data[16:20])) m.TaskTag = uint32(ParseUint(data[16:20]))
m.StartTime = time.Now()
switch m.OpCode { switch m.OpCode {
case OpSCSICmd: case OpSCSICmd:
m.LUN = [8]byte{data[9]} m.LUN = [8]byte{data[9]}
@@ -234,6 +239,13 @@ func parseHeader(data []byte) (*ISCSICommand, error) {
m.Write = data[1]&0x20 == 0x20 m.Write = data[1]&0x20 == 0x20
m.CDB = data[32:48] m.CDB = data[32:48]
m.ExpStatSN = uint32(ParseUint(data[28:32])) m.ExpStatSN = uint32(ParseUint(data[28:32]))
SCSIOpcode := api.SCSICommandType(m.SCSIOpCode)
switch SCSIOpcode {
case api.READ_6, api.READ_10, api.READ_12, api.READ_16:
m.Read = true
case api.WRITE_6, api.WRITE_10, api.WRITE_12, api.WRITE_16, api.WRITE_VERIFY, api.WRITE_VERIFY_12, api.WRITE_VERIFY_16:
m.Write = true
}
fallthrough fallthrough
case OpSCSITaskReq: case OpSCSITaskReq:
m.ReferencedTaskTag = uint32(ParseUint(data[20:24])) m.ReferencedTaskTag = uint32(ParseUint(data[20:24]))
@@ -359,6 +371,9 @@ func (m *ISCSICommand) dataInBytes() []byte {
copy(buf[40:], util.MarshalUint32(m.BufferOffset)) copy(buf[40:], util.MarshalUint32(m.BufferOffset))
copy(buf[44:], util.MarshalUint32(m.Resid)) copy(buf[44:], util.MarshalUint32(m.Resid))
copy(buf[48:], m.RawData[m.BufferOffset:m.BufferOffset+uint32(m.DataLen)]) copy(buf[48:], m.RawData[m.BufferOffset:m.BufferOffset+uint32(m.DataLen)])
if m.ExpectedDataLen != 0 {
copy(buf[48:], m.RawData[m.BufferOffset:m.BufferOffset+uint32(m.DataLen)])
}
return buf return buf
} }
+9 -1
View File
@@ -594,6 +594,14 @@ func (s *ISCSITargetDriver) scsiCommandHandler(conn *iscsiConnection) (err error
} }
task := &iscsiTask{conn: conn, cmd: conn.req, tag: conn.req.TaskTag, scmd: scmd} task := &iscsiTask{conn: conn, cmd: conn.req, tag: conn.req.TaskTag, scmd: scmd}
task.scmd.OpCode = conn.req.SCSIOpCode
if scmd.Direction == api.SCSIDataBidirection {
task.scmd.Result = api.SAMStatCheckCondition.Stat
scsi.BuildSenseData(task.scmd, scsi.ILLEGAL_REQUEST, scsi.NO_ADDITIONAL_SENSE)
conn.buildRespPackage(OpSCSIResp, task)
conn.rxTask = nil
break
}
if req.Write { if req.Write {
task.r2tCount = int(req.ExpectedDataLen) - req.DataLen task.r2tCount = int(req.ExpectedDataLen) - req.DataLen
if !req.Final { if !req.Final {
@@ -649,7 +657,7 @@ func (s *ISCSITargetDriver) scsiCommandHandler(conn *iscsiConnection) (err error
} }
return return
} else { } else {
if scmd.Direction == api.SCSIDataRead && scmd.SenseBuffer == nil { if scmd.Direction == api.SCSIDataRead && scmd.SenseBuffer == nil && req.ExpectedDataLen != 0 {
conn.buildRespPackage(OpSCSIIn, task) conn.buildRespPackage(OpSCSIIn, task)
} else { } else {
conn.buildRespPackage(OpSCSIResp, task) conn.buildRespPackage(OpSCSIResp, task)
+5
View File
@@ -126,6 +126,11 @@ func bsPerformCommand(bs api.BackingStore, cmd *api.SCSICommand) (err error, key
} }
cmd.InSDBBuffer.Resid = uint32(length) cmd.InSDBBuffer.Resid = uint32(length)
copy(cmd.InSDBBuffer.Buffer, rbuf) copy(cmd.InSDBBuffer.Buffer, rbuf)
if cmd.InSDBBuffer.Length < uint32(length) {
key = ILLEGAL_REQUEST
asc = ASC_INVALID_FIELD_IN_CDB
goto sense
}
case api.PRE_FETCH_10, api.PRE_FETCH_16: case api.PRE_FETCH_10, api.PRE_FETCH_16:
err = bs.DataAdvise(int64(offset), tl, util.POSIX_FADV_WILLNEED) err = bs.DataAdvise(int64(offset), tl, util.POSIX_FADV_WILLNEED)
if err != nil { if err != nil {