Automated cherry pick of #21039: fix(region,host,host-deployer): deploy guest ssh port add lock (#21040)

* fix(host): check nodes count on alloc cpuset

* fix(host-deployer): get ssh port add lock

* feat(region): guest clone add prefer host
This commit is contained in:
wanyaoqi
2024-08-16 09:56:37 +08:00
committed by GitHub
parent 71f559cf9d
commit 1dfd41697b
4 changed files with 22 additions and 0 deletions
+4
View File
@@ -1029,6 +1029,10 @@ type ServerSnapshotAndCloneInput struct {
// ignore
InstanceSnapshotId string `json:"instance_snapshot_id"`
// Perfer clone destination host
// 指定期望的迁移目标宿主机
PreferHostId string `json:"prefer_host_id"`
}
type ServerInstanceSnapshot struct {
+10
View File
@@ -5351,6 +5351,16 @@ func (self *SGuest) PerformSnapshotAndClone(
return nil, httperrors.NewInputParameterError("count must > 0")
}
}
if len(input.PreferHostId) > 0 {
if len(input.PreferHostId) > 0 {
iHost, _ := HostManager.FetchByIdOrName(ctx, userCred, input.PreferHostId)
if iHost == nil {
return nil, httperrors.NewBadRequestError("Host %s not found", input.PreferHostId)
}
host := iHost.(*SHost)
input.PreferHostId = host.Id
}
}
lockman.LockRawObject(ctx, InstanceSnapshotManager.Keyword(), "name")
defer lockman.ReleaseRawObject(ctx, InstanceSnapshotManager.Keyword(), "name")
+4
View File
@@ -66,6 +66,7 @@ type QemuDeployManager struct {
hugepage bool
hugepageSizeKB int
portsInUse *sync.Map
sshPortLock *sync.Mutex
lastUsedSshPort int
qemuCmd string
memSizeMb int
@@ -152,6 +153,8 @@ func (m *QemuDeployManager) unsetPort(port int) {
}
func (m *QemuDeployManager) GetSshFreePort() int {
m.sshPortLock.Lock()
defer m.sshPortLock.Unlock()
port := m.GetFreePortByBase(BASE_SSH_PORT + m.lastUsedSshPort)
m.lastUsedSshPort = port - BASE_SSH_PORT
if m.lastUsedSshPort >= 2000 {
@@ -230,6 +233,7 @@ func InitQemuDeployManager(
hugepageSizeKB: hugepageSizeKB,
memSizeMb: memSizeMb,
portsInUse: new(sync.Map),
sshPortLock: new(sync.Mutex),
c: make(chan struct{}, deployConcurrent),
qemuCmd: qemuCmd,
}
+4
View File
@@ -320,6 +320,10 @@ func (pq *CpuSetCounter) AllocCpuset(vcpuCount int, memSizeKB int64, perferNumaN
pq.Lock.Lock()
defer pq.Lock.Unlock()
if len(pq.Nodes) == 0 {
return nil, nil
}
if pq.NumaEnabled {
err := pq.AllocNumaNodes(vcpuCount, memSizeKB, perferNumaNode, res)
return res, err