fix: extract clearHostIP helper and restore IP cleanup on close

Restore CurrentHostIP cleanup on connection close (needed for
blockMultipleHostLogin feature). Extract to clearHostIP helper
to reduce duplication.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lei Xue
2026-03-17 14:54:08 +08:00
parent 8ffe5ec5ce
commit be3cad5aba

View File

@@ -359,12 +359,7 @@ func (s *ISCSITargetDriver) handler(events byte, conn *iscsiConnection) {
log.Warningf("iscsi connection[%d] closed", conn.cid)
s.removeConnectionFromSession(conn)
conn.close()
IPMutex.Lock()
remoteIP := strings.Split(conn.conn.RemoteAddr().String(), ":")[0]
if CurrentHostIP == remoteIP {
CurrentHostIP = ""
}
IPMutex.Unlock()
s.clearHostIP(conn)
}
}()
}
@@ -376,15 +371,19 @@ func (s *ISCSITargetDriver) handler(events byte, conn *iscsiConnection) {
log.Warningf("iscsi connection[%d] closed", conn.cid)
s.removeConnectionFromSession(conn)
conn.close()
IPMutex.Lock()
remoteIP := strings.Split(conn.conn.RemoteAddr().String(), ":")[0]
if CurrentHostIP == remoteIP {
CurrentHostIP = ""
}
IPMutex.Unlock()
s.clearHostIP(conn)
}
}
func (s *ISCSITargetDriver) clearHostIP(conn *iscsiConnection) {
IPMutex.Lock()
remoteIP := strings.Split(conn.conn.RemoteAddr().String(), ":")[0]
if CurrentHostIP == remoteIP {
CurrentHostIP = ""
}
IPMutex.Unlock()
}
func (s *ISCSITargetDriver) rxHandler(conn *iscsiConnection) {
var (
hdigest uint = 0