enable UNMAP when LUN is thin provisioned

- support Block Limits VPD page (0xB0)
 - add UNMAP to REPORT SUPPORTED OPERATION CODES
 - READ CAPACITY(16): set LBPME when Thin provisioning is enabled
 - move Thinprovisioning and BlockShift to config
 - add Unmap to BackingStore
This commit is contained in:
chessman
2019-05-21 12:54:55 +03:00
parent e2192b7b01
commit 22d47a9212
10 changed files with 86 additions and 17 deletions
+42 -3
View File
@@ -25,7 +25,7 @@ import (
log "github.com/Sirupsen/logrus"
"github.com/gostor/gotgt/pkg/api"
"github.com/gostor/gotgt/pkg/util"
"github.com/satori/go.uuid"
uuid "github.com/satori/go.uuid"
)
func SPCIllegalOp(host int, cmd *api.SCSICommand) api.SAMStat {
@@ -58,6 +58,7 @@ func InquiryPage0x00(host int, cmd *api.SCSICommand) (*bytes.Buffer, uint16) {
descBuf.WriteByte(0x00)
descBuf.WriteByte(0x80)
descBuf.WriteByte(0x83)
descBuf.WriteByte(0xB0)
/*
TODO:
descBuf.WriteByte(0x86)
@@ -188,6 +189,42 @@ func InquiryPage0x83(host int, cmd *api.SCSICommand) (*bytes.Buffer, uint16) {
return buf, pageLength
}
func InquiryPage0xB0(host int, cmd *api.SCSICommand) (*bytes.Buffer, uint16) {
var (
buf = &bytes.Buffer{}
pageLength uint16 = 0x3C
maxUnmapLbaCount uint32 = 0
maxUnmapBlockDescriptorCount uint32 = 0
)
if cmd.Device.Attrs.Thinprovisioning {
maxUnmapLbaCount = 0xFFFFFFFF
maxUnmapBlockDescriptorCount = 0xFFFFFFFF
}
//byte 0
if cmd.Device.Attrs.Online {
buf.WriteByte(PQ_DEVICE_CONNECTED | byte(cmd.Device.Attrs.DeviceType))
} else {
buf.WriteByte(PQ_DEVICE_NOT_CONNECT | byte(cmd.Device.Attrs.DeviceType))
}
//PAGE CODE
buf.WriteByte(0xB0)
//PAGE LENGTH
binary.Write(buf, binary.BigEndian, pageLength)
buf.Write(make([]byte, 16))
//MAXIMUM UNMAP LBA COUNT
binary.Write(buf, binary.BigEndian, maxUnmapLbaCount)
//MAXIMUM UNMAP BLOCK DESCRIPTOR COUNT
binary.Write(buf, binary.BigEndian, maxUnmapBlockDescriptorCount)
buf.Write(make([]byte, 36))
return buf, pageLength
}
/*
* SPCInquiry Implements SCSI INQUIRY command
* The INQUIRY command requests the device server to return information regarding the logical unit and SCSI target device.
@@ -231,6 +268,8 @@ func SPCInquiry(host int, cmd *api.SCSICommand) api.SAMStat {
buf, _ = InquiryPage0x80(host, cmd)
case 0x83:
buf, _ = InquiryPage0x83(host, cmd)
case 0xB0:
buf, _ = InquiryPage0xB0(host, cmd)
default:
goto sense
}
@@ -610,7 +649,7 @@ func reportOpcodesAll(cmd *api.SCSICommand, rctd int) error {
var (
data = []byte{0x00, 0x00, 0x00, 0x00}
)
for _, i := range []api.SCSICommandType{api.TEST_UNIT_READY, api.WRITE_6, api.INQUIRY, api.READ_CAPACITY, api.WRITE_10, api.WRITE_16, api.REPORT_LUNS, api.WRITE_12} {
for _, i := range []api.SCSICommandType{api.TEST_UNIT_READY, api.WRITE_6, api.INQUIRY, api.READ_CAPACITY, api.WRITE_10, api.WRITE_16, api.REPORT_LUNS, api.WRITE_12, api.UNMAP} {
data = append(data, byte(i))
// reserved
data = append(data, 0x00)
@@ -627,7 +666,7 @@ func reportOpcodesAll(cmd *api.SCSICommand, rctd int) error {
}
// cdb length
length := getSCSICmdSize(i)
data = append(data, (length>>8)&0xff)
data = append(data, 0)
data = append(data, length&0xff)
// timeout descriptor
if rctd != 0 {