Skip to content

Commit b477ee2

Browse files
committed
Add some checks to handle misc cases from gpudiscovery.sh
1 parent c7163df commit b477ee2

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,13 +2052,19 @@ protected List<VgpuTypesInfo> parseGpuDevicesFromResult(String result) {
20522052
gpuDevices.add(vgpuType);
20532053

20542054
for (JsonElement vgpuInstance : vgpuInstances) {
2055-
gpuDevices.add(getGpuDeviceFromVgpuInstance(vgpuInstance, busAddress, vendorId, vendorName, deviceId,
2056-
deviceName, numaNode, pciRoot));
2055+
VgpuTypesInfo vgpu = getGpuDeviceFromVgpuInstance(vgpuInstance, busAddress, vendorId, vendorName,
2056+
deviceId, deviceName, numaNode, pciRoot);
2057+
if (vgpu != null) {
2058+
gpuDevices.add(vgpu);
2059+
}
20572060
}
20582061

20592062
for (JsonElement vfInstance : vfInstances) {
2060-
gpuDevices.add(getGpuDeviceFromVfInstance(vfInstance, busAddress, vendorId, vendorName, deviceId,
2061-
deviceName, numaNode, pciRoot));
2063+
VgpuTypesInfo vf = getGpuDeviceFromVfInstance(vfInstance, busAddress, vendorId, vendorName,
2064+
deviceId, deviceName, numaNode, pciRoot);
2065+
if (vf != null) {
2066+
gpuDevices.add(vf);
2067+
}
20622068
}
20632069
}
20642070

@@ -2073,6 +2079,9 @@ protected VgpuTypesInfo getGpuDeviceFromVgpuInstance(JsonElement vgpuInstance, S
20732079
JsonObject vgpuInstanceJsonObject = vgpuInstance.getAsJsonObject();
20742080
String mdevUuid = getJsonStringValueOrNull(vgpuInstanceJsonObject, "mdev_uuid");
20752081
String profileName = getJsonStringValueOrNull(vgpuInstanceJsonObject, "profile_name");
2082+
if (profileName == null || profileName.isEmpty()) {
2083+
return null; // Skip if profile name is not provided
2084+
}
20762085
Long maxInstances = getJsonLongValueOrNull(vgpuInstanceJsonObject, "max_instances");
20772086
Long videoRam = getJsonLongValueOrNull(vgpuInstanceJsonObject, "video_ram");
20782087
Long maxHeads = getJsonLongValueOrNull(vgpuInstanceJsonObject, "max_heads");
@@ -2094,6 +2103,9 @@ protected VgpuTypesInfo getGpuDeviceFromVfInstance(JsonElement vfInstance, Strin
20942103
JsonObject vfInstanceJsonObject = vfInstance.getAsJsonObject();
20952104
String vfPciAddress = vfInstanceJsonObject.get("vf_pci_address").getAsString();
20962105
String vfProfile = vfInstanceJsonObject.get("vf_profile").getAsString();
2106+
if (vfProfile == null || vfProfile.isEmpty()) {
2107+
return null; // Skip if profile name is not provided
2108+
}
20972109
Long maxInstances = getJsonLongValueOrNull(vfInstanceJsonObject, "max_instances");
20982110
Long videoRam = getJsonLongValueOrNull(vfInstanceJsonObject, "video_ram");
20992111
Long maxHeads = getJsonLongValueOrNull(vfInstanceJsonObject, "max_heads");

scripts/vm/hypervisor/kvm/gpudiscovery.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,12 @@ for LINE in "${LINES[@]}"; do
556556
continue
557557
fi
558558

559-
# Only process GPU classes
559+
# If this is a VF, skip it. It will be processed under its PF.
560+
if [[ -e "/sys/bus/pci/devices/0000:$PCI_ADDR/physfn" ]]; then
561+
continue
562+
fi
563+
564+
# Only process GPU classes (3D controller)
560565
if [[ ! "$PCI_CLASS" =~ (3D\ controller) ]]; then
561566
continue
562567
fi
@@ -639,10 +644,7 @@ for LINE in "${LINES[@]}"; do
639644
USED_JSON=$(to_json_vm "$raw")
640645

641646
vlist+=(
642-
"{\"mdev_uuid\":\"$MDEV_UUID\",\"profile_name\":$(json_escape "$PROFILE_NAME"),"
643-
"\"max_instances\":$MAX_INSTANCES,\"video_ram\":$VIDEO_RAM,\"max_heads\":$MAX_HEADS,"
644-
"\"max_resolution_x\":$MAX_RESOLUTION_X,\"max_resolution_y\":$MAX_RESOLUTION_Y,\"libvirt_address\":{"
645-
"\"domain\":\"$DOMAIN\",\"bus\":\"$BUS\",\"slot\":\"$SLOT\",\"function\":\"$FUNC\"},\"used_by_vm\":$USED_JSON}")
647+
"{\"mdev_uuid\":\"$MDEV_UUID\",\"profile_name\":$(json_escape "$PROFILE_NAME"),\"max_instances\":$MAX_INSTANCES,\"video_ram\":$VIDEO_RAM,\"max_heads\":$MAX_HEADS,\"max_resolution_x\":$MAX_RESOLUTION_X,\"max_resolution_y\":$MAX_RESOLUTION_Y,\"libvirt_address\":{\"domain\":\"$DOMAIN\",\"bus\":\"$BUS\",\"slot\":\"$SLOT\",\"function\":\"$FUNC\"},\"used_by_vm\":$USED_JSON}")
646648
done
647649
fi
648650
done
@@ -669,8 +671,7 @@ for LINE in "${LINES[@]}"; do
669671
SLOT="0x${VF_BDF:3:2}"
670672
FUNC="0x${VF_BDF:6:1}"
671673

672-
# Determine vf_type and vf_profile
673-
VF_TYPE="sr-iov"
674+
# Determine vf_profile
674675
VF_PROFILE=""
675676
if VF_LINE=$(lspci -nnm -s "$VF_BDF" 2>/dev/null); then
676677
if [[ $VF_LINE =~ \"([^\"]+)\"[[:space:]]\"([^\"]+)\"[[:space:]]\"([^\"]+)\"[[:space:]]\"([^\"]+)\" ]]; then
@@ -685,8 +686,7 @@ for LINE in "${LINES[@]}"; do
685686
USED_JSON=$(to_json_vm "$raw")
686687

687688
flist+=(
688-
"{\"vf_pci_address\":\"$VF_BDF\",\"vf_profile\":$VF_PROFILE_JSON,\"libvirt_address\":{"
689-
"\"domain\":\"$DOMAIN\",\"bus\":\"$BUS\",\"slot\":\"$SLOT\",\"function\":\"$FUNC\"},\"used_by_vm\":$USED_JSON}")
689+
"{\"vf_pci_address\":\"$VF_BDF\",\"vf_profile\":$VF_PROFILE_JSON,\"libvirt_address\":{\"domain\":\"$DOMAIN\",\"bus\":\"$BUS\",\"slot\":\"$SLOT\",\"function\":\"$FUNC\"},\"used_by_vm\":$USED_JSON}")
690690
done
691691
if [ ${#flist[@]} -gt 0 ]; then
692692
VF_ARRAY="[$(

0 commit comments

Comments
 (0)