Add flag to disable login on multiple hosts
Signed-off-by: shubham <shubham.bajpai@mayadata.io>
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -44,23 +45,25 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
EnableStats bool
|
EnableStats bool
|
||||||
|
CurrentHostIP string
|
||||||
)
|
)
|
||||||
|
|
||||||
type ISCSITargetDriver struct {
|
type ISCSITargetDriver struct {
|
||||||
SCSI *scsi.SCSITargetService
|
SCSI *scsi.SCSITargetService
|
||||||
Name string
|
Name string
|
||||||
iSCSITargets map[string]*ISCSITarget
|
iSCSITargets map[string]*ISCSITarget
|
||||||
TSIHPool map[uint16]bool
|
TSIHPool map[uint16]bool
|
||||||
TSIHPoolMutex sync.Mutex
|
TSIHPoolMutex sync.Mutex
|
||||||
isClientConnected bool
|
isClientConnected bool
|
||||||
enableStats bool
|
enableStats bool
|
||||||
mu *sync.RWMutex
|
mu *sync.RWMutex
|
||||||
l net.Listener
|
l net.Listener
|
||||||
state uint8
|
state uint8
|
||||||
OpCode int
|
OpCode int
|
||||||
TargetStats scsi.Stats
|
TargetStats scsi.Stats
|
||||||
clusterIP string
|
clusterIP string
|
||||||
|
blockMultipleHostLogin bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -133,6 +136,10 @@ func (s *ISCSITargetDriver) SetClusterIP(ip string) {
|
|||||||
s.clusterIP = ip
|
s.clusterIP = ip
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ISCSITargetDriver) EnableBlockMultipleHostLogin() {
|
||||||
|
s.blockMultipleHostLogin = true
|
||||||
|
}
|
||||||
|
|
||||||
func (s *ISCSITargetDriver) RereadTargetLUNMap() {
|
func (s *ISCSITargetDriver) RereadTargetLUNMap() {
|
||||||
s.SCSI.RereadTargetLUNMap()
|
s.SCSI.RereadTargetLUNMap()
|
||||||
}
|
}
|
||||||
@@ -210,6 +217,19 @@ func (s *ISCSITargetDriver) Run() error {
|
|||||||
continue
|
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())
|
log.Info(conn.LocalAddr().String())
|
||||||
s.setClientStatus(true)
|
s.setClientStatus(true)
|
||||||
|
|
||||||
@@ -273,6 +293,7 @@ func (s *ISCSITargetDriver) handler(events byte, conn *iscsiConnection) {
|
|||||||
if conn.state == CONN_STATE_CLOSE {
|
if conn.state == CONN_STATE_CLOSE {
|
||||||
log.Warningf("iscsi connection[%d] closed", conn.cid)
|
log.Warningf("iscsi connection[%d] closed", conn.cid)
|
||||||
conn.close()
|
conn.close()
|
||||||
|
CurrentHostIP = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -457,6 +478,7 @@ func iscsiExecLogout(conn *iscsiConnection) error {
|
|||||||
conn.resp.ExpCmdSN = conn.session.ExpCmdSN
|
conn.resp.ExpCmdSN = conn.session.ExpCmdSN
|
||||||
conn.resp.MaxCmdSN = conn.session.ExpCmdSN + conn.session.MaxQueueCommand
|
conn.resp.MaxCmdSN = conn.session.ExpCmdSN + conn.session.MaxQueueCommand
|
||||||
}
|
}
|
||||||
|
CurrentHostIP = ""
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ type SCSITargetDriver interface {
|
|||||||
Resize(uint64) error
|
Resize(uint64) error
|
||||||
Stats() Stats
|
Stats() Stats
|
||||||
SetClusterIP(string)
|
SetClusterIP(string)
|
||||||
|
EnableBlockMultipleHostLogin()
|
||||||
}
|
}
|
||||||
|
|
||||||
type Stats struct {
|
type Stats struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user