LibvirtStoragePool libvirtPool = (LibvirtStoragePool)pool;
try {
StorageVol vol = getVolume(libvirtPool.getPool(), volumeUuid);
KVMPhysicalDisk disk;
LibvirtStorageVolumeDef voldef = getStorageVolumeDef(libvirtPool.getPool().getConnect(), vol);
disk = new KVMPhysicalDisk(vol.getPath(), vol.getName(), pool);
disk.setSize(vol.getInfo().allocation);
disk.setVirtualSize(vol.getInfo().capacity);
/**
* libvirt returns format = 'unknow', so we have to force
* the format to RAW for RBD storage volumes
*/
if (pool.getType() == StoragePoolType.RBD) {
disk.setFormat(PhysicalDiskFormat.RAW);
} else if (voldef.getFormat() == null) {
File diskDir = new File(disk.getPath());
if (diskDir.exists() && diskDir.isDirectory()) {
disk.setFormat(PhysicalDiskFormat.DIR);
} else if (volumeUuid.endsWith("tar") || volumeUuid.endsWith(("TAR"))) {
disk.setFormat(PhysicalDiskFormat.TAR);
} else if (volumeUuid.endsWith("raw") || volumeUuid.endsWith(("RAW"))) {
disk.setFormat(PhysicalDiskFormat.RAW);
} else {
disk.setFormat(pool.getDefaultFormat());
}
} else if (voldef.getFormat() == LibvirtStorageVolumeDef.volFormat.QCOW2) {
disk.setFormat(PhysicalDiskFormat.QCOW2);
} else if (voldef.getFormat() == LibvirtStorageVolumeDef.volFormat.RAW) {
disk.setFormat(PhysicalDiskFormat.RAW);
}
return disk;
} catch (LibvirtException e) {
s_logger.debug("Failed to get physical disk:", e);