Skip to content

Commit

Permalink
fix(host-deployer): detach nbd device do not block main thread (#18578)
Browse files Browse the repository at this point in the history
  • Loading branch information
wanyaoqi authored Nov 6, 2023
1 parent f1c71a1 commit e554905
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
4 changes: 3 additions & 1 deletion pkg/hostman/diskutils/nbd/nbdman.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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++
Expand Down
28 changes: 14 additions & 14 deletions pkg/hostman/hostdeployer/deployserver/deployserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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() {}

0 comments on commit e554905

Please sign in to comment.