[Libvir] [PATCH] Clean up the global name space.
by Jim Meyering
After mentioning "avoid global variables" as a potential
addition to HACKING, I did some quick tests and spotted
a few that are easy to eliminate. This is useful even
if we don't end up automating the check:
Clean up the global name space.
* src/qemu_conf.c: Add "static" and "const" attributes to some globals.
* src/qemu_conf.h: Update a declaration.
* src/qemu_driver.c (qemud_driver): Declare static.
diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index 15779b7..d03d989 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -231,35 +231,35 @@ void qemudFreeVM(struct qemud_vm *vm) {
/* The list of possible machine types for various architectures,
as supported by QEMU - taken from 'qemu -M ?' for each arch */
-static const char *arch_info_x86_machines[] = {
+static const char *const arch_info_x86_machines[] = {
"pc", "isapc", NULL
};
-static const char *arch_info_mips_machines[] = {
+static const char *const arch_info_mips_machines[] = {
"mips", NULL
};
-static const char *arch_info_sparc_machines[] = {
+static const char *const arch_info_sparc_machines[] = {
"sun4m", NULL
};
-static const char *arch_info_ppc_machines[] = {
+static const char *const arch_info_ppc_machines[] = {
"g3bw", "mac99", "prep", NULL
};
/* Feature flags for the architecture info */
-struct qemu_feature_flags arch_info_i686_flags [] = {
+static const struct qemu_feature_flags const arch_info_i686_flags [] = {
{ "pae", 1, 1 },
{ "acpi", 1, 1 },
{ "apic", 1, 0 },
{ NULL, -1, -1 }
};
-struct qemu_feature_flags arch_info_x86_64_flags [] = {
+static const struct qemu_feature_flags const arch_info_x86_64_flags [] = {
{ "acpi", 1, 1 },
{ "apic", 1, 0 },
{ NULL, -1, -1 }
};
/* The archicture tables for supported QEMU archs */
-struct qemu_arch_info qemudArchs[] = {
+const struct qemu_arch_info const qemudArchs[] = {
/* i686 must be in position 0 */
{ "i686", 32, arch_info_x86_machines, "qemu", arch_info_i686_flags },
/* x86_64 must be in position 1 */
diff --git a/src/qemu_conf.h b/src/qemu_conf.h
index 69342cb..e2c7514 100644
--- a/src/qemu_conf.h
+++ b/src/qemu_conf.h
@@ -426,11 +426,11 @@ struct qemu_feature_flags {
struct qemu_arch_info {
const char *arch;
int wordsize;
- const char **machines;
+ const char *const *machines;
const char *binary;
const struct qemu_feature_flags *fflags;
};
-extern struct qemu_arch_info qemudArchs[];
+extern const struct qemu_arch_info const qemudArchs[];
#endif /* WITH_QEMU */
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index c96fb45..dee6ba6 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -107,7 +107,7 @@ static int qemudShutdownNetworkDaemon(virConnectPtr conn,
struct qemud_driver *driver,
struct qemud_network *network);
-struct qemud_driver *qemu_driver = NULL;
+static struct qemud_driver *qemu_driver = NULL;
static
--
1.5.4.rc1.11.gd2f82
16 years, 12 months
Re: [Libvir] [patch 7/9] Add support for lokkit
by Richard W.M. Jones
+AC_ARG_ENABLE(iptables-lokkit,
Just a minor nit here: My reading of the autoconf info page is that this
should be a --with argument, not an --enable argument.
[...]
Optional Features:
...
--enable-bar include bar
Optional Packages:
...
--with-foo use foo
[...]
14.2 Working With External Software
===================================
Some packages require, or can optionally use, other software packages
that are already installed. The user can give `configure' command line
options to specify which such external software to use. The options
have one of these forms:
--with-PACKAGE[=ARG]
--without-PACKAGE
[...]
14.3 Choosing Package Options
=============================
If a software package has optional compile-time features, the user can
give `configure' command line options to specify whether to compile
them. The options have one of these forms:
--enable-FEATURE[=ARG]
--disable-FEATURE
Rich.
--
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom. Registered in
England and Wales under Company Registration No. 03798903
16 years, 12 months
[Libvir] [patch] qemu/kvm: use_system_powerdown instead of killing the vm hard
by Guido Guenther
Hi,
currently domainShutdown kills qemu/kvm instances hard which is not very
filesystem friendly. However recent kvm git acquired system_powerdown to
shutdown the system gracefully by simulating an acpi power button press.
We can now use this in libvirt:
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index f792eba..55adb18 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -1849,6 +1849,27 @@ static int qemudDomainResume(virDomainPtr dom) {
}
+static int qemudDomainShutdown(virDomainPtr dom) {
+ struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData;
+ struct qemud_vm *vm = qemudFindVMByID(driver, dom->id);
+ char* info;
+
+ if (!vm) {
+ qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN,
+ "no domain with matching id %d", dom->id);
+ return -1;
+ }
+
+ if (qemudMonitorCommand(driver, vm, "system_powerdown", &info) < 0) {
+ qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
+ "shutdown operation failed");
+ return -1;
+ }
+ return 0;
+
+}
+
+
static int qemudDomainDestroy(virDomainPtr dom) {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData;
struct qemud_vm *vm = qemudFindVMByID(driver, dom->id);
@@ -2855,7 +2876,7 @@ static virDriver qemuDriver = {
qemudDomainLookupByName, /* domainLookupByName */
qemudDomainSuspend, /* domainSuspend */
qemudDomainResume, /* domainResume */
- qemudDomainDestroy, /* domainShutdown */
+ qemudDomainShutdown, /* domainShutdown */
NULL, /* domainReboot */
qemudDomainDestroy, /* domainDestroy */
qemudDomainGetOSType, /* domainGetOSType */
Please apply,
-- Guido
16 years, 12 months
[Libvir] Error compiling libvirt 0.4.0 on debian etch
by Solli Honorio
Hi, when I'm trying to compile the libvirt 0.4.0 on Debian etch I'm getting
the error below, I have no problem with version 0.3.3.
I've look at line 578 of /usr/include/xen/xen.h and this error don't make
sense for me. Does any anyone had this problem on debian etch too ? Maybe
someone can help-me with this error ?
Thanks for attention,
Solli Honorio
<error>
....
In file included from /usr/include/xen/dom0_ops.h:31,
from xen_unified.c:29:
/usr/include/xen/xen.h:578: error: expected '=', ',', ';', 'asm' or
'__attribute__' before 'char'
/usr/include/xen/xen.h:579: error: expected '=', ',', ';', 'asm' or
'__attribute__' before 'short'
/usr/include/xen/xen.h:580: error: expected '=', ',', ';', 'asm' or
'__attribute__' before 'int'
/usr/include/xen/xen.h:581: error: expected '=', ',', ';', 'asm' or
'__attribute__' before 'long'
make[2]: *** [libvirt_la-xen_unified.lo] Error 1
make[2]: Leaving directory `/usr/src/libvirt-0.4.0/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/src/libvirt-0.4.0'
make: *** [all] Error 2
</error>
16 years, 12 months
[Libvir] [patch 1/1] Reduce the number of times lokkit is run
by Mark McLoughlin
plain text document attachment (libvirt-iptables-save-rules.patch)
With --enable-iptables-lokkit, the rules are saved to disk
and lokkit --custom-rules is run each time a single rule is
added or removed.
This patch moves this code into a new iptablesSaveRules()
function so that we can do it for all rules at once.
Signed-off-by: Mark McLoughlin <markmc(a)redhat.com>
Index: libvirt/src/iptables.c
===================================================================
--- libvirt.orig/src/iptables.c 2008-01-04 15:30:31.000000000 +0000
+++ libvirt.orig/src/iptables.c 2008-01-04 15:30:31.000000000 +0000
@@ -282,6 +282,25 @@ writeRules(const char *path,
#endif /* ENABLE_IPTABLES_LOKKIT */
static void
+iptRulesSave(iptRules *rules)
+{
+#ifdef ENABLE_IPTABLES_LOKKIT
+ int err;
+
+ if ((err = writeRules(rules->path, rules->rules, rules->nrules))) {
+ qemudLog(QEMUD_WARN, "Failed to saves iptables rules to %s : %s",
+ rules->path, strerror(err));
+ return;
+ }
+
+ if (rules->nrules > 0)
+ notifyRulesUpdated(rules->table, rules->path);
+ else
+ notifyRulesRemoved(rules->table, rules->path);
+#endif /* ENABLE_IPTABLES_LOKKIT */
+}
+
+static void
iptRuleFree(iptRule *rule)
{
if (rule->rule)
@@ -321,20 +340,6 @@ iptRulesAppend(iptRules *rules,
rules->nrules++;
-#ifdef ENABLE_IPTABLES_LOKKIT
- {
- int err;
-
- if ((err = virFileMakePath(rules->dir)))
- return err;
-
- if ((err = writeRules(rules->path, rules->rules, rules->nrules)))
- return err;
- }
-
- notifyRulesUpdated(rules->table, rules->path);
-#endif /* ENABLE_IPTABLES_LOKKIT */
-
return 0;
}
@@ -359,20 +364,6 @@ iptRulesRemove(iptRules *rules,
rules->nrules--;
-#ifdef ENABLE_IPTABLES_LOKKIT
- {
- int err;
-
- if ((err = writeRules(rules->path, rules->rules, rules->nrules)))
- return err;
- }
-
- if (rules->nrules > 0)
- notifyRulesUpdated(rules->table, rules->path);
- else
- notifyRulesRemoved(rules->table, rules->path);
-#endif /* ENABLE_IPTABLES_LOKKIT */
-
return 0;
}
@@ -658,6 +649,22 @@ iptablesContextFree(iptablesContext *ctx
free(ctx);
}
+/**
+ * iptablesSaveRules:
+ * @ctx: pointer to the IP table context
+ *
+ * Saves all the IP table rules associated with a context
+ * to disk so that if iptables is restarted, the rules
+ * will automatically be reload.
+ */
+void
+iptablesSaveRules(iptablesContext *ctx)
+{
+ iptRulesSave(ctx->input_filter);
+ iptRulesSave(ctx->forward_filter);
+ iptRulesSave(ctx->nat_postrouting);
+}
+
static void
iptRulesReload(iptRules *rules)
{
Index: libvirt/src/iptables.h
===================================================================
--- libvirt.orig/src/iptables.h 2007-12-13 09:05:31.000000000 +0000
+++ libvirt.orig/src/iptables.h 2007-12-13 09:05:31.000000000 +0000
@@ -29,6 +29,7 @@ typedef struct _iptablesContext iptables
iptablesContext *iptablesContextNew (void);
void iptablesContextFree (iptablesContext *ctx);
+void iptablesSaveRules (iptablesContext *ctx);
void iptablesReloadRules (iptablesContext *ctx);
int iptablesAddTcpInput (iptablesContext *ctx,
Index: libvirt/src/qemu_driver.c
===================================================================
--- libvirt.orig/src/qemu_driver.c 2007-12-13 09:05:31.000000000 +0000
+++ libvirt.orig/src/qemu_driver.c 2007-12-13 09:05:31.000000000 +0000
@@ -1009,8 +1009,10 @@ qemudAddIptablesRules(virConnectPtr conn
/* The remaining rules are only needed for IP forwarding */
- if (!network->def->forward)
+ if (!network->def->forward) {
+ iptablesSaveRules(driver->iptables);
return 1;
+ }
/* allow forwarding packets from the bridge interface */
if ((err = iptablesAddForwardAllowOut(driver->iptables,
@@ -1044,6 +1046,8 @@ qemudAddIptablesRules(virConnectPtr conn
goto err10;
}
+ iptablesSaveRules(driver->iptables);
+
return 1;
err10:
@@ -1100,6 +1104,7 @@ qemudRemoveIptablesRules(struct qemud_dr
iptablesRemoveTcpInput(driver->iptables, network->bridge, 53);
iptablesRemoveUdpInput(driver->iptables, network->bridge, 67);
iptablesRemoveTcpInput(driver->iptables, network->bridge, 67);
+ iptablesSaveRules(driver->iptables);
}
static int
--
16 years, 12 months
[Libvir] PATCH: BZ 427107: fix crash wrt auth callback
by Daniel P. Berrange
If the application does not supply an authentication callback, and tries to
connect to a server with PolicyKit auth turned on it will try to deference
a NULL pointer with predictably crashtastic results:
https://bugzilla.redhat.com/show_bug.cgi?id=427107
This patch has been tested by bug reporter to fix the issue
Index: src/remote_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/remote_internal.c,v
retrieving revision 1.49
diff -u -p -r1.49 remote_internal.c
--- src/remote_internal.c 17 Dec 2007 17:41:02 -0000 1.49
+++ src/remote_internal.c 31 Dec 2007 20:30:19 -0000
@@ -3347,24 +3347,26 @@ remoteAuthPolkit (virConnectPtr conn, st
};
remoteDebug(priv, "Client initialize PolicyKit authentication");
- for (i = 0 ; i < auth->ncredtype ; i++) {
- if (auth->credtype[i] == VIR_CRED_EXTERNAL)
- allowcb = 1;
- }
+ if (auth && auth->cb) {
+ /* Check if the neccessary credential type for PolicyKit is supported */
+ for (i = 0 ; i < auth->ncredtype ; i++) {
+ if (auth->credtype[i] == VIR_CRED_EXTERNAL)
+ allowcb = 1;
+ }
- /* Run the authentication callback */
- if (allowcb) {
- if (auth && auth->cb &&
- (*(auth->cb))(&cred, 1, auth->cbdata) < 0) {
- __virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
- VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
- "Failed to collect auth credentials");
- return -1;
+ if (allowcb) {
+ /* Run the authentication callback */
+ if ((*(auth->cb))(&cred, 1, auth->cbdata) < 0) {
+ __virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
+ VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
+ "Failed to collect auth credentials");
+ return -1;
+ }
} else {
- remoteDebug(priv, "No auth callback provided for PolicyKit");
+ remoteDebug(priv, "Client auth callback does not support PolicyKit");
}
} else {
- remoteDebug(priv, "Client auth callback does not support PolicyKit");
+ remoteDebug(priv, "No auth callback provided");
}
memset (&ret, 0, sizeof ret);
Regards,
Dan.
--
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=|
|=- Perl modules: http://search.cpan.org/~danberr/ -=|
|=- Projects: http://freshmeat.net/~danielpb/ -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
17 years
[Libvir] VMC - Virtual Machine Console
by Meng Kuan
Greetings,
I would like to announce the availability of VMC (Virtual Machine
Console). VMC is an attempt to provide an opensource, web-based VM
management infrastructure. It uses libvirt as the underlying library
to manage para-virtualized Xen VMs.
You can find out more on our "Introduction to VMC" page:
http://www.sxven.com/vmc
List of current features and future plans:
http://www.sxven.com/vmc/features
To get started, we have made available a "VMC Install" document:
http://www.sxven.com/vmc/gettingstarted
We invite people to take a look at VMC and tell us what you like and
what you don't like. If you have any problems, questions or
suggestions please feel free to contact us at dev(a)sxven.com or post
them on our forum:
http://forum.sxven.com/
Best regards,
Meng Kuan
17 years
[Libvir] [PATCH] an irregular value is set as 'CPU Affinity' by virsh vcpupin
by Saori Fukuta
Hi,
There is a difference between 'CPU Affinity' of 'virsh vcpuinfo' and
'CPU Affinity' of 'xm vcpu-list' when I set the vcpu affinity by
'virsh vcpupin'. i.e. 'xm vcpu-list' shows wrong value.
But there is no difference between them when I set by 'xm vcpu-pin'.
(a) set by 'virsh vcpupin'
# virsh vcpupin guest_dom 0 1
# virsh vcpuinfo guest_dom
VCPU: 0
CPU: 1
State: blocked
CPU time: 17.1s
CPU Affinity: -y------
# xm vcpu-list guest_dom
Name ID VCPUs CPU State Time(s) CPU Affinity
guest_dom 13 0 1 -b- 17.1 any cpu
(b) set by 'xm vcpu-pin'
# xm vcpu-pin guest_dom 0 0
# virsh vcpuinfo guest_dom
VCPU: 0
CPU: 0
State: blocked
CPU time: 17.1s
CPU Affinity: y-------
# xm vcpu-list guest_dom
Name ID VCPUs CPU State Time(s) CPU Affinity
guest_dom 13 0 0 -b- 17.1 0
I guess that the allocated memory to cpumap must be 8-byte for Xen
because "xc_vcpu_setaffinity(a)libxc/xc_domain.c" is using uint64_t
as cpumap. But the libvirt is allocating only maplen size for cpumap.
virsh +--- cpumaplen ---+
(more than 1-byte)
xen +----------------- 8-byte -----------------+
(uint64_t)
Then, an irregular value is set to the buffer that is more than the
number of physical CPU, because libvirt initialize maplen size only
(i.e. not initialize 8-byte buffer).
So, I changed the size of cpumap and the value of nr_cpus
at xen_internal.c.
Regards,
Saori Fukuta
17 years
Re: [Libvir] [patch 6/9] Move iptablesSpawn()
by Daniel P. Berrange
On Fri, Jan 04, 2008 at 03:57:31PM +0000, Mark McLoughlin wrote:
> The next patch requires iptablesSpawn() higher up in
> the file. This patch just moves the code around; there
> is no functional change.
The util.c file has a virExec function, although its a little more
cumbersome to use than iptablesSpawn. So for the storage APIs I've
got a new virRun() function in util.c which is very similar to your
iptablesSpawn code. How about we just make iptables use the virRun
method in the attached patch ?
diff -r a0ae4f87480b src/util.c
--- a/src/util.c Thu Dec 06 15:35:43 2007 -0500
+++ b/src/util.c Thu Dec 06 15:39:34 2007 -0500
@@ -34,6 +34,7 @@
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/wait.h>
#include <string.h>
#include "libvirt/virterror.h"
@@ -196,6 +197,43 @@ virExecNonBlock(virConnectPtr conn,
int *retpid, int infd, int *outfd, int *errfd) {
return(_virExec(conn, argv, retpid, infd, outfd, errfd, 1));
+}
+
+/**
+ * @conn connection to report errors against
+ * @argv NULL terminated argv to run
+ * @status optional variable to return exit status in
+ *
+ * Run a command without using the shell.
+ *
+ * If status is NULL, then return 0 if the command run and
+ * exited with 0 status; Otherwise return -1
+ *
+ * If status is not-NULL, then return 0 if the command ran.
+ * The status variable is filled with the command exit status
+ * and should be checked by caller for success. Return -1
+ * only if the command could not be run.
+ */
+int
+virRun(virConnectPtr conn,
+ char **argv,
+ int *status) {
+ int childpid, exitstatus, ret;
+
+ if ((ret = virExec(conn, argv, &childpid, -1, NULL, NULL)) < 0)
+ return ret;
+
+ while ((ret = waitpid(childpid, &exitstatus, 0) == -1) && errno == EINTR);
+ if (ret == -1)
+ return -1;
+
+ if (status == NULL) {
+ errno = EINVAL;
+ return (WIFEXITED(exitstatus) && WEXITSTATUS(exitstatus) == 0) ? 0 : -1;
+ } else {
+ *status = exitstatus;
+ return 0;
+ }
}
/* Like read(), but restarts after EINTR */
diff -r a0ae4f87480b src/util.h
--- a/src/util.h Thu Dec 06 15:35:43 2007 -0500
+++ b/src/util.h Thu Dec 06 15:39:34 2007 -0500
@@ -28,6 +28,7 @@
int virExec(virConnectPtr conn, char **argv, int *retpid, int infd, int *outfd, int *errfd);
int virExecNonBlock(virConnectPtr conn, char **argv, int *retpid, int infd, int *outfd, int *errfd);
+int virRun(virConnectPtr conn, char **argv, int *status);
int saferead(int fd, void *buf, size_t count);
ssize_t safewrite(int fd, const void *buf, size_t count);
Regards,
Dan.
--
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=|
|=- Perl modules: http://search.cpan.org/~danberr/ -=|
|=- Projects: http://freshmeat.net/~danielpb/ -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
17 years