From 22d47a92123ec3f4516728bbf5619f17e22e860d Mon Sep 17 00:00:00 2001 From: chessman Date: Tue, 21 May 2019 12:54:55 +0300 Subject: [PATCH 1/7] 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 --- pkg/api/types.go | 3 +- pkg/config/config.go | 8 +++-- pkg/scsi/backingstore.go | 6 +++- pkg/scsi/backingstore/cephstore_linux.go | 4 +++ pkg/scsi/backingstore/common.go | 4 +++ pkg/scsi/backingstore/null.go | 4 +++ pkg/scsi/lun.go | 13 +++---- pkg/scsi/sbc.go | 14 ++++++-- pkg/scsi/scsilumap.go | 2 +- pkg/scsi/spc.go | 45 ++++++++++++++++++++++-- 10 files changed, 86 insertions(+), 17 deletions(-) diff --git a/pkg/api/types.go b/pkg/api/types.go index 9b533a0..5cfd965 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -19,7 +19,7 @@ import ( "errors" "sync" - "github.com/satori/go.uuid" + uuid "github.com/satori/go.uuid" ) type SCSICommandType byte @@ -351,6 +351,7 @@ type BackingStore interface { Write([]byte, int64) error DataSync() error DataAdvise(int64, int64, uint32) error + Unmap() error } type SCSIDeviceProtocol interface { diff --git a/pkg/config/config.go b/pkg/config/config.go index 092b81f..8aa95b9 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -101,9 +101,11 @@ var ( ) type BackendStorage struct { - DeviceID uint64 `json:"deviceID"` - Path string `json:"path"` - Online bool `json:"online"` + DeviceID uint64 `json:"deviceID"` + Path string `json:"path"` + Online bool `json:"online"` + Thinprovisioning bool `json:"thinprovisioning"` + BlockShift uint `json:"blockShift"` } type ISCSIPortalInfo struct { diff --git a/pkg/scsi/backingstore.go b/pkg/scsi/backingstore.go index 7cf0315..6dcb541 100644 --- a/pkg/scsi/backingstore.go +++ b/pkg/scsi/backingstore.go @@ -135,7 +135,11 @@ func bsPerformCommand(bs api.BackingStore, cmd *api.SCSICommand) (err error, key doVerify = true goto verify case api.UNMAP: - // TODO + err = bs.Unmap() + if err != nil { + key = MEDIUM_ERROR + asc = NO_ADDITIONAL_SENSE + } default: break } diff --git a/pkg/scsi/backingstore/cephstore_linux.go b/pkg/scsi/backingstore/cephstore_linux.go index 291283a..c77820a 100644 --- a/pkg/scsi/backingstore/cephstore_linux.go +++ b/pkg/scsi/backingstore/cephstore_linux.go @@ -149,3 +149,7 @@ func (bs *CephBackingStore) DataSync() error { func (bs *CephBackingStore) DataAdvise(offset, length int64, advise uint32) error { return nil } + +func (bs *CephBackingStore) Unmap() error { + return nil +} diff --git a/pkg/scsi/backingstore/common.go b/pkg/scsi/backingstore/common.go index 4d78fab..fc35bad 100644 --- a/pkg/scsi/backingstore/common.go +++ b/pkg/scsi/backingstore/common.go @@ -113,3 +113,7 @@ func (bs *FileBackingStore) DataSync() error { func (bs *FileBackingStore) DataAdvise(offset, length int64, advise uint32) error { return util.Fadvise(bs.file, offset, length, advise) } + +func (bs *FileBackingStore) Unmap() error { + return nil +} diff --git a/pkg/scsi/backingstore/null.go b/pkg/scsi/backingstore/null.go index 2cbde02..f718d9a 100644 --- a/pkg/scsi/backingstore/null.go +++ b/pkg/scsi/backingstore/null.go @@ -74,3 +74,7 @@ func (bs *NullBackingStore) DataSync() error { func (bs *NullBackingStore) DataAdvise(offset, length int64, advise uint32) error { return nil } + +func (bs *NullBackingStore) Unmap() error { + return nil +} diff --git a/pkg/scsi/lun.go b/pkg/scsi/lun.go index a7a8afa..790377d 100644 --- a/pkg/scsi/lun.go +++ b/pkg/scsi/lun.go @@ -20,13 +20,13 @@ import ( "strings" "github.com/gostor/gotgt/pkg/api" + "github.com/gostor/gotgt/pkg/config" ) // NewSCSILu: create a new SCSI LU // path format :/absolute/file/path -func NewSCSILu(device_uuid uint64, path string, online bool) (*api.SCSILu, error) { - - pathinfo := strings.SplitN(path, ":", 2) +func NewSCSILu(bs *config.BackendStorage) (*api.SCSILu, error) { + pathinfo := strings.SplitN(bs.Path, ":", 2) if len(pathinfo) < 2 { return nil, errors.New("invalid device path string") } @@ -43,8 +43,8 @@ func NewSCSILu(device_uuid uint64, path string, online bool) (*api.SCSILu, error PerformCommand: luPerformCommand, DeviceProtocol: sbc, Storage: backing, - BlockShift: api.DefaultBlockShift, - UUID: device_uuid, + BlockShift: bs.BlockShift, + UUID: bs.DeviceID, } err = backing.Open(lu, backendPath) @@ -53,7 +53,8 @@ func NewSCSILu(device_uuid uint64, path string, online bool) (*api.SCSILu, error } lu.Size = backing.Size(lu) lu.DeviceProtocol.InitLu(lu) - lu.Attrs.Online = online + lu.Attrs.Thinprovisioning = bs.Thinprovisioning + lu.Attrs.Online = bs.Online lu.Attrs.Lbppbe = 3 return lu, nil } diff --git a/pkg/scsi/sbc.go b/pkg/scsi/sbc.go index ad54aec..36e668e 100644 --- a/pkg/scsi/sbc.go +++ b/pkg/scsi/sbc.go @@ -295,7 +295,13 @@ sense: } func SBCUnmap(host int, cmd *api.SCSICommand) api.SAMStat { - return api.SAMStatGood + err, key, asc := bsPerformCommand(cmd.Device.Storage, cmd) + if err == nil { + return api.SAMStatGood + } + + BuildSenseData(cmd, key, asc) + return api.SAMStatCheckCondition } /* @@ -594,7 +600,11 @@ func SBCReadCapacity16(host int, cmd *api.SCSICommand) api.SAMStat { if allocationLength > 12 { copy(cmd.InSDBBuffer.Buffer[8:], util.MarshalUint32(uint32(1< 16 { - val := (cmd.Device.Attrs.Lbppbe << 16) | cmd.Device.Attrs.LowestAlignedLBA + var lbpme int + if cmd.Device.Attrs.Thinprovisioning { + lbpme = 1 + } + val := (cmd.Device.Attrs.Lbppbe << 16) | (lbpme << 15) | cmd.Device.Attrs.LowestAlignedLBA copy(cmd.InSDBBuffer.Buffer[12:], util.MarshalUint32(uint32(val))) } } diff --git a/pkg/scsi/scsilumap.go b/pkg/scsi/scsilumap.go index 5803507..a968eef 100644 --- a/pkg/scsi/scsilumap.go +++ b/pkg/scsi/scsilumap.go @@ -73,7 +73,7 @@ func InitSCSILUMap(config *config.Config) error { defer globalSCSILUMap.mutex.Unlock() for _, bs := range config.Storages { - lu, err := NewSCSILu(bs.DeviceID, bs.Path, bs.Online) + lu, err := NewSCSILu(&bs) if err != nil { return fmt.Errorf("Init SCSI LU map error: %v", err) } diff --git a/pkg/scsi/spc.go b/pkg/scsi/spc.go index cc1bc7e..41b403c 100644 --- a/pkg/scsi/spc.go +++ b/pkg/scsi/spc.go @@ -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 { From 12b06c21ef56bd591c5dd8a52dcc4d0b121846bf Mon Sep 17 00:00:00 2001 From: chessman Date: Wed, 29 May 2019 16:14:31 +0300 Subject: [PATCH 2/7] UNMAP: propagate request to backing store --- pkg/api/types.go | 7 +++++- pkg/scsi/backingstore.go | 7 +----- pkg/scsi/backingstore/cephstore_linux.go | 2 +- pkg/scsi/backingstore/common.go | 2 +- pkg/scsi/backingstore/null.go | 2 +- pkg/scsi/sbc.go | 30 ++++++++++++++++++++---- 6 files changed, 36 insertions(+), 14 deletions(-) diff --git a/pkg/api/types.go b/pkg/api/types.go index 5cfd965..59576fb 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -351,7 +351,7 @@ type BackingStore interface { Write([]byte, int64) error DataSync() error DataAdvise(int64, int64, uint32) error - Unmap() error + Unmap([]UnmapBlockDescriptor) error } type SCSIDeviceProtocol interface { @@ -401,3 +401,8 @@ type SCSILu struct { } type LUNMap map[uint64]*SCSILu + +type UnmapBlockDescriptor struct { + Offset uint64 + TL uint32 +} diff --git a/pkg/scsi/backingstore.go b/pkg/scsi/backingstore.go index 6dcb541..f5d91b3 100644 --- a/pkg/scsi/backingstore.go +++ b/pkg/scsi/backingstore.go @@ -64,6 +64,7 @@ func bsPerformCommand(bs api.BackingStore, cmd *api.SCSICommand) (err error, key rbuf, wbuf []byte tl int64 = int64(cmd.TL) ) + key = HARDWARE_ERROR asc = ASC_INTERNAL_TGT_FAILURE switch opcode { @@ -134,12 +135,6 @@ func bsPerformCommand(bs api.BackingStore, cmd *api.SCSICommand) (err error, key } doVerify = true goto verify - case api.UNMAP: - err = bs.Unmap() - if err != nil { - key = MEDIUM_ERROR - asc = NO_ADDITIONAL_SENSE - } default: break } diff --git a/pkg/scsi/backingstore/cephstore_linux.go b/pkg/scsi/backingstore/cephstore_linux.go index c77820a..9e99f42 100644 --- a/pkg/scsi/backingstore/cephstore_linux.go +++ b/pkg/scsi/backingstore/cephstore_linux.go @@ -150,6 +150,6 @@ func (bs *CephBackingStore) DataAdvise(offset, length int64, advise uint32) erro return nil } -func (bs *CephBackingStore) Unmap() error { +func (bs *CephBackingStore) Unmap([]api.UnmapBlockDescriptor) error { return nil } diff --git a/pkg/scsi/backingstore/common.go b/pkg/scsi/backingstore/common.go index fc35bad..2a2d4b3 100644 --- a/pkg/scsi/backingstore/common.go +++ b/pkg/scsi/backingstore/common.go @@ -114,6 +114,6 @@ func (bs *FileBackingStore) DataAdvise(offset, length int64, advise uint32) erro return util.Fadvise(bs.file, offset, length, advise) } -func (bs *FileBackingStore) Unmap() error { +func (bs *FileBackingStore) Unmap([]api.UnmapBlockDescriptor) error { return nil } diff --git a/pkg/scsi/backingstore/null.go b/pkg/scsi/backingstore/null.go index f718d9a..8c74739 100644 --- a/pkg/scsi/backingstore/null.go +++ b/pkg/scsi/backingstore/null.go @@ -75,6 +75,6 @@ func (bs *NullBackingStore) DataAdvise(offset, length int64, advise uint32) erro return nil } -func (bs *NullBackingStore) Unmap() error { +func (bs *NullBackingStore) Unmap([]api.UnmapBlockDescriptor) error { return nil } diff --git a/pkg/scsi/sbc.go b/pkg/scsi/sbc.go index 36e668e..87ba500 100644 --- a/pkg/scsi/sbc.go +++ b/pkg/scsi/sbc.go @@ -18,6 +18,7 @@ limitations under the License. package scsi import ( + "encoding/binary" "fmt" "unsafe" @@ -295,13 +296,34 @@ sense: } func SBCUnmap(host int, cmd *api.SCSICommand) api.SAMStat { - err, key, asc := bsPerformCommand(cmd.Device.Storage, cmd) - if err == nil { + // check ANCHOR + if cmd.SCB[1]&0x01 != 0 { + BuildSenseData(cmd, ILLEGAL_REQUEST, ASC_INVALID_FIELD_IN_CDB) + return api.SAMStatCheckCondition + } + + const blockDescLen = 16 + + var blockDescs []api.UnmapBlockDescriptor + for off := 8; uint32(off+blockDescLen) <= cmd.OutSDBBuffer.Length; off += blockDescLen { + lba := binary.BigEndian.Uint64(cmd.OutSDBBuffer.Buffer[off : off+8]) + num := binary.BigEndian.Uint32(cmd.OutSDBBuffer.Buffer[off+8 : off+12]) + blockDescs = append(blockDescs, api.UnmapBlockDescriptor{ + Offset: lba << cmd.Device.BlockShift, + TL: num << cmd.Device.BlockShift, + }) + } + + if len(blockDescs) == 0 { return api.SAMStatGood } - BuildSenseData(cmd, key, asc) - return api.SAMStatCheckCondition + if err := cmd.Device.Storage.Unmap(blockDescs); err != nil { + BuildSenseData(cmd, MEDIUM_ERROR, NO_ADDITIONAL_SENSE) + return api.SAMStatCheckCondition + } + + return api.SAMStatGood } /* From c2184d789f498077c4831b30442b6fd657f56e31 Mon Sep 17 00:00:00 2001 From: chessman Date: Thu, 30 May 2019 17:41:10 +0300 Subject: [PATCH 3/7] add Logical Block Provisioning VPD page (0xB2) --- pkg/scsi/spc.go | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/pkg/scsi/spc.go b/pkg/scsi/spc.go index 41b403c..63e5c24 100644 --- a/pkg/scsi/spc.go +++ b/pkg/scsi/spc.go @@ -59,11 +59,10 @@ func InquiryPage0x00(host int, cmd *api.SCSICommand) (*bytes.Buffer, uint16) { descBuf.WriteByte(0x80) descBuf.WriteByte(0x83) descBuf.WriteByte(0xB0) + descBuf.WriteByte(0xB2) /* TODO: descBuf.WriteByte(0x86) - descBuf.WriteByte(0xB0) - descBuf.WriteByte(0xB2) */ data = descBuf.Bytes() @@ -225,6 +224,44 @@ func InquiryPage0xB0(host int, cmd *api.SCSICommand) (*bytes.Buffer, uint16) { return buf, pageLength } +func InquiryPage0xB2(host int, cmd *api.SCSICommand) (*bytes.Buffer, uint16) { + var ( + buf = &bytes.Buffer{} + pageLength uint16 = 0x4 + ) + + //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(0xB2) + + //PAGE LENGTH + binary.Write(buf, binary.BigEndian, pageLength) + + var lbpu byte + if cmd.Device.Attrs.Thinprovisioning { + lbpu = 1 << 7 + } + + // THRESHOLD EXPONENT + buf.WriteByte(0) + + // LBPU | LBPWS | LBPWS10 | LBPRZ | ANC_SUP | DP + buf.WriteByte(lbpu) + + // MINIMUM PERCENTAGE | PROVISIONING TYPE + buf.WriteByte(0) + + // THRESHOLD PERCENTAGE + buf.WriteByte(0) + + 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. @@ -270,6 +307,8 @@ func SPCInquiry(host int, cmd *api.SCSICommand) api.SAMStat { buf, _ = InquiryPage0x83(host, cmd) case 0xB0: buf, _ = InquiryPage0xB0(host, cmd) + case 0xB2: + buf, _ = InquiryPage0xB2(host, cmd) default: goto sense } From 5132cfdc8c5714911f235c1d959c8e4d35d789ee Mon Sep 17 00:00:00 2001 From: chessman Date: Thu, 30 May 2019 18:00:07 +0300 Subject: [PATCH 4/7] add UNMAP tests to libiscsi --- test/libiscsi-gotgt-test.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/test/libiscsi-gotgt-test.sh b/test/libiscsi-gotgt-test.sh index bb8d8bb..89937af 100755 --- a/test/libiscsi-gotgt-test.sh +++ b/test/libiscsi-gotgt-test.sh @@ -31,6 +31,7 @@ TESTCASES="ALL.Inquiry.Standard\ ALL.WriteSame10.Simple ALL.WriteSame16.Simple \ ALL.Verify10 ALL.Verify12 ALL.Verify16 \ ALL.iSCSITMF ALL.iSCSIcmdsn \ + ALL.Unmap.Simple ALL.Unmap.VPD ALL.Unmap.ZeroBlocks \ " #for i in $NEWCASES From d3ff8c0f6c3250ead6e6595fa8df460a6d2b581e Mon Sep 17 00:00:00 2001 From: chessman Date: Fri, 7 Jun 2019 18:20:38 +0300 Subject: [PATCH 5/7] disable WriteAtomic16 tests because the command is not supported --- test/libiscsi-gotgt-test.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/libiscsi-gotgt-test.sh b/test/libiscsi-gotgt-test.sh index 89937af..5050245 100755 --- a/test/libiscsi-gotgt-test.sh +++ b/test/libiscsi-gotgt-test.sh @@ -25,9 +25,7 @@ TESTCASES="ALL.Inquiry.Standard\ ALL.ReportSupportedOpcodes.Simple ALL.Reserve6.Simple \ ALL.StartStopUnit ALL.TestUnitReady \ ALL.Write10 ALL.Write16 ALL.Write12 ALL.WriteVerify10 \ - ALL.WriteVerify16 ALL.WriteVerify12 ALL.WriteAtomic16.BeyondEol \ - ALL.WriteAtomic16.ZeroBlocks ALL.WriteAtomic16.WriteProtect \ - ALL.WriteAtomic16.DpoFua \ + ALL.WriteVerify16 ALL.WriteVerify12 \ ALL.WriteSame10.Simple ALL.WriteSame16.Simple \ ALL.Verify10 ALL.Verify12 ALL.Verify16 \ ALL.iSCSITMF ALL.iSCSIcmdsn \ From ae74f39fa8918d7e0b1f47dbc395c88bf8eebdd7 Mon Sep 17 00:00:00 2001 From: chessman Date: Fri, 7 Jun 2019 18:28:03 +0300 Subject: [PATCH 6/7] disable WriteAtomic16 on travis as well --- .travis.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5de8acb..7113f64 100644 --- a/.travis.yml +++ b/.travis.yml @@ -74,10 +74,6 @@ script: - ./test-tool/iscsi-test-cu -d -A --test=ALL.WriteVerify10 iscsi://127.0.0.1:3260/${TARGET}/0 - ./test-tool/iscsi-test-cu -d -A --test=ALL.WriteVerify16 iscsi://127.0.0.1:3260/${TARGET}/0 - ./test-tool/iscsi-test-cu -d -A --test=ALL.WriteVerify12 iscsi://127.0.0.1:3260/${TARGET}/0 - - ./test-tool/iscsi-test-cu -d -A --test=ALL.WriteAtomic16.BeyondEol iscsi://127.0.0.1:3260/${TARGET}/0 - - ./test-tool/iscsi-test-cu -d -A --test=ALL.WriteAtomic16.ZeroBlocks iscsi://127.0.0.1:3260/${TARGET}/0 - - ./test-tool/iscsi-test-cu -d -A --test=ALL.WriteAtomic16.WriteProtect iscsi://127.0.0.1:3260/${TARGET}/0 - - ./test-tool/iscsi-test-cu -d -A --test=ALL.WriteAtomic16.DpoFua iscsi://127.0.0.1:3260/${TARGET}/0 - ./test-tool/iscsi-test-cu -d -A --test=ALL.WriteSame10.Simple iscsi://127.0.0.1:3260/${TARGET}/0 - ./test-tool/iscsi-test-cu -d -A --test=ALL.WriteSame16.Simple iscsi://127.0.0.1:3260/${TARGET}/0 - ./test-tool/iscsi-test-cu -d -A --test=ALL.Verify10 iscsi://127.0.0.1:3260/${TARGET}/0 From e2b7ea4891f522847fefc7364bc5d4d3c743dfe4 Mon Sep 17 00:00:00 2001 From: chessman Date: Mon, 10 Jun 2019 12:42:21 +0300 Subject: [PATCH 7/7] rename: Thinprovisioning -> ThinProvisioning --- examples/config.json | 4 +++- pkg/api/types.go | 2 +- pkg/config/config.go | 2 +- pkg/scsi/lun.go | 2 +- pkg/scsi/sbc.go | 6 +++--- pkg/scsi/spc.go | 4 ++-- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/examples/config.json b/examples/config.json index 2143c2b..0e749e7 100644 --- a/examples/config.json +++ b/examples/config.json @@ -3,7 +3,9 @@ { "deviceID":1000, "path":"file:/var/tmp/disk.img", - "online":true + "online":true, + "thinProvisioning":false, + "blockShift": 9, } ], "iscsiportals":[ diff --git a/pkg/api/types.go b/pkg/api/types.go index 59576fb..de303e7 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -264,7 +264,7 @@ type SCSILuPhyAttribute struct { // Software Write Protect SWP bool // Use thin-provisioning for this LUN - Thinprovisioning bool + ThinProvisioning bool // Logical Unit online Online bool // Descrptor format sense data supported diff --git a/pkg/config/config.go b/pkg/config/config.go index 8aa95b9..6fb4a42 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -104,7 +104,7 @@ type BackendStorage struct { DeviceID uint64 `json:"deviceID"` Path string `json:"path"` Online bool `json:"online"` - Thinprovisioning bool `json:"thinprovisioning"` + ThinProvisioning bool `json:"thinProvisioning"` BlockShift uint `json:"blockShift"` } diff --git a/pkg/scsi/lun.go b/pkg/scsi/lun.go index 790377d..244b24a 100644 --- a/pkg/scsi/lun.go +++ b/pkg/scsi/lun.go @@ -53,7 +53,7 @@ func NewSCSILu(bs *config.BackendStorage) (*api.SCSILu, error) { } lu.Size = backing.Size(lu) lu.DeviceProtocol.InitLu(lu) - lu.Attrs.Thinprovisioning = bs.Thinprovisioning + lu.Attrs.ThinProvisioning = bs.ThinProvisioning lu.Attrs.Online = bs.Online lu.Attrs.Lbppbe = 3 return lu, nil diff --git a/pkg/scsi/sbc.go b/pkg/scsi/sbc.go index 87ba500..58a9ba4 100644 --- a/pkg/scsi/sbc.go +++ b/pkg/scsi/sbc.go @@ -59,7 +59,7 @@ func (sbc SBCSCSIDeviceProtocol) InitLu(lu *api.SCSILu) error { // init LU's phy attribute lu.Attrs.DeviceType = sbc.DeviceType lu.Attrs.Qualifier = false - lu.Attrs.Thinprovisioning = false + lu.Attrs.ThinProvisioning = false lu.Attrs.Removable = false lu.Attrs.Readonly = false lu.Attrs.SWP = false @@ -380,7 +380,7 @@ func SBCReadWrite(host int, cmd *api.SCSICommand) api.SAMStat { goto sense } // We only support unmap for thin provisioned LUNS - if (scb[1]&0x08 != 0) && !dev.Attrs.Thinprovisioning { + if (scb[1]&0x08 != 0) && !dev.Attrs.ThinProvisioning { key = ILLEGAL_REQUEST asc = ASC_INVALID_FIELD_IN_CDB goto sense @@ -623,7 +623,7 @@ func SBCReadCapacity16(host int, cmd *api.SCSICommand) api.SAMStat { copy(cmd.InSDBBuffer.Buffer[8:], util.MarshalUint32(uint32(1< 16 { var lbpme int - if cmd.Device.Attrs.Thinprovisioning { + if cmd.Device.Attrs.ThinProvisioning { lbpme = 1 } val := (cmd.Device.Attrs.Lbppbe << 16) | (lbpme << 15) | cmd.Device.Attrs.LowestAlignedLBA diff --git a/pkg/scsi/spc.go b/pkg/scsi/spc.go index 63e5c24..29a2ea0 100644 --- a/pkg/scsi/spc.go +++ b/pkg/scsi/spc.go @@ -196,7 +196,7 @@ func InquiryPage0xB0(host int, cmd *api.SCSICommand) (*bytes.Buffer, uint16) { maxUnmapBlockDescriptorCount uint32 = 0 ) - if cmd.Device.Attrs.Thinprovisioning { + if cmd.Device.Attrs.ThinProvisioning { maxUnmapLbaCount = 0xFFFFFFFF maxUnmapBlockDescriptorCount = 0xFFFFFFFF } @@ -243,7 +243,7 @@ func InquiryPage0xB2(host int, cmd *api.SCSICommand) (*bytes.Buffer, uint16) { binary.Write(buf, binary.BigEndian, pageLength) var lbpu byte - if cmd.Device.Attrs.Thinprovisioning { + if cmd.Device.Attrs.ThinProvisioning { lbpu = 1 << 7 }