[libvirt] [PATCH 0/4] qemu: support live change of all netdev hostside config
by Laine Stump
This patch series resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=805071
It enhances virDomainUpdateDeviceFlags for network devices to allow
live change of just about everything that doesn't affect what hardware
is presented to the guest (e.g. the device model, mac address, PCI
address, and other PCI attributes can't be changed, but the
type/details of the connection to the host network can be changed,
including bandwidth, type of tap device, vlan setting, nwfilter).
I haven't tested the new code yet beyond compiling, but wanted to get
the patches up on the list since the weekend is coming. I'll be
testing this morning and hopefully won't encounter any major problems.
12 years, 1 month
[libvirt] [PATCH] Properly parse (unsigned) long long
by Guido Günther
This fixes problems on platforms where sizeof(long) != sizeof(long long)
like ia32.
---
Cheers,
-- Guido
python/generator.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/python/generator.py b/python/generator.py
index a98a894..1ef76e1 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -259,8 +259,8 @@ py_types = {
'double': ('d', None, "double", "double"),
'unsigned int': ('i', None, "int", "int"),
'unsigned long': ('l', None, "long", "long"),
- 'long long': ('l', None, "longlong", "long long"),
- 'unsigned long long': ('l', None, "longlong", "long long"),
+ 'long long': ('L', None, "longlong", "long long"),
+ 'unsigned long long': ('K', None, "longlong", "long long"),
'unsigned char *': ('z', None, "charPtr", "char *"),
'char *': ('z', None, "charPtr", "char *"),
'const char *': ('z', None, "constcharPtr", "const char *"),
--
1.7.10.4
12 years, 1 month
[libvirt] [PATCH] spec: Add support for libssh2 transport
by Peter Krempa
Libssh2 transport support was enabled lately but the spec file wasn't
updated to take this into account. This caused libvirt to be built
without libssh2 support in Red Hat based OSes.
---
I'm not sure how the {?rhel} >= 6 macro is evaluated:
Is there a possibility to be more specific with the version?
libvirt.spec.in | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/libvirt.spec.in b/libvirt.spec.in
index 318fe92..75623eb 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -108,6 +108,7 @@
%define with_systemd 0%{!?_without_systemd:0}
%define with_numad 0%{!?_without_numad:0}
%define with_firewalld 0%{!?_without_firewalld:0}
+%define with_libssh2_transport 0%{!?_without_libssh2_transport:0}
# Non-server/HV driver defaults which are always enabled
%define with_python 0%{!?_without_python:1}
@@ -229,6 +230,11 @@
%endif
%endif
+# Enable libssh2 transport for new enough distros
+%if 0%{?fedora} >= 17 || 0%{?rhel} >= 6
+%define with_libssh2_transport 0%{!?_without_libssh2_transport:1}
+%endif
+
# Disable some drivers when building without libvirt daemon.
# The logic is the same as in configure.ac
%if ! %{with_libvirtd}
@@ -491,9 +497,13 @@ BuildRequires: numactl-devel
%if %{with_capng}
BuildRequires: libcap-ng-devel >= 0.5.0
%endif
-%if %{with_phyp}
+%if %{with_phyp} || %{with_libssh2_transport}
+%if %{with_libssh2_transport}
+BuildRequires: libssh2-devel >= 1.3.0
+%else
BuildRequires: libssh2-devel
%endif
+%endif
%if %{with_netcf}
%if 0%{?fedora} >= 18 || 0%{?rhel} >= 7
--
1.7.12.3
12 years, 1 month
[libvirt] [PATCH] selinux: Use raw contexts
by Martin Kletzander
We are currently able to work only with non-translated SELinux
contexts, but we are using functions that work with translated
contexts throughout the code. This patch swaps all SELinux context
translation relative calls with their raw sisters to avoid parsing
problems.
The problems can be experienced with mcstrans for example.
Thanks Laurent Bigonville for finding this out.
---
configure.ac | 4 ++--
src/security/security_selinux.c | 26 +++++++++++++-------------
src/storage/storage_backend.c | 2 +-
tests/securityselinuxhelper.c | 6 +++---
tests/securityselinuxtest.c | 2 +-
5 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/configure.ac b/configure.ac
index bcdea9c..08dc63d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1440,14 +1440,14 @@ if test "$with_selinux" != "no"; then
old_libs="$LIBS"
if test "$with_selinux" = "check"; then
AC_CHECK_HEADER([selinux/selinux.h],[],[with_selinux=no])
- AC_CHECK_LIB([selinux], [fgetfilecon],[],[with_selinux=no])
+ AC_CHECK_LIB([selinux], [fgetfilecon_raw],[],[with_selinux=no])
if test "$with_selinux" != "no"; then
with_selinux="yes"
fi
else
fail=0
AC_CHECK_HEADER([selinux/selinux.h],[],[fail=1])
- AC_CHECK_LIB([selinux], [fgetfilecon],[],[fail=1])
+ AC_CHECK_LIB([selinux], [fgetfilecon_raw],[],[fail=1])
test $fail = 1 &&
AC_MSG_ERROR([You must install the libselinux development package in order to compile libvirt with basic SELinux support])
fi
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index d55c60d..10135ed 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -111,7 +111,7 @@ virSecuritySELinuxMCSFind(virSecurityManagerPtr mgr)
char *sens, *cat, *tmp;
int catMin, catMax, catRange;
- if (getcon(&ourSecContext) < 0) {
+ if (getcon_raw(&ourSecContext) < 0) {
virReportSystemError(errno, "%s",
_("Unable to get current process SELinux context"));
goto cleanup;
@@ -252,7 +252,7 @@ virSecuritySELinuxGenNewContext(const char *basecontext,
VIR_DEBUG("basecontext=%s mcs=%s isObjectContext=%d",
basecontext, mcs, isObjectContext);
- if (getcon(&ourSecContext) < 0) {
+ if (getcon_raw(&ourSecContext) < 0) {
virReportSystemError(errno, "%s",
_("Unable to get current process SELinux context"));
goto cleanup;
@@ -612,7 +612,7 @@ virSecuritySELinuxReserveSecurityLabel(virSecurityManagerPtr mgr,
if (seclabel->type == VIR_DOMAIN_SECLABEL_STATIC)
return 0;
- if (getpidcon(pid, &pctx) == -1) {
+ if (getpidcon_raw(pid, &pctx) == -1) {
virReportSystemError(errno,
_("unable to get PID %d security context"), pid);
return -1;
@@ -713,7 +713,7 @@ virSecuritySELinuxGetSecurityProcessLabel(virSecurityManagerPtr mgr ATTRIBUTE_UN
{
security_context_t ctx;
- if (getpidcon(pid, &ctx) == -1) {
+ if (getpidcon_raw(pid, &ctx) == -1) {
virReportSystemError(errno,
_("unable to get PID %d security context"),
pid);
@@ -753,10 +753,10 @@ virSecuritySELinuxSetFileconHelper(const char *path, char *tcon, bool optional)
VIR_INFO("Setting SELinux context on '%s' to '%s'", path, tcon);
- if (setfilecon(path, tcon) < 0) {
+ if (setfilecon_raw(path, tcon) < 0) {
int setfilecon_errno = errno;
- if (getfilecon(path, &econ) >= 0) {
+ if (getfilecon_raw(path, &econ) >= 0) {
if (STREQ(tcon, econ)) {
freecon(econ);
/* It's alright, there's nothing to change anyway. */
@@ -818,10 +818,10 @@ virSecuritySELinuxFSetFilecon(int fd, char *tcon)
VIR_INFO("Setting SELinux context on fd %d to '%s'", fd, tcon);
- if (fsetfilecon(fd, tcon) < 0) {
+ if (fsetfilecon_raw(fd, tcon) < 0) {
int fsetfilecon_errno = errno;
- if (fgetfilecon(fd, &econ) >= 0) {
+ if (fgetfilecon_raw(fd, &econ) >= 0) {
if (STREQ(tcon, econ)) {
freecon(econ);
/* It's alright, there's nothing to change anyway. */
@@ -1577,7 +1577,7 @@ virSecuritySELinuxSetSecurityProcessLabel(virSecurityManagerPtr mgr,
return -1;
}
- if (setexeccon(secdef->label) == -1) {
+ if (setexeccon_raw(secdef->label) == -1) {
virReportSystemError(errno,
_("unable to set security context '%s'"),
secdef->label);
@@ -1622,7 +1622,7 @@ virSecuritySELinuxSetSecurityDaemonSocketLabel(virSecurityManagerPtr mgr,
goto done;
}
- if (getcon(&scon) == -1) {
+ if (getcon_raw(&scon) == -1) {
virReportSystemError(errno,
_("unable to get current process context '%s'"),
secdef->label);
@@ -1645,7 +1645,7 @@ virSecuritySELinuxSetSecurityDaemonSocketLabel(virSecurityManagerPtr mgr,
VIR_DEBUG("Setting VM %s socket context %s",
def->name, context_str(proccon));
- if (setsockcreatecon(context_str(proccon)) == -1) {
+ if (setsockcreatecon_raw(context_str(proccon)) == -1) {
virReportSystemError(errno,
_("unable to set socket security context '%s'"),
context_str(proccon));
@@ -1688,7 +1688,7 @@ virSecuritySELinuxSetSecuritySocketLabel(virSecurityManagerPtr mgr,
VIR_DEBUG("Setting VM %s socket context %s",
vm->name, secdef->label);
- if (setsockcreatecon(secdef->label) == -1) {
+ if (setsockcreatecon_raw(secdef->label) == -1) {
virReportSystemError(errno,
_("unable to set socket security context '%s'"),
secdef->label);
@@ -1728,7 +1728,7 @@ virSecuritySELinuxClearSecuritySocketLabel(virSecurityManagerPtr mgr,
return -1;
}
- if (setsockcreatecon(NULL) == -1) {
+ if (setsockcreatecon_raw(NULL) == -1) {
virReportSystemError(errno,
_("unable to clear socket security context '%s'"),
secdef->label);
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index e159bd2..aea70e2 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -1227,7 +1227,7 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target,
#if HAVE_SELINUX
/* XXX: make this a security driver call */
- if (fgetfilecon(fd, &filecon) == -1) {
+ if (fgetfilecon_raw(fd, &filecon) == -1) {
if (errno != ENODATA && errno != ENOTSUP) {
virReportSystemError(errno,
_("cannot get file context of '%s'"),
diff --git a/tests/securityselinuxhelper.c b/tests/securityselinuxhelper.c
index 43676de..dc63ff3 100644
--- a/tests/securityselinuxhelper.c
+++ b/tests/securityselinuxhelper.c
@@ -31,7 +31,7 @@
* the process context, where as in fact we're faking it all
*/
-int getcon(security_context_t *context)
+int getcon_raw(security_context_t *context)
{
if (getenv("FAKE_CONTEXT") == NULL) {
*context = NULL;
@@ -43,7 +43,7 @@ int getcon(security_context_t *context)
return 0;
}
-int getpidcon(pid_t pid, security_context_t *context)
+int getpidcon_raw(pid_t pid, security_context_t *context)
{
if (pid != getpid()) {
*context = NULL;
@@ -60,7 +60,7 @@ int getpidcon(pid_t pid, security_context_t *context)
return 0;
}
-int setcon(security_context_t context)
+int setcon_raw(security_context_t context)
{
return setenv("FAKE_CONTEXT", context, 1);
}
diff --git a/tests/securityselinuxtest.c b/tests/securityselinuxtest.c
index 848a390..8bcf3a1 100644
--- a/tests/securityselinuxtest.c
+++ b/tests/securityselinuxtest.c
@@ -217,7 +217,7 @@ testSELinuxGenLabel(const void *opaque)
context_t con = NULL;
context_t imgcon = NULL;
- if (setcon((security_context_t)data->pidcon) < 0) {
+ if (setcon_raw((security_context_t)data->pidcon) < 0) {
perror("Cannot set process security context");
return -1;
}
--
1.7.12.3
12 years, 1 month
[libvirt] (no subject)
by cbley@av-test.de
>From 9c4881c67472575c3f1982f0921a4292025a9620 Mon Sep 17 00:00:00 2001
Message-Id: <9c4881c67472575c3f1982f0921a4292025a9620.1350037981.git.cbley(a)av-test.de>
In-Reply-To: <cover.1350037981.git.cbley(a)av-test.de>
References: <2DA6F4A3691599408358374D182280F9141CF6(a)xmb-rcd-x04.cisco.com> <cover.1350037981.git.cbley(a)av-test.de>
From: cbley(a)av-test.de (Claudio Bley)
Date: Fri, 17 Aug 2012 14:45:26 +0200
Subject: [PATCH 01/15] Explicitly set includeAntRuntime to false for javac tasks.
To: libvir-list(a)redhat.com
Organization: AV-Test GmbH, Germany
This prevents warnings like this:
warning: 'includeantruntime' was not set, defaulting to
build.sysclasspath=last; set to false for repeatable builds
---
build.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/build.xml b/build.xml
index 0b009aa..158a8a5 100644
--- a/build.xml
+++ b/build.xml
@@ -42,8 +42,8 @@
</target>
<target name="build" depends="init" description="builds the code and jar files">
- <javac srcdir="src/main/java" includes="**/*.java" classpathref="compile.classpath" destdir="target/classes" />
- <javac srcdir="src/test/java" includes="**/*.java" classpathref="test.classpath" destdir="target/testclasses" />
+ <javac srcdir="src/main/java" debug="${javac.debug}" includes="**/*.java" classpathref="compile.classpath" destdir="target/classes" includeAntRuntime="false" />
+ <javac srcdir="src/test/java" debug="${javac.debug}" includes="**/*.java" classpathref="test.classpath" destdir="target/testclasses" includeAntRuntime="false" />
<jar destfile="${jar.file}" basedir="target/classes" />
</target>
--
AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany
Phone: +49 341 265 310 19
Web:<http://www.av-test.org>
Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076)
Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern
12 years, 1 month
[libvirt] (no subject)
by cbley@av-test.de
>From f647654bb86a695e8ad6e3f442b3058d54647556 Mon Sep 17 00:00:00 2001
Message-Id: <f647654bb86a695e8ad6e3f442b3058d54647556.1350037981.git.cbley(a)av-test.de>
In-Reply-To: <cover.1350037981.git.cbley(a)av-test.de>
References: <2DA6F4A3691599408358374D182280F9141CF6(a)xmb-rcd-x04.cisco.com> <cover.1350037981.git.cbley(a)av-test.de>
From: cbley(a)av-test.de (Claudio Bley)
Date: Fri, 12 Oct 2012 11:01:29 +0200
Subject: [PATCH 02/15] Introduce a javac.debug property.
To: libvir-list(a)redhat.com
Organization: AV-Test GmbH, Germany
Set this to 'true' if you want to build your .class files with
debug information.
---
build.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/build.xml b/build.xml
index 158a8a5..0b147b0 100644
--- a/build.xml
+++ b/build.xml
@@ -13,6 +13,7 @@
<property name="debian.controlfile" value="${debian.pkgdir}/DEBIAN/control" />
<property name="debian.pkg" value="target/libvirt-java_${version}_all.deb" />
<property environment="env"/>
+ <property name="javac.debug" value="off" />
<path id="compile.classpath">
<fileset dir="${jar.dir}">
--
AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany
Phone: +49 341 265 310 19
Web:<http://www.av-test.org>
Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076)
Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern
12 years, 1 month
[libvirt] (no subject)
by cbley@av-test.de
>From 9af3b59730ed3d098fd8864cd48efd5a8dc8bcfe Mon Sep 17 00:00:00 2001
Message-Id: <9af3b59730ed3d098fd8864cd48efd5a8dc8bcfe.1350037981.git.cbley(a)av-test.de>
In-Reply-To: <cover.1350037981.git.cbley(a)av-test.de>
References: <2DA6F4A3691599408358374D182280F9141CF6(a)xmb-rcd-x04.cisco.com> <cover.1350037981.git.cbley(a)av-test.de>
From: cbley(a)av-test.de (Claudio Bley)
Date: Mon, 20 Aug 2012 16:52:28 +0200
Subject: [PATCH 07/15] Mark virConnCopyLastError and virConnGetLastError as deprecated.
To: libvir-list(a)redhat.com
Organization: AV-Test GmbH, Germany
They are only retained for backwards compatibility.
---
src/main/java/org/libvirt/jna/Libvirt.java | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java
index 02457b7..be0de3b 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -109,6 +109,14 @@ public interface Libvirt extends Library {
// Connection Functions
String virConnectBaselineCPU(ConnectionPointer virConnectPtr, String[] xmlCPUs, int ncpus, int flags);
+
+ /**
+ * @deprecated as of libvirt 0.6.0, all errors reported in the
+ * per-connection object are also duplicated in the global error
+ * object. This method remains for backwards compatibility. Use
+ * {@link #virCopyLastError} instead.
+ */
+ @Deprecated
int virConnCopyLastError(ConnectionPointer virConnectPtr, virError to);
int virConnectClose(ConnectionPointer virConnectPtr);
int virConnectCompareCPU(ConnectionPointer virConnectPtr, String xmlDesc, int flags);
@@ -148,6 +156,14 @@ public interface Libvirt extends Library {
ConnectionPointer virConnectOpen(String name);
ConnectionPointer virConnectOpenAuth(String name, virConnectAuth auth, int flags);
ConnectionPointer virConnectOpenReadOnly(String name);
+
+ /**
+ * @deprecated as of libvirt 0.6.0, all errors reported in the
+ * per-connection object are also duplicated in the global error
+ * object. This method remains only for backwards compatibility.
+ * Use {@link #virGetLastError} instead.
+ */
+ @Deprecated
virError virConnGetLastError(ConnectionPointer virConnectPtr);
int virConnResetLastError(ConnectionPointer virConnectPtr);
String virConnectDomainXMLFromNative(ConnectionPointer virConnectPtr, String nativeFormat,
--
AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany
Phone: +49 341 265 310 19
Web:<http://www.av-test.org>
Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076)
Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern
12 years, 1 month
[libvirt] (no subject)
by cbley@av-test.de
>From 285e443aa24cde2324380ebeac83c97efc456f94 Mon Sep 17 00:00:00 2001
Message-Id: <cover.1350037981.git.cbley(a)av-test.de>
In-Reply-To: <2DA6F4A3691599408358374D182280F9141CF6(a)xmb-rcd-x04.cisco.com>
References: <2DA6F4A3691599408358374D182280F9141CF6(a)xmb-rcd-x04.cisco.com>
From: cbley(a)av-test.de (Claudio Bley)
Date: Fri, 12 Oct 2012 12:33:01 +0200
Subject: [PATCH 00/15] [libvirt-java] some improvements and bug fixes
To: libvir-list(a)redhat.com
Organization: AV-Test GmbH, Germany
Hi.
Just sending off a few patches that have piled up during the last few
months.
Patch #1 to #7 and #9 to #10 and #12 contain mostly cosmetic changes
resp. changes to the build system.
Patch #8 changes the handling of errors. It is unnecessary trying to
retrieve an error when the libvirt function called did not signal any.
Also, some functions never fail (return void).
Patch #11 changes how errors are checked. This avoids copying and
freeing an error object and hence a few JVM to native calls.
Patch #13 fixes all the memory leaks I encountered by using my GDB
memcheck.py script. Running the junit tests under GDB's supervision
yielded 750 places of (potential) memory leaks, pointing to calls of
these libvirt functions:
virDomainDefineXML, virInterfaceGetXMLDesc,
virConnectListDefinedDomains, virStoragePoolLookupByName,
virDomainLookupByName, virNetworkGetBridgeName,
virNetworkLookupByUUIDString, virDomainLookupByUUID,
virDomainLookupByUUIDString, virConnectListInterfaces,
virDomainGetOSType, virConnectListDefinedNetworks,
virNetworkCreateXML, virStoragePoolDefineXML, virConnectOpen,
virDomainCreateXML, virNetworkDefineXML, virNetworkLookupByName,
virCopyLastError, virNetworkCreate, virNetworkLookupByUUID,
virInterfaceLookupByName, virConnectGetHostname,
virDomainGetXMLDesc, virConnectListNetworks, virNetworkGetXMLDesc
After applying patch #13, the script reports this:
1. @140737220948192
#1 __GI___strdup __GI___strdup strdup.c:45
#2 ... [1]
#3 Java_java_util_zip_ZipFile_open ? ?:0
#4 ... [5]
2. @140737221175744
#1 virAlloc virAlloc /build/buildd/libvirt-0.9.12/./src/util/memory.c:103
#2 virLastErrorObject virLastErrorObject /build/buildd/libvirt-0.9.12/./src/util/virterror.c:277
#3 virGetLastError virGetLastError /build/buildd/libvirt-0.9.12/./src/util/virterror.c:299
#4 ffi_call_unix64 ? ?:0
#5 ffi_call ? ?:0
#6 ... [1]
#7 Java_com_sun_jna_Native_invokePointer ? ?:0
#8 ... [5]
3. @140737220736736
#1 __libc_res_nsend __libc_res_nsend res_send.c:442
#2 __libc_res_nquery __libc_res_nquery res_query.c:226
#3 __libc_res_nquerydomain __libc_res_nquerydomain res_query.c:578
#4 __libc_res_nsearch __libc_res_nsearch res_query.c:416
#5 _nss_dns_gethostbyname3_r _nss_dns_gethostbyname3_r nss_dns/dns-host.c:197
#6 gaih_inet gaih_inet ../sysdeps/posix/getaddrinfo.c:940
#7 __GI_getaddrinfo __GI_getaddrinfo ../sysdeps/posix/getaddrinfo.c:2423
#8 virGetHostname virGetHostname /build/buildd/libvirt-0.9.12/./src/util/util.c:2105
#9 virConnectGetHostname virConnectGetHostname /build/buildd/libvirt-0.9.12/./src/libvirt.c:1724
#10 ffi_call_unix64 ? ?:0
#11 ffi_call ? ?:0
#12 ... [1]
#13 Java_com_sun_jna_Native_invokePointer ? ?:0
#14 ... [4]
4. @140737018598944
#1 virAlloc virAlloc /build/buildd/libvirt-0.9.12/./src/util/memory.c:103
#2 virLastErrorObject virLastErrorObject /build/buildd/libvirt-0.9.12/./src/util/virterror.c:277
#3 virResetLastError virResetLastError /build/buildd/libvirt-0.9.12/./src/util/virterror.c:428
#4 virNetworkFree virNetworkFree /build/buildd/libvirt-0.9.12/./src/libvirt.c:10151
#5 ffi_call_unix64 ? ?:0
#6 ffi_call ? ?:0
#7 ... [1]
#8 Java_com_sun_jna_Native_invokeInt ? ?:0
#9 ... [2]
5. @140737221440624
#1 __libc_res_nsend __libc_res_nsend res_send.c:442
#2 __libc_res_nquery __libc_res_nquery res_query.c:226
#3 __libc_res_nquerydomain __libc_res_nquerydomain res_query.c:578
#4 __libc_res_nsearch __libc_res_nsearch res_query.c:416
#5 _nss_dns_gethostbyname3_r _nss_dns_gethostbyname3_r nss_dns/dns-host.c:197
#6 gaih_inet gaih_inet ../sysdeps/posix/getaddrinfo.c:940
#7 __GI_getaddrinfo __GI_getaddrinfo ../sysdeps/posix/getaddrinfo.c:2423
#8 virGetHostname virGetHostname /build/buildd/libvirt-0.9.12/./src/util/util.c:2105
#9 virConnectGetHostname virConnectGetHostname /build/buildd/libvirt-0.9.12/./src/libvirt.c:1724
#10 ffi_call_unix64 ? ?:0
#11 ffi_call ? ?:0
#12 ... [1]
#13 Java_com_sun_jna_Native_invokePointer ? ?:0
#14 ... [4]
only pointing to the following function calls:
virConnectGetHostname, virNetworkFree, virGetLastError
AFAICS, these are neglectable. Probably just some global memory which
is not freed on exit.
(for the record: I'm on Ubuntu Precise, using libvirt 0.9.12. And yes,
I did call __libc_freeres on exit.)
Patch #14 removes functions that should have never been wrapped. These
functions do not increase the ref count and hence create Java objects
that actually do not represent "real" instances on the libvirt side.
I have tested with JNA 3.3.0, 3.4.{0, 1, 2}. I had JVM crashes
repeatedly with all JNA versions before 3.4.2. So, I strongly
recommend to use JNA 3.4.2.
Claudio Bley (15):
#1 Explicitly set includeAntRuntime to false for javac tasks.
#2 Introduce a javac.debug property.
#3 Add findbugs build file for ant.
#4 Make finalize() methods protected.
#5 Remove redundant public modifier from Libvirt interface methods.
#6 Change visibility of class members to private to enforce
encapsulation.
#7 Mark virConnCopyLastError and virConnGetLastError as deprecated.
#8 Call processError only if a libvirt function indicates an error.
#9 Split JUnit tests and use a fixture for Connect.
#10 Split "build" target and automatically rebuild out of date files.
#11 Avoid unnecessary copying and calling virResetLastError.
#12 Remove the libvirt instance attribute from all classes.
#13 Fix memory leaks for libvirt functions returning newly allocated
memory.
#14 Remove functions not intended to be used by libvirt bindings.
Explicitely define the order of a struct's fields.
build.xml | 37 +-
findbugs.xml | 36 ++
src/main/java/org/libvirt/Connect.java | 572 +++++++-------------
src/main/java/org/libvirt/Device.java | 9 +-
src/main/java/org/libvirt/Domain.java | 33 +-
src/main/java/org/libvirt/DomainSnapshot.java | 9 +-
src/main/java/org/libvirt/Error.java | 24 +-
src/main/java/org/libvirt/ErrorHandler.java | 9 +-
src/main/java/org/libvirt/Interface.java | 19 +-
src/main/java/org/libvirt/Library.java | 88 +++
src/main/java/org/libvirt/LibvirtException.java | 2 +-
src/main/java/org/libvirt/Network.java | 26 +-
src/main/java/org/libvirt/NetworkFilter.java | 9 +-
src/main/java/org/libvirt/Secret.java | 9 +-
src/main/java/org/libvirt/StoragePool.java | 9 +-
src/main/java/org/libvirt/StorageVol.java | 9 +-
src/main/java/org/libvirt/Stream.java | 11 +-
src/main/java/org/libvirt/jna/Libvirt.java | 502 ++++++++---------
src/main/java/org/libvirt/jna/virConnectAuth.java | 10 +
.../java/org/libvirt/jna/virConnectCredential.java | 12 +
.../java/org/libvirt/jna/virDomainBlockInfo.java | 8 +
.../java/org/libvirt/jna/virDomainBlockStats.java | 11 +
src/main/java/org/libvirt/jna/virDomainInfo.java | 11 +
.../org/libvirt/jna/virDomainInterfaceStats.java | 13 +
.../java/org/libvirt/jna/virDomainJobInfo.java | 18 +
.../java/org/libvirt/jna/virDomainMemoryStats.java | 7 +
src/main/java/org/libvirt/jna/virError.java | 19 +
src/main/java/org/libvirt/jna/virNodeInfo.java | 15 +
.../java/org/libvirt/jna/virSchedParameter.java | 9 +
.../java/org/libvirt/jna/virStoragePoolInfo.java | 10 +
.../java/org/libvirt/jna/virStorageVolInfo.java | 8 +
src/main/java/org/libvirt/jna/virVcpuInfo.java | 9 +
src/test/java/org/libvirt/TestJavaBindings.java | 50 +-
src/test/java/org/libvirt/TestLibvirtGlobals.java | 21 +
34 files changed, 883 insertions(+), 761 deletions(-)
create mode 100644 findbugs.xml
create mode 100644 src/main/java/org/libvirt/Library.java
create mode 100644 src/test/java/org/libvirt/TestLibvirtGlobals.java
--
AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany
Phone: +49 341 265 310 19
Web:<http://www.av-test.org>
Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076)
Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern
12 years, 1 month
[libvirt] (no subject)
by cbley@av-test.de
>From 3a4105d5eb1b4425fcf0dcb57fd1bedac6b7beb8 Mon Sep 17 00:00:00 2001
Message-Id: <3a4105d5eb1b4425fcf0dcb57fd1bedac6b7beb8.1350037981.git.cbley(a)av-test.de>
In-Reply-To: <cover.1350037981.git.cbley(a)av-test.de>
References: <2DA6F4A3691599408358374D182280F9141CF6(a)xmb-rcd-x04.cisco.com> <cover.1350037981.git.cbley(a)av-test.de>
From: cbley(a)av-test.de (Claudio Bley)
Date: Tue, 21 Aug 2012 16:06:59 +0200
Subject: [PATCH 08/15] Call processError only if a libvirt function indicates an error.
To: libvir-list(a)redhat.com
Organization: AV-Test GmbH, Germany
Usually, when libvirt functions return an int, an error is indicated
by returning -1.
If libvirt functions return an object (pointer), an error is indicated
by returning null.
Add overloads for method processError that check for these special
return values and call processError() in case an error occurred.
---
src/main/java/org/libvirt/Connect.java | 430 ++++++++++----------------------
1 file changed, 135 insertions(+), 295 deletions(-)
diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java
index 5419e85..e02c601 100644
--- a/src/main/java/org/libvirt/Connect.java
+++ b/src/main/java/org/libvirt/Connect.java
@@ -170,7 +170,7 @@ public class Connect {
public Connect(String uri) throws LibvirtException {
VCP = libvirt.virConnectOpen(uri);
// Check for an error
- processError();
+ processError(VCP);
ErrorHandler.processError(Libvirt.INSTANCE);
}
@@ -191,7 +191,7 @@ public class Connect {
VCP = libvirt.virConnectOpen(uri);
}
// Check for an error
- processError();
+ processError(VCP);
ErrorHandler.processError(Libvirt.INSTANCE);
}
@@ -224,7 +224,7 @@ public class Connect {
VCP = libvirt.virConnectOpenAuth(uri, vAuth, flags);
// Check for an error
- processError();
+ processError(VCP);
ErrorHandler.processError(Libvirt.INSTANCE);
}
@@ -238,9 +238,7 @@ public class Connect {
* @throws LibvirtException
*/
public String baselineCPU(String[] xmlCPUs) throws LibvirtException {
- String returnValue = libvirt.virConnectBaselineCPU(VCP, xmlCPUs, xmlCPUs.length, 0);
- processError();
- return returnValue;
+ return processError(libvirt.virConnectBaselineCPU(VCP, xmlCPUs, xmlCPUs.length, 0));
}
/**
@@ -248,20 +246,19 @@ public class Connect {
* the object after close() will result in an exception.
*
* @throws LibvirtException
- * @return number of references left (>= 0) for success, -1 for failure.
+ * @return number of remaining references (>= 0)
*/
public int close() throws LibvirtException {
int success = 0;
if (VCP != null) {
success = libvirt.virConnectClose(VCP);
- processError();
// 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
// it's called with a null virConnectPointer
VCP = null;
}
- return success;
+ return processError(success);
}
/**
@@ -290,13 +287,8 @@ public class Connect {
* @throws LibvirtException
*/
public Device deviceCreateXML(String xmlDesc) throws LibvirtException {
- Device returnValue = null;
- DevicePointer ptr = libvirt.virNodeDeviceCreateXML(VCP, xmlDesc, 0);
- processError();
- if (ptr != null) {
- returnValue = new Device(this, ptr);
- }
- return returnValue;
+ DevicePointer ptr = processError(libvirt.virNodeDeviceCreateXML(VCP, xmlDesc, 0));
+ return new Device(this, ptr);
}
/**
@@ -308,8 +300,7 @@ public class Connect {
* @throws LibvirtException
*/
public Device deviceLookupByName(String name) throws LibvirtException {
- DevicePointer ptr = libvirt.virNodeDeviceLookupByName(VCP, name);
- processError();
+ DevicePointer ptr = processError(libvirt.virNodeDeviceLookupByName(VCP, name));
return new Device(this, ptr);
}
@@ -328,13 +319,9 @@ public class Connect {
* description </a>
*/
public Domain domainCreateLinux(String xmlDesc, int flags) throws LibvirtException {
- Domain returnValue = null;
- DomainPointer ptr = libvirt.virDomainCreateLinux(VCP, xmlDesc, flags);
- processError();
- if (ptr != null) {
- returnValue = new Domain(this, ptr);
- }
- return returnValue;
+ DomainPointer ptr = processError(libvirt.virDomainCreateLinux(VCP, xmlDesc, flags));
+
+ return new Domain(this, ptr);
}
/**
@@ -347,13 +334,8 @@ public class Connect {
* description </a>
*/
public Domain domainCreateXML(String xmlDesc, int flags) throws LibvirtException {
- Domain returnValue = null;
- DomainPointer ptr = libvirt.virDomainCreateXML(VCP, xmlDesc, flags);
- processError();
- if (ptr != null) {
- returnValue = new Domain(this, ptr);
- }
- return returnValue;
+ DomainPointer ptr = processError(libvirt.virDomainCreateXML(VCP, xmlDesc, flags));
+ return new Domain(this, ptr);
}
/**
@@ -366,13 +348,8 @@ public class Connect {
* description </a>
*/
public Domain domainDefineXML(String xmlDesc) throws LibvirtException {
- Domain returnValue = null;
- DomainPointer ptr = libvirt.virDomainDefineXML(VCP, xmlDesc);
- processError();
- if (ptr != null) {
- returnValue = new Domain(this, ptr);
- }
- return returnValue;
+ DomainPointer ptr = processError(libvirt.virDomainDefineXML(VCP, xmlDesc));
+ return new Domain(this, ptr);
}
/**
@@ -405,16 +382,15 @@ public class Connect {
* 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. -1 if an error
- * @throws LibvirtException
+ * @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 {
DomainPointer ptr = domain == null ? null : domain.VDP;
int returnValue = libvirt.virConnectDomainEventRegisterAny(VCP, ptr, eventId, cb, null, null);
- processError();
- return returnValue;
+ return processError(returnValue);
}
/**
@@ -426,13 +402,8 @@ public class Connect {
* @throws LibvirtException
*/
public Domain domainLookupByID(int id) throws LibvirtException {
- Domain returnValue = null;
- DomainPointer ptr = libvirt.virDomainLookupByID(VCP, id);
- processError();
- if (ptr != null) {
- returnValue = new Domain(this, ptr);
- }
- return returnValue;
+ DomainPointer ptr = processError(libvirt.virDomainLookupByID(VCP, id));
+ return new Domain(this, ptr);
}
/**
@@ -444,13 +415,8 @@ public class Connect {
* @throws LibvirtException
*/
public Domain domainLookupByName(String name) throws LibvirtException {
- Domain returnValue = null;
- DomainPointer ptr = libvirt.virDomainLookupByName(VCP, name);
- processError();
- if (ptr != null) {
- returnValue = new Domain(this, ptr);
- }
- return returnValue;
+ DomainPointer ptr = processError(libvirt.virDomainLookupByName(VCP, name));
+ return new Domain(this, ptr);
}
/**
@@ -465,13 +431,8 @@ public class Connect {
*/
public Domain domainLookupByUUID(int[] UUID) throws LibvirtException {
byte[] uuidBytes = Connect.createUUIDBytes(UUID);
- Domain returnValue = null;
- DomainPointer ptr = libvirt.virDomainLookupByUUID(VCP, uuidBytes);
- processError();
- if (ptr != null) {
- returnValue = new Domain(this, ptr);
- }
- return returnValue;
+ DomainPointer ptr = processError(libvirt.virDomainLookupByUUID(VCP, uuidBytes));
+ return new Domain(this, ptr);
}
/**
@@ -495,13 +456,8 @@ public class Connect {
* @throws LibvirtException
*/
public Domain domainLookupByUUIDString(String UUID) throws LibvirtException {
- Domain returnValue = null;
- DomainPointer ptr = libvirt.virDomainLookupByUUIDString(VCP, UUID);
- processError();
- if (ptr != null) {
- returnValue = new Domain(this, ptr);
- }
- return returnValue;
+ DomainPointer ptr = processError(libvirt.virDomainLookupByUUIDString(VCP, UUID));
+ return new Domain(this, ptr);
}
/**
@@ -513,9 +469,7 @@ public class Connect {
* @throws LibvirtException
*/
public String domainXMLFromNative(String nativeFormat, String nativeConfig, int flags) throws LibvirtException {
- String returnValue = libvirt.virConnectDomainXMLFromNative(VCP, nativeFormat, nativeConfig, 0);
- processError();
- return returnValue;
+ return processError(libvirt.virConnectDomainXMLFromNative(VCP, nativeFormat, nativeConfig, 0));
}
/**
@@ -528,8 +482,7 @@ public class Connect {
*/
public String domainXMLToNative(String nativeFormat, String domainXML, int flags) throws LibvirtException {
String returnValue = libvirt.virConnectDomainXMLToNative(VCP, nativeFormat, domainXML, 0);
- processError();
- return returnValue;
+ return processError(returnValue);
}
@Override
@@ -559,8 +512,7 @@ public class Connect {
*/
public String findStoragePoolSources(String type, String srcSpecs, int flags) throws LibvirtException {
String returnValue = libvirt.virConnectFindStoragePoolSources(VCP, type, srcSpecs, flags);
- processError();
- return returnValue;
+ return processError(returnValue);
}
/**
@@ -573,8 +525,7 @@ public class Connect {
*/
public String getCapabilities() throws LibvirtException {
String returnValue = libvirt.virConnectGetCapabilities(VCP);
- processError();
- return returnValue;
+ return processError(returnValue);
}
/**
@@ -582,8 +533,10 @@ public class Connect {
*/
public long getCellsFreeMemory(int startCells, int maxCells) throws LibvirtException {
LongByReference returnValue = new LongByReference();
- libvirt.virNodeGetCellsFreeMemory(VCP, returnValue, startCells, maxCells);
- processError();
+ processError(libvirt.virNodeGetCellsFreeMemory(VCP,
+ returnValue,
+ startCells,
+ maxCells));
return returnValue.getValue();
}
@@ -593,7 +546,7 @@ public class Connect {
public long getFreeMemory() throws LibvirtException {
long returnValue = 0;
returnValue = libvirt.virNodeGetFreeMemory(VCP);
- processError();
+ if (returnValue == 0) processError();
return returnValue;
}
@@ -606,10 +559,7 @@ public class Connect {
* @throws LibvirtException
*/
public String getHostName() throws LibvirtException {
- String returnValue = libvirt.virConnectGetHostname(VCP);
- processError();
- return returnValue;
-
+ return processError(libvirt.virConnectGetHostname(VCP));
}
/**
@@ -624,8 +574,7 @@ public class Connect {
public long getHypervisorVersion(String type) throws LibvirtException {
LongByReference libVer = new LongByReference();
LongByReference typeVer = new LongByReference();
- libvirt.virGetVersion(libVer, type, typeVer);
- processError();
+ processError(libvirt.virGetVersion(libVer, type, typeVer));
return libVer.getValue();
}
@@ -639,8 +588,7 @@ public class Connect {
public long getLibVirVersion() throws LibvirtException {
LongByReference libVer = new LongByReference();
LongByReference typeVer = new LongByReference();
- libvirt.virGetVersion(libVer, null, typeVer);
- processError();
+ processError(libvirt.virGetVersion(libVer, null, typeVer));
return libVer.getValue();
}
@@ -654,9 +602,7 @@ public class Connect {
* @throws LibvirtException
*/
public int getMaxVcpus(String type) throws LibvirtException {
- int returnValue = libvirt.virConnectGetMaxVcpus(VCP, type);
- processError();
- return returnValue;
+ return processError(libvirt.virConnectGetMaxVcpus(VCP, type));
}
/**
@@ -666,9 +612,7 @@ public class Connect {
* @throws LibvirtException
*/
public String getType() throws LibvirtException {
- String returnValue = libvirt.virConnectGetType(VCP);
- processError();
- return returnValue;
+ return processError(libvirt.virConnectGetType(VCP));
}
/**
@@ -681,9 +625,7 @@ public class Connect {
* @throws LibvirtException
*/
public String getURI() throws LibvirtException {
- String returnValue = libvirt.virConnectGetURI(VCP);
- processError();
- return returnValue;
+ return processError(libvirt.virConnectGetURI(VCP));
}
/**
@@ -697,8 +639,7 @@ public class Connect {
*/
public long getVersion() throws LibvirtException {
LongByReference hvVer = new LongByReference();
- libvirt.virConnectGetVersion(VCP, hvVer);
- processError();
+ processError(libvirt.virConnectGetVersion(VCP, hvVer));
return hvVer.getValue();
}
@@ -711,13 +652,8 @@ public class Connect {
* @throws LibvirtException
*/
public Interface interfaceDefineXML(String xmlDesc) throws LibvirtException {
- Interface returnValue = null;
- InterfacePointer ptr = libvirt.virInterfaceDefineXML(VCP, xmlDesc, 0);
- processError();
- if (ptr != null) {
- returnValue = new Interface(this, ptr);
- }
- return returnValue;
+ InterfacePointer ptr = processError(libvirt.virInterfaceDefineXML(VCP, xmlDesc, 0));
+ return new Interface(this, ptr);
}
/**
@@ -726,13 +662,8 @@ public class Connect {
* @throws LibvirtException
*/
public Interface interfaceLookupByMACString(String mac) throws LibvirtException {
- Interface returnValue = null;
- InterfacePointer ptr = libvirt.virInterfaceLookupByMACString(VCP, mac);
- processError();
- if (ptr != null) {
- returnValue = new Interface(this, ptr);
- }
- return returnValue;
+ InterfacePointer ptr = processError(libvirt.virInterfaceLookupByMACString(VCP, mac));
+ return new Interface(this, ptr);
}
/**
@@ -741,13 +672,8 @@ public class Connect {
* @throws LibvirtException
*/
public Interface interfaceLookupByName(String name) throws LibvirtException {
- Interface returnValue = null;
- InterfacePointer ptr = libvirt.virInterfaceLookupByName(VCP, name);
- processError();
- if (ptr != null) {
- returnValue = new Interface(this, ptr);
- }
- return returnValue;
+ InterfacePointer ptr = processError(libvirt.virInterfaceLookupByName(VCP, name));
+ return new Interface(this, ptr);
}
/**
@@ -791,8 +717,7 @@ public class Connect {
int maxnames = numOfDefinedDomains();
String[] names = new String[maxnames];
if (maxnames > 0) {
- libvirt.virConnectListDefinedDomains(VCP, names, maxnames);
- processError();
+ processError(libvirt.virConnectListDefinedDomains(VCP, names, maxnames));
}
return names;
}
@@ -808,8 +733,7 @@ public class Connect {
int num = numOfDefinedInterfaces();
String[] returnValue = new String[num];
if (num > 0) {
- libvirt.virConnectListDefinedInterfaces(VCP, returnValue, num);
- processError();
+ processError(libvirt.virConnectListDefinedInterfaces(VCP, returnValue, num));
}
return returnValue;
}
@@ -826,8 +750,7 @@ public class Connect {
String[] names = new String[maxnames];
if (maxnames > 0) {
- libvirt.virConnectListDefinedNetworks(VCP, names, maxnames);
- processError();
+ processError(libvirt.virConnectListDefinedNetworks(VCP, names, maxnames));
}
return names;
}
@@ -842,8 +765,7 @@ public class Connect {
public String[] listDefinedStoragePools() throws LibvirtException {
int num = numOfDefinedStoragePools();
String[] returnValue = new String[num];
- libvirt.virConnectListDefinedStoragePools(VCP, returnValue, num);
- processError();
+ processError(libvirt.virConnectListDefinedStoragePools(VCP, returnValue, num));
return returnValue;
}
@@ -858,8 +780,7 @@ public class Connect {
String[] names = new String[maxDevices];
if (maxDevices > 0) {
- libvirt.virNodeListDevices(VCP, capabilityName, names, maxDevices, 0);
- processError();
+ processError(libvirt.virNodeListDevices(VCP, capabilityName, names, maxDevices, 0));
}
return names;
}
@@ -875,8 +796,7 @@ public class Connect {
int[] ids = new int[maxids];
if (maxids > 0) {
- libvirt.virConnectListDomains(VCP, ids, maxids);
- processError();
+ processError(libvirt.virConnectListDomains(VCP, ids, maxids));
}
return ids;
}
@@ -892,8 +812,7 @@ public class Connect {
int num = numOfInterfaces();
String[] returnValue = new String[num];
if (num > 0) {
- libvirt.virConnectListInterfaces(VCP, returnValue, num);
- processError();
+ processError(libvirt.virConnectListInterfaces(VCP, returnValue, num));
}
return returnValue;
}
@@ -908,8 +827,7 @@ public class Connect {
int maxnames = numOfNetworkFilters();
String[] names = new String[maxnames];
if (maxnames > 0) {
- libvirt.virConnectListNWFilters(VCP, names, maxnames);
- processError();
+ processError(libvirt.virConnectListNWFilters(VCP, names, maxnames));
}
return names;
}
@@ -926,8 +844,7 @@ public class Connect {
String[] names = new String[maxnames];
if (maxnames > 0) {
- libvirt.virConnectListNetworks(VCP, names, maxnames);
- processError();
+ processError(libvirt.virConnectListNetworks(VCP, names, maxnames));
}
return names;
}
@@ -941,8 +858,7 @@ public class Connect {
public String[] listSecrets() throws LibvirtException {
int num = numOfSecrets();
String[] returnValue = new String[num];
- libvirt.virConnectListSecrets(VCP, returnValue, num);
- processError();
+ processError(libvirt.virConnectListSecrets(VCP, returnValue, num));
return returnValue;
}
@@ -956,8 +872,7 @@ public class Connect {
public String[] listStoragePools() throws LibvirtException {
int num = numOfStoragePools();
String[] returnValue = new String[num];
- libvirt.virConnectListStoragePools(VCP, returnValue, num);
- processError();
+ processError(libvirt.virConnectListStoragePools(VCP, returnValue, num));
return returnValue;
}
@@ -974,13 +889,8 @@ public class Connect {
* description</a>
*/
public Network networkCreateXML(String xmlDesc) throws LibvirtException {
- Network returnValue = null;
- NetworkPointer ptr = libvirt.virNetworkCreateXML(VCP, xmlDesc);
- processError();
- if (ptr != null) {
- returnValue = new Network(this, ptr);
- }
- return returnValue;
+ NetworkPointer ptr = processError(libvirt.virNetworkCreateXML(VCP, xmlDesc));
+ return new Network(this, ptr);
}
/**
@@ -995,13 +905,8 @@ public class Connect {
* description</a>
*/
public Network networkDefineXML(String xmlDesc) throws LibvirtException {
- Network returnValue = null;
- NetworkPointer ptr = libvirt.virNetworkDefineXML(VCP, xmlDesc);
- processError();
- if (ptr != null) {
- returnValue = new Network(this, ptr);
- }
- return returnValue;
+ NetworkPointer ptr = processError(libvirt.virNetworkDefineXML(VCP, xmlDesc));
+ return new Network(this, ptr);
}
/**
@@ -1016,13 +921,8 @@ public class Connect {
* > Libvirt Documentation </a>
*/
public NetworkFilter networkFilterDefineXML(String xmlDesc) throws LibvirtException {
- NetworkFilter returnValue = null;
- NetworkFilterPointer ptr = libvirt.virNWFilterDefineXML(VCP, xmlDesc);
- processError();
- if (ptr != null) {
- returnValue = new NetworkFilter(this, ptr);
- }
- return returnValue;
+ NetworkFilterPointer ptr = processError(libvirt.virNWFilterDefineXML(VCP, xmlDesc));
+ return new NetworkFilter(this, ptr);
}
/**
@@ -1037,13 +937,8 @@ public class Connect {
* > Libvirt Documentation </a>
*/
public NetworkFilter networkFilterLookupByName(String name) throws LibvirtException {
- NetworkFilter returnValue = null;
- NetworkFilterPointer ptr = libvirt.virNWFilterLookupByName(VCP, name);
- processError();
- if (ptr != null) {
- returnValue = new NetworkFilter(this, ptr);
- }
- return returnValue;
+ NetworkFilterPointer ptr = processError(libvirt.virNWFilterLookupByName(VCP, name));
+ return new NetworkFilter(this, ptr);
}
/**
@@ -1058,13 +953,8 @@ public class Connect {
*/
public NetworkFilter networkFilterLookupByUUID(int[] UUID) throws LibvirtException {
byte[] uuidBytes = Connect.createUUIDBytes(UUID);
- NetworkFilter returnValue = null;
- NetworkFilterPointer ptr = libvirt.virNWFilterLookupByUUID(VCP, uuidBytes);
- processError();
- if (ptr != null) {
- returnValue = new NetworkFilter(this, ptr);
- }
- return returnValue;
+ NetworkFilterPointer ptr = processError(libvirt.virNWFilterLookupByUUID(VCP, uuidBytes));
+ return new NetworkFilter(this, ptr);
}
/**
@@ -1088,13 +978,8 @@ public class Connect {
* @throws LibvirtException
*/
public NetworkFilter networkFilterLookupByUUIDString(String UUID) throws LibvirtException {
- NetworkFilter returnValue = null;
- NetworkFilterPointer ptr = libvirt.virNWFilterLookupByUUIDString(VCP, UUID);
- processError();
- if (ptr != null) {
- returnValue = new NetworkFilter(this, ptr);
- }
- return returnValue;
+ NetworkFilterPointer ptr = processError(libvirt.virNWFilterLookupByUUIDString(VCP, UUID));
+ return new NetworkFilter(this, ptr);
}
/**
@@ -1106,13 +991,8 @@ public class Connect {
* @throws LibvirtException
*/
public Network networkLookupByName(String name) throws LibvirtException {
- Network returnValue = null;
- NetworkPointer ptr = libvirt.virNetworkLookupByName(VCP, name);
- processError();
- if (ptr != null) {
- returnValue = new Network(this, ptr);
- }
- return returnValue;
+ NetworkPointer ptr = processError(libvirt.virNetworkLookupByName(VCP, name));
+ return new Network(this, ptr);
}
/**
@@ -1129,13 +1009,8 @@ public class Connect {
@Deprecated
public Network networkLookupByUUID(int[] UUID) throws LibvirtException {
byte[] uuidBytes = Connect.createUUIDBytes(UUID);
- Network returnValue = null;
- NetworkPointer ptr = libvirt.virNetworkLookupByUUID(VCP, uuidBytes);
- processError();
- if (ptr != null) {
- returnValue = new Network(this, ptr);
- }
- return returnValue;
+ NetworkPointer ptr = processError(libvirt.virNetworkLookupByUUID(VCP, uuidBytes));
+ return new Network(this, ptr);
}
/**
@@ -1159,13 +1034,8 @@ public class Connect {
* @throws LibvirtException
*/
public Network networkLookupByUUIDString(String UUID) throws LibvirtException {
- Network returnValue = null;
- NetworkPointer ptr = libvirt.virNetworkLookupByUUIDString(VCP, UUID);
- processError();
- if (ptr != null) {
- returnValue = new Network(this, ptr);
- }
- return returnValue;
+ NetworkPointer ptr = processError(libvirt.virNetworkLookupByUUIDString(VCP, UUID));
+ return new Network(this, ptr);
}
/**
@@ -1177,8 +1047,7 @@ public class Connect {
*/
public NodeInfo nodeInfo() throws LibvirtException {
virNodeInfo vInfo = new virNodeInfo();
- libvirt.virNodeGetInfo(VCP, vInfo);
- processError();
+ processError(libvirt.virNodeGetInfo(VCP, vInfo));
return new NodeInfo(vInfo);
}
@@ -1189,9 +1058,7 @@ public class Connect {
* @throws LibvirtException
*/
public int numOfDefinedDomains() throws LibvirtException {
- int returnValue = libvirt.virConnectNumOfDefinedDomains(VCP);
- processError();
- return returnValue;
+ return processError(libvirt.virConnectNumOfDefinedDomains(VCP));
}
/**
@@ -1201,9 +1068,7 @@ public class Connect {
* @throws LibvirtException
*/
public int numOfDefinedInterfaces() throws LibvirtException {
- int returnValue = libvirt.virConnectNumOfDefinedInterfaces(VCP);
- processError();
- return returnValue;
+ return processError(libvirt.virConnectNumOfDefinedInterfaces(VCP));
}
/**
@@ -1213,9 +1078,7 @@ public class Connect {
* @throws LibvirtException
*/
public int numOfDefinedNetworks() throws LibvirtException {
- int returnValue = libvirt.virConnectNumOfDefinedNetworks(VCP);
- processError();
- return returnValue;
+ return processError(libvirt.virConnectNumOfDefinedNetworks(VCP));
}
/**
@@ -1225,9 +1088,7 @@ public class Connect {
* @throws LibvirtException
*/
public int numOfDefinedStoragePools() throws LibvirtException {
- int returnValue = libvirt.virConnectNumOfDefinedStoragePools(VCP);
- processError();
- return returnValue;
+ return processError(libvirt.virConnectNumOfDefinedStoragePools(VCP));
}
/**
@@ -1237,9 +1098,7 @@ public class Connect {
* @throws LibvirtException
*/
public int numOfDevices(String capabilityName) throws LibvirtException {
- int returnValue = libvirt.virNodeNumOfDevices(VCP, capabilityName, 0);
- processError();
- return returnValue;
+ return processError(libvirt.virNodeNumOfDevices(VCP, capabilityName, 0));
}
/**
@@ -1249,9 +1108,7 @@ public class Connect {
* @throws LibvirtException
*/
public int numOfDomains() throws LibvirtException {
- int returnValue = libvirt.virConnectNumOfDomains(VCP);
- processError();
- return returnValue;
+ return processError(libvirt.virConnectNumOfDomains(VCP));
}
/**
@@ -1261,9 +1118,7 @@ public class Connect {
* @throws LibvirtException
*/
public int numOfInterfaces() throws LibvirtException {
- int returnValue = libvirt.virConnectNumOfInterfaces(VCP);
- processError();
- return returnValue;
+ return processError(libvirt.virConnectNumOfInterfaces(VCP));
}
/**
@@ -1273,9 +1128,7 @@ public class Connect {
* @throws LibvirtException
*/
public int numOfNetworkFilters() throws LibvirtException {
- int returnValue = libvirt.virConnectNumOfNWFilters(VCP);
- processError();
- return returnValue;
+ return processError(libvirt.virConnectNumOfNWFilters(VCP));
}
/**
@@ -1285,9 +1138,7 @@ public class Connect {
* @throws LibvirtException
*/
public int numOfNetworks() throws LibvirtException {
- int returnValue = libvirt.virConnectNumOfNetworks(VCP);
- processError();
- return returnValue;
+ return processError(libvirt.virConnectNumOfNetworks(VCP));
}
/**
@@ -1296,9 +1147,7 @@ public class Connect {
* @return the number of secrets
*/
public int numOfSecrets() throws LibvirtException {
- int returnValue = libvirt.virConnectNumOfSecrets(VCP);
- processError();
- return returnValue;
+ return processError(libvirt.virConnectNumOfSecrets(VCP));
}
/**
@@ -1308,9 +1157,7 @@ public class Connect {
* @throws LibvirtException
*/
public int numOfStoragePools() throws LibvirtException {
- int returnValue = libvirt.virConnectNumOfStoragePools(VCP);
- processError();
- return returnValue;
+ return processError(libvirt.virConnectNumOfStoragePools(VCP));
}
/**
@@ -1323,6 +1170,32 @@ public class Connect {
}
/**
+ * 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
@@ -1330,8 +1203,7 @@ public class Connect {
* @throws LibvirtException
*/
public void restore(String from) throws LibvirtException {
- libvirt.virDomainRestore(VCP, from);
- processError();
+ processError(libvirt.virDomainRestore(VCP, from));
}
/**
@@ -1347,13 +1219,8 @@ public class Connect {
* @throws LibvirtException
*/
public Secret secretDefineXML(String xmlDesc) throws LibvirtException {
- Secret returnValue = null;
- SecretPointer ptr = libvirt.virSecretDefineXML(VCP, xmlDesc, 0);
- processError();
- if (ptr != null) {
- returnValue = new Secret(this, ptr);
- }
- return returnValue;
+ SecretPointer ptr = processError(libvirt.virSecretDefineXML(VCP, xmlDesc, 0));
+ return new Secret(this, ptr);
}
/**
@@ -1368,13 +1235,8 @@ public class Connect {
*/
public Secret secretLookupByUUID(int[] UUID) throws LibvirtException {
byte[] uuidBytes = Connect.createUUIDBytes(UUID);
- Secret returnValue = null;
- SecretPointer ptr = libvirt.virSecretLookupByUUID(VCP, uuidBytes);
- processError();
- if (ptr != null) {
- returnValue = new Secret(this, ptr);
- }
- return returnValue;
+ SecretPointer ptr = processError(libvirt.virSecretLookupByUUID(VCP, uuidBytes));
+ return new Secret(this, ptr);
}
/**
@@ -1398,13 +1260,8 @@ public class Connect {
* @throws LibvirtException
*/
public Secret secretLookupByUUIDString(String UUID) throws LibvirtException {
- Secret returnValue = null;
- SecretPointer ptr = libvirt.virSecretLookupByUUIDString(VCP, UUID);
- processError();
- if (ptr != null) {
- returnValue = new Secret(this, ptr);
- }
- return returnValue;
+ SecretPointer ptr = processError(libvirt.virSecretLookupByUUIDString(VCP, UUID));
+ return new Secret(this, ptr);
}
public void setConnectionErrorCallback(Libvirt.VirErrorCallback callback) throws LibvirtException {
@@ -1422,8 +1279,7 @@ public class Connect {
* @throws LibvirtException
*/
public void setDom0Memory(long memory) throws LibvirtException {
- libvirt.virDomainSetMemory(null, new NativeLong(memory));
- processError();
+ processError(libvirt.virDomainSetMemory(null, new NativeLong(memory)));
}
/**
@@ -1439,8 +1295,7 @@ public class Connect {
* @throws LibvirtException
*/
public StoragePool storagePoolCreateXML(String xmlDesc, int flags) throws LibvirtException {
- StoragePoolPointer ptr = libvirt.virStoragePoolCreateXML(VCP, xmlDesc, flags);
- processError();
+ StoragePoolPointer ptr = processError(libvirt.virStoragePoolCreateXML(VCP, xmlDesc, flags));
return new StoragePool(this, ptr);
}
@@ -1456,8 +1311,7 @@ public class Connect {
* @throws LibvirtException
*/
public StoragePool storagePoolDefineXML(String xml, int flags) throws LibvirtException {
- StoragePoolPointer ptr = libvirt.virStoragePoolDefineXML(VCP, xml, flags);
- processError();
+ StoragePoolPointer ptr = processError(libvirt.virStoragePoolDefineXML(VCP, xml, flags));
return new StoragePool(this, ptr);
}
@@ -1470,8 +1324,7 @@ public class Connect {
* @throws LibvirtException
*/
public StoragePool storagePoolLookupByName(String name) throws LibvirtException {
- StoragePoolPointer ptr = libvirt.virStoragePoolLookupByName(VCP, name);
- processError();
+ StoragePoolPointer ptr = processError(libvirt.virStoragePoolLookupByName(VCP, name));
return new StoragePool(this, ptr);
}
@@ -1487,13 +1340,8 @@ public class Connect {
@Deprecated
public StoragePool storagePoolLookupByUUID(int[] UUID) throws LibvirtException {
byte[] uuidBytes = Connect.createUUIDBytes(UUID);
- StoragePool returnValue = null;
- StoragePoolPointer ptr = libvirt.virStoragePoolLookupByUUID(VCP, uuidBytes);
- processError();
- if (ptr != null) {
- returnValue = new StoragePool(this, ptr);
- }
- return returnValue;
+ StoragePoolPointer ptr = processError(libvirt.virStoragePoolLookupByUUID(VCP, uuidBytes));
+ return new StoragePool(this, ptr);
}
/**
@@ -1517,13 +1365,8 @@ public class Connect {
* @throws LibvirtException
*/
public StoragePool storagePoolLookupByUUIDString(String UUID) throws LibvirtException {
- StoragePool returnValue = null;
- StoragePoolPointer ptr = libvirt.virStoragePoolLookupByUUIDString(VCP, UUID);
- processError();
- if (ptr != null) {
- returnValue = new StoragePool(this, ptr);
- }
- return returnValue;
+ StoragePoolPointer ptr = processError(libvirt.virStoragePoolLookupByUUIDString(VCP, UUID));
+ return new StoragePool(this, ptr);
}
/**
@@ -1534,8 +1377,7 @@ public class Connect {
* @return a storage volume
*/
public StorageVol storageVolLookupByKey(String key) throws LibvirtException {
- StorageVolPointer sPtr = libvirt.virStorageVolLookupByKey(VCP, key);
- processError();
+ StorageVolPointer sPtr = processError(libvirt.virStorageVolLookupByKey(VCP, key));
return new StorageVol(this, sPtr);
}
@@ -1547,8 +1389,7 @@ public class Connect {
* @return a storage volume
*/
public StorageVol storageVolLookupByPath(String path) throws LibvirtException {
- StorageVolPointer sPtr = libvirt.virStorageVolLookupByPath(VCP, path);
- processError();
+ StorageVolPointer sPtr = processError(libvirt.virStorageVolLookupByPath(VCP, path));
return new StorageVol(this, sPtr);
}
@@ -1561,8 +1402,7 @@ public class Connect {
* @return the new object
*/
public Stream streamNew(int flags) throws LibvirtException {
- StreamPointer sPtr = libvirt.virStreamNew(VCP, flags);
- processError();
+ StreamPointer sPtr = processError(libvirt.virStreamNew(VCP, flags));
return new Stream(this, sPtr);
}
--
AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany
Phone: +49 341 265 310 19
Web:<http://www.av-test.org>
Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076)
Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern
12 years, 1 month
[libvirt] (no subject)
by cbley@av-test.de
>From ab3c4135fe30953bf48ad526ed73c24d41f100d4 Mon Sep 17 00:00:00 2001
Message-Id: <ab3c4135fe30953bf48ad526ed73c24d41f100d4.1350037981.git.cbley(a)av-test.de>
In-Reply-To: <cover.1350037981.git.cbley(a)av-test.de>
References: <2DA6F4A3691599408358374D182280F9141CF6(a)xmb-rcd-x04.cisco.com> <cover.1350037981.git.cbley(a)av-test.de>
From: cbley(a)av-test.de (Claudio Bley)
Date: Thu, 23 Aug 2012 16:53:15 +0200
Subject: [PATCH 12/15] Remove the libvirt instance attribute from all classes.
To: libvir-list(a)redhat.com
Organization: AV-Test GmbH, Germany
Every class contained a member called "libvirt". This member
was initialized during construction to refer to the Connect.libvirt
member variable, which in turn referred to the static
jna.Libvirt.INSTANCE field.
Add a Library class which contains a static "libvirt" field and
import this field statically for convenient access.
---
src/main/java/org/libvirt/Connect.java | 16 +--------------
src/main/java/org/libvirt/Device.java | 7 +------
src/main/java/org/libvirt/Domain.java | 7 +------
src/main/java/org/libvirt/DomainSnapshot.java | 7 +------
src/main/java/org/libvirt/Interface.java | 7 +------
src/main/java/org/libvirt/Library.java | 26 +++++++++++++++++++++++++
src/main/java/org/libvirt/Network.java | 7 +------
src/main/java/org/libvirt/NetworkFilter.java | 7 +------
src/main/java/org/libvirt/Secret.java | 7 +------
src/main/java/org/libvirt/StoragePool.java | 7 +------
src/main/java/org/libvirt/StorageVol.java | 7 +------
src/main/java/org/libvirt/Stream.java | 7 +------
12 files changed, 37 insertions(+), 75 deletions(-)
diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java
index e02c601..ae306d6 100644
--- a/src/main/java/org/libvirt/Connect.java
+++ b/src/main/java/org/libvirt/Connect.java
@@ -15,6 +15,7 @@ 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 com.sun.jna.Memory;
import com.sun.jna.NativeLong;
@@ -28,16 +29,6 @@ import com.sun.jna.ptr.LongByReference;
*/
public class Connect {
- // Load the native part
- static {
- Libvirt.INSTANCE.virInitialize();
- try {
- ErrorHandler.processError(Libvirt.INSTANCE);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
/**
* Creates a new connection object from the domain. If all you want is the
* existing domain's connection, use the getConnection method directly. Thie
@@ -135,11 +126,6 @@ public class Connect {
protected ConnectionPointer VCP;
/**
- * The libvirt library
- */
- Libvirt libvirt = Libvirt.INSTANCE;
-
- /**
* Protected constructor to return a Connection with ConnectionPointer
*/
Connect(ConnectionPointer ptr) {
diff --git a/src/main/java/org/libvirt/Device.java b/src/main/java/org/libvirt/Device.java
index bc25258..416e06a 100644
--- a/src/main/java/org/libvirt/Device.java
+++ b/src/main/java/org/libvirt/Device.java
@@ -2,6 +2,7 @@ package org.libvirt;
import org.libvirt.jna.DevicePointer;
import org.libvirt.jna.Libvirt;
+import static org.libvirt.Library.libvirt;
/**
* A device which is attached to a node
@@ -19,11 +20,6 @@ public class Device {
private Connect virConnect;
/**
- * The libvirt connection from the hypervisor
- */
- protected Libvirt libvirt;
-
- /**
* Constructs a Device object from a DevicePointer, and a Connect object.
*
* @param virConnect
@@ -34,7 +30,6 @@ public class Device {
Device(Connect virConnect, DevicePointer VDP) {
this.virConnect = virConnect;
this.VDP = VDP;
- libvirt = virConnect.libvirt;
}
/**
diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java
index f4f5225..45fba26 100644
--- a/src/main/java/org/libvirt/Domain.java
+++ b/src/main/java/org/libvirt/Domain.java
@@ -11,6 +11,7 @@ import org.libvirt.jna.virDomainJobInfo;
import org.libvirt.jna.virDomainMemoryStats;
import org.libvirt.jna.virSchedParameter;
import org.libvirt.jna.virVcpuInfo;
+import static org.libvirt.Library.libvirt;
import com.sun.jna.Native;
import com.sun.jna.NativeLong;
@@ -86,11 +87,6 @@ public class Domain {
private Connect virConnect;
/**
- * The libvirt connection from the hypervisor
- */
- protected Libvirt libvirt;
-
- /**
* Constructs a Domain object from a known native DomainPointer, and a
* Connect object.
*
@@ -102,7 +98,6 @@ public class Domain {
Domain(Connect virConnect, DomainPointer VDP) {
this.virConnect = virConnect;
this.VDP = VDP;
- libvirt = virConnect.libvirt;
}
/**
diff --git a/src/main/java/org/libvirt/DomainSnapshot.java b/src/main/java/org/libvirt/DomainSnapshot.java
index 3083ca0..355d9d0 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 org.libvirt.jna.Libvirt;
+import static org.libvirt.Library.libvirt;
public class DomainSnapshot {
@@ -15,15 +16,9 @@ public class DomainSnapshot {
*/
private Connect virConnect;
- /**
- * The libvirt connection from the hypervisor
- */
- protected Libvirt libvirt;
-
public DomainSnapshot(Connect virConnect, DomainSnapshotPointer VDSP) {
this.VDSP = VDSP;
this.virConnect = virConnect;
- libvirt = virConnect.libvirt;
}
/**
diff --git a/src/main/java/org/libvirt/Interface.java b/src/main/java/org/libvirt/Interface.java
index 17c189d..684adca 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 org.libvirt.jna.Libvirt;
+import static org.libvirt.Library.libvirt;
/**
* A device which is attached to a node
@@ -24,11 +25,6 @@ public class Interface {
private Connect virConnect;
/**
- * The libvirt connection from the hypervisor
- */
- protected Libvirt libvirt;
-
- /**
* Constructs an Interface object from an InterfacePointer, and a Connect
* object.
*
@@ -40,7 +36,6 @@ public class Interface {
Interface(Connect virConnect, InterfacePointer VIP) {
this.virConnect = virConnect;
this.VIP = VIP;
- libvirt = virConnect.libvirt;
}
/**
diff --git a/src/main/java/org/libvirt/Library.java b/src/main/java/org/libvirt/Library.java
new file mode 100644
index 0000000..035ed06
--- /dev/null
+++ b/src/main/java/org/libvirt/Library.java
@@ -0,0 +1,26 @@
+package org.libvirt;
+
+import org.libvirt.jna.Libvirt;
+
+/**
+ * This class represents an instance of the JNA mapped libvirt
+ * library.
+ *
+ * The library will get loaded when first accessing this class.
+ */
+final class Library {
+ final static Libvirt libvirt;
+
+ // Load the native part
+ static {
+ Libvirt.INSTANCE.virInitialize();
+ libvirt = Libvirt.INSTANCE;
+ try {
+ ErrorHandler.processError(Libvirt.INSTANCE);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private Library() {}
+}
diff --git a/src/main/java/org/libvirt/Network.java b/src/main/java/org/libvirt/Network.java
index acaef0e..bdb0d78 100644
--- a/src/main/java/org/libvirt/Network.java
+++ b/src/main/java/org/libvirt/Network.java
@@ -2,6 +2,7 @@ package org.libvirt;
import org.libvirt.jna.Libvirt;
import org.libvirt.jna.NetworkPointer;
+import static org.libvirt.Library.libvirt;
import com.sun.jna.Native;
import com.sun.jna.ptr.IntByReference;
@@ -22,11 +23,6 @@ public class Network {
protected Connect virConnect;
/**
- * The libvirt connection from the hypervisor
- */
- protected Libvirt libvirt;
-
- /**
* Constructs a Network object from a known native virNetworkPtr, and a
* Connect object. For use when native libvirt returns a virConnectPtr, i.e.
* error handling.
@@ -37,7 +33,6 @@ public class Network {
Network(Connect virConnect, NetworkPointer VNP) {
this.virConnect = virConnect;
this.VNP = VNP;
- libvirt = virConnect.libvirt;
}
/**
diff --git a/src/main/java/org/libvirt/NetworkFilter.java b/src/main/java/org/libvirt/NetworkFilter.java
index 7bc07a5..ba4d2ea 100644
--- a/src/main/java/org/libvirt/NetworkFilter.java
+++ b/src/main/java/org/libvirt/NetworkFilter.java
@@ -2,6 +2,7 @@ package org.libvirt;
import org.libvirt.jna.Libvirt;
import org.libvirt.jna.NetworkFilterPointer;
+import static org.libvirt.Library.libvirt;
import com.sun.jna.Native;
@@ -16,15 +17,9 @@ public class NetworkFilter {
*/
private Connect virConnect;
- /**
- * The libvirt connection from the hypervisor
- */
- protected Libvirt libvirt;
-
public NetworkFilter(Connect virConnect, NetworkFilterPointer NFP) {
this.NFP = NFP;
this.virConnect = virConnect;
- libvirt = virConnect.libvirt;
}
@Override
diff --git a/src/main/java/org/libvirt/Secret.java b/src/main/java/org/libvirt/Secret.java
index 888cdf3..5332e02 100644
--- a/src/main/java/org/libvirt/Secret.java
+++ b/src/main/java/org/libvirt/Secret.java
@@ -2,6 +2,7 @@ package org.libvirt;
import org.libvirt.jna.Libvirt;
import org.libvirt.jna.SecretPointer;
+import static org.libvirt.Library.libvirt;
import com.sun.jna.Native;
import com.sun.jna.NativeLong;
@@ -24,15 +25,9 @@ public class Secret {
*/
private Connect virConnect;
- /**
- * The libvirt connection from the hypervisor
- */
- protected Libvirt libvirt;
-
Secret(Connect virConnect, SecretPointer VSP) {
this.virConnect = virConnect;
this.VSP = VSP;
- libvirt = virConnect.libvirt;
}
@Override
diff --git a/src/main/java/org/libvirt/StoragePool.java b/src/main/java/org/libvirt/StoragePool.java
index 29a18ed..2d59f68 100644
--- a/src/main/java/org/libvirt/StoragePool.java
+++ b/src/main/java/org/libvirt/StoragePool.java
@@ -4,6 +4,7 @@ import org.libvirt.jna.Libvirt;
import org.libvirt.jna.StoragePoolPointer;
import org.libvirt.jna.StorageVolPointer;
import org.libvirt.jna.virStoragePoolInfo;
+import static org.libvirt.Library.libvirt;
import com.sun.jna.Native;
import com.sun.jna.ptr.IntByReference;
@@ -50,11 +51,6 @@ public class StoragePool {
protected Connect virConnect;
/**
- * the libvirt instance
- */
- protected Libvirt libvirt;
-
- /**
* Constructs a VirStoragePool object from a known native virStoragePoolPtr,
* and a VirConnect object. For use when native libvirt returns a
* virStoragePoolPtr, i.e. error handling.
@@ -67,7 +63,6 @@ public class StoragePool {
StoragePool(Connect virConnect, StoragePoolPointer VSPP) {
this.virConnect = virConnect;
this.VSPP = VSPP;
- libvirt = virConnect.libvirt;
}
/**
diff --git a/src/main/java/org/libvirt/StorageVol.java b/src/main/java/org/libvirt/StorageVol.java
index e2bc717..4b9db80 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.Libvirt;
import org.libvirt.jna.StoragePoolPointer;
import org.libvirt.jna.StorageVolPointer;
import org.libvirt.jna.virStorageVolInfo;
+import static org.libvirt.Library.libvirt;
/**
* An acutal storage bucket.
@@ -43,11 +44,6 @@ public class StorageVol {
protected Connect virConnect;
/**
- * the libvirt instance
- */
- protected Libvirt libvirt;
-
- /**
* Constructs a VirStorageVol object from a known native virStoragePoolPtr,
* and a VirConnect object. For use when native libvirt returns a
* virStorageVolPtr, i.e. error handling.
@@ -60,7 +56,6 @@ public class StorageVol {
StorageVol(Connect virConnect, StorageVolPointer VSVP) {
this.virConnect = virConnect;
this.VSVP = VSVP;
- libvirt = virConnect.libvirt;
}
/**
diff --git a/src/main/java/org/libvirt/Stream.java b/src/main/java/org/libvirt/Stream.java
index 06b67cf..84e300c 100644
--- a/src/main/java/org/libvirt/Stream.java
+++ b/src/main/java/org/libvirt/Stream.java
@@ -2,6 +2,7 @@ package org.libvirt;
import org.libvirt.jna.Libvirt;
import org.libvirt.jna.StreamPointer;
+import static org.libvirt.Library.libvirt;
import com.sun.jna.NativeLong;
@@ -19,15 +20,9 @@ public class Stream {
*/
private Connect virConnect;
- /**
- * The libvirt connection from the hypervisor
- */
- protected Libvirt libvirt;
-
Stream(Connect virConnect, StreamPointer VSP) {
this.virConnect = virConnect;
this.VSP = VSP;
- libvirt = virConnect.libvirt;
}
/**
--
AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany
Phone: +49 341 265 310 19
Web:<http://www.av-test.org>
Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076)
Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern
12 years, 1 month