[libvirt] [libvirt-java] [PATCH 00/65]

Hi. Here are a few patches that piled up in my local branch. Some of them I already submitted to this list, but there has been no reponse to them. Included are a few trivial fixes as well as memory leak fixes and additions to the public API. There had been some minor interest in my first version of domain event support in the Java wrapper[1], which I have reworked almost entirely. If nobody objects, say, within the next two weeks or so, I'll go ahead and push the whole series as was suggested to me by Daniel P. Berrange on this list[2]. I've made sure that all JUnit tests pass after every commit with JNA versions 3.4.1, 3.4.2, 3.5.0, 3.5.1, 3.5.2 and 4.0.0. I'd really appreciate your comments or suggestions. Thanks! [1]: https://www.redhat.com/archives/libvir-list/2013-January/msg01236.html [2]: https://www.redhat.com/archives/libvir-list/2014-January/msg01091.html Claudio Bley (65): Fix warnings about using raw types Fix warnings about accessing static methods Fix typos in Error.java test: fix typo in testConnection() test: ensure that exceptions are thrown when expected Make comments proper javadoc comments for enum constants Ignore editor backup files Depend on JNA versions 3.4.1 to 4.0.0 jna: load virt-0 or virt library depending on the platform Fix wrapping of native size_t data type Use virFree in order to release memory acquired from libvirt tests: remove obsolete test driver Make Device.listCapabilities return only valid array elements test: ensure the Device.listCapabilities method works Start refactoring of error handling Remove processError from Device class Remove processError from Domain class Remove processError from DomainSnapshot class Remove processError from Interface class Remove processError method from Network class Remove processError method from NetworkFilter class Remove processError method from Secret class Remove processError method from StoragePool class Remove processError method from StorageVol class Remove processError method from Stream class Remove processError method from Connect class Call processError only when virInitialize signalled an error Remove ErrorHandler.processError(Libvirt) method Implement equals and hashCode methods for Connect and Domain Fix Domain.getSchedulerParameters / getSchedulerType Fix memleak in Domain.snapshotListNames Fix memleak in StoragePool.listVolumes Fix memleak in DomainSnapshot.getXMLDesc Fix memleak in StorageVol.getPath Fix memleak in StorageVol.getXMLDesc jna: Wrap the virEvent(Add,Remove)Timeout libvirt functions Implement Connect.isAlive Implement Connect.setKeepAlive Introduce event loop support Add constants for enum virDomainEventID Prepare to define proper domain event callback support Add constructIncRef factory method to Domain class events: handle registration for IOError events events: handle registration for Reboot events events: handle registration of domain lifecycle events test: add unit test for domain lifecycle events events: handle registration for PMWakeup events events: add support for PMSuspend events Implement connection close callback support Implement Connect.getSysinfo Implement Domain.blockPeek Implement Domain.memoryPeek Implement Secret.getUsageType Implement Domain.isUpdated Implement Domain.reset Implement Domain.PMwakeup Implement Domain.sendKey Implement interface ByteChannel for Stream class Implement Domain.screenshot test: add testDomainScreenshot JUnit test Add helper for handling bit-flags Connect: add constructors using java.net.URI params Replace Connect.getLibVirVersion method with Library.getVersion Replace static connectionVersion method with getLibVersion Deprecate Connect.getHypervisorVersion .gitignore | 2 + pom.xml.in | 2 +- src/main/java/org/libvirt/BitFlags.java | 18 + src/main/java/org/libvirt/Connect.java | 731 +++++++++++++++++--- src/main/java/org/libvirt/Device.java | 57 +- src/main/java/org/libvirt/Domain.java | 672 +++++++++++------- src/main/java/org/libvirt/DomainSnapshot.java | 29 +- src/main/java/org/libvirt/Error.java | 409 +++++++---- src/main/java/org/libvirt/ErrorHandler.java | 54 +- src/main/java/org/libvirt/Interface.java | 43 +- src/main/java/org/libvirt/KeycodeSet.java | 46 ++ src/main/java/org/libvirt/Library.java | 134 +++- src/main/java/org/libvirt/MemoryAddressMode.java | 19 + src/main/java/org/libvirt/Network.java | 61 +- src/main/java/org/libvirt/NetworkFilter.java | 43 +- src/main/java/org/libvirt/Secret.java | 72 +- src/main/java/org/libvirt/SecretUsageType.java | 23 + src/main/java/org/libvirt/StoragePool.java | 106 ++- src/main/java/org/libvirt/StorageVol.java | 68 +- src/main/java/org/libvirt/Stream.java | 232 +++++-- src/main/java/org/libvirt/SuspendTarget.java | 15 + src/main/java/org/libvirt/event/CrashedDetail.java | 15 + src/main/java/org/libvirt/event/DefinedDetail.java | 17 + src/main/java/org/libvirt/event/DetailInfo.java | 5 + src/main/java/org/libvirt/event/DomainEvent.java | 71 ++ .../java/org/libvirt/event/DomainEventDetail.java | 7 + .../java/org/libvirt/event/DomainEventType.java | 60 ++ src/main/java/org/libvirt/event/EventListener.java | 7 + src/main/java/org/libvirt/event/IOErrorAction.java | 39 ++ .../java/org/libvirt/event/IOErrorListener.java | 21 + .../java/org/libvirt/event/LifecycleListener.java | 24 + .../java/org/libvirt/event/PMSuspendListener.java | 17 + .../java/org/libvirt/event/PMSuspendReason.java | 5 + .../java/org/libvirt/event/PMSuspendedDetail.java | 15 + .../java/org/libvirt/event/PMWakeupListener.java | 17 + .../java/org/libvirt/event/PMWakeupReason.java | 5 + .../java/org/libvirt/event/RebootListener.java | 15 + src/main/java/org/libvirt/event/ResumedDetail.java | 20 + .../java/org/libvirt/event/ShutdownDetail.java | 12 + src/main/java/org/libvirt/event/StartedDetail.java | 30 + src/main/java/org/libvirt/event/StoppedDetail.java | 40 ++ .../java/org/libvirt/event/SuspendedDetail.java | 40 ++ .../java/org/libvirt/event/UndefinedDetail.java | 7 + src/main/java/org/libvirt/jna/Libvirt.java | 121 +++- src/main/java/org/libvirt/jna/SizeT.java | 19 + .../java/org/libvirt/jna/SizeTByReference.java | 50 ++ src/main/java/org/libvirt/jna/virConnectAuth.java | 4 +- .../java/org/libvirt/jna/virConnectCredential.java | 4 +- .../java/org/libvirt/jna/virDomainBlockInfo.java | 4 +- .../java/org/libvirt/jna/virDomainBlockStats.java | 4 +- src/main/java/org/libvirt/jna/virDomainInfo.java | 4 +- .../org/libvirt/jna/virDomainInterfaceStats.java | 4 +- .../java/org/libvirt/jna/virDomainJobInfo.java | 4 +- .../java/org/libvirt/jna/virDomainMemoryStats.java | 4 +- src/main/java/org/libvirt/jna/virError.java | 4 +- src/main/java/org/libvirt/jna/virNodeInfo.java | 4 +- .../java/org/libvirt/jna/virSchedParameter.java | 4 +- .../java/org/libvirt/jna/virStoragePoolInfo.java | 4 +- .../java/org/libvirt/jna/virStorageVolInfo.java | 4 +- src/main/java/org/libvirt/jna/virVcpuInfo.java | 4 +- src/test/java/org/libvirt/TestJavaBindings.java | 139 +++- src/test/java/org/libvirt/TestLibvirtGlobals.java | 4 + src/test/java/test.java | 280 -------- 63 files changed, 2807 insertions(+), 1187 deletions(-) create mode 100644 src/main/java/org/libvirt/BitFlags.java create mode 100644 src/main/java/org/libvirt/KeycodeSet.java create mode 100644 src/main/java/org/libvirt/MemoryAddressMode.java create mode 100644 src/main/java/org/libvirt/SecretUsageType.java create mode 100644 src/main/java/org/libvirt/SuspendTarget.java create mode 100644 src/main/java/org/libvirt/event/CrashedDetail.java create mode 100644 src/main/java/org/libvirt/event/DefinedDetail.java create mode 100644 src/main/java/org/libvirt/event/DetailInfo.java create mode 100644 src/main/java/org/libvirt/event/DomainEvent.java create mode 100644 src/main/java/org/libvirt/event/DomainEventDetail.java create mode 100644 src/main/java/org/libvirt/event/DomainEventType.java create mode 100644 src/main/java/org/libvirt/event/EventListener.java create mode 100644 src/main/java/org/libvirt/event/IOErrorAction.java create mode 100644 src/main/java/org/libvirt/event/IOErrorListener.java create mode 100644 src/main/java/org/libvirt/event/LifecycleListener.java create mode 100644 src/main/java/org/libvirt/event/PMSuspendListener.java create mode 100644 src/main/java/org/libvirt/event/PMSuspendReason.java create mode 100644 src/main/java/org/libvirt/event/PMSuspendedDetail.java create mode 100644 src/main/java/org/libvirt/event/PMWakeupListener.java create mode 100644 src/main/java/org/libvirt/event/PMWakeupReason.java create mode 100644 src/main/java/org/libvirt/event/RebootListener.java create mode 100644 src/main/java/org/libvirt/event/ResumedDetail.java create mode 100644 src/main/java/org/libvirt/event/ShutdownDetail.java create mode 100644 src/main/java/org/libvirt/event/StartedDetail.java create mode 100644 src/main/java/org/libvirt/event/StoppedDetail.java create mode 100644 src/main/java/org/libvirt/event/SuspendedDetail.java create mode 100644 src/main/java/org/libvirt/event/UndefinedDetail.java create mode 100644 src/main/java/org/libvirt/jna/SizeT.java create mode 100644 src/main/java/org/libvirt/jna/SizeTByReference.java delete mode 100644 src/test/java/test.java -- 1.7.9.5

Eclipse generates this kind of warning: org/libvirt/jna/virConnectCredential.java:20: List is a raw type. References to generic type List<E> should be parameterized Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/jna/virConnectAuth.java | 4 ++-- .../java/org/libvirt/jna/virConnectCredential.java | 4 ++-- .../java/org/libvirt/jna/virDomainBlockInfo.java | 4 ++-- .../java/org/libvirt/jna/virDomainBlockStats.java | 4 ++-- src/main/java/org/libvirt/jna/virDomainInfo.java | 4 ++-- .../org/libvirt/jna/virDomainInterfaceStats.java | 4 ++-- .../java/org/libvirt/jna/virDomainJobInfo.java | 4 ++-- .../java/org/libvirt/jna/virDomainMemoryStats.java | 4 ++-- src/main/java/org/libvirt/jna/virError.java | 4 ++-- src/main/java/org/libvirt/jna/virNodeInfo.java | 4 ++-- .../java/org/libvirt/jna/virSchedParameter.java | 4 ++-- .../java/org/libvirt/jna/virStoragePoolInfo.java | 4 ++-- .../java/org/libvirt/jna/virStorageVolInfo.java | 4 ++-- src/main/java/org/libvirt/jna/virVcpuInfo.java | 4 ++-- 14 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/libvirt/jna/virConnectAuth.java b/src/main/java/org/libvirt/jna/virConnectAuth.java index ece61f6..0451348 100644 --- a/src/main/java/org/libvirt/jna/virConnectAuth.java +++ b/src/main/java/org/libvirt/jna/virConnectAuth.java @@ -15,11 +15,11 @@ public class virConnectAuth extends Structure { public Libvirt.VirConnectAuthCallback cb; public Pointer cbdata; - private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "credtype", "ncredtype", "cb", "cbdata"); @Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virConnectCredential.java b/src/main/java/org/libvirt/jna/virConnectCredential.java index 6dd4a75..316b1f4 100644 --- a/src/main/java/org/libvirt/jna/virConnectCredential.java +++ b/src/main/java/org/libvirt/jna/virConnectCredential.java @@ -17,12 +17,12 @@ public class virConnectCredential extends Structure implements Structure.ByRefer public String result; public int resultlen; - private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "type", "prompt", "challenge", "defresult", "result", "resultlen"); @Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virDomainBlockInfo.java b/src/main/java/org/libvirt/jna/virDomainBlockInfo.java index fb1b845..5a88ba3 100644 --- a/src/main/java/org/libvirt/jna/virDomainBlockInfo.java +++ b/src/main/java/org/libvirt/jna/virDomainBlockInfo.java @@ -10,11 +10,11 @@ public class virDomainBlockInfo extends Structure { public long allocation; public long physical; - private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "capacity", "allocation", "physical"); @Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virDomainBlockStats.java b/src/main/java/org/libvirt/jna/virDomainBlockStats.java index a7331f6..e48629a 100644 --- a/src/main/java/org/libvirt/jna/virDomainBlockStats.java +++ b/src/main/java/org/libvirt/jna/virDomainBlockStats.java @@ -20,11 +20,11 @@ public class virDomainBlockStats extends Structure { public long errs; // this is a long long in the code, so a long mapping is // correct - private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "rd_req", "rd_bytes", "wr_req", "wr_bytes", "errs"); @Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virDomainInfo.java b/src/main/java/org/libvirt/jna/virDomainInfo.java index 0b667f6..ff20d16 100644 --- a/src/main/java/org/libvirt/jna/virDomainInfo.java +++ b/src/main/java/org/libvirt/jna/virDomainInfo.java @@ -16,11 +16,11 @@ public class virDomainInfo extends Structure { public short nrVirtCpu; public long cpuTime; - private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "state", "maxMem", "memory", "nrVirtCpu", "cpuTime"); @Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virDomainInterfaceStats.java b/src/main/java/org/libvirt/jna/virDomainInterfaceStats.java index eea6a49..9b98aa8 100644 --- a/src/main/java/org/libvirt/jna/virDomainInterfaceStats.java +++ b/src/main/java/org/libvirt/jna/virDomainInterfaceStats.java @@ -26,12 +26,12 @@ public class virDomainInterfaceStats extends Structure { public long tx_drop; // this is a long long in the code, so a long mapping // is correct - private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "rx_bytes", "rx_packets", "rx_errs", "rx_drop", "tx_bytes", "tx_packets", "tx_errs", "tx_drop"); @Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virDomainJobInfo.java b/src/main/java/org/libvirt/jna/virDomainJobInfo.java index 0398901..1bab587 100644 --- a/src/main/java/org/libvirt/jna/virDomainJobInfo.java +++ b/src/main/java/org/libvirt/jna/virDomainJobInfo.java @@ -19,13 +19,13 @@ public class virDomainJobInfo extends Structure { public long fileProcessed; public long fileRemaining; - private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "type", "timeElapsed", "timeRemaining", "dataTotal", "dataProcessed", "dataRemaining", "memTotal", "memProcessed", "memRemaining", "fileTotal", "fileProcessed", "fileRemaining"); @Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virDomainMemoryStats.java b/src/main/java/org/libvirt/jna/virDomainMemoryStats.java index b14fb95..dfbd3f9 100644 --- a/src/main/java/org/libvirt/jna/virDomainMemoryStats.java +++ b/src/main/java/org/libvirt/jna/virDomainMemoryStats.java @@ -9,10 +9,10 @@ public class virDomainMemoryStats extends Structure { public int tag ; public long val ; - private static final List fields = Arrays.asList( "tag", "val"); + private static final List<String> fields = Arrays.asList( "tag", "val"); @Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virError.java b/src/main/java/org/libvirt/jna/virError.java index 36b9f69..e58f5f3 100644 --- a/src/main/java/org/libvirt/jna/virError.java +++ b/src/main/java/org/libvirt/jna/virError.java @@ -22,12 +22,12 @@ public class virError extends Structure { public int int2; public NetworkPointer net; - private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "code", "domain", "message", "level", "conn", "dom", "str1", "str2", "str3", "int1", "int2", "net"); @Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virNodeInfo.java b/src/main/java/org/libvirt/jna/virNodeInfo.java index 9ff1251..7a7716e 100644 --- a/src/main/java/org/libvirt/jna/virNodeInfo.java +++ b/src/main/java/org/libvirt/jna/virNodeInfo.java @@ -25,12 +25,12 @@ public class virNodeInfo extends Structure { public int cores; public int threads; - private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "model", "memory", "cpus", "mhz", "nodes", "sockets", "cores", "threads"); @Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virSchedParameter.java b/src/main/java/org/libvirt/jna/virSchedParameter.java index f579ef0..f3787a9 100644 --- a/src/main/java/org/libvirt/jna/virSchedParameter.java +++ b/src/main/java/org/libvirt/jna/virSchedParameter.java @@ -13,11 +13,11 @@ public class virSchedParameter extends Structure { public int type; public virSchedParameterValue value; - private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "field", "type", "value"); @Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virStoragePoolInfo.java b/src/main/java/org/libvirt/jna/virStoragePoolInfo.java index fe20f0f..7077175 100644 --- a/src/main/java/org/libvirt/jna/virStoragePoolInfo.java +++ b/src/main/java/org/libvirt/jna/virStoragePoolInfo.java @@ -17,11 +17,11 @@ public class virStoragePoolInfo extends Structure { public long available; // this is a long long in the code, so a long mapping // is correct - private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "state", "capacity", "allocation", "available"); @Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virStorageVolInfo.java b/src/main/java/org/libvirt/jna/virStorageVolInfo.java index 93132ea..8bf2d5c 100644 --- a/src/main/java/org/libvirt/jna/virStorageVolInfo.java +++ b/src/main/java/org/libvirt/jna/virStorageVolInfo.java @@ -15,11 +15,11 @@ public class virStorageVolInfo extends Structure { public long allocation; // this is a long long in the code, so a long // mapping is correct - private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "type", "capacity", "allocation"); @Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virVcpuInfo.java b/src/main/java/org/libvirt/jna/virVcpuInfo.java index 96eca2f..bc1a539 100644 --- a/src/main/java/org/libvirt/jna/virVcpuInfo.java +++ b/src/main/java/org/libvirt/jna/virVcpuInfo.java @@ -15,11 +15,11 @@ public class virVcpuInfo extends Structure { // is correct public int cpu; - private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "number", "state", "cpuTime", "cpu"); @Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } -- 1.7.9.5

Hi, On Thu, Feb 13, 2014 at 04:22:09PM +0100, Claudio Bley wrote:
Eclipse generates this kind of warning:
org/libvirt/jna/virConnectCredential.java:20: List is a raw type. References to generic type List<E> should be parameterized
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/jna/virConnectAuth.java | 4 ++-- .../java/org/libvirt/jna/virConnectCredential.java | 4 ++-- .../java/org/libvirt/jna/virDomainBlockInfo.java | 4 ++-- .../java/org/libvirt/jna/virDomainBlockStats.java | 4 ++-- src/main/java/org/libvirt/jna/virDomainInfo.java | 4 ++-- .../org/libvirt/jna/virDomainInterfaceStats.java | 4 ++-- .../java/org/libvirt/jna/virDomainJobInfo.java | 4 ++-- .../java/org/libvirt/jna/virDomainMemoryStats.java | 4 ++-- src/main/java/org/libvirt/jna/virError.java | 4 ++-- src/main/java/org/libvirt/jna/virNodeInfo.java | 4 ++-- .../java/org/libvirt/jna/virSchedParameter.java | 4 ++-- .../java/org/libvirt/jna/virStoragePoolInfo.java | 4 ++-- .../java/org/libvirt/jna/virStorageVolInfo.java | 4 ++-- src/main/java/org/libvirt/jna/virVcpuInfo.java | 4 ++-- 14 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/src/main/java/org/libvirt/jna/virConnectAuth.java b/src/main/java/org/libvirt/jna/virConnectAuth.java index ece61f6..0451348 100644 --- a/src/main/java/org/libvirt/jna/virConnectAuth.java +++ b/src/main/java/org/libvirt/jna/virConnectAuth.java @@ -15,11 +15,11 @@ public class virConnectAuth extends Structure { public Libvirt.VirConnectAuthCallback cb; public Pointer cbdata;
- private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "credtype", "ncredtype", "cb", "cbdata");
@Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virConnectCredential.java b/src/main/java/org/libvirt/jna/virConnectCredential.java index 6dd4a75..316b1f4 100644 --- a/src/main/java/org/libvirt/jna/virConnectCredential.java +++ b/src/main/java/org/libvirt/jna/virConnectCredential.java @@ -17,12 +17,12 @@ public class virConnectCredential extends Structure implements Structure.ByRefer public String result; public int resultlen;
- private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "type", "prompt", "challenge", "defresult", "result", "resultlen");
@Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virDomainBlockInfo.java b/src/main/java/org/libvirt/jna/virDomainBlockInfo.java index fb1b845..5a88ba3 100644 --- a/src/main/java/org/libvirt/jna/virDomainBlockInfo.java +++ b/src/main/java/org/libvirt/jna/virDomainBlockInfo.java @@ -10,11 +10,11 @@ public class virDomainBlockInfo extends Structure { public long allocation; public long physical;
- private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "capacity", "allocation", "physical");
@Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virDomainBlockStats.java b/src/main/java/org/libvirt/jna/virDomainBlockStats.java index a7331f6..e48629a 100644 --- a/src/main/java/org/libvirt/jna/virDomainBlockStats.java +++ b/src/main/java/org/libvirt/jna/virDomainBlockStats.java @@ -20,11 +20,11 @@ public class virDomainBlockStats extends Structure { public long errs; // this is a long long in the code, so a long mapping is // correct
- private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "rd_req", "rd_bytes", "wr_req", "wr_bytes", "errs");
@Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virDomainInfo.java b/src/main/java/org/libvirt/jna/virDomainInfo.java index 0b667f6..ff20d16 100644 --- a/src/main/java/org/libvirt/jna/virDomainInfo.java +++ b/src/main/java/org/libvirt/jna/virDomainInfo.java @@ -16,11 +16,11 @@ public class virDomainInfo extends Structure { public short nrVirtCpu; public long cpuTime;
- private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "state", "maxMem", "memory", "nrVirtCpu", "cpuTime");
@Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virDomainInterfaceStats.java b/src/main/java/org/libvirt/jna/virDomainInterfaceStats.java index eea6a49..9b98aa8 100644 --- a/src/main/java/org/libvirt/jna/virDomainInterfaceStats.java +++ b/src/main/java/org/libvirt/jna/virDomainInterfaceStats.java @@ -26,12 +26,12 @@ public class virDomainInterfaceStats extends Structure { public long tx_drop; // this is a long long in the code, so a long mapping // is correct
- private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "rx_bytes", "rx_packets", "rx_errs", "rx_drop", "tx_bytes", "tx_packets", "tx_errs", "tx_drop");
@Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virDomainJobInfo.java b/src/main/java/org/libvirt/jna/virDomainJobInfo.java index 0398901..1bab587 100644 --- a/src/main/java/org/libvirt/jna/virDomainJobInfo.java +++ b/src/main/java/org/libvirt/jna/virDomainJobInfo.java @@ -19,13 +19,13 @@ public class virDomainJobInfo extends Structure { public long fileProcessed; public long fileRemaining;
- private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "type", "timeElapsed", "timeRemaining", "dataTotal", "dataProcessed", "dataRemaining", "memTotal", "memProcessed", "memRemaining", "fileTotal", "fileProcessed", "fileRemaining");
@Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virDomainMemoryStats.java b/src/main/java/org/libvirt/jna/virDomainMemoryStats.java index b14fb95..dfbd3f9 100644 --- a/src/main/java/org/libvirt/jna/virDomainMemoryStats.java +++ b/src/main/java/org/libvirt/jna/virDomainMemoryStats.java @@ -9,10 +9,10 @@ public class virDomainMemoryStats extends Structure { public int tag ; public long val ;
- private static final List fields = Arrays.asList( "tag", "val"); + private static final List<String> fields = Arrays.asList( "tag", "val");
@Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virError.java b/src/main/java/org/libvirt/jna/virError.java index 36b9f69..e58f5f3 100644 --- a/src/main/java/org/libvirt/jna/virError.java +++ b/src/main/java/org/libvirt/jna/virError.java @@ -22,12 +22,12 @@ public class virError extends Structure { public int int2; public NetworkPointer net;
- private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "code", "domain", "message", "level", "conn", "dom", "str1", "str2", "str3", "int1", "int2", "net");
@Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virNodeInfo.java b/src/main/java/org/libvirt/jna/virNodeInfo.java index 9ff1251..7a7716e 100644 --- a/src/main/java/org/libvirt/jna/virNodeInfo.java +++ b/src/main/java/org/libvirt/jna/virNodeInfo.java @@ -25,12 +25,12 @@ public class virNodeInfo extends Structure { public int cores; public int threads;
- private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "model", "memory", "cpus", "mhz", "nodes", "sockets", "cores", "threads");
@Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virSchedParameter.java b/src/main/java/org/libvirt/jna/virSchedParameter.java index f579ef0..f3787a9 100644 --- a/src/main/java/org/libvirt/jna/virSchedParameter.java +++ b/src/main/java/org/libvirt/jna/virSchedParameter.java @@ -13,11 +13,11 @@ public class virSchedParameter extends Structure { public int type; public virSchedParameterValue value;
- private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "field", "type", "value");
@Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virStoragePoolInfo.java b/src/main/java/org/libvirt/jna/virStoragePoolInfo.java index fe20f0f..7077175 100644 --- a/src/main/java/org/libvirt/jna/virStoragePoolInfo.java +++ b/src/main/java/org/libvirt/jna/virStoragePoolInfo.java @@ -17,11 +17,11 @@ public class virStoragePoolInfo extends Structure { public long available; // this is a long long in the code, so a long mapping // is correct
- private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "state", "capacity", "allocation", "available");
@Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virStorageVolInfo.java b/src/main/java/org/libvirt/jna/virStorageVolInfo.java index 93132ea..8bf2d5c 100644 --- a/src/main/java/org/libvirt/jna/virStorageVolInfo.java +++ b/src/main/java/org/libvirt/jna/virStorageVolInfo.java @@ -15,11 +15,11 @@ public class virStorageVolInfo extends Structure { public long allocation; // this is a long long in the code, so a long // mapping is correct
- private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "type", "capacity", "allocation");
@Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } } diff --git a/src/main/java/org/libvirt/jna/virVcpuInfo.java b/src/main/java/org/libvirt/jna/virVcpuInfo.java index 96eca2f..bc1a539 100644 --- a/src/main/java/org/libvirt/jna/virVcpuInfo.java +++ b/src/main/java/org/libvirt/jna/virVcpuInfo.java @@ -15,11 +15,11 @@ public class virVcpuInfo extends Structure { // is correct public int cpu;
- private static final List fields = Arrays.asList( + private static final List<String> fields = Arrays.asList( "number", "state", "cpuTime", "cpu");
@Override - protected List getFieldOrder() { + protected List<String> getFieldOrder() { return fields; } }
ACK (from a non Java expert). -- Guido
-- 1.7.9.5
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Thu, Feb 13, 2014 at 04:22:09PM +0100, Claudio Bley wrote:
Eclipse generates this kind of warning:
org/libvirt/jna/virConnectCredential.java:20: List is a raw type. References to generic type List<E> should be parameterized
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/jna/virConnectAuth.java | 4 ++-- .../java/org/libvirt/jna/virConnectCredential.java | 4 ++-- .../java/org/libvirt/jna/virDomainBlockInfo.java | 4 ++-- .../java/org/libvirt/jna/virDomainBlockStats.java | 4 ++-- src/main/java/org/libvirt/jna/virDomainInfo.java | 4 ++-- .../org/libvirt/jna/virDomainInterfaceStats.java | 4 ++-- .../java/org/libvirt/jna/virDomainJobInfo.java | 4 ++-- .../java/org/libvirt/jna/virDomainMemoryStats.java | 4 ++-- src/main/java/org/libvirt/jna/virError.java | 4 ++-- src/main/java/org/libvirt/jna/virNodeInfo.java | 4 ++-- .../java/org/libvirt/jna/virSchedParameter.java | 4 ++-- .../java/org/libvirt/jna/virStoragePoolInfo.java | 4 ++-- .../java/org/libvirt/jna/virStorageVolInfo.java | 4 ++-- src/main/java/org/libvirt/jna/virVcpuInfo.java | 4 ++-- 14 files changed, 28 insertions(+), 28 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:32:08 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:09PM +0100, Claudio Bley wrote:
Eclipse generates this kind of warning:
org/libvirt/jna/virConnectCredential.java:20: List is a raw type. References to generic type List<E> should be parameterized
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/jna/virConnectAuth.java | 4 ++-- .../java/org/libvirt/jna/virConnectCredential.java | 4 ++-- .../java/org/libvirt/jna/virDomainBlockInfo.java | 4 ++-- .../java/org/libvirt/jna/virDomainBlockStats.java | 4 ++-- src/main/java/org/libvirt/jna/virDomainInfo.java | 4 ++-- .../org/libvirt/jna/virDomainInterfaceStats.java | 4 ++-- .../java/org/libvirt/jna/virDomainJobInfo.java | 4 ++-- .../java/org/libvirt/jna/virDomainMemoryStats.java | 4 ++-- src/main/java/org/libvirt/jna/virError.java | 4 ++-- src/main/java/org/libvirt/jna/virNodeInfo.java | 4 ++-- .../java/org/libvirt/jna/virSchedParameter.java | 4 ++-- .../java/org/libvirt/jna/virStoragePoolInfo.java | 4 ++-- .../java/org/libvirt/jna/virStorageVolInfo.java | 4 ++-- src/main/java/org/libvirt/jna/virVcpuInfo.java | 4 ++-- 14 files changed, 28 insertions(+), 28 deletions(-)
ACK
Thanks, pushed.

java/org/libvirt/Error.java:217: The static method wrap(int) from the type Error.ErrorDomain should be accessed in a static way Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Error.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/libvirt/Error.java b/src/main/java/org/libvirt/Error.java index 114e758..6f68f57 100644 --- a/src/main/java/org/libvirt/Error.java +++ b/src/main/java/org/libvirt/Error.java @@ -213,9 +213,9 @@ public class Error implements Serializable { private NetworkPointer VNP; /* Deprecated */ public Error(virError vError) { - code = code.wrap(vError.code); - domain = domain.wrap(vError.domain); - level = level.wrap(vError.level); + code = ErrorNumber.wrap(vError.code); + domain = ErrorDomain.wrap(vError.domain); + level = ErrorLevel.wrap(vError.level); message = vError.message; str1 = vError.str1; str2 = vError.str2; -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:10PM +0100, Claudio Bley wrote:
java/org/libvirt/Error.java:217: The static method wrap(int) from the type Error.ErrorDomain should be accessed in a static way
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Error.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/libvirt/Error.java b/src/main/java/org/libvirt/Error.java index 114e758..6f68f57 100644 --- a/src/main/java/org/libvirt/Error.java +++ b/src/main/java/org/libvirt/Error.java @@ -213,9 +213,9 @@ public class Error implements Serializable { private NetworkPointer VNP; /* Deprecated */
public Error(virError vError) { - code = code.wrap(vError.code); - domain = domain.wrap(vError.domain); - level = level.wrap(vError.level); + code = ErrorNumber.wrap(vError.code); + domain = ErrorDomain.wrap(vError.domain); + level = ErrorLevel.wrap(vError.level); message = vError.message; str1 = vError.str1; str2 = vError.str2;
ACK (from a non Java expert). -- Guido
-- 1.7.9.5
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Thu, Feb 13, 2014 at 04:22:10PM +0100, Claudio Bley wrote:
java/org/libvirt/Error.java:217: The static method wrap(int) from the type Error.ErrorDomain should be accessed in a static way
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Error.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:33:44 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:10PM +0100, Claudio Bley wrote:
java/org/libvirt/Error.java:217: The static method wrap(int) from the type Error.ErrorDomain should be accessed in a static way
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Error.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
ACK
Thanks, pushed.

Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Error.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/libvirt/Error.java b/src/main/java/org/libvirt/Error.java index 6f68f57..ef339bd 100644 --- a/src/main/java/org/libvirt/Error.java +++ b/src/main/java/org/libvirt/Error.java @@ -228,9 +228,9 @@ public class Error implements Serializable { } /** - * Gets he error code + * Gets the error code * - * @return a VirErroNumber + * @return a VirErrorNumber */ public ErrorNumber getCode() { return code; @@ -294,7 +294,7 @@ public class Error implements Serializable { } /** - * Returns human-readable informative error messag + * Returns a human-readable informative error message * * @return error message */ -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:11PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Error.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/libvirt/Error.java b/src/main/java/org/libvirt/Error.java index 6f68f57..ef339bd 100644 --- a/src/main/java/org/libvirt/Error.java +++ b/src/main/java/org/libvirt/Error.java @@ -228,9 +228,9 @@ public class Error implements Serializable { }
/** - * Gets he error code + * Gets the error code * - * @return a VirErroNumber + * @return a VirErrorNumber */ public ErrorNumber getCode() { return code; @@ -294,7 +294,7 @@ public class Error implements Serializable { }
/** - * Returns human-readable informative error messag + * Returns a human-readable informative error message * * @return error message */
ACK (from a non Java expert). -- Guido
-- 1.7.9.5
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Thu, Feb 13, 2014 at 04:22:11PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Error.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:34:05 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:11PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Error.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
ACK
Thanks, pushed.

Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/test/java/org/libvirt/TestJavaBindings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/libvirt/TestJavaBindings.java b/src/test/java/org/libvirt/TestJavaBindings.java index bba4cdb..9e7fa82 100644 --- a/src/test/java/org/libvirt/TestJavaBindings.java +++ b/src/test/java/org/libvirt/TestJavaBindings.java @@ -40,7 +40,7 @@ public final class TestJavaBindings extends TestCase { assertNotNull("conn.getCapabilities()", conn.getCapabilities()); assertTrue("conn.getLibVirVersion()", conn.getLibVirVersion() > 6000); assertTrue("conn.connectionVersion()", Connect.connectionVersion(conn) > 6000); - assertEquals("conn.getLibVirVersion()", 2, conn.getVersion()); + assertEquals("conn.getVersion()", 2, conn.getVersion()); assertTrue("conn.isEncrypted", conn.isEncrypted() == 0); assertTrue("conn.isSecure", conn.isSecure() == 1); } -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:12PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/test/java/org/libvirt/TestJavaBindings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:34:24 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:12PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/test/java/org/libvirt/TestJavaBindings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ACK
Thanks, pushed.

Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/test/java/org/libvirt/TestJavaBindings.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/org/libvirt/TestJavaBindings.java b/src/test/java/org/libvirt/TestJavaBindings.java index 9e7fa82..a25c4f3 100644 --- a/src/test/java/org/libvirt/TestJavaBindings.java +++ b/src/test/java/org/libvirt/TestJavaBindings.java @@ -27,6 +27,7 @@ public final class TestJavaBindings extends TestCase { try { conn.domainDefineXML("fail, miserably"); + fail("LibvirtException expected"); } catch (LibvirtException e) {} // ignore assertTrue("Error callback was not called", cb.error); @@ -87,6 +88,7 @@ public final class TestJavaBindings extends TestCase { // this should throw an exception try { network1.create(); + fail("LibvirtException expected"); } catch (LibvirtException e) { // eat it } -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:13PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/test/java/org/libvirt/TestJavaBindings.java | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/src/test/java/org/libvirt/TestJavaBindings.java b/src/test/java/org/libvirt/TestJavaBindings.java index 9e7fa82..a25c4f3 100644 --- a/src/test/java/org/libvirt/TestJavaBindings.java +++ b/src/test/java/org/libvirt/TestJavaBindings.java @@ -27,6 +27,7 @@ public final class TestJavaBindings extends TestCase {
try { conn.domainDefineXML("fail, miserably"); + fail("LibvirtException expected"); } catch (LibvirtException e) {} // ignore
assertTrue("Error callback was not called", cb.error); @@ -87,6 +88,7 @@ public final class TestJavaBindings extends TestCase { // this should throw an exception try { network1.create(); + fail("LibvirtException expected"); } catch (LibvirtException e) { // eat it }
ACK (from a non Java expert). -- Guido

On Thu, Feb 13, 2014 at 04:22:13PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/test/java/org/libvirt/TestJavaBindings.java | 2 ++ 1 file changed, 2 insertions(+)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:34:52 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:13PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/test/java/org/libvirt/TestJavaBindings.java | 2 ++ 1 file changed, 2 insertions(+)
ACK
Thanks, pushed.

Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Error.java | 397 ++++++++++++++++++++++------------ 1 file changed, 262 insertions(+), 135 deletions(-) diff --git a/src/main/java/org/libvirt/Error.java b/src/main/java/org/libvirt/Error.java index ef339bd..15dd870 100644 --- a/src/main/java/org/libvirt/Error.java +++ b/src/main/java/org/libvirt/Error.java @@ -28,54 +28,104 @@ public class Error implements Serializable { } public static enum ErrorDomain { - VIR_FROM_NONE, VIR_FROM_XEN, /* Error at Xen hypervisor layer */ - VIR_FROM_XEND, /* Error at connection with xend daemon */ - VIR_FROM_XENSTORE, /* Error at connection with xen store */ - VIR_FROM_SEXPR, /* Error in the S-Expression code */ - VIR_FROM_XML, /* Error in the XML code */ - VIR_FROM_DOM, /* Error when operating on a domain */ - VIR_FROM_RPC, /* Error in the XML-RPC code */ - VIR_FROM_PROXY, /* Error in the proxy code */ - VIR_FROM_CONF, /* Error in the configuration file handling */ - VIR_FROM_QEMU, /* Error at the QEMU daemon */ - VIR_FROM_NET, /* Error when operating on a network */ - VIR_FROM_TEST, /* Error from test driver */ - VIR_FROM_REMOTE, /* Error from remote driver */ - VIR_FROM_OPENVZ, /* Error from OpenVZ driver */ - VIR_FROM_XENXM, /* Error at Xen XM layer */ - VIR_FROM_STATS_LINUX, /* Error in the Linux Stats code */ - VIR_FROM_LXC, /* Error from Linux Container driver */ - VIR_FROM_STORAGE, /* Error from storage driver */ - VIR_FROM_NETWORK, /* Error from network config */ - VIR_FROM_DOMAIN, /* Error from domain config */ - VIR_FROM_UML, /* Error at the UML driver */ - VIR_FROM_NODEDEV, /* Error from node device monitor */ - VIR_FROM_XEN_INOTIFY, /* Error from xen inotify layer */ - VIR_FROM_SECURITY, /* Error from security framework */ - VIR_FROM_VBOX, /* Error from VirtualBox driver */ - VIR_FROM_INTERFACE, /* Error when operating on an interface */ - VIR_FROM_ONE, /* Error from OpenNebula driver */ - VIR_FROM_ESX, /* Error from ESX driver */ - VIR_FROM_PHYP, /* Error from IBM power hypervisor */ - VIR_FROM_SECRET, /* Error from secret storage */ - VIR_FROM_CPU, /* Error from CPU driver */ - VIR_FROM_XENAPI, /* Error from XenAPI */ - VIR_FROM_NWFILTER, /* Error from network filter driver */ - VIR_FROM_HOOK, /* Error from Synchronous hooks */ - VIR_FROM_DOMAIN_SNAPSHOT, /* Error from domain snapshot */ - VIR_FROM_AUDIT, /* Error from auditing subsystem */ - VIR_FROM_SYSINFO, /* Error from sysinfo/SMBIOS */ - VIR_FROM_STREAMS, /* Error from I/O streams */ - VIR_FROM_VMWARE, /* Error from VMware driver */ - VIR_FROM_EVENT, /* Error from event loop impl */ - VIR_FROM_LIBXL, /* Error from libxenlight driver */ - VIR_FROM_LOCKING, /* Error from lock manager */ - VIR_FROM_HYPERV, /* Error from Hyper-V driver */ - VIR_FROM_CAPABILITIES, /* Error from capabilities */ - VIR_FROM_URI, /* Error from URI handling */ - VIR_FROM_AUTH, /* Error from auth handling */ - VIR_FROM_DBUS, /* Error from DBus */ - VIR_FROM_UNKNOWN; /* unknown error domain (must be the last entry!) */ + VIR_FROM_NONE, + /** Error at Xen hypervisor layer */ + VIR_FROM_XEN, + /** Error at connection with xend daemon */ + VIR_FROM_XEND, + /** Error at connection with xen store */ + VIR_FROM_XENSTORE, + /** Error in the S-Expression code */ + VIR_FROM_SEXPR, + /** Error in the XML code */ + VIR_FROM_XML, + /** Error when operating on a domain */ + VIR_FROM_DOM, + /** Error in the XML-RPC code */ + VIR_FROM_RPC, + /** Error in the proxy code */ + VIR_FROM_PROXY, + /** Error in the configuration file handling */ + VIR_FROM_CONF, + /** Error at the QEMU daemon */ + VIR_FROM_QEMU, + /** Error when operating on a network */ + VIR_FROM_NET, + /** Error from test driver */ + VIR_FROM_TEST, + /** Error from remote driver */ + VIR_FROM_REMOTE, + /** Error from OpenVZ driver */ + VIR_FROM_OPENVZ, + /** Error at Xen XM layer */ + VIR_FROM_XENXM, + /** Error in the Linux Stats code */ + VIR_FROM_STATS_LINUX, + /** Error from Linux Container driver */ + VIR_FROM_LXC, + /** Error from storage driver */ + VIR_FROM_STORAGE, + /** Error from network config */ + VIR_FROM_NETWORK, + /** Error from domain config */ + VIR_FROM_DOMAIN, + /** Error at the UML driver */ + VIR_FROM_UML, + /** Error from node device monitor */ + VIR_FROM_NODEDEV, + /** Error from xen inotify layer */ + VIR_FROM_XEN_INOTIFY, + /** Error from security framework */ + VIR_FROM_SECURITY, + /** Error from VirtualBox driver */ + VIR_FROM_VBOX, + /** Error when operating on an interface */ + VIR_FROM_INTERFACE, + /** Error from OpenNebula driver */ + VIR_FROM_ONE, + /** Error from ESX driver */ + VIR_FROM_ESX, + /** Error from IBM power hypervisor */ + VIR_FROM_PHYP, + /** Error from secret storage */ + VIR_FROM_SECRET, + /** Error from CPU driver */ + VIR_FROM_CPU, + /** Error from XenAPI */ + VIR_FROM_XENAPI, + /** Error from network filter driver */ + VIR_FROM_NWFILTER, + /** Error from Synchronous hooks */ + VIR_FROM_HOOK, + /** Error from domain snapshot */ + VIR_FROM_DOMAIN_SNAPSHOT, + /** Error from auditing subsystem */ + VIR_FROM_AUDIT, + /** Error from sysinfo/SMBIOS */ + VIR_FROM_SYSINFO, + /** Error from I/O streams */ + VIR_FROM_STREAMS, + /** Error from VMware driver */ + VIR_FROM_VMWARE, + /** Error from event loop impl */ + VIR_FROM_EVENT, + /** Error from libxenlight driver */ + VIR_FROM_LIBXL, + /** Error from lock manager */ + VIR_FROM_LOCKING, + /** Error from Hyper-V driver */ + VIR_FROM_HYPERV, + /** Error from capabilities */ + VIR_FROM_CAPABILITIES, + /** Error from URI handling */ + VIR_FROM_URI, + /** Error from auth handling */ + VIR_FROM_AUTH, + /** Error from DBus */ + VIR_FROM_DBUS, + + /** unknown error domain */ + VIR_FROM_UNKNOWN; // must be the last entry! protected static final ErrorDomain wrap(int value) { return safeElementAt(value, values()); @@ -101,93 +151,170 @@ public class Error implements Serializable { } public static enum ErrorNumber { - VIR_ERR_OK, VIR_ERR_INTERNAL_ERROR, /* internal error */ - VIR_ERR_NO_MEMORY, /* memory allocation failure */ - VIR_ERR_NO_SUPPORT, /* no support for this function */ - VIR_ERR_UNKNOWN_HOST, /* could not resolve hostname */ - VIR_ERR_NO_CONNECT, /* can't connect to hypervisor */ - VIR_ERR_INVALID_CONN, /* invalid connection object */ - VIR_ERR_INVALID_DOMAIN, /* invalid domain object */ - VIR_ERR_INVALID_ARG, /* invalid function argument */ - VIR_ERR_OPERATION_FAILED, /* a command to hypervisor failed */ - VIR_ERR_GET_FAILED, /* a HTTP GET command to failed */ - VIR_ERR_POST_FAILED, /* a HTTP POST command to failed */ - VIR_ERR_HTTP_ERROR, /* unexpected HTTP error code */ - VIR_ERR_SEXPR_SERIAL, /* failure to serialize an S-Expr */ - VIR_ERR_NO_XEN, /* could not open Xen hypervisor control */ - VIR_ERR_XEN_CALL, /* failure doing an hypervisor call */ - VIR_ERR_OS_TYPE, /* unknown OS type */ - VIR_ERR_NO_KERNEL, /* missing kernel information */ - VIR_ERR_NO_ROOT, /* missing root device information */ - VIR_ERR_NO_SOURCE, /* missing source device information */ - VIR_ERR_NO_TARGET, /* missing target device information */ - VIR_ERR_NO_NAME, /* missing domain name information */ - VIR_ERR_NO_OS, /* missing domain OS information */ - VIR_ERR_NO_DEVICE, /* missing domain devices information */ - VIR_ERR_NO_XENSTORE, /* could not open Xen Store control */ - VIR_ERR_DRIVER_FULL, /* too many drivers registered */ - VIR_ERR_CALL_FAILED, /* not supported by the drivers (DEPRECATED) */ - VIR_ERR_XML_ERROR, /* an XML description is not well formed or broken */ - VIR_ERR_DOM_EXIST, /* the domain already exist */ - VIR_ERR_OPERATION_DENIED, /* - * operation forbidden on read-only - * connections - */ - VIR_ERR_OPEN_FAILED, /* failed to open a conf file */ - VIR_ERR_READ_FAILED, /* failed to read a conf file */ - VIR_ERR_PARSE_FAILED, /* failed to parse a conf file */ - VIR_ERR_CONF_SYNTAX, /* failed to parse the syntax of a conf file */ - VIR_ERR_WRITE_FAILED, /* failed to write a conf file */ - VIR_ERR_XML_DETAIL, /* detail of an XML error */ - VIR_ERR_INVALID_NETWORK, /* invalid network object */ - VIR_ERR_NETWORK_EXIST, /* the network already exist */ - VIR_ERR_SYSTEM_ERROR, /* general system call failure */ - VIR_ERR_RPC, /* some sort of RPC error */ - VIR_ERR_GNUTLS_ERROR, /* error from a GNUTLS call */ - VIR_WAR_NO_NETWORK, /* failed to start network */ - VIR_ERR_NO_DOMAIN, /* domain not found or unexpectedly disappeared */ - VIR_ERR_NO_NETWORK, /* network not found */ - VIR_ERR_INVALID_MAC, /* invalid MAC address */ - VIR_ERR_AUTH_FAILED, /* authentication failed */ - VIR_ERR_INVALID_STORAGE_POOL, /* invalid storage pool object */ - VIR_ERR_INVALID_STORAGE_VOL, /* invalid storage vol object */ - VIR_WAR_NO_STORAGE, /* failed to start storage */ - VIR_ERR_NO_STORAGE_POOL, /* storage pool not found */ - VIR_ERR_NO_STORAGE_VOL, /* storage pool not found */ - VIR_WAR_NO_NODE, /* failed to start node driver */ - VIR_ERR_INVALID_NODE_DEVICE, /* invalid node device object */ - VIR_ERR_NO_NODE_DEVICE, /* node device not found */ - VIR_ERR_NO_SECURITY_MODEL, /* security model not found */ - VIR_ERR_OPERATION_INVALID, /* operation is not applicable at this time */ - VIR_WAR_NO_INTERFACE, /* failed to start interface driver */ - VIR_ERR_NO_INTERFACE, /* interface driver not running */ - VIR_ERR_INVALID_INTERFACE, /* invalid interface object */ - VIR_ERR_MULTIPLE_INTERFACES, /* more than one matching interface found */ - VIR_WAR_NO_SECRET, /* failed to start secret storage */ - VIR_ERR_INVALID_SECRET, /* invalid secret */ - VIR_ERR_NO_SECRET, /* secret not found */ - VIR_ERR_CONFIG_UNSUPPORTED, /* unsupported configuration construct */ - VIR_ERR_OPERATION_TIMEOUT, /* timeout occurred during operation */ - VIR_ERR_MIGRATE_PERSIST_FAILED, /* a migration worked, but making the - VM persist on the dest host failed */ - VIR_ERR_HOOK_SCRIPT_FAILED, /* a synchronous hook script failed */ - VIR_ERR_INVALID_DOMAIN_SNAPSHOT, /* invalid domain snapshot */ - VIR_ERR_NO_DOMAIN_SNAPSHOT, /* domain snapshot not found */ - VIR_ERR_INVALID_STREAM, /* stream pointer not valid */ - VIR_ERR_ARGUMENT_UNSUPPORTED, /* valid API use but unsupported by - the given driver */ - VIR_ERR_STORAGE_PROBE_FAILED, /* storage pool probe failed */ - VIR_ERR_STORAGE_POOL_BUILT, /* storage pool already built */ - VIR_ERR_SNAPSHOT_REVERT_RISKY, /* force was not requested for a - risky domain snapshot revert */ - VIR_ERR_OPERATION_ABORTED, /* operation on a domain was - canceled/aborted by user */ - VIR_ERR_AUTH_CANCELLED, /* authentication cancelled */ - VIR_ERR_NO_DOMAIN_METADATA, /* The metadata is not present */ - VIR_ERR_MIGRATE_UNSAFE, /* Migration is not safe */ - VIR_ERR_OVERFLOW, /* integer overflow */ - VIR_ERR_BLOCK_COPY_ACTIVE, /* action prevented by block copy job */ - VIR_ERR_UNKNOWN; /* unknown error (must be the last entry!) */ + VIR_ERR_OK, + /** internal error */ + VIR_ERR_INTERNAL_ERROR, + /** memory allocation failure */ + VIR_ERR_NO_MEMORY, + /** no support for this function */ + VIR_ERR_NO_SUPPORT, + /** could not resolve hostname */ + VIR_ERR_UNKNOWN_HOST, + /** can't connect to hypervisor */ + VIR_ERR_NO_CONNECT, + /** invalid connection object */ + VIR_ERR_INVALID_CONN, + /** invalid domain object */ + VIR_ERR_INVALID_DOMAIN, + /** invalid function argument */ + VIR_ERR_INVALID_ARG, + /** a command to hypervisor failed */ + VIR_ERR_OPERATION_FAILED, + /** a HTTP GET command to failed */ + VIR_ERR_GET_FAILED, + /** a HTTP POST command to failed */ + VIR_ERR_POST_FAILED, + /** unexpected HTTP error code */ + VIR_ERR_HTTP_ERROR, + /** failure to serialize an S-Expr */ + VIR_ERR_SEXPR_SERIAL, + /** could not open Xen hypervisor control */ + VIR_ERR_NO_XEN, + /** failure doing an hypervisor call */ + VIR_ERR_XEN_CALL, + /** unknown OS type */ + VIR_ERR_OS_TYPE, + /** missing kernel information */ + VIR_ERR_NO_KERNEL, + /** missing root device information */ + VIR_ERR_NO_ROOT, + /** missing source device information */ + VIR_ERR_NO_SOURCE, + /** missing target device information */ + VIR_ERR_NO_TARGET, + /** missing domain name information */ + VIR_ERR_NO_NAME, + /** missing domain OS information */ + VIR_ERR_NO_OS, + /** missing domain devices information */ + VIR_ERR_NO_DEVICE, + /** could not open Xen Store control */ + VIR_ERR_NO_XENSTORE, + /** too many drivers registered */ + VIR_ERR_DRIVER_FULL, + /** not supported by the drivers (DEPRECATED) */ + VIR_ERR_CALL_FAILED, + /** an XML description is not well formed or broken */ + VIR_ERR_XML_ERROR, + /** the domain already exist */ + VIR_ERR_DOM_EXIST, + /** operation forbidden on read-only connections */ + VIR_ERR_OPERATION_DENIED, + /** failed to open a conf file */ + VIR_ERR_OPEN_FAILED, + /** failed to read a conf file */ + VIR_ERR_READ_FAILED, + /** failed to parse a conf file */ + VIR_ERR_PARSE_FAILED, + /** failed to parse the syntax of a conf file */ + VIR_ERR_CONF_SYNTAX, + /** failed to write a conf file */ + VIR_ERR_WRITE_FAILED, + /** detail of an XML error */ + VIR_ERR_XML_DETAIL, + /** invalid network object */ + VIR_ERR_INVALID_NETWORK, + /** the network already exist */ + VIR_ERR_NETWORK_EXIST, + /** general system call failure */ + VIR_ERR_SYSTEM_ERROR, + /** some sort of RPC error */ + VIR_ERR_RPC, + /** error from a GNUTLS call */ + VIR_ERR_GNUTLS_ERROR, + /** failed to start network */ + VIR_WAR_NO_NETWORK, + /** domain not found or unexpectedly disappeared */ + VIR_ERR_NO_DOMAIN, + /** network not found */ + VIR_ERR_NO_NETWORK, + /** invalid MAC address */ + VIR_ERR_INVALID_MAC, + /** authentication failed */ + VIR_ERR_AUTH_FAILED, + /** invalid storage pool object */ + VIR_ERR_INVALID_STORAGE_POOL, + /** invalid storage vol object */ + VIR_ERR_INVALID_STORAGE_VOL, + /** failed to start storage */ + VIR_WAR_NO_STORAGE, + /** storage pool not found */ + VIR_ERR_NO_STORAGE_POOL, + /** storage pool not found */ + VIR_ERR_NO_STORAGE_VOL, + /** failed to start node driver */ + VIR_WAR_NO_NODE, + /** invalid node device object */ + VIR_ERR_INVALID_NODE_DEVICE, + /** node device not found */ + VIR_ERR_NO_NODE_DEVICE, + /** security model not found */ + VIR_ERR_NO_SECURITY_MODEL, + /** operation is not applicable at this time */ + VIR_ERR_OPERATION_INVALID, + /** failed to start interface driver */ + VIR_WAR_NO_INTERFACE, + /** interface driver not running */ + VIR_ERR_NO_INTERFACE, + /** invalid interface object */ + VIR_ERR_INVALID_INTERFACE, + /** more than one matching interface found */ + VIR_ERR_MULTIPLE_INTERFACES, + /** failed to start secret storage */ + VIR_WAR_NO_SECRET, + /** invalid secret */ + VIR_ERR_INVALID_SECRET, + /** secret not found */ + VIR_ERR_NO_SECRET, + /** unsupported configuration construct */ + VIR_ERR_CONFIG_UNSUPPORTED, + /** timeout occurred during operation */ + VIR_ERR_OPERATION_TIMEOUT, + /** a migration worked, but making the VM persist on the dest + * host failed */ + VIR_ERR_MIGRATE_PERSIST_FAILED, + /** a synchronous hook script failed */ + VIR_ERR_HOOK_SCRIPT_FAILED, + /** invalid domain snapshot */ + VIR_ERR_INVALID_DOMAIN_SNAPSHOT, + /** domain snapshot not found */ + VIR_ERR_NO_DOMAIN_SNAPSHOT, + /** stream pointer not valid */ + VIR_ERR_INVALID_STREAM, + /** valid API use but unsupported by the given driver */ + VIR_ERR_ARGUMENT_UNSUPPORTED, + /** storage pool probe failed */ + VIR_ERR_STORAGE_PROBE_FAILED, + /** storage pool already built */ + VIR_ERR_STORAGE_POOL_BUILT, + /** force was not requested for a risky domain snapshot + revert */ + VIR_ERR_SNAPSHOT_REVERT_RISKY, + /** operation on a domain was canceled/aborted by user */ + VIR_ERR_OPERATION_ABORTED, + /** authentication cancelled */ + VIR_ERR_AUTH_CANCELLED, + /** The metadata is not present */ + VIR_ERR_NO_DOMAIN_METADATA, + /** Migration is not safe */ + VIR_ERR_MIGRATE_UNSAFE, + /** integer overflow */ + VIR_ERR_OVERFLOW, + /** action prevented by block copy job */ + VIR_ERR_BLOCK_COPY_ACTIVE, + + /** unknown error */ + VIR_ERR_UNKNOWN; // must be the last entry! protected static final ErrorNumber wrap(int value) { return safeElementAt(value, values()); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:14PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Error.java | 397 ++++++++++++++++++++++------------ 1 file changed, 262 insertions(+), 135 deletions(-)
diff --git a/src/main/java/org/libvirt/Error.java b/src/main/java/org/libvirt/Error.java index ef339bd..15dd870 100644 --- a/src/main/java/org/libvirt/Error.java +++ b/src/main/java/org/libvirt/Error.java @@ -28,54 +28,104 @@ public class Error implements Serializable { }
public static enum ErrorDomain { - VIR_FROM_NONE, VIR_FROM_XEN, /* Error at Xen hypervisor layer */ - VIR_FROM_XEND, /* Error at connection with xend daemon */ - VIR_FROM_XENSTORE, /* Error at connection with xen store */ - VIR_FROM_SEXPR, /* Error in the S-Expression code */ - VIR_FROM_XML, /* Error in the XML code */ - VIR_FROM_DOM, /* Error when operating on a domain */ - VIR_FROM_RPC, /* Error in the XML-RPC code */ - VIR_FROM_PROXY, /* Error in the proxy code */ - VIR_FROM_CONF, /* Error in the configuration file handling */ - VIR_FROM_QEMU, /* Error at the QEMU daemon */ - VIR_FROM_NET, /* Error when operating on a network */ - VIR_FROM_TEST, /* Error from test driver */ - VIR_FROM_REMOTE, /* Error from remote driver */ - VIR_FROM_OPENVZ, /* Error from OpenVZ driver */ - VIR_FROM_XENXM, /* Error at Xen XM layer */ - VIR_FROM_STATS_LINUX, /* Error in the Linux Stats code */ - VIR_FROM_LXC, /* Error from Linux Container driver */ - VIR_FROM_STORAGE, /* Error from storage driver */ - VIR_FROM_NETWORK, /* Error from network config */ - VIR_FROM_DOMAIN, /* Error from domain config */ - VIR_FROM_UML, /* Error at the UML driver */ - VIR_FROM_NODEDEV, /* Error from node device monitor */ - VIR_FROM_XEN_INOTIFY, /* Error from xen inotify layer */ - VIR_FROM_SECURITY, /* Error from security framework */ - VIR_FROM_VBOX, /* Error from VirtualBox driver */ - VIR_FROM_INTERFACE, /* Error when operating on an interface */ - VIR_FROM_ONE, /* Error from OpenNebula driver */ - VIR_FROM_ESX, /* Error from ESX driver */ - VIR_FROM_PHYP, /* Error from IBM power hypervisor */ - VIR_FROM_SECRET, /* Error from secret storage */ - VIR_FROM_CPU, /* Error from CPU driver */ - VIR_FROM_XENAPI, /* Error from XenAPI */ - VIR_FROM_NWFILTER, /* Error from network filter driver */ - VIR_FROM_HOOK, /* Error from Synchronous hooks */ - VIR_FROM_DOMAIN_SNAPSHOT, /* Error from domain snapshot */ - VIR_FROM_AUDIT, /* Error from auditing subsystem */ - VIR_FROM_SYSINFO, /* Error from sysinfo/SMBIOS */ - VIR_FROM_STREAMS, /* Error from I/O streams */ - VIR_FROM_VMWARE, /* Error from VMware driver */ - VIR_FROM_EVENT, /* Error from event loop impl */ - VIR_FROM_LIBXL, /* Error from libxenlight driver */ - VIR_FROM_LOCKING, /* Error from lock manager */ - VIR_FROM_HYPERV, /* Error from Hyper-V driver */ - VIR_FROM_CAPABILITIES, /* Error from capabilities */ - VIR_FROM_URI, /* Error from URI handling */ - VIR_FROM_AUTH, /* Error from auth handling */ - VIR_FROM_DBUS, /* Error from DBus */ - VIR_FROM_UNKNOWN; /* unknown error domain (must be the last entry!) */ + VIR_FROM_NONE, + /** Error at Xen hypervisor layer */ + VIR_FROM_XEN, + /** Error at connection with xend daemon */ + VIR_FROM_XEND, + /** Error at connection with xen store */ + VIR_FROM_XENSTORE, + /** Error in the S-Expression code */ + VIR_FROM_SEXPR, + /** Error in the XML code */ + VIR_FROM_XML, + /** Error when operating on a domain */ + VIR_FROM_DOM, + /** Error in the XML-RPC code */ + VIR_FROM_RPC, + /** Error in the proxy code */ + VIR_FROM_PROXY, + /** Error in the configuration file handling */ + VIR_FROM_CONF, + /** Error at the QEMU daemon */ + VIR_FROM_QEMU, + /** Error when operating on a network */ + VIR_FROM_NET, + /** Error from test driver */ + VIR_FROM_TEST, + /** Error from remote driver */ + VIR_FROM_REMOTE, + /** Error from OpenVZ driver */ + VIR_FROM_OPENVZ, + /** Error at Xen XM layer */ + VIR_FROM_XENXM, + /** Error in the Linux Stats code */ + VIR_FROM_STATS_LINUX, + /** Error from Linux Container driver */ + VIR_FROM_LXC, + /** Error from storage driver */ + VIR_FROM_STORAGE, + /** Error from network config */ + VIR_FROM_NETWORK, + /** Error from domain config */ + VIR_FROM_DOMAIN, + /** Error at the UML driver */ + VIR_FROM_UML, + /** Error from node device monitor */ + VIR_FROM_NODEDEV, + /** Error from xen inotify layer */ + VIR_FROM_XEN_INOTIFY, + /** Error from security framework */ + VIR_FROM_SECURITY, + /** Error from VirtualBox driver */ + VIR_FROM_VBOX, + /** Error when operating on an interface */ + VIR_FROM_INTERFACE, + /** Error from OpenNebula driver */ + VIR_FROM_ONE, + /** Error from ESX driver */ + VIR_FROM_ESX, + /** Error from IBM power hypervisor */ + VIR_FROM_PHYP, + /** Error from secret storage */ + VIR_FROM_SECRET, + /** Error from CPU driver */ + VIR_FROM_CPU, + /** Error from XenAPI */ + VIR_FROM_XENAPI, + /** Error from network filter driver */ + VIR_FROM_NWFILTER, + /** Error from Synchronous hooks */ + VIR_FROM_HOOK, + /** Error from domain snapshot */ + VIR_FROM_DOMAIN_SNAPSHOT, + /** Error from auditing subsystem */ + VIR_FROM_AUDIT, + /** Error from sysinfo/SMBIOS */ + VIR_FROM_SYSINFO, + /** Error from I/O streams */ + VIR_FROM_STREAMS, + /** Error from VMware driver */ + VIR_FROM_VMWARE, + /** Error from event loop impl */ + VIR_FROM_EVENT, + /** Error from libxenlight driver */ + VIR_FROM_LIBXL, + /** Error from lock manager */ + VIR_FROM_LOCKING, + /** Error from Hyper-V driver */ + VIR_FROM_HYPERV, + /** Error from capabilities */ + VIR_FROM_CAPABILITIES, + /** Error from URI handling */ + VIR_FROM_URI, + /** Error from auth handling */ + VIR_FROM_AUTH, + /** Error from DBus */ + VIR_FROM_DBUS, + + /** unknown error domain */ + VIR_FROM_UNKNOWN; // must be the last entry!
protected static final ErrorDomain wrap(int value) { return safeElementAt(value, values()); @@ -101,93 +151,170 @@ public class Error implements Serializable { }
public static enum ErrorNumber { - VIR_ERR_OK, VIR_ERR_INTERNAL_ERROR, /* internal error */ - VIR_ERR_NO_MEMORY, /* memory allocation failure */ - VIR_ERR_NO_SUPPORT, /* no support for this function */ - VIR_ERR_UNKNOWN_HOST, /* could not resolve hostname */ - VIR_ERR_NO_CONNECT, /* can't connect to hypervisor */ - VIR_ERR_INVALID_CONN, /* invalid connection object */ - VIR_ERR_INVALID_DOMAIN, /* invalid domain object */ - VIR_ERR_INVALID_ARG, /* invalid function argument */ - VIR_ERR_OPERATION_FAILED, /* a command to hypervisor failed */ - VIR_ERR_GET_FAILED, /* a HTTP GET command to failed */ - VIR_ERR_POST_FAILED, /* a HTTP POST command to failed */ - VIR_ERR_HTTP_ERROR, /* unexpected HTTP error code */ - VIR_ERR_SEXPR_SERIAL, /* failure to serialize an S-Expr */ - VIR_ERR_NO_XEN, /* could not open Xen hypervisor control */ - VIR_ERR_XEN_CALL, /* failure doing an hypervisor call */ - VIR_ERR_OS_TYPE, /* unknown OS type */ - VIR_ERR_NO_KERNEL, /* missing kernel information */ - VIR_ERR_NO_ROOT, /* missing root device information */ - VIR_ERR_NO_SOURCE, /* missing source device information */ - VIR_ERR_NO_TARGET, /* missing target device information */ - VIR_ERR_NO_NAME, /* missing domain name information */ - VIR_ERR_NO_OS, /* missing domain OS information */ - VIR_ERR_NO_DEVICE, /* missing domain devices information */ - VIR_ERR_NO_XENSTORE, /* could not open Xen Store control */ - VIR_ERR_DRIVER_FULL, /* too many drivers registered */ - VIR_ERR_CALL_FAILED, /* not supported by the drivers (DEPRECATED) */ - VIR_ERR_XML_ERROR, /* an XML description is not well formed or broken */ - VIR_ERR_DOM_EXIST, /* the domain already exist */ - VIR_ERR_OPERATION_DENIED, /* - * operation forbidden on read-only - * connections - */ - VIR_ERR_OPEN_FAILED, /* failed to open a conf file */ - VIR_ERR_READ_FAILED, /* failed to read a conf file */ - VIR_ERR_PARSE_FAILED, /* failed to parse a conf file */ - VIR_ERR_CONF_SYNTAX, /* failed to parse the syntax of a conf file */ - VIR_ERR_WRITE_FAILED, /* failed to write a conf file */ - VIR_ERR_XML_DETAIL, /* detail of an XML error */ - VIR_ERR_INVALID_NETWORK, /* invalid network object */ - VIR_ERR_NETWORK_EXIST, /* the network already exist */ - VIR_ERR_SYSTEM_ERROR, /* general system call failure */ - VIR_ERR_RPC, /* some sort of RPC error */ - VIR_ERR_GNUTLS_ERROR, /* error from a GNUTLS call */ - VIR_WAR_NO_NETWORK, /* failed to start network */ - VIR_ERR_NO_DOMAIN, /* domain not found or unexpectedly disappeared */ - VIR_ERR_NO_NETWORK, /* network not found */ - VIR_ERR_INVALID_MAC, /* invalid MAC address */ - VIR_ERR_AUTH_FAILED, /* authentication failed */ - VIR_ERR_INVALID_STORAGE_POOL, /* invalid storage pool object */ - VIR_ERR_INVALID_STORAGE_VOL, /* invalid storage vol object */ - VIR_WAR_NO_STORAGE, /* failed to start storage */ - VIR_ERR_NO_STORAGE_POOL, /* storage pool not found */ - VIR_ERR_NO_STORAGE_VOL, /* storage pool not found */ - VIR_WAR_NO_NODE, /* failed to start node driver */ - VIR_ERR_INVALID_NODE_DEVICE, /* invalid node device object */ - VIR_ERR_NO_NODE_DEVICE, /* node device not found */ - VIR_ERR_NO_SECURITY_MODEL, /* security model not found */ - VIR_ERR_OPERATION_INVALID, /* operation is not applicable at this time */ - VIR_WAR_NO_INTERFACE, /* failed to start interface driver */ - VIR_ERR_NO_INTERFACE, /* interface driver not running */ - VIR_ERR_INVALID_INTERFACE, /* invalid interface object */ - VIR_ERR_MULTIPLE_INTERFACES, /* more than one matching interface found */ - VIR_WAR_NO_SECRET, /* failed to start secret storage */ - VIR_ERR_INVALID_SECRET, /* invalid secret */ - VIR_ERR_NO_SECRET, /* secret not found */ - VIR_ERR_CONFIG_UNSUPPORTED, /* unsupported configuration construct */ - VIR_ERR_OPERATION_TIMEOUT, /* timeout occurred during operation */ - VIR_ERR_MIGRATE_PERSIST_FAILED, /* a migration worked, but making the - VM persist on the dest host failed */ - VIR_ERR_HOOK_SCRIPT_FAILED, /* a synchronous hook script failed */ - VIR_ERR_INVALID_DOMAIN_SNAPSHOT, /* invalid domain snapshot */ - VIR_ERR_NO_DOMAIN_SNAPSHOT, /* domain snapshot not found */ - VIR_ERR_INVALID_STREAM, /* stream pointer not valid */ - VIR_ERR_ARGUMENT_UNSUPPORTED, /* valid API use but unsupported by - the given driver */ - VIR_ERR_STORAGE_PROBE_FAILED, /* storage pool probe failed */ - VIR_ERR_STORAGE_POOL_BUILT, /* storage pool already built */ - VIR_ERR_SNAPSHOT_REVERT_RISKY, /* force was not requested for a - risky domain snapshot revert */ - VIR_ERR_OPERATION_ABORTED, /* operation on a domain was - canceled/aborted by user */ - VIR_ERR_AUTH_CANCELLED, /* authentication cancelled */ - VIR_ERR_NO_DOMAIN_METADATA, /* The metadata is not present */ - VIR_ERR_MIGRATE_UNSAFE, /* Migration is not safe */ - VIR_ERR_OVERFLOW, /* integer overflow */ - VIR_ERR_BLOCK_COPY_ACTIVE, /* action prevented by block copy job */ - VIR_ERR_UNKNOWN; /* unknown error (must be the last entry!) */ + VIR_ERR_OK, + /** internal error */ + VIR_ERR_INTERNAL_ERROR, + /** memory allocation failure */ + VIR_ERR_NO_MEMORY, + /** no support for this function */ + VIR_ERR_NO_SUPPORT, + /** could not resolve hostname */ + VIR_ERR_UNKNOWN_HOST, + /** can't connect to hypervisor */ + VIR_ERR_NO_CONNECT, + /** invalid connection object */ + VIR_ERR_INVALID_CONN, + /** invalid domain object */ + VIR_ERR_INVALID_DOMAIN, + /** invalid function argument */ + VIR_ERR_INVALID_ARG, + /** a command to hypervisor failed */ + VIR_ERR_OPERATION_FAILED, + /** a HTTP GET command to failed */ + VIR_ERR_GET_FAILED, + /** a HTTP POST command to failed */ + VIR_ERR_POST_FAILED, + /** unexpected HTTP error code */ + VIR_ERR_HTTP_ERROR, + /** failure to serialize an S-Expr */ + VIR_ERR_SEXPR_SERIAL, + /** could not open Xen hypervisor control */ + VIR_ERR_NO_XEN, + /** failure doing an hypervisor call */ + VIR_ERR_XEN_CALL, + /** unknown OS type */ + VIR_ERR_OS_TYPE, + /** missing kernel information */ + VIR_ERR_NO_KERNEL, + /** missing root device information */ + VIR_ERR_NO_ROOT, + /** missing source device information */ + VIR_ERR_NO_SOURCE, + /** missing target device information */ + VIR_ERR_NO_TARGET, + /** missing domain name information */ + VIR_ERR_NO_NAME, + /** missing domain OS information */ + VIR_ERR_NO_OS, + /** missing domain devices information */ + VIR_ERR_NO_DEVICE, + /** could not open Xen Store control */ + VIR_ERR_NO_XENSTORE, + /** too many drivers registered */ + VIR_ERR_DRIVER_FULL, + /** not supported by the drivers (DEPRECATED) */ + VIR_ERR_CALL_FAILED, + /** an XML description is not well formed or broken */ + VIR_ERR_XML_ERROR, + /** the domain already exist */ + VIR_ERR_DOM_EXIST, + /** operation forbidden on read-only connections */ + VIR_ERR_OPERATION_DENIED, + /** failed to open a conf file */ + VIR_ERR_OPEN_FAILED, + /** failed to read a conf file */ + VIR_ERR_READ_FAILED, + /** failed to parse a conf file */ + VIR_ERR_PARSE_FAILED, + /** failed to parse the syntax of a conf file */ + VIR_ERR_CONF_SYNTAX, + /** failed to write a conf file */ + VIR_ERR_WRITE_FAILED, + /** detail of an XML error */ + VIR_ERR_XML_DETAIL, + /** invalid network object */ + VIR_ERR_INVALID_NETWORK, + /** the network already exist */ + VIR_ERR_NETWORK_EXIST, + /** general system call failure */ + VIR_ERR_SYSTEM_ERROR, + /** some sort of RPC error */ + VIR_ERR_RPC, + /** error from a GNUTLS call */ + VIR_ERR_GNUTLS_ERROR, + /** failed to start network */ + VIR_WAR_NO_NETWORK, + /** domain not found or unexpectedly disappeared */ + VIR_ERR_NO_DOMAIN, + /** network not found */ + VIR_ERR_NO_NETWORK, + /** invalid MAC address */ + VIR_ERR_INVALID_MAC, + /** authentication failed */ + VIR_ERR_AUTH_FAILED, + /** invalid storage pool object */ + VIR_ERR_INVALID_STORAGE_POOL, + /** invalid storage vol object */ + VIR_ERR_INVALID_STORAGE_VOL, + /** failed to start storage */ + VIR_WAR_NO_STORAGE, + /** storage pool not found */ + VIR_ERR_NO_STORAGE_POOL, + /** storage pool not found */ + VIR_ERR_NO_STORAGE_VOL, + /** failed to start node driver */ + VIR_WAR_NO_NODE, + /** invalid node device object */ + VIR_ERR_INVALID_NODE_DEVICE, + /** node device not found */ + VIR_ERR_NO_NODE_DEVICE, + /** security model not found */ + VIR_ERR_NO_SECURITY_MODEL, + /** operation is not applicable at this time */ + VIR_ERR_OPERATION_INVALID, + /** failed to start interface driver */ + VIR_WAR_NO_INTERFACE, + /** interface driver not running */ + VIR_ERR_NO_INTERFACE, + /** invalid interface object */ + VIR_ERR_INVALID_INTERFACE, + /** more than one matching interface found */ + VIR_ERR_MULTIPLE_INTERFACES, + /** failed to start secret storage */ + VIR_WAR_NO_SECRET, + /** invalid secret */ + VIR_ERR_INVALID_SECRET, + /** secret not found */ + VIR_ERR_NO_SECRET, + /** unsupported configuration construct */ + VIR_ERR_CONFIG_UNSUPPORTED, + /** timeout occurred during operation */ + VIR_ERR_OPERATION_TIMEOUT, + /** a migration worked, but making the VM persist on the dest + * host failed */ + VIR_ERR_MIGRATE_PERSIST_FAILED, + /** a synchronous hook script failed */ + VIR_ERR_HOOK_SCRIPT_FAILED, + /** invalid domain snapshot */ + VIR_ERR_INVALID_DOMAIN_SNAPSHOT, + /** domain snapshot not found */ + VIR_ERR_NO_DOMAIN_SNAPSHOT, + /** stream pointer not valid */ + VIR_ERR_INVALID_STREAM, + /** valid API use but unsupported by the given driver */ + VIR_ERR_ARGUMENT_UNSUPPORTED, + /** storage pool probe failed */ + VIR_ERR_STORAGE_PROBE_FAILED, + /** storage pool already built */ + VIR_ERR_STORAGE_POOL_BUILT, + /** force was not requested for a risky domain snapshot + revert */ + VIR_ERR_SNAPSHOT_REVERT_RISKY, + /** operation on a domain was canceled/aborted by user */ + VIR_ERR_OPERATION_ABORTED, + /** authentication cancelled */ + VIR_ERR_AUTH_CANCELLED, + /** The metadata is not present */ + VIR_ERR_NO_DOMAIN_METADATA, + /** Migration is not safe */ + VIR_ERR_MIGRATE_UNSAFE, + /** integer overflow */ + VIR_ERR_OVERFLOW, + /** action prevented by block copy job */ + VIR_ERR_BLOCK_COPY_ACTIVE, + + /** unknown error */ + VIR_ERR_UNKNOWN; // must be the last entry!
protected static final ErrorNumber wrap(int value) { return safeElementAt(value, values());
ACK (from a non Java expert). -- Guido

On Thu, Feb 13, 2014 at 04:22:14PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Error.java | 397 ++++++++++++++++++++++------------ 1 file changed, 262 insertions(+), 135 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:35:17 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:14PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Error.java | 397 ++++++++++++++++++++++------------ 1 file changed, 262 insertions(+), 135 deletions(-)
ACK
Thanks, pushed.

Signed-off-by: Claudio Bley <cbley@av-test.de> --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index b02fd55..28ddc6e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +*~ +\#*\# .classpath .project .settings -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:15PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- .gitignore | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/.gitignore b/.gitignore index b02fd55..28ddc6e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +*~ +\#*\# .classpath .project .settings
ACK (from a non Java expert). -- Guido

At Fri, 14 Feb 2014 11:06:12 +0100, Guido Günther wrote:
On Thu, Feb 13, 2014 at 04:22:15PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- .gitignore | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/.gitignore b/.gitignore index b02fd55..28ddc6e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +*~ +\#*\# .classpath .project .settings
ACK (from a non Java expert).
Thank you for your reviews! It's always good to have a second pair of eyes look over... :-) Claudio

On Thu, Feb 13, 2014 at 04:22:15PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- .gitignore | 2 ++ 1 file changed, 2 insertions(+)
ACK. Counts as a trivial patch that can be pushed without asking. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:35:42 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:15PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- .gitignore | 2 ++ 1 file changed, 2 insertions(+)
ACK. Counts as a trivial patch that can be pushed without asking.
OK, thanks anyway :-). Pushed.

Specify a version range for the net.java.dev.jna / jna artifact in order to accept any version we tested the libvirt Java bindings against. Signed-off-by: Claudio Bley <cbley@av-test.de> --- As discussed previously[1], with a little delay, here's the patch. [1]: http://www.redhat.com/archives/libvir-list/2013-September/msg00929.html pom.xml.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml.in b/pom.xml.in index 25b2ae7..4f49a3a 100644 --- a/pom.xml.in +++ b/pom.xml.in @@ -27,7 +27,7 @@ <groupId>net.java.dev.jna</groupId> <artifactId>jna</artifactId> <scope>provided</scope> - <version>3.5.0</version> + <version>[3.4.1,4.0.0]</version> </dependency> </dependencies> -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:16PM +0100, Claudio Bley wrote:
Specify a version range for the net.java.dev.jna / jna artifact in order to accept any version we tested the libvirt Java bindings against.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- As discussed previously[1], with a little delay, here's the patch.
[1]: http://www.redhat.com/archives/libvir-list/2013-September/msg00929.html
pom.xml.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:36:10 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:16PM +0100, Claudio Bley wrote:
Specify a version range for the net.java.dev.jna / jna artifact in order to accept any version we tested the libvirt Java bindings against.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- As discussed previously[1], with a little delay, here's the patch.
[1]: http://www.redhat.com/archives/libvir-list/2013-September/msg00929.html
pom.xml.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ACK
Thanks, pushed.

On Windows, the libvirt DLL is called libvirt-0.dll. Trying to load the "virt" library hence fails to find the file. Branch on the platform and load "virt-0" if we're running on this OS, use "virt" otherwise. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/jna/Libvirt.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 813f09b..1be7c4f 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -4,6 +4,7 @@ import com.sun.jna.Callback; import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.NativeLong; +import com.sun.jna.Platform; import com.sun.jna.Pointer; import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.LongByReference; @@ -96,7 +97,7 @@ public interface Libvirt extends Library { void eventCallback(ConnectionPointer virConnectPtr, DomainPointer virDomainPointer, Pointer opaque) ; } - Libvirt INSTANCE = (Libvirt) Native.loadLibrary("virt", Libvirt.class); + Libvirt INSTANCE = (Libvirt) Native.loadLibrary(Platform.isWindows() ? "virt-0" : "virt", Libvirt.class); // Constants we need public static int VIR_UUID_BUFLEN = 16; -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:17PM +0100, Claudio Bley wrote:
On Windows, the libvirt DLL is called libvirt-0.dll. Trying to load the "virt" library hence fails to find the file. Branch on the platform and load "virt-0" if we're running on this OS, use "virt" otherwise.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/jna/Libvirt.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:36:33 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:17PM +0100, Claudio Bley wrote:
On Windows, the libvirt DLL is called libvirt-0.dll. Trying to load the "virt" library hence fails to find the file. Branch on the platform and load "virt-0" if we're running on this OS, use "virt" otherwise.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/jna/Libvirt.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
ACK
Thanks, pushed.

Libvirt function parameters having type (pointer to) size_t were wrapped via JNA using int, long or even NativeLong. Alas, none of these is actually correct as the size of size_t may be the same as the size of either (unsigned) int, long or even long long on different platforms. JNA provides the size of a native size_t to us, so using this information we define and use class SizeT and class SizeTByReference for wrapping a native size_t and size_t*, respectively. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 5 +- src/main/java/org/libvirt/Secret.java | 10 ++-- src/main/java/org/libvirt/Stream.java | 7 ++- src/main/java/org/libvirt/jna/Libvirt.java | 14 +++--- src/main/java/org/libvirt/jna/SizeT.java | 19 ++++++++ .../java/org/libvirt/jna/SizeTByReference.java | 50 ++++++++++++++++++++ 6 files changed, 87 insertions(+), 18 deletions(-) create mode 100644 src/main/java/org/libvirt/jna/SizeT.java create mode 100644 src/main/java/org/libvirt/jna/SizeTByReference.java diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 2f70bf2..b50e182 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -3,6 +3,7 @@ package org.libvirt; import org.libvirt.jna.DomainPointer; import org.libvirt.jna.DomainSnapshotPointer; import org.libvirt.jna.Libvirt; +import org.libvirt.jna.SizeT; import org.libvirt.jna.virDomainBlockInfo; import org.libvirt.jna.virDomainBlockStats; import org.libvirt.jna.virDomainInfo; @@ -233,7 +234,7 @@ public class Domain { */ public DomainBlockStats blockStats(String path) throws LibvirtException { virDomainBlockStats stats = new virDomainBlockStats(); - int success = libvirt.virDomainBlockStats(VDP, path, stats, stats.size()); + int success = libvirt.virDomainBlockStats(VDP, path, stats, new SizeT(stats.size())); processError(); return success == 0 ? new DomainBlockStats(stats) : null; } @@ -694,7 +695,7 @@ public class Domain { */ public DomainInterfaceStats interfaceStats(String path) throws LibvirtException { virDomainInterfaceStats stats = new virDomainInterfaceStats(); - libvirt.virDomainInterfaceStats(VDP, path, stats, stats.size()); + libvirt.virDomainInterfaceStats(VDP, path, stats, new SizeT(stats.size())); processError(); return new DomainInterfaceStats(stats); } diff --git a/src/main/java/org/libvirt/Secret.java b/src/main/java/org/libvirt/Secret.java index 5332e02..4edb515 100644 --- a/src/main/java/org/libvirt/Secret.java +++ b/src/main/java/org/libvirt/Secret.java @@ -2,11 +2,11 @@ package org.libvirt; import org.libvirt.jna.Libvirt; import org.libvirt.jna.SecretPointer; +import org.libvirt.jna.SizeT; +import org.libvirt.jna.SizeTByReference; import static org.libvirt.Library.libvirt; import com.sun.jna.Native; -import com.sun.jna.NativeLong; -import com.sun.jna.ptr.LongByReference; import com.sun.jna.Pointer; import java.nio.ByteBuffer; @@ -120,7 +120,7 @@ public class Secret { * @return the value of the secret, or null on failure. */ public byte[] getByteValue() throws LibvirtException { - LongByReference value_size = new LongByReference(); + SizeTByReference value_size = new SizeTByReference(); Pointer value = libvirt.virSecretGetValue(VSP, value_size, 0); processError(); ByteBuffer bb = value.getByteBuffer(0, value_size.getValue()); @@ -154,7 +154,7 @@ public class Secret { * @return 0 on success, -1 on failure. */ public int setValue(String value) throws LibvirtException { - int returnValue = libvirt.virSecretSetValue(VSP, value, new NativeLong(value.length()), 0); + int returnValue = libvirt.virSecretSetValue(VSP, value, new SizeT(value.length()), 0); processError(); return returnValue; } @@ -165,7 +165,7 @@ public class Secret { * @return 0 on success, -1 on failure. */ public int setValue(byte[] value) throws LibvirtException { - int returnValue = libvirt.virSecretSetValue(VSP, value, new NativeLong(value.length), 0); + int returnValue = libvirt.virSecretSetValue(VSP, value, new SizeT(value.length), 0); processError(); return returnValue; } diff --git a/src/main/java/org/libvirt/Stream.java b/src/main/java/org/libvirt/Stream.java index bd8e87f..6d488e3 100644 --- a/src/main/java/org/libvirt/Stream.java +++ b/src/main/java/org/libvirt/Stream.java @@ -1,11 +1,10 @@ package org.libvirt; import org.libvirt.jna.Libvirt; +import org.libvirt.jna.SizeT; import org.libvirt.jna.StreamPointer; import static org.libvirt.Library.libvirt; -import com.sun.jna.NativeLong; - public class Stream { public static int VIR_STREAM_NONBLOCK = (1 << 0); @@ -108,7 +107,7 @@ public class Stream { * @throws LibvirtException */ public int receive(byte[] data) throws LibvirtException { - int returnValue = libvirt.virStreamRecv(VSP, data, new NativeLong(data.length)); + int returnValue = libvirt.virStreamRecv(VSP, data, new SizeT(data.length)); processError(); return returnValue; } @@ -151,7 +150,7 @@ public class Stream { * @throws LibvirtException */ public int send(String data) throws LibvirtException { - int returnValue = libvirt.virStreamSend(VSP, data, new NativeLong(data.length())); + int returnValue = libvirt.virStreamSend(VSP, data, new SizeT(data.length())); processError(); return returnValue; } diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 1be7c4f..ffbb5a0 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -180,7 +180,7 @@ public interface Libvirt extends Library { int virDomainAbortJob(DomainPointer virDomainPtr); int virDomainAttachDevice(DomainPointer virDomainPtr, String deviceXML); int virDomainAttachDeviceFlags(DomainPointer virDomainPtr, String deviceXML, int flags); - int virDomainBlockStats(DomainPointer virDomainPtr, String path, virDomainBlockStats stats, int size); + int virDomainBlockStats(DomainPointer virDomainPtr, String path, virDomainBlockStats stats, SizeT size); int virDomainBlockResize(DomainPointer virDomainPtr, String disk, long size, int flags); int virDomainCoreDump(DomainPointer virDomainPtr, String to, int flags); int virDomainCreate(DomainPointer virDomainPtr); @@ -210,7 +210,7 @@ public interface Libvirt extends Library { Pointer virDomainGetXMLDesc(DomainPointer virDomainPtr, int flags); int virDomainHasCurrentSnapshot(DomainPointer virDomainPtr, int flags); int virDomainHasManagedSaveImage(DomainPointer virDomainPtr, int flags); - int virDomainInterfaceStats(DomainPointer virDomainPtr, String path, virDomainInterfaceStats stats, int size); + int virDomainInterfaceStats(DomainPointer virDomainPtr, String path, virDomainInterfaceStats stats, SizeT size); int virDomainIsActive(DomainPointer virDomainPtr); int virDomainIsPersistent(DomainPointer virDomainPtr); DomainPointer virDomainLookupByID(ConnectionPointer virConnectPtr, int id); @@ -351,13 +351,13 @@ public interface Libvirt extends Library { int virSecretGetUUID(SecretPointer virSecretPtr, byte[] uuidString); int virSecretGetUUIDString(SecretPointer virSecretPtr, byte[] uuidString); String virSecretGetUsageID(SecretPointer virSecretPtr); - Pointer virSecretGetValue(SecretPointer virSecretPtr, LongByReference value_size, int flags); + Pointer virSecretGetValue(SecretPointer virSecretPtr, SizeTByReference value_size, int flags); String virSecretGetXMLDesc(SecretPointer virSecretPtr, int flags); SecretPointer virSecretLookupByUsage(ConnectionPointer virConnectPtr, int usageType, String usageID); SecretPointer virSecretLookupByUUID(ConnectionPointer virConnectPtr, byte[] uuidBytes); SecretPointer virSecretLookupByUUIDString(ConnectionPointer virConnectPtr, String uuidstr); - int virSecretSetValue(SecretPointer virSecretPtr, String value, NativeLong value_size, int flags); - int virSecretSetValue(SecretPointer virSecretPtr, byte[] value, NativeLong value_size, int flags); + int virSecretSetValue(SecretPointer virSecretPtr, String value, SizeT value_size, int flags); + int virSecretSetValue(SecretPointer virSecretPtr, byte[] value, SizeT value_size, int flags); int virSecretUndefine(SecretPointer virSecretPtr); //Stream Methods @@ -369,9 +369,9 @@ public interface Libvirt extends Library { int virStreamFinish(StreamPointer virStreamPtr) ; int virStreamFree(StreamPointer virStreamPtr) ; StreamPointer virStreamNew(ConnectionPointer virConnectPtr, int flags) ; - int virStreamSend(StreamPointer virStreamPtr, String data, NativeLong size); + int virStreamSend(StreamPointer virStreamPtr, String data, SizeT size); int virStreamSendAll(StreamPointer virStreamPtr, Libvirt.VirStreamSourceFunc handler, Pointer opaque); - int virStreamRecv(StreamPointer virStreamPtr, byte[] data, NativeLong length); + int virStreamRecv(StreamPointer virStreamPtr, byte[] data, SizeT length); int virStreamRecvAll(StreamPointer virStreamPtr, Libvirt.VirStreamSinkFunc handler, Pointer opaque); //DomainSnapshot Methods diff --git a/src/main/java/org/libvirt/jna/SizeT.java b/src/main/java/org/libvirt/jna/SizeT.java new file mode 100644 index 0000000..02e8f18 --- /dev/null +++ b/src/main/java/org/libvirt/jna/SizeT.java @@ -0,0 +1,19 @@ +package org.libvirt.jna; + +import com.sun.jna.Native; +import com.sun.jna.IntegerType; + +/** + * Represents the native {@code size_t} data type. + */ +public final class SizeT extends IntegerType { + public SizeT() { this(0); } + public SizeT(long value) { + /* The third argument determines whether this class represents + * an unsigned integer type. When extracting a value into a + * larger-sized container (e.g. 4 byte native type into Java + * long), the value is properly converted as unsigned. + */ + super(Native.SIZE_T_SIZE, value, true); + } +} diff --git a/src/main/java/org/libvirt/jna/SizeTByReference.java b/src/main/java/org/libvirt/jna/SizeTByReference.java new file mode 100644 index 0000000..474527f --- /dev/null +++ b/src/main/java/org/libvirt/jna/SizeTByReference.java @@ -0,0 +1,50 @@ +package org.libvirt.jna; + +import com.sun.jna.Native; +import com.sun.jna.Pointer; +import com.sun.jna.ptr.ByReference; + +/** + * Represents a native (call-by-reference) pointer to {@code size_t} data type. + */ +public final class SizeTByReference extends ByReference { + public SizeTByReference() { + this(0); + } + + public SizeTByReference(long value) { + super(Native.SIZE_T_SIZE); + setValue(value); + } + + public void setValue(long value) { + Pointer p = getPointer(); + switch (Native.SIZE_T_SIZE) { + case 2: + p.setShort(0, (short)value); + break; + case 4: + p.setInt(0, (int)value); + break; + case 8: + p.setLong(0, value); + break; + default: + throw new IllegalArgumentException("Unsupported size: " + Native.SIZE_T_SIZE); + } + } + + public long getValue() { + Pointer p = getPointer(); + switch (Native.SIZE_T_SIZE) { + case 2: + return p.getShort(0) & 0xFFFFL; + case 4: + return p.getInt(0) & 0xFFFFFFFFL; + case 8: + return p.getLong(0); + default: + throw new IllegalArgumentException("Unsupported size: " + Native.SIZE_T_SIZE); + } + } +} -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:18PM +0100, Claudio Bley wrote:
Libvirt function parameters having type (pointer to) size_t were wrapped via JNA using int, long or even NativeLong. Alas, none of these is actually correct as the size of size_t may be the same as the size of either (unsigned) int, long or even long long on different platforms.
JNA provides the size of a native size_t to us, so using this information we define and use class SizeT and class SizeTByReference for wrapping a native size_t and size_t*, respectively.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 5 +- src/main/java/org/libvirt/Secret.java | 10 ++-- src/main/java/org/libvirt/Stream.java | 7 ++- src/main/java/org/libvirt/jna/Libvirt.java | 14 +++--- src/main/java/org/libvirt/jna/SizeT.java | 19 ++++++++ .../java/org/libvirt/jna/SizeTByReference.java | 50 ++++++++++++++++++++ 6 files changed, 87 insertions(+), 18 deletions(-) create mode 100644 src/main/java/org/libvirt/jna/SizeT.java create mode 100644 src/main/java/org/libvirt/jna/SizeTByReference.java
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:37:36 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:18PM +0100, Claudio Bley wrote:
Libvirt function parameters having type (pointer to) size_t were wrapped via JNA using int, long or even NativeLong. Alas, none of these is actually correct as the size of size_t may be the same as the size of either (unsigned) int, long or even long long on different platforms.
JNA provides the size of a native size_t to us, so using this information we define and use class SizeT and class SizeTByReference for wrapping a native size_t and size_t*, respectively.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 5 +- src/main/java/org/libvirt/Secret.java | 10 ++-- src/main/java/org/libvirt/Stream.java | 7 ++- src/main/java/org/libvirt/jna/Libvirt.java | 14 +++--- src/main/java/org/libvirt/jna/SizeT.java | 19 ++++++++ .../java/org/libvirt/jna/SizeTByReference.java | 50 ++++++++++++++++++++ 6 files changed, 87 insertions(+), 18 deletions(-) create mode 100644 src/main/java/org/libvirt/jna/SizeT.java create mode 100644 src/main/java/org/libvirt/jna/SizeTByReference.java
ACK
Thanks. I'll squash this in before pushing, since throwing an IllegalArgumentException is not appropriate here. ------- >8 ----------- 8< -------------------- >8 ----------------- 8< ----------------------------------------------- diff --git a/src/main/java/org/libvirt/jna/SizeTByReference.java b/src/main/java/org/libvirt/jna/SizeTByReference.java index 474527f..24a4677 100644 --- a/src/main/java/org/libvirt/jna/SizeTByReference.java +++ b/src/main/java/org/libvirt/jna/SizeTByReference.java @@ -30,7 +30,7 @@ public final class SizeTByReference extends ByReference { p.setLong(0, value); break; default: - throw new IllegalArgumentException("Unsupported size: " + Native.SIZE_T_SIZE); + throw new RuntimeException("Unsupported size: " + Native.SIZE_T_SIZE); } } @@ -44,7 +44,7 @@ public final class SizeTByReference extends ByReference { case 8: return p.getLong(0); default: - throw new IllegalArgumentException("Unsupported size: " + Native.SIZE_T_SIZE); + throw new RuntimeException("Unsupported size: " + Native.SIZE_T_SIZE); } } }

At Fri, 21 Feb 2014 14:42:26 +0100, Claudio Bley wrote:
At Fri, 21 Feb 2014 10:37:36 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:18PM +0100, Claudio Bley wrote:
Libvirt function parameters having type (pointer to) size_t were wrapped via JNA using int, long or even NativeLong. Alas, none of these is actually correct as the size of size_t may be the same as the size of either (unsigned) int, long or even long long on different platforms.
JNA provides the size of a native size_t to us, so using this information we define and use class SizeT and class SizeTByReference for wrapping a native size_t and size_t*, respectively.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 5 +- src/main/java/org/libvirt/Secret.java | 10 ++-- src/main/java/org/libvirt/Stream.java | 7 ++- src/main/java/org/libvirt/jna/Libvirt.java | 14 +++--- src/main/java/org/libvirt/jna/SizeT.java | 19 ++++++++ .../java/org/libvirt/jna/SizeTByReference.java | 50 ++++++++++++++++++++ 6 files changed, 87 insertions(+), 18 deletions(-) create mode 100644 src/main/java/org/libvirt/jna/SizeT.java create mode 100644 src/main/java/org/libvirt/jna/SizeTByReference.java
ACK
Thanks. I'll squash this in before pushing, since throwing an IllegalArgumentException is not appropriate here.
------- >8 ----------- 8< -------------------- >8 ----------------- 8< ----------------------------------------------- diff --git a/src/main/java/org/libvirt/jna/SizeTByReference.java b/src/main/java/org/libvirt/jna/SizeTByReference.java index 474527f..24a4677 100644 --- a/src/main/java/org/libvirt/jna/SizeTByReference.java +++ b/src/main/java/org/libvirt/jna/SizeTByReference.java @@ -30,7 +30,7 @@ public final class SizeTByReference extends ByReference { p.setLong(0, value); break; default: - throw new IllegalArgumentException("Unsupported size: " + Native.SIZE_T_SIZE); + throw new RuntimeException("Unsupported size: " + Native.SIZE_T_SIZE); } }
@@ -44,7 +44,7 @@ public final class SizeTByReference extends ByReference { case 8: return p.getLong(0); default: - throw new IllegalArgumentException("Unsupported size: " + Native.SIZE_T_SIZE); + throw new RuntimeException("Unsupported size: " + Native.SIZE_T_SIZE); } } }
Pushed.

When JNA is linked to a different runtime library than libvirt, using JNA's Native.free will probably lead to crashes as witnessed on Windows: # A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000077363290, pid=10180, tid=9908 # # JRE version: 7.0_25-b16 # Java VM: Java HotSpot(TM) 64-Bit Server VM (23.25-b01 mixed mode windows-amd64 compressed oops) # Problematic frame: # C [ntdll.dll+0x53290] RtlFreeHeap+0xd0 The root cause is that the libvirt DLL uses MSVCRT as its runtime library, whereas the jnidispatch DLL of JNA uses a different one. At runtime, when calling org.sun.com.jna.Native.free() the OS function RtlFreeHeap is called with an invalid Pointer that was actually allocated by MSVCRT's malloc. Basically, we cannot simply mix and match memory allocation functions from different runtime libraries, but have to call virFree for pointers orignating from libvirt itself. So, this patch re-adds and uses the virFree method which had been removed in commit 3220de292990bed71828fba2f3700bc846d440f2. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Library.java | 4 ++-- src/main/java/org/libvirt/jna/Libvirt.java | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/libvirt/Library.java b/src/main/java/org/libvirt/Library.java index 0136095..33d3042 100644 --- a/src/main/java/org/libvirt/Library.java +++ b/src/main/java/org/libvirt/Library.java @@ -4,6 +4,7 @@ import org.libvirt.jna.Libvirt; import com.sun.jna.Native; import com.sun.jna.Pointer; +import com.sun.jna.ptr.PointerByReference; /** * This class represents an instance of the JNA mapped libvirt @@ -38,8 +39,7 @@ final class Library { * Free memory pointed to by ptr. */ static void free(Pointer ptr) { - Native.free(Pointer.nativeValue(ptr)); - Pointer.nativeValue(ptr, 0L); + libvirt.virFree(new PointerByReference(ptr)); } /** diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index ffbb5a0..78dd9bc 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -8,6 +8,7 @@ import com.sun.jna.Platform; import com.sun.jna.Pointer; import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.LongByReference; +import com.sun.jna.ptr.PointerByReference; /** * The libvirt interface which is exposed via JNA. The complete API is @@ -172,6 +173,7 @@ public interface Libvirt extends Library { int virGetVersion(LongByReference libVer, String type, LongByReference typeVer); int virInitialize(); int virCopyLastError(virError error); + void virFree(PointerByReference ptr); virError virGetLastError(); void virResetLastError(); void virSetErrorFunc(Pointer userData, VirErrorCallback callback); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:19PM +0100, Claudio Bley wrote:
When JNA is linked to a different runtime library than libvirt, using JNA's Native.free will probably lead to crashes as witnessed on Windows:
# A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000077363290, pid=10180, tid=9908 # # JRE version: 7.0_25-b16 # Java VM: Java HotSpot(TM) 64-Bit Server VM (23.25-b01 mixed mode windows-amd64 compressed oops) # Problematic frame: # C [ntdll.dll+0x53290] RtlFreeHeap+0xd0
The root cause is that the libvirt DLL uses MSVCRT as its runtime library, whereas the jnidispatch DLL of JNA uses a different one.
At runtime, when calling org.sun.com.jna.Native.free() the OS function RtlFreeHeap is called with an invalid Pointer that was actually allocated by MSVCRT's malloc.
Basically, we cannot simply mix and match memory allocation functions from different runtime libraries, but have to call virFree for pointers orignating from libvirt itself.
So, this patch re-adds and uses the virFree method which had been removed in commit 3220de292990bed71828fba2f3700bc846d440f2.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Library.java | 4 ++-- src/main/java/org/libvirt/jna/Libvirt.java | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-)
NACK to this. virFree is an internal only symbol which is not guaranteeed to be ABI stable across libvirt releases. ie we may remove or rename it or change its API signature at any time. Not sure what else to suggest though. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

JUnit is used for quite some time now, which supercedes the tests defined in the old "test" class. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/test/java/test.java | 280 ----------------------------------------------- 1 file changed, 280 deletions(-) delete mode 100644 src/test/java/test.java diff --git a/src/test/java/test.java b/src/test/java/test.java deleted file mode 100644 index 3442bec..0000000 --- a/src/test/java/test.java +++ /dev/null @@ -1,280 +0,0 @@ -import java.util.UUID; - -import org.libvirt.*; - -public class test { - - // Use this to flag errors in the test run. - public static String FIXME = "\n<=====================================>\n<============== FIXME ================> "; - - public static void main(String[] args) { - // Create the connection - Connect conn = null; - Network testNetwork = null; - - // The array below is to support the uuid lookup based on an array of - // ints. - // This is deprectaed, but is kept here until the code is removed. - int UUIDArray[] = { Integer.decode("0x00"), Integer.decode("0x4b"), Integer.decode("0x96"), - Integer.decode("0xe1"), Integer.decode("0x2d"), Integer.decode("0x78"), Integer.decode("0xc3"), - Integer.decode("0x0f"), Integer.decode("0x5a"), Integer.decode("0xa5"), Integer.decode("0xf0"), - Integer.decode("0x3c"), Integer.decode("0x87"), Integer.decode("0xd2"), Integer.decode("0x1e"), - Integer.decode("0x67") }; - - /* - * Test Authentication - * - * If you want to test authentication, uncomment the try catch block and - * one of the conn lines. You need to configure your libvirtd for - * remote/authenticated connections before this will work. - */ - /* - * ConnectAuth defaultAuth = new ConnectAuthDefault(); - * - * try{ conn = new Connect("test+tcp://localhost/default", defaultAuth, - * 0); conn = new Connect("qemu+tcp://localhost/system", defaultAuth, - * 0); conn = new Connect("test:///default", defaultAuth, 0); - * System.out.println("Encrypted connection successful!"); } catch - * (LibvirtException e){ System.out.println("exception caught:"+e); - * System.out.println(e.getError()); } - */ - - try { - conn = new Connect("test:///default", false); - } catch (LibvirtException e) { - System.out.println("exception caught:" + e); - System.out.println(e.getError()); - } - try { - // Check nodeinfo - NodeInfo nodeInfo = conn.nodeInfo(); - System.out.println("virNodeInfo.model:" + nodeInfo.model); - System.out.println("virNodeInfo.memory:" + nodeInfo.memory); - System.out.println("virNodeInfo.cpus:" + nodeInfo.cpus); - System.out.println("virNodeInfo.nodes:" + nodeInfo.nodes); - System.out.println("virNodeInfo.sockets:" + nodeInfo.sockets); - System.out.println("virNodeInfo.cores:" + nodeInfo.cores); - System.out.println("virNodeInfo.threads:" + nodeInfo.threads); - - // Exercise the information getter methods - System.out.println("getHostName:" + conn.getHostName()); - System.out.println("getCapabilities:" + conn.getCapabilities()); - System.out.println("getMaxVcpus:" + conn.getMaxVcpus("xen")); - System.out.println("getType:" + conn.getType()); - System.out.println("getURI:" + conn.getURI()); - System.out.println("getVersion:" + conn.getVersion()); - System.out.println("getLibVirVersion:" + conn.getLibVirVersion()); - - // By default, there are 1 created and 0 defined networks - - // Create a new network to test the create method - System.out.println("conn.networkCreateXML: " - + conn.networkCreateXML("<network>" + " <name>createst</name>" - + " <uuid>004b96e1-2d78-c30f-5aa5-f03c87d21e68</uuid>" + " <bridge name='createst'/>" - + " <forward dev='eth0'/>" + " <ip address='192.168.66.1' netmask='255.255.255.0'>" - + " <dhcp>" + " <range start='192.168.66.128' end='192.168.66.253'/>" - + " </dhcp>" + " </ip>" + "</network>")); - - // Same for the define method - System.out.println("conn.networkDefineXML: " - + conn.networkDefineXML("<network>" + " <name>deftest</name>" - + " <uuid>004b96e1-2d78-c30f-5aa5-f03c87d21e67</uuid>" + " <bridge name='deftest'/>" - + " <forward dev='eth0'/>" + " <ip address='192.168.88.1' netmask='255.255.255.0'>" - + " <dhcp>" + " <range start='192.168.88.128' end='192.168.88.253'/>" - + " </dhcp>" + " </ip>" + "</network>")); - - // We should have 2:1 but it shows up 3:0 hopefully a bug in the - // test driver - System.out.println("numOfDefinedNetworks:" + conn.numOfDefinedNetworks()); - System.out.println("listDefinedNetworks:" + conn.listDefinedNetworks()); - for (String c : conn.listDefinedNetworks()) - System.out.println(" -> " + c); - System.out.println("numOfNetworks:" + conn.numOfNetworks()); - System.out.println("listNetworks:" + conn.listNetworks()); - for (String c : conn.listNetworks()) - System.out.println(" -> " + c); - - // Look at the interfaces - // TODO Post 0.5.1 - // System.out.println("numOfInterfaces:" + conn.numOfInterfaces()); - // System.out.println("listDefinedInterfaces:" + - // conn.listInterfaces()); - // for(String c: conn.listInterfaces()) - // System.out.println(" -> "+c); - - // Define a new Domain - System.out.println("conn.domainDefineXML:" - + conn.domainDefineXML("<domain type='test' id='2'>" + " <name>deftest</name>" - + " <uuid>004b96e1-2d78-c30f-5aa5-f03c87d21e70</uuid>" + " <memory>8388608</memory>" - + " <vcpu>2</vcpu>" + " <os><type arch='i686'>hvm</type></os>" - + " <on_reboot>restart</on_reboot>" + " <on_poweroff>destroy</on_poweroff>" - + " <on_crash>restart</on_crash>" + "</domain>")); - - System.out.println("conn.domainCreateLinux:" - + conn.domainCreateLinux("<domain type='test' id='3'>" + " <name>createst</name>" - + " <uuid>004b96e1-2d78-c30f-5aa5-f03c87d21e67</uuid>" + " <memory>8388608</memory>" - + " <vcpu>2</vcpu>" + " <os><type arch='i686'>hvm</type></os>" - + " <on_reboot>restart</on_reboot>" + " <on_poweroff>destroy</on_poweroff>" - + " <on_crash>restart</on_crash>" + "</domain>", 0)); - - // Domain enumeration stuff - System.out.println("numOfDefinedDomains:" + conn.numOfDefinedDomains()); - System.out.println("listDefinedDomains:" + conn.listDefinedDomains()); - for (String c : conn.listDefinedDomains()) - System.out.println(" " + c); - System.out.println("numOfDomains:" + conn.numOfDomains()); - System.out.println("listDomains:" + conn.listDomains()); - for (int c : conn.listDomains()) - System.out.println(" -> " + c); - - } catch (LibvirtException e) { - System.out.println(FIXME); - System.out.println("exception caught:" + e); - System.out.println(e.getError()); - } - - // Network Object - - try { - // Choose one, they should have the exact same effect - testNetwork = conn.networkLookupByName("deftest"); - System.out.println("networkLookupByName: " + testNetwork.getName()); - testNetwork = conn.networkLookupByUUID(UUIDArray); - System.out.println("networkLookupByUUID: " + testNetwork.getName()); - testNetwork = conn.networkLookupByUUIDString("004b96e1-2d78-c30f-5aa5-f03c87d21e67"); - System.out.println("networkLookupByUUIDString: " + testNetwork.getName()); - testNetwork = conn.networkLookupByUUID(UUID.fromString("004b96e1-2d78-c30f-5aa5-f03c87d21e67")); - System.out.println("networkLookupByUUID (Java UUID): " + testNetwork.getName()); - - // Exercise the getter methods on the default network - System.out.println("virNetworkGetXMLDesc:" + testNetwork.getXMLDesc(0)); - System.out.println("virNetworkGetAutostart:" + testNetwork.getAutostart()); - System.out.println("virNetworkGetBridgeName:" + testNetwork.getBridgeName()); - System.out.println("virNetworkGetName:" + testNetwork.getName()); - System.out.println("virNetworkGetUUID:" + testNetwork.getUUID() + " "); - for (int c : testNetwork.getUUID()) - System.out.print(String.format("%02x", c)); - System.out.println(); - System.out.println("virNetworkGetName:" + testNetwork.getUUIDString()); - - // Destroy and create the network - System.out.println("virNetworkDestroy:"); - testNetwork.destroy(); - System.out.println("virNetworkCreate:"); - testNetwork.create(); - } catch (LibvirtException e) { - System.out.println(FIXME); - System.out.println("exception caught:" + e); - System.out.println(e.getError()); - } - // This should raise an excpetion - try { - System.out.println("virNetworkCreate (should error):"); - testNetwork.create(); - } catch (LibvirtException e) { - System.out.println("exception caught:" + e); - System.out.println(e.getError()); - } - - // Domain stuff - - try { - // Domain lookup - Domain testDomain = conn.domainLookupByID(1); - System.out.println("domainLookupByID: " + testDomain.getName()); - testDomain = conn.domainLookupByName("test"); - System.out.println("domainLookupByName: " + testDomain.getName()); - testDomain = conn.domainLookupByUUIDString("004b96e1-2d78-c30f-5aa5-f03c87d21e67"); - System.out.println("domainLookupByUUIDString: " + testDomain.getName()); - testDomain = conn.domainLookupByUUID(UUIDArray); - System.out.println("domainLookupByUUID: " + testDomain.getName()); - testDomain = conn.domainLookupByUUID(UUID.fromString("004b96e1-2d78-c30f-5aa5-f03c87d21e67")); - System.out.println("domainLookupByUUID (JAVA UID): " + testDomain.getName()); - - // Exercise the getter methods on the default domain - System.out.println("virDomainGetXMLDesc:" + testDomain.getXMLDesc(0)); - System.out.println("virDomainGetAutostart:" + testDomain.getAutostart()); - System.out.println("virDomainGetConnect:" + testDomain.getConnect()); - System.out.println("virDomainGetID:" + testDomain.getID()); - System.out.println("virDomainGetInfo:" + testDomain.getInfo()); - System.out.println("virDomainGetMaxMemory:" + testDomain.getMaxMemory()); - // Should fail, test driver does not support it - try { - System.out.println("virDomainGetMaxVcpus:" + testDomain.getMaxVcpus()); - System.out.println(FIXME); - } catch (LibvirtException e) { - - } - System.out.println("virDomainGetName:" + testDomain.getName()); - System.out.println("virDomainGetOSType:" + testDomain.getOSType()); - System.out.println("virDomainGetSchedulerType:" + testDomain.getSchedulerType()); - System.out.println("virDomainGetSchedulerParameters:" + testDomain.getSchedulerParameters()); - // Iterate over the parameters the painful way - for (SchedParameter c : testDomain.getSchedulerParameters()) { - if (c instanceof SchedIntParameter) - System.out.println("Int:" + ((SchedIntParameter) c).field + ":" + ((SchedIntParameter) c).value); - if (c instanceof SchedUintParameter) - System.out.println("Uint:" + ((SchedUintParameter) c).field + ":" + ((SchedUintParameter) c).value); - if (c instanceof SchedLongParameter) - System.out.println("Long:" + ((SchedLongParameter) c).field + ":" + ((SchedLongParameter) c).value); - if (c instanceof SchedUlongParameter) - System.out.println("Ulong:" + ((SchedUlongParameter) c).field + ":" - + ((SchedUlongParameter) c).value); - if (c instanceof SchedDoubleParameter) - System.out.println("Double:" + ((SchedDoubleParameter) c).field + ":" - + ((SchedDoubleParameter) c).value); - if (c instanceof SchedBooleanParameter) - System.out.println("Boolean:" + ((SchedBooleanParameter) c).field + ":" - + ((SchedBooleanParameter) c).value); - } - // Iterate over the parameters the easy way - for (SchedParameter c : testDomain.getSchedulerParameters()) { - System.out.println(c.getTypeAsString() + ":" + c.field + ":" + c.getValueAsString()); - } - - // test setting a scheduled parameter - SchedUintParameter[] pars = new SchedUintParameter[1]; - pars[0] = new SchedUintParameter(); - pars[0].field = "weight"; - pars[0].value = 100; - testDomain.setSchedulerParameters(pars); - - System.out.println("virDomainGetUUID:" + testDomain.getUUID()); - for (int c : testDomain.getUUID()) - System.out.print(String.format("%02x", c)); - System.out.println(); - System.out.println("virDomainGetUUIDString:" + testDomain.getUUIDString()); - // Should fail, unimplemented in test driver - // System.out.println("virDomainGetVcpusInfo:" + - // testDomain.getVcpusInfo()); - // Same as above - // System.out.println("virDomainGetVcpusCpuMap:" + - // testDomain.getVcpusCpuMaps()); - // Should test pinVcpu, when we test with real xen - // Here - // Attach default network to test domain - // System.out.println("virDomainGetVcpusCpuMap:" + - // testDomain.getVcpusCpuMaps()); - - // Should test interfacestats and blockstats with real xen - - // Close the connection - - conn.close(); - } catch (LibvirtException e) { - System.out.println(FIXME); - System.out.println("exception caught:" + e); - System.out.println(e.getError()); - } - - try { - // We should get an exception, not a crash - System.out.println(conn.getHostName()); - } catch (LibvirtException e) { - System.out.println("exception caught:" + e); - System.out.println(e.getError()); - } - System.out.println("Fini!"); - } - -} -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:20PM +0100, Claudio Bley wrote:
JUnit is used for quite some time now, which supercedes the tests defined in the old "test" class.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/test/java/test.java | 280 ----------------------------------------------- 1 file changed, 280 deletions(-) delete mode 100644 src/test/java/test.java
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:40:46 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:20PM +0100, Claudio Bley wrote:
JUnit is used for quite some time now, which supercedes the tests defined in the old "test" class.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/test/java/test.java | 280 ----------------------------------------------- 1 file changed, 280 deletions(-) delete mode 100644 src/test/java/test.java
ACK
Thanks, pushed.

The libvirt function virNodeDeviceListCaps might return fewer elements than requested. Take this into account and properly decode the UTF-8 strings returned. Additionally, the given strings are freed before returning the resulting string array. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Device.java | 10 +++++++--- src/main/java/org/libvirt/jna/Libvirt.java | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/libvirt/Device.java b/src/main/java/org/libvirt/Device.java index fe49ce9..d55321e 100644 --- a/src/main/java/org/libvirt/Device.java +++ b/src/main/java/org/libvirt/Device.java @@ -3,6 +3,8 @@ package org.libvirt; import org.libvirt.jna.DevicePointer; import static org.libvirt.Library.libvirt; +import com.sun.jna.Pointer; + /** * A device which is attached to a node */ @@ -135,13 +137,15 @@ public class Device { */ public String[] listCapabilities() throws LibvirtException { int maxCaps = getNumberOfCapabilities(); - String[] names = new String[maxCaps]; if (maxCaps > 0) { - libvirt.virNodeDeviceListCaps(VDP, names, maxCaps); + Pointer[] ptrs = new Pointer[maxCaps]; + int got = libvirt.virNodeDeviceListCaps(VDP, ptrs, maxCaps); processError(); + return Library.toStringArray(ptrs, got); + } else { + return Library.NO_STRINGS; } - return names; } /** diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 78dd9bc..bf3291d 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -282,7 +282,7 @@ public interface Libvirt extends Library { String virNodeDeviceGetName(DevicePointer virDevicePointer); String virNodeDeviceGetParent(DevicePointer virDevicePointer); int virNodeDeviceNumOfCaps(DevicePointer virDevicePointer); - int virNodeDeviceListCaps(DevicePointer virDevicePointer, String[] names, int maxNames); + int virNodeDeviceListCaps(DevicePointer virDevicePointer, Pointer[] names, int maxNames); String virNodeDeviceGetXMLDesc(DevicePointer virDevicePointer); int virNodeDeviceFree(DevicePointer virDevicePointer); int virNodeDeviceDettach(DevicePointer virDevicePointer); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:21PM +0100, Claudio Bley wrote:
The libvirt function virNodeDeviceListCaps might return fewer elements than requested. Take this into account and properly decode the UTF-8 strings returned.
Additionally, the given strings are freed before returning the resulting string array.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Device.java | 10 +++++++--- src/main/java/org/libvirt/jna/Libvirt.java | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:41:35 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:21PM +0100, Claudio Bley wrote:
The libvirt function virNodeDeviceListCaps might return fewer elements than requested. Take this into account and properly decode the UTF-8 strings returned.
Additionally, the given strings are freed before returning the resulting string array.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Device.java | 10 +++++++--- src/main/java/org/libvirt/jna/Libvirt.java | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-)
ACK
Thanks, pushed.

Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/test/java/org/libvirt/TestJavaBindings.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/test/java/org/libvirt/TestJavaBindings.java b/src/test/java/org/libvirt/TestJavaBindings.java index a25c4f3..0123e6a 100644 --- a/src/test/java/org/libvirt/TestJavaBindings.java +++ b/src/test/java/org/libvirt/TestJavaBindings.java @@ -46,6 +46,20 @@ public final class TestJavaBindings extends TestCase { assertTrue("conn.isSecure", conn.isSecure() == 1); } + /* + * Excercise the listCapabilities method of the Device class. + */ + public void testDeviceListCapabilities() throws Exception { + Device dev = this.conn.deviceLookupByName("computer"); + String[] caps = dev.listCapabilities(); + + // check that all caps are non-empty strings + for (String c: caps) { + assertNotNull("capability is null", c); + assertFalse("capability is empty", c.isEmpty()); + } + } + public void testNodeInfo() throws Exception { NodeInfo nodeInfo = conn.nodeInfo(); assertEquals("nodeInfo.model", "i686", nodeInfo.model); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:22PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/test/java/org/libvirt/TestJavaBindings.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:42:22 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:22PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/test/java/org/libvirt/TestJavaBindings.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
ACK
Thanks, pushed.

Almost every class contains a processError() method with an identical definition, just forwarding the call to ErrorHandler.processError(Libvirt). This function is always called after a libvirt function call (as per its javadoc comment). But, actually, there's no use in always calling processError when there was no error signalled by the libvirt function having been called. This is just a waste of CPU cycles. Furthermore, it's more than ugly that the error handling is littered all over the place in every class. This patch lays ground for generalizing the error handling in a common place and removing those functions from the individual classes. Basically, this copies the processError(int) and processError<T>(T) methods from the Connect class to the ErrorHandler class as static methods. It deprecates the processError(Libvirt) method, which will be removed eventually in a later patch. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/ErrorHandler.java | 47 ++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/libvirt/ErrorHandler.java b/src/main/java/org/libvirt/ErrorHandler.java index 434c85d..8dcac8f 100644 --- a/src/main/java/org/libvirt/ErrorHandler.java +++ b/src/main/java/org/libvirt/ErrorHandler.java @@ -3,6 +3,11 @@ package org.libvirt; import org.libvirt.jna.Libvirt; import org.libvirt.jna.virError; +import static org.libvirt.Library.libvirt; + +import com.sun.jna.Pointer; +import com.sun.jna.PointerType; + /** * Utility class which processes the last error from the libvirt library. It * turns errors into Libvirt Exceptions. @@ -18,7 +23,12 @@ public class ErrorHandler { * the active connection * @throws LibvirtException */ - public static void processError(Libvirt libvirt) throws LibvirtException { + @Deprecated + static void processError(Libvirt libvirt) throws LibvirtException { + processError(); + } + + private static final void processError() throws LibvirtException { virError vError = libvirt.virGetLastError(); if (vError != null) { Error error = new Error(vError); @@ -30,4 +40,39 @@ public class ErrorHandler { } } } + + /** + * Calls {@link #processError()} when the given libvirt return code + * indicates an error. + * + * @param ret libvirt return code, indicating error if -1. + * @return {@code ret} + * @throws LibvirtException + */ + static final int processError(int ret) throws LibvirtException { + if (ret == -1) processError(); + return ret; + } + + /** + * Calls {@link #processError()} if {@code arg} is null. + * + * @param arg An arbitrary object returned by libvirt. + * @return {@code arg} + * @throws LibvirtException + */ + static final <T extends PointerType> T processError(T arg) throws LibvirtException { + if (arg == null) processError(); + return arg; + } + + static final Pointer processError(Pointer arg) throws LibvirtException { + if (arg == null) processError(); + return arg; + } + + static final String processError(String str) throws LibvirtException { + if (str == null) processError(); + return str; + } } -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:23PM +0100, Claudio Bley wrote:
Almost every class contains a processError() method with an identical definition, just forwarding the call to ErrorHandler.processError(Libvirt).
This function is always called after a libvirt function call (as per its javadoc comment).
But, actually, there's no use in always calling processError when there was no error signalled by the libvirt function having been called. This is just a waste of CPU cycles.
Furthermore, it's more than ugly that the error handling is littered all over the place in every class.
This patch lays ground for generalizing the error handling in a common place and removing those functions from the individual classes.
Basically, this copies the processError(int) and processError<T>(T) methods from the Connect class to the ErrorHandler class as static methods.
It deprecates the processError(Libvirt) method, which will be removed eventually in a later patch.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/ErrorHandler.java | 47 ++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:43:15 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:23PM +0100, Claudio Bley wrote:
Almost every class contains a processError() method with an identical definition, just forwarding the call to ErrorHandler.processError(Libvirt).
This function is always called after a libvirt function call (as per its javadoc comment).
But, actually, there's no use in always calling processError when there was no error signalled by the libvirt function having been called. This is just a waste of CPU cycles.
Furthermore, it's more than ugly that the error handling is littered all over the place in every class.
This patch lays ground for generalizing the error handling in a common place and removing those functions from the individual classes.
Basically, this copies the processError(int) and processError<T>(T) methods from the Connect class to the ErrorHandler class as static methods.
It deprecates the processError(Libvirt) method, which will be removed eventually in a later patch.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/ErrorHandler.java | 47 ++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)
ACK
Thanks, pushed.

Wrap any fallible libvirt function in a call to ErrorHandler.processError(..). Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Device.java | 49 ++++++++++----------------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/libvirt/Device.java b/src/main/java/org/libvirt/Device.java index d55321e..a3b20b8 100644 --- a/src/main/java/org/libvirt/Device.java +++ b/src/main/java/org/libvirt/Device.java @@ -2,6 +2,9 @@ package org.libvirt; import org.libvirt.jna.DevicePointer; import static org.libvirt.Library.libvirt; +import static org.libvirt.ErrorHandler.processError; + +import com.sun.jna.Pointer; import com.sun.jna.Pointer; @@ -43,8 +46,7 @@ public class Device { public int destroy() throws LibvirtException { int success = 0; if (VDP != null) { - success = libvirt.virNodeDeviceDestroy(VDP); - processError(); + success = processError(libvirt.virNodeDeviceDestroy(VDP)); VDP = null; } @@ -58,9 +60,7 @@ public class Device { * @throws LibvirtException */ public int detach() throws LibvirtException { - int num = libvirt.virNodeDeviceDettach(VDP); - processError(); - return num; + return processError(libvirt.virNodeDeviceDettach(VDP)); } @Override @@ -78,8 +78,7 @@ public class Device { public int free() throws LibvirtException { int success = 0; if (VDP != null) { - success = libvirt.virNodeDeviceFree(VDP); - processError(); + success = processError(libvirt.virNodeDeviceFree(VDP)); VDP = null; } @@ -92,9 +91,7 @@ public class Device { * @throws LibvirtException */ public String getName() throws LibvirtException { - String name = libvirt.virNodeDeviceGetName(VDP); - processError(); - return name; + return processError(libvirt.virNodeDeviceGetName(VDP)); } /** @@ -103,9 +100,7 @@ public class Device { * @throws LibvirtException */ public int getNumberOfCapabilities() throws LibvirtException { - int num = libvirt.virNodeDeviceNumOfCaps(VDP); - processError(); - return num; + return processError(libvirt.virNodeDeviceNumOfCaps(VDP)); } /** @@ -114,9 +109,7 @@ public class Device { * @throws LibvirtException */ public String getParent() throws LibvirtException { - String parent = libvirt.virNodeDeviceGetParent(VDP); - processError(); - return parent; + return processError(libvirt.virNodeDeviceGetParent(VDP)); } /** @@ -125,9 +118,7 @@ public class Device { * @throws LibvirtException */ public String getXMLDescription() throws LibvirtException { - String desc = libvirt.virNodeDeviceGetXMLDesc(VDP); - processError(); - return desc; + return processError(libvirt.virNodeDeviceGetXMLDesc(VDP)); } /** @@ -140,8 +131,8 @@ public class Device { if (maxCaps > 0) { Pointer[] ptrs = new Pointer[maxCaps]; - int got = libvirt.virNodeDeviceListCaps(VDP, ptrs, maxCaps); - processError(); + int got = processError(libvirt.virNodeDeviceListCaps(VDP, ptrs, maxCaps)); + return Library.toStringArray(ptrs, got); } else { return Library.NO_STRINGS; @@ -149,22 +140,12 @@ public class Device { } /** - * Error handling logic to throw errors. Must be called after every libvirt - * call. - */ - protected void processError() throws LibvirtException { - virConnect.processError(); - } - - /** * ReAttach a device to the node. * * @throws LibvirtException */ public int reAttach() throws LibvirtException { - int num = libvirt.virNodeDeviceReAttach(VDP); - processError(); - return num; + return processError(libvirt.virNodeDeviceReAttach(VDP)); } /** @@ -174,8 +155,6 @@ public class Device { * @throws LibvirtException */ public int reset() throws LibvirtException { - int num = libvirt.virNodeDeviceReset(VDP); - processError(); - return num; + return processError(libvirt.virNodeDeviceReset(VDP)); } } -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:24PM +0100, Claudio Bley wrote:
Wrap any fallible libvirt function in a call to ErrorHandler.processError(..).
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Device.java | 49 ++++++++++----------------------- 1 file changed, 14 insertions(+), 35 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:43:43 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:24PM +0100, Claudio Bley wrote:
Wrap any fallible libvirt function in a call to ErrorHandler.processError(..).
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Device.java | 49 ++++++++++----------------------- 1 file changed, 14 insertions(+), 35 deletions(-)
ACK
Thanks, pushed.

Wrap any fallible libvirt function in a call to ErrorHandler.processError(..). Also update erroneous javadoc comments stating that methods would return a value in case an error occurs. In case of a libvirt error, a LibvirtException is thrown. Add processErrorIfZero(long) to ErrorHandler class to handle special libvirt return codes, such as for virDomainGetMaxMemory. Use it in Domain.getMaxMemory(). Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 328 +++++++++------------------ src/main/java/org/libvirt/ErrorHandler.java | 5 + 2 files changed, 113 insertions(+), 220 deletions(-) diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index b50e182..047ac33 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -13,6 +13,8 @@ import org.libvirt.jna.virDomainMemoryStats; import org.libvirt.jna.virSchedParameter; import org.libvirt.jna.virVcpuInfo; import static org.libvirt.Library.libvirt; +import static org.libvirt.ErrorHandler.processError; +import static org.libvirt.ErrorHandler.processErrorIfZero; import com.sun.jna.Native; import com.sun.jna.NativeLong; @@ -160,13 +162,11 @@ public class Domain { * @see <a * href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainAbortJob">Libvirt * Documentation</a> - * @return 0 in case of success and -1 in case of failure. + * @return <em>ignore</em> (always 0) * @throws LibvirtException */ public int abortJob() throws LibvirtException { - int returnValue = libvirt.virDomainAbortJob(VDP); - processError(); - return returnValue; + return processError(libvirt.virDomainAbortJob(VDP)); } /** @@ -180,8 +180,7 @@ public class Domain { * @throws LibvirtException */ public void attachDevice(String xmlDesc) throws LibvirtException { - libvirt.virDomainAttachDevice(VDP, xmlDesc); - processError(); + processError(libvirt.virDomainAttachDevice(VDP, xmlDesc)); } /** @@ -197,8 +196,7 @@ public class Domain { * @throws LibvirtException */ public void attachDeviceFlags(String xmlDesc, int flags) throws LibvirtException { - libvirt.virDomainAttachDeviceFlags(VDP, xmlDesc, flags); - processError(); + processError(libvirt.virDomainAttachDeviceFlags(VDP, xmlDesc, flags)); } /** @@ -207,14 +205,13 @@ public class Domain { * * @param path * the path to the block device - * @return the info, or null if an error + * @return the info * @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; + processError(libvirt.virDomainGetBlockInfo(VDP, path, info, 0)); + return new DomainBlockInfo(info); } /** @@ -234,9 +231,8 @@ public class Domain { */ public DomainBlockStats blockStats(String path) throws LibvirtException { virDomainBlockStats stats = new virDomainBlockStats(); - int success = libvirt.virDomainBlockStats(VDP, path, stats, new SizeT(stats.size())); - processError(); - return success == 0 ? new DomainBlockStats(stats) : null; + processError(libvirt.virDomainBlockStats(VDP, path, stats, new SizeT(stats.size()))); + return new DomainBlockStats(stats); } /** @@ -251,8 +247,7 @@ public class Domain { * @throws LibvirtException */ public void blockResize(String disk, long size, int flags) throws LibvirtException { - int returnValue = libvirt.virDomainBlockResize(VDP, disk, size, flags); - processError(); + processError(libvirt.virDomainBlockResize(VDP, disk, size, flags)); } @@ -267,8 +262,7 @@ public class Domain { * @throws LibvirtException */ public void coreDump(String to, int flags) throws LibvirtException { - libvirt.virDomainCoreDump(VDP, to, flags); - processError(); + processError(libvirt.virDomainCoreDump(VDP, to, flags)); } /** @@ -283,12 +277,11 @@ public class Domain { * Launches this defined domain. If the call succeed the domain moves from * the defined to the running domains pools. * + * @return <em>ignore</em> (always 0) * @throws LibvirtException */ public int create() throws LibvirtException { - int returnValue = libvirt.virDomainCreate(VDP); - processError(); - return returnValue; + return processError(libvirt.virDomainCreate(VDP)); } /** @@ -296,12 +289,11 @@ public class Domain { * If the call succeed the domain moves from * the defined to the running domains pools. * + * @return <em>ignore</em> (always 0) * @throws LibvirtException */ public int create(int flags) throws LibvirtException { - int returnValue = libvirt.virDomainCreateWithFlags(VDP, flags); - processError(); - return returnValue; + return processError(libvirt.virDomainCreateWithFlags(VDP, flags)); } /** @@ -313,8 +305,7 @@ public class Domain { * @throws LibvirtException */ public void destroy() throws LibvirtException { - libvirt.virDomainDestroy(VDP); - processError(); + processError(libvirt.virDomainDestroy(VDP)); } /** @@ -328,8 +319,7 @@ public class Domain { * @throws LibvirtException */ public void detachDevice(String xmlDesc) throws LibvirtException { - libvirt.virDomainDetachDevice(VDP, xmlDesc); - processError(); + processError(libvirt.virDomainDetachDevice(VDP, xmlDesc)); } /** @@ -343,8 +333,7 @@ public class Domain { * @throws LibvirtException */ public void detachDeviceFlags(String xmlDesc, int flags) throws LibvirtException { - libvirt.virDomainDetachDeviceFlags(VDP, xmlDesc, flags); - processError(); + processError(libvirt.virDomainDetachDeviceFlags(VDP, xmlDesc, flags)); } @Override @@ -357,13 +346,12 @@ public class Domain { * structure is freed and should not be used thereafter. * * @throws LibvirtException - * @return number of references left (>= 0) for success, -1 for failure. + * @return number of references left (>= 0) */ public int free() throws LibvirtException { int success = 0; if (VDP != null) { - success = libvirt.virDomainFree(VDP); - processError(); + success = processError(libvirt.virDomainFree(VDP)); VDP = null; } @@ -379,8 +367,7 @@ public class Domain { */ public boolean getAutostart() throws LibvirtException { IntByReference autoStart = new IntByReference(); - libvirt.virDomainGetAutostart(VDP, autoStart); - processError(); + processError(libvirt.virDomainGetAutostart(VDP, autoStart)); return autoStart.getValue() != 0 ? true : false; } @@ -400,9 +387,7 @@ public class Domain { * @throws LibvirtException */ public int getID() throws LibvirtException { - int returnValue = libvirt.virDomainGetID(VDP); - processError(); - return returnValue; + return processError(libvirt.virDomainGetID(VDP)); } /** @@ -418,14 +403,9 @@ public class Domain { * @throws LibvirtException */ public DomainInfo getInfo() throws LibvirtException { - DomainInfo returnValue = null; virDomainInfo vInfo = new virDomainInfo(); - int success = libvirt.virDomainGetInfo(VDP, vInfo); - processError(); - if (success == 0) { - returnValue = new DomainInfo(vInfo); - } - return returnValue; + processError(libvirt.virDomainGetInfo(VDP, vInfo)); + return new DomainInfo(vInfo); } /** @@ -439,14 +419,9 @@ public class Domain { * @throws LibvirtException */ public DomainJobInfo getJobInfo() throws LibvirtException { - DomainJobInfo returnValue = null; virDomainJobInfo vInfo = new virDomainJobInfo(); - int success = libvirt.virDomainGetJobInfo(VDP, vInfo); - processError(); - if (success == 0) { - returnValue = new DomainJobInfo(vInfo); - } - return returnValue; + processError(libvirt.virDomainGetJobInfo(VDP, vInfo)); + return new DomainJobInfo(vInfo); } /** @@ -456,9 +431,9 @@ public class Domain { * @throws LibvirtException */ public long getMaxMemory() throws LibvirtException { + // the memory size in kibibytes (blocks of 1024 bytes), or 0 in case of error. NativeLong returnValue = libvirt.virDomainGetMaxMemory(VDP); - processError(); - return returnValue.longValue(); + return processErrorIfZero(returnValue.longValue()); } /** @@ -471,21 +446,17 @@ public class Domain { * @throws LibvirtException */ public int getMaxVcpus() throws LibvirtException { - int returnValue = libvirt.virDomainGetMaxVcpus(VDP); - processError(); - return returnValue; + return processError(libvirt.virDomainGetMaxVcpus(VDP)); } /** * Gets the public name for this domain * - * @return the name - * @throws LibvirtException + * @return the name, null if there is no name + * @throws LibvirtException <em>never</em> */ public String getName() throws LibvirtException { - String returnValue = libvirt.virDomainGetName(VDP); - processError(); - return returnValue; + return libvirt.virDomainGetName(VDP); } /** @@ -495,8 +466,7 @@ public class Domain { * @throws LibvirtException */ public String getOSType() throws LibvirtException { - Pointer ptr = libvirt.virDomainGetOSType(VDP); - processError(); + Pointer ptr = processError(libvirt.virDomainGetOSType(VDP)); try { return Library.getString(ptr); } finally { @@ -513,18 +483,14 @@ public class Domain { public SchedParameter[] getSchedulerParameters() throws LibvirtException { IntByReference nParams = new IntByReference(); SchedParameter[] returnValue = new SchedParameter[0]; - Pointer pScheduler = libvirt.virDomainGetSchedulerType(VDP, nParams); - processError(); - if (pScheduler != null) { - String scheduler = Library.getString(pScheduler); - Library.free(pScheduler); - virSchedParameter[] nativeParams = new virSchedParameter[nParams.getValue()]; - returnValue = new SchedParameter[nParams.getValue()]; - libvirt.virDomainGetSchedulerParameters(VDP, nativeParams, nParams); - processError(); - for (int x = 0; x < nParams.getValue(); x++) { - returnValue[x] = SchedParameter.create(nativeParams[x]); - } + Pointer pScheduler = processError(libvirt.virDomainGetSchedulerType(VDP, nParams)); + String scheduler = Library.getString(pScheduler); + Library.free(pScheduler); + virSchedParameter[] nativeParams = new virSchedParameter[nParams.getValue()]; + returnValue = new SchedParameter[nParams.getValue()]; + processError(libvirt.virDomainGetSchedulerParameters(VDP, nativeParams, nParams)); + for (int x = 0; x < nParams.getValue(); x++) { + returnValue[x] = SchedParameter.create(nativeParams[x]); } return returnValue; @@ -542,8 +508,7 @@ public class Domain { */ public String[] getSchedulerType() throws LibvirtException { IntByReference nParams = new IntByReference(); - Pointer pScheduler = libvirt.virDomainGetSchedulerType(VDP, nParams); - processError(); + Pointer pScheduler = processError(libvirt.virDomainGetSchedulerType(VDP, nParams)); String[] array = new String[1]; array[0] = Library.getString(pScheduler); Library.free(pScheduler); @@ -559,13 +524,8 @@ public class Domain { */ public int[] getUUID() throws LibvirtException { byte[] bytes = new byte[Libvirt.VIR_UUID_BUFLEN]; - int success = libvirt.virDomainGetUUID(VDP, bytes); - processError(); - int[] returnValue = new int[0]; - if (success == 0) { - returnValue = Connect.convertUUIDBytes(bytes); - } - return returnValue; + processError(libvirt.virDomainGetUUID(VDP, bytes)); + return Connect.convertUUIDBytes(bytes); } /** @@ -577,13 +537,8 @@ public class Domain { */ public String getUUIDString() throws LibvirtException { byte[] bytes = new byte[Libvirt.VIR_UUID_STRING_BUFLEN]; - int success = libvirt.virDomainGetUUIDString(VDP, bytes); - processError(); - String returnValue = null; - if (success == 0) { - returnValue = Native.toString(bytes); - } - return returnValue; + processError(libvirt.virDomainGetUUIDString(VDP, bytes)); + return Native.toString(bytes); } /** @@ -603,8 +558,7 @@ public class Domain { virVcpuInfo[] infos = new virVcpuInfo[cpuCount]; returnValue = new int[cpuCount * maplength]; byte[] cpumaps = new byte[cpuCount * maplength]; - libvirt.virDomainGetVcpus(VDP, infos, cpuCount, cpumaps, maplength); - processError(); + processError(libvirt.virDomainGetVcpus(VDP, infos, cpuCount, cpumaps, maplength)); for (int x = 0; x < cpuCount * maplength; x++) { returnValue[x] = cpumaps[x]; } @@ -622,8 +576,7 @@ public class Domain { int cpuCount = getMaxVcpus(); VcpuInfo[] returnValue = new VcpuInfo[cpuCount]; virVcpuInfo[] infos = new virVcpuInfo[cpuCount]; - libvirt.virDomainGetVcpus(VDP, infos, cpuCount, null, 0); - processError(); + processError(libvirt.virDomainGetVcpus(VDP, infos, cpuCount, null, 0)); for (int x = 0; x < cpuCount; x++) { returnValue[x] = new VcpuInfo(infos[x]); } @@ -642,8 +595,7 @@ public class Domain { * Description format </a> */ public String getXMLDesc(int flags) throws LibvirtException { - Pointer ptr = libvirt.virDomainGetXMLDesc(VDP, flags); - processError(); + Pointer ptr = processError(libvirt.virDomainGetXMLDesc(VDP, flags)); try { return Library.getString(ptr); } finally { @@ -656,13 +608,11 @@ public class Domain { * * @see <a href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainHasCurrentSnapshot>Libvi * r t Documentation</a> - * @return 1 if running, 0 if inactive, -1 on error + * @return 1 if running, 0 if inactive * @throws LibvirtException */ public int hasCurrentSnapshot() throws LibvirtException { - int returnValue = libvirt.virDomainHasCurrentSnapshot(VDP, 0); - processError(); - return returnValue; + return processError(libvirt.virDomainHasCurrentSnapshot(VDP, 0)); } /** @@ -675,9 +625,7 @@ public class Domain { * @throws LibvirtException */ public int hasManagedSaveImage() throws LibvirtException { - int returnValue = libvirt.virDomainHasManagedSaveImage(VDP, 0); - processError(); - return returnValue; + return processError(libvirt.virDomainHasManagedSaveImage(VDP, 0)); } /** @@ -695,8 +643,7 @@ public class Domain { */ public DomainInterfaceStats interfaceStats(String path) throws LibvirtException { virDomainInterfaceStats stats = new virDomainInterfaceStats(); - libvirt.virDomainInterfaceStats(VDP, path, stats, new SizeT(stats.size())); - processError(); + processError(libvirt.virDomainInterfaceStats(VDP, path, stats, new SizeT(stats.size()))); return new DomainInterfaceStats(stats); } @@ -706,13 +653,11 @@ public class Domain { * @see <a * href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainIsActive">Libvirt * Documentation</a> - * @return 1 if running, 0 if inactive, -1 on error + * @return 1 if running, 0 if inactive * @throws LibvirtException */ public int isActive() throws LibvirtException { - int returnValue = libvirt.virDomainIsActive(VDP); - processError(); - return returnValue; + return processError(libvirt.virDomainIsActive(VDP)); } /** @@ -722,13 +667,11 @@ public class Domain { * @see <a * href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainIsPersistent">Libvirt * Documentation</a> - * @return 1 if persistent, 0 if transient, -1 on error + * @return 1 if persistent, 0 if transient * @throws LibvirtException */ public int isPersistent() throws LibvirtException { - int returnValue = libvirt.virDomainIsPersistent(VDP); - processError(); - return returnValue; + return processError(libvirt.virDomainIsPersistent(VDP)); } /** @@ -737,13 +680,11 @@ public class Domain { * @see <a * href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainManagedSave">Libvirt * Documentation</a> - * @return 0 in case of success or -1 in case of failure + * @return always 0 * @throws LibvirtException */ public int managedSave() throws LibvirtException { - int returnValue = libvirt.virDomainManagedSave(VDP, 0); - processError(); - return returnValue; + return processError(libvirt.virDomainManagedSave(VDP, 0)); } /** @@ -752,13 +693,11 @@ public class Domain { * @see <a * href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainManagedSaveRemove">Libvirt * Documentation</a> - * @return 0 in case of success, and -1 in case of error + * @return always 0 * @throws LibvirtException */ public int managedSaveRemove() throws LibvirtException { - int returnValue = libvirt.virDomainManagedSaveRemove(VDP, 0); - processError(); - return returnValue; + return processError(libvirt.virDomainManagedSaveRemove(VDP, 0)); } /** @@ -766,19 +705,16 @@ public class Domain { * * @param number * the number of stats to retrieve - * @return the collection of stats, or null if an error occurs. + * @return the collection of stats * @throws LibvirtException */ public MemoryStatistic[] memoryStats(int number) throws LibvirtException { virDomainMemoryStats[] stats = new virDomainMemoryStats[number]; MemoryStatistic[] returnStats = null; - int result = libvirt.virDomainMemoryStats(VDP, stats, number, 0); - processError(); - if (result >= 0) { - returnStats = new MemoryStatistic[result]; - for (int x = 0; x < result; x++) { - returnStats[x] = new MemoryStatistic(stats[x]); - } + int result = processError(libvirt.virDomainMemoryStats(VDP, stats, number, 0)); + returnStats = new MemoryStatistic[result]; + for (int x = 0; x < result; x++) { + returnStats[x] = new MemoryStatistic(stats[x]); } return returnStats; } @@ -852,8 +788,8 @@ public class Domain { * @throws LibvirtException if the migration fails */ public Domain migrate(Connect dconn, long flags, String dxml, String dname, String uri, long bandwidth) throws LibvirtException { - DomainPointer newPtr = libvirt.virDomainMigrate2(VDP, dconn.VCP, dxml, new NativeLong(flags), dname, uri, new NativeLong(bandwidth)); - processError(); + DomainPointer newPtr = + processError(libvirt.virDomainMigrate2(VDP, dconn.VCP, dxml, new NativeLong(flags), dname, uri, new NativeLong(bandwidth))); return new Domain(dconn, newPtr); } @@ -896,14 +832,13 @@ public class Domain { * (optional) dest hostname/URI as seen from the source host * @param bandwidth * optional) specify migration bandwidth limit in Mbps - * @return the new domain object if the migration was successful, or NULL in - * case of error. Note that the new domain object exists in the - * scope of the destination connection (dconn). + * @return the new domain object if the migration was successful. Note that + * the new domain object exists in the scope of the destination + * connection (dconn). * @throws LibvirtException */ public Domain migrate(Connect dconn, long flags, String dname, String uri, long bandwidth) throws LibvirtException { - DomainPointer newPtr = libvirt.virDomainMigrate(VDP, dconn.VCP, new NativeLong(flags), dname, uri, new NativeLong(bandwidth)); - processError(); + DomainPointer newPtr = processError(libvirt.virDomainMigrate(VDP, dconn.VCP, new NativeLong(flags), dname, uri, new NativeLong(bandwidth))); return new Domain(dconn, newPtr); } @@ -916,13 +851,11 @@ public class Domain { * Documentation</a> * @param downtime * the time to be down - * @return 0 in case of success, -1 otherwise. + * @return always 0 * @throws LibvirtException */ public int migrateSetMaxDowntime(long downtime) throws LibvirtException { - int returnValue = libvirt.virDomainMigrateSetMaxDowntime(VDP, downtime, 0); - processError(); - return returnValue; + return processError(libvirt.virDomainMigrateSetMaxDowntime(VDP, downtime, 0)); } /** @@ -956,9 +889,9 @@ public class Domain { * @throws LibvirtException */ public int migrateToURI(String dconnuri, String miguri, String dxml, long flags, String dname, long bandwidth) throws LibvirtException { - int returnValue = libvirt.virDomainMigrateToURI2(VDP, dconnuri, miguri, dxml, new NativeLong(flags), dname, new NativeLong(bandwidth)); - processError(); - return returnValue; + return processError(libvirt.virDomainMigrateToURI2(VDP, dconnuri, miguri, + dxml, new NativeLong(flags), + dname, new NativeLong(bandwidth))); } /** @@ -981,9 +914,7 @@ public class Domain { * @throws LibvirtException */ public int migrateToURI(String uri, long flags, String dname, long bandwidth) throws LibvirtException { - int returnValue = libvirt.virDomainMigrateToURI(VDP, uri, new NativeLong(flags), dname, new NativeLong(bandwidth)); - processError(); - return returnValue; + return processError(libvirt.virDomainMigrateToURI(VDP, uri, new NativeLong(flags), dname, new NativeLong(bandwidth))); } /** @@ -1005,16 +936,7 @@ public class Domain { for (int x = 0; x < cpumap.length; x++) { packedMap[x] = (byte) cpumap[x]; } - libvirt.virDomainPinVcpu(VDP, vcpu, packedMap, cpumap.length); - processError(); - } - - /** - * Error handling logic to throw errors. Must be called after every libvirt - * call. - */ - protected void processError() throws LibvirtException { - virConnect.processError(); + processError(libvirt.virDomainPinVcpu(VDP, vcpu, packedMap, cpumap.length)); } /** @@ -1027,8 +949,7 @@ public class Domain { * @throws LibvirtException */ public void reboot(int flags) throws LibvirtException { - libvirt.virDomainReboot(VDP, flags); - processError(); + processError(libvirt.virDomainReboot(VDP, flags)); } /** @@ -1039,8 +960,7 @@ public class Domain { * @throws LibvirtException */ public void resume() throws LibvirtException { - libvirt.virDomainResume(VDP); - processError(); + processError(libvirt.virDomainResume(VDP)); } /** @@ -1051,13 +971,11 @@ public class Domain { * >Libvirt Documentation</> * @param snapshot * the snapshot to revert to - * @return 0 if the creation is successful, -1 on error. + * @return 0 if the creation is successful * @throws LibvirtException */ public int revertToSnapshot(DomainSnapshot snapshot) throws LibvirtException { - int returnCode = libvirt.virDomainRevertToSnapshot(snapshot.VDSP, 0); - processError(); - return returnCode; + return processError(libvirt.virDomainRevertToSnapshot(snapshot.VDSP, 0)); } /** @@ -1071,8 +989,7 @@ public class Domain { * @throws LibvirtException */ public void save(String to) throws LibvirtException { - libvirt.virDomainSave(VDP, to); - processError(); + processError(libvirt.virDomainSave(VDP, to)); } /** @@ -1084,8 +1001,7 @@ public class Domain { */ public void setAutostart(boolean autostart) throws LibvirtException { int autoValue = autostart ? 1 : 0; - libvirt.virDomainSetAutostart(VDP, autoValue); - processError(); + processError(libvirt.virDomainSetAutostart(VDP, autoValue)); } /** @@ -1097,8 +1013,7 @@ public class Domain { * @throws LibvirtException */ public void setMaxMemory(long memory) throws LibvirtException { - libvirt.virDomainSetMaxMemory(VDP, new NativeLong(memory)); - processError(); + processError(libvirt.virDomainSetMaxMemory(VDP, new NativeLong(memory))); } /** @@ -1111,8 +1026,7 @@ public class Domain { * @throws LibvirtException */ public void setMemory(long memory) throws LibvirtException { - libvirt.virDomainSetMemory(VDP, new NativeLong(memory)); - processError(); + processError(libvirt.virDomainSetMemory(VDP, new NativeLong(memory))); } /** @@ -1127,8 +1041,7 @@ public class Domain { for (int x = 0; x < params.length; x++) { input[x] = SchedParameter.toNative(params[x]); } - libvirt.virDomainSetSchedulerParameters(VDP, input, params.length); - processError(); + processError(libvirt.virDomainSetSchedulerParameters(VDP, input, params.length)); } /** @@ -1142,8 +1055,7 @@ public class Domain { * @throws LibvirtException */ public void setVcpus(int nvcpus) throws LibvirtException { - libvirt.virDomainSetVcpus(VDP, nvcpus); - processError(); + processError(libvirt.virDomainSetVcpus(VDP, nvcpus)); } /** @@ -1155,8 +1067,7 @@ public class Domain { * @throws LibvirtException */ public void shutdown() throws LibvirtException { - libvirt.virDomainShutdown(VDP); - processError(); + processError(libvirt.virDomainShutdown(VDP)); } /** @@ -1170,17 +1081,12 @@ public class Domain { * string containing an XML description of the domain * @param flags * flags for creating the snapshot, see the virDomainSnapshotCreateFlags for the flag options - * @return the snapshot, or null on Error + * @return the snapshot * @throws LibvirtException */ public DomainSnapshot snapshotCreateXML(String xmlDesc, int flags) throws LibvirtException { - DomainSnapshotPointer ptr = libvirt.virDomainSnapshotCreateXML(VDP, xmlDesc, flags); - processError(); - DomainSnapshot returnValue = null; - if (ptr != null) { - returnValue = new DomainSnapshot(virConnect, ptr); - } - return returnValue; + DomainSnapshotPointer ptr = processError(libvirt.virDomainSnapshotCreateXML(VDP, xmlDesc, flags)); + return new DomainSnapshot(virConnect, ptr); } /** @@ -1209,17 +1115,12 @@ public class Domain { * @see <a * href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnapshotCurrent">Libvirt * Documentation</a> - * @return the snapshot, or null on Error + * @return the snapshot * @throws LibvirtException */ public DomainSnapshot snapshotCurrent() throws LibvirtException { - DomainSnapshotPointer ptr = libvirt.virDomainSnapshotCurrent(VDP, 0); - processError(); - DomainSnapshot returnValue = null; - if (ptr != null) { - returnValue = new DomainSnapshot(virConnect, ptr); - } - return returnValue; + DomainSnapshotPointer ptr = processError(libvirt.virDomainSnapshotCurrent(VDP, 0)); + return new DomainSnapshot(virConnect, ptr); } /** @@ -1237,8 +1138,7 @@ public class Domain { if (num >= 0) { returnValue = new String[num]; if (num > 0) { - libvirt.virDomainSnapshotListNames(VDP, returnValue, num, flags); - processError(); + processError(libvirt.virDomainSnapshotListNames(VDP, returnValue, num, flags)); } } return returnValue; @@ -1269,17 +1169,12 @@ public class Domain { * Documentation</a> * @param name * the name - * @return The located snapshot, or null if an error + * @return The located snapshot * @throws LibvirtException */ public DomainSnapshot snapshotLookupByName(String name) throws LibvirtException { - DomainSnapshotPointer ptr = libvirt.virDomainSnapshotLookupByName(VDP, name, 0); - processError(); - DomainSnapshot returnValue = null; - if (ptr != null) { - returnValue = new DomainSnapshot(virConnect, ptr); - } - return returnValue; + DomainSnapshotPointer ptr = processError(libvirt.virDomainSnapshotLookupByName(VDP, name, 0)); + return new DomainSnapshot(virConnect, ptr); } /** @@ -1290,9 +1185,7 @@ public class Domain { * Documentation</a> */ public int snapshotNum() throws LibvirtException { - int returnValue = libvirt.virDomainSnapshotNum(VDP, 0); - processError(); - return returnValue; + return processError(libvirt.virDomainSnapshotNum(VDP, 0)); } /** @@ -1304,8 +1197,7 @@ public class Domain { * @throws LibvirtException */ public void suspend() throws LibvirtException { - libvirt.virDomainSuspend(VDP); - processError(); + processError(libvirt.virDomainSuspend(VDP)); } /** @@ -1314,8 +1206,7 @@ public class Domain { * @throws LibvirtException */ public void undefine() throws LibvirtException { - libvirt.virDomainUndefine(VDP); - processError(); + processError(libvirt.virDomainUndefine(VDP)); } /** @@ -1327,8 +1218,7 @@ public class Domain { * @throws LibvirtException */ public void undefine(int flags) throws LibvirtException { - libvirt.virDomainUndefineFlags(VDP, flags); - processError(); + processError(libvirt.virDomainUndefineFlags(VDP, flags)); } /** @@ -1339,13 +1229,11 @@ public class Domain { * the xml to update with * @param flags * controls the update - * @return 0 in case of success, -1 in case of failure. + * @return always 0 * @throws LibvirtException */ public int updateDeviceFlags(String xml, int flags) throws LibvirtException { - int returnValue = libvirt.virDomainUpdateDeviceFlags(VDP, xml, flags); - processError(); - return returnValue; + return processError(libvirt.virDomainUpdateDeviceFlags(VDP, xml, flags)); } } diff --git a/src/main/java/org/libvirt/ErrorHandler.java b/src/main/java/org/libvirt/ErrorHandler.java index 8dcac8f..01e25d6 100644 --- a/src/main/java/org/libvirt/ErrorHandler.java +++ b/src/main/java/org/libvirt/ErrorHandler.java @@ -75,4 +75,9 @@ public class ErrorHandler { if (str == null) processError(); return str; } + + static final long processErrorIfZero(long ret) throws LibvirtException { + if (ret == 0) processError(); + return ret; + } } -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:25PM +0100, Claudio Bley wrote:
Wrap any fallible libvirt function in a call to ErrorHandler.processError(..).
Also update erroneous javadoc comments stating that methods would return a value in case an error occurs. In case of a libvirt error, a LibvirtException is thrown.
Add processErrorIfZero(long) to ErrorHandler class to handle special libvirt return codes, such as for virDomainGetMaxMemory. Use it in Domain.getMaxMemory().
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 328 +++++++++------------------ src/main/java/org/libvirt/ErrorHandler.java | 5 + 2 files changed, 113 insertions(+), 220 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:44:42 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:25PM +0100, Claudio Bley wrote:
Wrap any fallible libvirt function in a call to ErrorHandler.processError(..).
Also update erroneous javadoc comments stating that methods would return a value in case an error occurs. In case of a libvirt error, a LibvirtException is thrown.
Add processErrorIfZero(long) to ErrorHandler class to handle special libvirt return codes, such as for virDomainGetMaxMemory. Use it in Domain.getMaxMemory().
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 328 +++++++++------------------ src/main/java/org/libvirt/ErrorHandler.java | 5 + 2 files changed, 113 insertions(+), 220 deletions(-)
ACK
Thanks, pushed.

Wrap any fallible libvirt function in a call to ErrorHandler.processError(..). Also correct wrong javadoc comments stating that methods would return a value in case an error happens. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/DomainSnapshot.java | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/libvirt/DomainSnapshot.java b/src/main/java/org/libvirt/DomainSnapshot.java index 9409fef..4736a71 100644 --- a/src/main/java/org/libvirt/DomainSnapshot.java +++ b/src/main/java/org/libvirt/DomainSnapshot.java @@ -2,6 +2,7 @@ package org.libvirt; import org.libvirt.jna.DomainSnapshotPointer; import static org.libvirt.Library.libvirt; +import static org.libvirt.ErrorHandler.processError; public class DomainSnapshot { @@ -28,14 +29,13 @@ public class DomainSnapshot { * Documentation</a> * @param flags * controls the deletion - * @return 0 if the selected snapshot(s) were successfully deleted, -1 on error. + * @return <em>ignore</em> (always 0) * @throws LibvirtException */ public int delete(int flags) throws LibvirtException { int success = 0; if (VDSP != null) { - success = libvirt.virDomainSnapshotDelete(VDSP, flags); - processError(); + success = processError(libvirt.virDomainSnapshotDelete(VDSP, flags)); VDSP = null; } @@ -52,13 +52,12 @@ public class DomainSnapshot { * exist. * * @throws LibvirtException - * @return 0 on success, or -1 on error. + * @return 0 on success */ public int free() throws LibvirtException { int success = 0; if (VDSP != null) { - success = libvirt.virDomainSnapshotFree(VDSP); - processError(); + success = processError(libvirt.virDomainSnapshotFree(VDSP)); VDSP = null; } @@ -72,16 +71,6 @@ public class DomainSnapshot { * @return the XML document */ public String getXMLDesc() throws LibvirtException { - String returnValue = libvirt.virDomainSnapshotGetXMLDesc(VDSP, 0); - processError(); - return returnValue; - } - - /** - * Error handling logic to throw errors. Must be called after every libvirt - * call. - */ - protected void processError() throws LibvirtException { - virConnect.processError(); + return processError(libvirt.virDomainSnapshotGetXMLDesc(VDSP, 0)); } } -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:26PM +0100, Claudio Bley wrote:
Wrap any fallible libvirt function in a call to ErrorHandler.processError(..).
Also correct wrong javadoc comments stating that methods would return a value in case an error happens.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/DomainSnapshot.java | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:45:01 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:26PM +0100, Claudio Bley wrote:
Wrap any fallible libvirt function in a call to ErrorHandler.processError(..).
Also correct wrong javadoc comments stating that methods would return a value in case an error happens.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/DomainSnapshot.java | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-)
ACK
Thanks, pushed.

Wrap any fallible libvirt function in a call to ErrorHandler.processError(..). Also correct wrong javadoc comments stating that methods would return a value in case an error occurs. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Interface.java | 43 ++++++++---------------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/src/main/java/org/libvirt/Interface.java b/src/main/java/org/libvirt/Interface.java index 6ea21b6..e0ddc3f 100644 --- a/src/main/java/org/libvirt/Interface.java +++ b/src/main/java/org/libvirt/Interface.java @@ -2,6 +2,7 @@ package org.libvirt; import org.libvirt.jna.InterfacePointer; import static org.libvirt.Library.libvirt; +import static org.libvirt.ErrorHandler.processError; import com.sun.jna.Pointer; @@ -51,9 +52,7 @@ public class Interface { * @throws LibvirtException */ public int create() throws LibvirtException { - int returnValue = libvirt.virInterfaceCreate(VIP); - processError(); - return returnValue; + return processError(libvirt.virInterfaceCreate(VIP)); } /** @@ -72,9 +71,7 @@ public class Interface { * @throws LibvirtException */ public int destroy() throws LibvirtException { - int returnValue = libvirt.virInterfaceDestroy(VIP); - processError(); - return returnValue; + return processError(libvirt.virInterfaceDestroy(VIP)); } @Override @@ -87,13 +84,12 @@ public class Interface { * structure is freed and should not be used thereafter. * * @throws LibvirtException - * @return number of references left (>= 0) for success, -1 for failure. + * @return number of references left (>= 0) */ public int free() throws LibvirtException { int success = 0; if (VIP != null) { - success = libvirt.virInterfaceFree(VIP); - processError(); + success = processError(libvirt.virInterfaceFree(VIP)); VIP = null; } @@ -106,9 +102,7 @@ public class Interface { * @throws LibvirtException */ public String getMACString() throws LibvirtException { - String name = libvirt.virInterfaceGetMACString(VIP); - processError(); - return name; + return processError(libvirt.virInterfaceGetMACString(VIP)); } /** @@ -117,9 +111,7 @@ public class Interface { * @throws LibvirtException */ public String getName() throws LibvirtException { - String name = libvirt.virInterfaceGetName(VIP); - processError(); - return name; + return processError(libvirt.virInterfaceGetName(VIP)); } /** @@ -128,8 +120,7 @@ public class Interface { * @throws LibvirtException */ public String getXMLDescription(int flags) throws LibvirtException { - Pointer xml = libvirt.virInterfaceGetXMLDesc(VIP, flags); - processError(); + Pointer xml = processError(libvirt.virInterfaceGetXMLDesc(VIP, flags)); try { return Library.getString(xml); } finally { @@ -143,21 +134,11 @@ public class Interface { * @see <a * href="http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceIsActive">Libvirt * Documentation</a> - * @return 1 if running, 0 if inactive, -1 on error + * @return 1 if running, 0 if inactive * @throws LibvirtException */ public int isActive() throws LibvirtException { - int returnValue = libvirt.virInterfaceIsActive(VIP); - processError(); - return returnValue; - } - - /** - * Error handling logic to throw errors. Must be called after every libvirt - * call. - */ - protected void processError() throws LibvirtException { - virConnect.processError(); + return processError(libvirt.virInterfaceIsActive(VIP)); } /** @@ -167,8 +148,6 @@ public class Interface { * @throws LibvirtException */ public int undefine() throws LibvirtException { - int returnValue = libvirt.virInterfaceUndefine(VIP); - processError(); - return returnValue; + return processError(libvirt.virInterfaceUndefine(VIP)); } } -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:27PM +0100, Claudio Bley wrote:
Wrap any fallible libvirt function in a call to ErrorHandler.processError(..).
Also correct wrong javadoc comments stating that methods would return a value in case an error occurs.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Interface.java | 43 ++++++++---------------------- 1 file changed, 11 insertions(+), 32 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:45:22 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:27PM +0100, Claudio Bley wrote:
Wrap any fallible libvirt function in a call to ErrorHandler.processError(..).
Also correct wrong javadoc comments stating that methods would return a value in case an error occurs.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Interface.java | 43 ++++++++---------------------- 1 file changed, 11 insertions(+), 32 deletions(-)
ACK
Thanks, pushed.

Wrap any fallible libvirt function in a call to ErrorHandler.processError(..). Also correct wrong javadoc comments stating that methods would return a value in case an error occurs. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Network.java | 61 +++++++++----------------------- 1 file changed, 17 insertions(+), 44 deletions(-) diff --git a/src/main/java/org/libvirt/Network.java b/src/main/java/org/libvirt/Network.java index 2244c5d..2a77028 100644 --- a/src/main/java/org/libvirt/Network.java +++ b/src/main/java/org/libvirt/Network.java @@ -3,6 +3,7 @@ package org.libvirt; import org.libvirt.jna.Libvirt; import org.libvirt.jna.NetworkPointer; import static org.libvirt.Library.libvirt; +import static org.libvirt.ErrorHandler.processError; import com.sun.jna.Native; import com.sun.jna.Pointer; @@ -43,8 +44,7 @@ public class Network { * @throws LibvirtException */ public void create() throws LibvirtException { - libvirt.virNetworkCreate(VNP); - processError(); + processError(libvirt.virNetworkCreate(VNP)); } /** @@ -56,8 +56,7 @@ public class Network { * @throws LibvirtException */ public void destroy() throws LibvirtException { - libvirt.virNetworkDestroy(VNP); - processError(); + processError(libvirt.virNetworkDestroy(VNP)); } @Override @@ -71,13 +70,12 @@ public class Network { * return an error. * * @throws LibvirtException - * @return number of references left (>= 0) for success, -1 for failure. + * @return number of references left (>= 0) */ public int free() throws LibvirtException { int success = 0; if (VNP != null) { - success = libvirt.virNetworkFree(VNP); - processError(); + success = processError(libvirt.virNetworkFree(VNP)); VNP = null; } @@ -93,8 +91,7 @@ public class Network { */ public boolean getAutostart() throws LibvirtException { IntByReference autoStart = new IntByReference(); - libvirt.virNetworkGetAutostart(VNP, autoStart); - processError(); + processError(libvirt.virNetworkGetAutostart(VNP, autoStart)); return (autoStart.getValue() != 0) ? true : false; } @@ -106,8 +103,7 @@ public class Network { * @throws LibvirtException */ public String getBridgeName() throws LibvirtException { - final Pointer ptr = libvirt.virNetworkGetBridgeName(VNP); - processError(); + final Pointer ptr = processError(libvirt.virNetworkGetBridgeName(VNP)); try { return Library.getString(ptr); } finally { @@ -131,9 +127,7 @@ public class Network { * @throws LibvirtException */ public String getName() throws LibvirtException { - String returnValue = libvirt.virNetworkGetName(VNP); - processError(); - return returnValue; + return processError(libvirt.virNetworkGetName(VNP)); } /** @@ -145,13 +139,8 @@ public class Network { */ public int[] getUUID() throws LibvirtException { byte[] bytes = new byte[Libvirt.VIR_UUID_BUFLEN]; - int success = libvirt.virNetworkGetUUID(VNP, bytes); - processError(); - int[] returnValue = new int[0]; - if (success == 0) { - returnValue = Connect.convertUUIDBytes(bytes); - } - return returnValue; + processError(libvirt.virNetworkGetUUID(VNP, bytes)); + return Connect.convertUUIDBytes(bytes); } /** @@ -163,13 +152,8 @@ public class Network { */ public String getUUIDString() throws LibvirtException { byte[] bytes = new byte[Libvirt.VIR_UUID_STRING_BUFLEN]; - int success = libvirt.virNetworkGetUUIDString(VNP, bytes); - processError(); - String returnValue = null; - if (success == 0) { - returnValue = Native.toString(bytes); - } - return returnValue; + processError(libvirt.virNetworkGetUUIDString(VNP, bytes)); + return Native.toString(bytes); } /** @@ -183,8 +167,7 @@ public class Network { * @throws LibvirtException */ public String getXMLDesc(int flags) throws LibvirtException { - Pointer ptr = libvirt.virNetworkGetXMLDesc(VNP, flags); - processError(); + Pointer ptr = processError(libvirt.virNetworkGetXMLDesc(VNP, flags)); try { return Library.getString(ptr); } finally { @@ -202,9 +185,7 @@ public class Network { * @throws LibvirtException */ public int isActive() throws LibvirtException { - int returnValue = libvirt.virNetworkIsActive(VNP); - processError(); - return returnValue; + return processError(libvirt.virNetworkIsActive(VNP)); } /** @@ -218,13 +199,7 @@ public class Network { * @throws LibvirtException */ public int isPersistent() throws LibvirtException { - int returnValue = libvirt.virNetworkIsPersistent(VNP); - processError(); - return returnValue; - } - - protected void processError() throws LibvirtException { - virConnect.processError(); + return processError(libvirt.virNetworkIsPersistent(VNP)); } /** @@ -237,8 +212,7 @@ public class Network { */ public void setAutostart(boolean autostart) throws LibvirtException { int autoValue = autostart ? 1 : 0; - libvirt.virNetworkSetAutostart(VNP, autoValue); - processError(); + processError(libvirt.virNetworkSetAutostart(VNP, autoValue)); } /** @@ -247,8 +221,7 @@ public class Network { * @throws LibvirtException */ public void undefine() throws LibvirtException { - libvirt.virNetworkUndefine(VNP); - processError(); + processError(libvirt.virNetworkUndefine(VNP)); } } -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:28PM +0100, Claudio Bley wrote:
Wrap any fallible libvirt function in a call to ErrorHandler.processError(..).
Also correct wrong javadoc comments stating that methods would return a value in case an error occurs.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Network.java | 61 +++++++++----------------------- 1 file changed, 17 insertions(+), 44 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:45:55 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:28PM +0100, Claudio Bley wrote:
Wrap any fallible libvirt function in a call to ErrorHandler.processError(..).
Also correct wrong javadoc comments stating that methods would return a value in case an error occurs.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Network.java | 61 +++++++++----------------------- 1 file changed, 17 insertions(+), 44 deletions(-)
ACK
Thanks, pushed.

Wrap any fallible libvirt function in a call to ErrorHandler.processError(..). Also correct wrong javadoc comments stating that methods would return a value in case an error occurs. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/NetworkFilter.java | 43 ++++++-------------------- 1 file changed, 10 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/libvirt/NetworkFilter.java b/src/main/java/org/libvirt/NetworkFilter.java index ba4d2ea..4f4bc6c 100644 --- a/src/main/java/org/libvirt/NetworkFilter.java +++ b/src/main/java/org/libvirt/NetworkFilter.java @@ -3,6 +3,7 @@ package org.libvirt; import org.libvirt.jna.Libvirt; import org.libvirt.jna.NetworkFilterPointer; import static org.libvirt.Library.libvirt; +import static org.libvirt.ErrorHandler.processError; import com.sun.jna.Native; @@ -32,13 +33,12 @@ public class NetworkFilter { * exist. * * @throws LibvirtException - * @return 0 on success, or -1 on error. + * @return <em>ignore</em> (always 0) */ public int free() throws LibvirtException { int success = 0; if (NFP != null) { - success = libvirt.virNWFilterFree(NFP); - processError(); + success = processError(libvirt.virNWFilterFree(NFP)); NFP = null; } @@ -52,9 +52,7 @@ public class NetworkFilter { * @throws LibvirtException */ public String getName() throws LibvirtException { - String returnValue = libvirt.virNWFilterGetName(NFP); - processError(); - return returnValue; + return processError(libvirt.virNWFilterGetName(NFP)); } /** @@ -66,13 +64,8 @@ public class NetworkFilter { */ public int[] getUUID() throws LibvirtException { byte[] bytes = new byte[Libvirt.VIR_UUID_BUFLEN]; - int success = libvirt.virNWFilterGetUUID(NFP, bytes); - processError(); - int[] returnValue = new int[0]; - if (success == 0) { - returnValue = Connect.convertUUIDBytes(bytes); - } - return returnValue; + processError(libvirt.virNWFilterGetUUID(NFP, bytes)); + return Connect.convertUUIDBytes(bytes); } /** @@ -84,13 +77,8 @@ public class NetworkFilter { */ public String getUUIDString() throws LibvirtException { byte[] bytes = new byte[Libvirt.VIR_UUID_STRING_BUFLEN]; - int success = libvirt.virNWFilterGetUUIDString(NFP, bytes); - processError(); - String returnValue = null; - if (success == 0) { - returnValue = Native.toString(bytes); - } - return returnValue; + processError(libvirt.virNWFilterGetUUIDString(NFP, bytes)); + return Native.toString(bytes); } /** @@ -102,17 +90,7 @@ public class NetworkFilter { * @return the XML document */ public String getXMLDesc() throws LibvirtException { - String returnValue = libvirt.virNWFilterGetXMLDesc(NFP, 0); - processError(); - return returnValue; - } - - /** - * Error handling logic to throw errors. Must be called after every libvirt - * call. - */ - protected void processError() throws LibvirtException { - virConnect.processError(); + return processError(libvirt.virNWFilterGetXMLDesc(NFP, 0)); } /** @@ -121,7 +99,6 @@ public class NetworkFilter { * @throws LibvirtException */ public void undefine() throws LibvirtException { - libvirt.virNWFilterUndefine(NFP); - processError(); + processError(libvirt.virNWFilterUndefine(NFP)); } } -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:29PM +0100, Claudio Bley wrote:
Wrap any fallible libvirt function in a call to ErrorHandler.processError(..).
Also correct wrong javadoc comments stating that methods would return a value in case an error occurs.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/NetworkFilter.java | 43 ++++++-------------------- 1 file changed, 10 insertions(+), 33 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:46:19 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:29PM +0100, Claudio Bley wrote:
Wrap any fallible libvirt function in a call to ErrorHandler.processError(..).
Also correct wrong javadoc comments stating that methods would return a value in case an error occurs.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/NetworkFilter.java | 43 ++++++-------------------- 1 file changed, 10 insertions(+), 33 deletions(-)
ACK
Thanks, pushed.

Wrap any fallible libvirt function in a call to ErrorHandler.processError(..). Also correct wrong javadoc comments stating that methods would return a value in case an error occurs. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Secret.java | 61 +++++++++------------------------ 1 file changed, 16 insertions(+), 45 deletions(-) diff --git a/src/main/java/org/libvirt/Secret.java b/src/main/java/org/libvirt/Secret.java index 4edb515..868fcc8 100644 --- a/src/main/java/org/libvirt/Secret.java +++ b/src/main/java/org/libvirt/Secret.java @@ -5,6 +5,7 @@ import org.libvirt.jna.SecretPointer; import org.libvirt.jna.SizeT; import org.libvirt.jna.SizeTByReference; import static org.libvirt.Library.libvirt; +import static org.libvirt.ErrorHandler.processError; import com.sun.jna.Native; import com.sun.jna.Pointer; @@ -39,13 +40,12 @@ public class Secret { * Release the secret handle. The underlying secret continues to exist. * * @throws LibvirtException - * @return 0 on success, or -1 on error. + * @return <em>ignore</em> (always 0) */ public int free() throws LibvirtException { int success = 0; if (VSP != null) { - success = libvirt.virSecretFree(VSP); - processError(); + success = processError(libvirt.virSecretFree(VSP)); VSP = null; } @@ -61,9 +61,7 @@ public class Secret { * @throws LibvirtException */ public String getUsageID() throws LibvirtException { - String returnValue = libvirt.virSecretGetUsageID(VSP); - processError(); - return returnValue; + return processError(libvirt.virSecretGetUsageID(VSP)); } /** @@ -75,13 +73,8 @@ public class Secret { */ public int[] getUUID() throws LibvirtException { byte[] bytes = new byte[Libvirt.VIR_UUID_BUFLEN]; - int success = libvirt.virSecretGetUUID(VSP, bytes); - processError(); - int[] returnValue = new int[0]; - if (success == 0) { - returnValue = Connect.convertUUIDBytes(bytes); - } - return returnValue; + processError(libvirt.virSecretGetUUID(VSP, bytes)); + return Connect.convertUUIDBytes(bytes); } /** @@ -93,13 +86,8 @@ public class Secret { */ public String getUUIDString() throws LibvirtException { byte[] bytes = new byte[Libvirt.VIR_UUID_STRING_BUFLEN]; - int success = libvirt.virSecretGetUUIDString(VSP, bytes); - processError(); - String returnValue = null; - if (success == 0) { - returnValue = Native.toString(bytes); - } - return returnValue; + processError(libvirt.virSecretGetUUIDString(VSP, bytes)); + return Native.toString(bytes); } /** @@ -121,8 +109,7 @@ public class Secret { */ public byte[] getByteValue() throws LibvirtException { SizeTByReference value_size = new SizeTByReference(); - Pointer value = libvirt.virSecretGetValue(VSP, value_size, 0); - processError(); + Pointer value = processError(libvirt.virSecretGetValue(VSP, value_size, 0)); ByteBuffer bb = value.getByteBuffer(0, value_size.getValue()); byte[] returnValue = new byte[bb.remaining()]; bb.get(returnValue); @@ -135,49 +122,33 @@ public class Secret { * @return the XML document */ public String getXMLDesc() throws LibvirtException { - String returnValue = libvirt.virSecretGetXMLDesc(VSP, 0); - processError(); - return returnValue; - } - - /** - * Error handling logic to throw errors. Must be called after every libvirt - * call. - */ - protected void processError() throws LibvirtException { - virConnect.processError(); + return processError(libvirt.virSecretGetXMLDesc(VSP, 0)); } /** * Sets the value of the secret * - * @return 0 on success, -1 on failure. + * @return <em>ignore</em> (always 0) */ public int setValue(String value) throws LibvirtException { - int returnValue = libvirt.virSecretSetValue(VSP, value, new SizeT(value.length()), 0); - processError(); - return returnValue; + return processError(libvirt.virSecretSetValue(VSP, value, new SizeT(value.length()), 0)); } /** * Sets the value of the secret * - * @return 0 on success, -1 on failure. + * @return <em>ignore</em> (always 0) */ public int setValue(byte[] value) throws LibvirtException { - int returnValue = libvirt.virSecretSetValue(VSP, value, new SizeT(value.length), 0); - processError(); - return returnValue; + return processError(libvirt.virSecretSetValue(VSP, value, new SizeT(value.length), 0)); } /** * Undefines, but does not free, the Secret. * - * @return 0 on success, -1 on failure. + * @return <em>ignore</em> (always 0) */ public int undefine() throws LibvirtException { - int returnValue = libvirt.virSecretUndefine(VSP); - processError(); - return returnValue; + return processError(libvirt.virSecretUndefine(VSP)); } } -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:30PM +0100, Claudio Bley wrote:
Wrap any fallible libvirt function in a call to ErrorHandler.processError(..).
Also correct wrong javadoc comments stating that methods would return a value in case an error occurs.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Secret.java | 61 +++++++++------------------------ 1 file changed, 16 insertions(+), 45 deletions(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:48:44 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:30PM +0100, Claudio Bley wrote:
Wrap any fallible libvirt function in a call to ErrorHandler.processError(..).
Also correct wrong javadoc comments stating that methods would return a value in case an error occurs.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Secret.java | 61 +++++++++------------------------ 1 file changed, 16 insertions(+), 45 deletions(-)
ACK
Thanks, pushed.

Wrap any fallible libvirt function in a call to ErrorHandler.processError(..). Adjust the doc comment for storageVolLookupByName to indicate that it might return null. Also correct wrong javadoc comments stating that methods would return a value in case an error occurs. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/StoragePool.java | 95 +++++++++------------------- 1 file changed, 30 insertions(+), 65 deletions(-) diff --git a/src/main/java/org/libvirt/StoragePool.java b/src/main/java/org/libvirt/StoragePool.java index 2d59f68..bb608e3 100644 --- a/src/main/java/org/libvirt/StoragePool.java +++ b/src/main/java/org/libvirt/StoragePool.java @@ -5,6 +5,7 @@ import org.libvirt.jna.StoragePoolPointer; import org.libvirt.jna.StorageVolPointer; import org.libvirt.jna.virStoragePoolInfo; import static org.libvirt.Library.libvirt; +import static org.libvirt.ErrorHandler.processError; import com.sun.jna.Native; import com.sun.jna.ptr.IntByReference; @@ -72,8 +73,7 @@ public class StoragePool { * future flags, use 0 for now */ public void build(int flags) throws LibvirtException { - libvirt.virStoragePoolBuild(VSPP, flags); - processError(); + processError(libvirt.virStoragePoolBuild(VSPP, flags)); } /** @@ -83,8 +83,7 @@ public class StoragePool { * future flags, use 0 for now */ public void create(int flags) throws LibvirtException { - libvirt.virStoragePoolCreate(VSPP, flags); - processError(); + processError(libvirt.virStoragePoolCreate(VSPP, flags)); } /** @@ -95,8 +94,7 @@ public class StoragePool { * flags for obliteration process */ public void delete(int flags) throws LibvirtException { - libvirt.virStoragePoolDelete(VSPP, flags); - processError(); + processError(libvirt.virStoragePoolDelete(VSPP, flags)); } /** @@ -106,8 +104,7 @@ public class StoragePool { * This does not free the associated virStoragePoolPtr object. */ public void destroy() throws LibvirtException { - libvirt.virStoragePoolDestroy(VSPP); - processError(); + processError(libvirt.virStoragePoolDestroy(VSPP)); } @Override @@ -120,13 +117,12 @@ public class StoragePool { * not change the state of the pool on the host. * * @throws LibvirtException - * @return number of references left (>= 0) for success, -1 for failure. + * @return number of references left (>= 0) */ public int free() throws LibvirtException { int success = 0; if (VSPP != null) { - success = libvirt.virStoragePoolFree(VSPP); - processError(); + success = processError(libvirt.virStoragePoolFree(VSPP)); VSPP = null; } return success; @@ -141,8 +137,7 @@ public class StoragePool { */ public boolean getAutostart() throws LibvirtException { IntByReference autoStart = new IntByReference(); - libvirt.virStoragePoolGetAutostart(VSPP, autoStart); - processError(); + processError(libvirt.virStoragePoolGetAutostart(VSPP, autoStart)); return autoStart.getValue() != 0 ? true : false; } @@ -164,8 +159,7 @@ public class StoragePool { */ public StoragePoolInfo getInfo() throws LibvirtException { virStoragePoolInfo vInfo = new virStoragePoolInfo(); - libvirt.virStoragePoolGetInfo(VSPP, vInfo); - processError(); + processError(libvirt.virStoragePoolGetInfo(VSPP, vInfo)); return new StoragePoolInfo(vInfo); } @@ -176,9 +170,7 @@ public class StoragePool { * @throws LibvirtException */ public String getName() throws LibvirtException { - String returnValue = libvirt.virStoragePoolGetName(VSPP); - processError(); - return returnValue; + return processError(libvirt.virStoragePoolGetName(VSPP)); } /** @@ -189,13 +181,8 @@ public class StoragePool { */ public int[] getUUID() throws LibvirtException { byte[] bytes = new byte[Libvirt.VIR_UUID_BUFLEN]; - int success = libvirt.virStoragePoolGetUUID(VSPP, bytes); - processError(); - int[] returnValue = new int[0]; - if (success == 0) { - returnValue = Connect.convertUUIDBytes(bytes); - } - return returnValue; + processError(libvirt.virStoragePoolGetUUID(VSPP, bytes)); + return Connect.convertUUIDBytes(bytes); } /** @@ -206,13 +193,8 @@ public class StoragePool { */ public String getUUIDString() throws LibvirtException { byte[] bytes = new byte[Libvirt.VIR_UUID_STRING_BUFLEN]; - int success = libvirt.virStoragePoolGetUUIDString(VSPP, bytes); - processError(); - String returnValue = null; - if (success == 0) { - returnValue = Native.toString(bytes); - } - return returnValue; + processError(libvirt.virStoragePoolGetUUIDString(VSPP, bytes)); + return Native.toString(bytes); } /** @@ -224,9 +206,7 @@ public class StoragePool { * @return a XML document -java @throws LibvirtException */ public String getXMLDesc(int flags) throws LibvirtException { - String returnValue = libvirt.virStoragePoolGetXMLDesc(VSPP, flags); - processError(); - return returnValue; + return processError(libvirt.virStoragePoolGetXMLDesc(VSPP, flags)); } /** @@ -235,13 +215,11 @@ public class StoragePool { * @see <a * href="http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolIsActive">Libvirt * Documentation</a> - * @return 1 if running, 0 if inactive, -1 on error + * @return 1 if running, 0 if inactive * @throws LibvirtException */ public int isActive() throws LibvirtException { - int returnValue = libvirt.virStoragePoolIsActive(VSPP); - processError(); - return returnValue; + return processError(libvirt.virStoragePoolIsActive(VSPP)); } /** @@ -251,13 +229,11 @@ public class StoragePool { * @see <a * href="http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolIsPersistent">Libvirt * Documentation</a> - * @return 1 if persistent, 0 if transient, -1 on error + * @return 1 if persistent, 0 if transient * @throws LibvirtException */ public int isPersistent() throws LibvirtException { - int returnValue = libvirt.virStoragePoolIsPersistent(VSPP); - processError(); - return returnValue; + return processError(libvirt.virStoragePoolIsPersistent(VSPP)); } /** @@ -270,8 +246,7 @@ public class StoragePool { public String[] listVolumes() throws LibvirtException { int num = numOfVolumes(); String[] returnValue = new String[num]; - libvirt.virStoragePoolListVolumes(VSPP, returnValue, num); - processError(); + processError(libvirt.virStoragePoolListVolumes(VSPP, returnValue, num)); return returnValue; } @@ -282,13 +257,7 @@ public class StoragePool { * @throws LibvirtException */ public int numOfVolumes() throws LibvirtException { - int returnValue = libvirt.virStoragePoolNumOfVolumes(VSPP); - processError(); - return returnValue; - } - - protected void processError() throws LibvirtException { - virConnect.processError(); + return processError(libvirt.virStoragePoolNumOfVolumes(VSPP)); } /** @@ -301,8 +270,7 @@ public class StoragePool { * @throws LibvirtException */ public void refresh(int flags) throws LibvirtException { - libvirt.virStoragePoolRefresh(VSPP, flags); - processError(); + processError(libvirt.virStoragePoolRefresh(VSPP, flags)); } /** @@ -328,8 +296,7 @@ public class StoragePool { * @throws LibvirtException */ public StorageVol storageVolCreateXML(String xmlDesc, int flags) throws LibvirtException { - StorageVolPointer sPtr = libvirt.virStorageVolCreateXML(VSPP, xmlDesc, flags); - processError(); + StorageVolPointer sPtr = processError(libvirt.virStorageVolCreateXML(VSPP, xmlDesc, flags)); return new StorageVol(virConnect, sPtr); } @@ -338,13 +305,12 @@ public class StoragePool { * as input. Information for the new volume (name, perms) are passed via a * typical volume XML description. * - * @return The storage volume, or {@code null} on error. + * @return The storage volume * @throws LibvirtException */ public StorageVol storageVolCreateXMLFrom(String xmlDesc, StorageVol cloneVolume, int flags) throws LibvirtException { - StorageVolPointer sPtr = libvirt.virStorageVolCreateXMLFrom(VSPP, xmlDesc, cloneVolume.VSVP, flags); - processError(); + StorageVolPointer sPtr = processError(libvirt.virStorageVolCreateXMLFrom(VSPP, xmlDesc, cloneVolume.VSVP, flags)); return new StorageVol(virConnect, sPtr); } @@ -354,13 +320,13 @@ public class StoragePool { * * @param name * name of storage volume - * @return The StorageVol object found + * @return a StorageVol object, or {@code null} if not found. * @throws LibvirtException */ public StorageVol storageVolLookupByName(String name) throws LibvirtException { - StorageVolPointer sPtr = libvirt.virStorageVolLookupByName(VSPP, name); - processError(); - return new StorageVol(virConnect, sPtr); + StorageVolPointer sPtr = processError(libvirt.virStorageVolLookupByName(VSPP, name)); + + return (sPtr == null) ? null : new StorageVol(virConnect, sPtr); } /** @@ -369,8 +335,7 @@ public class StoragePool { * @throws LibvirtException */ public void undefine() throws LibvirtException { - libvirt.virStoragePoolUndefine(VSPP); - processError(); + processError(libvirt.virStoragePoolUndefine(VSPP)); } } -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:31PM +0100, Claudio Bley wrote:
Wrap any fallible libvirt function in a call to ErrorHandler.processError(..).
Adjust the doc comment for storageVolLookupByName to indicate that it might return null.
Also correct wrong javadoc comments stating that methods would return a value in case an error occurs.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/StoragePool.java | 95 +++++++++------------------- 1 file changed, 30 insertions(+), 65 deletions(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:49:15 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:31PM +0100, Claudio Bley wrote:
Wrap any fallible libvirt function in a call to ErrorHandler.processError(..).
Adjust the doc comment for storageVolLookupByName to indicate that it might return null.
Also correct wrong javadoc comments stating that methods would return a value in case an error occurs.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/StoragePool.java | 95 +++++++++------------------- 1 file changed, 30 insertions(+), 65 deletions(-)
ACK
Thanks, pushed.

Wrap any fallible libvirt function in a call to ErrorHandler.processError(..). Also correct wrong javadoc comments stating that methods would return a value in case an error occurs. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/StorageVol.java | 56 +++++++++-------------------- 1 file changed, 16 insertions(+), 40 deletions(-) diff --git a/src/main/java/org/libvirt/StorageVol.java b/src/main/java/org/libvirt/StorageVol.java index 561cb4d..1573070 100644 --- a/src/main/java/org/libvirt/StorageVol.java +++ b/src/main/java/org/libvirt/StorageVol.java @@ -4,6 +4,7 @@ import org.libvirt.jna.StoragePoolPointer; import org.libvirt.jna.StorageVolPointer; import org.libvirt.jna.virStorageVolInfo; import static org.libvirt.Library.libvirt; +import static org.libvirt.ErrorHandler.processError; /** * An acutal storage bucket. @@ -82,8 +83,7 @@ public class StorageVol { * @throws LibvirtException */ public void delete(int flags) throws LibvirtException { - libvirt.virStorageVolDelete(VSVP, flags); - processError(); + processError(libvirt.virStorageVolDelete(VSVP, flags)); } @Override @@ -96,13 +96,12 @@ public class StorageVol { * to exist * * @throws LibvirtException - * @return number of references left (>= 0) for success, -1 for failure. + * @return number of references left (>= 0) */ public int free() throws LibvirtException { int success = 0; if (VSVP != null) { - libvirt.virStorageVolFree(VSVP); - processError(); + success = processError(libvirt.virStorageVolFree(VSVP)); VSVP = null; } return success; @@ -127,8 +126,7 @@ public class StorageVol { */ public StorageVolInfo getInfo() throws LibvirtException { virStorageVolInfo vInfo = new virStorageVolInfo(); - libvirt.virStorageVolGetInfo(VSVP, vInfo); - processError(); + processError(libvirt.virStorageVolGetInfo(VSVP, vInfo)); return new StorageVolInfo(vInfo); } @@ -140,9 +138,7 @@ public class StorageVol { * @throws LibvirtException */ public String getKey() throws LibvirtException { - String returnValue = libvirt.virStorageVolGetKey(VSVP); - processError(); - return returnValue; + return processError(libvirt.virStorageVolGetKey(VSVP)); } /** @@ -152,9 +148,7 @@ public class StorageVol { * @throws LibvirtException */ public String getName() throws LibvirtException { - String returnValue = libvirt.virStorageVolGetName(VSVP); - processError(); - return returnValue; + return processError(libvirt.virStorageVolGetName(VSVP)); } /** @@ -167,9 +161,7 @@ public class StorageVol { * @throws LibvirtException */ public String getPath() throws LibvirtException { - String returnValue = libvirt.virStorageVolGetPath(VSVP); - processError(); - return returnValue; + return processError(libvirt.virStorageVolGetPath(VSVP)); } /** @@ -181,43 +173,29 @@ public class StorageVol { * @throws LibvirtException */ public String getXMLDesc(int flags) throws LibvirtException { - String returnValue = libvirt.virStorageVolGetXMLDesc(VSVP, flags); - processError(); - return returnValue; - } - - /** - * Error handling logic which should be called after every libvirt call - * - * @throws LibvirtException - */ - protected void processError() throws LibvirtException { - virConnect.processError(); + return processError(libvirt.virStorageVolGetXMLDesc(VSVP, flags)); } /** * Fetch a storage pool which contains this volume * - * @return StoragePool object, + * @return StoragePool object, or {@code null} if not found. * @throws LibvirtException */ public StoragePool storagePoolLookupByVolume() throws LibvirtException { - StoragePoolPointer ptr = libvirt.virStoragePoolLookupByVolume(VSVP); - processError(); - return new StoragePool(virConnect, ptr); + StoragePoolPointer ptr = processError(libvirt.virStoragePoolLookupByVolume(VSVP)); + return (ptr == null) ? null : new StoragePool(virConnect, ptr); } /** * Ensure data previously on a volume is not accessible to future reads * * @see <a href="http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolWipe">Libvirt Documentation</a> - * @return 0 on success, or -1 on error + * @return <em>ignore</em> (always 0) * @throws LibvirtException */ public int wipe() throws LibvirtException { - int returnValue = libvirt.virStorageVolWipe(VSVP, 0); - processError(); - return returnValue; + return processError(libvirt.virStorageVolWipe(VSVP, 0)); } /** @@ -228,12 +206,10 @@ public class StorageVol { * new capacity for volume * @param flags * flags for resizing, see libvirt API for exact flags - * @return 0 on success, or -1 on error + * @return <em>ignore</em> (always 0) * @throws LibvirtException */ public int resize(long capacity, int flags) throws LibvirtException { - int returnValue = libvirt.virStorageVolResize(VSVP, capacity, flags); - processError(); - return returnValue; + return processError(libvirt.virStorageVolResize(VSVP, capacity, flags)); } } -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:32PM +0100, Claudio Bley wrote:
Wrap any fallible libvirt function in a call to ErrorHandler.processError(..).
Also correct wrong javadoc comments stating that methods would return a value in case an error occurs.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/StorageVol.java | 56 +++++++++-------------------- 1 file changed, 16 insertions(+), 40 deletions(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:49:33 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:32PM +0100, Claudio Bley wrote:
Wrap any fallible libvirt function in a call to ErrorHandler.processError(..).
Also correct wrong javadoc comments stating that methods would return a value in case an error occurs.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/StorageVol.java | 56 +++++++++-------------------- 1 file changed, 16 insertions(+), 40 deletions(-)
ACK
Thanks, pushed.

Wrap any fallible libvirt function in a call to ErrorHandler.processError(..). Also correct wrong javadoc comments stating that methods would return a value in case an error occurs. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Stream.java | 64 +++++++++++---------------------- 1 file changed, 20 insertions(+), 44 deletions(-) diff --git a/src/main/java/org/libvirt/Stream.java b/src/main/java/org/libvirt/Stream.java index 6d488e3..c36ed70 100644 --- a/src/main/java/org/libvirt/Stream.java +++ b/src/main/java/org/libvirt/Stream.java @@ -4,6 +4,7 @@ import org.libvirt.jna.Libvirt; import org.libvirt.jna.SizeT; import org.libvirt.jna.StreamPointer; import static org.libvirt.Library.libvirt; +import static org.libvirt.ErrorHandler.processError; public class Stream { @@ -27,11 +28,11 @@ public class Stream { /** * Request that the in progress data transfer be cancelled abnormally before * the end of the stream has been reached + * + * @return <em>ignore</em> (always 0) */ public int abort() throws LibvirtException { - int returnValue = libvirt.virStreamAbort(VSP); - processError(); - return returnValue; + return processError(libvirt.virStreamAbort(VSP)); } /** @@ -45,13 +46,11 @@ public class Stream { * the events to monitor * @param cb * the callback method - * @return 0 for success, -1 for failure + * @return <em>ignore</em> (always 0) * @throws LibvirtException */ public int addCallback(int events, Libvirt.VirStreamEventCallback cb) throws LibvirtException { - int returnValue = libvirt.virStreamEventAddCallback(VSP, events, cb, null, null); - processError(); - return returnValue; + return processError(libvirt.virStreamEventAddCallback(VSP, events, cb, null, null)); } @Override @@ -63,27 +62,24 @@ public class Stream { * Indicate that there is no further data is to be transmitted on the * stream. * - * @return 0 if success, -1 if failure + * @return <em>ignore</em> (always 0) * @throws LibvirtException */ public int finish() throws LibvirtException { - int returnValue = libvirt.virStreamFinish(VSP); - processError(); - return returnValue; + return processError(libvirt.virStreamFinish(VSP)); } /** * Decrement the reference count on a stream, releasing the stream object if * the reference count has hit zero. * + * @return <em>ignore</em> (always 0) * @throws LibvirtException - * @return 0 on success, or -1 on error. */ public int free() throws LibvirtException { int success = 0; if (VSP != null) { - success = libvirt.virStreamFree(VSP); - processError(); + processError(libvirt.virStreamFree(VSP)); VSP = null; } @@ -91,14 +87,6 @@ public class Stream { } /** - * Error handling logic to throw errors. Must be called after every libvirt - * call. - */ - protected void processError() throws LibvirtException { - virConnect.processError(); - } - - /** * Receives data from the stream into the buffer provided. * * @param data @@ -107,9 +95,7 @@ public class Stream { * @throws LibvirtException */ public int receive(byte[] data) throws LibvirtException { - int returnValue = libvirt.virStreamRecv(VSP, data, new SizeT(data.length)); - processError(); - return returnValue; + return processError(libvirt.virStreamRecv(VSP, data, new SizeT(data.length))); } /** @@ -118,26 +104,22 @@ public class Stream { * @see <a href="http://www.libvirt.org/html/libvirt-libvirt.html#virStreamRecvAll">virStreamRecvAll</a> * @param handler * the callback handler - * @return 0 if successfule, -1 otherwise + * @return <em>ignore</em> (always 0) * @throws LibvirtException */ public int receiveAll(Libvirt.VirStreamSinkFunc handler) throws LibvirtException { - int returnValue = libvirt.virStreamRecvAll(VSP, handler, null); - processError(); - return returnValue; + return processError(libvirt.virStreamRecvAll(VSP, handler, null)); } /** * Remove an event callback from the stream * * @see <a href="http://www.libvirt.org/html/libvirt-libvirt.html#virStreamEventRemoveCallback">Libvirt Docs</a> - * @return 0 for success, -1 for failure + * @return <em>ignore</em> (always 0) * @throws LibvirtException */ public int removeCallback() throws LibvirtException { - int returnValue = libvirt.virStreamEventRemoveCallback(VSP); - processError(); - return returnValue; + return processError(libvirt.virStreamEventRemoveCallback(VSP)); } /** @@ -150,9 +132,7 @@ public class Stream { * @throws LibvirtException */ public int send(String data) throws LibvirtException { - int returnValue = libvirt.virStreamSend(VSP, data, new SizeT(data.length())); - processError(); - return returnValue; + return processError(libvirt.virStreamSend(VSP, data, new SizeT(data.length()))); } /** @@ -163,13 +143,11 @@ public class Stream { * Documentation</a> * @param handler * the callback handler - * @return 0 if successfule, -1 otherwise + * @return <em>ignore</em> (always 0) * @throws LibvirtException */ public int sendAll(Libvirt.VirStreamSourceFunc handler) throws LibvirtException { - int returnValue = libvirt.virStreamSendAll(VSP, handler, null); - processError(); - return returnValue; + return processError(libvirt.virStreamSendAll(VSP, handler, null)); } /** @@ -178,12 +156,10 @@ public class Stream { * @see <a href="http://www.libvirt.org/html/libvirt-libvirt.html#virStreamEventUpdateCallback">Libvirt Docs</a> * @param events * the events to monitor - * @return 0 for success, -1 for failure + * @return <em>ignore</em> (always 0) * @throws LibvirtException */ public int updateCallback(int events) throws LibvirtException { - int returnValue = libvirt.virStreamEventUpdateCallback(VSP, events); - processError(); - return returnValue; + return processError(libvirt.virStreamEventUpdateCallback(VSP, events)); } } -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:33PM +0100, Claudio Bley wrote:
Wrap any fallible libvirt function in a call to ErrorHandler.processError(..).
Also correct wrong javadoc comments stating that methods would return a value in case an error occurs.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Stream.java | 64 +++++++++++---------------------- 1 file changed, 20 insertions(+), 44 deletions(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:49:52 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:33PM +0100, Claudio Bley wrote:
Wrap any fallible libvirt function in a call to ErrorHandler.processError(..).
Also correct wrong javadoc comments stating that methods would return a value in case an error occurs.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Stream.java | 64 +++++++++++---------------------- 1 file changed, 20 insertions(+), 44 deletions(-)
ACK
Thanks, pushed.

Wrap any fallible libvirt function in a call to ErrorHandler.processError(..) and remove calls to the deprecated ErrorHandler.processError(Libvirt) method. Also correct wrong javadoc comments stating that methods would return a value in case an error occurs. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 69 +++++--------------------------- 1 file changed, 11 insertions(+), 58 deletions(-) diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index b3e29be..fedc60e 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -15,7 +15,10 @@ import org.libvirt.jna.StorageVolPointer; import org.libvirt.jna.StreamPointer; import org.libvirt.jna.virConnectAuth; import org.libvirt.jna.virNodeInfo; + import static org.libvirt.Library.libvirt; +import static org.libvirt.ErrorHandler.processError; +import static org.libvirt.ErrorHandler.processErrorIfZero; import com.sun.jna.Memory; import com.sun.jna.NativeLong; @@ -79,7 +82,6 @@ public class Connect { */ public static void setErrorCallback(Libvirt.VirErrorCallback callback) throws LibvirtException { Libvirt.INSTANCE.virSetErrorFunc(null, callback); - ErrorHandler.processError(Libvirt.INSTANCE); } /** @@ -119,7 +121,6 @@ public class Connect { VCP = libvirt.virConnectOpen(uri); // Check for an error processError(VCP); - ErrorHandler.processError(Libvirt.INSTANCE); } /** @@ -140,7 +141,6 @@ public class Connect { } // Check for an error processError(VCP); - ErrorHandler.processError(Libvirt.INSTANCE); } /** @@ -173,7 +173,6 @@ public class Connect { VCP = libvirt.virConnectOpenAuth(uri, vAuth, flags); // Check for an error processError(VCP); - ErrorHandler.processError(Libvirt.INSTANCE); } /** @@ -220,8 +219,7 @@ public class Connect { * @throws LibvirtException */ public CPUCompareResult compareCPU(String xmlDesc) throws LibvirtException { - int rawResult = libvirt.virConnectCompareCPU(VCP, xmlDesc, 0); - processError(); + int rawResult = processError(libvirt.virConnectCompareCPU(VCP, xmlDesc, 0)); return CPUCompareResult.get(rawResult); } @@ -308,13 +306,11 @@ public class Connect { * Documentation</a> * @param callbackID * the callback to deregister - * @return 0 on success, -1 on failure + * @return <em>ignore</em> (always 0) * @throws LibvirtException */ public int domainEventDeregisterAny(int callbackID) throws LibvirtException { - int returnValue = libvirt.virConnectDomainEventDeregisterAny(VCP, callbackID); - processError(); - return returnValue; + return processError(libvirt.virConnectDomainEventDeregisterAny(VCP, callbackID)); } /** @@ -496,10 +492,7 @@ public class Connect { * Returns the free memory for the connection */ public long getFreeMemory() throws LibvirtException { - long returnValue = 0; - returnValue = libvirt.virNodeGetFreeMemory(VCP); - if (returnValue == 0) processError(); - return returnValue; + return processErrorIfZero(libvirt.virNodeGetFreeMemory(VCP)); } /** @@ -639,13 +632,11 @@ public class Connect { * @see <a * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectIsEncrypted">Libvirt * Documentation</a> - * @return 1 if encrypted, 0 if not encrypted, -1 on error + * @return 1 if encrypted, 0 if not encrypted * @throws LibvirtException */ public int isEncrypted() throws LibvirtException { - int returnValue = libvirt.virConnectIsEncrypted(VCP); - processError(); - return returnValue; + return processError(libvirt.virConnectIsEncrypted(VCP)); } /** @@ -654,13 +645,11 @@ public class Connect { * @see <a * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectIsSecure">Libvirt * Documentation</a> - * @return 1 if secure, 0 if not secure, -1 on error + * @return 1 if secure, 0 if not secure * @throws LibvirtException */ public int isSecure() throws LibvirtException { - int returnValue = libvirt.virConnectIsSecure(VCP); - processError(); - return returnValue; + return processError(libvirt.virConnectIsSecure(VCP)); } /** @@ -1141,41 +1130,6 @@ public class Connect { } /** - * call the error handling logic. Should be called after every libvirt call - * - * @throws LibvirtException - */ - protected void processError() throws LibvirtException { - ErrorHandler.processError(libvirt); - } - - /** - * Calls {@link #processError()} when the given libvirt return code - * indicates an error. - * - * @param ret libvirt return code, indicating error if negative. - * @return {@code ret} - * @throws LibvirtException - */ - protected final int processError(int ret) throws LibvirtException { - if (ret < 0) processError(); - return ret; - } - - /** - * Calls {@link #processError()} if {@code arg} is null. - * - * @param arg An arbitrary object returned by libvirt. - * @return {@code arg} - * @throws LibvirtException - */ - protected final <T> T processError(T arg) throws LibvirtException { - if (arg == null) processError(); - return arg; - } - - - /** * Restores a domain saved to disk by Domain.save(). * * @param from @@ -1246,7 +1200,6 @@ public class Connect { public void setConnectionErrorCallback(Libvirt.VirErrorCallback callback) throws LibvirtException { libvirt.virConnSetErrorFunc(VCP, null, callback); - processError(); } /** -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:34PM +0100, Claudio Bley wrote:
Wrap any fallible libvirt function in a call to ErrorHandler.processError(..) and remove calls to the deprecated ErrorHandler.processError(Libvirt) method.
Also correct wrong javadoc comments stating that methods would return a value in case an error occurs.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 69 +++++--------------------------- 1 file changed, 11 insertions(+), 58 deletions(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:50:22 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:34PM +0100, Claudio Bley wrote:
Wrap any fallible libvirt function in a call to ErrorHandler.processError(..) and remove calls to the deprecated ErrorHandler.processError(Libvirt) method.
Also correct wrong javadoc comments stating that methods would return a value in case an error occurs.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 69 +++++--------------------------- 1 file changed, 11 insertions(+), 58 deletions(-)
ACK
Thanks, pushed.

Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Library.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/libvirt/Library.java b/src/main/java/org/libvirt/Library.java index 33d3042..95c13cb 100644 --- a/src/main/java/org/libvirt/Library.java +++ b/src/main/java/org/libvirt/Library.java @@ -1,6 +1,7 @@ package org.libvirt; import org.libvirt.jna.Libvirt; +import static org.libvirt.ErrorHandler.processError; import com.sun.jna.Native; import com.sun.jna.Pointer; @@ -24,10 +25,9 @@ final class Library { // Load the native part static { - Libvirt.INSTANCE.virInitialize(); libvirt = Libvirt.INSTANCE; try { - ErrorHandler.processError(Libvirt.INSTANCE); + processError(libvirt.virInitialize()); } catch (Exception e) { e.printStackTrace(); } -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:35PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Library.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:50:57 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:35PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Library.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
ACK
Thanks, pushed.

It was deprecated and is no longer used. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/ErrorHandler.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/main/java/org/libvirt/ErrorHandler.java b/src/main/java/org/libvirt/ErrorHandler.java index 01e25d6..c2e7337 100644 --- a/src/main/java/org/libvirt/ErrorHandler.java +++ b/src/main/java/org/libvirt/ErrorHandler.java @@ -16,18 +16,6 @@ import com.sun.jna.PointerType; */ public class ErrorHandler { - /** - * Look for the latest error from libvirt not tied to a connection - * - * @param libvirt - * the active connection - * @throws LibvirtException - */ - @Deprecated - static void processError(Libvirt libvirt) throws LibvirtException { - processError(); - } - private static final void processError() throws LibvirtException { virError vError = libvirt.virGetLastError(); if (vError != null) { -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:36PM +0100, Claudio Bley wrote:
It was deprecated and is no longer used.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/ErrorHandler.java | 12 ------------ 1 file changed, 12 deletions(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:51:17 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:36PM +0100, Claudio Bley wrote:
It was deprecated and is no longer used.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/ErrorHandler.java | 12 ------------ 1 file changed, 12 deletions(-)
ACK
Thanks, pushed.

Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 35 +++++++++++++++++ src/main/java/org/libvirt/Domain.java | 48 ++++++++++++++++++++++- src/test/java/org/libvirt/TestJavaBindings.java | 4 ++ 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index fedc60e..d92976e 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -89,6 +89,41 @@ public class Connect { */ protected ConnectionPointer VCP; + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((VCP == null) ? 0 : VCP.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof Connect)) + return false; + Connect other = (Connect) obj; + if (VCP == null) + return (other.VCP == null); + else if (VCP.equals(other.VCP)) + return true; + + try { + return getURI().equals(other.getURI()); + } catch (LibvirtException e) { + throw new RuntimeException("libvirt error testing connect equality", e); + } + } + /** * Protected constructor to return a Connection with ConnectionPointer */ diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 047ac33..ab6f9f0 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -21,6 +21,8 @@ import com.sun.jna.NativeLong; import com.sun.jna.Pointer; import com.sun.jna.ptr.IntByReference; +import java.util.Arrays; + /** * A virtual machine defined within libvirt. */ @@ -135,10 +137,52 @@ public class Domain { */ DomainPointer VDP; + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((VDP == null) ? 0 : VDP.hashCode()); + result = prime * result + + ((virConnect == null) ? 0 : virConnect.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof Domain)) + return false; + Domain other = (Domain) obj; + + // return false when this domain belongs to + // a different hypervisor than the other + if (!this.virConnect.equals(other.virConnect)) + return false; + + if (VDP == null) return (other.VDP == null); + + if (VDP.equals(other.VDP)) return true; + + try { + return Arrays.equals(getUUID(), other.getUUID()); + } catch (LibvirtException e) { + throw new RuntimeException("libvirt error testing domain equality", e); + } + } + /** * The Connect Object that represents the Hypervisor of this Domain */ - private Connect virConnect; + private final Connect virConnect; /** * Constructs a Domain object from a known native DomainPointer, and a @@ -150,6 +194,8 @@ public class Domain { * the native virDomainPtr */ Domain(Connect virConnect, DomainPointer VDP) { + assert virConnect != null; + this.virConnect = virConnect; this.VDP = VDP; } diff --git a/src/test/java/org/libvirt/TestJavaBindings.java b/src/test/java/org/libvirt/TestJavaBindings.java index 0123e6a..91f8df4 100644 --- a/src/test/java/org/libvirt/TestJavaBindings.java +++ b/src/test/java/org/libvirt/TestJavaBindings.java @@ -132,6 +132,7 @@ public final class TestJavaBindings extends TestCase { + " <uuid>004b96e1-2d78-c30f-5aa5-f03c87d21e67</uuid>" + " <memory>8388608</memory>" + " <vcpu>2</vcpu>" + " <os><type arch='i686'>hvm</type></os>" + " <on_reboot>restart</on_reboot>" + " <on_poweroff>destroy</on_poweroff>" + " <on_crash>restart</on_crash>" + "</domain>", 0); + UUID dom2UUID = UUID.fromString("004b96e1-2d78-c30f-5aa5-f03c87d21e67"); assertEquals("Number of domains", 2, conn.numOfDomains()); assertEquals("Number of listed domains", 2, conn.listDomains().length); @@ -145,6 +146,9 @@ public final class TestJavaBindings extends TestCase { this.validateDomainData(conn.domainLookupByUUID(UUIDArray)); this.validateDomainData(conn.domainLookupByUUIDString("004b96e1-2d78-c30f-5aa5-f03c87d21e67")); this.validateDomainData(conn.domainLookupByUUID(UUID.fromString("004b96e1-2d78-c30f-5aa5-f03c87d21e67"))); + assertEquals("Domain is not equal to Domain retrieved by lookup", + dom2, + conn.domainLookupByUUID(dom2.getUUID())); } private void validateDomainData(Domain dom) throws Exception { -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:37PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 35 +++++++++++++++++ src/main/java/org/libvirt/Domain.java | 48 ++++++++++++++++++++++- src/test/java/org/libvirt/TestJavaBindings.java | 4 ++ 3 files changed, 86 insertions(+), 1 deletion(-)
NACK
+ /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((VCP == null) ? 0 : VCP.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof Connect)) + return false; + Connect other = (Connect) obj; + if (VCP == null) + return (other.VCP == null); + else if (VCP.equals(other.VCP)) + return true; + + try { + return getURI().equals(other.getURI()); + } catch (LibvirtException e) { + throw new RuntimeException("libvirt error testing connect equality", e); + } + }
This causes a violation of the hashCode API contract. Per the java api docs for java.lang.Object "If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result." If the equals method falls through to checking equality of the URIs and returns true, the hashCode method is going to return different results since they have different VCP pointers. Either you have to remove the comparison of getURI in the equals method, or make the hashCode method use the URI to build up the hash code.
diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 047ac33..ab6f9f0 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -21,6 +21,8 @@ import com.sun.jna.NativeLong; import com.sun.jna.Pointer; import com.sun.jna.ptr.IntByReference;
+import java.util.Arrays; + /** * A virtual machine defined within libvirt. */ @@ -135,10 +137,52 @@ public class Domain { */ DomainPointer VDP;
+ /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((VDP == null) ? 0 : VDP.hashCode()); + result = prime * result + + ((virConnect == null) ? 0 : virConnect.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof Domain)) + return false; + Domain other = (Domain) obj; + + // return false when this domain belongs to + // a different hypervisor than the other + if (!this.virConnect.equals(other.virConnect)) + return false; + + if (VDP == null) return (other.VDP == null); + + if (VDP.equals(other.VDP)) return true; + + try { + return Arrays.equals(getUUID(), other.getUUID()); + } catch (LibvirtException e) { + throw new RuntimeException("libvirt error testing domain equality", e); + } + }
Again, violation of hashCode API contract due to use of UUID comparison Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:56:36 +0000, Daniel P. Berrange wrote:
This causes a violation of the hashCode API contract. Per the java api docs for java.lang.Object
Of course, right you're. I've change the implementation of the hashCode methods accordingly in order to take the URI and UUID into account. Please have a look at the following patch. As a future improvement, I think it would be feasible to cache the URI and UUID per Connect and Domain instance, respectively. Claudio Bley (1): Implement equals and hashCode methods for Connect and Domain src/main/java/org/libvirt/Connect.java | 39 +++++++++++++++++ src/main/java/org/libvirt/Domain.java | 52 ++++++++++++++++++++++- src/test/java/org/libvirt/TestJavaBindings.java | 4 ++ 3 files changed, 94 insertions(+), 1 deletion(-) -- 1.7.9.5

Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 39 +++++++++++++++++ src/main/java/org/libvirt/Domain.java | 52 ++++++++++++++++++++++- src/test/java/org/libvirt/TestJavaBindings.java | 4 ++ 3 files changed, 94 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index fedc60e..7dca98a 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -89,6 +89,45 @@ public class Connect { */ protected ConnectionPointer VCP; + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + try { + result = prime * result + ((VCP == null) ? 0 : this.getURI().hashCode()); + } catch (LibvirtException e) { + throw new RuntimeException("libvirt error testing connection equality", e); + } + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof Connect)) + return false; + Connect other = (Connect) obj; + if (VCP == null) + return (other.VCP == null); + else if (VCP.equals(other.VCP)) + return true; + + try { + return getURI().equals(other.getURI()); + } catch (LibvirtException e) { + throw new RuntimeException("libvirt error testing connect equality", e); + } + } + /** * Protected constructor to return a Connection with ConnectionPointer */ diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 047ac33..18bbc48 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -21,6 +21,8 @@ import com.sun.jna.NativeLong; import com.sun.jna.Pointer; import com.sun.jna.ptr.IntByReference; +import java.util.Arrays; + /** * A virtual machine defined within libvirt. */ @@ -135,10 +137,56 @@ public class Domain { */ DomainPointer VDP; + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((virConnect == null) ? 0 : virConnect.hashCode()); + try { + result = prime * result + ((VDP == null) ? 0 : Arrays.hashCode(this.getUUID())); + } catch (LibvirtException e) { + throw new RuntimeException("libvirt error testing domain equality", e); + } + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof Domain)) + return false; + Domain other = (Domain) obj; + + // return false when this domain belongs to + // a different hypervisor than the other + if (!this.virConnect.equals(other.virConnect)) + return false; + + if (VDP == null) return (other.VDP == null); + + if (VDP.equals(other.VDP)) return true; + + try { + return Arrays.equals(getUUID(), other.getUUID()); + } catch (LibvirtException e) { + throw new RuntimeException("libvirt error testing domain equality", e); + } + } + /** * The Connect Object that represents the Hypervisor of this Domain */ - private Connect virConnect; + private final Connect virConnect; /** * Constructs a Domain object from a known native DomainPointer, and a @@ -150,6 +198,8 @@ public class Domain { * the native virDomainPtr */ Domain(Connect virConnect, DomainPointer VDP) { + assert virConnect != null; + this.virConnect = virConnect; this.VDP = VDP; } diff --git a/src/test/java/org/libvirt/TestJavaBindings.java b/src/test/java/org/libvirt/TestJavaBindings.java index 0123e6a..91f8df4 100644 --- a/src/test/java/org/libvirt/TestJavaBindings.java +++ b/src/test/java/org/libvirt/TestJavaBindings.java @@ -132,6 +132,7 @@ public final class TestJavaBindings extends TestCase { + " <uuid>004b96e1-2d78-c30f-5aa5-f03c87d21e67</uuid>" + " <memory>8388608</memory>" + " <vcpu>2</vcpu>" + " <os><type arch='i686'>hvm</type></os>" + " <on_reboot>restart</on_reboot>" + " <on_poweroff>destroy</on_poweroff>" + " <on_crash>restart</on_crash>" + "</domain>", 0); + UUID dom2UUID = UUID.fromString("004b96e1-2d78-c30f-5aa5-f03c87d21e67"); assertEquals("Number of domains", 2, conn.numOfDomains()); assertEquals("Number of listed domains", 2, conn.listDomains().length); @@ -145,6 +146,9 @@ public final class TestJavaBindings extends TestCase { this.validateDomainData(conn.domainLookupByUUID(UUIDArray)); this.validateDomainData(conn.domainLookupByUUIDString("004b96e1-2d78-c30f-5aa5-f03c87d21e67")); this.validateDomainData(conn.domainLookupByUUID(UUID.fromString("004b96e1-2d78-c30f-5aa5-f03c87d21e67"))); + assertEquals("Domain is not equal to Domain retrieved by lookup", + dom2, + conn.domainLookupByUUID(dom2.getUUID())); } private void validateDomainData(Domain dom) throws Exception { -- 1.7.9.5

At Tue, 11 Mar 2014 11:18:57 +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 39 +++++++++++++++++ src/main/java/org/libvirt/Domain.java | 52 ++++++++++++++++++++++- src/test/java/org/libvirt/TestJavaBindings.java | 4 ++ 3 files changed, 94 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index fedc60e..7dca98a 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -89,6 +89,45 @@ public class Connect { */ protected ConnectionPointer VCP;
+ /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + try { + result = prime * result + ((VCP == null) ? 0 : this.getURI().hashCode()); + } catch (LibvirtException e) { + throw new RuntimeException("libvirt error testing connection equality", e); + }
Darn copy'n'paste; just pretend it says "libvirt error generating hash code", OK?! Likewise for the Domain class. Claudio

The getSchedulerType method returns a String (the name of the scheduler), not a String array containing a single element. It's OK to just pass null for the second argument to virDomainGetSchedulerType. Ensure to free the returned string. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 43 +++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index ab6f9f0..6db8745 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -528,18 +528,25 @@ public class Domain { */ public SchedParameter[] getSchedulerParameters() throws LibvirtException { IntByReference nParams = new IntByReference(); - SchedParameter[] returnValue = new SchedParameter[0]; - Pointer pScheduler = processError(libvirt.virDomainGetSchedulerType(VDP, nParams)); - String scheduler = Library.getString(pScheduler); - Library.free(pScheduler); - virSchedParameter[] nativeParams = new virSchedParameter[nParams.getValue()]; - returnValue = new SchedParameter[nParams.getValue()]; - processError(libvirt.virDomainGetSchedulerParameters(VDP, nativeParams, nParams)); - for (int x = 0; x < nParams.getValue(); x++) { - returnValue[x] = SchedParameter.create(nativeParams[x]); - } + Library.free(processError(libvirt.virDomainGetSchedulerType(VDP, nParams))); - return returnValue; + int n = nParams.getValue(); + + if (n > 0) { + virSchedParameter[] nativeParams = new virSchedParameter[n]; + + processError(libvirt.virDomainGetSchedulerParameters(VDP, nativeParams, nParams)); + n = nParams.getValue(); + + SchedParameter[] returnValue = new SchedParameter[n]; + + for (int x = 0; x < n; x++) { + returnValue[x] = SchedParameter.create(nativeParams[x]); + } + return returnValue; + } else { + return new SchedParameter[] {}; + } } // getSchedulerType @@ -552,13 +559,13 @@ public class Domain { * @return the type of the scheduler * @throws LibvirtException */ - public String[] getSchedulerType() throws LibvirtException { - IntByReference nParams = new IntByReference(); - Pointer pScheduler = processError(libvirt.virDomainGetSchedulerType(VDP, nParams)); - String[] array = new String[1]; - array[0] = Library.getString(pScheduler); - Library.free(pScheduler); - return array; + public String getSchedulerType() throws LibvirtException { + Pointer pScheduler = processError(libvirt.virDomainGetSchedulerType(VDP, null)); + try { + return Library.getString(pScheduler); + } finally { + Library.free(pScheduler); + } } /** -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:38PM +0100, Claudio Bley wrote:
The getSchedulerType method returns a String (the name of the scheduler), not a String array containing a single element.
It's OK to just pass null for the second argument to virDomainGetSchedulerType.
Ensure to free the returned string.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 43 +++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 18 deletions(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:57:10 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:38PM +0100, Claudio Bley wrote:
The getSchedulerType method returns a String (the name of the scheduler), not a String array containing a single element.
It's OK to just pass null for the second argument to virDomainGetSchedulerType.
Ensure to free the returned string.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 43 +++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 18 deletions(-)
ACK
Thanks, pushed.

We need to free the char* entries of the result array returned ourselves. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 14 +++++++------- src/main/java/org/libvirt/jna/Libvirt.java | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 6db8745..39cb7c5 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -1186,15 +1186,15 @@ public class Domain { * @throws LibvirtException */ public String[] snapshotListNames(int flags) throws LibvirtException { - String[] returnValue = null; int num = snapshotNum(); - if (num >= 0) { - returnValue = new String[num]; - if (num > 0) { - processError(libvirt.virDomainSnapshotListNames(VDP, returnValue, num, flags)); - } + if (num > 0) { + Pointer[] ptrs = new Pointer[num]; + int got = processError(libvirt.virDomainSnapshotListNames(VDP, ptrs, num, flags)); + + return Library.toStringArray(ptrs, got); + } else { + return Library.NO_STRINGS; } - return returnValue; } /** diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index bf3291d..5666c66 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -382,7 +382,7 @@ public interface Libvirt extends Library { int virDomainSnapshotDelete(DomainSnapshotPointer virDomainSnapshotPtr, int flags); String virDomainSnapshotGetXMLDesc(DomainSnapshotPointer virDomainSnapshotPtr, int flags); int virDomainSnapshotFree(DomainSnapshotPointer virDomainSnapshotPtr); - int virDomainSnapshotListNames(DomainPointer virDomainPtr, String[] names, int nameslen, int flags); + int virDomainSnapshotListNames(DomainPointer virDomainPtr, Pointer[] names, int nameslen, int flags); DomainSnapshotPointer virDomainSnapshotLookupByName(DomainPointer virDomainPtr, String name, int flags); int virDomainSnapshotNum(DomainPointer virDomainPtr, int flags); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:39PM +0100, Claudio Bley wrote:
We need to free the char* entries of the result array returned ourselves.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 14 +++++++------- src/main/java/org/libvirt/jna/Libvirt.java | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

eAt Fri, 21 Feb 2014 10:57:44 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:39PM +0100, Claudio Bley wrote:
We need to free the char* entries of the result array returned ourselves.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 14 +++++++------- src/main/java/org/libvirt/jna/Libvirt.java | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-)
ACK
Thanks, pushed.

We need to free the char* entries of the result array returned ourselves. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/StoragePool.java | 13 ++++++++++--- src/main/java/org/libvirt/jna/Libvirt.java | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/libvirt/StoragePool.java b/src/main/java/org/libvirt/StoragePool.java index bb608e3..14ecab8 100644 --- a/src/main/java/org/libvirt/StoragePool.java +++ b/src/main/java/org/libvirt/StoragePool.java @@ -8,6 +8,7 @@ import static org.libvirt.Library.libvirt; import static org.libvirt.ErrorHandler.processError; import com.sun.jna.Native; +import com.sun.jna.Pointer; import com.sun.jna.ptr.IntByReference; /** @@ -245,9 +246,15 @@ public class StoragePool { */ public String[] listVolumes() throws LibvirtException { int num = numOfVolumes(); - String[] returnValue = new String[num]; - processError(libvirt.virStoragePoolListVolumes(VSPP, returnValue, num)); - return returnValue; + if (num > 0) { + Pointer[] ptrs = new Pointer[num]; + + int got = processError(libvirt.virStoragePoolListVolumes(VSPP, ptrs, num)); + + return Library.toStringArray(ptrs, got); + } else { + return Library.NO_STRINGS; + } } /** diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 5666c66..2eb1cdc 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -305,7 +305,7 @@ public interface Libvirt extends Library { int virStoragePoolGetUUID(StoragePoolPointer storagePoolPtr, byte[] uuidString); int virStoragePoolGetUUIDString(StoragePoolPointer storagePoolPtr, byte[] uuidString); String virStoragePoolGetXMLDesc(StoragePoolPointer storagePoolPtr, int flags); - int virStoragePoolListVolumes(StoragePoolPointer storagePoolPtr, String[] names, int maxnames); + int virStoragePoolListVolumes(StoragePoolPointer storagePoolPtr, Pointer[] names, int maxnames); int virStoragePoolIsActive(StoragePoolPointer storagePoolPtr); int virStoragePoolIsPersistent(StoragePoolPointer storagePoolPtr); StoragePoolPointer virStoragePoolLookupByName(ConnectionPointer virConnectPtr, String name); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:40PM +0100, Claudio Bley wrote:
We need to free the char* entries of the result array returned ourselves.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/StoragePool.java | 13 ++++++++++--- src/main/java/org/libvirt/jna/Libvirt.java | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:58:35 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:40PM +0100, Claudio Bley wrote:
We need to free the char* entries of the result array returned ourselves.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/StoragePool.java | 13 ++++++++++--- src/main/java/org/libvirt/jna/Libvirt.java | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-)
ACK
Thanks, pushed.

Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/DomainSnapshot.java | 10 +++++++++- src/main/java/org/libvirt/jna/Libvirt.java | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/libvirt/DomainSnapshot.java b/src/main/java/org/libvirt/DomainSnapshot.java index 4736a71..3013117 100644 --- a/src/main/java/org/libvirt/DomainSnapshot.java +++ b/src/main/java/org/libvirt/DomainSnapshot.java @@ -4,6 +4,8 @@ import org.libvirt.jna.DomainSnapshotPointer; import static org.libvirt.Library.libvirt; import static org.libvirt.ErrorHandler.processError; +import com.sun.jna.Pointer; + public class DomainSnapshot { /** @@ -71,6 +73,12 @@ public class DomainSnapshot { * @return the XML document */ public String getXMLDesc() throws LibvirtException { - return processError(libvirt.virDomainSnapshotGetXMLDesc(VDSP, 0)); + Pointer p = processError(libvirt.virDomainSnapshotGetXMLDesc(VDSP, 0)); + + try { + return Library.getString(p); + } finally { + Library.free(p); + } } } diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 2eb1cdc..33b5f8c 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -380,7 +380,7 @@ public interface Libvirt extends Library { DomainSnapshotPointer virDomainSnapshotCreateXML(DomainPointer virDomainPtr, String xmlDesc, int flags); DomainSnapshotPointer virDomainSnapshotCurrent(DomainPointer virDomainPtr, int flags); int virDomainSnapshotDelete(DomainSnapshotPointer virDomainSnapshotPtr, int flags); - String virDomainSnapshotGetXMLDesc(DomainSnapshotPointer virDomainSnapshotPtr, int flags); + Pointer virDomainSnapshotGetXMLDesc(DomainSnapshotPointer virDomainSnapshotPtr, int flags); int virDomainSnapshotFree(DomainSnapshotPointer virDomainSnapshotPtr); int virDomainSnapshotListNames(DomainPointer virDomainPtr, Pointer[] names, int nameslen, int flags); DomainSnapshotPointer virDomainSnapshotLookupByName(DomainPointer virDomainPtr, String name, int flags); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:41PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/DomainSnapshot.java | 10 +++++++++- src/main/java/org/libvirt/jna/Libvirt.java | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:59:02 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:41PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/DomainSnapshot.java | 10 +++++++++- src/main/java/org/libvirt/jna/Libvirt.java | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-)
ACK
Thanks, pushed.

Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/StorageVol.java | 10 +++++++++- src/main/java/org/libvirt/jna/Libvirt.java | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/libvirt/StorageVol.java b/src/main/java/org/libvirt/StorageVol.java index 1573070..7035c93 100644 --- a/src/main/java/org/libvirt/StorageVol.java +++ b/src/main/java/org/libvirt/StorageVol.java @@ -6,6 +6,8 @@ import org.libvirt.jna.virStorageVolInfo; import static org.libvirt.Library.libvirt; import static org.libvirt.ErrorHandler.processError; +import com.sun.jna.Pointer; + /** * An acutal storage bucket. */ @@ -161,7 +163,13 @@ public class StorageVol { * @throws LibvirtException */ public String getPath() throws LibvirtException { - return processError(libvirt.virStorageVolGetPath(VSVP)); + Pointer p = processError(libvirt.virStorageVolGetPath(VSVP)); + + try { + return Library.getString(p); + } finally { + Library.free(p); + } } /** diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 33b5f8c..97907d0 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -326,7 +326,7 @@ public interface Libvirt extends Library { int virStorageVolGetInfo(StorageVolPointer storageVolPtr, virStorageVolInfo info); String virStorageVolGetKey(StorageVolPointer storageVolPtr); String virStorageVolGetName(StorageVolPointer storageVolPtr); - String virStorageVolGetPath(StorageVolPointer storageVolPtr); + Pointer virStorageVolGetPath(StorageVolPointer storageVolPtr); String virStorageVolGetXMLDesc(StorageVolPointer storageVolPtr, int flags); StorageVolPointer virStorageVolLookupByKey(ConnectionPointer virConnectPtr, String name); StorageVolPointer virStorageVolLookupByName(StoragePoolPointer storagePoolPtr, String name); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:42PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/StorageVol.java | 10 +++++++++- src/main/java/org/libvirt/jna/Libvirt.java | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:59:25 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:42PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/StorageVol.java | 10 +++++++++- src/main/java/org/libvirt/jna/Libvirt.java | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-)
ACK
Thanks, pushed.

Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/StorageVol.java | 8 +++++++- src/main/java/org/libvirt/jna/Libvirt.java | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/libvirt/StorageVol.java b/src/main/java/org/libvirt/StorageVol.java index 7035c93..47b79f6 100644 --- a/src/main/java/org/libvirt/StorageVol.java +++ b/src/main/java/org/libvirt/StorageVol.java @@ -181,7 +181,13 @@ public class StorageVol { * @throws LibvirtException */ public String getXMLDesc(int flags) throws LibvirtException { - return processError(libvirt.virStorageVolGetXMLDesc(VSVP, flags)); + Pointer p = processError(libvirt.virStorageVolGetXMLDesc(VSVP, flags)); + + try { + return Library.getString(p); + } finally { + Library.free(p); + } } /** diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 97907d0..67b6053 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -327,7 +327,7 @@ public interface Libvirt extends Library { String virStorageVolGetKey(StorageVolPointer storageVolPtr); String virStorageVolGetName(StorageVolPointer storageVolPtr); Pointer virStorageVolGetPath(StorageVolPointer storageVolPtr); - String virStorageVolGetXMLDesc(StorageVolPointer storageVolPtr, int flags); + Pointer virStorageVolGetXMLDesc(StorageVolPointer storageVolPtr, int flags); StorageVolPointer virStorageVolLookupByKey(ConnectionPointer virConnectPtr, String name); StorageVolPointer virStorageVolLookupByName(StoragePoolPointer storagePoolPtr, String name); StorageVolPointer virStorageVolLookupByPath(ConnectionPointer virConnectPtr, String path); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:43PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/StorageVol.java | 8 +++++++- src/main/java/org/libvirt/jna/Libvirt.java | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 10:59:44 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:43PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/StorageVol.java | 8 +++++++- src/main/java/org/libvirt/jna/Libvirt.java | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-)
ACK
Thanks, pushed.

These functions are not (yet) exposed in the public org.libvirt package but only used internally. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/jna/Libvirt.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 67b6053..ae03f18 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -98,6 +98,13 @@ public interface Libvirt extends Library { void eventCallback(ConnectionPointer virConnectPtr, DomainPointer virDomainPointer, Pointer opaque) ; } + /* + * Timeout Callback + */ + interface VirEventTimeoutCallback extends Callback { + void tick(int timerID, Pointer opaque); + } + Libvirt INSTANCE = (Libvirt) Native.loadLibrary(Platform.isWindows() ? "virt-0" : "virt", Libvirt.class); // Constants we need @@ -397,4 +404,8 @@ public interface Libvirt extends Library { int virNWFilterGetUUID(NetworkFilterPointer virNWFilterPtr, byte[] uuidString); int virNWFilterGetUUIDString(NetworkFilterPointer virNWFilterPtr, byte[] uuidString); int virNWFilterUndefine(NetworkFilterPointer virNWFilterPtr); + + // Event functions + int virEventAddTimeout(int milliSeconds, VirEventTimeoutCallback cb, Pointer opaque, Pointer ff); + int virEventRemoveTimeout(int timer); } -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:44PM +0100, Claudio Bley wrote:
These functions are not (yet) exposed in the public org.libvirt package but only used internally.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/jna/Libvirt.java | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 67b6053..ae03f18 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -98,6 +98,13 @@ public interface Libvirt extends Library { void eventCallback(ConnectionPointer virConnectPtr, DomainPointer virDomainPointer, Pointer opaque) ; }
+ /* + * Timeout Callback + */ + interface VirEventTimeoutCallback extends Callback { + void tick(int timerID, Pointer opaque); + } + Libvirt INSTANCE = (Libvirt) Native.loadLibrary(Platform.isWindows() ? "virt-0" : "virt", Libvirt.class);
// Constants we need @@ -397,4 +404,8 @@ public interface Libvirt extends Library { int virNWFilterGetUUID(NetworkFilterPointer virNWFilterPtr, byte[] uuidString); int virNWFilterGetUUIDString(NetworkFilterPointer virNWFilterPtr, byte[] uuidString); int virNWFilterUndefine(NetworkFilterPointer virNWFilterPtr); + + // Event functions + int virEventAddTimeout(int milliSeconds, VirEventTimeoutCallback cb, Pointer opaque, Pointer ff); + int virEventRemoveTimeout(int timer); }
ACK, if you also add the virEventUpdateTimeout method Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 11:01:47 +0000, Daniel P. Berrange wrote:
ACK, if you also add the virEventUpdateTimeout method
OK, but why should I add it? It's useless (for the user) and unused by the wrapping code. I want to keep the JNA library definition clean -- e.g. in a later patch I remove all the *UUIDString functions. Claudio

On Mon, Mar 03, 2014 at 04:46:51PM +0100, Claudio Bley wrote:
At Fri, 21 Feb 2014 11:01:47 +0000, Daniel P. Berrange wrote:
ACK, if you also add the virEventUpdateTimeout method
OK, but why should I add it? It's useless (for the user) and unused by the wrapping code. I want to keep the JNA library definition clean -- e.g. in a later patch I remove all the *UUIDString functions.
What makes you say it is useless ? The UpdateTimeout method lets you alter the timeout value for an existing timer, without having to go through Remove+Add of it. This might seem like a subtle distinction, but the difference is that the UpdateTimeout is guaranteed not to fail, where as Remove+Add may fail. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 03/03/2014 08:58 AM, Daniel P. Berrange wrote:
On Mon, Mar 03, 2014 at 04:46:51PM +0100, Claudio Bley wrote:
At Fri, 21 Feb 2014 11:01:47 +0000, Daniel P. Berrange wrote:
ACK, if you also add the virEventUpdateTimeout method
OK, but why should I add it? It's useless (for the user) and unused by the wrapping code. I want to keep the JNA library definition clean -- e.g. in a later patch I remove all the *UUIDString functions.
What makes you say it is useless ? The UpdateTimeout method lets you alter the timeout value for an existing timer, without having to go through Remove+Add of it. This might seem like a subtle distinction, but the difference is that the UpdateTimeout is guaranteed not to fail, where as Remove+Add may fail.
In fact, in my recent 'virsh event' additions, I explicitly used code that adds a timer with a -1 initial period (never fires), then use Update to turn it on and back off for each use of the 'event' command, rather than having to worry about Add failing on a per-command basis. The event loop code really does want all three callbacks to exist. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Eric Blake wrote:
On 03/03/2014 08:58 AM, Daniel P. Berrange wrote:
On Mon, Mar 03, 2014 at 04:46:51PM +0100, Claudio Bley wrote:
At Fri, 21 Feb 2014 11:01:47 +0000, Daniel P. Berrange wrote:
ACK, if you also add the virEventUpdateTimeout method
OK, but why should I add it? It's useless (for the user) and unused by the wrapping code. I want to keep the JNA library definition clean -- e.g. in a later patch I remove all the *UUIDString functions.
What makes you say it is useless ? The UpdateTimeout method lets you alter the timeout value for an existing timer, without having to go through Remove+Add of it. This might seem like a subtle distinction, but the difference is that the UpdateTimeout is guaranteed not to fail, where as Remove+Add may fail.
In fact, in my recent 'virsh event' additions, I explicitly used code that adds a timer with a -1 initial period (never fires),
The libxl driver also temporarily disables timers in this way. Regards, Jim

At Mon, 3 Mar 2014 15:58:25 +0000, Daniel P. Berrange wrote:
On Mon, Mar 03, 2014 at 04:46:51PM +0100, Claudio Bley wrote:
At Fri, 21 Feb 2014 11:01:47 +0000, Daniel P. Berrange wrote:
ACK, if you also add the virEventUpdateTimeout method
OK, but why should I add it? It's useless (for the user) and unused by the wrapping code. I want to keep the JNA library definition clean -- e.g. in a later patch I remove all the *UUIDString functions.
What makes you say it is useless ?
I don't regard the JNA mappings part of the public API of the Java bindings. It is a private implementation detail, which is (alas) public solely due to technical/historical reasons. So, it is useless for the user, because there is no way that he can use it (via the /public/ API)... Furthermore, I think there is no reason to expose those functions to the user at all. There are other means to program timeouts in Java than using the JNA wrapped libvirt functions where you have to run an event loop and take some speed drawbacks into account (libffi / native code to Java transition).
The UpdateTimeout method lets you alter the timeout value for an existing timer, without having to go through Remove+Add of it. This might seem like a subtle distinction, but the difference is that the UpdateTimeout is guaranteed not to fail, where as Remove+Add may fail.
At Mon, 03 Mar 2014 13:05:01 -0700, Eric Blake wrote:
In fact, in my recent 'virsh event' additions, I explicitly used code that adds a timer with a -1 initial period (never fires), then use Update to turn it on and back off for each use of the 'event' command, rather than having to worry about Add failing on a per-command basis.
For the Java event loop I've only used the Add / Remove timeout functions in order to break out of the event loop. In light of what both of you say, I think that is indeed better to do it using a disabled timer with updating it and I'll post a followup patch to change the implementation. Thanks, Claudio -- BSc (Comp) Claudio Bley - Principal Software Engineer AV-TEST GmbH, Klewitzstr. 7, 39112 Magdeburg, Germany Phone: +49 391 6075460, Fax: +49 391 6075469 Web: <http://www.av-test.org> * https://twitter.com/avtestorg * https://facebook.com/avtestorg * * https://plus.google.com/100383867141221115206/ * Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076) Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern Our services shall be effected on the basis of the General Terms and Conditions of AV-TEST GmbH, which are accessible under <http://www.av-test.org/en/av-test/terms-and-conditions/> or obtainable upon request. Unsere Leistungen erfolgen auf der Grundlage der Allgemeinen Geschäftsbedingungen der AV-TEST GmbH, die unter <http://www.av-test.org/av-test/agb/> abrufbar sind oder auf Anfrage übersandt werden.

On Tue, Mar 04, 2014 at 08:31:04AM +0100, Claudio Bley wrote:
At Mon, 3 Mar 2014 15:58:25 +0000, Daniel P. Berrange wrote:
On Mon, Mar 03, 2014 at 04:46:51PM +0100, Claudio Bley wrote:
At Fri, 21 Feb 2014 11:01:47 +0000, Daniel P. Berrange wrote:
ACK, if you also add the virEventUpdateTimeout method
OK, but why should I add it? It's useless (for the user) and unused by the wrapping code. I want to keep the JNA library definition clean -- e.g. in a later patch I remove all the *UUIDString functions.
What makes you say it is useless ?
I don't regard the JNA mappings part of the public API of the Java bindings. It is a private implementation detail, which is (alas) public solely due to technical/historical reasons.
So, it is useless for the user, because there is no way that he can use it (via the /public/ API)...
Furthermore, I think there is no reason to expose those functions to the user at all. There are other means to program timeouts in Java than using the JNA wrapped libvirt functions where you have to run an event loop and take some speed drawbacks into account (libffi / native code to Java transition).
Well we exposed them to the user in the C library because people did have a use for them. Sure you could use a separate Java APIs for doing timeouts, but IMHO many apps will find it useful to have just one single event loop in their program and thus want to make use of the libvirt virEvent{Add,Update,Remove}{Handle,Timer} APIs from their app. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

This wraps the virConnectIsAlive libvirt function available since version 0.9.8. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 12 ++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + src/test/java/org/libvirt/TestJavaBindings.java | 1 + 3 files changed, 14 insertions(+) diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index d92976e..d4868f0 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -1383,4 +1383,16 @@ public class Connect { public boolean isConnected() throws LibvirtException { return ( ( VCP != null ) ? true : false ); } + + /** + * Determine if the connection to the hypervisor is still alive. + * <p> + * A connection will be classed as alive if it is either local, + * or running over a channel (TCP or UNIX socket) which is not closed. + * + * @return {@code true} if alive, {@code false} otherwise. + */ + public boolean isAlive() throws LibvirtException { + return (1 == processError(libvirt.virConnectIsAlive(VCP))); + } } diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index ae03f18..69dabe2 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -128,6 +128,7 @@ public interface Libvirt extends Library { int virConnectDomainEventRegisterAny(ConnectionPointer virConnectPtr, DomainPointer virDomainPtr, int eventID, Libvirt.VirConnectDomainEventGenericCallback cb, Pointer opaque, Libvirt.VirFreeCallback freecb); int virConnectDomainEventDeregisterAny(ConnectionPointer virConnectPtr, int callbackID) ; void virConnSetErrorFunc(ConnectionPointer virConnectPtr, Pointer userData, VirErrorCallback callback); + int virConnectIsAlive(ConnectionPointer virConnectPtr); int virConnectIsEncrypted(ConnectionPointer virConnectPtr) ; int virConnectIsSecure(ConnectionPointer virConnectPtr) ; String virConnectFindStoragePoolSources(ConnectionPointer virConnectPtr, String type, String srcSpec, int flags); diff --git a/src/test/java/org/libvirt/TestJavaBindings.java b/src/test/java/org/libvirt/TestJavaBindings.java index 91f8df4..5cc77e7 100644 --- a/src/test/java/org/libvirt/TestJavaBindings.java +++ b/src/test/java/org/libvirt/TestJavaBindings.java @@ -42,6 +42,7 @@ public final class TestJavaBindings extends TestCase { assertTrue("conn.getLibVirVersion()", conn.getLibVirVersion() > 6000); assertTrue("conn.connectionVersion()", Connect.connectionVersion(conn) > 6000); assertEquals("conn.getVersion()", 2, conn.getVersion()); + assertTrue("conn.isAlive", conn.isAlive()); assertTrue("conn.isEncrypted", conn.isEncrypted() == 0); assertTrue("conn.isSecure", conn.isSecure() == 1); } -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:45PM +0100, Claudio Bley wrote:
This wraps the virConnectIsAlive libvirt function available since version 0.9.8.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 12 ++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + src/test/java/org/libvirt/TestJavaBindings.java | 1 + 3 files changed, 14 insertions(+)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

This wraps the virConnectSetKeepAlive libvirt function available since version 0.9.8. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 34 ++++++++++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + 2 files changed, 35 insertions(+) diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index d4868f0..0a45ac8 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -1395,4 +1395,38 @@ public class Connect { public boolean isAlive() throws LibvirtException { return (1 == processError(libvirt.virConnectIsAlive(VCP))); } + + /** + * Start sending keepalive messages. + * + * After {@code interval} seconds of inactivity, consider the + * connection to be broken when no response is received after + * {@code count} keepalive messages sent in a row. + * <p> + * In other words, sending {@code count + 1} keepalive message + * results in closing the connection. + * <p> + * When interval is <= 0, no keepalive messages will be sent. + * <p> + * When count is 0, the connection will be automatically closed after + * interval seconds of inactivity without sending any keepalive + * messages. + * <p> + * <em>Note</em>: client has to implement and run event loop to be + * able to use keepalive messages. Failure to do so may result in + * connections being closed unexpectedly. + * <p> + * <em>Note</em>: This API function controls only keepalive messages sent by + * the client. If the server is configured to use keepalive you still + * need to run the event loop to respond to them, even if you disable + * keepalives by this function. + * + * @param interval number of seconds of inactivity before a keepalive + * message is sent + * @param count number of messages that can be sent in a row + * @return {@code true} when successful, {@code false} otherwise. + */ + public boolean setKeepAlive(int interval, int count) throws LibvirtException { + return (0 == processError(libvirt.virConnectSetKeepAlive(VCP, interval, count))); + } } diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 69dabe2..2bc5b6b 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -162,6 +162,7 @@ public interface Libvirt extends Library { ConnectionPointer virConnectOpen(String name); ConnectionPointer virConnectOpenAuth(String name, virConnectAuth auth, int flags); ConnectionPointer virConnectOpenReadOnly(String name); + int virConnectSetKeepAlive(ConnectionPointer virConnectPtr, int interval, int count); /** * @deprecated as of libvirt 0.6.0, all errors reported in the -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:46PM +0100, Claudio Bley wrote:
This wraps the virConnectSetKeepAlive libvirt function available since version 0.9.8.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 34 ++++++++++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + 2 files changed, 35 insertions(+)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Add initEventLoop(), processEvent(), runEventLoop() and stopEventLoop() static methods to the Library class. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Library.java | 91 ++++++++++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 4 ++ 2 files changed, 95 insertions(+) diff --git a/src/main/java/org/libvirt/Library.java b/src/main/java/org/libvirt/Library.java index 95c13cb..3cfb8fd 100644 --- a/src/main/java/org/libvirt/Library.java +++ b/src/main/java/org/libvirt/Library.java @@ -7,6 +7,8 @@ import com.sun.jna.Native; import com.sun.jna.Pointer; import com.sun.jna.ptr.PointerByReference; +import java.util.concurrent.atomic.AtomicBoolean; + /** * This class represents an instance of the JNA mapped libvirt * library. @@ -17,6 +19,8 @@ import com.sun.jna.ptr.PointerByReference; * implementing the public API. */ final class Library { + private static AtomicBoolean runLoop = new AtomicBoolean(); + final static Libvirt libvirt; // an empty string array constant @@ -85,4 +89,91 @@ final class Library { } } } + + /** + * Initialize the event loop. + * + * Registers a default event loop implementation based on the + * poll() system call. + * <p> + * Once registered, the application has to invoke + * {@link #processEvent} in a loop or call {@link #runEventLoop} + * in another thread. + * <p> + * Note: You must call this function <em>before</em> connecting to + * the hypervisor. + * + * @throws LibvirtException on failure + * + * @see #processEvent + * @see #runLoop + */ + public static void initEventLoop() throws LibvirtException { + processError(libvirt.virEventRegisterDefaultImpl()); + } + + /** + * Run one iteration of the event loop. + * <p> + * Applications will generally want to have a thread which invokes + * this method in an infinite loop: + * <pre> + * {@code while (true) connection.processEvent(); } + * </pre> + * <p> + * Failure to do so may result in connections being closed + * unexpectedly as a result of keepalive timeout. + * + * @throws LibvirtException on failure + * + * @see #initEventLoop() + */ + public static void processEvent() throws LibvirtException { + processError(libvirt.virEventRunDefaultImpl()); + } + + /** + * Runs the event loop. + * + * This method blocks until {@link #stopEventLoop} is called or an + * exception is thrown. + * <p> + * Usually, this method is run in another thread. + * + * @throws LibvirtException if there was an error during the call of a + * native libvirt function + * @throws InterruptedException if this thread was interrupted by a call to + * {@link java.lang.Thread#interrupt() Thread.interrupt()} + */ + public static void runEventLoop() throws LibvirtException, InterruptedException { + runLoop.set(true); + do { + processEvent(); + if (Thread.interrupted()) + throw new InterruptedException(); + } while (runLoop.get()); + } + + /** + * Stops the event loop. + * + * This methods stops an event loop when an event loop is + * currently running, otherwise it does nothing. + * + * @see #runEventLoop + */ + public static void stopEventLoop() throws LibvirtException { + if (runLoop.getAndSet(false)) { + // add a timeout which fires immediately so that the processEvent + // method returns if it is waiting + libvirt.virEventAddTimeout(0, new org.libvirt.jna.Libvirt.VirEventTimeoutCallback() { + @Override + public void tick(int id, Pointer p) { + // remove itself right after it served its purpose + libvirt.virEventRemoveTimeout(id); + } + }, + null, null); + } + } } diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 2bc5b6b..ed52bd3 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -187,6 +187,10 @@ public interface Libvirt extends Library { void virResetLastError(); void virSetErrorFunc(Pointer userData, VirErrorCallback callback); + // Event loop functions. + int virEventRegisterDefaultImpl(); + int virEventRunDefaultImpl(); + // Domain functions int virDomainAbortJob(DomainPointer virDomainPtr); int virDomainAttachDevice(DomainPointer virDomainPtr, String deviceXML); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:47PM +0100, Claudio Bley wrote:
Add initEventLoop(), processEvent(), runEventLoop() and stopEventLoop() static methods to the Library class.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Library.java | 91 ++++++++++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 4 ++ 2 files changed, 95 insertions(+)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 11:03:49 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:47PM +0100, Claudio Bley wrote:
Add initEventLoop(), processEvent(), runEventLoop() and stopEventLoop() static methods to the Library class.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Library.java | 91 ++++++++++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 4 ++ 2 files changed, 95 insertions(+)
ACK
This is what I'd want to squash in prior pushing the patch in order to avoid failures due to virEventAddTimeout when stopping an event loop as suggested by you, Eric[1] and Jim[2]. Since this code requires the virEventUpdateTimeout function, I've added it into patch 36/65 as you requested[3]. [1]: http://www.redhat.com/archives/libvir-list/2014-March/msg00144.html [2]: http://www.redhat.com/archives/libvir-list/2014-March/msg00168.html [3]: http://www.redhat.com/archives/libvir-list/2014-February/msg01318.html --- diff --git a/src/main/java/org/libvirt/Library.java b/src/main/java/org/libvirt/Library.java --- a/src/main/java/org/libvirt/Library.java +++ b/src/main/java/org/libvirt/Library.java @@ -1,6 +1,7 @@ package org.libvirt; import org.libvirt.jna.Libvirt; +import org.libvirt.jna.Libvirt.VirEventTimeoutCallback; import static org.libvirt.ErrorHandler.processError; import com.sun.jna.Native; @@ -8,6 +9,7 @@ import com.sun.jna.ptr.PointerByReference; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; /** * This class represents an instance of the JNA mapped libvirt @@ -20,6 +22,14 @@ */ final class Library { private static AtomicBoolean runLoop = new AtomicBoolean(); + private static AtomicInteger timerID = new AtomicInteger(-1); + private static VirEventTimeoutCallback timer = new VirEventTimeoutCallback() { + @Override + public void tick(int id, Pointer p) { + // disable myself again right after being triggered + libvirt.virEventUpdateTimeout(id, -1); + } + }; final static Libvirt libvirt; @@ -109,7 +119,18 @@ * @see #runLoop */ public static void initEventLoop() throws LibvirtException { - processError(libvirt.virEventRegisterDefaultImpl()); + if (timerID.get() == -1) { + processError(libvirt.virEventRegisterDefaultImpl()); + + // add a disabled timer which is used later to break out + // of the event loop + int id = processError(libvirt.virEventAddTimeout(-1, timer, null, null)); + + // remove this timer when there already is another one + if (!timerID.compareAndSet(-1, id)) { + libvirt.virEventRemoveTimeout(id); + } + } } /** @@ -164,16 +185,10 @@ */ public static void stopEventLoop() throws LibvirtException { if (runLoop.getAndSet(false)) { - // add a timeout which fires immediately so that the processEvent - // method returns if it is waiting - libvirt.virEventAddTimeout(0, new org.libvirt.jna.Libvirt.VirEventTimeoutCallback() { - @Override - public void tick(int id, Pointer p) { - // remove itself right after it served its purpose - libvirt.virEventRemoveTimeout(id); - } - }, - null, null); + // fire the timer immediately + int timer = timerID.get(); + if (timer >= 0) + libvirt.virEventUpdateTimeout(timer, 0); } } }

Note: these are only used internally. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index 0a45ac8..8ba9691 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -34,6 +34,26 @@ import com.sun.jna.ptr.LongByReference; public class Connect { /** + * Event IDs. + */ + private interface DomainEventID { + static final int LIFECYCLE = 0; + static final int REBOOT = 1; + static final int RTC_CHANGE = 2; + static final int WATCHDOG = 3; + static final int IO_ERROR = 4; + static final int GRAPHICS = 5; + static final int IO_ERROR_REASON = 6; + static final int CONTROL_ERROR = 7; + static final int BLOCK_JOB = 8; + static final int DISK_CHANGE = 9; + static final int TRAY_CHANGE = 10; + static final int PMWAKEUP = 11; + static final int PMSUSPEND = 12; + static final int LAST = 13; + } + + /** * Get the version of a connection. * * @see <a -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:48PM +0100, Claudio Bley wrote:
Note: these are only used internally.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 02/13/2014 08:22 AM, Claudio Bley wrote:
Note: these are only used internally.
Signed-off-by: Claudio Bley <cbley@av-test.de> ---
+ static final int CONTROL_ERROR = 7; + static final int BLOCK_JOB = 8; + static final int DISK_CHANGE = 9; + static final int TRAY_CHANGE = 10; + static final int PMWAKEUP = 11; + static final int PMSUSPEND = 12;
Up to here, I can understand.
+ static final int LAST = 13;
But you probably do NOT want this value, as we explicitly document that our _LAST C enums are not constant (we reserve the right to add more events), but merely aids for compilation to ensure that all cases are covered compared to the current state of the libvirt.h header. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

At Mon, 03 Mar 2014 13:06:50 -0700, Eric Blake wrote:
[1 <text/plain; UTF-8 (quoted-printable)>] On 02/13/2014 08:22 AM, Claudio Bley wrote:
Note: these are only used internally.
Signed-off-by: Claudio Bley <cbley@av-test.de> ---
+ static final int CONTROL_ERROR = 7; + static final int BLOCK_JOB = 8; + static final int DISK_CHANGE = 9; + static final int TRAY_CHANGE = 10; + static final int PMWAKEUP = 11; + static final int PMSUSPEND = 12;
Up to here, I can understand.
+ static final int LAST = 13;
But you probably do NOT want this value, as we explicitly document that our _LAST C enums are not constant (we reserve the right to add more events), but merely aids for compilation to ensure that all cases are covered compared to the current state of the libvirt.h header.
Trust me, I want this constant. ;-) Note, that all those constants are private. This constant is used in patch #41 to define the length of an array: + // registered event listeners by DomainEventID + private Map<EventListener, Integer>[] eventListeners = makeHashMapArray(DomainEventID.LAST); Claudio

Remove the public domainEventRegisterAny and domainEventDeregisterAny methods. These methods basically were of no use since the only thing you could register was a "generic" callback. At runtime, you would have to provide a real callback function matching the prototype of the native callback type. Trying to use a generic callback instead quickly leads to failures or JVM crashes. For convenience and the sake of type safety we don't let the user deal with Libvirt.VirDomainEventCallback interfaces directly. Instead, there will be a specific interface definition for each type of callback as we soon shall see. To prevent the garbage collector from reaping registered callback objects every event callback will be stored along with its eventID and corresponding listener instance. This will provide a natural, idiomatic interface using addListener/removeListener methods. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 79 ++++++++++++-------- src/main/java/org/libvirt/event/EventListener.java | 7 ++ src/main/java/org/libvirt/jna/Libvirt.java | 22 ++++-- 3 files changed, 73 insertions(+), 35 deletions(-) create mode 100644 src/main/java/org/libvirt/event/EventListener.java diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index 8ba9691..14668ef 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -1,7 +1,10 @@ package org.libvirt; +import java.util.HashMap; +import java.util.Map; import java.util.UUID; +import org.libvirt.event.*; import org.libvirt.jna.ConnectionPointer; import org.libvirt.jna.DevicePointer; import org.libvirt.jna.DomainPointer; @@ -33,6 +36,14 @@ import com.sun.jna.ptr.LongByReference; */ public class Connect { + // registered event listeners by DomainEventID + private Map<EventListener, Integer>[] eventListeners = makeHashMapArray(DomainEventID.LAST); + + @SuppressWarnings("unchecked") + private static <K, V> HashMap<K, V>[] makeHashMapArray(int size) { + return new HashMap[size]; + } + /** * Event IDs. */ @@ -354,42 +365,50 @@ public class Connect { } /** - * Removes an event callback. + * Removes the event listener for the given eventID parameter so + * that it no longer receives events. + * + * @param eventID the domain event identifier + * @param l the event listener + * @throws LibvirtException * * @see <a - * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventDeregisterAny">Libvirt - * Documentation</a> - * @param callbackID - * the callback to deregister - * @return <em>ignore</em> (always 0) - * @throws LibvirtException + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventDeregi..." + * >virConnectDomainEventDeregisterAny</a> */ - public int domainEventDeregisterAny(int callbackID) throws LibvirtException { - return processError(libvirt.virConnectDomainEventDeregisterAny(VCP, callbackID)); + private void domainEventDeregister(int eventID, EventListener l) throws LibvirtException { + if (l == null) + return; + + Map<EventListener, Integer> handlers = eventListeners[eventID]; + + if (handlers == null) return; + + Integer listenerID = handlers.remove(l); + + if (listenerID != null) + processError(libvirt.virConnectDomainEventDeregisterAny(VCP, listenerID)); } - /** - * Adds a callback to receive notifications of arbitrary domain events - * occurring on a domain. - * - * @see <a - * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventRegisterAny">Libvirt - * Documentation</a> - * @param domain - * option domain to limit the events monitored - * @param eventId - * the events to monitor - * @param cb - * the callback function to use. - * @return The return value from this method is a positive integer - * identifier for the callback. - * @throws LibvirtException on failure - */ - public int domainEventRegisterAny(Domain domain, int eventId, Libvirt.VirConnectDomainEventGenericCallback cb) - throws LibvirtException { + private void domainEventRegister(Domain domain, int eventID, Libvirt.VirDomainEventCallback cb, EventListener l) + throws LibvirtException + { + Map<EventListener, Integer> handlers = eventListeners[eventID]; + + if (handlers == null) { + handlers = new HashMap<EventListener, Integer>(); + eventListeners[eventID] = handlers; + } else if (handlers.containsKey(l)) { + return; + } + DomainPointer ptr = domain == null ? null : domain.VDP; - int returnValue = libvirt.virConnectDomainEventRegisterAny(VCP, ptr, eventId, cb, null, null); - return processError(returnValue); + + int ret = processError(libvirt.virConnectDomainEventRegisterAny(VCP, ptr, + eventID, cb, + null, null)); + + handlers.put(l, ret); } /** diff --git a/src/main/java/org/libvirt/event/EventListener.java b/src/main/java/org/libvirt/event/EventListener.java new file mode 100644 index 0000000..fe7e127 --- /dev/null +++ b/src/main/java/org/libvirt/event/EventListener.java @@ -0,0 +1,7 @@ +package org.libvirt.event; + +/** + * Base interface implemented by every event listener. + */ +public interface EventListener { +} diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index ed52bd3..9eb9e86 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -66,6 +66,19 @@ public interface Libvirt extends Library { } /** + * Domain Event Callbacks + */ + + /** + * Common Event Callback super interface. + * + * All domain event callbacks extend this interface. + * + * @see #virConnectDomainEventRegisterAny + */ + interface VirDomainEventCallback extends Callback {} + + /** * Error callback */ interface VirErrorCallback extends Callback { @@ -94,10 +107,6 @@ public interface Libvirt extends Library { void freeCallback(Pointer opaque) ; } - interface VirConnectDomainEventGenericCallback extends Callback { - void eventCallback(ConnectionPointer virConnectPtr, DomainPointer virDomainPointer, Pointer opaque) ; - } - /* * Timeout Callback */ @@ -125,7 +134,10 @@ public interface Libvirt extends Library { int virConnCopyLastError(ConnectionPointer virConnectPtr, virError to); int virConnectClose(ConnectionPointer virConnectPtr); int virConnectCompareCPU(ConnectionPointer virConnectPtr, String xmlDesc, int flags); - int virConnectDomainEventRegisterAny(ConnectionPointer virConnectPtr, DomainPointer virDomainPtr, int eventID, Libvirt.VirConnectDomainEventGenericCallback cb, Pointer opaque, Libvirt.VirFreeCallback freecb); + + // Register Domain Event Callbacks + int virConnectDomainEventRegisterAny(ConnectionPointer virConnectPtr, DomainPointer virDomainPtr, int eventID, VirDomainEventCallback cb, Pointer opaque, Libvirt.VirFreeCallback freecb); + int virConnectDomainEventDeregisterAny(ConnectionPointer virConnectPtr, int callbackID) ; void virConnSetErrorFunc(ConnectionPointer virConnectPtr, Pointer userData, VirErrorCallback callback); int virConnectIsAlive(ConnectionPointer virConnectPtr); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:49PM +0100, Claudio Bley wrote:
Remove the public domainEventRegisterAny and domainEventDeregisterAny methods. These methods basically were of no use since the only thing you could register was a "generic" callback.
At runtime, you would have to provide a real callback function matching the prototype of the native callback type.
Trying to use a generic callback instead quickly leads to failures or JVM crashes.
For convenience and the sake of type safety we don't let the user deal with Libvirt.VirDomainEventCallback interfaces directly.
Instead, there will be a specific interface definition for each type of callback as we soon shall see.
To prevent the garbage collector from reaping registered callback objects every event callback will be stored along with its eventID and corresponding listener instance.
This will provide a natural, idiomatic interface using addListener/removeListener methods.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 79 ++++++++++++-------- src/main/java/org/libvirt/event/EventListener.java | 7 ++ src/main/java/org/libvirt/jna/Libvirt.java | 22 ++++-- 3 files changed, 73 insertions(+), 35 deletions(-) create mode 100644 src/main/java/org/libvirt/event/EventListener.java
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

This method constructs a new Domain class instance while increasing the reference count on the virDomainPtr in order to make sure the Domain object "owns" the given virDomainPtr. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 14 ++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 39cb7c5..ec95f5f 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -201,6 +201,20 @@ public class Domain { } /** + * Constructs a new Domain object increasing the reference count + * on the DomainPointer. + * <p> + * This factory method is mostly useful with callback functions, + * since the virDomainPtr passed is only valid for the duration of + * execution of the callback. + */ + static Domain constructIncRef(Connect virConnect, DomainPointer VDP) throws LibvirtException { + processError(libvirt.virDomainRef(VDP)); + + return new Domain(virConnect, VDP); + } + + /** * Requests that the current background job be aborted at the soonest * opportunity. This will block until the job has either completed, or * aborted. diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 9eb9e86..ba8b073 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -31,7 +31,6 @@ import com.sun.jna.ptr.PointerByReference; * * LIBVIRT_0.6.0 * virConnectRef - * virDomainRef * virNetworkRef * virStoragePoolRef * virStorageVolRef @@ -258,6 +257,7 @@ public interface Libvirt extends Library { int virDomainMemoryStats(DomainPointer virDomainPtr, virDomainMemoryStats[] stats, int nr_stats, int flags); int virDomainPinVcpu(DomainPointer virDomainPtr, int vcpu, byte[] cpumap, int maplen); int virDomainReboot(DomainPointer virDomainPtr, int flags); + int virDomainRef(DomainPointer virDomainPtr); int virDomainRestore(ConnectionPointer virConnectPtr, String from); int virDomainRevertToSnapshot(DomainSnapshotPointer virDomainSnapshotPtr, int flags); int virDomainResume(DomainPointer virDomainPtr); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:50PM +0100, Claudio Bley wrote:
This method constructs a new Domain class instance while increasing the reference count on the virDomainPtr in order to make sure the Domain object "owns" the given virDomainPtr.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 14 ++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Add IOErrorActionListener and IOErrorAction enum which is handed to the onIOError callback method when an IO error event occurs. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 59 ++++++++++++++++++++ src/main/java/org/libvirt/Domain.java | 16 ++++++ src/main/java/org/libvirt/Library.java | 20 +++++++ src/main/java/org/libvirt/event/IOErrorAction.java | 39 +++++++++++++ .../java/org/libvirt/event/IOErrorListener.java | 21 +++++++ src/main/java/org/libvirt/jna/Libvirt.java | 8 +++ 6 files changed, 163 insertions(+) create mode 100644 src/main/java/org/libvirt/event/IOErrorAction.java create mode 100644 src/main/java/org/libvirt/event/IOErrorListener.java diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index 14668ef..5637337 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -20,6 +20,7 @@ import org.libvirt.jna.virConnectAuth; import org.libvirt.jna.virNodeInfo; import static org.libvirt.Library.libvirt; +import static org.libvirt.Library.getConstant; import static org.libvirt.ErrorHandler.processError; import static org.libvirt.ErrorHandler.processErrorIfZero; @@ -411,6 +412,64 @@ public class Connect { handlers.put(l, ret); } + void domainEventRegister(Domain domain, final IOErrorListener cb) throws LibvirtException { + if (cb == null) + throw new IllegalArgumentException("IOError callback cannot be null"); + + Libvirt.VirConnectDomainEventIOErrorCallback virCB = new Libvirt.VirConnectDomainEventIOErrorCallback() { + @Override + public void eventCallback(ConnectionPointer virConnectPtr, DomainPointer virDomainPointer, + String srcPath, + String devAlias, + int action, + Pointer opaque) { + assert VCP.equals(virConnectPtr); + + try { + Domain d = Domain.constructIncRef(Connect.this, virDomainPointer); + cb.onIOError(d, + srcPath, + devAlias, + getConstant(IOErrorAction.class, action)); + } catch (LibvirtException e) { + throw new RuntimeException("libvirt error in IOError callback", e); + } + } + }; + + domainEventRegister(domain, DomainEventID.IO_ERROR, virCB, cb); + } + + /** + * Adds the specified I/O error listener to receive I/O error events + * for domains of this connection. + * + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventRegisterAny">Libvirt + * Documentation</a> + * @param l + * the I/O error listener + * @throws LibvirtException on failure + */ + public void addIOErrorListener(final IOErrorListener l) throws LibvirtException { + domainEventRegister(null, l); + } + + /** + * Removes the specified I/O error listener so that it no longer + * receives I/O error events. + * + * @param l the I/O error listener + * @throws LibvirtException + * + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventDeregi..." + * >virConnectDomainEventDeregisterAny</a> + */ + public void removeIOErrorListener(IOErrorListener l) throws LibvirtException { + domainEventDeregister(DomainEventID.IO_ERROR, l); + } + /** * Finds a domain based on the hypervisor ID number. * diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index ec95f5f..f37f299 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -1,5 +1,6 @@ package org.libvirt; +import org.libvirt.event.IOErrorListener; import org.libvirt.jna.DomainPointer; import org.libvirt.jna.DomainSnapshotPointer; import org.libvirt.jna.Libvirt; @@ -1031,6 +1032,21 @@ public class Domain { } /** + * Adds a callback to receive notifications of IOError domain events + * occurring on this domain. + * + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventRegisterAny">Libvirt + * Documentation</a> + * @param cb + * the IOErrorCallback instance + * @throws LibvirtException on failure + */ + public void addIOErrorListener(final IOErrorListener cb) throws LibvirtException { + virConnect.domainEventRegister(this, cb); + } + + /** * Revert the domain to a given snapshot. * * @see <a href= diff --git a/src/main/java/org/libvirt/Library.java b/src/main/java/org/libvirt/Library.java index 3cfb8fd..81df223 100644 --- a/src/main/java/org/libvirt/Library.java +++ b/src/main/java/org/libvirt/Library.java @@ -176,4 +176,24 @@ final class Library { null, null); } } + + /** + * Look up a constant of an enum by its ordinal number. + * + * @return the corresponding enum constant when such a constant exists, + * otherwise the element which has the biggest ordinal number + * assigned. + * + * @throws IllegalArgumentException if {@code ordinal} is negative + */ + static <T extends Enum<T>> T getConstant(final Class<T> c, final int ordinal) { + if (ordinal < 0) + throw new IllegalArgumentException("ordinal must be >= 0"); + + T[] a = c.getEnumConstants(); + + assert a.length > 0 : "there must be at least one enum constant"; + + return a[Math.min(ordinal, a.length - 1)]; + } } diff --git a/src/main/java/org/libvirt/event/IOErrorAction.java b/src/main/java/org/libvirt/event/IOErrorAction.java new file mode 100644 index 0000000..bfda1de --- /dev/null +++ b/src/main/java/org/libvirt/event/IOErrorAction.java @@ -0,0 +1,39 @@ +package org.libvirt.event; + +public enum IOErrorAction { + /** + * No action, I/O error ignored. + */ + NONE, + + /** + * Guest CPUs are paused. + */ + PAUSE, + + /** + * I/O error was reported to the guest OS. + */ + REPORT, + + /** + * An unknown action was taken. + */ + UNKNOWN; + + private static final IOErrorAction vals[] = IOErrorAction.values(); + + static { + // make sure that the enum constants have the correct + // ordinal number assigned in correspondence to the + // values of the virDomainEventIOErrorAction enum + // members + + assert NONE.ordinal() == 0; + assert PAUSE.ordinal() == 1; + assert REPORT.ordinal() == 2; + + // must be the last constant + assert UNKNOWN.ordinal() == vals.length - 1; + } +} diff --git a/src/main/java/org/libvirt/event/IOErrorListener.java b/src/main/java/org/libvirt/event/IOErrorListener.java new file mode 100644 index 0000000..efd66c4 --- /dev/null +++ b/src/main/java/org/libvirt/event/IOErrorListener.java @@ -0,0 +1,21 @@ +package org.libvirt.event; + +import org.libvirt.Domain; + +/** + * Interface for receiving domain I/O error events. + */ +public interface IOErrorListener extends EventListener { + /** + * This method gets called upon a domain I/O error event. + * + * @param domain the domain which got an I/O error + * @param srcPath the src of the block device with errors + * @param devAlias the device alias of the block device with errors + * @param action the action that is to be taken due to the I/O error + */ + void onIOError(Domain domain, + String srcPath, + String devAlias, + IOErrorAction action); +} diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index ba8b073..0e36251 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -77,6 +77,14 @@ public interface Libvirt extends Library { */ interface VirDomainEventCallback extends Callback {} + interface VirConnectDomainEventIOErrorCallback extends VirDomainEventCallback { + void eventCallback(ConnectionPointer virConnectPtr, DomainPointer virDomainPointer, + String srcPath, + String devAlias, + int action, + Pointer opaque); + } + /** * Error callback */ -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:51PM +0100, Claudio Bley wrote:
Add IOErrorActionListener and IOErrorAction enum which is handed to the onIOError callback method when an IO error event occurs.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 59 ++++++++++++++++++++ src/main/java/org/libvirt/Domain.java | 16 ++++++ src/main/java/org/libvirt/Library.java | 20 +++++++ src/main/java/org/libvirt/event/IOErrorAction.java | 39 +++++++++++++ .../java/org/libvirt/event/IOErrorListener.java | 21 +++++++ src/main/java/org/libvirt/jna/Libvirt.java | 8 +++ 6 files changed, 163 insertions(+) create mode 100644 src/main/java/org/libvirt/event/IOErrorAction.java create mode 100644 src/main/java/org/libvirt/event/IOErrorListener.java
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Add RebootListener interface in package org.libvirt.event and implement addRebootListener methods in classes Domain and Connect. Add removeRebootListener to Connect class. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 41 ++++++++++++++++++++ src/main/java/org/libvirt/Domain.java | 17 ++++++++ .../java/org/libvirt/event/RebootListener.java | 15 +++++++ src/main/java/org/libvirt/jna/Libvirt.java | 4 ++ 4 files changed, 77 insertions(+) create mode 100644 src/main/java/org/libvirt/event/RebootListener.java diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index 5637337..bbbd000 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -18,6 +18,7 @@ import org.libvirt.jna.StorageVolPointer; import org.libvirt.jna.StreamPointer; import org.libvirt.jna.virConnectAuth; import org.libvirt.jna.virNodeInfo; +import org.libvirt.event.*; import static org.libvirt.Library.libvirt; import static org.libvirt.Library.getConstant; @@ -455,6 +456,46 @@ public class Connect { domainEventRegister(null, l); } + void domainEventRegister(Domain domain, final RebootListener cb) throws LibvirtException { + if (cb == null) + throw new IllegalArgumentException("RebootCallback cannot be null"); + + Libvirt.VirConnectDomainEventGenericCallback virCB = new Libvirt.VirConnectDomainEventGenericCallback() { + @Override + public void eventCallback(ConnectionPointer virConnectPtr, + DomainPointer virDomainPointer, + Pointer opaque) { + assert VCP.equals(virConnectPtr); + + try { + Domain d = Domain.constructIncRef(Connect.this, virDomainPointer); + cb.onReboot(d); + } catch (LibvirtException e) { + throw new RuntimeException("libvirt error in reboot callback", e); + } + } + }; + + domainEventRegister(domain, DomainEventID.REBOOT, virCB, cb); + } + + /** + * Adds the specified reboot listener to receive reboot events for + * domains of this connection. + * + * @param l the reboot listener + * @throws LibvirtException on failure + * + * @see Domain#addRebootListener + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventRegist..." + * >virConnectDomainEventRegisterAny</a> + * @since 1.5.2 + */ + public void addRebootListener(final RebootListener l) throws LibvirtException { + domainEventRegister(null, l); + } + /** * Removes the specified I/O error listener so that it no longer * receives I/O error events. diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index f37f299..010fee0 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -13,6 +13,7 @@ import org.libvirt.jna.virDomainJobInfo; import org.libvirt.jna.virDomainMemoryStats; import org.libvirt.jna.virSchedParameter; import org.libvirt.jna.virVcpuInfo; +import org.libvirt.event.RebootListener; import static org.libvirt.Library.libvirt; import static org.libvirt.ErrorHandler.processError; import static org.libvirt.ErrorHandler.processErrorIfZero; @@ -1047,6 +1048,22 @@ public class Domain { } /** + * Adds the specified listener to receive reboot events for this domain. + * + * @param l the reboot listener + * @throws LibvirtException on failure + * + * @see Connect#addRebootListener + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventRegist..." + * >virConnectDomainEventRegisterAny</a> + * @since 1.5.2 + */ + public void addRebootListener(final RebootListener l) throws LibvirtException { + virConnect.domainEventRegister(this, l); + } + + /** * Revert the domain to a given snapshot. * * @see <a href= diff --git a/src/main/java/org/libvirt/event/RebootListener.java b/src/main/java/org/libvirt/event/RebootListener.java new file mode 100644 index 0000000..1b440c0 --- /dev/null +++ b/src/main/java/org/libvirt/event/RebootListener.java @@ -0,0 +1,15 @@ +package org.libvirt.event; + +import org.libvirt.Domain; + +/** + * Interface for receiving domain reboot events. + */ +public interface RebootListener extends EventListener { + /** + * This method gets called upon a domain reboot event. + * + * @param domain the domain which was rebooted + */ + void onReboot(Domain domain); +} diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 0e36251..913fe08 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -85,6 +85,10 @@ public interface Libvirt extends Library { Pointer opaque); } + interface VirConnectDomainEventGenericCallback extends VirDomainEventCallback { + void eventCallback(ConnectionPointer virConnectPtr, DomainPointer virDomainPointer, Pointer opaque); + } + /** * Error callback */ -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:52PM +0100, Claudio Bley wrote:
Add RebootListener interface in package org.libvirt.event and implement addRebootListener methods in classes Domain and Connect.
Add removeRebootListener to Connect class.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 41 ++++++++++++++++++++ src/main/java/org/libvirt/Domain.java | 17 ++++++++ .../java/org/libvirt/event/RebootListener.java | 15 +++++++ src/main/java/org/libvirt/jna/Libvirt.java | 4 ++ 4 files changed, 77 insertions(+) create mode 100644 src/main/java/org/libvirt/event/RebootListener.java
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Add LifecycleListener interface which needs to be implemented when the user wishes to receive lifecycle change events on domains. The DomainEvent class represents the kind of event that occurred including details on that event. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 66 ++++++++++++++++++ src/main/java/org/libvirt/Domain.java | 18 +++++ src/main/java/org/libvirt/event/CrashedDetail.java | 15 +++++ src/main/java/org/libvirt/event/DefinedDetail.java | 17 +++++ src/main/java/org/libvirt/event/DetailInfo.java | 5 ++ src/main/java/org/libvirt/event/DomainEvent.java | 71 ++++++++++++++++++++ .../java/org/libvirt/event/DomainEventDetail.java | 7 ++ .../java/org/libvirt/event/DomainEventType.java | 60 +++++++++++++++++ .../java/org/libvirt/event/LifecycleListener.java | 24 +++++++ .../java/org/libvirt/event/PMSuspendedDetail.java | 15 +++++ src/main/java/org/libvirt/event/ResumedDetail.java | 20 ++++++ .../java/org/libvirt/event/ShutdownDetail.java | 12 ++++ src/main/java/org/libvirt/event/StartedDetail.java | 30 +++++++++ src/main/java/org/libvirt/event/StoppedDetail.java | 40 +++++++++++ .../java/org/libvirt/event/SuspendedDetail.java | 40 +++++++++++ .../java/org/libvirt/event/UndefinedDetail.java | 7 ++ src/main/java/org/libvirt/jna/Libvirt.java | 7 ++ 17 files changed, 454 insertions(+) create mode 100644 src/main/java/org/libvirt/event/CrashedDetail.java create mode 100644 src/main/java/org/libvirt/event/DefinedDetail.java create mode 100644 src/main/java/org/libvirt/event/DetailInfo.java create mode 100644 src/main/java/org/libvirt/event/DomainEvent.java create mode 100644 src/main/java/org/libvirt/event/DomainEventDetail.java create mode 100644 src/main/java/org/libvirt/event/DomainEventType.java create mode 100644 src/main/java/org/libvirt/event/LifecycleListener.java create mode 100644 src/main/java/org/libvirt/event/PMSuspendedDetail.java create mode 100644 src/main/java/org/libvirt/event/ResumedDetail.java create mode 100644 src/main/java/org/libvirt/event/ShutdownDetail.java create mode 100644 src/main/java/org/libvirt/event/StartedDetail.java create mode 100644 src/main/java/org/libvirt/event/StoppedDetail.java create mode 100644 src/main/java/org/libvirt/event/SuspendedDetail.java create mode 100644 src/main/java/org/libvirt/event/UndefinedDetail.java diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index bbbd000..d82dba2 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -479,6 +479,72 @@ public class Connect { domainEventRegister(domain, DomainEventID.REBOOT, virCB, cb); } + void domainEventRegister(Domain domain, final LifecycleListener cb) throws LibvirtException { + if (cb == null) + throw new IllegalArgumentException("LifecycleCallback cannot be null"); + + Libvirt.VirConnectDomainEventCallback virCB = new Libvirt.VirConnectDomainEventCallback() { + @Override + public int eventCallback(ConnectionPointer virConnectPtr, DomainPointer virDomainPointer, + final int eventCode, + final int detailCode, + Pointer opaque) { + assert VCP.equals(virConnectPtr); + + try { + Domain dom = Domain.constructIncRef(Connect.this, virDomainPointer); + DomainEventType type = getConstant(DomainEventType.class, eventCode); + DomainEvent event = new DomainEvent(type, detailCode); + + cb.onLifecycleChange(dom, event); + } catch (LibvirtException e) { + throw new RuntimeException("libvirt error in lifecycle callback", e); + } + + // always return 0, regardless of what the + // callback method returned. This may need to be + // changed in the future, in case the return value + // is used for something by libvirt. + return 0; + } + }; + + domainEventRegister(domain, DomainEventID.LIFECYCLE, virCB, cb); + } + + /** + * Adds the specified listener to receive lifecycle events for + * domains of this connections. + * + * @param l the lifecycle listener + * @throws LibvirtException on failure + * + * @see #removeLifecycleListener + * @see Domain#addLifecycleListener + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventRegist..." + * >virConnectDomainEventRegisterAny</a> + */ + public void addLifecycleListener(final LifecycleListener l) throws LibvirtException + { + domainEventRegister(null, l); + } + + /** + * Removes the specified I/O error listener so that it no longer + * receives I/O error events. + * + * @param l the I/O error listener + * @throws LibvirtException + * + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventDeregi..." + * >virConnectDomainEventDeregisterAny</a> + */ + public void removeLifecycleListener(LifecycleListener l) throws LibvirtException { + domainEventDeregister(DomainEventID.LIFECYCLE, l); + } + /** * Adds the specified reboot listener to receive reboot events for * domains of this connection. diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 010fee0..fb59781 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -14,6 +14,7 @@ import org.libvirt.jna.virDomainMemoryStats; import org.libvirt.jna.virSchedParameter; import org.libvirt.jna.virVcpuInfo; import org.libvirt.event.RebootListener; +import org.libvirt.event.LifecycleListener; import static org.libvirt.Library.libvirt; import static org.libvirt.ErrorHandler.processError; import static org.libvirt.ErrorHandler.processErrorIfZero; @@ -1064,6 +1065,23 @@ public class Domain { } /** + * Adds the specified listener to receive lifecycle events for this domain. + * + * @param l the lifecycle listener + * @throws LibvirtException on failure + * + * @see Connect#addLifecycleListener + * @see Connect#removeLifecycleListener + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventRegist..." + * >virConnectDomainEventRegisterAny</a> + */ + public void addLifecycleListener(final LifecycleListener l) throws LibvirtException + { + virConnect.domainEventRegister(this, l); + } + + /** * Revert the domain to a given snapshot. * * @see <a href= diff --git a/src/main/java/org/libvirt/event/CrashedDetail.java b/src/main/java/org/libvirt/event/CrashedDetail.java new file mode 100644 index 0000000..638a901 --- /dev/null +++ b/src/main/java/org/libvirt/event/CrashedDetail.java @@ -0,0 +1,15 @@ +package org.libvirt.event; + +/** + * Details about a CRASHED domain event + * + * @see DomainEvent + */ +public enum CrashedDetail implements DomainEventDetail { + /** + * Guest was panicked. + */ + PANICKED, + + UNKNOWN +} diff --git a/src/main/java/org/libvirt/event/DefinedDetail.java b/src/main/java/org/libvirt/event/DefinedDetail.java new file mode 100644 index 0000000..f0220f0 --- /dev/null +++ b/src/main/java/org/libvirt/event/DefinedDetail.java @@ -0,0 +1,17 @@ +package org.libvirt.event; + +import org.libvirt.Domain; + +public enum DefinedDetail implements DomainEventDetail { + /** + * Newly created config file. + */ + ADDED, + + /** + * Changed config file. + */ + UPDATED, + + UNKNOWN +} diff --git a/src/main/java/org/libvirt/event/DetailInfo.java b/src/main/java/org/libvirt/event/DetailInfo.java new file mode 100644 index 0000000..c2572b9 --- /dev/null +++ b/src/main/java/org/libvirt/event/DetailInfo.java @@ -0,0 +1,5 @@ +package org.libvirt.event; + +// public interface DetailInfo { +// <T extends Enum<T>> T detail(final DomainEventDetail d); +// } diff --git a/src/main/java/org/libvirt/event/DomainEvent.java b/src/main/java/org/libvirt/event/DomainEvent.java new file mode 100644 index 0000000..21fac60 --- /dev/null +++ b/src/main/java/org/libvirt/event/DomainEvent.java @@ -0,0 +1,71 @@ +package org.libvirt.event; + +/** + * Contains information about a life cycle change of a domain. + * <p> + * This includes the domain event that occurred together with + * further details about that event. + * <p> + * Usage: + * <pre>{@code + * int onLifecycleChange(Domain dom, DomainEvent info) { + * switch (info.getType()) { + * case STARTED: + * StartedDetail detail = info.getDetail(); + * + * switch (detail) { + * case BOOTED: + * ... + * break; + * ... + * } + * } + * } + * }}</pre> + * <p> + * Note, that a ClassCastException will be thrown at runtime when + * assigning to the wrong detail enumeration type: + * <pre>{@code + * DomainEvent info; + * + * if (info.getType() == DomainEventType.STARTED) { + * // info.getDetails() returns a StartedDetail enum + * StoppedDetail detail = info.getDetail(); // throws ClassCastException + * }}</pre> + * + * @see LifecycleListener + * @since 1.5.2 + */ +public final class DomainEvent { + private final DomainEventType type; + private final int detail; + + public DomainEvent(DomainEventType type, int code) { + this.type = type; + this.detail = code; + } + + /** + * Returns the type of event which occurred. + */ + public DomainEventType getType() { + return this.type; + } + + /** + * Returns the corresponding domain event detail in regard to + * the DomainEventType of this instance. + * + * @return a constant of one of the enums implementing the + * {@link DomainEventDetail} interface + */ + public <T extends Enum<T> & DomainEventDetail> T getDetail() { + return this.type.obtain(this.detail); + } + + @Override + public String toString() { + Object d = this.type.safeAt(this.detail); + return this.type + " (" + d + ")"; + } +} diff --git a/src/main/java/org/libvirt/event/DomainEventDetail.java b/src/main/java/org/libvirt/event/DomainEventDetail.java new file mode 100644 index 0000000..59ef5aa --- /dev/null +++ b/src/main/java/org/libvirt/event/DomainEventDetail.java @@ -0,0 +1,7 @@ +package org.libvirt.event; + +/** + * A common interface for all domain event detail enums. + */ +public interface DomainEventDetail { +} diff --git a/src/main/java/org/libvirt/event/DomainEventType.java b/src/main/java/org/libvirt/event/DomainEventType.java new file mode 100644 index 0000000..b675d8b --- /dev/null +++ b/src/main/java/org/libvirt/event/DomainEventType.java @@ -0,0 +1,60 @@ +package org.libvirt.event; + +/** + * Enum constants representing the type of event occurred on + * a domain + */ +public enum DomainEventType { + /** A domain was defined */ + DEFINED(DefinedDetail.values()), + + /** A domain was undefined */ + UNDEFINED(UndefinedDetail.values()), + + /** A domain was started */ + STARTED(StartedDetail.values()), + + /** A domain was suspended */ + SUSPENDED(SuspendedDetail.values()), + + /** A domain was resumed */ + RESUMED(ResumedDetail.values()), + + /** A domain was stopped */ + STOPPED(StoppedDetail.values()), + + /** A domain was shut down */ + SHUTDOWN(ShutdownDetail.values()), + + /** A domain was PM suspended */ + PMSUSPENDED(PMSuspendedDetail.values()), + + /** A domain crashed */ + CRASHED(CrashedDetail.values()), + + /** + * An unknown event occured + * + * This can happen if upstream libvirt adds more event types + * that this library does not yet know about. + */ + UNKNOWN(null); + + private final Object[] details; + + DomainEventType(Object[] d) { + details = d; + } + + @SuppressWarnings("unchecked") + <T extends Enum<T>> T obtain(final int detail) { + return (T)safeAt(detail); + } + + // this method is only necessary for OpenJDK 6 which does not + // compile calls to `obtain(d)` in some circumstances + Object safeAt(final int detail) { + final int index = Math.min(this.details.length - 1, detail); + return this.details[index]; + } +} diff --git a/src/main/java/org/libvirt/event/LifecycleListener.java b/src/main/java/org/libvirt/event/LifecycleListener.java new file mode 100644 index 0000000..78d7419 --- /dev/null +++ b/src/main/java/org/libvirt/event/LifecycleListener.java @@ -0,0 +1,24 @@ +package org.libvirt.event; + +import org.libvirt.Domain; + +/** + * Interface for receiving events occurring on a domain. + * + * @see <a href="http://libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventCallback">virConnectDomainEventCallback</a> + */ +public interface LifecycleListener extends EventListener { + + /** + * This method gets called when a change in the lifecycle + * of a domain occurs. + * + * @param domain the domain on which the event occurred + * @param event contains information about the type of event + * that occurred and details about that event + * + * @return the return value is currently ignored. + */ + int onLifecycleChange(Domain domain, + DomainEvent event); +} diff --git a/src/main/java/org/libvirt/event/PMSuspendedDetail.java b/src/main/java/org/libvirt/event/PMSuspendedDetail.java new file mode 100644 index 0000000..05e5ee0 --- /dev/null +++ b/src/main/java/org/libvirt/event/PMSuspendedDetail.java @@ -0,0 +1,15 @@ +package org.libvirt.event; + +public enum PMSuspendedDetail implements DomainEventDetail { + /** + * Guest was PM suspended to memory. + */ + MEMORY, + + /** + * Guest was PM suspended to disk. + */ + DISK, + + UNKNOWN +} diff --git a/src/main/java/org/libvirt/event/ResumedDetail.java b/src/main/java/org/libvirt/event/ResumedDetail.java new file mode 100644 index 0000000..55bcf4a --- /dev/null +++ b/src/main/java/org/libvirt/event/ResumedDetail.java @@ -0,0 +1,20 @@ +package org.libvirt.event; + +public enum ResumedDetail implements DomainEventDetail { + /** + * Normal resume due to admin unpause. + */ + UNPAUSED, + + /** + * Resumed for completion of migration. + */ + MIGRATED, + + /** + * Resumed from snapshot. + */ + FROM_SNAPSHOT, + + UNKNOWN +} diff --git a/src/main/java/org/libvirt/event/ShutdownDetail.java b/src/main/java/org/libvirt/event/ShutdownDetail.java new file mode 100644 index 0000000..8975831 --- /dev/null +++ b/src/main/java/org/libvirt/event/ShutdownDetail.java @@ -0,0 +1,12 @@ +package org.libvirt.event; + +public enum ShutdownDetail implements DomainEventDetail { + /** + * Guest finished shutdown sequence. + */ + FINISHED, + + UNKNOWN +} + + diff --git a/src/main/java/org/libvirt/event/StartedDetail.java b/src/main/java/org/libvirt/event/StartedDetail.java new file mode 100644 index 0000000..12c52bc --- /dev/null +++ b/src/main/java/org/libvirt/event/StartedDetail.java @@ -0,0 +1,30 @@ +package org.libvirt.event; + +public enum StartedDetail implements DomainEventDetail { + /** + * Normal startup from boot. + */ + BOOTED, + + /** + * Incoming migration from another host. + */ + MIGRATED, + + /** + * Restored from a state file. + */ + RESTORED, + + /** + * Restored from snapshot + */ + FROM_SNAPSHOT, + + /** + * Started due to wakeup event. + */ + WAKEUP, + + UNKNOWN +} diff --git a/src/main/java/org/libvirt/event/StoppedDetail.java b/src/main/java/org/libvirt/event/StoppedDetail.java new file mode 100644 index 0000000..53e25e9 --- /dev/null +++ b/src/main/java/org/libvirt/event/StoppedDetail.java @@ -0,0 +1,40 @@ +package org.libvirt.event; + +public enum StoppedDetail implements DomainEventDetail { + /** + * Normal shutdown. + */ + SHUTDOWN, + + /** + * Forced poweroff from host. + */ + DESTROYED, + + /** + * Guest crashed. + */ + CRASHED, + + /** + * Migrated off to another host. + */ + MIGRATED, + + /** + * Saved to a state file. + */ + SAVED, + + /** + * Host emulator/mgmt failed. + */ + FAILED, + + /** + * Offline snapshot was loaded. + */ + FROM_SNAPSHOT, + + UNKNOWN +} diff --git a/src/main/java/org/libvirt/event/SuspendedDetail.java b/src/main/java/org/libvirt/event/SuspendedDetail.java new file mode 100644 index 0000000..9862052 --- /dev/null +++ b/src/main/java/org/libvirt/event/SuspendedDetail.java @@ -0,0 +1,40 @@ +package org.libvirt.event; + +public enum SuspendedDetail implements DomainEventDetail { + /** + * Normal suspend due to admin pause. + */ + PAUSED, + + /** + * Suspended for offline migration. + */ + MIGRATED, + + /** + * Suspended due to a disk I/O error. + */ + IOERROR, + + /** + * Suspended due to a watchdog firing. + */ + WATCHDOG, + + /** + * Restored from paused state file. + */ + RESTORED, + + /** + * Restored from paused snapshot. + */ + FROM_SNAPSHOT, + + /** + * Suspended after failure during libvirt API call. + */ + API_ERROR, + + UNKNOWN +} diff --git a/src/main/java/org/libvirt/event/UndefinedDetail.java b/src/main/java/org/libvirt/event/UndefinedDetail.java new file mode 100644 index 0000000..ec814f1 --- /dev/null +++ b/src/main/java/org/libvirt/event/UndefinedDetail.java @@ -0,0 +1,7 @@ +package org.libvirt.event; + +public enum UndefinedDetail implements DomainEventDetail { + REMOVED, + + UNKNOWN +} diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 913fe08..5bb9fa0 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -89,6 +89,13 @@ public interface Libvirt extends Library { void eventCallback(ConnectionPointer virConnectPtr, DomainPointer virDomainPointer, Pointer opaque); } + interface VirConnectDomainEventCallback extends VirDomainEventCallback { + int eventCallback(ConnectionPointer virConnectPtr, DomainPointer virDomainPointer, + int event, + int detail, + Pointer opaque); + } + /** * Error callback */ -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:53PM +0100, Claudio Bley wrote:
Add LifecycleListener interface which needs to be implemented when the user wishes to receive lifecycle change events on domains.
The DomainEvent class represents the kind of event that occurred including details on that event.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 66 ++++++++++++++++++ src/main/java/org/libvirt/Domain.java | 18 +++++ src/main/java/org/libvirt/event/CrashedDetail.java | 15 +++++ src/main/java/org/libvirt/event/DefinedDetail.java | 17 +++++ src/main/java/org/libvirt/event/DetailInfo.java | 5 ++ src/main/java/org/libvirt/event/DomainEvent.java | 71 ++++++++++++++++++++ .../java/org/libvirt/event/DomainEventDetail.java | 7 ++ .../java/org/libvirt/event/DomainEventType.java | 60 +++++++++++++++++ .../java/org/libvirt/event/LifecycleListener.java | 24 +++++++ .../java/org/libvirt/event/PMSuspendedDetail.java | 15 +++++ src/main/java/org/libvirt/event/ResumedDetail.java | 20 ++++++ .../java/org/libvirt/event/ShutdownDetail.java | 12 ++++ src/main/java/org/libvirt/event/StartedDetail.java | 30 +++++++++ src/main/java/org/libvirt/event/StoppedDetail.java | 40 +++++++++++ .../java/org/libvirt/event/SuspendedDetail.java | 40 +++++++++++ .../java/org/libvirt/event/UndefinedDetail.java | 7 ++ src/main/java/org/libvirt/jna/Libvirt.java | 7 ++ 17 files changed, 454 insertions(+) create mode 100644 src/main/java/org/libvirt/event/CrashedDetail.java create mode 100644 src/main/java/org/libvirt/event/DefinedDetail.java create mode 100644 src/main/java/org/libvirt/event/DetailInfo.java create mode 100644 src/main/java/org/libvirt/event/DomainEvent.java create mode 100644 src/main/java/org/libvirt/event/DomainEventDetail.java create mode 100644 src/main/java/org/libvirt/event/DomainEventType.java create mode 100644 src/main/java/org/libvirt/event/LifecycleListener.java create mode 100644 src/main/java/org/libvirt/event/PMSuspendedDetail.java create mode 100644 src/main/java/org/libvirt/event/ResumedDetail.java create mode 100644 src/main/java/org/libvirt/event/ShutdownDetail.java create mode 100644 src/main/java/org/libvirt/event/StartedDetail.java create mode 100644 src/main/java/org/libvirt/event/StoppedDetail.java create mode 100644 src/main/java/org/libvirt/event/SuspendedDetail.java create mode 100644 src/main/java/org/libvirt/event/UndefinedDetail.java
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 11:10:22 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:53PM +0100, Claudio Bley wrote:
Add LifecycleListener interface which needs to be implemented when the user wishes to receive lifecycle change events on domains.
The DomainEvent class represents the kind of event that occurred including details on that event.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 66 ++++++++++++++++++ src/main/java/org/libvirt/Domain.java | 18 +++++ src/main/java/org/libvirt/event/CrashedDetail.java | 15 +++++ src/main/java/org/libvirt/event/DefinedDetail.java | 17 +++++ src/main/java/org/libvirt/event/DetailInfo.java | 5 ++ src/main/java/org/libvirt/event/DomainEvent.java | 71 ++++++++++++++++++++ .../java/org/libvirt/event/DomainEventDetail.java | 7 ++ .../java/org/libvirt/event/DomainEventType.java | 60 +++++++++++++++++ .../java/org/libvirt/event/LifecycleListener.java | 24 +++++++ .../java/org/libvirt/event/PMSuspendedDetail.java | 15 +++++ src/main/java/org/libvirt/event/ResumedDetail.java | 20 ++++++ .../java/org/libvirt/event/ShutdownDetail.java | 12 ++++ src/main/java/org/libvirt/event/StartedDetail.java | 30 +++++++++ src/main/java/org/libvirt/event/StoppedDetail.java | 40 +++++++++++ .../java/org/libvirt/event/SuspendedDetail.java | 40 +++++++++++ .../java/org/libvirt/event/UndefinedDetail.java | 7 ++ src/main/java/org/libvirt/jna/Libvirt.java | 7 ++ 17 files changed, 454 insertions(+) create mode 100644 src/main/java/org/libvirt/event/CrashedDetail.java create mode 100644 src/main/java/org/libvirt/event/DefinedDetail.java create mode 100644 src/main/java/org/libvirt/event/DetailInfo.java create mode 100644 src/main/java/org/libvirt/event/DomainEvent.java create mode 100644 src/main/java/org/libvirt/event/DomainEventDetail.java create mode 100644 src/main/java/org/libvirt/event/DomainEventType.java create mode 100644 src/main/java/org/libvirt/event/LifecycleListener.java create mode 100644 src/main/java/org/libvirt/event/PMSuspendedDetail.java create mode 100644 src/main/java/org/libvirt/event/ResumedDetail.java create mode 100644 src/main/java/org/libvirt/event/ShutdownDetail.java create mode 100644 src/main/java/org/libvirt/event/StartedDetail.java create mode 100644 src/main/java/org/libvirt/event/StoppedDetail.java create mode 100644 src/main/java/org/libvirt/event/SuspendedDetail.java create mode 100644 src/main/java/org/libvirt/event/UndefinedDetail.java
ACK
Thanks. I just noticed one minor thing: diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index bbbd000..d82dba2 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java + /** + * Adds the specified listener to receive lifecycle events for + * domains of this connections. s/connections/connection I'll fix that typo before pushing. Claudio

Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/test/java/org/libvirt/TestJavaBindings.java | 69 +++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/src/test/java/org/libvirt/TestJavaBindings.java b/src/test/java/org/libvirt/TestJavaBindings.java index 5cc77e7..a73148f 100644 --- a/src/test/java/org/libvirt/TestJavaBindings.java +++ b/src/test/java/org/libvirt/TestJavaBindings.java @@ -1,5 +1,10 @@ package org.libvirt; +import org.libvirt.event.*; + +import java.util.Arrays; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; import junit.framework.TestCase; @@ -12,6 +17,15 @@ public final class TestJavaBindings extends TestCase { private Connect conn; + static { + // do this once for each JVM instance, before connecting + try { + Library.initEventLoop(); + } catch (LibvirtException e) { + // XXX warn + } + } + protected void setUp() throws LibvirtException { conn = new Connect("test:///default", false); } @@ -237,4 +251,59 @@ public final class TestJavaBindings extends TestCase { assertTrue("pool1 should not be active", pool1.isActive() == 0); assertTrue("Domain2 should be active", defaultPool.isActive() == 1); } + + public void testDomainEvents() throws Exception { + final List<DomainEventType> events = new ArrayList<DomainEventType>(); + final Thread t = new Thread() { + @Override + public void run() { + try { + Library.runEventLoop(); + } catch (LibvirtException e) { + fail("LibvirtException was thrown: " + e); + } catch (InterruptedException e) { + } + } + }; + t.setDaemon(true); + t.start(); + + LifecycleListener listener = new LifecycleListener() { + @Override + public int onLifecycleChange(Domain d, DomainEvent e) + { + events.add(e.getType()); + + return 0; + } + }; + try { + conn.addLifecycleListener(listener); + + Domain dom = conn.domainDefineXML("<domain type='test' id='2'>" + " <name>deftest</name>" + + " <uuid>004b96e1-2d78-c30f-5aa5-f03c87d21e70</uuid>" + " <memory>8388608</memory>" + + " <vcpu>2</vcpu>" + " <os><type arch='i686'>hvm</type></os>" + " <on_reboot>restart</on_reboot>" + + " <on_poweroff>destroy</on_poweroff>" + " <on_crash>restart</on_crash>" + "</domain>"); + + dom.create(); + dom.suspend(); + dom.resume(); + dom.destroy(); + dom.undefine(); + + // wait until (presumably) all events have been processed + Thread.sleep(300); + + assertEquals(Arrays.asList(DomainEventType.DEFINED, + DomainEventType.STARTED, + DomainEventType.SUSPENDED, + DomainEventType.RESUMED, + DomainEventType.STOPPED, + DomainEventType.UNDEFINED), + events); + } finally { + conn.removeLifecycleListener(listener); + Library.stopEventLoop(); + } + } } -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:54PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/test/java/org/libvirt/TestJavaBindings.java | 69 +++++++++++++++++++++++ 1 file changed, 69 insertions(+)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 57 ++++++++++++++++++++ src/main/java/org/libvirt/Domain.java | 20 +++++++ .../java/org/libvirt/event/PMWakeupListener.java | 17 ++++++ .../java/org/libvirt/event/PMWakeupReason.java | 5 ++ src/main/java/org/libvirt/jna/Libvirt.java | 6 +++ 5 files changed, 105 insertions(+) create mode 100644 src/main/java/org/libvirt/event/PMWakeupListener.java create mode 100644 src/main/java/org/libvirt/event/PMWakeupReason.java diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index d82dba2..d18a996 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -530,6 +530,63 @@ public class Connect { domainEventRegister(null, l); } + void domainEventRegister(Domain domain, final PMWakeupListener cb) throws LibvirtException { + if (cb == null) + throw new IllegalArgumentException("PMWakeupCallback cannot be null"); + + Libvirt.VirDomainEventCallback virCB = + new Libvirt.VirConnectDomainEventPMChangeCallback() { + @Override + public void eventCallback(ConnectionPointer virConnectPtr, DomainPointer virDomainPointer, + int reason, Pointer opaque) { + assert VCP.equals(virConnectPtr); + + try { + Domain d = Domain.constructIncRef(Connect.this, virDomainPointer); + cb.onPMWakeup(d, getConstant(PMWakeupReason.class, reason)); + } catch (LibvirtException e) { + throw new RuntimeException("libvirt error handling PMWakeup callback", e); + } + } + }; + + domainEventRegister(domain, DomainEventID.PMWAKEUP, virCB, cb); + } + + /** + * Adds the specified listener to receive PMWakeup events for + * domains of this connection. + * + * @param l the PMWakeup listener + * @throws LibvirtException on failure + * + * @see #removePMWakeupListener + * @see Domain#addPMWakeupListener + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventRegist..." + * >virConnectDomainEventRegisterAny</a> + * + * @since 1.5.2 + */ + public void addPMWakeupListener(final PMWakeupListener l) throws LibvirtException { + domainEventRegister(null, l); + } + + /** + * Removes the specified PMWakeup listener so that it no longer + * receives PMWakeup events. + * + * @param l the PMWakeup listener + * @throws LibvirtException + * + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventDeregi..." + * >virConnectDomainEventDeregisterAny</a> + */ + public void removePMWakeupListener(final PMWakeupListener l) throws LibvirtException { + domainEventDeregister(DomainEventID.PMWAKEUP, l); + } + /** * Removes the specified I/O error listener so that it no longer * receives I/O error events. diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index fb59781..6dda2a6 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -15,6 +15,7 @@ import org.libvirt.jna.virSchedParameter; import org.libvirt.jna.virVcpuInfo; import org.libvirt.event.RebootListener; import org.libvirt.event.LifecycleListener; +import org.libvirt.event.PMWakeupListener; import static org.libvirt.Library.libvirt; import static org.libvirt.ErrorHandler.processError; import static org.libvirt.ErrorHandler.processErrorIfZero; @@ -1082,6 +1083,25 @@ public class Domain { } /** + * Adds the specified listener to receive PMWakeup events for this domain. + * + * @param l the PMWakeup listener + * @throws LibvirtException on failure + * + * @see Connect#removePMWakeupListener + * @see Connect#addPMWakeupListener + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventRegist..." + * >virConnectDomainEventRegisterAny</a> + * + * @since 1.5.2 + */ + public void addPMWakeupListener(final PMWakeupListener l) throws LibvirtException + { + virConnect.domainEventRegister(this, l); + } + + /** * Revert the domain to a given snapshot. * * @see <a href= diff --git a/src/main/java/org/libvirt/event/PMWakeupListener.java b/src/main/java/org/libvirt/event/PMWakeupListener.java new file mode 100644 index 0000000..50d69ef --- /dev/null +++ b/src/main/java/org/libvirt/event/PMWakeupListener.java @@ -0,0 +1,17 @@ +package org.libvirt.event; + +import org.libvirt.Domain; + +/** + * Interface for receiving PMWakeup events on a domain. + */ +public interface PMWakeupListener extends EventListener { + + /** + * This method gets called when a domain is woken up. + * + * @param domain the domain that was woken up + * @param reason the reason why that event happened + */ + void onPMWakeup(Domain domain, PMWakeupReason reason); +} diff --git a/src/main/java/org/libvirt/event/PMWakeupReason.java b/src/main/java/org/libvirt/event/PMWakeupReason.java new file mode 100644 index 0000000..12c37bf --- /dev/null +++ b/src/main/java/org/libvirt/event/PMWakeupReason.java @@ -0,0 +1,5 @@ +package org.libvirt.event; + +public enum PMWakeupReason { + UNKNOWN +} diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 5bb9fa0..1eaeab8 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -96,6 +96,12 @@ public interface Libvirt extends Library { Pointer opaque); } + // PMWakeup and PMSuspend have the same callback interface. + interface VirConnectDomainEventPMChangeCallback extends VirDomainEventCallback { + void eventCallback(ConnectionPointer virConnectPtr, DomainPointer virDomainPointer, + int reason, Pointer opaque); + } + /** * Error callback */ -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:55PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 57 ++++++++++++++++++++ src/main/java/org/libvirt/Domain.java | 20 +++++++ .../java/org/libvirt/event/PMWakeupListener.java | 17 ++++++ .../java/org/libvirt/event/PMWakeupReason.java | 5 ++ src/main/java/org/libvirt/jna/Libvirt.java | 6 +++ 5 files changed, 105 insertions(+) create mode 100644 src/main/java/org/libvirt/event/PMWakeupListener.java create mode 100644 src/main/java/org/libvirt/event/PMWakeupReason.java
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 59 ++++++++++++++++++++ src/main/java/org/libvirt/Domain.java | 20 +++++++ .../java/org/libvirt/event/PMSuspendListener.java | 17 ++++++ .../java/org/libvirt/event/PMSuspendReason.java | 5 ++ 4 files changed, 101 insertions(+) create mode 100644 src/main/java/org/libvirt/event/PMSuspendListener.java create mode 100644 src/main/java/org/libvirt/event/PMSuspendReason.java diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index d18a996..10fc2e8 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -553,6 +553,65 @@ public class Connect { domainEventRegister(domain, DomainEventID.PMWAKEUP, virCB, cb); } + void domainEventRegister(Domain domain, final PMSuspendListener cb) throws LibvirtException { + if (cb == null) + throw new IllegalArgumentException("PMSuspendCallback cannot be null"); + + Libvirt.VirDomainEventCallback virCB = + new Libvirt.VirConnectDomainEventPMChangeCallback() { + @Override + public void eventCallback(ConnectionPointer virConnectPtr, DomainPointer virDomainPointer, + int reason, Pointer opaque) { + assert VCP.equals(virConnectPtr); + + try { + Domain d = Domain.constructIncRef(Connect.this, virDomainPointer); + cb.onPMSuspend(d, getConstant(PMSuspendReason.class, reason)); + } catch (LibvirtException e) { + throw new RuntimeException("libvirt error in PMSuspend callback", e); + } + } + }; + + domainEventRegister(domain, DomainEventID.PMSUSPEND, virCB, cb); + } + + /** + * Adds the specified listener to receive PMSuspend events for + * domains of this connection. + * + * @param l the PMSuspend listener + * @throws LibvirtException on failure + * + * @see #removePMSuspendListener + * @see Domain#addPMSuspendListener + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventRegist..." + * >virConnectDomainEventRegisterAny</a> + * + * @since 1.5.2 + */ + public void addPMSuspendListener(final PMSuspendListener l) throws LibvirtException { + domainEventRegister(null, l); + } + + /** + * Removes the specified PMSuspend listener so that it no longer + * receives PMSuspend events. + * + * @param l the PMSuspend listener + * @throws LibvirtException + * + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventDeregi..." + * >virConnectDomainEventDeregisterAny</a> + * + * @since 1.5.2 + */ + public void removePMSuspendListener(final PMSuspendListener l) throws LibvirtException { + domainEventDeregister(DomainEventID.PMWAKEUP, l); + } + /** * Adds the specified listener to receive PMWakeup events for * domains of this connection. diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 6dda2a6..f3fffdd 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -16,6 +16,7 @@ import org.libvirt.jna.virVcpuInfo; import org.libvirt.event.RebootListener; import org.libvirt.event.LifecycleListener; import org.libvirt.event.PMWakeupListener; +import org.libvirt.event.PMSuspendListener; import static org.libvirt.Library.libvirt; import static org.libvirt.ErrorHandler.processError; import static org.libvirt.ErrorHandler.processErrorIfZero; @@ -1102,6 +1103,25 @@ public class Domain { } /** + * Adds the specified listener to receive PMSuspend events for this domain. + * + * @param l the PMSuspend listener + * @throws LibvirtException on failure + * + * @see Connect#removePMSuspendListener + * @see Connect#addPMSuspendListener + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventRegist..." + * >virConnectDomainEventRegisterAny</a> + * + * @since 1.5.2 + */ + public void addPMSuspendListener(final PMSuspendListener l) throws LibvirtException + { + virConnect.domainEventRegister(this, l); + } + + /** * Revert the domain to a given snapshot. * * @see <a href= diff --git a/src/main/java/org/libvirt/event/PMSuspendListener.java b/src/main/java/org/libvirt/event/PMSuspendListener.java new file mode 100644 index 0000000..ec111e1 --- /dev/null +++ b/src/main/java/org/libvirt/event/PMSuspendListener.java @@ -0,0 +1,17 @@ +package org.libvirt.event; + +import org.libvirt.Domain; + +/** + * Interface for receiving PMSuspend events on a domain. + */ +public interface PMSuspendListener extends EventListener { + + /** + * This method gets called when a domain is suspended. + * + * @param domain the domain that was suspended + * @param reason the reason why that event happened + */ + void onPMSuspend(Domain domain, PMSuspendReason reason); +} diff --git a/src/main/java/org/libvirt/event/PMSuspendReason.java b/src/main/java/org/libvirt/event/PMSuspendReason.java new file mode 100644 index 0000000..58f06a1 --- /dev/null +++ b/src/main/java/org/libvirt/event/PMSuspendReason.java @@ -0,0 +1,5 @@ +package org.libvirt.event; + +public enum PMSuspendReason { + UNKNOWN +} -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:56PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 59 ++++++++++++++++++++ src/main/java/org/libvirt/Domain.java | 20 +++++++ .../java/org/libvirt/event/PMSuspendListener.java | 17 ++++++ .../java/org/libvirt/event/PMSuspendReason.java | 5 ++ 4 files changed, 101 insertions(+) create mode 100644 src/main/java/org/libvirt/event/PMSuspendListener.java create mode 100644 src/main/java/org/libvirt/event/PMSuspendReason.java
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

There can only be a single connection close listener registered per connection object. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 57 ++++++++++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 11 ++++++ 2 files changed, 68 insertions(+) diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index 10fc2e8..f597826 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -46,6 +46,22 @@ public class Connect { return new HashMap[size]; } + private class CloseFunc implements Libvirt.VirConnectCloseFunc { + final ConnectionCloseListener listener; + + CloseFunc(ConnectionCloseListener l) { + this.listener = l; + } + + @Override + public void callback(ConnectionPointer VCP, int reason, Pointer opaque) { + this.listener.onClose(Connect.this, + getConstant(ConnectionCloseReason.class, reason)); + } + } + + private CloseFunc registeredCloseFunc = null; + /** * Event IDs. */ @@ -267,6 +283,11 @@ public class Connect { int success = 0; if (VCP != null) { success = libvirt.virConnectClose(VCP); + + // if the connection has been closed (i.e. the reference count is + // down to zero), forget about the registered close function + if (success == 0) registeredCloseFunc = null; + // If leave an invalid pointer dangling around JVM crashes and burns // if someone tries to call a method on us // We rely on the underlying libvirt error handling to detect that @@ -277,6 +298,42 @@ public class Connect { } /** + * Register the specified connection close listener to receive notifications + * when this connection is closed. + * <p> + * <strong>Note:</strong> There can only be at most one registered listener + * at a time. + * @param l the connection close listener + * @throws LibvirtException on failure + * @see #unregisterCloseListener + */ + public void registerCloseListener(final ConnectionCloseListener l) throws LibvirtException { + CloseFunc cf = new CloseFunc(l); + + processError(libvirt.virConnectRegisterCloseCallback(this.VCP, + cf, + null, + null)); + this.registeredCloseFunc = cf; + } + + /** + * Unregister the previously registered close listener. + * + * When there currently is no registered close listener, this method + * does nothing. + * + * @see #registerCloseListener + */ + public void unregisterCloseListener() throws LibvirtException { + if (this.registeredCloseFunc != null) { + processError(libvirt.virConnectUnregisterCloseCallback(this.VCP, + this.registeredCloseFunc)); + this.registeredCloseFunc = null; + } + } + + /** * Compares the given CPU description with the host CPU * * @see <a diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 1eaeab8..e4b2cfb 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -65,6 +65,13 @@ public interface Libvirt extends Library { } /** + * Callback interface for connection closed events. + */ + interface VirConnectCloseFunc extends Callback { + void callback(ConnectionPointer VCP, int reason, Pointer opaque); + } + + /** * Domain Event Callbacks */ @@ -162,6 +169,10 @@ public interface Libvirt extends Library { // Register Domain Event Callbacks int virConnectDomainEventRegisterAny(ConnectionPointer virConnectPtr, DomainPointer virDomainPtr, int eventID, VirDomainEventCallback cb, Pointer opaque, Libvirt.VirFreeCallback freecb); + int virConnectRegisterCloseCallback(ConnectionPointer virConnectPtr, VirConnectCloseFunc cb, + Pointer opaque, Pointer freeOpaque); + int virConnectUnregisterCloseCallback(ConnectionPointer virConnectPtr, VirConnectCloseFunc cb); + int virConnectDomainEventDeregisterAny(ConnectionPointer virConnectPtr, int callbackID) ; void virConnSetErrorFunc(ConnectionPointer virConnectPtr, Pointer userData, VirErrorCallback callback); int virConnectIsAlive(ConnectionPointer virConnectPtr); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:57PM +0100, Claudio Bley wrote:
There can only be a single connection close listener registered per connection object.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 57 ++++++++++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 11 ++++++ 2 files changed, 68 insertions(+)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

This wraps the virConnectGetSysinfo function available since libvirt version 0.8.8. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 21 +++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + 2 files changed, 22 insertions(+) diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index f597826..8659076 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -969,6 +969,27 @@ public class Connect { } /** + * Returns the XML description of the sysinfo details for the host + * on which the hypervisor is running. + * <p> + * This information is generally available only for hypervisors + * running with root privileges. + * + * @return sysinfo details in the same format as the {@code + * <sysinfo>} element of a domain XML. + * @since 1.5.2 + */ + public String getSysinfo() throws LibvirtException { + Pointer p = processError(libvirt.virConnectGetSysinfo(this.VCP, 0)); + + try { + return Library.getString(p); + } finally { + Library.free(p); + } + } + + /** * Gets the name of the Hypervisor software used. * * @return the name diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index e4b2cfb..3bd63e1 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -183,6 +183,7 @@ public interface Libvirt extends Library { Pointer virConnectGetHostname(ConnectionPointer virConnectPtr); int virConnectGetLibVersion(ConnectionPointer virConnectPtr, LongByReference libVer); int virConnectGetMaxVcpus(ConnectionPointer virConnectPtr, String type); + Pointer virConnectGetSysinfo(ConnectionPointer virConnectPtr, int flags); String virConnectGetType(ConnectionPointer virConnectPtr); String virConnectGetURI(ConnectionPointer virConnectPtr); int virConnectGetVersion(ConnectionPointer virConnectPtr, LongByReference hvVer); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:58PM +0100, Claudio Bley wrote:
This wraps the virConnectGetSysinfo function available since libvirt version 0.8.8.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 21 +++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + 2 files changed, 22 insertions(+)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

This wraps the virDomainBlockPeek libvirt function, available since version 0.4.5. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 53 ++++++++++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 4 +++ 2 files changed, 57 insertions(+) diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index f3fffdd..f57460f 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -1,5 +1,7 @@ package org.libvirt; +import java.nio.ByteBuffer; + import org.libvirt.event.IOErrorListener; import org.libvirt.jna.DomainPointer; import org.libvirt.jna.DomainSnapshotPointer; @@ -280,6 +282,57 @@ public class Domain { } /** + * Read the contents of a domain's disk device. + * <p> + * Typical uses for this are to determine if the domain has + * written a Master Boot Record (indicating that the domain has + * completed installation), or to try to work out the state of the + * domain's filesystems. + * <p> + * (Note that in the local case you might try to open the block + * device or file directly, but that won't work in the remote + * case, nor if you don't have sufficient permission. Hence the + * need for this call). + * <p> + * The disk parameter can either be an unambiguous source name of + * the block device (the {@code <source file='...'/>} sub-element, + * such as "/path/to/image"), or <em>(since 0.9.5)</em> the device + * target shorthand (the {@code <target dev='...'/>} sub-element, + * such as "xvda"). + * <p> + * Valid names can be found by calling {@link #getXMLDesc} and + * inspecting elements within {@code //domain/devices/disk}. + * <p> + * This method always reads the number of bytes remaining in the + * buffer, that is, {@code buffer.remaining()} at the moment this + * method is invoked. Upon return the buffer's position will be + * equal to the limit, the limit itself will not have changed. + * + * @param disk the path to the block device, or device shorthand + * @param offset the offset within block device + * @param buffer the buffer receiving the data + */ + public void blockPeek(String disk, long offset, ByteBuffer buffer) throws LibvirtException { + SizeT size = new SizeT(); + + // older libvirt has a limitation on the size of data + // transferred per request in the remote driver. So, split + // larger requests into 64K blocks. + + do { + final int req = Math.min(65536, buffer.remaining()); + + size.setValue(req); + + processError(libvirt.virDomainBlockPeek(this.VDP, disk, offset, size, buffer, 0)); + + buffer.position(buffer.position() + req); + } while (buffer.hasRemaining()); + + assert buffer.position() == buffer.limit(); + } + + /** * 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 * calling virDomainGetXMLDesc and finding the <target dev='...'> attribute diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 3bd63e1..0452246 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -1,5 +1,7 @@ package org.libvirt.jna; +import java.nio.ByteBuffer; + import com.sun.jna.Callback; import com.sun.jna.Library; import com.sun.jna.Native; @@ -243,6 +245,8 @@ public interface Libvirt extends Library { int virDomainAbortJob(DomainPointer virDomainPtr); int virDomainAttachDevice(DomainPointer virDomainPtr, String deviceXML); int virDomainAttachDeviceFlags(DomainPointer virDomainPtr, String deviceXML, int flags); + int virDomainBlockPeek(DomainPointer virDomainPtr, String disk, long offset, SizeT size, + ByteBuffer buffer, int flags); int virDomainBlockStats(DomainPointer virDomainPtr, String path, virDomainBlockStats stats, SizeT size); int virDomainBlockResize(DomainPointer virDomainPtr, String disk, long size, int flags); int virDomainCoreDump(DomainPointer virDomainPtr, String to, int flags); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:22:59PM +0100, Claudio Bley wrote:
This wraps the virDomainBlockPeek libvirt function, available since version 0.4.5.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 53 ++++++++++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 4 +++ 2 files changed, 57 insertions(+)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

This wraps the virDomainMemoryPeek libvirt function, available since version 0.4.5. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 40 ++++++++++++++++++++++ src/main/java/org/libvirt/MemoryAddressMode.java | 19 ++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 5 +-- 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/libvirt/MemoryAddressMode.java diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index f57460f..5f0d1d0 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -826,6 +826,46 @@ public class Domain { } /** + * Read the contents of a domain's memory. + * <p> + * If mode is MemoryAddressMode.VIRTUAL the 'start' parameter is + * interpreted as virtual memory address for whichever task + * happens to be running on the domain at the moment. Although + * this sounds haphazard it is in fact what you want in order to + * read Linux kernel state, because it ensures that pointers in + * the kernel image can be interpreted coherently. + * <p> + * This method always reads the number of bytes remaining in the + * buffer, that is, {@code buffer.remaining()} at the moment this + * method is invoked. Upon return the buffer's position will be + * equal to the limit, the limit itself will not have changed. + * + * @param start the start address of the memory to peek + * @param mode the mode which determines whether the given addresses + * are interpreted as virtual or physical addresses + */ + public void memoryPeek(long start, ByteBuffer buffer, MemoryAddressMode mode) throws LibvirtException + { + SizeT size = new SizeT(); + + // older libvirt has a limitation on the size of data + // transferred per request in the remote driver. So, split + // larger requests into 64K blocks. + + do { + final int req = Math.min(65536, buffer.remaining()); + + size.setValue(req); + + processError(libvirt.virDomainMemoryPeek(this.VDP, start, size, buffer, mode.getValue())); + + buffer.position(buffer.position() + req); + } while (buffer.hasRemaining()); + + assert buffer.position() == buffer.limit(); + } + + /** * This function provides memory statistics for the domain. * * @param number diff --git a/src/main/java/org/libvirt/MemoryAddressMode.java b/src/main/java/org/libvirt/MemoryAddressMode.java new file mode 100644 index 0000000..c16edea --- /dev/null +++ b/src/main/java/org/libvirt/MemoryAddressMode.java @@ -0,0 +1,19 @@ +package org.libvirt; + +public enum MemoryAddressMode { + /** addresses are virtual addresses */ + VIRTUAL(1), + + /** addresses are physical addresses */ + PHYSICAL(2); + + private final int value; + + MemoryAddressMode(int v) { + this.value = v; + } + + int getValue() { + return value; + } +} diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 0452246..28fbff1 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -22,10 +22,6 @@ import com.sun.jna.ptr.PointerByReference; * virConnCopyLastError * virFreeError * - * LIBVIRT_0.4.2 - * virDomainBlockPeek - * virDomainMemoryPeek - * * LIBVIRT_0_5.0 * virEventRegisterImpl * virConnectDomainEventRegister @@ -286,6 +282,7 @@ public interface Libvirt extends Library { DomainPointer virDomainLookupByUUIDString(ConnectionPointer virConnectPtr, String uuidstr); int virDomainManagedSave(DomainPointer virDomainPtr, int flags); int virDomainManagedSaveRemove(DomainPointer virDomainPtr, int flags); + int virDomainMemoryPeek(DomainPointer virDomainPtr, long start, SizeT size, ByteBuffer buffer, int flags); DomainPointer virDomainMigrate(DomainPointer virDomainPtr, ConnectionPointer virConnectPtr, NativeLong flags, String dname, String uri, NativeLong bandwidth); DomainPointer virDomainMigrate2(DomainPointer virDomainPtr, ConnectionPointer virConnectPtr, -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:23:00PM +0100, Claudio Bley wrote:
This wraps the virDomainMemoryPeek libvirt function, available since version 0.4.5.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 40 ++++++++++++++++++++++ src/main/java/org/libvirt/MemoryAddressMode.java | 19 ++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 5 +-- 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/libvirt/MemoryAddressMode.java
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

This wraps the virSecretGetUsageType libvirt function available since version 0.7.1. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Secret.java | 5 +++++ src/main/java/org/libvirt/SecretUsageType.java | 23 +++++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + 3 files changed, 29 insertions(+) create mode 100644 src/main/java/org/libvirt/SecretUsageType.java diff --git a/src/main/java/org/libvirt/Secret.java b/src/main/java/org/libvirt/Secret.java index 868fcc8..e0ded73 100644 --- a/src/main/java/org/libvirt/Secret.java +++ b/src/main/java/org/libvirt/Secret.java @@ -64,6 +64,11 @@ public class Secret { return processError(libvirt.virSecretGetUsageID(VSP)); } + public SecretUsageType getUsageType() throws LibvirtException { + final int ret = processError(libvirt.virSecretGetUsageType(this.VSP)); + return Library.getConstant(SecretUsageType.class, ret); + } + /** * Get the UUID for this secret. * diff --git a/src/main/java/org/libvirt/SecretUsageType.java b/src/main/java/org/libvirt/SecretUsageType.java new file mode 100644 index 0000000..3907bdb --- /dev/null +++ b/src/main/java/org/libvirt/SecretUsageType.java @@ -0,0 +1,23 @@ +package org.libvirt; + +/** + * An enumeration of constants identifying the type of + * the owner of a secret. + * + * @see Secret#getUsageType + */ +public enum SecretUsageType { + /** No one uses the secret */ + NONE, + + /** A volume uses the secret */ + VOLUME, + + /** A CEPH object uses the secret */ + CEPH, + + /** A ISCSI object uses the secret */ + ISCSI, + + UNKNOWN +} diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 28fbff1..21ee2c2 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -416,6 +416,7 @@ public interface Libvirt extends Library { int virSecretGetUUID(SecretPointer virSecretPtr, byte[] uuidString); int virSecretGetUUIDString(SecretPointer virSecretPtr, byte[] uuidString); String virSecretGetUsageID(SecretPointer virSecretPtr); + int virSecretGetUsageType(SecretPointer virSecretPtr); Pointer virSecretGetValue(SecretPointer virSecretPtr, SizeTByReference value_size, int flags); String virSecretGetXMLDesc(SecretPointer virSecretPtr, int flags); SecretPointer virSecretLookupByUsage(ConnectionPointer virConnectPtr, int usageType, String usageID); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:23:01PM +0100, Claudio Bley wrote:
This wraps the virSecretGetUsageType libvirt function available since version 0.7.1.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Secret.java | 5 +++++ src/main/java/org/libvirt/SecretUsageType.java | 23 +++++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + 3 files changed, 29 insertions(+) create mode 100644 src/main/java/org/libvirt/SecretUsageType.java
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

This wraps the virDomainIsUpdated libvirt function available since version 0.8.6. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 8 ++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + 2 files changed, 9 insertions(+) diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 5f0d1d0..fae95fe 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -799,6 +799,14 @@ public class Domain { return processError(libvirt.virDomainIsPersistent(VDP)); } + + /** + * Returns {@code true} if, and only if, this domain has been updated. + */ + public boolean isUpdated() throws LibvirtException { + return processError(libvirt.virDomainIsUpdated(this.VDP)) == 1; + } + /** * suspend a domain and save its memory contents to a file on disk. * diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 21ee2c2..2c75018 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -276,6 +276,7 @@ public interface Libvirt extends Library { int virDomainInterfaceStats(DomainPointer virDomainPtr, String path, virDomainInterfaceStats stats, SizeT size); int virDomainIsActive(DomainPointer virDomainPtr); int virDomainIsPersistent(DomainPointer virDomainPtr); + int virDomainIsUpdated(DomainPointer virDomainPtr); DomainPointer virDomainLookupByID(ConnectionPointer virConnectPtr, int id); DomainPointer virDomainLookupByName(ConnectionPointer virConnectPtr, String name); DomainPointer virDomainLookupByUUID(ConnectionPointer virConnectPtr, byte[] uuidBytes); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:23:02PM +0100, Claudio Bley wrote:
This wraps the virDomainIsUpdated libvirt function available since version 0.8.6.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 8 ++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + 2 files changed, 9 insertions(+)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

This wraps the virDomainReset libvirt function available since version 0.9.7. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 7 +++++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + 2 files changed, 8 insertions(+) diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index fae95fe..89bc659 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -1223,6 +1223,13 @@ public class Domain { } /** + * Reset a domain immediately without any guest OS shutdown. + */ + public void reset() throws LibvirtException { + processError(libvirt.virDomainReset(this.VDP, 0)); + } + + /** * Revert the domain to a given snapshot. * * @see <a href= diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 2c75018..7183d5b 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -297,6 +297,7 @@ public interface Libvirt extends Library { int virDomainPinVcpu(DomainPointer virDomainPtr, int vcpu, byte[] cpumap, int maplen); int virDomainReboot(DomainPointer virDomainPtr, int flags); int virDomainRef(DomainPointer virDomainPtr); + int virDomainReset(DomainPointer virDomainPtr, int flags); int virDomainRestore(ConnectionPointer virConnectPtr, String from); int virDomainRevertToSnapshot(DomainSnapshotPointer virDomainSnapshotPtr, int flags); int virDomainResume(DomainPointer virDomainPtr); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:23:03PM +0100, Claudio Bley wrote:
This wraps the virDomainReset libvirt function available since version 0.9.7.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 7 +++++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + 2 files changed, 8 insertions(+)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

This wraps the virDomainPMWakeup libvirt function available since version 0.9.11. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 27 ++++++++++++++++++++++++++ src/main/java/org/libvirt/SuspendTarget.java | 15 ++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 2 ++ 3 files changed, 44 insertions(+) create mode 100644 src/main/java/org/libvirt/SuspendTarget.java diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 89bc659..e0dba46 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -1,6 +1,7 @@ package org.libvirt; import java.nio.ByteBuffer; +import java.util.concurrent.TimeUnit; import org.libvirt.event.IOErrorListener; import org.libvirt.jna.DomainPointer; @@ -1091,6 +1092,32 @@ public class Domain { } /** + * Enter the given power management suspension target level. + */ + public void PMsuspend(SuspendTarget target) throws LibvirtException { + PMsuspendFor(target, 0, TimeUnit.SECONDS); + } + + /** + * Enter the given power management suspension target level for the given duration. + */ + public void PMsuspendFor(SuspendTarget target, long duration, TimeUnit unit) throws LibvirtException { + processError(libvirt.virDomainPMSuspendForDuration(this.VDP, target.ordinal(), unit.toSeconds(duration), 0)); + } + + /** + * Immediately wake up a guest using power management. + * <p> + * Injects a <em>wakeup<em> into the guest that previously used + * {@link #PMsuspend} or {@link #PMsuspendFor}, rather than + * waiting for the previously requested duration (if any) to + * elapse. + */ + public void PMwakeup() throws LibvirtException { + processError(libvirt.virDomainPMWakeup(this.VDP, 0)); + } + + /** * Dynamically changes the real CPUs which can be allocated to a virtual * CPU. This function requires priviledged access to the hypervisor. * diff --git a/src/main/java/org/libvirt/SuspendTarget.java b/src/main/java/org/libvirt/SuspendTarget.java new file mode 100644 index 0000000..456c980 --- /dev/null +++ b/src/main/java/org/libvirt/SuspendTarget.java @@ -0,0 +1,15 @@ +package org.libvirt; + +/** + * Power management suspension target levels + */ +public enum SuspendTarget { + /** Suspend-to-RAM */ + MEMORY, + + /** Suspend-to-Disk */ + DISK, + + /** Hybrid-Suspend */ + HYBRID; +} diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 7183d5b..a6d3b1d 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -295,6 +295,8 @@ public interface Libvirt extends Library { String dxml, NativeLong flags, String dname, NativeLong bandwidth); int virDomainMemoryStats(DomainPointer virDomainPtr, virDomainMemoryStats[] stats, int nr_stats, int flags); int virDomainPinVcpu(DomainPointer virDomainPtr, int vcpu, byte[] cpumap, int maplen); + int virDomainPMSuspendForDuration(DomainPointer virDomainPtr, int target, long duration, int flags); + int virDomainPMWakeup(DomainPointer virDomainPtr, int flags); int virDomainReboot(DomainPointer virDomainPtr, int flags); int virDomainRef(DomainPointer virDomainPtr); int virDomainReset(DomainPointer virDomainPtr, int flags); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:23:04PM +0100, Claudio Bley wrote:
This wraps the virDomainPMWakeup libvirt function available since version 0.9.11.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 27 ++++++++++++++++++++++++++ src/main/java/org/libvirt/SuspendTarget.java | 15 ++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 2 ++ 3 files changed, 44 insertions(+) create mode 100644 src/main/java/org/libvirt/SuspendTarget.java
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

This wraps the virDomainSendKey libvirt function available since version 0.9.3. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 12 ++++++++ src/main/java/org/libvirt/KeycodeSet.java | 46 ++++++++++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + 3 files changed, 59 insertions(+) create mode 100644 src/main/java/org/libvirt/KeycodeSet.java diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index e0dba46..1c0af91 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -1352,6 +1352,18 @@ public class Domain { } /** + * Send key(s) to the guest. + * + * @param codeset the set of keycodes + * @param holdtime the duration that the keys will be held (in milliseconds) + * @param keys the key codes to be send + */ + public void sendKey(KeycodeSet codeset, int holdtime, int... keys) throws LibvirtException { + processError(libvirt.virDomainSendKey(this.VDP, codeset.ordinal(), + holdtime, keys, keys.length, 0)); + } + + /** * Shuts down this domain, the domain object is still usable there after but * the domain OS is being stopped. Note that the guest OS may ignore the * request. TODO: should we add an option for reboot, knowing it may not be diff --git a/src/main/java/org/libvirt/KeycodeSet.java b/src/main/java/org/libvirt/KeycodeSet.java new file mode 100644 index 0000000..132e508 --- /dev/null +++ b/src/main/java/org/libvirt/KeycodeSet.java @@ -0,0 +1,46 @@ +package org.libvirt; + +/** + */ +public enum KeycodeSet { + /** + * Linux key code set. + * <p> + * Defined in the linux/input.h header, this set of key codes is able + * to represent any scan code from any type of keyboard. + */ + LINUX, + + /** IBM XT keyboard code set */ + XT, + + /** AT set 1 key codes */ + ATSET1, + + /** AT set 2 key codes */ + ATSET2, + + /** AT set 3 key codes */ + ATSET3, + + /** Apple OS-X virtual key codes */ + OSX, + + /** */ + XT_KBD, + + /** Key code set as defined by the USB HID specification */ + USB, + + /** + * Microsoft Windows virtual key code set + * <p> + * Reference: <a target='blank' + * href='http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).as...' + * >MSDN Virtual-Key Codes</a>. + */ + WIN32, + + /** Key code set as used by GTK-VNC and QEMU */ + RFB; +} diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index a6d3b1d..c8735d2 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -304,6 +304,7 @@ public interface Libvirt extends Library { int virDomainRevertToSnapshot(DomainSnapshotPointer virDomainSnapshotPtr, int flags); int virDomainResume(DomainPointer virDomainPtr); int virDomainSave(DomainPointer virDomainPtr, String to); + int virDomainSendKey(DomainPointer virDomainPtr, int codeset, int holdtime, int[] keycodes, int nkeycodes, int flags); int virDomainSetAutostart(DomainPointer virDomainPtr, int autoStart); int virDomainSetMaxMemory(DomainPointer virDomainPtr, NativeLong maxMemory); int virDomainSetMemory(DomainPointer virDomainPtr, NativeLong maxMemory); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:23:05PM +0100, Claudio Bley wrote:
This wraps the virDomainSendKey libvirt function available since version 0.9.3.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 12 ++++++++ src/main/java/org/libvirt/KeycodeSet.java | 46 ++++++++++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + 3 files changed, 59 insertions(+) create mode 100644 src/main/java/org/libvirt/KeycodeSet.java
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

This makes the Stream class a native citizen of the Java API. It can be used with the NIO Channel API, as well as (In,Out)putStream's using the java.nio.channels.Channels convenience wrappers. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Stream.java | 183 ++++++++++++++++++++++++++-- src/main/java/org/libvirt/jna/Libvirt.java | 4 +- 2 files changed, 178 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/libvirt/Stream.java b/src/main/java/org/libvirt/Stream.java index c36ed70..71a2a6e 100644 --- a/src/main/java/org/libvirt/Stream.java +++ b/src/main/java/org/libvirt/Stream.java @@ -1,12 +1,46 @@ package org.libvirt; +import java.io.IOException; + +import java.nio.ByteBuffer; +import java.nio.channels.ByteChannel; +import java.nio.channels.ClosedChannelException; +import java.nio.channels.NonReadableChannelException; +import java.nio.channels.NonWritableChannelException; + import org.libvirt.jna.Libvirt; import org.libvirt.jna.SizeT; import org.libvirt.jna.StreamPointer; import static org.libvirt.Library.libvirt; import static org.libvirt.ErrorHandler.processError; -public class Stream { +/** + * The Stream class is used to transfer data between a libvirt daemon + * and a client. + * <p> + * It implements the ByteChannel interface. + * <p> + * Basic usage: + * + * <pre> + * {@code + * ByteBuffer buf = ByteBuffer.allocate(1024); + * Stream str = conn.streamNew(0); + * + * ... // open the stream e.g. calling Domain.screenshot + * + * while (str.read(buf) != -1) { + * buf.flip(); + * ... // do something with the data + * buf.compact(); + * }}</pre> + * <p> + * If you want to use this class as an InputStream or OutputStream, + * convert it using the {@link java.nio.channels.Channels#newInputStream + * Channels.newInputStream} and {@link java.nio.channels.Channels#newOutputStream + * Channels.newOutputStream} respectively. + */ +public class Stream implements ByteChannel { public static int VIR_STREAM_NONBLOCK = (1 << 0); @@ -20,6 +54,56 @@ public class Stream { */ private Connect virConnect; + private final static int CLOSED = 0; + private final static int READABLE = 1; + private final static int WRITABLE = 2; + private final static int OPEN = READABLE | WRITABLE; + private final static int EOF = 4; + + /* The status of the stream. A stream starts its live in the + * "CLOSED" state. + * + * It will be opened for input / output by another libvirt + * operation (e.g. virStorageVolDownload), which means it will + * be in state "READABLE" or "WRITABLE", exclusively. + * + * It will reach state "EOF", if {@link finish()} is called. + * + * It will be in the "CLOSED" state again, after calling abort() + * or close(). + */ + private int state = CLOSED; + + void markReadable() { + assert !isWritable() + : "A Stream cannot be readable and writable at the same time"; + + state |= READABLE; + } + + void markWritable() { + assert !isReadable() + : "A Stream cannot be readable and writable at the same time"; + + state |= WRITABLE; + } + + boolean isReadable() { + return (state & READABLE) != 0; + } + + boolean isWritable() { + return (state & WRITABLE) != 0; + } + + protected boolean isEOF() { + return (state & EOF) != 0; + } + + private void markEOF() { + state |= EOF; + } + Stream(Connect virConnect, StreamPointer VSP) { this.virConnect = virConnect; this.VSP = VSP; @@ -32,7 +116,9 @@ public class Stream { * @return <em>ignore</em> (always 0) */ public int abort() throws LibvirtException { - return processError(libvirt.virStreamAbort(VSP)); + int returnValue = processError(libvirt.virStreamAbort(VSP)); + this.state = CLOSED; + return returnValue; } /** @@ -66,7 +152,9 @@ public class Stream { * @throws LibvirtException */ public int finish() throws LibvirtException { - return processError(libvirt.virStreamFinish(VSP)); + int returnValue = processError(libvirt.virStreamFinish(VSP)); + markEOF(); + return returnValue; } /** @@ -79,7 +167,8 @@ public class Stream { public int free() throws LibvirtException { int success = 0; if (VSP != null) { - processError(libvirt.virStreamFree(VSP)); + closeStream(); + success = processError(libvirt.virStreamFree(VSP)); VSP = null; } @@ -95,7 +184,80 @@ public class Stream { * @throws LibvirtException */ public int receive(byte[] data) throws LibvirtException { - return processError(libvirt.virStreamRecv(VSP, data, new SizeT(data.length))); + return receive(ByteBuffer.wrap(data)); + } + + protected int receive(ByteBuffer buffer) throws LibvirtException { + int returnValue = processError(libvirt.virStreamRecv(VSP, buffer, new SizeT(buffer.remaining()))); + buffer.position(buffer.position() + returnValue); + return returnValue; + } + + @Override + public int read(ByteBuffer buffer) throws IOException { + if (!isOpen()) throw new ClosedChannelException(); + if (!isReadable()) throw new NonReadableChannelException(); + if (isEOF()) return -1; + + try { + int ret = receive(buffer); + + switch (ret) { + case 0: + finish(); + return -1; + + case -2: + throw new UnsupportedOperationException("non-blocking I/O stream not yet supported"); + + default: + return ret; + } + } catch (LibvirtException e) { + throw new IOException("could not read from stream", e); + } + } + + @Override + public int write(ByteBuffer buffer) throws IOException { + if (!isOpen()) throw new ClosedChannelException(); + if (!isWritable()) throw new NonWritableChannelException(); + + int pos = buffer.position(); + + try { + while (buffer.hasRemaining()) { + int ret = send(buffer); + + if (ret == -2) + throw new UnsupportedOperationException("non-blocking I/O stream not yet supported"); + } + return buffer.position() - pos; + } catch (LibvirtException e) { + throw new IOException("could not write to stream", e); + } + } + + protected void closeStream() throws LibvirtException { + if (isOpen() && !isEOF()) { + if (isWritable()) finish(); + else if (isReadable()) abort(); + } + this.state = CLOSED; + } + + @Override + public void close() throws IOException { + try { + closeStream(); + } catch (LibvirtException e) { + throw new IOException("error while closing Stream", e); + } + } + + @Override + public boolean isOpen() { + return (this.state & OPEN) != 0; } /** @@ -131,8 +293,15 @@ public class Stream { * full * @throws LibvirtException */ - public int send(String data) throws LibvirtException { - return processError(libvirt.virStreamSend(VSP, data, new SizeT(data.length()))); + public int send(byte[] data) throws LibvirtException { + return send(ByteBuffer.wrap(data)); + } + + protected int send(ByteBuffer buffer) throws LibvirtException { + SizeT size = new SizeT(buffer.remaining()); + int returnValue = processError(libvirt.virStreamSend(VSP, buffer, size)); + buffer.position(buffer.position() + returnValue); + return returnValue; } /** diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index c8735d2..c383ba6 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -440,9 +440,9 @@ public interface Libvirt extends Library { int virStreamFinish(StreamPointer virStreamPtr) ; int virStreamFree(StreamPointer virStreamPtr) ; StreamPointer virStreamNew(ConnectionPointer virConnectPtr, int flags) ; - int virStreamSend(StreamPointer virStreamPtr, String data, SizeT size); + int virStreamSend(StreamPointer virStreamPtr, ByteBuffer data, SizeT size); int virStreamSendAll(StreamPointer virStreamPtr, Libvirt.VirStreamSourceFunc handler, Pointer opaque); - int virStreamRecv(StreamPointer virStreamPtr, byte[] data, SizeT length); + int virStreamRecv(StreamPointer virStreamPtr, ByteBuffer data, SizeT length); int virStreamRecvAll(StreamPointer virStreamPtr, Libvirt.VirStreamSinkFunc handler, Pointer opaque); //DomainSnapshot Methods -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:23:06PM +0100, Claudio Bley wrote:
This makes the Stream class a native citizen of the Java API.
It can be used with the NIO Channel API, as well as (In,Out)putStream's using the java.nio.channels.Channels convenience wrappers.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Stream.java | 183 ++++++++++++++++++++++++++-- src/main/java/org/libvirt/jna/Libvirt.java | 4 +- 2 files changed, 178 insertions(+), 9 deletions(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

This wraps the native virDomainScreenshot libvirt function available since version 0.9.2. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 10 ++++++++++ src/main/java/org/libvirt/Stream.java | 4 ++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + 3 files changed, 15 insertions(+) diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 1c0af91..a9113cf 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -1285,6 +1285,16 @@ public class Domain { processError(libvirt.virDomainSave(VDP, to)); } + public String screenshot(Stream stream, int screen) throws LibvirtException { + Pointer ptr = processError(libvirt.virDomainScreenshot(this.VDP, stream.getVSP(), screen, 0)); + stream.markReadable(); + try { + return Library.getString(ptr); + } finally { + Library.free(ptr); + } + } + /** * Configures the network to be automatically started when the host machine * boots. diff --git a/src/main/java/org/libvirt/Stream.java b/src/main/java/org/libvirt/Stream.java index 71a2a6e..97bebdd 100644 --- a/src/main/java/org/libvirt/Stream.java +++ b/src/main/java/org/libvirt/Stream.java @@ -175,6 +175,10 @@ public class Stream implements ByteChannel { return success; } + StreamPointer getVSP() { + return VSP; + } + /** * Receives data from the stream into the buffer provided. * diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index c383ba6..80dacdb 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -305,6 +305,7 @@ public interface Libvirt extends Library { int virDomainResume(DomainPointer virDomainPtr); int virDomainSave(DomainPointer virDomainPtr, String to); int virDomainSendKey(DomainPointer virDomainPtr, int codeset, int holdtime, int[] keycodes, int nkeycodes, int flags); + Pointer virDomainScreenshot(DomainPointer virDomainPtr, StreamPointer virStreamPtr, int screen, int flags); int virDomainSetAutostart(DomainPointer virDomainPtr, int autoStart); int virDomainSetMaxMemory(DomainPointer virDomainPtr, NativeLong maxMemory); int virDomainSetMemory(DomainPointer virDomainPtr, NativeLong maxMemory); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:23:07PM +0100, Claudio Bley wrote:
This wraps the native virDomainScreenshot libvirt function available since version 0.9.2.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Domain.java | 10 ++++++++++ src/main/java/org/libvirt/Stream.java | 4 ++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + 3 files changed, 15 insertions(+)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/test/java/org/libvirt/TestJavaBindings.java | 44 +++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/test/java/org/libvirt/TestJavaBindings.java b/src/test/java/org/libvirt/TestJavaBindings.java index a73148f..24d850a 100644 --- a/src/test/java/org/libvirt/TestJavaBindings.java +++ b/src/test/java/org/libvirt/TestJavaBindings.java @@ -2,6 +2,9 @@ package org.libvirt; import org.libvirt.event.*; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.ClosedChannelException; import java.util.Arrays; import java.util.ArrayList; import java.util.List; @@ -306,4 +309,45 @@ public final class TestJavaBindings extends TestCase { Library.stopEventLoop(); } } + + public void testDomainScreenshot() throws Exception { + long version = conn.getLibVirVersion(); + + // virDomainScreenshot works since version 1.0.5 on test:// + // connections + if (version < 1000005) { + System.err.format("testDomainScreenshot skipped (libvirt version %d.%d.%d < 1.0.5)\n", + version / 1000000, version / 1000 % 1000, version % 1000); + return; + } + + Stream str = this.conn.streamNew(0); + Domain dom = this.conn.domainLookupByName("test"); + + assertFalse("Domain \"test\" not found", dom == null); + + String mimetype = dom.screenshot(str, 0); + + ByteBuffer bb = ByteBuffer.allocateDirect(8192); + + while (str.read(bb) != -1) // consume data + bb.clear(); + + // ensure that read() repeatedly returns -1 after EOF + + assertEquals("Stream is at EOF (1)", -1, str.read(bb)); + assertEquals("Stream is at EOF (2)", -1, str.read(bb)); + assertEquals("Stream is at EOF (3)", -1, str.read(bb)); + + // ensure that a ClosedChannelException gets thrown when + // trying to read() after closing the stream + + str.close(); + + try { + str.read(bb); + fail("ClosedChannelException expected calling read() on a closed stream"); + } catch (ClosedChannelException expected) { + } + } } -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:23:08PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/test/java/org/libvirt/TestJavaBindings.java | 44 +++++++++++++++++++++++ 1 file changed, 44 insertions(+)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/BitFlags.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main/java/org/libvirt/BitFlags.java diff --git a/src/main/java/org/libvirt/BitFlags.java b/src/main/java/org/libvirt/BitFlags.java new file mode 100644 index 0000000..f078c6c --- /dev/null +++ b/src/main/java/org/libvirt/BitFlags.java @@ -0,0 +1,18 @@ +package org.libvirt; + +public interface BitFlags { + int getBit(); +} + +final class BitFlagsHelper { + // bitwise-OR + static int OR(BitFlags[] flags) { + int ret = 0; + for (BitFlags f: flags) { + ret |= f.getBit(); + } + return ret; + } + + final static BitFlags[] NONE = {}; +} -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:23:09PM +0100, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/BitFlags.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main/java/org/libvirt/BitFlags.java
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Additionally, add an OpenFlags enum to the Connect classes which implements the BitFlags interface. This should be used when creating a read-only connection or to prevent using URI aliases. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 104 +++++++++++++++++++++++++------- 1 file changed, 82 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index 8659076..4ab61b3 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -1,5 +1,6 @@ package org.libvirt; +import java.net.URI; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -24,6 +25,7 @@ import static org.libvirt.Library.libvirt; import static org.libvirt.Library.getConstant; import static org.libvirt.ErrorHandler.processError; import static org.libvirt.ErrorHandler.processErrorIfZero; +import static org.libvirt.BitFlagsHelper.OR; import com.sun.jna.Memory; import com.sun.jna.NativeLong; @@ -82,6 +84,24 @@ public class Connect { static final int LAST = 13; } + public enum OpenFlags implements BitFlags { + /** Open a connection in read-only mode */ + READONLY(1), + + /** Don't try to resolve URI aliases */ + NO_ALIASES(2); + + OpenFlags(int v) { + this.value = v; + } + + @Override + public int getBit() { + return value; + } + private final int value; + } + /** * Get the version of a connection. * @@ -202,9 +222,20 @@ public class Connect { * @see <a href="http://libvirt.org/uri.html">The URI documentation</a> */ public Connect(String uri) throws LibvirtException { - VCP = libvirt.virConnectOpen(uri); - // Check for an error - processError(VCP); + this(uri, null, 0); + } + + + /** + * Constructs a read-write Connect object from the supplied URI. + * + * @param uri + * The connection URI + * @throws LibvirtException + * @see <a href="http://libvirt.org/uri.html">The URI documentation</a> + */ + public Connect(URI uri, OpenFlags... flags) throws LibvirtException { + this(uri, null, flags); } /** @@ -218,13 +249,7 @@ public class Connect { * @see <a href="http://libvirt.org/uri.html">The URI documentation</a> */ public Connect(String uri, boolean readOnly) throws LibvirtException { - if (readOnly) { - VCP = libvirt.virConnectOpenReadOnly(uri); - } else { - VCP = libvirt.virConnectOpen(uri); - } - // Check for an error - processError(VCP); + this(uri, null, readOnly ? OpenFlags.READONLY.getBit() : 0); } /** @@ -240,26 +265,61 @@ public class Connect { * @see <a href="http://libvirt.org/uri.html">The URI documentation</a> */ public Connect(String uri, ConnectAuth auth, int flags) throws LibvirtException { - virConnectAuth vAuth = new virConnectAuth(); - vAuth.cb = auth; - vAuth.cbdata = null; - vAuth.ncredtype = auth.credType.length; - int[] authInts = new int[vAuth.ncredtype]; - - for (int x = 0; x < vAuth.ncredtype; x++) { - authInts[x] = auth.credType[x].mapToInt(); + virConnectAuth vAuth = null; + + if (auth != null) { + vAuth = new virConnectAuth(); + vAuth.cb = auth; + vAuth.cbdata = null; + vAuth.ncredtype = auth.credType.length; + int[] authInts = new int[vAuth.ncredtype]; + + for (int x = 0; x < vAuth.ncredtype; x++) { + authInts[x] = auth.credType[x].mapToInt(); + } + + Memory mem = new Memory(4 * vAuth.ncredtype); + mem.write(0, authInts, 0, vAuth.ncredtype); + vAuth.credtype = mem.share(0); } - Memory mem = new Memory(4 * vAuth.ncredtype); - mem.write(0, authInts, 0, vAuth.ncredtype); - vAuth.credtype = mem.share(0); - VCP = libvirt.virConnectOpenAuth(uri, vAuth, flags); // Check for an error processError(VCP); } /** + * Constructs a Connect object from the supplied URI, using the supplied + * authentication callback + * + * @param uri + * The connection URI + * @param auth + * a ConnectAuth object + * @param flags + * @throws LibvirtException + * @see <a href="http://libvirt.org/uri.html">The URI documentation</a> + */ + public Connect(URI uri, ConnectAuth auth, OpenFlags... flags) throws LibvirtException { + this(uri.toString(), auth, OR(flags)); + } + + /** + * Constructs a Connect object from the supplied URI, using the supplied + * authentication callback + * + * @param uri + * The connection URI + * @param auth + * a ConnectAuth object + * @throws LibvirtException + * @see <a href="http://libvirt.org/uri.html">The URI documentation</a> + */ + public Connect(URI uri, ConnectAuth auth) throws LibvirtException { + this(uri.toString(), auth, 0); + } + + /** * Computes the most feature-rich CPU which is compatible with all given * host CPUs. * -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:23:10PM +0100, Claudio Bley wrote:
Additionally, add an OpenFlags enum to the Connect classes which implements the BitFlags interface.
This should be used when creating a read-only connection or to prevent using URI aliases.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 104 +++++++++++++++++++++++++------- 1 file changed, 82 insertions(+), 22 deletions(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

It should not be necessary to create a Connect object in order to determine the version of the libvirt library. Introduce Library.getVersion which returns this information. Deprecate Connect.getLibVirVersion but keep it for backwards compat. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 5 +++-- src/main/java/org/libvirt/Library.java | 15 ++++++++++++++- src/test/java/org/libvirt/TestJavaBindings.java | 3 +-- src/test/java/org/libvirt/TestLibvirtGlobals.java | 4 ++++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index 4ab61b3..72f60f1 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -1007,11 +1007,12 @@ public class Connect { * * @return major * 1,000,000 + minor * 1,000 + release * @throws LibvirtException + * @deprecated use {@link Library#getVersion} instead */ + @Deprecated public long getLibVirVersion() throws LibvirtException { LongByReference libVer = new LongByReference(); - LongByReference typeVer = new LongByReference(); - processError(libvirt.virGetVersion(libVer, null, typeVer)); + processError(libvirt.virGetVersion(libVer, null, null)); return libVer.getValue(); } diff --git a/src/main/java/org/libvirt/Library.java b/src/main/java/org/libvirt/Library.java index 81df223..992e29d 100644 --- a/src/main/java/org/libvirt/Library.java +++ b/src/main/java/org/libvirt/Library.java @@ -5,6 +5,7 @@ import static org.libvirt.ErrorHandler.processError; import com.sun.jna.Native; import com.sun.jna.Pointer; +import com.sun.jna.ptr.LongByReference; import com.sun.jna.ptr.PointerByReference; import java.util.concurrent.atomic.AtomicBoolean; @@ -18,7 +19,7 @@ import java.util.concurrent.atomic.AtomicBoolean; * Additionally, this class contains internal methods to ease * implementing the public API. */ -final class Library { +public final class Library { private static AtomicBoolean runLoop = new AtomicBoolean(); final static Libvirt libvirt; @@ -40,6 +41,18 @@ final class Library { private Library() {} /** + * Returns the version of the native libvirt library. + * + * @return major * 1,000,000 + minor * 1,000 + release + * @throws LibvirtException + */ + public static long getVersion() throws LibvirtException { + LongByReference libVer = new LongByReference(); + processError(libvirt.virGetVersion(libVer, null, null)); + return libVer.getValue(); + } + + /** * Free memory pointed to by ptr. */ static void free(Pointer ptr) { diff --git a/src/test/java/org/libvirt/TestJavaBindings.java b/src/test/java/org/libvirt/TestJavaBindings.java index 24d850a..86a1f53 100644 --- a/src/test/java/org/libvirt/TestJavaBindings.java +++ b/src/test/java/org/libvirt/TestJavaBindings.java @@ -56,7 +56,6 @@ public final class TestJavaBindings extends TestCase { assertEquals("conn.getMaxVcpus(xen)", 32, conn.getMaxVcpus("xen")); assertNotNull("conn.getHostName()", conn.getHostName()); assertNotNull("conn.getCapabilities()", conn.getCapabilities()); - assertTrue("conn.getLibVirVersion()", conn.getLibVirVersion() > 6000); assertTrue("conn.connectionVersion()", Connect.connectionVersion(conn) > 6000); assertEquals("conn.getVersion()", 2, conn.getVersion()); assertTrue("conn.isAlive", conn.isAlive()); @@ -311,7 +310,7 @@ public final class TestJavaBindings extends TestCase { } public void testDomainScreenshot() throws Exception { - long version = conn.getLibVirVersion(); + long version = Library.getVersion(); // virDomainScreenshot works since version 1.0.5 on test:// // connections diff --git a/src/test/java/org/libvirt/TestLibvirtGlobals.java b/src/test/java/org/libvirt/TestLibvirtGlobals.java index b2b0d9f..ab36fb9 100644 --- a/src/test/java/org/libvirt/TestLibvirtGlobals.java +++ b/src/test/java/org/libvirt/TestLibvirtGlobals.java @@ -18,4 +18,8 @@ public class TestLibvirtGlobals extends TestCase { } assertTrue("We should have caught an error", cb.error); } + + public void testLibrary() throws Exception { + assertTrue("Library.getVersion() > 6000", Library.getVersion() > 6000); + } } -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:23:11PM +0100, Claudio Bley wrote:
It should not be necessary to create a Connect object in order to determine the version of the libvirt library.
Introduce Library.getVersion which returns this information.
Deprecate Connect.getLibVirVersion but keep it for backwards compat.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 5 +++-- src/main/java/org/libvirt/Library.java | 15 ++++++++++++++- src/test/java/org/libvirt/TestJavaBindings.java | 3 +-- src/test/java/org/libvirt/TestLibvirtGlobals.java | 4 ++++ 4 files changed, 22 insertions(+), 5 deletions(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Since the libvirt version information is a property of an *instance* of a connnection, the method to retrieve this information should not be static. Deprecate its use and recommend using aConnect.getLibVersion instead. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 18 ++++++++++++++++++ src/test/java/org/libvirt/TestJavaBindings.java | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index 72f60f1..e909b29 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -112,7 +112,9 @@ public class Connect { * the connection to use. * @return -1 in case of failure, versions have the format major * 1,000,000 * + minor * 1,000 + release. + * @deprecated Use {@link #getLibVersion} instead. */ + @Deprecated public static long connectionVersion(Connect conn) { LongByReference libVer = new LongByReference(); int result = Libvirt.INSTANCE.virConnectGetLibVersion(conn.VCP, libVer); @@ -144,6 +146,22 @@ public class Connect { } /** + * Get the libvirt library version of this connection. + * + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectGetLibVersion">Libvirt + * Documentation</a> + * @return The version of libvirt used by the daemon running on + * the connected host in the format {@code major * + * 1,000,000 + minor * 1,000 + release}. + */ + public long getLibVersion() throws LibvirtException { + LongByReference libVer = new LongByReference(); + processError(libvirt.virConnectGetLibVersion(this.VCP, libVer)); + return libVer.getValue(); + } + + /** * Sets the error function to a user defined callback * * @param callback diff --git a/src/test/java/org/libvirt/TestJavaBindings.java b/src/test/java/org/libvirt/TestJavaBindings.java index 86a1f53..c8674ad 100644 --- a/src/test/java/org/libvirt/TestJavaBindings.java +++ b/src/test/java/org/libvirt/TestJavaBindings.java @@ -56,7 +56,7 @@ public final class TestJavaBindings extends TestCase { assertEquals("conn.getMaxVcpus(xen)", 32, conn.getMaxVcpus("xen")); assertNotNull("conn.getHostName()", conn.getHostName()); assertNotNull("conn.getCapabilities()", conn.getCapabilities()); - assertTrue("conn.connectionVersion()", Connect.connectionVersion(conn) > 6000); + assertTrue("conn.getLibVersion() > 6000", conn.getLibVersion() > 6000); assertEquals("conn.getVersion()", 2, conn.getVersion()); assertTrue("conn.isAlive", conn.isAlive()); assertTrue("conn.isEncrypted", conn.isEncrypted() == 0); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:23:12PM +0100, Claudio Bley wrote:
Since the libvirt version information is a property of an *instance* of a connnection, the method to retrieve this information should not be static.
Deprecate its use and recommend using aConnect.getLibVersion instead.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 18 ++++++++++++++++++ src/test/java/org/libvirt/TestJavaBindings.java | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

In libvirt 0.9.3 this has been changed to simply return the libvirt version number. Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index e909b29..a88abc1 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -1005,13 +1005,18 @@ public class Connect { /** * Returns the version of the hypervisor against which the library was - * compiled. The type parameter specified which hypervisor's version is - * returned + * compiled. * - * @param type + * Since libvirt 0.9.3 this simply returns the same version number + * as {@link Library#getVersion}. + * @param type The type of connection/driver to look at. See + * {@link #getType()}. May be {@code null}. * @return major * 1,000,000 + minor * 1,000 + release * @throws LibvirtException + * @deprecated To get the version of the running hypervisor use + * {@link #getVersion()} instead. */ + @Deprecated public long getHypervisorVersion(String type) throws LibvirtException { LongByReference libVer = new LongByReference(); LongByReference typeVer = new LongByReference(); -- 1.7.9.5

On Thu, Feb 13, 2014 at 04:23:13PM +0100, Claudio Bley wrote:
In libvirt 0.9.3 this has been changed to simply return the libvirt version number.
Signed-off-by: Claudio Bley <cbley@av-test.de> --- src/main/java/org/libvirt/Connect.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Thu, Feb 13, 2014 at 04:22:08PM +0100, Claudio Bley wrote:
Hi.
Here are a few patches that piled up in my local branch. Some of them I already submitted to this list, but there has been no reponse to them.
Included are a few trivial fixes as well as memory leak fixes and additions to the public API.
There had been some minor interest in my first version of domain event support in the Java wrapper[1], which I have reworked almost entirely.
If nobody objects, say, within the next two weeks or so, I'll go ahead and push the whole series as was suggested to me by Daniel P. Berrange on this list[2].
I've made sure that all JUnit tests pass after every commit with JNA versions 3.4.1, 3.4.2, 3.5.0, 3.5.1, 3.5.2 and 4.0.0.
I'd really appreciate your comments or suggestions.
I've ACK'd all of the patches except for the one about virFree and a couple related to hashCode/equals implementation. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 11:19:23 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:08PM +0100, Claudio Bley wrote:
Hi.
Here are a few patches that piled up in my local branch. Some of them I already submitted to this list, but there has been no reponse to them.
Included are a few trivial fixes as well as memory leak fixes and additions to the public API.
There had been some minor interest in my first version of domain event support in the Java wrapper[1], which I have reworked almost entirely.
If nobody objects, say, within the next two weeks or so, I'll go ahead and push the whole series as was suggested to me by Daniel P. Berrange on this list[2].
I've made sure that all JUnit tests pass after every commit with JNA versions 3.4.1, 3.4.2, 3.5.0, 3.5.1, 3.5.2 and 4.0.0.
I'd really appreciate your comments or suggestions.
I've ACK'd all of the patches except for the one about virFree and a couple related to hashCode/equals implementation.
Thank you! I'm just about clocking out now and will be on vacation until the first week of march. So, I'll push after I've returned and managed to read through my pile of emails. Claudio

At Fri, 21 Feb 2014 11:19:23 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:08PM +0100, Claudio Bley wrote:
Hi.
Here are a few patches that piled up in my local branch. Some of them I already submitted to this list, but there has been no reponse to them.
Included are a few trivial fixes as well as memory leak fixes and additions to the public API.
There had been some minor interest in my first version of domain event support in the Java wrapper[1], which I have reworked almost entirely.
If nobody objects, say, within the next two weeks or so, I'll go ahead and push the whole series as was suggested to me by Daniel P. Berrange on this list[2].
I've made sure that all JUnit tests pass after every commit with JNA versions 3.4.1, 3.4.2, 3.5.0, 3.5.1, 3.5.2 and 4.0.0.
I'd really appreciate your comments or suggestions.
I've ACK'd all of the patches except for the one about virFree and a couple related to hashCode/equals implementation.
Without further ado, since I have addressed your complains I pushed the remaining patches a couple of seconds ago (except the virFree patch). Additionally, since my email address changed I've also pushed this patch under the trivial rule: ------- >8 ------------------ 8< --------------- 8< ------------------
From 0b6f6e970c7e8dc666bf6084b80268077d09fa04 Mon Sep 17 00:00:00 2001 From: Claudio Bley <cbley@av-test.de> Date: Fri, 31 Oct 2014 22:59:10 +0100 Subject: [java] [PATCH] Update my Email address
--- AUTHORS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 07809bf..6ea5092 100644 --- a/AUTHORS +++ b/AUTHORS @@ -3,7 +3,7 @@ Initial code base from Tóth István <stoty@tvnet.hu> Primary maintainer: -Claudio Bley <cbley@av-test.de> +Claudio Bley <claudio.bley@gmail.com> Patches provided by: -- 2.1.3 --

On Sat, Nov 01, 2014 at 10:40:06PM +0100, Claudio Bley wrote:
At Fri, 21 Feb 2014 11:19:23 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:08PM +0100, Claudio Bley wrote:
Hi.
Here are a few patches that piled up in my local branch. Some of them I already submitted to this list, but there has been no reponse to them.
Included are a few trivial fixes as well as memory leak fixes and additions to the public API.
There had been some minor interest in my first version of domain event support in the Java wrapper[1], which I have reworked almost entirely.
If nobody objects, say, within the next two weeks or so, I'll go ahead and push the whole series as was suggested to me by Daniel P. Berrange on this list[2].
I've made sure that all JUnit tests pass after every commit with JNA versions 3.4.1, 3.4.2, 3.5.0, 3.5.1, 3.5.2 and 4.0.0.
I'd really appreciate your comments or suggestions.
I've ACK'd all of the patches except for the one about virFree and a couple related to hashCode/equals implementation.
Without further ado, since I have addressed your complains I pushed the remaining patches a couple of seconds ago (except the virFree patch).
Additionally, since my email address changed I've also pushed this patch under the trivial rule:
------- >8 ------------------ 8< --------------- 8< ------------------
From 0b6f6e970c7e8dc666bf6084b80268077d09fa04 Mon Sep 17 00:00:00 2001 From: Claudio Bley <cbley@av-test.de> Date: Fri, 31 Oct 2014 22:59:10 +0100 Subject: [java] [PATCH] Update my Email address
--- AUTHORS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/AUTHORS b/AUTHORS index 07809bf..6ea5092 100644 --- a/AUTHORS +++ b/AUTHORS @@ -3,7 +3,7 @@ Initial code base from Tóth István <stoty@tvnet.hu>
Primary maintainer:
-Claudio Bley <cbley@av-test.de> +Claudio Bley <claudio.bley@gmail.com>
Sounds good, thanks for all the improvements you've done on the Java work Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Thu, Feb 13, 2014 at 04:22:08PM +0100, Claudio Bley wrote:
Hi.
Here are a few patches that piled up in my local branch. Some of them I already submitted to this list, but there has been no reponse to them.
Included are a few trivial fixes as well as memory leak fixes and additions to the public API.
There had been some minor interest in my first version of domain event support in the Java wrapper[1], which I have reworked almost entirely.
If nobody objects, say, within the next two weeks or so, I'll go ahead and push the whole series as was suggested to me by Daniel P. Berrange on this list[2].
BTW, when you push these patches, you should also update AUTHORS to list yourself as the primary maintainer of the binding, similar to how we list maintainers in the main libvirt AUTHORS file. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

At Fri, 21 Feb 2014 11:21:17 +0000, Daniel P. Berrange wrote:
On Thu, Feb 13, 2014 at 04:22:08PM +0100, Claudio Bley wrote:
Hi.
Here are a few patches that piled up in my local branch. Some of them I already submitted to this list, but there has been no reponse to them.
Included are a few trivial fixes as well as memory leak fixes and additions to the public API.
There had been some minor interest in my first version of domain event support in the Java wrapper[1], which I have reworked almost entirely.
If nobody objects, say, within the next two weeks or so, I'll go ahead and push the whole series as was suggested to me by Daniel P. Berrange on this list[2].
BTW, when you push these patches, you should also update AUTHORS to list yourself as the primary maintainer of the binding, similar to how we list maintainers in the main libvirt AUTHORS file.
Sure thing. I've pushed this a couple of minutes ago under the trivial rule: ---------------------------------------------------------------------- commit c04d0aef148e9f89b08a4ccbfc17b17e2e4c8caf Author: Claudio Bley <cbley@av-test.de> Date: Wed Mar 26 10:50:41 2014 +0100 Take over libvirt-java as the primary maintainer diff --git a/AUTHORS b/AUTHORS index 8404152..07809bf 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,6 +1,10 @@ Packaging Daniel Veillard <veillard@redhat.com> Initial code base from Tóth István <stoty@tvnet.hu> +Primary maintainer: + +Claudio Bley <cbley@av-test.de> + Patches provided by: Daniel Schwager <Daniel.Schwager@dtnet.de> @@ -11,5 +15,4 @@ Luis Carlos Moreira da Costa <tcljava@gmail.com> Andrea Sansottera <andrea.sansottera@gmail.com> Stefan Majer <stefan.majer@gmail.com> Wido den Hollander <wido@widodh.nl> -Claudio Bley <cbley@av-test.de> Eric Blake <eblake@redhat.com> ---------------------------------------------------------------------- Regards, Claudio
participants (6)
-
Claudio Bley
-
Claudio Bley
-
Daniel P. Berrange
-
Eric Blake
-
Guido Günther
-
Jim Fehlig