Add flag to disable login on multiple hosts

Signed-off-by: shubham <shubham.bajpai@mayadata.io>
This commit is contained in:
shubham
2021-06-29 21:15:54 +05:30
parent 8b433a89c6
commit b278ab3133
2 changed files with 37 additions and 14 deletions

View File

@@ -21,6 +21,7 @@ import (
"net"
"os"
"strconv"
"strings"
"sync"
"time"
@@ -44,23 +45,25 @@ const (
)
var (
EnableStats bool
EnableStats bool
CurrentHostIP string
)
type ISCSITargetDriver struct {
SCSI *scsi.SCSITargetService
Name string
iSCSITargets map[string]*ISCSITarget
TSIHPool map[uint16]bool
TSIHPoolMutex sync.Mutex
isClientConnected bool
enableStats bool
mu *sync.RWMutex
l net.Listener
state uint8
OpCode int
TargetStats scsi.Stats
clusterIP string
SCSI *scsi.SCSITargetService
Name string
iSCSITargets map[string]*ISCSITarget
TSIHPool map[uint16]bool
TSIHPoolMutex sync.Mutex
isClientConnected bool
enableStats bool
mu *sync.RWMutex
l net.Listener
state uint8
OpCode int
TargetStats scsi.Stats
clusterIP string
blockMultipleHostLogin bool
}
func init() {
@@ -133,6 +136,10 @@ func (s *ISCSITargetDriver) SetClusterIP(ip string) {
s.clusterIP = ip
}
func (s *ISCSITargetDriver) EnableBlockMultipleHostLogin() {
s.blockMultipleHostLogin = true
}
func (s *ISCSITargetDriver) RereadTargetLUNMap() {
s.SCSI.RereadTargetLUNMap()
}
@@ -210,6 +217,19 @@ func (s *ISCSITargetDriver) Run() error {
continue
}
remoteIP := strings.Split(conn.RemoteAddr().String(), ":")[0]
if CurrentHostIP == "" {
CurrentHostIP = remoteIP
}
if s.blockMultipleHostLogin && remoteIP != CurrentHostIP {
conn.Close()
log.Infof("rejecting connection: %s target already connected at %s",
remoteIP, CurrentHostIP)
continue
}
log.Info(conn.LocalAddr().String())
s.setClientStatus(true)
@@ -273,6 +293,7 @@ func (s *ISCSITargetDriver) handler(events byte, conn *iscsiConnection) {
if conn.state == CONN_STATE_CLOSE {
log.Warningf("iscsi connection[%d] closed", conn.cid)
conn.close()
CurrentHostIP = ""
}
}
@@ -457,6 +478,7 @@ func iscsiExecLogout(conn *iscsiConnection) error {
conn.resp.ExpCmdSN = conn.session.ExpCmdSN
conn.resp.MaxCmdSN = conn.session.ExpCmdSN + conn.session.MaxQueueCommand
}
CurrentHostIP = ""
return nil
}

View File

@@ -31,6 +31,7 @@ type SCSITargetDriver interface {
Resize(uint64) error
Stats() Stats
SetClusterIP(string)
EnableBlockMultipleHostLogin()
}
type Stats struct {