fix several bugs during read/write operations
This commit is contained in:
@@ -185,7 +185,7 @@ func parseHeader(data []byte) (*ISCSICommand, error) {
|
||||
m.TaskTag = uint32(ParseUint(data[16:20]))
|
||||
switch m.OpCode {
|
||||
case OpSCSICmd, OpSCSITaskReq:
|
||||
m.LUN = [8]uint8{data[9]}
|
||||
m.LUN = [8]byte{data[9]}
|
||||
m.ExpectedDataLen = uint32(ParseUint(data[20:24]))
|
||||
m.CmdSN = uint32(ParseUint(data[24:28]))
|
||||
m.Read = data[1]&0x40 == 0x40
|
||||
@@ -194,7 +194,7 @@ func parseHeader(data []byte) (*ISCSICommand, error) {
|
||||
m.ExpStatSN = uint32(ParseUint(data[28:32]))
|
||||
case OpSCSIResp:
|
||||
case OpSCSIOut:
|
||||
m.LUN = [8]uint8{data[9]}
|
||||
m.LUN = [8]byte{data[9]}
|
||||
m.ExpStatSN = uint32(ParseUint(data[28:32]))
|
||||
m.DataSN = uint32(ParseUint(data[36:40]))
|
||||
m.BufferOffset = uint32(ParseUint(data[40:44]))
|
||||
|
||||
@@ -243,6 +243,17 @@ func (s *ISCSITargetService) iscsiExecLogin(conn *iscsiConnection) error {
|
||||
RawData: util.MarshalKVText([]util.KeyValue{
|
||||
{"HeaderDigest", "None"},
|
||||
{"DataDigest", "None"},
|
||||
{"ImmediateData", "Yes"},
|
||||
{"InitialR2T", "Yes"},
|
||||
{"MaxBurstLength", "262144"},
|
||||
{"FirstBurstLength", "65536"},
|
||||
{"DefaultTime2Wait", "2"},
|
||||
{"DefaultTime2Retain", "0"},
|
||||
{"MaxOutstandingR2T", "1"},
|
||||
{"IFMarker", "No"},
|
||||
{"OFMarker", "No"},
|
||||
{"DataPDUInOrder", "Yes"},
|
||||
{"DataSequenceInOrder", "Yes"},
|
||||
}),
|
||||
}
|
||||
pairs := util.ParseKVText(cmd.RawData)
|
||||
@@ -332,7 +343,7 @@ func (s *ISCSITargetService) iscsiExecText(conn *iscsiConnection) error {
|
||||
}
|
||||
for _, t := range list {
|
||||
result = append(result, util.KeyValue{"TargetName", t.Name})
|
||||
result = append(result, util.KeyValue{"TargetAddress", "172.16.69.169:3260,1"})
|
||||
result = append(result, util.KeyValue{"TargetAddress", "172.16.69.1:3260,1"})
|
||||
//result = append(result, util.KeyValue{"TargetAddress", "127.0.0.1:3260,1"})
|
||||
}
|
||||
}
|
||||
@@ -495,6 +506,7 @@ func (s *ISCSITargetService) scsiCommandHandler(conn *iscsiConnection) (err erro
|
||||
}
|
||||
task.scmd.OutSDBBuffer.Buffer.Write(conn.req.RawData)
|
||||
if task.r2tCount > 0 {
|
||||
conn.session.ExpCmdSN += 1
|
||||
// prepare to receive more data
|
||||
task.state = taskPending
|
||||
conn.session.PendingTasks.Push(task)
|
||||
@@ -703,6 +715,7 @@ func (s *ISCSITargetService) iscsiTaskQueueHandler(task *iscsiTask) error {
|
||||
// add this connection into queue and set this task as pending task
|
||||
task.state = taskPending
|
||||
sess.PendingTasks.Push(task)
|
||||
return fmt.Errorf("pending")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -48,6 +48,7 @@ func NewSCSILu(lun uint64, target *api.SCSITarget) (*api.SCSILu, error) {
|
||||
lu.File = f
|
||||
lu.DeviceProtocol.InitLu(lu)
|
||||
lu.Attrs.Online = true
|
||||
lu.Attrs.Lbppbe = 3
|
||||
return lu, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -477,11 +477,17 @@ sense:
|
||||
}
|
||||
|
||||
func SBCReadCapacity16(host int, cmd *api.SCSICommand) api.SAMStat {
|
||||
data := &bytes.Buffer{}
|
||||
data.Write(util.MarshalUint64(1))
|
||||
data.Write(util.MarshalUint32(1 << cmd.Device.BlockShift))
|
||||
var (
|
||||
data = &bytes.Buffer{}
|
||||
bshift = cmd.Device.BlockShift
|
||||
size = cmd.Device.Size >> bshift
|
||||
)
|
||||
data.Write(util.MarshalUint64(uint64(size - 1)))
|
||||
binary.Write(data, binary.BigEndian, uint32(1<<bshift))
|
||||
val := (cmd.Device.Attrs.Lbppbe << 16) | cmd.Device.Attrs.LowestAlignedLBA
|
||||
data.Write(util.MarshalUint32(uint32(val)))
|
||||
binary.Write(data, binary.BigEndian, uint64(0))
|
||||
binary.Write(data, binary.BigEndian, uint64(0))
|
||||
cmd.InSDBBuffer.Buffer = data
|
||||
return api.SAMStatGood
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"unsafe"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/gostor/gotgt/pkg/api"
|
||||
@@ -130,40 +131,84 @@ func SPCLuOnline(lu *api.SCSILu) error {
|
||||
}
|
||||
|
||||
func SPCInquiry(host int, cmd *api.SCSICommand) api.SAMStat {
|
||||
buf := &bytes.Buffer{}
|
||||
var b byte = 0x75
|
||||
var (
|
||||
buf = &bytes.Buffer{}
|
||||
data []byte = []byte{}
|
||||
b byte = 0x75
|
||||
scb []byte = cmd.SCB.Bytes()
|
||||
pcode byte = scb[2]
|
||||
evpd bool = false
|
||||
)
|
||||
if scb[1]&0x01 > 0 {
|
||||
evpd = true
|
||||
}
|
||||
if reflect.DeepEqual(util.MarshalUint64(cmd.Device.Lun)[0:7], cmd.Lun[0:7]) {
|
||||
b = (uint8(0) & 0x7) << 5
|
||||
b |= uint8(0) & 0x1f
|
||||
}
|
||||
buf.WriteByte(b)
|
||||
b = 0
|
||||
buf.WriteByte(b)
|
||||
buf.WriteByte(byte(1))
|
||||
b = 0x02
|
||||
buf.WriteByte(b)
|
||||
buf.WriteByte(0x00)
|
||||
// byte 5
|
||||
b = 0
|
||||
b |= byte(1) << 4 & 0x30
|
||||
buf.WriteByte(b)
|
||||
// byte 6
|
||||
b = 0
|
||||
buf.WriteByte(b)
|
||||
buf.WriteByte(0x02)
|
||||
buf.Write([]byte{'1', '1', 'c', 'a', 'n', 's'})
|
||||
buf.WriteByte(0x00)
|
||||
buf.WriteByte(0x00)
|
||||
buf.Write([]byte{'c', 'o', 'f', 'f', 'e', 'e'})
|
||||
for i := 0; i < 10; i++ {
|
||||
if cmd.Device.Lun != *(*uint64)(unsafe.Pointer(&cmd.Lun)) {
|
||||
goto sense
|
||||
}
|
||||
if evpd {
|
||||
if pcode == 0x0 {
|
||||
buf.WriteByte(b)
|
||||
b = 0
|
||||
buf.WriteByte(b)
|
||||
buf.WriteByte(b)
|
||||
buf.WriteByte(b)
|
||||
buf.WriteByte(b)
|
||||
buf.WriteByte(b)
|
||||
} else if pcode == 0xb0 {
|
||||
buf.WriteByte(b)
|
||||
buf.WriteByte(0xb0)
|
||||
buf.WriteByte(0x00)
|
||||
buf.WriteByte(0x3c)
|
||||
buf.WriteByte(0x00)
|
||||
buf.WriteByte(0x80)
|
||||
|
||||
for i := 0; i < 58; i++ {
|
||||
buf.WriteByte(0x00)
|
||||
}
|
||||
} else {
|
||||
buf.WriteByte(b)
|
||||
buf.WriteByte(0xb0)
|
||||
buf.WriteByte(0x00)
|
||||
buf.WriteByte(0x00)
|
||||
buf.WriteByte(0x00)
|
||||
}
|
||||
} else {
|
||||
buf.WriteByte(b)
|
||||
b = 0
|
||||
buf.WriteByte(b)
|
||||
buf.WriteByte(byte(1))
|
||||
b = 0x02
|
||||
buf.WriteByte(b)
|
||||
buf.WriteByte(0x00)
|
||||
// byte 5
|
||||
b = 0
|
||||
b |= byte(1) << 4 & 0x30
|
||||
buf.WriteByte(b)
|
||||
// byte 6
|
||||
b = 0
|
||||
buf.WriteByte(b)
|
||||
buf.WriteByte(0x02)
|
||||
buf.Write([]byte{'1', '1', 'c', 'a', 'n', 's'})
|
||||
buf.WriteByte(0x00)
|
||||
buf.WriteByte(0x00)
|
||||
buf.Write([]byte{'c', 'o', 'f', 'f', 'e', 'e'})
|
||||
for i := 0; i < 10; i++ {
|
||||
buf.WriteByte(0x00)
|
||||
}
|
||||
buf.Write([]byte{'1', '.', '0'})
|
||||
buf.WriteByte(0x00)
|
||||
}
|
||||
buf.Write([]byte{'1', '.', '0'})
|
||||
buf.WriteByte(0x00)
|
||||
data := buf.Bytes()
|
||||
data = buf.Bytes()
|
||||
data[4] = byte(len(data) - 4)
|
||||
cmd.InSDBBuffer.Buffer = bytes.NewBuffer(data)
|
||||
return api.SAMStatGood
|
||||
sense:
|
||||
BuildSenseData(cmd, ILLEGAL_REQUEST, ASC_INVALID_FIELD_IN_CDB)
|
||||
return api.SAMStatCheckCondition
|
||||
}
|
||||
|
||||
func SPCReportLuns(host int, cmd *api.SCSICommand) api.SAMStat {
|
||||
|
||||
Reference in New Issue
Block a user