[libvirt] [PATCH] qemu: Exit on first error in qemuDomainGetMemoryParameters
by Matthias Bolte
There is no point in trying to fill params beyond the first error,
because when qemuDomainGetMemoryParameters returns -1 then the caller
cannot detect which values in params are valid.
---
There is a similar pattern in qemuDomainSetMemoryParameters that tries
to apply all given params even if one already failed. From a user's
POV it's probably better to apply all params without an error or to
apply non at all when one fails. But this is harder to implemeneted
and requires a rollback mechanism.
src/qemu/qemu_driver.c | 21 ++++++++-------------
1 files changed, 8 insertions(+), 13 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 6395c93..ae1d833 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9676,7 +9676,6 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
goto cleanup;
}
- ret = 0;
for (i = 0; i < *nparams; i++) {
virMemoryParameterPtr param = ¶ms[i];
val = 0;
@@ -9689,14 +9688,12 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
if (rc != 0) {
virReportSystemError(-rc, "%s",
_("unable to get memory hard limit"));
- ret = -1;
- continue;
+ goto cleanup;
}
if (virStrcpyStatic(param->field, VIR_DOMAIN_MEMORY_HARD_LIMIT) == NULL) {
qemuReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Field memory hard limit too long for destination"));
- ret = -1;
- continue;
+ goto cleanup;
}
param->value.ul = val;
break;
@@ -9706,14 +9703,12 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
if (rc != 0) {
virReportSystemError(-rc, "%s",
_("unable to get memory soft limit"));
- ret = -1;
- continue;
+ goto cleanup;
}
if (virStrcpyStatic(param->field, VIR_DOMAIN_MEMORY_SOFT_LIMIT) == NULL) {
qemuReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Field memory soft limit too long for destination"));
- ret = -1;
- continue;
+ goto cleanup;
}
param->value.ul = val;
break;
@@ -9723,14 +9718,12 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
if (rc != 0) {
virReportSystemError(-rc, "%s",
_("unable to get swap hard limit"));
- ret = -1;
- continue;
+ goto cleanup;
}
if (virStrcpyStatic(param->field, VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT) == NULL) {
qemuReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Field swap hard limit too long for destination"));
- ret = -1;
- continue;
+ goto cleanup;
}
param->value.ul = val;
break;
@@ -9741,6 +9734,8 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
}
}
+ ret = 0;
+
cleanup:
if (group)
virCgroupFree(&group);
--
1.7.0.4
14 years, 1 month
[libvirt] [PATCH] Fix formatting of the memtune XML element
by Matthias Bolte
Also output the min_guarantee element when set.
---
src/conf/domain_conf.c | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a997e06..6486f9c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6466,7 +6466,8 @@ char *virDomainDefFormat(virDomainDefPtr def,
def->mem.cur_balloon);
/* add memtune only if there are any */
- if(def->mem.hard_limit || def->mem.hard_limit || def->mem.hard_limit)
+ if (def->mem.hard_limit || def->mem.soft_limit || def->mem.min_guarantee ||
+ def->mem.swap_hard_limit)
virBufferVSprintf(&buf, " <memtune>\n");
if (def->mem.hard_limit) {
virBufferVSprintf(&buf, " <hard_limit>%lu</hard_limit>\n",
@@ -6476,11 +6477,16 @@ char *virDomainDefFormat(virDomainDefPtr def,
virBufferVSprintf(&buf, " <soft_limit>%lu</soft_limit>\n",
def->mem.soft_limit);
}
+ if (def->mem.min_guarantee) {
+ virBufferVSprintf(&buf, " <min_guarantee>%lu</min_guarantee>\n",
+ def->mem.min_guarantee);
+ }
if (def->mem.swap_hard_limit) {
virBufferVSprintf(&buf, " <swap_hard_limit>%lu</swap_hard_limit>\n",
def->mem.swap_hard_limit);
}
- if(def->mem.hard_limit || def->mem.hard_limit || def->mem.hard_limit)
+ if (def->mem.hard_limit || def->mem.soft_limit || def->mem.min_guarantee ||
+ def->mem.swap_hard_limit)
virBufferVSprintf(&buf, " </memtune>\n");
if (def->mem.hugepage_backed) {
--
1.7.0.4
14 years, 1 month
[libvirt] [PATCH] virsh: Don't read nparams when virDomainGetMemoryParameters fails
by Matthias Bolte
Also exit early when nparams is 0.
---
tools/virsh.c | 13 +++++++++----
1 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index d1ef698..3e37b06 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -2941,17 +2941,22 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd)
if (nparams == 0) {
/* get the number of memory parameters */
- if ((virDomainGetMemoryParameters(dom, NULL, &nparams, 0) != 0) &&
- (nparams != 0)) {
+ if (virDomainGetMemoryParameters(dom, NULL, &nparams, 0) != 0) {
vshError(ctl, "%s",
_("Unable to get number of memory parameters"));
goto cleanup;
}
+ if (nparams == 0) {
+ /* nothing to output */
+ ret = TRUE;
+ goto cleanup;
+ }
+
/* now go get all the memory parameters */
params = vshMalloc(ctl, sizeof(virMemoryParameter) * nparams);
memset(params, 0, sizeof(virMemoryParameter) * nparams);
- if (virDomainGetMemoryParameters(dom, params, &nparams, 0)) {
+ if (virDomainGetMemoryParameters(dom, params, &nparams, 0) != 0) {
vshError(ctl, "%s", _("Unable to get memory parameters"));
goto cleanup;
}
@@ -3026,7 +3031,7 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd)
}
}
if (virDomainSetMemoryParameters(dom, params, nparams, 0) != 0)
- vshError(ctl, "%s", _("Unable to change Memory Parameters"));
+ vshError(ctl, "%s", _("Unable to change memory parameters"));
else
ret = TRUE;
}
--
1.7.0.4
14 years, 1 month
[libvirt] [PATCH] Rename VIR_DOMAIN_SWAP_HARD_LIMIT to VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT
by Matthias Bolte
To get them under the common VIR_DOMAIN_MEMORY_* prefix.
---
include/libvirt/libvirt.h.in | 4 ++--
src/lxc/lxc_driver.c | 4 ++--
src/qemu/qemu_driver.c | 4 ++--
tools/virsh.c | 6 +++---
4 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 4cdf5b4..81db3a2 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -722,13 +722,13 @@ typedef enum {
#define VIR_DOMAIN_MEMORY_MIN_GUARANTEE "min_guarantee"
/**
- * VIR_DOMAIN_SWAP_HARD_LIMIT:
+ * VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT:
*
* Macro for the swap tunable swap_hard_limit: it represents the maximum swap
* the guest can use.
*/
-#define VIR_DOMAIN_SWAP_HARD_LIMIT "swap_hard_limit"
+#define VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT "swap_hard_limit"
/**
* virDomainMemoryParameter:
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 0145d5e..d39b60e 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -746,7 +746,7 @@ static int lxcDomainSetMemoryParameters(virDomainPtr dom,
_("unable to set memory soft_limit tunable"));
ret = -1;
}
- } else if (STREQ(param->field, VIR_DOMAIN_SWAP_HARD_LIMIT)) {
+ } else if (STREQ(param->field, VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT)) {
int rc;
if (param->type != VIR_DOMAIN_MEMORY_PARAM_ULLONG) {
lxcError(VIR_ERR_INVALID_ARG, "%s",
@@ -873,7 +873,7 @@ static int lxcDomainGetMemoryParameters(virDomainPtr dom,
ret = -1;
continue;
}
- if (virStrcpyStatic(param->field, VIR_DOMAIN_SWAP_HARD_LIMIT) == NULL) {
+ if (virStrcpyStatic(param->field, VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT) == NULL) {
lxcError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Field swap hard limit too long for destination"));
ret = -1;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d1ab128..6395c93 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9594,7 +9594,7 @@ static int qemuDomainSetMemoryParameters(virDomainPtr dom,
_("unable to set memory soft_limit tunable"));
ret = -1;
}
- } else if (STREQ(param->field, VIR_DOMAIN_SWAP_HARD_LIMIT)) {
+ } else if (STREQ(param->field, VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT)) {
int rc;
if (param->type != VIR_DOMAIN_MEMORY_PARAM_ULLONG) {
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
@@ -9726,7 +9726,7 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
ret = -1;
continue;
}
- if (virStrcpyStatic(param->field, VIR_DOMAIN_SWAP_HARD_LIMIT) == NULL) {
+ if (virStrcpyStatic(param->field, VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT) == NULL) {
qemuReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Field swap hard limit too long for destination"));
ret = -1;
diff --git a/tools/virsh.c b/tools/virsh.c
index 7fb7fbd..d1ef698 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -2894,7 +2894,7 @@ static const vshCmdOptDef opts_memtune[] = {
N_("Max memory in kilobytes")},
{VIR_DOMAIN_MEMORY_SOFT_LIMIT, VSH_OT_STRING, VSH_OFLAG_NONE,
N_("Memory during contention in kilobytes")},
- {VIR_DOMAIN_SWAP_HARD_LIMIT, VSH_OT_STRING, VSH_OFLAG_NONE,
+ {VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT, VSH_OT_STRING, VSH_OFLAG_NONE,
N_("Max swap in kilobytes")},
{VIR_DOMAIN_MEMORY_MIN_GUARANTEE, VSH_OT_STRING, VSH_OFLAG_NONE,
N_("Min guaranteed memory in kilobytes")},
@@ -2928,7 +2928,7 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd)
nparams++;
swap_hard_limit =
- vshCommandOptInt(cmd, VIR_DOMAIN_SWAP_HARD_LIMIT,
+ vshCommandOptInt(cmd, VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT,
&swap_hard_limit);
if (swap_hard_limit)
nparams++;
@@ -3015,7 +3015,7 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd)
hard_limit = 0;
} else if (swap_hard_limit) {
temp->value.ul = swap_hard_limit;
- strncpy(temp->field, VIR_DOMAIN_SWAP_HARD_LIMIT,
+ strncpy(temp->field, VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT,
sizeof(temp->field));
swap_hard_limit = 0;
} else if (min_guarantee) {
--
1.7.0.4
14 years, 1 month
[libvirt] [PATCH] C#Bindings patch, rename classes
by arnaud.champion@devatom.fr
?Hi,
here is a new patch. It propose to separate types of function by classes. For example :
all virConnect[*] (virConnectOpen, virConnectNumOfDomains, etc...) functions are in the virConnect class.
all virDomain[*] (virDomainCreate, virDomainDestroy, etc...) function are in the virDomain class.
so we have these classes now :
virConnect
virDomain
virEvent
virInterface
virLibrary
virNetwork
virNode
virSecret
virStoragePool
virStorageVol
virStream
and finally
libvirtError
I know, the name is not correct, but I can't use virError name because virError is also a structure name :S don't know how to name it.
This patch also introduce the DllMap configuration directive in Mono project, with this, the binary library names are correclty automagically changed at runtime (libvirt-0.dll under windows become libvirt.so.0 under linux...) so it guarantee the correct work under windows or linux.
Sample code have been updated also to deal with new classes names
Regards,
Arnaud
14 years, 1 month
[libvirt] [PATCH] Change/create solution and project for Visual Studio and MonoDevelop for C# bindings
by arnaud.champion@devatom.fr
Hi,
here are 2 patches for C# libvirt bindings.
These patches create a new solution/project couple for Visual Studio 2010 with also a sample code and a solution/project couple for MonoDevelop with a sample code also.
The sample code have been tested under .Net/Windows, Mono/Windows and Mono/Linux. And it works, the sample code consist of the using au virConnectOpenAuth and callback handling. It connect to a URI (I have made my tests with ESX hypervisor only) and list domains in a listbox.
So, to summarize, code work under linux or windows, the binary library name depends of a project directive (a kind of pragma). When the directive WINDOWS is declared, DllImport will try to find "libvirt-0.dll" (for windows) otherwise it looks for "libvirt.so.0" (for linux). For now, in the same manner, when the directive WINDOWS is declared, we find _strdup in "msvcrt.dll" otherwise we look in "libc.so.6".
I'm currently trying to remove strdup call by Custom Marshaling but it seems that .Net (or Mono anyway) doesn't allow to use custom marshaler with structure (and we need it for virConnectCredential structure). If anyone had an idea...
Arnaud
14 years, 1 month
[libvirt] [PATCH] Fix make check on RHEL-5
by Jiri Denemark
The test for <vcpu> element is unrelated to vnc so the easiest fix is to
remove related configuration.
---
tests/xmconfigdata/test-paravirt-vcpu.cfg | 5 -----
tests/xmconfigdata/test-paravirt-vcpu.xml | 2 --
2 files changed, 0 insertions(+), 7 deletions(-)
diff --git a/tests/xmconfigdata/test-paravirt-vcpu.cfg b/tests/xmconfigdata/test-paravirt-vcpu.cfg
index 24c78f4..d0844f5 100644
--- a/tests/xmconfigdata/test-paravirt-vcpu.cfg
+++ b/tests/xmconfigdata/test-paravirt-vcpu.cfg
@@ -8,10 +8,5 @@ bootloader = "/usr/bin/pygrub"
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
-sdl = 0
-vnc = 1
-vncunused = 1
-vnclisten = "127.0.0.1"
-vncpasswd = "123poi"
disk = [ "phy:/dev/HostVG/XenGuest1,xvda,w" ]
vif = [ "mac=00:16:3e:66:94:9c,bridge=br0,script=vif-bridge" ]
diff --git a/tests/xmconfigdata/test-paravirt-vcpu.xml b/tests/xmconfigdata/test-paravirt-vcpu.xml
index 0be9456..5817f80 100644
--- a/tests/xmconfigdata/test-paravirt-vcpu.xml
+++ b/tests/xmconfigdata/test-paravirt-vcpu.xml
@@ -26,7 +26,5 @@
<console type='pty'>
<target type='xen' port='0'/>
</console>
- <input type='mouse' bus='xen'/>
- <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' passwd='123poi'/>
</devices>
</domain>
--
1.7.3.1
14 years, 1 month
[libvirt] First patch
by arnaud.champion@devatom.fr
?Hi,
this is my first patch import for libvirt C# bindings. Sorry I haven't been
able to change the mime type for the patch (Windows Mail doesn't allow this
it seems)
Arnaud
14 years, 1 month
[libvirt] virConnectClose question
by Radek Hladik
Hello,
I did find out that in some cases virConnectClose does not close the
connection at all. It only returns -1 which by the documentation means
error:
Returns: 0 in case of success or -1 in case of error.
But there is no other indication of what error it is. I am almost sure
that it is because some open domains or other libvirt objects. If this
is the case it would be good to add notice like: "You need to free all
domains,....,etc before calling virConnectClose". And is there any
possibility how to force closing the connection? I know that it is a
good programming manner to close all objects before closing the master
object but I did run into this in php-libvrit development and it is
quite painful.
PHP is keeping a list of all resources (objects from libvirt) and is
calling my destructors to close it. Unfortunately there are some
problems with this:
* when garbage collector clears my resource my destructor is not called.
It is probably my mistake that I do not set it correctly somewhere but I
am not able to find out where.
* I can not influence the order of calls. It seems that there were some
discussions and that for quite some time PHP is calling destructors in
reverse order of creation. That would be good but I am not sure whether
it is granted.
The problem with this all is that if I for some reason fail to free some
domain object the connection is not closed. But as PHP does reuse
threads the connection will be open forever and connection limit for
libvirtd get drained very fast.
So basically my question is: should I implement some list of all objects
I did create and free them before calling virConnectClose or is there
any other way how to "terminate" libvirt connection for good?
Radek
14 years, 1 month
[libvirt] [PATCH] Don't let daemon-conf test fail when auditing is disabled
by Matthias Bolte
---
tests/daemon-conf | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/tests/daemon-conf b/tests/daemon-conf
index 0e756d4..921e589 100755
--- a/tests/daemon-conf
+++ b/tests/daemon-conf
@@ -86,6 +86,10 @@ fi
# Replace the invalid host_uuid with one that is valid:
sed 's/^\(host_uuid =.*\)0"$/\11"/' tmp.conf > k; mv k tmp.conf
+# Relax audit_level from 2 to 1, otherwise libvirtd will report an error
+# when auditing is disabled on the host or during compilation
+sed 's/^\(audit_level =.*\)2$/\1 1/' tmp.conf > k; mv k tmp.conf
+
$abs_top_builddir/daemon/libvirtd --pid-file=pid-file --config=tmp.conf \
> log 2>&1 & pid=$!
sleep $sleep_secs
--
1.7.0.4
14 years, 1 month