Fix in the calculation of a volume's physical size#13286
Conversation
|
@blueorangutan package |
|
@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. |
There was a problem hiding this comment.
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
allocationacross 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.
| Element backingStore = (Element)rootElement.getElementsByTagName("backingStore").item(0); | ||
| if (backingStore != null) { | ||
| String[] paths = getTagValue("path", backingStore).split("/"); | ||
| return paths[paths.length-1]; | ||
| } |
| 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; | ||
| } |
| Long allSizes = getBackingFileSizes(libvirtPool.getPool(), vol); | ||
| disk = new KVMPhysicalDisk(vol.getPath(), vol.getName(), pool); | ||
| disk.setSize(vol.getInfo().allocation); | ||
| disk.setSize(allSizes); |
| public String getBackingFileOfVolumeIfExists(StorageVol vol) throws LibvirtException { | ||
| String volDefXML = vol.getXMLDesc(0); | ||
| LibvirtStorageVolumeXMLParser parser = new LibvirtStorageVolumeXMLParser(); | ||
| return parser.getBackingFileNameIfExists(volDefXML); | ||
| } |
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18087 |
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
Feature/Enhancement Scale or Bug Severity
Bug Severity
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.