fix(scheduler): fetch host storages directly

This commit is contained in:
Zexi Li
2023-10-24 14:24:39 +08:00
parent 63ef9ebdf4
commit 80ff0dcf3f
3 changed files with 15 additions and 9 deletions
+4 -1
View File
@@ -859,7 +859,10 @@ func (hh *SHost) GetStorages() ([]SStorage, error) {
sq := HoststorageManager.Query("storage_id").Equals("host_id", hh.Id).SubQuery()
q := StorageManager.Query().In("id", sq)
storages := []SStorage{}
return storages, db.FetchModelObjects(StorageManager, q, &storages)
if err := db.FetchModelObjects(StorageManager, q, &storages); err != nil {
return nil, err
}
return storages, nil
}
func (hh *SHost) GetHoststorageOfId(storageId string) *SHoststorage {
+4 -1
View File
@@ -133,7 +133,10 @@ func (self *SHoststorage) GetHost() *SHost {
}
func (self *SHoststorage) GetStorage() *SStorage {
storage, _ := StorageManager.FetchById(self.StorageId)
storage, err := StorageManager.FetchById(self.StorageId)
if err != nil {
log.Errorf("Hoststorage fetch storage %q error: %v", self.StorageId, err)
}
if storage != nil {
return storage.(*SStorage)
}
+7 -7
View File
@@ -775,14 +775,14 @@ func (b *BaseHostDesc) GetHypervisorDriver() computemodels.IGuestDriver {
func (b *BaseHostDesc) fillStorages(host *computemodels.SHost) error {
ss := make([]*api.CandidateStorage, 0)
for _, s := range host.GetHoststorages() {
storage := s.GetStorage()
if storage == nil {
log.Warningf("%s invoke s.GetStorage return nil", s.StorageId)
continue
}
storages, err := host.GetStorages()
if err != nil {
return errors.Wrapf(err, "host %s/%s get storages", b.Name, b.Id)
}
for _, tmpS := range storages {
storage := tmpS
cs := &api.CandidateStorage{
SStorage: storage,
SStorage: &storage,
ActualFreeCapacity: storage.Capacity - storage.ActualCapacityUsed,
}
if b.GetHypervisorDriver() == nil {