improve logs and add client (initiator) status
Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
This commit is contained in:
+19
-10
@@ -36,11 +36,12 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
l net.Listener
|
l net.Listener
|
||||||
@@ -165,9 +166,8 @@ func (s *ISCSITargetDriver) Run() error {
|
|||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
s.l = l
|
s.l = l
|
||||||
s.mu.Unlock()
|
s.mu.Unlock()
|
||||||
|
log.Infof("iSCSI service listening on: %v", s.listen.Addr())
|
||||||
for {
|
for {
|
||||||
log.Info("Listening ...")
|
|
||||||
conn, err := l.Accept()
|
conn, err := l.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err, ok := err.(net.Error); ok {
|
if err, ok := err.(net.Error); ok {
|
||||||
@@ -180,24 +180,30 @@ func (s *ISCSITargetDriver) Run() error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Info(conn.LocalAddr().String())
|
log.Info(conn.LocalAddr().String())
|
||||||
log.Info("Accepting ...")
|
|
||||||
|
|
||||||
iscsiConn := &iscsiConnection{conn: conn,
|
iscsiConn := &iscsiConnection{conn: conn,
|
||||||
loginParam: &iscsiLoginParam{}}
|
loginParam: &iscsiLoginParam{}}
|
||||||
|
|
||||||
iscsiConn.init()
|
iscsiConn.init()
|
||||||
iscsiConn.rxIOState = IOSTATE_RX_BHS
|
iscsiConn.rxIOState = IOSTATE_RX_BHS
|
||||||
|
log.Infof("Target is connected to initiator: %s", conn.RemoteAddr().String())
|
||||||
log.Infof("connection is connected from %s...\n", conn.RemoteAddr().String())
|
|
||||||
// start a new thread to do with this command
|
// start a new thread to do with this command
|
||||||
go s.handler(DATAIN, iscsiConn)
|
go s.handler(DATAIN, iscsiConn)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ISCSITargetDriver) setClientStatus(ok bool) {
|
||||||
|
s.isClientConnected = ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ISCSITargetDriver) isInitiatorConnected() bool {
|
||||||
|
return s.isClientConnected
|
||||||
|
}
|
||||||
func (s *ISCSITargetDriver) Close() error {
|
func (s *ISCSITargetDriver) Close() error {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
l := s.l
|
l := s.l
|
||||||
|
s.setClientStatus(false)
|
||||||
s.mu.Unlock()
|
s.mu.Unlock()
|
||||||
if l != nil {
|
if l != nil {
|
||||||
return l.Close()
|
return l.Close()
|
||||||
@@ -324,6 +330,7 @@ func (s *ISCSITargetDriver) rxHandler(conn *iscsiConnection) {
|
|||||||
}
|
}
|
||||||
case OpLogoutReq:
|
case OpLogoutReq:
|
||||||
log.Debug("OpLogoutReq")
|
log.Debug("OpLogoutReq")
|
||||||
|
s.setClientStatus(false)
|
||||||
if err := iscsiExecLogout(conn); err != nil {
|
if err := iscsiExecLogout(conn); err != nil {
|
||||||
log.Warningf("set connection to close")
|
log.Warningf("set connection to close")
|
||||||
conn.state = CONN_STATE_CLOSE
|
conn.state = CONN_STATE_CLOSE
|
||||||
@@ -386,6 +393,7 @@ func (s *ISCSITargetDriver) iscsiExecLogin(conn *iscsiConnection) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func iscsiExecLogout(conn *iscsiConnection) error {
|
func iscsiExecLogout(conn *iscsiConnection) error {
|
||||||
|
log.Infof("Logout request received from initiator: %v", conn.conn.RemoteAddr().String())
|
||||||
cmd := conn.req
|
cmd := conn.req
|
||||||
conn.resp = &ISCSICommand{
|
conn.resp = &ISCSICommand{
|
||||||
OpCode: OpLogoutResp,
|
OpCode: OpLogoutResp,
|
||||||
@@ -718,6 +726,7 @@ func (s *ISCSITargetDriver) scsiCommandHandler(conn *iscsiConnection) (err error
|
|||||||
case OpNoopOut:
|
case OpNoopOut:
|
||||||
iscsiExecNoopOut(conn)
|
iscsiExecNoopOut(conn)
|
||||||
case OpLogoutReq:
|
case OpLogoutReq:
|
||||||
|
s.setClientStatus(false)
|
||||||
conn.txTask = &iscsiTask{conn: conn, cmd: conn.req, tag: conn.req.TaskTag}
|
conn.txTask = &iscsiTask{conn: conn, cmd: conn.req, tag: conn.req.TaskTag}
|
||||||
conn.txIOState = IOSTATE_TX_BHS
|
conn.txIOState = IOSTATE_TX_BHS
|
||||||
iscsiExecLogout(conn)
|
iscsiExecLogout(conn)
|
||||||
|
|||||||
@@ -392,8 +392,8 @@ func (s *ISCSITargetDriver) BindISCSISession(conn *iscsiConnection) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if newSess.SessionType == SESSION_NORMAL {
|
if newSess.SessionType == SESSION_NORMAL {
|
||||||
log.Infof("New Session initiator name:%v,target name:%v,ISID:0x%x",
|
log.Infof("Login request received from initiator: %v, Session type: %s, Target name:%v, ISID: 0x%x",
|
||||||
conn.loginParam.initiator, conn.loginParam.target, conn.loginParam.isid)
|
conn.loginParam.initiator, "Normal", conn.loginParam.target, conn.loginParam.isid)
|
||||||
//register normal session
|
//register normal session
|
||||||
itnexus := &api.ITNexus{uuid.NewV1(), GeniSCSIITNexusID(newSess)}
|
itnexus := &api.ITNexus{uuid.NewV1(), GeniSCSIITNexusID(newSess)}
|
||||||
scsi.AddITNexus(&newSess.Target.SCSITarget, itnexus)
|
scsi.AddITNexus(&newSess.Target.SCSITarget, itnexus)
|
||||||
@@ -404,6 +404,8 @@ func (s *ISCSITargetDriver) BindISCSISession(conn *iscsiConnection) error {
|
|||||||
newSess.Target.Sessions[newSess.TSIH] = newSess
|
newSess.Target.Sessions[newSess.TSIH] = newSess
|
||||||
newSess.Target.SessionsRWMutex.Unlock()
|
newSess.Target.SessionsRWMutex.Unlock()
|
||||||
} else {
|
} else {
|
||||||
|
log.Infof("Discovery request received from initiator: %v, Session type: %s, ISID: 0x%x",
|
||||||
|
conn.loginParam.initiator, "Discovery", conn.loginParam.isid)
|
||||||
conn.session = newSess
|
conn.session = newSess
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+1
-1
@@ -717,7 +717,7 @@ func reportOpcodesAll(cmd *api.SCSICommand, rctd int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func reportOpcodeOne(cmd *api.SCSICommand, rctd int, opcode byte, rsa uint16, serviceAction bool) error {
|
func reportOpcodeOne(cmd *api.SCSICommand, rctd int, opcode byte, rsa uint16, serviceAction bool) error {
|
||||||
return fmt.Errorf("non support")
|
return fmt.Errorf("rsa: %xh, sa:%v not supported", rsa, serviceAction)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SPCReportSupportedOperationCodes(host int, cmd *api.SCSICommand) api.SAMStat {
|
func SPCReportSupportedOperationCodes(host int, cmd *api.SCSICommand) api.SAMStat {
|
||||||
|
|||||||
Reference in New Issue
Block a user