Merge pull request #17 from carmark/sense
return sense data while error
This commit is contained in:
@@ -21,7 +21,6 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/gostor/gotgt/pkg/api"
|
||||
@@ -362,14 +361,10 @@ func (s *ISCSITargetService) iscsiExecText(conn *iscsiConnection) error {
|
||||
keys := util.ParseKVText(cmd.RawData)
|
||||
if st, ok := keys["SendTargets"]; ok {
|
||||
if st == "All" {
|
||||
|
||||
for name, tgt := range s.Targets {
|
||||
glog.V(2).Infof("iscsi target:", name)
|
||||
glog.V(2).Infof("iscsi target portals:", tgt.Portals)
|
||||
glog.V(2).Infof("iscsi target: %v", name)
|
||||
glog.V(2).Infof("iscsi target portals: %v", tgt.Portals)
|
||||
|
||||
}
|
||||
|
||||
for name, tgt := range s.Targets {
|
||||
result = append(result, util.KeyValue{"TargetName", name})
|
||||
for portal := range tgt.Portals {
|
||||
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 resp is %d", len(conn.resp.Bytes()))
|
||||
if l, err := conn.write(conn.resp.Bytes()); err != nil {
|
||||
debug.PrintStack()
|
||||
glog.Error(err)
|
||||
panic(err)
|
||||
return
|
||||
} else {
|
||||
conn.txIOState = IOSTATE_TX_INIT_AHS
|
||||
@@ -609,6 +602,9 @@ func (s *ISCSITargetService) scsiCommandHandler(conn *iscsiConnection) (err erro
|
||||
case api.SCSIDataNone:
|
||||
resp.OpCode = OpSCSIResp
|
||||
}
|
||||
if scmd.Result != 0 && scmd.SenseBuffer != nil {
|
||||
resp.RawData = scmd.SenseBuffer.Bytes()
|
||||
}
|
||||
conn.resp = resp
|
||||
}
|
||||
case OpSCSITaskReq:
|
||||
@@ -664,7 +660,7 @@ func (s *ISCSITargetService) scsiCommandHandler(conn *iscsiConnection) (err erro
|
||||
TaskTag: req.TaskTag,
|
||||
ExpCmdSN: conn.session.ExpCmdSN,
|
||||
MaxCmdSN: conn.session.ExpCmdSN + 10,
|
||||
Status: 0,
|
||||
Status: task.scmd.Result,
|
||||
SCSIResponse: 0x00,
|
||||
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");
|
||||
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]
|
||||
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)
|
||||
scmd.Result = result.Stat
|
||||
if result.Err != nil {
|
||||
glog.Error(result.Err)
|
||||
return result.Err
|
||||
if result != api.SAMStatGood {
|
||||
scmd.Result = result.Stat
|
||||
glog.Warningf("%v", result.Err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -114,10 +113,8 @@ func NewSCSIDeviceOperation(fn api.CommandFunc, sa *SCSIServiceAction, pr uint8)
|
||||
}
|
||||
|
||||
func BuildSenseData(cmd *api.SCSICommand, key byte, asc SCSISubError) {
|
||||
senseBuffer := cmd.SenseBuffer
|
||||
if senseBuffer == nil {
|
||||
senseBuffer = &bytes.Buffer{}
|
||||
}
|
||||
senseBuffer := &bytes.Buffer{}
|
||||
|
||||
if cmd.Device.Attrs.SenseFormat {
|
||||
// descriptor format
|
||||
// current, not deferred
|
||||
@@ -144,6 +141,8 @@ func BuildSenseData(cmd *api.SCSICommand, key byte, asc SCSISubError) {
|
||||
senseBuffer.WriteByte(byte(asc) & 0xff)
|
||||
cmd.SenseLength = length + 8
|
||||
}
|
||||
cmd.Result = key
|
||||
cmd.SenseBuffer = senseBuffer
|
||||
}
|
||||
|
||||
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) & 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)) {
|
||||
goto sense
|
||||
}
|
||||
@@ -237,7 +237,7 @@ func SPCReportLuns(host int, cmd *api.SCSICommand) api.SAMStat {
|
||||
}
|
||||
|
||||
for lunumber, lu := range cmd.Target.Devices {
|
||||
fmt.Println("LUN:", lunumber)
|
||||
glog.V(2).Infof("LUN: ", lunumber)
|
||||
if remainLength > 0 {
|
||||
lun := lu.Lun
|
||||
if lun > 0xff {
|
||||
|
||||
Reference in New Issue
Block a user