diff --git a/pkg/apis/compute/guests.go b/pkg/apis/compute/guests.go index 75ca9fc052..136f9400b7 100644 --- a/pkg/apis/compute/guests.go +++ b/pkg/apis/compute/guests.go @@ -1021,6 +1021,10 @@ type ServerSnapshotAndCloneInput struct { // ignore InstanceSnapshotId string `json:"instance_snapshot_id"` + + // Perfer clone destination host + // 指定期望的迁移目标宿主机 + PreferHostId string `json:"prefer_host_id"` } type ServerInstanceSnapshot struct { diff --git a/pkg/compute/models/guest_actions.go b/pkg/compute/models/guest_actions.go index 64f410ebbe..342f50bab6 100644 --- a/pkg/compute/models/guest_actions.go +++ b/pkg/compute/models/guest_actions.go @@ -5193,6 +5193,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") diff --git a/pkg/hostman/diskutils/qemu_kvm/driver.go b/pkg/hostman/diskutils/qemu_kvm/driver.go index 434a7d7184..06ed93e77c 100644 --- a/pkg/hostman/diskutils/qemu_kvm/driver.go +++ b/pkg/hostman/diskutils/qemu_kvm/driver.go @@ -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, } diff --git a/pkg/hostman/guestman/guesthelper.go b/pkg/hostman/guestman/guesthelper.go index ed0425d5c3..e3832f410e 100644 --- a/pkg/hostman/guestman/guesthelper.go +++ b/pkg/hostman/guestman/guesthelper.go @@ -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