Skip to content

Fix in the calculation of a volume's physical size#13286

Open
Tonitzpp wants to merge 1 commit into
apache:4.22from
scclouds:fix-calculation-volume-physicalsize
Open

Fix in the calculation of a volume's physical size#13286
Tonitzpp wants to merge 1 commit into
apache:4.22from
scclouds:fix-calculation-volume-physicalsize

Conversation

@Tonitzpp
Copy link
Copy Markdown
Contributor

Description

Currently, when using the KVM hypervisor, the calculation of a volume's physical size ignores the backing files (if they exist) as part of the volume's physical size in storage, which can cause confusion for users. This behavior has been changed in this PR so that the backing files are now taken into account for the volume's physical size.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

To perform the tests, I created a new VM with a backing file, and after that I took a few backups of this VM. Then, when checking the volume of this VM, it was observed that the physical size is proportional to the physical size in the storage.

@winterhazel winterhazel added this to the 4.22.2 milestone May 29, 2026
@winterhazel
Copy link
Copy Markdown
Member

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@winterhazel a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes KVM volume physical-size reporting by including the storage allocation of QCOW2 backing files in the reported KVMPhysicalDisk.size, aligning the “physical size” users see with actual storage usage when backing chains exist.

Changes:

  • Added XML parsing to detect a volume’s backing file from libvirt volume XML.
  • Updated KVM volume size calculation to recursively sum allocation across the backing chain.
  • Added a getter on LibvirtStorageVolumeDef (though not directly used by the new sizing flow).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java Recursively sums backing-file allocations and uses the result as the disk “physical size”.
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStorageVolumeXMLParser.java Adds backing-store parsing from volume XML to resolve backing file names.
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStorageVolumeDef.java Adds getVolSize() accessor for the volume size field.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +47 to +51
Element backingStore = (Element)rootElement.getElementsByTagName("backingStore").item(0);
if (backingStore != null) {
String[] paths = getTagValue("path", backingStore).split("/");
return paths[paths.length-1];
}
Comment on lines +666 to +674
public Long getBackingFileSizes(StoragePool pool, StorageVol vol) throws LibvirtException {
long size = vol.getInfo().allocation;
String backingFileOfVolumeIfExists = getBackingFileOfVolumeIfExists(vol);
if (backingFileOfVolumeIfExists != null) {
StorageVol backingFile = getVolume(pool, backingFileOfVolumeIfExists);
size += getBackingFileSizes(pool, backingFile);
}
return size;
}
Comment on lines +684 to +686
Long allSizes = getBackingFileSizes(libvirtPool.getPool(), vol);
disk = new KVMPhysicalDisk(vol.getPath(), vol.getName(), pool);
disk.setSize(vol.getInfo().allocation);
disk.setSize(allSizes);
Comment on lines +510 to +514
public String getBackingFileOfVolumeIfExists(StorageVol vol) throws LibvirtException {
String volDefXML = vol.getXMLDesc(0);
LibvirtStorageVolumeXMLParser parser = new LibvirtStorageVolumeXMLParser();
return parser.getBackingFileNameIfExists(volDefXML);
}
@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

❌ Patch coverage is 0% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.67%. Comparing base (a289bb0) to head (89532a4).
⚠️ Report is 13 commits behind head on 4.22.

Files with missing lines Patch % Lines
...or/kvm/resource/LibvirtStorageVolumeXMLParser.java 0.00% 16 Missing ⚠️
.../hypervisor/kvm/storage/LibvirtStorageAdaptor.java 0.00% 15 Missing ⚠️
...pervisor/kvm/resource/LibvirtStorageVolumeDef.java 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #13286      +/-   ##
============================================
- Coverage     17.67%   17.67%   -0.01%     
  Complexity    15792    15792              
============================================
  Files          5922     5922              
  Lines        533123   533198      +75     
  Branches      65201    65210       +9     
============================================
- Hits          94246    94244       -2     
- Misses       428236   428308      +72     
- Partials      10641    10646       +5     
Flag Coverage Δ
uitests 3.69% <ø> (ø)
unittests 18.75% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@blueorangutan
Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18087

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants