return sense data while error
This commit is contained in:
@@ -21,7 +21,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"runtime/debug"
|
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"github.com/gostor/gotgt/pkg/api"
|
"github.com/gostor/gotgt/pkg/api"
|
||||||
@@ -362,14 +361,10 @@ func (s *ISCSITargetService) iscsiExecText(conn *iscsiConnection) error {
|
|||||||
keys := util.ParseKVText(cmd.RawData)
|
keys := util.ParseKVText(cmd.RawData)
|
||||||
if st, ok := keys["SendTargets"]; ok {
|
if st, ok := keys["SendTargets"]; ok {
|
||||||
if st == "All" {
|
if st == "All" {
|
||||||
|
|
||||||
for name, tgt := range s.Targets {
|
for name, tgt := range s.Targets {
|
||||||
glog.V(2).Infof("iscsi target:", name)
|
glog.V(2).Infof("iscsi target: %v", name)
|
||||||
glog.V(2).Infof("iscsi target portals:", tgt.Portals)
|
glog.V(2).Infof("iscsi target portals: %v", tgt.Portals)
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
for name, tgt := range s.Targets {
|
|
||||||
result = append(result, util.KeyValue{"TargetName", name})
|
result = append(result, util.KeyValue{"TargetName", name})
|
||||||
for portal := range tgt.Portals {
|
for portal := range tgt.Portals {
|
||||||
result = append(result, util.KeyValue{"TargetAddress", portal + ",1"})
|
result = append(result, util.KeyValue{"TargetAddress", portal + ",1"})
|
||||||
@@ -476,9 +471,7 @@ func (s *ISCSITargetService) txHandler(conn *iscsiConnection) {
|
|||||||
glog.V(2).Infof("length of RawData is %d", len(conn.resp.RawData))
|
glog.V(2).Infof("length of RawData is %d", len(conn.resp.RawData))
|
||||||
glog.V(2).Infof("length of resp is %d", len(conn.resp.Bytes()))
|
glog.V(2).Infof("length of resp is %d", len(conn.resp.Bytes()))
|
||||||
if l, err := conn.write(conn.resp.Bytes()); err != nil {
|
if l, err := conn.write(conn.resp.Bytes()); err != nil {
|
||||||
debug.PrintStack()
|
|
||||||
glog.Error(err)
|
glog.Error(err)
|
||||||
panic(err)
|
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
conn.txIOState = IOSTATE_TX_INIT_AHS
|
conn.txIOState = IOSTATE_TX_INIT_AHS
|
||||||
@@ -609,6 +602,9 @@ func (s *ISCSITargetService) scsiCommandHandler(conn *iscsiConnection) (err erro
|
|||||||
case api.SCSIDataNone:
|
case api.SCSIDataNone:
|
||||||
resp.OpCode = OpSCSIResp
|
resp.OpCode = OpSCSIResp
|
||||||
}
|
}
|
||||||
|
if scmd.Result != 0 && scmd.SenseBuffer != nil {
|
||||||
|
resp.RawData = scmd.SenseBuffer.Bytes()
|
||||||
|
}
|
||||||
conn.resp = resp
|
conn.resp = resp
|
||||||
}
|
}
|
||||||
case OpSCSITaskReq:
|
case OpSCSITaskReq:
|
||||||
@@ -664,7 +660,7 @@ func (s *ISCSITargetService) scsiCommandHandler(conn *iscsiConnection) (err erro
|
|||||||
TaskTag: req.TaskTag,
|
TaskTag: req.TaskTag,
|
||||||
ExpCmdSN: conn.session.ExpCmdSN,
|
ExpCmdSN: conn.session.ExpCmdSN,
|
||||||
MaxCmdSN: conn.session.ExpCmdSN + 10,
|
MaxCmdSN: conn.session.ExpCmdSN + 10,
|
||||||
Status: 0,
|
Status: task.scmd.Result,
|
||||||
SCSIResponse: 0x00,
|
SCSIResponse: 0x00,
|
||||||
HasStatus: true,
|
HasStatus: true,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2015 The GoStor Authors All rights reserved.
|
Copyright 2016 The GoStor Authors All rights reserved.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -81,10 +81,9 @@ func (s *SCSITargetService) AddCommandQueue(tid int, scmd *api.SCSICommand) erro
|
|||||||
scmd.Device = target.Devices[0]
|
scmd.Device = target.Devices[0]
|
||||||
glog.V(2).Infof("scsi opcode: 0x%x, LUN: %d:", int(scmd.SCB.Bytes()[0]), binary.LittleEndian.Uint64(scmd.Lun[:]))
|
glog.V(2).Infof("scsi opcode: 0x%x, LUN: %d:", int(scmd.SCB.Bytes()[0]), binary.LittleEndian.Uint64(scmd.Lun[:]))
|
||||||
result := scmd.Device.PerformCommand(tid, scmd)
|
result := scmd.Device.PerformCommand(tid, scmd)
|
||||||
scmd.Result = result.Stat
|
if result != api.SAMStatGood {
|
||||||
if result.Err != nil {
|
scmd.Result = result.Stat
|
||||||
glog.Error(result.Err)
|
glog.Warningf("%v", result.Err)
|
||||||
return result.Err
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -114,10 +113,8 @@ func NewSCSIDeviceOperation(fn api.CommandFunc, sa *SCSIServiceAction, pr uint8)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BuildSenseData(cmd *api.SCSICommand, key byte, asc SCSISubError) {
|
func BuildSenseData(cmd *api.SCSICommand, key byte, asc SCSISubError) {
|
||||||
senseBuffer := cmd.SenseBuffer
|
senseBuffer := &bytes.Buffer{}
|
||||||
if senseBuffer == nil {
|
|
||||||
senseBuffer = &bytes.Buffer{}
|
|
||||||
}
|
|
||||||
if cmd.Device.Attrs.SenseFormat {
|
if cmd.Device.Attrs.SenseFormat {
|
||||||
// descriptor format
|
// descriptor format
|
||||||
// current, not deferred
|
// current, not deferred
|
||||||
@@ -144,6 +141,8 @@ func BuildSenseData(cmd *api.SCSICommand, key byte, asc SCSISubError) {
|
|||||||
senseBuffer.WriteByte(byte(asc) & 0xff)
|
senseBuffer.WriteByte(byte(asc) & 0xff)
|
||||||
cmd.SenseLength = length + 8
|
cmd.SenseLength = length + 8
|
||||||
}
|
}
|
||||||
|
cmd.Result = key
|
||||||
|
cmd.SenseBuffer = senseBuffer
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSCSIReadWriteOffset(scb []byte) uint64 {
|
func getSCSIReadWriteOffset(scb []byte) uint64 {
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ func SPCInquiry(host int, cmd *api.SCSICommand) api.SAMStat {
|
|||||||
b = (uint8(0) & 0x7) << 5
|
b = (uint8(0) & 0x7) << 5
|
||||||
b |= uint8(0) & 0x1f
|
b |= uint8(0) & 0x1f
|
||||||
}
|
}
|
||||||
fmt.Println(cmd.Device.Lun, *(*uint64)(unsafe.Pointer(&cmd.Lun)))
|
glog.V(2).Infof("%v, %v", cmd.Device.Lun, *(*uint64)(unsafe.Pointer(&cmd.Lun)))
|
||||||
if cmd.Device.Lun != *(*uint64)(unsafe.Pointer(&cmd.Lun)) {
|
if cmd.Device.Lun != *(*uint64)(unsafe.Pointer(&cmd.Lun)) {
|
||||||
goto sense
|
goto sense
|
||||||
}
|
}
|
||||||
@@ -237,7 +237,7 @@ func SPCReportLuns(host int, cmd *api.SCSICommand) api.SAMStat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for lunumber, lu := range cmd.Target.Devices {
|
for lunumber, lu := range cmd.Target.Devices {
|
||||||
fmt.Println("LUN:", lunumber)
|
glog.V(2).Infof("LUN: ", lunumber)
|
||||||
if remainLength > 0 {
|
if remainLength > 0 {
|
||||||
lun := lu.Lun
|
lun := lu.Lun
|
||||||
if lun > 0xff {
|
if lun > 0xff {
|
||||||
|
|||||||
Reference in New Issue
Block a user