date: 2016-08-30/17:00

This commit is contained in:
Lei Xue
2016-08-30 17:04:11 +08:00
parent 28aa50c59c
commit ca14aab4c2
4 changed files with 62 additions and 9 deletions

View File

@@ -19,6 +19,7 @@ package backingstore
import (
"bytes"
"fmt"
"io"
"os"
"github.com/golang/glog"
@@ -74,7 +75,7 @@ func (bs *FileBackingStore) CommandSubmit(cmd *api.SCSICommand) (err error) {
key = scsi.ILLEGAL_REQUEST
asc = scsi.ASC_INVALID_FIELD_IN_CDB
wbuf []byte = []byte{}
rbuf []byte = []byte{}
rbuf = make([]byte, cmd.TL)
length int
doVerify bool = false
doWrite bool = false
@@ -98,6 +99,9 @@ func (bs *FileBackingStore) CommandSubmit(cmd *api.SCSICommand) (err error) {
doWrite = true
goto write
case api.SYNCHRONIZE_CACHE, api.SYNCHRONIZE_CACHE_16:
if err = util.Fdatasync(lu.File); err != nil {
panic(err)
}
break
case api.WRITE_VERIFY, api.WRITE_VERIFY_12, api.WRITE_VERIFY_16:
doVerify = true
@@ -110,7 +114,7 @@ func (bs *FileBackingStore) CommandSubmit(cmd *api.SCSICommand) (err error) {
break
case api.READ_6, api.READ_10, api.READ_12, api.READ_16:
length, err = lu.File.ReadAt(rbuf, int64(offset))
if err != nil {
if err != nil && err != io.EOF {
key = scsi.MEDIUM_ERROR
asc = scsi.ASC_READ_ERROR
break

View File

@@ -35,13 +35,13 @@ func NewSCSILu(lun uint64, target *api.SCSITarget) (*api.SCSILu, error) {
DeviceProtocol: sbc,
Storage: backing,
BlockShift: 0,
Size: 1024 * 1024 * 1024,
Size: 1024 * 1024 * 10,
}
// hack this
if _, err = os.Stat("/tmp/data.txt"); err != nil && os.IsExist(err) {
os.Create("/tmp/data.txt")
if _, err = os.Stat("/var/tmp/disk.img"); err != nil && os.IsExist(err) {
panic(err)
}
f, err := backing.Open(lu, "/tmp/data.txt")
f, err := backing.Open(lu, "/var/tmp/disk.img")
if err != nil {
return nil, err
}