From d7caf89610a28d4bf3efcd69cb9c4d833ea98111 Mon Sep 17 00:00:00 2001 From: Utkarsh Mani Tripathi Date: Tue, 19 Nov 2019 10:19:58 +0530 Subject: [PATCH] Implement InitSCSILuMap func for jiva Signed-off-by: Utkarsh Mani Tripathi --- pkg/api/types.go | 3 +++ pkg/port/iscsit/iscsid.go | 2 +- pkg/scsi/backingstore/remote/remote.go | 14 +++++++++++--- pkg/scsi/cmd.go | 1 + pkg/scsi/sbc.go | 2 +- pkg/scsi/scsilumap.go | 14 ++++---------- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/pkg/api/types.go b/pkg/api/types.go index a638277..4daca00 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -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) diff --git a/pkg/port/iscsit/iscsid.go b/pkg/port/iscsit/iscsid.go index dc2863c..cfb7818 100644 --- a/pkg/port/iscsit/iscsid.go +++ b/pkg/port/iscsit/iscsid.go @@ -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 { diff --git a/pkg/scsi/backingstore/remote/remote.go b/pkg/scsi/backingstore/remote/remote.go index 71f15cc..2dcfbf8 100644 --- a/pkg/scsi/backingstore/remote/remote.go +++ b/pkg/scsi/backingstore/remote/remote.go @@ -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 } diff --git a/pkg/scsi/cmd.go b/pkg/scsi/cmd.go index 1ad4d4c..8b3cf7d 100644 --- a/pkg/scsi/cmd.go +++ b/pkg/scsi/cmd.go @@ -231,6 +231,7 @@ const ( const ( SCSIVendorID = "GOSTOR" SCSIProductID = "GOTGT" + SCSIID = "iqn.2016-09.com.gotgt.gostor:iscsi-tgt" ) /* diff --git a/pkg/scsi/sbc.go b/pkg/scsi/sbc.go index 13dc242..ee1e333 100644 --- a/pkg/scsi/sbc.go +++ b/pkg/scsi/sbc.go @@ -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) diff --git a/pkg/scsi/scsilumap.go b/pkg/scsi/scsilumap.go index ac5bb27..396138b 100644 --- a/pkg/scsi/scsilumap.go +++ b/pkg/scsi/scsilumap.go @@ -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, },