This commit is contained in:
Lei Xue
2017-07-09 09:33:34 +08:00
parent 8ce8ade3d4
commit eeb30723c8
8 changed files with 60 additions and 35 deletions
+1
View File
@@ -43,6 +43,7 @@ script:
- ./test-tool/iscsi-test-cu -d -A --test=ALL.Inquiry.MandatoryVPDSBC iscsi://127.0.0.1:3260/${TARGET}/0 - ./test-tool/iscsi-test-cu -d -A --test=ALL.Inquiry.MandatoryVPDSBC iscsi://127.0.0.1:3260/${TARGET}/0
- ./test-tool/iscsi-test-cu -d -A --test=ALL.Inquiry.SupportedVPD iscsi://127.0.0.1:3260/${TARGET}/0 - ./test-tool/iscsi-test-cu -d -A --test=ALL.Inquiry.SupportedVPD iscsi://127.0.0.1:3260/${TARGET}/0
- ./test-tool/iscsi-test-cu -d -A --test=ALL.Inquiry.VersionDescriptors iscsi://127.0.0.1:3260/${TARGET}/0 - ./test-tool/iscsi-test-cu -d -A --test=ALL.Inquiry.VersionDescriptors iscsi://127.0.0.1:3260/${TARGET}/0
- ./test-tool/iscsi-test-cu -d -A --test=ALL.Inquiry.EVPD iscsi://127.0.0.1:3260/${TARGET}/0
- ./test-tool/iscsi-test-cu -d -A --test=ALL.Mandatory iscsi://127.0.0.1:3260/${TARGET}/0 - ./test-tool/iscsi-test-cu -d -A --test=ALL.Mandatory iscsi://127.0.0.1:3260/${TARGET}/0
- ./test-tool/iscsi-test-cu -d -A --test=ALL.ModeSense6 iscsi://127.0.0.1:3260/${TARGET}/0 - ./test-tool/iscsi-test-cu -d -A --test=ALL.ModeSense6 iscsi://127.0.0.1:3260/${TARGET}/0
- ./test-tool/iscsi-test-cu -d -A --test=ALL.NoMedia iscsi://127.0.0.1:3260/${TARGET}/0 - ./test-tool/iscsi-test-cu -d -A --test=ALL.NoMedia iscsi://127.0.0.1:3260/${TARGET}/0
+13 -3
View File
@@ -21,6 +21,7 @@ import (
"fmt" "fmt"
"strings" "strings"
log "github.com/Sirupsen/logrus"
"github.com/gostor/gotgt/pkg/util" "github.com/gostor/gotgt/pkg/util"
) )
@@ -186,7 +187,7 @@ func (m *ISCSICommand) String() string {
s = append(s, fmt.Sprintf("Next Stage = %v", m.NSG)) s = append(s, fmt.Sprintf("Next Stage = %v", m.NSG))
s = append(s, fmt.Sprintf("Status Class = %d", m.StatusClass)) s = append(s, fmt.Sprintf("Status Class = %d", m.StatusClass))
s = append(s, fmt.Sprintf("Status Detail = %d", m.StatusDetail)) s = append(s, fmt.Sprintf("Status Detail = %d", m.StatusDetail))
case OpSCSICmd, OpSCSIOut: case OpSCSICmd, OpSCSIOut, OpSCSIIn:
s = append(s, fmt.Sprintf("LUN = %d", m.LUN)) s = append(s, fmt.Sprintf("LUN = %d", m.LUN))
s = append(s, fmt.Sprintf("ExpectedDataLen = %d", m.ExpectedDataLen)) s = append(s, fmt.Sprintf("ExpectedDataLen = %d", m.ExpectedDataLen))
s = append(s, fmt.Sprintf("CmdSN = %d", m.CmdSN)) s = append(s, fmt.Sprintf("CmdSN = %d", m.CmdSN))
@@ -281,7 +282,11 @@ func (m *ISCSICommand) scsiCmdRespBytes() []byte {
buf.WriteByte(byte(OpSCSIResp)) buf.WriteByte(byte(OpSCSIResp))
var flag byte = 0x80 var flag byte = 0x80
if m.Resid > 0 { if m.Resid > 0 {
flag |= 0x02 if m.Resid > m.ExpectedDataLen {
flag |= 0x04
} else {
flag |= 0x02
}
} }
buf.WriteByte(flag) buf.WriteByte(flag)
buf.WriteByte(byte(m.SCSIResponse)) buf.WriteByte(byte(m.SCSIResponse))
@@ -325,8 +330,13 @@ func (m *ISCSICommand) dataInBytes() []byte {
if m.HasStatus && m.Final == true { if m.HasStatus && m.Final == true {
flag |= 0x01 flag |= 0x01
} }
log.Debugf("resid: %v, ExpectedDataLen: %v", m.Resid, m.ExpectedDataLen)
if m.Resid > 0 { if m.Resid > 0 {
flag |= 0x02 if m.Resid > m.ExpectedDataLen {
flag |= 0x04
} else {
flag |= 0x02
}
} }
buf.WriteByte(flag) buf.WriteByte(flag)
buf.WriteByte(0x00) buf.WriteByte(0x00)
+5 -4
View File
@@ -155,10 +155,11 @@ func (conn *iscsiConnection) buildRespPackage(oc OpCode, task *iscsiTask) error
task = conn.rxTask task = conn.rxTask
} }
resp := &ISCSICommand{ resp := &ISCSICommand{
StatSN: conn.req.ExpStatSN, StatSN: conn.req.ExpStatSN,
TaskTag: conn.req.TaskTag, TaskTag: conn.req.TaskTag,
ExpCmdSN: conn.session.ExpCmdSN, ExpCmdSN: conn.session.ExpCmdSN,
MaxCmdSN: conn.session.ExpCmdSN + conn.session.MaxQueueCommand, MaxCmdSN: conn.session.ExpCmdSN + conn.session.MaxQueueCommand,
ExpectedDataLen: conn.req.ExpectedDataLen,
} }
switch oc { switch oc {
case OpReady: case OpReady:
+2 -5
View File
@@ -313,8 +313,7 @@ func (s *ISCSITargetDriver) rxHandler(conn *iscsiConnection) {
default: default:
iscsiExecReject(conn) iscsiExecReject(conn)
} }
log.Debugf("connection state is %v", conn.state) log.Debugf("connection state is %v", conn.State())
log.Debugf("%#v", conn.resp.String())
s.handler(DATAOUT, conn) s.handler(DATAOUT, conn)
} }
} }
@@ -476,9 +475,7 @@ SendRemainingData:
switch conn.txIOState { switch conn.txIOState {
case IOSTATE_TX_BHS: case IOSTATE_TX_BHS:
log.Debug("ready to write response") log.Debug("ready to write response")
log.Debugf("%s", resp.String()) log.Debugf("response is %s", resp.String())
log.Debugf("length of RawData is %d", len(resp.RawData))
log.Debugf("length of resp is %d", len(resp.Bytes()))
if l, err := conn.write(resp.Bytes()); err != nil { if l, err := conn.write(resp.Bytes()); err != nil {
log.Error(err) log.Error(err)
return return
+16 -1
View File
@@ -1,10 +1,25 @@
/*
Copyright 2017 The GoStor Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package iscsit package iscsit
import ( import (
"bytes" "bytes"
"fmt" "fmt"
// log "github.com/Sirupsen/logrus"
"github.com/gostor/gotgt/pkg/util" "github.com/gostor/gotgt/pkg/util"
) )
+3
View File
@@ -20,6 +20,7 @@ package scsi
import ( import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"fmt"
"unsafe" "unsafe"
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
@@ -67,6 +68,8 @@ func (sbc SBCSCSIDeviceProtocol) InitLu(lu *api.SCSILu) error {
lu.Attrs.VendorID = SCSIVendorID lu.Attrs.VendorID = SCSIVendorID
lu.Attrs.ProductID = SCSIProductID lu.Attrs.ProductID = SCSIProductID
lu.Attrs.ProductRev = version.SCSIVersion lu.Attrs.ProductRev = version.SCSIVersion
lu.Attrs.SCSIID = fmt.Sprintf("gotgt-scsi-%d%d", 0, lu.UUID)
lu.Attrs.SCSISN = fmt.Sprintf("gotgt-beaf-%d%d", 0, lu.UUID)
/* /*
SCSIID for PAGE83 T10 VENDOR IDENTIFICATION field SCSIID for PAGE83 T10 VENDOR IDENTIFICATION field
+1
View File
@@ -158,6 +158,7 @@ func BuildSenseData(cmd *api.SCSICommand, key byte, asc SCSISubError) {
} }
if ok { if ok {
if int64(len(senseBuffer.Bytes())) > inBufLen { if int64(len(senseBuffer.Bytes())) > inBufLen {
log.Warnf("sense buffer is bigger than in buffer")
senseBuffer.Truncate(int(inBufLen)) senseBuffer.Truncate(int(inBufLen))
} }
} else { } else {
+19 -22
View File
@@ -86,31 +86,23 @@ func InquiryPage0x00(host int, cmd *api.SCSICommand) (*bytes.Buffer, uint16) {
func InquiryPage0x80(host int, cmd *api.SCSICommand) (*bytes.Buffer, uint16) { func InquiryPage0x80(host int, cmd *api.SCSICommand) (*bytes.Buffer, uint16) {
var ( var (
buf = &bytes.Buffer{} buf = &bytes.Buffer{}
descBuf = &bytes.Buffer{} pageLength uint16 = 36
data []byte = []byte{} scsisn = make([]byte, pageLength)
pageLength uint16 = 0
) )
descBuf.WriteByte(0x20)
descBuf.WriteByte(0x20)
descBuf.WriteByte(0x20)
descBuf.WriteByte(0x20)
data = descBuf.Bytes()
pageLength = uint16(len(data))
//byte 0 //byte 0
if cmd.Device.Attrs.Online { if cmd.Device.Attrs.Online {
buf.WriteByte(PQ_DEVICE_CONNECTED | byte(cmd.Device.Attrs.DeviceType)) buf.WriteByte(PQ_DEVICE_CONNECTED | byte(cmd.Device.Attrs.DeviceType))
} else { } else {
buf.WriteByte(PQ_DEVICE_NOT_CONNECT | byte(cmd.Device.Attrs.DeviceType)) buf.WriteByte(PQ_DEVICE_NOT_CONNECT | byte(cmd.Device.Attrs.DeviceType))
} }
//byte 1 //byte 1: PAGE CODE
//PAGE CODE
buf.WriteByte(0x80) buf.WriteByte(0x80)
//PAGE LENGTH //byte 2-3: PAGE LENGTH
binary.Write(buf, binary.BigEndian, pageLength) buf.WriteByte(uint8(pageLength >> 8))
buf.Write(data) buf.WriteByte(uint8(pageLength & 0xff))
copy(scsisn, []byte(fmt.Sprintf("gotgt-%-36v", cmd.Device.UUID)))
buf.Write(scsisn)
return buf, pageLength return buf, pageLength
} }
@@ -206,7 +198,6 @@ func InquiryPage0x83(host int, cmd *api.SCSICommand) (*bytes.Buffer, uint16) {
func SPCInquiry(host int, cmd *api.SCSICommand) api.SAMStat { func SPCInquiry(host int, cmd *api.SCSICommand) api.SAMStat {
var ( var (
allocationLength uint16 allocationLength uint16
pageLength uint16
additionLength byte additionLength byte
buf = &bytes.Buffer{} buf = &bytes.Buffer{}
data []byte = []byte{} data []byte = []byte{}
@@ -235,24 +226,28 @@ func SPCInquiry(host int, cmd *api.SCSICommand) api.SAMStat {
if evpd { if evpd {
switch pcode { switch pcode {
case 0x00: case 0x00:
buf, pageLength = InquiryPage0x00(host, cmd) buf, _ = InquiryPage0x00(host, cmd)
case 0x80: case 0x80:
buf, pageLength = InquiryPage0x80(host, cmd) buf, _ = InquiryPage0x80(host, cmd)
case 0x83: case 0x83:
buf, pageLength = InquiryPage0x83(host, cmd) buf, _ = InquiryPage0x83(host, cmd)
default: default:
goto sense goto sense
} }
data = buf.Bytes() data = buf.Bytes()
if allocationLength < pageLength { if int(allocationLength) < len(data) {
cmd.InSDBBuffer.Buffer = bytes.NewBuffer(data[0:allocationLength]) cmd.InSDBBuffer.Buffer = bytes.NewBuffer(data[0:allocationLength])
cmd.InSDBBuffer.Resid = uint32(len(data))
} else { } else {
cmd.InSDBBuffer.Buffer = bytes.NewBuffer(data[0:]) cmd.InSDBBuffer.Buffer = bytes.NewBuffer(data[0:])
} }
} else { } else {
if pcode != 0 {
goto sense
}
//byte 5 //byte 5
//SCCS(0) AAC(0) TPGS(0) 3PC(0) PROTECT(0) //SCCS(0) AAC(0) TPGS(0) 3PC(0) PROTECT(0)
addBuf.WriteByte(INQUIRY_TPGS_IMPLICIT) addBuf.WriteByte(INQUIRY_TPGS_IMPLICIT)
@@ -576,7 +571,9 @@ func SPCModeSense(host int, cmd *api.SCSICommand) api.SAMStat {
data[6] = uint8(blkDesctionLen >> 8) data[6] = uint8(blkDesctionLen >> 8)
data[7] = uint8(blkDesctionLen) data[7] = uint8(blkDesctionLen)
} }
cmd.InSDBBuffer.Resid = uint32(len(data)) if rlen := uint32(len(data)); rlen < allocLen {
cmd.InSDBBuffer.Resid = rlen
}
cmd.InSDBBuffer.Buffer = bytes.NewBuffer(data) cmd.InSDBBuffer.Buffer = bytes.NewBuffer(data)
return api.SAMStatGood return api.SAMStatGood
sense: sense: