@@ -505,6 +505,12 @@ public LibvirtStoragePoolDef getStoragePoolDef(Connect conn, StoragePool pool) t
505505 return parser .parseStoragePoolXML (poolDefXML );
506506 }
507507
508+ public String getBackingFileOfVolumeIfExists (StorageVol vol ) throws LibvirtException {
509+ String volDefXML = vol .getXMLDesc (0 );
510+ LibvirtStorageVolumeXMLParser parser = new LibvirtStorageVolumeXMLParser ();
511+ return parser .getBackingFileNameIfExists (volDefXML );
512+ }
513+
508514 public LibvirtStorageVolumeDef getStorageVolumeDef (Connect conn , StorageVol vol ) throws LibvirtException {
509515 String volDefXML = vol .getXMLDesc (0 );
510516 LibvirtStorageVolumeXMLParser parser = new LibvirtStorageVolumeXMLParser ();
@@ -606,6 +612,16 @@ public KVMStoragePool getStoragePool(String uuid, boolean refreshInfo) {
606612 }
607613 }
608614
615+ public Long getBackingFileSizes (StoragePool pool , StorageVol vol ) throws LibvirtException {
616+ long size = vol .getInfo ().allocation ;
617+ String backingFileOfVolumeIfExists = getBackingFileOfVolumeIfExists (vol );
618+ if (backingFileOfVolumeIfExists != null ) {
619+ StorageVol backingFile = getVolume (pool , backingFileOfVolumeIfExists );
620+ size += getBackingFileSizes (pool , backingFile );
621+ }
622+ return size ;
623+ }
624+
609625 @ Override
610626 public KVMPhysicalDisk getPhysicalDisk (String volumeUuid , KVMStoragePool pool ) {
611627 LibvirtStoragePool libvirtPool = (LibvirtStoragePool )pool ;
@@ -614,8 +630,9 @@ public KVMPhysicalDisk getPhysicalDisk(String volumeUuid, KVMStoragePool pool) {
614630 StorageVol vol = getVolume (libvirtPool .getPool (), volumeUuid );
615631 KVMPhysicalDisk disk ;
616632 LibvirtStorageVolumeDef voldef = getStorageVolumeDef (libvirtPool .getPool ().getConnect (), vol );
633+ Long allSizes = getBackingFileSizes (libvirtPool .getPool (), vol );
617634 disk = new KVMPhysicalDisk (vol .getPath (), vol .getName (), pool );
618- disk .setSize (vol . getInfo (). allocation );
635+ disk .setSize (allSizes );
619636 disk .setVirtualSize (vol .getInfo ().capacity );
620637
621638 /**
0 commit comments