fix sense data issue
This commit is contained in:
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
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 (
|
||||
@@ -260,8 +276,10 @@ func (m *ISCSICommand) scsiCmdRespBytes() []byte {
|
||||
buf.WriteByte(byte(m.SCSIResponse))
|
||||
buf.WriteByte(byte(m.Status))
|
||||
|
||||
buf.WriteByte(0x00)
|
||||
buf.Write(util.MarshalUint64(uint64(len(m.RawData)))[5:]) // 5-8
|
||||
// Skip through to byte 16
|
||||
for i := 0; i < 3*4; i++ {
|
||||
for i := 0; i < 8; i++ {
|
||||
buf.WriteByte(0x00)
|
||||
}
|
||||
buf.Write(util.MarshalUint64(uint64(m.TaskTag))[4:])
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2016 The GoStor Authors All rights reserved.
|
||||
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.
|
||||
@@ -174,7 +174,10 @@ func (conn *iscsiConnection) buildRespPackage(oc OpCode, task *iscsiTask) error
|
||||
resp.HasStatus = true
|
||||
scmd := task.scmd
|
||||
resp.Status = scmd.Result
|
||||
if scmd.Direction == api.SCSIDataRead || scmd.Direction == api.SCSIDataWrite {
|
||||
if scmd.Result != 0 && scmd.SenseBuffer != nil {
|
||||
length := util.MarshalUint32(uint32(scmd.SenseLength))
|
||||
resp.RawData = append(length[2:4], scmd.SenseBuffer.Bytes()...)
|
||||
} else if scmd.Direction == api.SCSIDataRead || scmd.Direction == api.SCSIDataWrite {
|
||||
if scmd.InSDBBuffer.Buffer != nil {
|
||||
buf := scmd.InSDBBuffer.Buffer.Bytes()
|
||||
resp.RawData = buf
|
||||
@@ -182,9 +185,7 @@ func (conn *iscsiConnection) buildRespPackage(oc OpCode, task *iscsiTask) error
|
||||
resp.RawData = []byte{}
|
||||
}
|
||||
}
|
||||
if scmd.Result != 0 && scmd.SenseBuffer != nil {
|
||||
resp.RawData = scmd.SenseBuffer.Bytes()
|
||||
}
|
||||
|
||||
case OpNoopIn, OpReject:
|
||||
resp.OpCode = oc
|
||||
resp.Final = true
|
||||
|
||||
@@ -549,7 +549,7 @@ func (s *ISCSITargetDriver) scsiCommandHandler(conn *iscsiConnection) (err error
|
||||
if err = s.iscsiTaskQueueHandler(task); err != nil {
|
||||
return
|
||||
} else {
|
||||
if scmd.Direction == api.SCSIDataRead {
|
||||
if scmd.Direction == api.SCSIDataRead && scmd.SenseBuffer == nil {
|
||||
conn.buildRespPackage(OpSCSIIn, task)
|
||||
} else {
|
||||
conn.buildRespPackage(OpSCSIResp, task)
|
||||
@@ -667,7 +667,7 @@ func (s *ISCSITargetDriver) iscsiTaskQueueHandler(task *iscsiTask) error {
|
||||
return err
|
||||
}
|
||||
log.Debugf("add task(%d) into task queue", task.cmd.CmdSN)
|
||||
// add this connection into queue and set this task as pending task
|
||||
// add this task into queue and set it as a pending task
|
||||
sess.PendingTasksMutex.Lock()
|
||||
task.state = taskPending
|
||||
sess.PendingTasks.Push(task)
|
||||
@@ -732,7 +732,11 @@ func (s *ISCSITargetDriver) iscsiExecTask(task *iscsiTask) error {
|
||||
} else {
|
||||
// abort this task
|
||||
log.Debugf("abort the task[%v]", stask.tag)
|
||||
stask.scmd.Result = api.SAM_STAT_TASK_ABORTED
|
||||
if stask.scmd == nil {
|
||||
stask.scmd = &api.SCSICommand{Result: api.SAM_STAT_TASK_ABORTED}
|
||||
}
|
||||
stask.conn = task.conn
|
||||
log.Debugf("stask.conn: %#v", stask.conn)
|
||||
stask.conn.buildRespPackage(OpSCSIResp, stask)
|
||||
stask.conn.rxTask = nil
|
||||
s.handler(DATAOUT, stask.conn)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2016 The GoStor Authors All rights reserved.
|
||||
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.
|
||||
@@ -151,10 +151,9 @@ func BuildSenseData(cmd *api.SCSICommand, key byte, asc SCSISubError) {
|
||||
}
|
||||
senseBuffer.WriteByte((byte(asc) >> 8) & 0xff)
|
||||
senseBuffer.WriteByte(byte(asc) & 0xff)
|
||||
senseBuffer.WriteByte(0x00)
|
||||
senseBuffer.WriteByte(0x00)
|
||||
senseBuffer.WriteByte(0x00)
|
||||
senseBuffer.WriteByte(0x00)
|
||||
for i := 0; i < 4; i++ {
|
||||
senseBuffer.WriteByte(0x00)
|
||||
}
|
||||
cmd.SenseLength = length + 8
|
||||
}
|
||||
if ok {
|
||||
|
||||
Reference in New Issue
Block a user