2010/11/14 Andrea Turli <andrea.turli(a)eng.it>:
I'm trying to connect to vbox hypervisor on an Ubuntu 10.04
machine
through libvirt java binding (libvirt-java-0.4.6) by simply invoking:
Connect conn = new Connect("vbox:///session", false);
but I got this exception:
libvir: warning : Failed to find the interface: Is the daemon running ?
libvir: Remote error : unable to connect to
'/var/run/libvirt/libvirt-sock': Connection refused
libvir: warning : Failed to find a node driver: Is the libvirtd daemon running ?
libvir: Remote error : unable to connect to
'/var/run/libvirt/libvirt-sock': Connection refused
libvir: warning : Failed to find a secret storage driver: Is the
daemon running ?
org.libvirt.LibvirtException: Failed to find a secret storage driver:
Is the daemon running ?
at org.libvirt.ErrorHandler.processError(ErrorHandler.java:28)
at org.libvirt.Connect.<init>(Connect.java:195)
at VBOX.main(VBOX.java:32)
This is a bit tricky and took me a moment to understand.
libvirt's error handling can report warnings. This feature is not used
often in libvirt, basically only in the virConnectOpen* functions to
report missing subdrivers.
The Java bindings now have two problems:
1) The error processing in the bindings is done unconditional, it
always checks for an error even if the called function succeeded. Also
this results in an unnecessary call to the JNA interface for each
successful libvirt call.
2) The error processing raises an exception for all error, even for
errors with level VIR_ERR_WARNING.
This results in the exception you see. The call to virConnectOpen
succeeds but libvirt reports a warning about missing sudrivers and the
bindings turn this into an exception.
You can apply this workaround to the Java bindings code:
diff --git a/src/main/java/org/libvirt/ErrorHandler.java
b/src/main/java/org/libvirt/ErrorHandler.java
index e30291b..de66518 100644
--- a/src/main/java/org/libvirt/ErrorHandler.java
+++ b/src/main/java/org/libvirt/ErrorHandler.java
@@ -25,7 +25,11 @@ public class ErrorHandler {
if (errorCode > 0) {
Error error = new Error(vError);
libvirt.virResetLastError();
- throw new LibvirtException(error);
+
+ /* FIXME: Don't throw exceptions for VIR_ERR_WARNING
level errors */
+ if (error.getLevel() == Error.ErrorLevel.VIR_ERR_ERROR) {
+ throw new LibvirtException(error);
+ }
}
}
}
The actually fix is more involved as it includes making the error
processing conditional.
Matthias