add iscsi target driver closer

This commit is contained in:
chessman
2019-06-27 18:15:30 +03:00
parent f11001ec71
commit 93a6cf0c31
2 changed files with 23 additions and 1 deletions

View File

@@ -42,6 +42,9 @@ type ISCSITargetDriver struct {
iSCSITargets map[string]*ISCSITarget
TSIHPool map[uint16]bool
TSIHPoolMutex sync.Mutex
mu sync.Mutex
l net.Listener
}
func init() {
@@ -160,11 +163,20 @@ func (s *ISCSITargetDriver) Run() error {
log.Error(err)
os.Exit(1)
}
s.mu.Lock()
s.l = l
s.mu.Unlock()
for {
log.Info("Listening ...")
conn, err := l.Accept()
if err != nil {
if err, ok := err.(net.Error); ok {
if !err.Temporary() {
log.Info("Closing ...")
break
}
}
log.Error(err)
continue
}
@@ -181,7 +193,16 @@ func (s *ISCSITargetDriver) Run() error {
// start a new thread to do with this command
go s.handler(DATAIN, iscsiConn)
}
l.Close()
return nil
}
func (s *ISCSITargetDriver) Close() error {
s.mu.Lock()
l := s.l
s.mu.Unlock()
if l != nil {
return l.Close()
}
return nil
}

View File

@@ -27,6 +27,7 @@ type SCSITargetDriver interface {
Run() error
NewTarget(string, *config.Config) error
RereadTargetLUNMap()
Close() error
}
type TargetDriverFunc func(*SCSITargetService) (SCSITargetDriver, error)