Implement InitSCSILuMap func for jiva

Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
This commit is contained in:
Utkarsh Mani Tripathi
2019-11-19 10:19:58 +05:30
parent 1b02c7897e
commit d7caf89610
6 changed files with 21 additions and 15 deletions

View File

@@ -397,6 +397,9 @@ type SCSILu struct {
Storage BackingStore
DeviceProtocol SCSIDeviceProtocol
ModeBlockDescriptor []byte
SCSIVendorID string
SCSIProductID string
SCSIID string
PerformCommand CommandFunc
FinishCommand func(*SCSITarget, *SCSICommand)

View File

@@ -166,7 +166,7 @@ func (s *ISCSITargetDriver) Run() error {
s.mu.Lock()
s.l = l
s.mu.Unlock()
log.Infof("iSCSI service listening on: %v", s.listen.Addr())
log.Infof("iSCSI service listening on: %v", s.l.Addr())
for {
conn, err := l.Accept()
if err != nil {

View File

@@ -24,6 +24,10 @@ import (
log "github.com/sirupsen/logrus"
)
var (
Size uint64
)
func init() {
scsi.RegisterBackingStore("RemBs", newRemBs)
}
@@ -33,7 +37,7 @@ type RemBackingStore struct {
scsi.BaseBackingStore
// Remote backing store, remote server exposing
// read and write methods.
RemBs api.RemBackingStore
RemBs api.RemoteBackingStore
}
func newRemBs() (api.BackingStore, error) {
@@ -46,7 +50,11 @@ func newRemBs() (api.BackingStore, error) {
}
func (bs *RemBackingStore) Open(dev *api.SCSILu, path string) error {
bs.DataSize = uint64(dev.Size)
if Size == 0 {
return fmt.Errorf("Size is not initialized")
}
bs.DataSize = Size
bs.RemBs = scsi.GetTargetBSMap(path)
return nil
}
@@ -102,6 +110,6 @@ func (bs *RemBackingStore) DataSync(offset, length int64) (err error) {
}
func (bs *RemBackingStore) Unmap(bd []api.UnmapBlockDescriptor) (err error) {
_, err = bs.RemBs.Unmap()
_, err = bs.RemBs.Unmap(int64(bd[0].Offset), int64(bd[0].TL))
return
}

View File

@@ -231,6 +231,7 @@ const (
const (
SCSIVendorID = "GOSTOR"
SCSIProductID = "GOTGT"
SCSIID = "iqn.2016-09.com.gotgt.gostor:iscsi-tgt"
)
/*

View File

@@ -76,7 +76,7 @@ func (sbc SBCSCSIDeviceProtocol) InitLu(lu *api.SCSILu) error {
leave it with a default target name
*/
lu.Attrs.SCSIID = "iqn.2016-09.com.gotgt.gostor:iscsi-tgt"
lu.Attrs.SCSIID = SCSIID
/*
The PRODUCT SERIAL NUMBER field contains
right-aligned ASCII data (see 4.3.1)

View File

@@ -147,7 +147,7 @@ func InitSCSILUMap(config *config.Config) error {
return nil
}
func InitSCSILUMapEx(tgtName, devpath string, deviceID, lun, size, sectorSize uint64, bs api.RemoteBackingStore) error {
func InitSCSILUMapEx(config *config.BackendStorage, tgtName string, lun uint64, bs api.RemoteBackingStore) error {
globalSCSILUMap.mutex.Lock()
defer globalSCSILUMap.mutex.Unlock()
@@ -156,20 +156,14 @@ func InitSCSILUMapEx(tgtName, devpath string, deviceID, lun, size, sectorSize ui
}
globalSCSILUMap.TargetsBSMap[tgtName] = bs
lu, err := NewSCSILu(&config.BackendStorage{
DeviceID: deviceID,
Path: "RemBs:" + devpath,
Online: true,
},
)
lu, err := NewSCSILu(config)
if err != nil {
return errors.New("Init SCSI LU map error.")
}
globalSCSILUMap.AllDevices[deviceID] = lu
globalSCSILUMap.AllDevices[config.DeviceID] = lu
mappingLUN(LUNMapping{
DeviceID: deviceID,
DeviceID: config.DeviceID,
LUN: lun,
TargetName: tgtName,
},