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

View File

@@ -21,6 +21,7 @@ import (
"fmt"
"strings"
log "github.com/Sirupsen/logrus"
"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("Status Class = %d", m.StatusClass))
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("ExpectedDataLen = %d", m.ExpectedDataLen))
s = append(s, fmt.Sprintf("CmdSN = %d", m.CmdSN))
@@ -281,7 +282,11 @@ func (m *ISCSICommand) scsiCmdRespBytes() []byte {
buf.WriteByte(byte(OpSCSIResp))
var flag byte = 0x80
if m.Resid > 0 {
flag |= 0x02
if m.Resid > m.ExpectedDataLen {
flag |= 0x04
} else {
flag |= 0x02
}
}
buf.WriteByte(flag)
buf.WriteByte(byte(m.SCSIResponse))
@@ -325,8 +330,13 @@ func (m *ISCSICommand) dataInBytes() []byte {
if m.HasStatus && m.Final == true {
flag |= 0x01
}
log.Debugf("resid: %v, ExpectedDataLen: %v", m.Resid, m.ExpectedDataLen)
if m.Resid > 0 {
flag |= 0x02
if m.Resid > m.ExpectedDataLen {
flag |= 0x04
} else {
flag |= 0x02
}
}
buf.WriteByte(flag)
buf.WriteByte(0x00)

View File

@@ -155,10 +155,11 @@ func (conn *iscsiConnection) buildRespPackage(oc OpCode, task *iscsiTask) error
task = conn.rxTask
}
resp := &ISCSICommand{
StatSN: conn.req.ExpStatSN,
TaskTag: conn.req.TaskTag,
ExpCmdSN: conn.session.ExpCmdSN,
MaxCmdSN: conn.session.ExpCmdSN + conn.session.MaxQueueCommand,
StatSN: conn.req.ExpStatSN,
TaskTag: conn.req.TaskTag,
ExpCmdSN: conn.session.ExpCmdSN,
MaxCmdSN: conn.session.ExpCmdSN + conn.session.MaxQueueCommand,
ExpectedDataLen: conn.req.ExpectedDataLen,
}
switch oc {
case OpReady:

View File

@@ -313,8 +313,7 @@ func (s *ISCSITargetDriver) rxHandler(conn *iscsiConnection) {
default:
iscsiExecReject(conn)
}
log.Debugf("connection state is %v", conn.state)
log.Debugf("%#v", conn.resp.String())
log.Debugf("connection state is %v", conn.State())
s.handler(DATAOUT, conn)
}
}
@@ -476,9 +475,7 @@ SendRemainingData:
switch conn.txIOState {
case IOSTATE_TX_BHS:
log.Debug("ready to write response")
log.Debugf("%s", resp.String())
log.Debugf("length of RawData is %d", len(resp.RawData))
log.Debugf("length of resp is %d", len(resp.Bytes()))
log.Debugf("response is %s", resp.String())
if l, err := conn.write(resp.Bytes()); err != nil {
log.Error(err)
return

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
import (
"bytes"
"fmt"
// log "github.com/Sirupsen/logrus"
"github.com/gostor/gotgt/pkg/util"
)