[libvirt] [PATCH] qemu: Fix memory leak when building -cpu argument
by Jiri Denemark
Reported by Alex Jia:
==21503== 112 (32 direct, 80 indirect) bytes in 1 blocks are
definitely lost in loss record 37 of 40
==21503== at 0x4A04A28: calloc (vg_replace_malloc.c:467)
==21503== by 0x4A8991: virAlloc (memory.c:101)
==21503== by 0x505A6C: x86DataCopy (cpu_x86.c:247)
==21503== by 0x507B34: x86Compute (cpu_x86.c:1225)
==21503== by 0x43103C: qemuBuildCommandLine (qemu_command.c:3561)
==21503== by 0x41C9F7: testCompareXMLToArgvHelper
(qemuxml2argvtest.c:183)
==21503== by 0x41E10D: virtTestRun (testutils.c:141)
==21503== by 0x41B942: mymain (qemuxml2argvtest.c:705)
==21503== by 0x41D7E7: virtTestMain (testutils.c:696)
---
I should really stop postponing my work to emebed the architecture into
cpu data so that cpuDataFree() only needs one argument.
src/qemu/qemu_command.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 0e26df1..a346f1e 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3666,8 +3666,7 @@ qemuBuildCpuArgStr(const struct qemud_driver *driver,
ret = 0;
cleanup:
- if (guest)
- cpuDataFree(guest->arch, data);
+ cpuDataFree(host->arch, data);
virCPUDefFree(guest);
virCPUDefFree(cpu);
--
1.7.8.4
12 years, 9 months
[libvirt] [PATCH] Update symbols file for virFileDirectFd/virFileWrapperFd rename
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
---
src/libvirt_private.syms | 7 +++----
1 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index d6ad36c..eeafd38 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1158,10 +1158,9 @@ virAuditSend;
# virfile.h
virFileClose;
-virFileDirectFdClose;
-virFileDirectFdFlag;
-virFileDirectFdFree;
-virFileDirectFdNew;
+virFileWrapperFdClose;
+virFileWrapperFdFree;
+virFileWrapperFdNew;
virFileFclose;
virFileFdopen;
virFileRewrite;
--
1.7.7.6
12 years, 9 months
[libvirt] [PATCH] Populate /dev/std{in, out, err} symlinks in LXC containers
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
Some applications expect /dev/std{in,out,err} to exist. Populate
them during container startup as symlinks to /proc/self/fd
---
src/lxc/lxc_container.c | 17 +++++++++++++++++
1 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 04af39b..cb51bbc 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -584,6 +584,14 @@ static int lxcContainerPopulateDevices(char **ttyPaths, size_t nttyPaths)
{ LXC_DEV_MAJ_MEMORY, LXC_DEV_MIN_RANDOM, 0666, "/dev/random" },
{ LXC_DEV_MAJ_MEMORY, LXC_DEV_MIN_URANDOM, 0666, "/dev/urandom" },
};
+ const struct {
+ const char *src;
+ const char *dst;
+ } links[] = {
+ { "/proc/self/fd/0", "/dev/stdin" },
+ { "/proc/self/fd/1", "/dev/stdout" },
+ { "/proc/self/fd/2", "/dev/stderr" },
+ };
/* Populate /dev/ with a few important bits */
for (i = 0 ; i < ARRAY_CARDINALITY(devs) ; i++) {
@@ -597,6 +605,15 @@ static int lxcContainerPopulateDevices(char **ttyPaths, size_t nttyPaths)
}
}
+ for (i = 0 ; i < ARRAY_CARDINALITY(links) ; i++) {
+ if (symlink(links[i].src, links[i].dst) < 0) {
+ virReportSystemError(errno,
+ _("Failed to symlink device %s to %s"),
+ links[i].dst, links[i].src);
+ return -1;
+ }
+ }
+
if (access("/dev/pts/ptmx", W_OK) == 0) {
/* We have private devpts capability, so bind that */
if (virFileTouch("/dev/ptmx", 0666) < 0)
--
1.7.7.6
12 years, 9 months
[libvirt] [PATCH] Replace truncate() with ftruncate()
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
Mingw32 does not have any truncate() API defined, but it does
have ftruncate(). So replace use of the former with the latter
---
src/util/storage_file.c | 23 ++++++++++++++++++++---
1 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/src/util/storage_file.c b/src/util/storage_file.c
index 8260adb..a8661e3 100644
--- a/src/util/storage_file.c
+++ b/src/util/storage_file.c
@@ -939,12 +939,29 @@ virStorageFileFreeMetadata(virStorageFileMetadata *meta)
int
virStorageFileResize(const char *path, unsigned long long capacity)
{
- if (truncate(path, capacity) < 0) {
+ int fd = -1;
+ int ret = -1;
+
+ if ((fd = open(path, O_RDWR)) < 0) {
+ virReportSystemError(errno, _("Unable to open '%s'"), path);
+ goto cleanup;
+ }
+
+ if (ftruncate(fd, capacity) < 0) {
virReportSystemError(errno, _("Failed to truncate file '%s'"), path);
- return -1;
+ goto cleanup;
}
- return 0;
+ if (VIR_CLOSE(fd) < 0) {
+ virReportSystemError(errno, _("Unable to save '%s'"), path);
+ goto cleanup;
+ }
+
+ ret = 0;
+
+cleanup:
+ VIR_FORCE_CLOSE(fd);
+ return ret;
}
#ifdef __linux__
--
1.7.7.6
12 years, 9 months
[libvirt] [PATCH 0/2] Don't lose running domains configured with no seclabel
by Jiri Denemark
It's not exactly obvious but these two patches fix quite an ugly bug affecting
setups without any useful security driver (i.e., either explicitly or
implicitly using driver 'none').
When a domain is defined without any <seclabel> element in its XML and started
by libvirt, an incorrect <seclabel> element is put into its runtime XML
configuration which causes such domain to disappear from libvirt when libvirtd
is restarted. Without these patches, the incorrect element is
<seclabel type='dynamic' relabel='yes'/>
after applying patch 2/2, the element is
<seclabel type='none' relabel='yes'/>
which is still wrong and after applying both of these patches, correct element
<seclabel type='none'/>
is placed into the runtime XML configuration.
Jiri Denemark (2):
seclabel: Do not output relabel attribute for type 'none'
security: Driver 'none' cannot create confined guests
src/conf/domain_conf.c | 9 +++++----
src/security/security_manager.c | 20 ++++++++++++++++++++
.../qemuxml2argv-seclabel-none.xml | 2 +-
tests/seclabeltest.c | 2 +-
4 files changed, 27 insertions(+), 6 deletions(-)
--
1.7.8.4
12 years, 9 months
[libvirt] libvirt build errors
by Chandrashekhar Jamadarkhani (cjamadar)
Hi,
While doing make, I got below errors. Got same build errors for
libvirt-0.9.8 and libvirt-0.9.9. Appreciate your help on this.
CC libvirt_driver_nwfilter_la-nwfilter_driver.lo
CC libvirt_driver_nwfilter_la-nwfilter_gentech_driver.lo
CC libvirt_driver_nwfilter_la-nwfilter_ebiptables_driver.lo
CC libvirt_driver_nwfilter_la-nwfilter_learnipaddr.lo
In file included from
/usr/cisco/packages/libpcap/libpcap-1.0.0/include/pcap.h:45,
from nwfilter/nwfilter_learnipaddr.c:29:
/usr/cisco/packages/libpcap/libpcap-1.0.0/include/pcap/pcap.h:339:
warning: redundant redeclaration of 'bpf_filter' [-Wredundant-decls]
/usr/cisco/packages/libpcap/libpcap-1.0.0/include/pcap/bpf.h:919:
warning: previous declaration of 'bpf_filter' was here
/usr/cisco/packages/libpcap/libpcap-1.0.0/include/pcap/pcap.h:340:
warning: redundant redeclaration of 'bpf_validate' [-Wredundant-decls]
/usr/cisco/packages/libpcap/libpcap-1.0.0/include/pcap/bpf.h:918:
warning: previous declaration of 'bpf_validate' was here
CCLD libvirt_driver_nwfilter.la
libtool: link: require no space between `-L' and
`/usr/cisco/packages/libpcap/libpcap-1.0.0/lib'
make[3]: *** [libvirt_driver_nwfilter.la] Error 1
make[3]: Leaving directory `/nobackup/vsm/libvirt-0.9.8/src'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/nobackup/vsm/libvirt-0.9.8/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/nobackup/vsm/libvirt-0.9.8'
make: *** [all] Error 2
[root@blr-vxr-009 libvirt-0.9.8]#
Thanks,
Chandrashekhar
12 years, 9 months
[libvirt] [test-API][PATCH] Add new APIs and fix problems in connectAPI
by Wayne Sun
* add 8 new APIs
get_sys_info(self, flag = 0)
get_memory_stats(self, cellNum, flag = 0)
get_cpu_stats(self, cpuNum, flag = 0)
is_alive(self)
change_begin(self, flag = 0)
change_commit(self, flag = 0)
change_rollback(self, flag = 0)
suspend_for_duration(self, target, duration, flag = 0)
* remove outdated ref(self, uri) function
* fix typo in following functions
migrate(self, domain, flags, dname, uri, bandwidth)
networkLookupByUUID(self, uuid)
numOfDefinedDomains(self)
numOfDomains(self)
nwfilterLookupByUUID(self, uuid)
---
lib/connectAPI.py | 83 ++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 72 insertions(+), 11 deletions(-)
diff --git a/lib/connectAPI.py b/lib/connectAPI.py
index 9f2b728..87b0a59 100644
--- a/lib/connectAPI.py
+++ b/lib/connectAPI.py
@@ -105,6 +105,15 @@ class ConnectAPI(object):
code = e.get_error_code()
raise exception.LibvirtAPI(message, code)
+ def get_sys_info(self, flag = 0):
+ try:
+ sysinfo = self.conn.getSysinfo(flag)
+ return sysinfo
+ except libvirt.libvirtError, e:
+ message = e.get_error_message()
+ code = e.get_error_code()
+ raise exception.LibvirtAPI(message, code)
+
def get_type(self):
try:
type = self.conn.getType()
@@ -123,19 +132,18 @@ class ConnectAPI(object):
code = e.get_error_code()
raise exception.LibvirtAPI(message, code)
- def ref(self, uri):
+ def get_cells_free_memory(self, startCell, maxCells):
try:
- refer = self.conn.ref()
- return refer
+ cfreemem = self.conn.getCellsFreeMemory(startCell, maxCells)
+ return cfreemem
except libvirt.libvirtError, e:
message = e.get_error_message()
code = e.get_error_code()
raise exception.LibvirtAPI(message, code)
- def get_cells_free_memory(self, startCell, maxCells):
+ def get_memory_stats(self, cellNum, flag = 0):
try:
- cfreemem = self.conn.getCellsFreeMemory(startCell, maxCells)
- return cfreemem
+ return self.conn.getMemoryStats(cellNum, flag)
except libvirt.libvirtError, e:
message = e.get_error_message()
code = e.get_error_code()
@@ -158,6 +166,14 @@ class ConnectAPI(object):
code = e.get_error_code()
raise exception.LibvirtAPI(message, code)
+ def get_cpu_stats(self, cpuNum, flag = 0):
+ try:
+ return self.conn.getCPUStats(cpuNum, flag)
+ except libvirt.libvirtError, e:
+ message = e.get_error_message()
+ code = e.get_error_code()
+ raise exception.LibvirtAPI(message, code)
+
def compare_cpu(self, xmlDesc, flag = 0):
try:
return self.conn.compareCPU(xmlDesc, flag)
@@ -208,6 +224,14 @@ class ConnectAPI(object):
code = e.get_error_code()
raise exception.LibvirtAPI(message, code)
+ def is_alive(self):
+ try:
+ return self.conn.isAlive()
+ except libvirt.libvirtError, e:
+ message = e.get_error_message()
+ code = e.get_error_code()
+ raise exception.LibvirtAPI(message, code)
+
def isEncrypted(self):
try:
return self.conn.isEncrypted()
@@ -307,7 +331,7 @@ class ConnectAPI(object):
def migrate(self, domain, flags, dname, uri, bandwidth):
try:
- return self.migrate(self, domain, flags, dname, uri, bandwidth)
+ return self.conn.migrate(domain, flags, dname, uri, bandwidth)
except libvirt.libvirtError, e:
message = e.get_error_message()
code = e.get_error_code()
@@ -315,7 +339,7 @@ class ConnectAPI(object):
def networkLookupByUUID(self, uuid):
try:
- return self.networkLookupByUUID(self, uuid)
+ return self.conn.networkLookupByUUID(uuid)
except libvirt.libvirtError, e:
message = e.get_error_message()
code = e.get_error_code()
@@ -323,7 +347,7 @@ class ConnectAPI(object):
def numOfDefinedDomains(self):
try:
- return self.numOfDefinedDomains(self)
+ return self.conn.numOfDefinedDomains()
except libvirt.libvirtError, e:
message = e.get_error_message()
code = e.get_error_code()
@@ -331,7 +355,7 @@ class ConnectAPI(object):
def numOfDomains(self):
try:
- return self.numOfDomains(self)
+ return self.conn.numOfDomains()
except libvirt.libvirtError, e:
message = e.get_error_message()
code = e.get_error_code()
@@ -339,7 +363,39 @@ class ConnectAPI(object):
def nwfilterLookupByUUID(self, uuid):
try:
- return self.nwfilterLookupByUUID(self, uuid)
+ return self.conn.nwfilterLookupByUUID(uuid)
+ except libvirt.libvirtError, e:
+ message = e.get_error_message()
+ code = e.get_error_code()
+ raise exception.LibvirtAPI(message, code)
+
+ def change_begin(self, flag = 0):
+ try:
+ return self.conn.changeBegin(flag)
+ except libvirt.libvirtError, e:
+ message = e.get_error_message()
+ code = e.get_error_code()
+ raise exception.LibvirtAPI(message, code)
+
+ def change_commit(self, flag = 0):
+ try:
+ return self.conn.changeCommit(flag)
+ except libvirt.libvirtError, e:
+ message = e.get_error_message()
+ code = e.get_error_code()
+ raise exception.LibvirtAPI(message, code)
+
+ def change_rollback(self, flag = 0):
+ try:
+ return self.conn.changeRollback(flag)
+ except libvirt.libvirtError, e:
+ message = e.get_error_message()
+ code = e.get_error_code()
+ raise exception.LibvirtAPI(message, code)
+
+ def suspend_for_duration(self, target, duration, flag = 0):
+ try:
+ return self.conn.suspendForDuration(target, duration, flag)
except libvirt.libvirtError, e:
message = e.get_error_message()
code = e.get_error_code()
@@ -348,3 +404,8 @@ class ConnectAPI(object):
VIR_CRED_AUTHNAME = libvirt.VIR_CRED_AUTHNAME
VIR_CRED_PASSPHRASE = libvirt.VIR_CRED_PASSPHRASE
+# virNodeSuspendTarget
+VIR_NODE_SUSPEND_TARGET_MEM = 0
+VIR_NODE_SUSPEND_TARGET_DISK = 1
+VIR_NODE_SUSPEND_TARGET_HYBRID = 2
+VIR_NODE_SUSPEND_TARGET_LAST = 3
--
1.7.1
12 years, 9 months
[libvirt] [PATCH] virsh: update virsh desc help docs
by ajia@redhat.com
From: Alex Jia <ajia(a)redhat.com>
The function cmdDesc says 'current is ignored', so should remove related
part from help docs.
Signed-off-by: Alex Jia <ajia(a)redhat.com>
---
tools/virsh.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index c107d8c..e60ef5a 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -1038,7 +1038,6 @@ static const vshCmdOptDef opts_desc[] = {
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
{"live", VSH_OT_BOOL, 0, N_("modify/get running state")},
{"config", VSH_OT_BOOL, 0, N_("modify/get persistent configuration")},
- {"current", VSH_OT_BOOL, 0, N_("modify/get current state configuration")},
{"title", VSH_OT_BOOL, 0, N_("modify the title instead of description")},
{"edit", VSH_OT_BOOL, 0, N_("open an editor to modify the description")},
{"new-desc", VSH_OT_ARGV, 0, N_("message")},
--
1.7.1
12 years, 9 months
[libvirt] [PATCH] virsh: Plug memory leak on cmdDesc
by ajia@redhat.com
From: Alex Jia <ajia(a)redhat.com>
Forgot to free the domain object, this will intruduce resource leaks including
memory leak and FD leaks.
* tools/virsh.c(cmdDesc): fix memory leak.
* How to reproduce?
% virsh desc <domain>
No description for domain: <domain>
error: Failed to disconnect from the hypervisor, 1 leaked reference(s)
Signed-off-by: Alex Jia <ajia(a)redhat.com>
---
tools/virsh.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index bff7d5d..c107d8c 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -1167,6 +1167,8 @@ cleanup:
unlink(tmp);
VIR_FREE(tmp);
}
+ if (dom)
+ virDomainFree(dom);
return ret;
}
--
1.7.1
12 years, 9 months
[libvirt] [PATCH v2] virsh: Do not check the input XML at virsh layer for cmdDetachDevice
by Osier Yang
Any device XML doesn't use the same order as libvirt generates, or
uses decimal for attributes like "slot" of "<address>" will cause
device detaching to fail, as virsh compares the XML simply earlier
in strict manner before internal parsing.
This is regression introduced by ea7182c.
v1 is here:
https://www.redhat.com/archives/libvir-list/2012-January/msg00395.html
v1 - v2:
* The two useful functions is left unchanged, marked as unused.
---
tools/virsh.c | 23 +++++------------------
1 files changed, 5 insertions(+), 18 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index 72ca93a..7997cbb 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -13153,6 +13153,7 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd)
* @n2 second node
* returns true in case n1 covers n2, false otherwise.
*/
+__attribute__((unused))
static bool
vshNodeIsSuperset(xmlNodePtr n1, xmlNodePtr n2)
{
@@ -13278,6 +13279,7 @@ cleanup:
* (is too ambiguous), 0 in case of success. Otherwise returns -1. @newXML
* is touched only in case of success.
*/
+__attribute__((unused))
static int
vshCompleteXMLFromDomain(vshControl *ctl, virDomainPtr dom, char *oldXML,
char **newXML)
@@ -13412,7 +13414,7 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom = NULL;
const char *from = NULL;
- char *buffer = NULL, *new_buffer = NULL;
+ char *buffer = NULL;
int ret;
bool funcRet = false;
unsigned int flags;
@@ -13431,27 +13433,13 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd)
goto cleanup;
}
- ret = vshCompleteXMLFromDomain(ctl, dom, buffer, &new_buffer);
- if (ret < 0) {
- if (ret == -2) {
- vshError(ctl, _("no such device in %s"), virDomainGetName(dom));
- } else if (ret == -3) {
- vshError(ctl, "%s", _("given XML selects too many devices. "
- "Please, be more specific"));
- } else {
- /* vshCompleteXMLFromDomain() already printed error message,
- * so nothing to do here. */
- }
- goto cleanup;
- }
-
if (vshCommandOptBool(cmd, "persistent")) {
flags = VIR_DOMAIN_AFFECT_CONFIG;
if (virDomainIsActive(dom) == 1)
flags |= VIR_DOMAIN_AFFECT_LIVE;
- ret = virDomainDetachDeviceFlags(dom, new_buffer, flags);
+ ret = virDomainDetachDeviceFlags(dom, buffer, flags);
} else {
- ret = virDomainDetachDevice(dom, new_buffer);
+ ret = virDomainDetachDevice(dom, buffer);
}
if (ret < 0) {
@@ -13463,7 +13451,6 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd)
funcRet = true;
cleanup:
- VIR_FREE(new_buffer);
VIR_FREE(buffer);
virDomainFree(dom);
return funcRet;
--
1.7.7.3
12 years, 9 months