Skip to content

Commit 60c091d

Browse files
committed
Fix how XenServer uses GPU Card name
1 parent 306655d commit 60c091d

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

api/src/main/java/org/apache/cloudstack/gpu/GpuCard.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,11 @@ public interface GpuCard extends InternalIdentity, Identity {
5959
* @return the date when the GPU card was created
6060
*/
6161
Date getCreated();
62+
63+
64+
/**
65+
* @return the group name of the GPU card based on how the XenServer expects it.
66+
*/
67+
String getGroupName();
68+
6269
}

engine/schema/src/main/java/com/cloud/gpu/GpuCardVO.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,9 @@ public void setVendorId(String vendorId) {
139139
public Date getCreated() {
140140
return created;
141141
}
142+
143+
@Override
144+
public String getGroupName() {
145+
return "Group of " + getVendorName() + " " + getDeviceName() + " GPUs";
146+
}
142147
}

engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDaoImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
139139
"GROUP BY vm.service_offering_id) results GROUP BY pci, type";
140140

141141
private static final String COUNT_VMS_BASED_ON_VGPU_TYPES1 =
142-
"SELECT gpu_card.device_name, vgpu_profile.name, COUNT(gpu_device.vm_id) "
142+
"SELECT CONCAT(gpu_card.vendor_name, ' ', gpu_card.device_name), vgpu_profile.name, COUNT(gpu_device.vm_id) "
143143
+ "FROM `cloud`.`gpu_device` "
144144
+ "INNER JOIN `cloud`.`host` ON gpu_device.host_id = host.id "
145145
+ "INNER JOIN `cloud`.`gpu_card` ON gpu_device.card_id = gpu_card.id "

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4276,7 +4276,7 @@ public boolean isGPUDeviceAvailable(ServiceOffering offering, Host host, Long vm
42764276
public boolean isGPUDeviceAvailable(Host host, Long vmId, VgpuProfileVO vgpuProfile, int gpuCount) {
42774277
if (host.getHypervisorType().equals(HypervisorType.XenServer)) {
42784278
GpuCardVO gpuCard = gpuCardDao.findById(vgpuProfile.getCardId());
4279-
String groupName = gpuCard.getName();
4279+
String groupName = gpuCard.getGroupName();
42804280
String vgpuType = vgpuProfile.getName();
42814281
return isGPUDeviceAvailable(host, groupName, vgpuType);
42824282
} else {
@@ -4289,7 +4289,7 @@ public GPUDeviceTO getGPUDevice(VirtualMachine vm, long hostId, VgpuProfileVO vg
42894289
HostVO host = _hostDao.findById(vm.getHostId());
42904290
if (host.getHypervisorType().equals(HypervisorType.XenServer)) {
42914291
GpuCardVO gpuCard = gpuCardDao.findById(vgpuProfile.getCardId());
4292-
String groupName = gpuCard.getName();
4292+
String groupName = gpuCard.getGroupName();
42934293
String vgpuType = vgpuProfile.getName();
42944294
return getGPUDevice(vm.getHostId(), groupName, vgpuType);
42954295
} else {

server/src/main/java/org/apache/cloudstack/gpu/GpuServiceImpl.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -819,12 +819,13 @@ public HashMap<String, HashMap<String, VgpuTypesInfo>> getGpuGroupDetailsFromGpu
819819
for (final GpuDeviceVO device : gpuDevices) {
820820
// Calculate GPU capacity and update gpuGroupDetails
821821
GpuCardVO card = gpuCardDao.findById(device.getCardId());
822-
if (!gpuGroupDetails.containsKey(card.getDeviceName())) {
823-
gpuGroupDetails.put(card.getDeviceName(), new HashMap<>());
822+
String groupName = card.getName();
823+
if (!gpuGroupDetails.containsKey(groupName)) {
824+
gpuGroupDetails.put(groupName, new HashMap<>());
824825
}
825826
VgpuProfileVO vgpuProfile = vgpuProfileDao.findById(device.getVgpuProfileId());
826827

827-
VgpuTypesInfo gpuDeviceInfo = gpuGroupDetails.get(card.getDeviceName()).get(vgpuProfile.getName());
828+
VgpuTypesInfo gpuDeviceInfo = gpuGroupDetails.get(groupName).get(vgpuProfile.getName());
828829
long remainingCapacity = 0L;
829830
long maxCapacity = 1L;
830831
if (GpuDevice.State.Free.equals(device.getState()) && GpuDevice.ManagedState.Managed.equals(
@@ -836,9 +837,14 @@ public HashMap<String, HashMap<String, VgpuTypesInfo>> getGpuGroupDetailsFromGpu
836837
remainingCapacity = 0L;
837838
}
838839
if (gpuDeviceInfo == null) {
839-
gpuDeviceInfo = new VgpuTypesInfo(card.getName(), vgpuProfile.getName(), null, null, null, null,
840+
gpuDeviceInfo = new VgpuTypesInfo(card.getName(), vgpuProfile.getName(), vgpuProfile.getVideoRam(), vgpuProfile.getMaxHeads(),
841+
vgpuProfile.getMaxResolutionX(), vgpuProfile.getMaxResolutionY(),
840842
vgpuProfile.getMaxVgpuPerPgpu(), remainingCapacity, maxCapacity);
841-
gpuGroupDetails.get(card.getDeviceName()).put(vgpuProfile.getName(), gpuDeviceInfo);
843+
gpuDeviceInfo.setDeviceName(card.getDeviceName());
844+
gpuDeviceInfo.setVendorId(card.getVendorId());
845+
gpuDeviceInfo.setVendorName(card.getVendorName());
846+
gpuDeviceInfo.setDeviceId(card.getDeviceId());
847+
gpuGroupDetails.get(groupName).put(vgpuProfile.getName(), gpuDeviceInfo);
842848
} else {
843849
// Update the existing VgpuTypesInfo with the new device's information
844850
gpuDeviceInfo.setRemainingCapacity(gpuDeviceInfo.getRemainingCapacity() + remainingCapacity);

0 commit comments

Comments
 (0)