migrate_predicate.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package guest
  15. import (
  16. "context"
  17. "yunion.io/x/onecloud/pkg/apis/compute"
  18. "yunion.io/x/onecloud/pkg/scheduler/algorithm/predicates"
  19. "yunion.io/x/onecloud/pkg/scheduler/core"
  20. )
  21. // MigratePredicate filters whether the current candidate can be migrated.
  22. type MigratePredicate struct {
  23. predicates.BasePredicate
  24. }
  25. func (p *MigratePredicate) Name() string {
  26. return "host_migrate"
  27. }
  28. func (p *MigratePredicate) Clone() core.FitPredicate {
  29. return &MigratePredicate{}
  30. }
  31. func (p *MigratePredicate) PreExecute(ctx context.Context, u *core.Unit, cs []core.Candidater) (bool, error) {
  32. if u.SchedData().ResetCpuNumaPin {
  33. return false, nil
  34. }
  35. return len(u.SchedData().HostId) > 0, nil
  36. }
  37. func (p *MigratePredicate) Execute(ctx context.Context, u *core.Unit, c core.Candidater) (bool, []core.PredicateFailureReason, error) {
  38. h := predicates.NewPredicateHelper(p, u, c)
  39. schedData := u.SchedData()
  40. if schedData.HostId == c.IndexKey() {
  41. h.Exclude(predicates.ErrHostIsSpecifiedForMigration)
  42. return h.GetResult()
  43. }
  44. // live migrate check
  45. if schedData.LiveMigrate {
  46. host := c.Getter().Host()
  47. guestHypervisor := u.SchedData().Hypervisor
  48. if guestHypervisor != compute.HYPERVISOR_ESXI {
  49. // target host mem page size check
  50. if schedData.HostMemPageSizeKB != host.PageSizeKB {
  51. h.Exclude(predicates.ErrHostMemPageSizeNotMatchForLiveMigrate)
  52. return h.GetResult()
  53. }
  54. // target host cpu check
  55. if schedData.CpuMode != compute.CPU_MODE_QEMU && (schedData.SkipCpuCheck == nil || *schedData.SkipCpuCheck == false) {
  56. if schedData.CpuDesc != host.CpuDesc {
  57. h.Exclude(predicates.ErrHostCpuModelIsNotMatchForLiveMigrate)
  58. return h.GetResult()
  59. }
  60. if len(schedData.CpuMicrocode) > 0 && schedData.CpuMicrocode != host.CpuMicrocode {
  61. h.Exclude(predicates.ErrHostCpuMicrocodeNotMatchForLiveMigrate)
  62. return h.GetResult()
  63. }
  64. }
  65. // target host kernel check
  66. if schedData.SkipKernelCheck != nil && !*schedData.SkipKernelCheck {
  67. kv, _ := host.SysInfo.GetString("kernel_version")
  68. if schedData.TargetHostKernel != "" && schedData.TargetHostKernel != kv {
  69. h.Exclude2(predicates.ErrHostKernelNotMatchForLiveMigrate, kv, schedData.TargetHostKernel)
  70. return h.GetResult()
  71. }
  72. }
  73. }
  74. }
  75. return h.GetResult()
  76. }