Merge pull request #80 from datomia/fix-write-cache

MODE SENSE: ALLOCATION LENGTH shouldn't affect a size in response
This commit is contained in:
Lei Xue
2019-06-03 09:28:16 +08:00
committed by GitHub
2 changed files with 22 additions and 32 deletions

View File

@@ -101,7 +101,7 @@ func (sbc SBCSCSIDeviceProtocol) InitLu(lu *api.SCSILu) error {
// Disconnect page // Disconnect page
pages = append(pages, api.ModePage{2, 0, 14, []byte{0x80, 0x80, 0, 0xa, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}) pages = append(pages, api.ModePage{2, 0, 14, []byte{0x80, 0x80, 0, 0xa, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}})
// Caching Page // Caching Page
pages = append(pages, api.ModePage{8, 0, 18, []byte{0x14, 0, 0xff, 0xff, 0, 0, 0xff, 0xff, 0xff, 0xff, 0x80, 0x14, 0, 0, 0, 0, 0, 0, 0x4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}) pages = append(pages, api.ModePage{8, 0, 18, []byte{0x14, 0, 0xff, 0xff, 0, 0, 0xff, 0xff, 0xff, 0xff, 0x80, 0x14, 0, 0, 0, 0, 0, 0}})
// Control page // Control page
pages = append(pages, api.ModePage{0x0a, 0, 10, []byte{2, 0x10, 0, 0, 0, 0, 0, 0, 2, 0, 0x08, 0, 0, 0, 0, 0, 0, 0}}) pages = append(pages, api.ModePage{0x0a, 0, 10, []byte{2, 0x10, 0, 0, 0, 0, 0, 0, 2, 0, 0x08, 0, 0, 0, 0, 0, 0, 0}})

View File

@@ -476,9 +476,9 @@ func SPCModeSense(host int, cmd *api.SCSICommand) api.SAMStat {
asc = ASC_INVALID_FIELD_IN_CDB asc = ASC_INVALID_FIELD_IN_CDB
data []byte data []byte
allocLen uint32 allocLen uint32
remainLen uint32
i uint32 i uint32
) )
if dbd == 0 { if dbd == 0 {
blkDesctionLen = 8 blkDesctionLen = 8
} }
@@ -499,22 +499,15 @@ func SPCModeSense(host int, cmd *api.SCSICommand) api.SAMStat {
data = append(data, 0x00) data = append(data, 0x00)
} }
} }
remainLen = allocLen - uint32(len(data)) if dbd == 0 {
if dbd == 0 && remainLen >= 8 {
data = append(data, cmd.Device.ModeBlockDescriptor...) data = append(data, cmd.Device.ModeBlockDescriptor...)
} }
if pcode == 0x3f { if pcode == 0x3f {
for _, pg := range cmd.Device.ModePages { for _, pg := range cmd.Device.ModePages {
if pg.SubPageCode == 0 { if pg.SubPageCode == 0 {
if remainLen < 2+uint32(pg.Size) {
break
}
data = append(data, pg.PageCode) data = append(data, pg.PageCode)
data = append(data, pg.Size) data = append(data, pg.Size)
} else { } else {
if remainLen < 4+uint32(pg.Size) {
break
}
data = append(data, pg.PageCode|0x40) data = append(data, pg.PageCode|0x40)
data = append(data, pg.SubPageCode) data = append(data, pg.SubPageCode)
data = append(data, (pg.Size>>8)&0xff) data = append(data, (pg.Size>>8)&0xff)
@@ -537,27 +530,24 @@ func SPCModeSense(host int, cmd *api.SCSICommand) api.SAMStat {
if pg == nil { if pg == nil {
goto sense goto sense
} }
if remainLen >= 2+uint32(pg.Size) { if pg.SubPageCode == 0 {
if pg.SubPageCode == 0 { data = append(data, pg.PageCode)
data = append(data, pg.PageCode) data = append(data, pg.Size)
data = append(data, pg.Size) if pctrl == 1 {
if pctrl == 1 { data = append(data, pg.Data[pg.Size:]...)
data = append(data, pg.Data[pg.Size:]...) } else {
} else { data = append(data, pg.Data[:pg.Size]...)
data = append(data, pg.Data[:pg.Size]...) }
} } else {
} else if remainLen >= 4+uint32(pg.Size) { data = append(data, pg.PageCode|0x40)
data = append(data, pg.PageCode|0x40) data = append(data, pg.SubPageCode)
data = append(data, pg.SubPageCode) data = append(data, (pg.Size>>8)&0xff)
data = append(data, (pg.Size>>8)&0xff) data = append(data, pg.Size&0xff)
data = append(data, pg.Size&0xff) if pctrl == 1 {
if pctrl == 1 { data = append(data, pg.Data[pg.Size:]...)
data = append(data, pg.Data[pg.Size:]...) } else {
} else { data = append(data, pg.Data[:pg.Size]...)
data = append(data, pg.Data[:pg.Size]...)
}
} }
} }
} }
if mode6 { if mode6 {
@@ -569,8 +559,8 @@ func SPCModeSense(host int, cmd *api.SCSICommand) api.SAMStat {
data[6] = uint8(blkDesctionLen >> 8) data[6] = uint8(blkDesctionLen >> 8)
data[7] = uint8(blkDesctionLen) data[7] = uint8(blkDesctionLen)
} }
if rlen := uint32(len(data)); rlen < allocLen { if rlen := uint32(len(data)); rlen > allocLen {
cmd.InSDBBuffer.Resid = rlen cmd.InSDBBuffer.Resid = allocLen
} }
copy(cmd.InSDBBuffer.Buffer, data) copy(cmd.InSDBBuffer.Buffer, data)
return api.SAMStatGood return api.SAMStatGood