Skip to content

Commit c0582d2

Browse files
TonitzppCopilot
andauthored
Apply suggestions from code review
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 668dfd1 commit c0582d2

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public String getBackingFileNameIfExists(String volXML) {
5151
NodeList pathNodes = backingStore.getElementsByTagName("path");
5252
if (pathNodes.getLength() > 0) {
5353
String path = pathNodes.item(0).getTextContent();
54-
if (StringUtils.isEmpty(path)) {
54+
if (StringUtils.isBlank(path)) {
5555
return null;
5656
}
5757
path = path.trim();

‎plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -664,13 +664,25 @@ public KVMStoragePool getStoragePool(String uuid, boolean refreshInfo) {
664664
}
665665

666666
private Long getBackingFileSizes(StoragePool pool, StorageVol vol) throws LibvirtException {
667-
long size = vol.getInfo().allocation;
668-
String backingFileOfVolumeIfExists = getBackingFileOfVolumeIfExists(vol);
669-
if (backingFileOfVolumeIfExists != null) {
670-
StorageVol backingFile = getVolume(pool, backingFileOfVolumeIfExists);
671-
size += getBackingFileSizes(pool, backingFile);
667+
long total = 0L;
668+
Set<String> visited = new HashSet<>();
669+
StorageVol current = vol;
670+
671+
while (current != null) {
672+
total += current.getInfo().allocation;
673+
String backingName = getBackingFileOfVolumeIfExists(current);
674+
if (StringUtils.isBlank(backingName) || !visited.add(backingName)) {
675+
break;
676+
}
677+
try {
678+
current = getVolume(pool, backingName);
679+
} catch (CloudRuntimeException e) {
680+
logger.debug("Unable to resolve backing volume {} in pool {}: {}", backingName, pool.getName(), e.getMessage());
681+
break;
682+
}
672683
}
673-
return size;
684+
685+
return total;
674686
}
675687

676688
@Override

0 commit comments

Comments
 (0)