[libvirt] [PATCH] python: Avoid memory leaks on libvirt_virNodeGetCPUStats
by ajia@redhat.com
From: Alex Jia <ajia(a)redhat.com>
Detected by valgrind. Leaks are introduced in commit 4955602.
* python/libvirt-override.c (libvirt_virNodeGetCPUStats): fix memory leaks
and improve codes return value.
For details, please see the following link:
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=770943
Signed-off-by: Alex Jia <ajia(a)redhat.com>
---
python/libvirt-override.c | 46 ++++++++++++++++++++++++++++++--------------
1 files changed, 31 insertions(+), 15 deletions(-)
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index 792cfa3..6e076bc 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -2503,7 +2503,9 @@ libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED, PyObject *arg
static PyObject *
libvirt_virNodeGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
{
- PyObject *ret;
+ PyObject *ret = NULL;
+ PyObject *key = NULL;
+ PyObject *val = NULL;
PyObject *pyobj_conn;
virConnectPtr conn;
unsigned int flags;
@@ -2512,39 +2514,53 @@ libvirt_virNodeGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
virNodeCPUStatsPtr stats = NULL;
if (!PyArg_ParseTuple(args, (char *)"Oii:virNodeGetCPUStats", &pyobj_conn, &cpuNum, &flags))
- return(NULL);
+ return ret;
conn = (virConnectPtr)(PyvirConnect_Get(pyobj_conn));
LIBVIRT_BEGIN_ALLOW_THREADS;
c_retval = virNodeGetCPUStats(conn, cpuNum, NULL, &nparams, flags);
LIBVIRT_END_ALLOW_THREADS;
if (c_retval < 0)
- return VIR_PY_NONE;
+ return ret;
if (nparams) {
if (VIR_ALLOC_N(stats, nparams) < 0)
- return VIR_PY_NONE;
+ return PyErr_NoMemory();
LIBVIRT_BEGIN_ALLOW_THREADS;
c_retval = virNodeGetCPUStats(conn, cpuNum, stats, &nparams, flags);
LIBVIRT_END_ALLOW_THREADS;
- if (c_retval < 0) {
- VIR_FREE(stats);
- return VIR_PY_NONE;
- }
- }
- if (!(ret = PyDict_New())) {
- VIR_FREE(stats);
- return VIR_PY_NONE;
+ if (c_retval < 0)
+ goto error;
}
+
+ if (!(ret = PyDict_New()))
+ goto error;
+
for (i = 0; i < nparams; i++) {
- PyDict_SetItem(ret,
- libvirt_constcharPtrWrap(stats[i].field),
- libvirt_ulonglongWrap(stats[i].value));
+ key = libvirt_constcharPtrWrap(stats[i].field);
+ val = libvirt_ulonglongWrap(stats[i].value);
+
+ if (!key || !val)
+ goto error;
+
+ if (PyDict_SetItem(ret, key, val) < 0) {
+ Py_DECREF(ret);
+ goto error;
+ }
+
+ Py_DECREF(key);
+ Py_DECREF(val);
}
VIR_FREE(stats);
return ret;
+
+error:
+ VIR_FREE(stats);
+ Py_XDECREF(key);
+ Py_XDECREF(val);
+ return ret;
}
static PyObject *
--
1.7.1
12 years, 10 months
[libvirt] [PATCH] nwfilter: improved logging during driver initialization
by Stefan Berger
Improve the logging during nwfilter driver initialization when testing the
command line tools.
---
src/nwfilter/nwfilter_ebiptables_driver.c | 41
+++++++++++++++++++++---------
1 file changed, 29 insertions(+), 12 deletions(-)
Index: libvirt-acl/src/nwfilter/nwfilter_ebiptables_driver.c
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_ebiptables_driver.c
+++ libvirt-acl/src/nwfilter/nwfilter_ebiptables_driver.c
@@ -4036,6 +4036,7 @@ static int
ebiptablesDriverInit(bool privileged)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
+ char *errmsg = NULL;
if (!privileged)
return 0;
@@ -4056,8 +4057,14 @@ ebiptablesDriverInit(bool privileged)
"%s",
CMD_STOPONERR(1));
- if (ebiptablesExecCLI(&buf, NULL, NULL) < 0)
- VIR_FREE(ebtables_cmd_path);
+ if (ebiptablesExecCLI(&buf, NULL, &errmsg) < 0) {
+ VIR_FREE(ebtables_cmd_path);
+ VIR_ERROR(_("Testing of ebtables command failed%s%s."),
+ errmsg ? ": " : "",
+ errmsg ? errmsg : "");
+ }
+ } else {
+ VIR_WARN(_("Could not find 'ebtables' executable."));
}
iptables_cmd_path = virFindFileInPath("iptables");
@@ -4070,8 +4077,14 @@ ebiptablesDriverInit(bool privileged)
"%s",
CMD_STOPONERR(1));
- if (ebiptablesExecCLI(&buf, NULL, NULL) < 0)
- VIR_FREE(iptables_cmd_path);
+ if (ebiptablesExecCLI(&buf, NULL, &errmsg) < 0) {
+ VIR_FREE(iptables_cmd_path);
+ VIR_ERROR(_("Testing of iptables command failed%s%s."),
+ errmsg ? ": " : "",
+ errmsg ? errmsg : "");
+ }
+ } else {
+ VIR_WARN(_("Could not find 'iptables' executable."));
}
ip6tables_cmd_path = virFindFileInPath("ip6tables");
@@ -4084,25 +4097,29 @@ ebiptablesDriverInit(bool privileged)
"%s",
CMD_STOPONERR(1));
- if (ebiptablesExecCLI(&buf, NULL, NULL) < 0)
- VIR_FREE(ip6tables_cmd_path);
+ if (ebiptablesExecCLI(&buf, NULL, &errmsg) < 0) {
+ VIR_FREE(ip6tables_cmd_path);
+ VIR_ERROR(_("Testing of ip6tables command failed%s%s."),
+ errmsg ? ": " : "",
+ errmsg ? errmsg : "");
+ }
+ } else {
+ VIR_WARN(_("Could not find 'ip6tables' executable."));
}
/* ip(6)tables support needs gawk & grep, ebtables doesn't */
if ((iptables_cmd_path != NULL || ip6tables_cmd_path != NULL) &&
(!grep_cmd_path || !gawk_cmd_path)) {
- virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("essential tools to support ip(6)tables "
- "firewalls could not be located"));
+ VIR_ERROR(_("essential tools to support ip(6)tables "
+ "firewalls could not be located"));
VIR_FREE(iptables_cmd_path);
VIR_FREE(ip6tables_cmd_path);
}
+ VIR_FREE(errmsg);
if (!ebtables_cmd_path && !iptables_cmd_path && !ip6tables_cmd_path) {
- virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("firewall tools were not found or "
- "cannot be used"));
+ VIR_ERROR(_("firewall tools were not found or cannot be used"));
ebiptablesDriverShutdown();
return -ENOTSUP;
}
12 years, 10 months
[libvirt] [PATCHv2] qemu: Prevent crash of libvirtd without guest agent
by ajia@redhat.com
From: Alex Jia <ajia(a)redhat.com>
* src/qemu/qemu_process.c (qemuFindAgentConfig): avoid crash libvirtd due to
deref a NULL pointer.
* How to reproduce?
1. virsh edit the following xml into guest configuration:
<channel type='pty'>
<target type='virtio'/>
</channel>
2. virsh start <domain>
or
% virt-install -n foo -r 1024 --disk path=/var/lib/libvirt/images/foo.img,size=1 \
--channel pty,target_type=virtio -l <installation tree>
Signed-off-by: Alex Jia <ajia(a)redhat.com>
---
src/qemu/qemu_process.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 939a83d..41218de 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -194,7 +194,7 @@ qemuFindAgentConfig(virDomainDefPtr def)
if (channel->targetType != VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO)
continue;
- if (STREQ(channel->target.name, "org.qemu.guest_agent.0")) {
+ if (STREQ_NULLABLE(channel->target.name, "org.qemu.guest_agent.0")) {
config = &channel->source;
break;
}
--
1.7.1
12 years, 10 months
[libvirt] [PATCH] qemu: Unlock monitor when connecting to dest qemu fails
by Jiri Denemark
When migrating a qemu domain, we enter the monitor, send some commands,
try to connect to destination qemu, send other commands, end exit the
monitor. However, if we couldn't connect to destination qemu we forgot
to exit the monitor.
Bug introduced by commit d9d518b1c8ef3b65658cc91f85ba33a63c0959a4.
---
src/qemu/qemu_migration.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 12cfbde..ea4185e 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1624,8 +1624,10 @@ qemuMigrationRun(struct qemud_driver *driver,
/* connect to the destination qemu if needed */
if (spec->destType == MIGRATION_DEST_CONNECT_HOST &&
- qemuMigrationConnect(driver, vm, spec) < 0)
+ qemuMigrationConnect(driver, vm, spec) < 0) {
+ qemuDomainObjExitMonitorWithDriver(driver, vm);
goto cleanup;
+ }
switch (spec->destType) {
case MIGRATION_DEST_HOST:
--
1.7.8.4
12 years, 10 months
[libvirt] [PATCH] qemu: Fix segfault when CPU host is empty
by Jiri Denemark
In case libvirtd cannot detect host CPU model (which may happen if it
runs inside a virtual machine), the daemon is likely to segfault when
starting a new qemu domain. It segfaults when domain XML asks for host
(either model or passthrough) CPU or does not ask for any specific CPU
model at all.
---
src/qemu/qemu_command.c | 24 ++++++++++++------------
1 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 99d7129..5633dfd 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3508,22 +3508,13 @@ qemuBuildCpuArgStr(const struct qemud_driver *driver,
*hasHwVirt = false;
- if (def->cpu &&
- (def->cpu->mode != VIR_CPU_MODE_CUSTOM || def->cpu->model)) {
- if (!(cpu = virCPUDefCopy(def->cpu)))
- goto cleanup;
- if (cpu->mode != VIR_CPU_MODE_CUSTOM &&
- !migrating &&
- cpuUpdate(cpu, host) < 0)
- goto cleanup;
- }
-
if (STREQ(def->os.arch, "i686"))
default_model = "qemu32";
else
default_model = "qemu64";
- if (cpu) {
+ if (def->cpu &&
+ (def->cpu->mode != VIR_CPU_MODE_CUSTOM || def->cpu->model)) {
virCPUCompareResult cmp;
const char *preferred;
int hasSVM;
@@ -3539,6 +3530,14 @@ qemuBuildCpuArgStr(const struct qemud_driver *driver,
goto cleanup;
}
+ if (!(cpu = virCPUDefCopy(def->cpu)))
+ goto cleanup;
+
+ if (cpu->mode != VIR_CPU_MODE_CUSTOM &&
+ !migrating &&
+ cpuUpdate(cpu, host) < 0)
+ goto cleanup;
+
cmp = cpuGuestData(host, cpu, &data);
switch (cmp) {
case VIR_CPU_COMPARE_INCOMPATIBLE:
@@ -3647,7 +3646,8 @@ qemuBuildCpuArgStr(const struct qemud_driver *driver,
ret = 0;
cleanup:
- cpuDataFree(host->arch, data);
+ if (host)
+ cpuDataFree(host->arch, data);
virCPUDefFree(guest);
virCPUDefFree(cpu);
--
1.7.8.4
12 years, 10 months
[libvirt] [PATCH v2] storage: Allow runtime detection of scrub
by Michal Privoznik
Currently, if scrub (used for wiping algorithms) is not present
at compile time, we don't support any other wiping algorithms than
zeroing, even if it was installed later. Switch to runtime detection
instead.
---
diff to v1:
-Add BuildRequires to spec file
configure.ac | 30 ++++--------------------------
libvirt.spec.in | 3 +++
src/storage/storage_driver.c | 4 ----
3 files changed, 7 insertions(+), 30 deletions(-)
diff --git a/configure.ac b/configure.ac
index 67351d9..5320f71 100644
--- a/configure.ac
+++ b/configure.ac
@@ -213,6 +213,8 @@ AC_PATH_PROG([UDEVSETTLE], [udevsettle], [],
[/sbin:/usr/sbin:/usr/local/sbin:$PATH])
AC_PATH_PROG([MODPROBE], [modprobe], [],
[/sbin:/usr/sbin:/usr/local/sbin:$PATH])
+AC_PATH_PROG([SCRUB], [scrub], [],
+ [/sbin:/usr/sbin:/usr/local/sbin:$PATH])
AC_DEFINE_UNQUOTED([DNSMASQ],["$DNSMASQ"],
[Location or name of the dnsmasq program])
@@ -232,6 +234,8 @@ if test -n "$MODPROBE"; then
AC_DEFINE_UNQUOTED([MODPROBE],["$MODPROBE"],
[Location or name of the modprobe program])
fi
+AC_DEFINE_UNQUOTED([SCRUB],["$SCRUB"],
+ [Location or name of the scrub program (for wiping algorithms)])
dnl Specific dir for HTML output ?
AC_ARG_WITH([html-dir], [AC_HELP_STRING([--with-html-dir=path],
@@ -2500,32 +2504,6 @@ AM_CONDITIONAL([HAVE_LIBNL], [test "$have_libnl" = "yes"])
AC_SUBST([LIBNL_CFLAGS])
AC_SUBST([LIBNL_LIBS])
-dnl scrub program for different volume wiping algorithms
-
-AC_ARG_WITH([scrub],
- AC_HELP_STRING([--with-scrub], [enable different volume wiping algorithms
- @<:@default=check@:>@]),
- [with_macvtap=${withval}],
- [with_scrub=check])
-
-if test "$with_scrub" != "no"; then
- AC_PATH_PROG([SCRUB], [scrub])
- if test -z "$SCRUB" ; then
- if test "$with_scrub" = "check"; then
- with_scrub=no
- else
- AC_MSG_ERROR([You must install the 'scrub' binary to enable
- different volume wiping algorithms])
- fi
- else
- with_scrub=yes
- fi
- if test "$with_scrub" = "yes"; then
- AC_DEFINE_UNQUOTED([SCRUB], ["$SCRUB"],
- [Location of the scrub program])
- fi
-fi
-
# Only COPYING.LIB is under version control, yet COPYING
# is included as part of the distribution tarball.
# Copy one to the other, but only if this is a srcdir-build.
diff --git a/libvirt.spec.in b/libvirt.spec.in
index e48d8b8..3f0f19a 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -513,6 +513,9 @@ BuildRequires: nfs-utils
# Fedora build root suckage
BuildRequires: gawk
+# For storage wiping with different algorithms
+BuildRequires: scrub
+
%description
Libvirt is a C toolkit to interact with the virtualization capabilities
of recent versions of Linux (and other OSes). The main package includes
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 9170a17..df0e291 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1918,7 +1918,6 @@ storageVolumeWipeInternal(virStorageVolDefPtr def,
if (algorithm != VIR_STORAGE_VOL_WIPE_ALG_ZERO) {
const char *alg_char ATTRIBUTE_UNUSED = NULL;
switch (algorithm) {
-#ifdef SCRUB
case VIR_STORAGE_VOL_WIPE_ALG_NNSA:
alg_char = "nnsa";
break;
@@ -1943,13 +1942,11 @@ storageVolumeWipeInternal(virStorageVolDefPtr def,
case VIR_STORAGE_VOL_WIPE_ALG_RANDOM:
alg_char = "random";
break;
-#endif
default:
virStorageReportError(VIR_ERR_INVALID_ARG,
_("unsupported algorithm %d"),
algorithm);
}
-#ifdef SCRUB
cmd = virCommandNew(SCRUB);
virCommandAddArgList(cmd, "-f", "-p", alg_char,
def->target.path, NULL);
@@ -1958,7 +1955,6 @@ storageVolumeWipeInternal(virStorageVolDefPtr def,
goto out;
ret = 0;
-#endif
goto out;
} else {
if (S_ISREG(st.st_mode) && st.st_blocks < (st.st_size / DEV_BSIZE)) {
--
1.7.3.4
12 years, 10 months
[libvirt] question about guest status
by Wen Congyang
Hi all:
If the guest runs on xen, we can know the guest OS paniced, and the guest status
is paniced. But if the guest runs on qemu/kvm, we need the same feature. And the
feature to know guest-is-panic is a very very good feature for enterprise.
We have some ways to know that guest has paniced:
1. watchdog timeouts
It is not a good way, because we can not say "the guest is paniced" in 100% accuracy
2. use a PV driver(like the XEN)
The old RHELs do not have such driver...
It can not work for the second kernel...
3. Adding a function for console-logging (in ring buffer or some) and check messages
given by guests. If we allow some filtering script or some, we can catch Linux's
panic messages. We can say the guest paniced if we catch such messages. We may be
able to catch other events by other script
I prefer to 3 now. Does anyone have a better idea?
Thanks
Wen Congyang
12 years, 10 months
[libvirt] [PATCH] daemon: fix logic bug with virAsprintf
by Eric Blake
Regression introduced in commit 7033c5f2, due to improper conversion
from snprintf to virAsprintf.
* daemon/remote.c (remoteDispatchAuthList): Check return value
correctly.
---
This one's embarrassing. I think I broke polkit authorization in
0.9.10. :(
daemon/remote.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/daemon/remote.c b/daemon/remote.c
index 9c61306..724db23 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -2052,7 +2052,7 @@ remoteDispatchAuthList(virNetServerPtr server ATTRIBUTE_UNUSED,
} else if (callerUid == 0) {
char *ident;
if (virAsprintf(&ident, "pid:%lld,uid:%d",
- (long long) callerPid, callerUid) == 0) {
+ (long long) callerPid, callerUid) >= 0) {
VIR_INFO("Bypass polkit auth for privileged client %s",
ident);
if (virNetServerClientSetIdentity(client, ident) < 0)
--
1.7.7.6
12 years, 10 months
[libvirt] [PATCH] Fix build with polkit0
by Jim Fehlig
Commit 8dd623b9 introduced a build error with --enable-compile-warnings=error
remote.c:2593: error: unused variable 'rv' [-Wunused-variable]
Pushing under build-breaker rule.
---
daemon/remote.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/daemon/remote.c b/daemon/remote.c
index 724db23..ed27053 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -2590,7 +2590,6 @@ remoteDispatchAuthPolkit(virNetServerPtr server,
DBusError err;
const char *action;
char *ident = NULL;
- int rv = -1;
struct daemonClientPrivate *priv =
virNetServerClientGetPrivateData(client);
--
1.7.7
12 years, 10 months