diff --git a/build.properties b/build.properties index 41fe8f7..436ef3d 100644 --- a/build.properties +++ b/build.properties @@ -1,6 +1,6 @@ version=0.4.3 release=1 -libvirt.required=0.8.0 +libvirt.required=0.8.1 java.required=1:1.5.0 rpm.topdir=/home/bkearney/rpmbuild jar.dir=/usr/share/java diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 81ecf20..67c368b 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -3,6 +3,7 @@ import org.libvirt.jna.DomainPointer; import org.libvirt.jna.DomainSnapshotPointer; import org.libvirt.jna.Libvirt; +import org.libvirt.jna.virDomainBlockInfo; import org.libvirt.jna.virDomainBlockStats; import org.libvirt.jna.virDomainInfo; import org.libvirt.jna.virDomainInterfaceStats; @@ -121,6 +122,22 @@ public void attachDeviceFlags(String xmlDesc, int flags) throws LibvirtException processError(); } + /** + * This function returns block device (disk) stats for block devices + * attached to the domain. + * + * @param path + * the path to the block device + * @return the info, or null if an error + * @throws LibvirtException + */ + public DomainBlockInfo blockInfo(String path) throws LibvirtException { + virDomainBlockInfo info = new virDomainBlockInfo(); + int success = libvirt.virDomainGetBlockInfo(VDP, path, info, 0); + processError(); + return success == 0 ? new DomainBlockInfo(info) : null; + } + /** * Returns block device (disk) stats for block devices attached to this * domain. The path parameter is the name of the block device. Get this by @@ -138,9 +155,9 @@ public void attachDeviceFlags(String xmlDesc, int flags) throws LibvirtException */ public DomainBlockStats blockStats(String path) throws LibvirtException { virDomainBlockStats stats = new virDomainBlockStats(); - libvirt.virDomainBlockStats(VDP, path, stats, stats.size()); + int success = libvirt.virDomainBlockStats(VDP, path, stats, stats.size()); processError(); - return new DomainBlockStats(stats); + return success == 0 ? new DomainBlockStats(stats) : null; } /** @@ -516,8 +533,8 @@ public String getXMLDesc(int flags) throws LibvirtException { /** * Determine if the domain has a snapshot * - * @see Libvi + * r t Documentation * @return 1 if running, 0 if inactive, -1 on error * @throws LibvirtException */ @@ -530,8 +547,8 @@ public int hasCurrentSnapshot() throws LibvirtException { /** * Determine if the domain has a managed save image * - * @see Libvi + * r t Documentation * @return 0 if no image is present, 1 if an image is present, and -1 in * case of error * @throws LibvirtException diff --git a/src/main/java/org/libvirt/DomainBlockInfo.java b/src/main/java/org/libvirt/DomainBlockInfo.java new file mode 100644 index 0000000..9116c32 --- /dev/null +++ b/src/main/java/org/libvirt/DomainBlockInfo.java @@ -0,0 +1,39 @@ +package org.libvirt; + +import org.libvirt.jna.virDomainBlockInfo; + +public class DomainBlockInfo { + protected long capacity; + protected long allocation; + protected long physical; + + public DomainBlockInfo(virDomainBlockInfo info) { + capacity = info.capacity; + allocation = info.allocation; + physical = info.physical; + } + + public long getAllocation() { + return allocation; + } + + public long getCapacity() { + return capacity; + } + + public long getPhysical() { + return physical; + } + + public void setAllocation(long allocation) { + this.allocation = allocation; + } + + public void setCapacity(long capacity) { + this.capacity = capacity; + } + + public void setPhysical(long physical) { + this.physical = physical; + } +} diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 4aa36f0..1e9d222 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -174,7 +174,8 @@ public String virConnectDomainXMLToNative(ConnectionPointer virConnectPtr, Strin public int virDomainDetachDeviceFlags(DomainPointer virDomainPtr, String deviceXML, int flags); public int virDomainFree(DomainPointer virDomainPtr); public int virDomainGetAutostart(DomainPointer virDomainPtr, IntByReference value); - public ConnectionPointer virDomainGetConnect(DomainPointer virDomainPtr); + public ConnectionPointer virDomainGetConnect(DomainPointer virDomainPtr); + public int virDomainGetBlockInfo(DomainPointer virDomainPtr, String path, virDomainBlockInfo info, int flags); public int virDomainGetID(DomainPointer virDomainPtr); public int virDomainGetInfo(DomainPointer virDomainPtr, virDomainInfo vInfo); public int virDomainGetJobInfo(DomainPointer virDomainPtr, virDomainJobInfo vInfo); diff --git a/src/main/java/org/libvirt/jna/virDomainBlockInfo.java b/src/main/java/org/libvirt/jna/virDomainBlockInfo.java new file mode 100644 index 0000000..234a381 --- /dev/null +++ b/src/main/java/org/libvirt/jna/virDomainBlockInfo.java @@ -0,0 +1,10 @@ +package org.libvirt.jna; + +import com.sun.jna.Structure; + +public class virDomainBlockInfo extends Structure { + public long capacity; + public long allocation; + public long physical; + +}