Merge pull request #108 from prateekpandey14/handle-connection-state
fix(state): reset the CurrentHostIP on closed iscsi connection
This commit is contained in:
@@ -47,6 +47,7 @@ const (
|
|||||||
var (
|
var (
|
||||||
EnableStats bool
|
EnableStats bool
|
||||||
CurrentHostIP string
|
CurrentHostIP string
|
||||||
|
IPMutex sync.Mutex
|
||||||
)
|
)
|
||||||
|
|
||||||
type ISCSITargetDriver struct {
|
type ISCSITargetDriver struct {
|
||||||
@@ -219,9 +220,11 @@ func (s *ISCSITargetDriver) Run() error {
|
|||||||
|
|
||||||
remoteIP := strings.Split(conn.RemoteAddr().String(), ":")[0]
|
remoteIP := strings.Split(conn.RemoteAddr().String(), ":")[0]
|
||||||
|
|
||||||
|
IPMutex.Lock()
|
||||||
if CurrentHostIP == "" {
|
if CurrentHostIP == "" {
|
||||||
CurrentHostIP = remoteIP
|
CurrentHostIP = remoteIP
|
||||||
}
|
}
|
||||||
|
IPMutex.Unlock()
|
||||||
|
|
||||||
if s.blockMultipleHostLogin && remoteIP != CurrentHostIP {
|
if s.blockMultipleHostLogin && remoteIP != CurrentHostIP {
|
||||||
conn.Close()
|
conn.Close()
|
||||||
@@ -230,7 +233,7 @@ func (s *ISCSITargetDriver) Run() error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info(conn.LocalAddr().String())
|
log.Info("connection establishing at: ", conn.LocalAddr().String())
|
||||||
s.setClientStatus(true)
|
s.setClientStatus(true)
|
||||||
|
|
||||||
iscsiConn := &iscsiConnection{conn: conn,
|
iscsiConn := &iscsiConnection{conn: conn,
|
||||||
@@ -284,7 +287,19 @@ func (s *ISCSITargetDriver) handler(events byte, conn *iscsiConnection) {
|
|||||||
|
|
||||||
if events&DATAIN != 0 {
|
if events&DATAIN != 0 {
|
||||||
log.Debug("rx handler processing...")
|
log.Debug("rx handler processing...")
|
||||||
go s.rxHandler(conn)
|
go func() {
|
||||||
|
s.rxHandler(conn)
|
||||||
|
if conn.state == CONN_STATE_CLOSE {
|
||||||
|
log.Warningf("iscsi connection[%d] closed", conn.cid)
|
||||||
|
conn.close()
|
||||||
|
IPMutex.Lock()
|
||||||
|
remoteIP := strings.Split(conn.conn.RemoteAddr().String(), ":")[0]
|
||||||
|
if CurrentHostIP == remoteIP {
|
||||||
|
CurrentHostIP = ""
|
||||||
|
}
|
||||||
|
IPMutex.Unlock()
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
if conn.state != CONN_STATE_CLOSE && events&DATAOUT != 0 {
|
if conn.state != CONN_STATE_CLOSE && events&DATAOUT != 0 {
|
||||||
log.Debug("tx handler processing...")
|
log.Debug("tx handler processing...")
|
||||||
@@ -293,7 +308,12 @@ 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 = ""
|
IPMutex.Lock()
|
||||||
|
remoteIP := strings.Split(conn.conn.RemoteAddr().String(), ":")[0]
|
||||||
|
if CurrentHostIP == remoteIP {
|
||||||
|
CurrentHostIP = ""
|
||||||
|
}
|
||||||
|
IPMutex.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,7 +339,8 @@ func (s *ISCSITargetDriver) rxHandler(conn *iscsiConnection) {
|
|||||||
log.Debug("rx handler: IOSTATE_RX_BHS")
|
log.Debug("rx handler: IOSTATE_RX_BHS")
|
||||||
length, err = conn.readData(buf)
|
length, err = conn.readData(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error("read BHS failed:", err)
|
||||||
|
conn.state = CONN_STATE_CLOSE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if length == 0 {
|
if length == 0 {
|
||||||
@@ -363,7 +384,8 @@ func (s *ISCSITargetDriver) rxHandler(conn *iscsiConnection) {
|
|||||||
for length < dl {
|
for length < dl {
|
||||||
l, err := conn.readData(cmd.RawData[length:])
|
l, err := conn.readData(cmd.RawData[length:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error("read data failed:", err)
|
||||||
|
conn.state = CONN_STATE_CLOSE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
length += l
|
length += l
|
||||||
@@ -478,7 +500,12 @@ 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 = ""
|
IPMutex.Lock()
|
||||||
|
remoteIP := strings.Split(conn.conn.RemoteAddr().String(), ":")[0]
|
||||||
|
if CurrentHostIP == remoteIP {
|
||||||
|
CurrentHostIP = ""
|
||||||
|
}
|
||||||
|
IPMutex.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user