Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public VolumeFormat getFormat() {
return this._volFormat;
}

public Long getVolSize() {
return _volSize;
}

@Override
public String toString() {
StringBuilder storageVolBuilder = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@
public class LibvirtStorageVolumeXMLParser {
protected Logger logger = LogManager.getLogger(getClass());

public String getBackingFileNameIfExists(String volXML) {
try {
DocumentBuilder builder = ParserUtils.getSaferDocumentBuilderFactory().newDocumentBuilder();

InputSource is = new InputSource();
is.setCharacterStream(new StringReader(volXML));
Document doc = builder.parse(is);

Element rootElement = doc.getDocumentElement();
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 +47 to +51
} catch (ParserConfigurationException | SAXException | IOException e) {
logger.error(e.toString(), e);
}
return null;
}

public LibvirtStorageVolumeDef parseStorageVolumeXML(String volXML) {
DocumentBuilder builder;
try {
Expand All @@ -50,6 +70,7 @@ public LibvirtStorageVolumeDef parseStorageVolumeXML(String volXML) {
Element target = (Element)rootElement.getElementsByTagName("target").item(0);
String format = getAttrValue("type", "format", target);
Long capacity = Long.parseLong(getTagValue("capacity", rootElement));

return new LibvirtStorageVolumeDef(VolName, capacity, LibvirtStorageVolumeDef.VolumeFormat.getFormat(format), null, null);
} catch (ParserConfigurationException e) {
logger.debug(e.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,12 @@ public LibvirtStoragePoolDef getStoragePoolDef(Connect conn, StoragePool pool) t
return parser.parseStoragePoolXML(poolDefXML);
}

public String getBackingFileOfVolumeIfExists(StorageVol vol) throws LibvirtException {
String volDefXML = vol.getXMLDesc(0);
LibvirtStorageVolumeXMLParser parser = new LibvirtStorageVolumeXMLParser();
return parser.getBackingFileNameIfExists(volDefXML);
}
Comment on lines +510 to +514

public LibvirtStorageVolumeDef getStorageVolumeDef(Connect conn, StorageVol vol) throws LibvirtException {
String volDefXML = vol.getXMLDesc(0);
LibvirtStorageVolumeXMLParser parser = new LibvirtStorageVolumeXMLParser();
Expand Down Expand Up @@ -657,6 +663,16 @@ public KVMStoragePool getStoragePool(String uuid, boolean refreshInfo) {
}
}

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 +666 to +674

@Override
public KVMPhysicalDisk getPhysicalDisk(String volumeUuid, KVMStoragePool pool) {
LibvirtStoragePool libvirtPool = (LibvirtStoragePool)pool;
Expand All @@ -665,8 +681,9 @@ public KVMPhysicalDisk getPhysicalDisk(String volumeUuid, KVMStoragePool pool) {
StorageVol vol = getVolume(libvirtPool.getPool(), volumeUuid);
KVMPhysicalDisk disk;
LibvirtStorageVolumeDef voldef = getStorageVolumeDef(libvirtPool.getPool().getConnect(), vol);
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 +684 to +686
disk.setVirtualSize(vol.getInfo().capacity);

/**
Expand Down
Loading