diff --git a/pkg/port/iscsit/cmd.go b/pkg/port/iscsit/cmd.go index 8bd293a..7ec3037 100644 --- a/pkg/port/iscsit/cmd.go +++ b/pkg/port/iscsit/cmd.go @@ -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])) diff --git a/pkg/port/iscsit/iscsid.go b/pkg/port/iscsit/iscsid.go index e715c93..599aa7c 100644 --- a/pkg/port/iscsit/iscsid.go +++ b/pkg/port/iscsit/iscsid.go @@ -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 diff --git a/pkg/scsi/lun.go b/pkg/scsi/lun.go index 53396aa..d58c8c4 100644 --- a/pkg/scsi/lun.go +++ b/pkg/scsi/lun.go @@ -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 } diff --git a/pkg/scsi/sbc.go b/pkg/scsi/sbc.go index 30a193c..43f9645 100644 --- a/pkg/scsi/sbc.go +++ b/pkg/scsi/sbc.go @@ -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< 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 {