mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
fix(host-deployer): detach nbd device do not block main thread (#18578)
This commit is contained in:
@@ -49,13 +49,13 @@ func NewNBDManager() (*SNBDManager, error) {
|
||||
ret.nbdDevs = make(map[string]bool, 0)
|
||||
ret.nbdLock = new(sync.Mutex)
|
||||
|
||||
ret.cleanupNbdDevices()
|
||||
if err := ret.reloadNbdDevices(); err != nil {
|
||||
return ret, errors.Wrap(err, "reloadNbdDevices")
|
||||
}
|
||||
if err := ret.findNbdDevices(); err != nil {
|
||||
return ret, errors.Wrap(err, "findNbdDevices")
|
||||
}
|
||||
go ret.cleanupNbdDevices()
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
@@ -120,6 +120,8 @@ func (m *SNBDManager) cleanupNbdDevices() {
|
||||
err := tryDetachNbd(nbddev)
|
||||
if err != nil {
|
||||
log.Errorf("tryDetachNbd fail %s", err)
|
||||
} else {
|
||||
m.ReleaseNbddev(nbddev)
|
||||
}
|
||||
}
|
||||
i++
|
||||
|
||||
@@ -440,6 +440,20 @@ func (s *SDeployService) checkLvmRemote() error {
|
||||
}
|
||||
|
||||
func (s *SDeployService) InitService() {
|
||||
s.SignalTrap(func() {
|
||||
for {
|
||||
if len(connectedEsxiDisks) > 0 {
|
||||
log.Warningf("Waiting for esxi disks %d disconnect !!!", len(connectedEsxiDisks))
|
||||
time.Sleep(time.Second * 1)
|
||||
} else {
|
||||
if s.grpcServer != nil {
|
||||
s.grpcServer.Stop()
|
||||
} else {
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
log.Infof("exec socket path: %s", DeployOption.ExecutorSocketPath)
|
||||
if DeployOption.EnableRemoteExecutor {
|
||||
execlient.Init(DeployOption.ExecutorSocketPath)
|
||||
@@ -462,20 +476,6 @@ func (s *SDeployService) InitService() {
|
||||
if len(DeployOption.DeployServerSocketPath) == 0 {
|
||||
log.Fatalf("missing deploy server socket path")
|
||||
}
|
||||
s.SignalTrap(func() {
|
||||
for {
|
||||
if len(connectedEsxiDisks) > 0 {
|
||||
log.Warningf("Waiting for esxi disks %d disconnect !!!", len(connectedEsxiDisks))
|
||||
time.Sleep(time.Second * 1)
|
||||
} else {
|
||||
if s.grpcServer != nil {
|
||||
s.grpcServer.Stop()
|
||||
} else {
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (s *SDeployService) OnExitService() {}
|
||||
|
||||
Reference in New Issue
Block a user