Skip to content

Commit 2530bf9

Browse files
CLOUDSTACK-6345: Non gpu enabled VMs are getting deployed in gpu enabled Hosts.
1 parent 6da087e commit 2530bf9

4 files changed

Lines changed: 38 additions & 2 deletions

File tree

engine/components-api/src/com/cloud/resource/ResourceManager.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ public interface ResourceManager extends ResourceService {
141141
*/
142142
List<HostVO> listAllUpAndEnabledNonHAHosts(Type type, Long clusterId, Long podId, long dcId);
143143

144+
/**
145+
* Check if host is GPU enabled
146+
* @param hostId the host to be checked
147+
* @return true if host contains GPU card else false
148+
*/
149+
boolean isHostGpuEnabled(long hostId);
150+
144151
/**
145152
* Check if host has GPU devices available
146153
* @param hostId the host to be checked

server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ protected List<Host> allocateTo(DeploymentPlan plan, ServiceOffering offering, V
243243

244244
// We will try to reorder the host lists such that we give priority to hosts that have
245245
// the minimums to support a VM's requirements
246-
hosts = prioritizeHosts(template, hosts);
246+
hosts = prioritizeHosts(template, offering, hosts);
247247

248248
if (s_logger.isDebugEnabled()) {
249249
s_logger.debug("Found " + hosts.size() + " hosts for allocation after prioritization: " + hosts);
@@ -353,7 +353,7 @@ public boolean isVirtualMachineUpgradable(VirtualMachine vm, ServiceOffering off
353353
return true;
354354
}
355355

356-
protected List<? extends Host> prioritizeHosts(VMTemplateVO template, List<? extends Host> hosts) {
356+
protected List<? extends Host> prioritizeHosts(VMTemplateVO template, ServiceOffering offering, List<? extends Host> hosts) {
357357
if (template == null) {
358358
return hosts;
359359
}
@@ -416,6 +416,22 @@ protected List<? extends Host> prioritizeHosts(VMTemplateVO template, List<? ext
416416
prioritizedHosts.addAll(0, highPriorityHosts);
417417
prioritizedHosts.addAll(lowPriorityHosts);
418418

419+
// if service offering is not GPU enabled then move all the GPU enabled hosts to the end of priority list.
420+
if (_serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.vgpuType.toString()) == null) {
421+
422+
List<Host> gpuEnabledHosts = new ArrayList<Host>();
423+
// Check for GPU enabled hosts.
424+
for (Host host : prioritizedHosts) {
425+
if (_resourceMgr.isHostGpuEnabled(host.getId())) {
426+
gpuEnabledHosts.add(host);
427+
}
428+
}
429+
// Move GPU enabled hosts to the end of list
430+
if(!gpuEnabledHosts.isEmpty()) {
431+
prioritizedHosts.removeAll(gpuEnabledHosts);
432+
prioritizedHosts.addAll(gpuEnabledHosts);
433+
}
434+
}
419435
return prioritizedHosts;
420436
}
421437

server/src/com/cloud/resource/ResourceManagerImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,6 +2500,13 @@ public List<HostVO> listAllUpAndEnabledHostsInOneZoneByHypervisor(HypervisorType
25002500
return sc.list();
25012501
}
25022502

2503+
@Override
2504+
public boolean isHostGpuEnabled(long hostId) {
2505+
SearchCriteria<HostGpuGroupsVO> sc = _gpuAvailability.create();
2506+
sc.setParameters("hostId", hostId);
2507+
return _hostGpuGroupsDao.customSearch(sc, null).size() > 0 ? true : false;
2508+
}
2509+
25032510
@Override
25042511
public List<HostGpuGroupsVO> listAvailableGPUDevice(long hostId, String vgpuType) {
25052512
if (vgpuType == null) {

server/test/com/cloud/resource/MockResourceManagerImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,4 +585,10 @@ public HashMap<String, HashMap<String, Long>> getGPUStatistics(HostVO host) {
585585
// TODO Auto-generated method stub
586586
return null;
587587
}
588+
589+
@Override
590+
public boolean isHostGpuEnabled(long hostId) {
591+
// TODO Auto-generated method stub
592+
return false;
593+
}
588594
}

0 commit comments

Comments
 (0)