Merge pull request #15675 from zexi/automated-cherry-pick-of-#15673-upstream-master

Automated cherry pick of #15673: fix(scheduler): reduce calculation of storage's free_capacity
This commit is contained in:
Zexi Li
2022-12-30 14:52:46 +08:00
committed by GitHub
2 changed files with 20 additions and 4 deletions
+1 -1
View File
@@ -123,7 +123,7 @@ func ParseDiskConfig(diskStr string, idx int) (*compute.DiskConfig, error) {
diskConfig.Mountpoint = p
} else if p == "autoextend" {
diskConfig.SizeMb = -1
} else if utils.IsInStringArray(p, compute.STORAGE_ALL_TYPES) {
} else if utils.IsInStringArray(p, compute.STORAGE_TYPES) {
diskConfig.Backend = p
} else if len(p) > 0 {
diskConfig.ImageId = p
+19 -3
View File
@@ -28,6 +28,7 @@ import (
computeapi "yunion.io/x/onecloud/pkg/apis/compute"
computedb "yunion.io/x/onecloud/pkg/cloudcommon/db"
"yunion.io/x/onecloud/pkg/cloudcommon/types"
"yunion.io/x/onecloud/pkg/compute/models"
computemodels "yunion.io/x/onecloud/pkg/compute/models"
"yunion.io/x/onecloud/pkg/scheduler/api"
"yunion.io/x/onecloud/pkg/scheduler/core"
@@ -750,16 +751,31 @@ func (b *BaseHostDesc) fillOnecloudVpcNetworks(netGetter *networkGetter) error {
return nil
}
func (b *BaseHostDesc) GetHypervisorDriver() models.IGuestDriver {
hypervisor := computeapi.HOSTTYPE_HYPERVISOR[b.HostType]
if hypervisor == "" {
return nil
}
return models.GetDriver(hypervisor)
}
func (b *BaseHostDesc) fillStorages(host *computemodels.SHost) error {
ss := make([]*api.CandidateStorage, 0)
for _, s := range host.GetHoststorages() {
storage := s.GetStorage()
ss = append(ss, &api.CandidateStorage{
cs := &api.CandidateStorage{
SStorage: storage,
FreeCapacity: storage.GetFreeCapacity(),
ActualFreeCapacity: storage.Capacity - storage.ActualCapacityUsed,
Schedtags: storage.GetSchedtags(),
})
}
if b.GetHypervisorDriver() == nil {
cs.FreeCapacity = storage.GetFreeCapacity()
} else {
if b.GetHypervisorDriver().DoScheduleStorageFilter() {
cs.FreeCapacity = storage.GetFreeCapacity()
}
}
ss = append(ss, cs)
}
b.Storages = ss
return nil