support iscsi task function

This commit is contained in:
Lei Xue
2017-06-12 21:06:57 +08:00
parent 8ca6860460
commit 7a2b08ff80
9 changed files with 206 additions and 40 deletions
+16 -3
View File
@@ -56,6 +56,12 @@ var opCodeMap = map[OpCode]string{
const DataPadding = 4
type ISCSITaskManagementFunc struct {
Result byte
TaskFunc uint32
ReferencedTaskTag uint32
}
type ISCSICommand struct {
OpCode OpCode
RawHeader []byte
@@ -99,6 +105,9 @@ type ISCSICommand struct {
Status byte
SCSIResponse byte
// Task request
ISCSITaskManagementFunc
// R2T
R2TSN uint32
DesiredLength uint32
@@ -187,13 +196,13 @@ func parseHeader(data []byte) (*ISCSICommand, error) {
// TODO: sync.Pool
m := &ISCSICommand{}
m.Immediate = 0x40&data[0] == 0x40
m.OpCode = OpCode(data[0] & 0x3f)
m.OpCode = OpCode(data[0] & ISCSI_OPCODE_MASK)
m.Final = 0x80&data[1] == 0x80
m.AHSLen = int(data[4]) * 4
m.DataLen = int(ParseUint(data[5:8]))
m.TaskTag = uint32(ParseUint(data[16:20]))
switch m.OpCode {
case OpSCSICmd, OpSCSITaskReq:
case OpSCSICmd:
m.LUN = [8]byte{data[9]}
m.ExpectedDataLen = uint32(ParseUint(data[20:24]))
m.CmdSN = uint32(ParseUint(data[24:28]))
@@ -201,6 +210,10 @@ func parseHeader(data []byte) (*ISCSICommand, error) {
m.Write = data[1]&0x20 == 0x20
m.CDB = data[32:48]
m.ExpStatSN = uint32(ParseUint(data[28:32]))
fallthrough
case OpSCSITaskReq:
m.ReferencedTaskTag = uint32(ParseUint(data[20:24]))
m.TaskFunc = uint32(data[1] & ISCSI_FLAG_TM_FUNC_MASK)
case OpSCSIResp:
case OpSCSIOut:
m.LUN = [8]byte{data[9]}
@@ -399,7 +412,7 @@ func (m *ISCSICommand) scsiTMFRespBytes() []byte {
buf := &bytes.Buffer{}
buf.WriteByte(byte(OpSCSITaskResp))
buf.WriteByte(0x80)
buf.WriteByte(0x00)
buf.WriteByte(m.Result)
buf.WriteByte(0x00)
// Skip through to byte 16