[Libvir] more printf-style function checking
by Jim Meyering
I had the first hunk of the following patch laying around,
but when I updated/compiled today, it triggered a warning:
virsh.c:3162: warning: format '%d' expects type 'int', but argument 6 has type 's
ize_t'
I've fixed it by using %lu, which is more likely to be the same
width as size_t that %d, and by casting strlen's return val to
the new, expected type.
2007-03-19 Jim Meyering <jim(a)meyering.net>
Avoid printf-style format mismatch.
* src/virsh.c (vshError): Use ATTRIBUTE_FORMAT.
(_vshStrdup): Use %lu (not %d) for strlen, and cast the strlen
return value to "unsigned long" to match the format.
Index: src/virsh.c
===================================================================
RCS file: /data/cvs/libvirt/src/virsh.c,v
retrieving revision 1.65
diff -u -p -r1.65 virsh.c
--- src/virsh.c 19 Mar 2007 09:46:13 -0000 1.65
+++ src/virsh.c 19 Mar 2007 14:03:10 -0000
@@ -179,8 +179,8 @@ typedef struct __vshControl {
static vshCmdDef commands[];
-static void vshError(vshControl * ctl, int doexit, const char *format,
- ...);
+static void vshError(vshControl * ctl, int doexit, const char *format, ...)
+ ATTRIBUTE_FORMAT(printf, 3, 4);
static int vshInit(vshControl * ctl);
static int vshDeinit(vshControl * ctl);
static void vshUsage(vshControl * ctl, const char *cmdname);
@@ -3158,8 +3158,8 @@ _vshStrdup(vshControl * ctl, const char
if ((x = strdup(s)))
return x;
- vshError(ctl, TRUE, _("%s: %d: failed to allocate %d bytes"),
- filename, line, strlen(s));
+ vshError(ctl, TRUE, _("%s: %d: failed to allocate %lu bytes"),
+ filename, line, (unsigned long)strlen(s));
return NULL;
}
17 years, 9 months
[Libvir] remove global variables from header files
by Jim Meyering
Hello,
I compiled the latest-from-cvs libvirt and was surprised to
see link failures. It was because I used -fno-common:
.libs/libvirt_la-hash.o:(.bss+0x0): multiple definition of `virDomainFlags'
.libs/libvirt_la-libvirt.o:(.bss+0x0): first defined here
libvirt_qemud-buf.o:(.bss+0x0): multiple definition of `qemud_packet_type'
libvirt_qemud-qemud.o:(.bss+0x0): first defined here
libvirt_qemud-buf.o:(.bss+0x4): multiple definition of `qemud_domain_runstate'
libvirt_qemud-qemud.o:(.bss+0x4): first defined here
Those happen when more than one compilation unit contains a non-extern
declaration of the same global variable.
In each of the three cases, the name in question appears only
at the point of declaration, so one could conceivably simply
remove the name, leaving the anonymous "enum". But then there
would be no way to declare a variable to be of that type, so
I chose to reuse the name, making it the name of the enum.
If name space pollution is an issue, and applications that use
those headers won't need those types, then it'd be better to
remove the names altogether.
Here's a patch:
2007-03-19 Jim Meyering <jim(a)meyering.net>
Remove global variables from header files.
* qemud/protocol.h (qemud_domain_runstate): Declare a named enum and
no variable, rather than a global variable of type "anonymous enum".
(qemud_packet_type): Likewise.
* src/internal.h (virDomainFlags): Likewise.
Index: qemud/protocol.h
===================================================================
RCS file: /data/cvs/libvirt/qemud/protocol.h,v
retrieving revision 1.5
diff -u -p -r1.5 protocol.h
--- qemud/protocol.h 15 Mar 2007 17:24:57 -0000 1.5
+++ qemud/protocol.h 19 Mar 2007 13:36:55 -0000
@@ -29,7 +29,7 @@
#include <net/if.h> /* for IF_NAMESIZE */
/* List of different packet types which can be sent */
-enum {
+enum qemud_packet_type {
QEMUD_PKT_FAILURE = 0,
QEMUD_PKT_GET_VERSION,
QEMUD_PKT_GET_NODEINFO,
@@ -71,7 +71,7 @@ enum {
QEMUD_PKT_GET_CAPABILITIES,
QEMUD_PKT_MAX,
-} qemud_packet_type;
+};
#define QEMUD_PROTOCOL_VERSION_MAJOR 1
@@ -86,11 +86,11 @@ enum {
#define QEMUD_MAX_ERROR_LEN 1024
/* Possible guest VM states */
-enum {
+enum qemud_domain_runstate {
QEMUD_STATE_RUNNING = 1,
QEMUD_STATE_PAUSED,
QEMUD_STATE_STOPPED,
-} qemud_domain_runstate;
+};
/* Each packets has at least a fixed size header.
*
Index: src/internal.h
===================================================================
RCS file: /data/cvs/libvirt/src/internal.h,v
retrieving revision 1.35
diff -u -p -r1.35 internal.h
--- src/internal.h 16 Mar 2007 15:03:21 -0000 1.35
+++ src/internal.h 19 Mar 2007 13:36:55 -0000
@@ -155,10 +155,10 @@ struct _virConnect {
* a set of special flag values associated to the domain
*/
-enum {
+enum virDomainFlags {
DOMAIN_IS_SHUTDOWN = (1 << 0), /* the domain is being shutdown */
DOMAIN_IS_DEFINED = (1 << 1) /* the domain is defined not running */
-} virDomainFlags;
+};
/**
* _virDomain:
17 years, 9 months
[Libvir] [PATCH] Fix driver counting in virConnectOpen
by Atsushi SAKAI
Hi,
I think virConnectOpen driver counting check is wrong.
If we does not run libvirt_qemud, virsh does not run on root privilege.
This restriction forces Xen user to run verbose libvirt_qemud.
Signed-off-by: Atsushi SAKAI <sakaia(a)jp.fujitsu.com>
Thanks
Atsushi SAKAI
diff -urpN libvirt-0.2.1/src/libvirt.c libvirt-0.2.1.check/src/libvirt.c
--- libvirt-0.2.1/src/libvirt.c 2007-03-16 01:45:36.000000000 +0900
+++ libvirt-0.2.1.check/src/libvirt.c 2007-03-19 18:37:22.000000000 +0900
@@ -322,7 +322,7 @@ virConnectOpen(const char *name)
}
}
- if (ret->nb_drivers == 0 || ret->nb_network_drivers == 0) {
+ if (ret->nb_drivers == 0 && ret->nb_network_drivers == 0) {
/* we failed to find an adequate driver */
virLibConnError(NULL, VIR_ERR_NO_SUPPORT, name);
goto failed;
@@ -389,7 +389,7 @@ virConnectOpenReadOnly(const char *name)
ret->networkDrivers[ret->nb_network_drivers++] = virNetworkDriverTab[i];
}
}
- if (ret->nb_drivers == 0) {
+ if (ret->nb_drivers == 0 && ret->nb_network_drivers == 0) {
if (name == NULL)
virLibConnError(NULL, VIR_ERR_NO_CONNECT,
_("Xen Daemon or Xen Store"));
17 years, 9 months
[Libvir] [PATCH] Guard a negative value of "virsh setmem" and "virsh setmexmem"
by Masayuki Sunou
Hi
"virsh setmem" and "virsh setmexmem" have the problem of setting a very
big value in the domain when -1 is set in the domain.
As a result, I detected the problem of doing abnormal operation of Xen
in 64bit machine. (virsh setmem)
Therefore, I contribute the patch that corrects the argument of the
function to guard a negative value.
This treatment is based on setMemoryTarget(a)XendDomainInfo.py.
Signed-off-by: Masayuki Sunou <fj1826dm(a)aa.jp.fujitsu.com>
Thanks,
Masayuki Sunou.
-------------------------------------------------------------------------------
Index: include/libvirt/libvirt.h
===================================================================
RCS file: /data/cvs/libvirt/include/libvirt/libvirt.h,v
retrieving revision 1.41
diff -u -p -r1.41 libvirt.h
--- include/libvirt/libvirt.h 15 Mar 2007 17:24:57 -0000 1.41
+++ include/libvirt/libvirt.h 16 Mar 2007 01:37:25 -0000
@@ -314,9 +314,9 @@ int virDomainGetUUIDString (virDomainP
char * virDomainGetOSType (virDomainPtr domain);
unsigned long virDomainGetMaxMemory (virDomainPtr domain);
int virDomainSetMaxMemory (virDomainPtr domain,
- unsigned long memory);
+ int memory);
int virDomainSetMemory (virDomainPtr domain,
- unsigned long memory);
+ int memory);
int virDomainGetMaxVcpus (virDomainPtr domain);
/*
Index: include/libvirt/libvirt.h.in
===================================================================
RCS file: /data/cvs/libvirt/include/libvirt/libvirt.h.in,v
retrieving revision 1.26
diff -u -p -r1.26 libvirt.h.in
--- include/libvirt/libvirt.h.in 15 Mar 2007 17:24:57 -0000 1.26
+++ include/libvirt/libvirt.h.in 16 Mar 2007 01:37:26 -0000
@@ -314,9 +314,9 @@ int virDomainGetUUIDString (virDomainP
char * virDomainGetOSType (virDomainPtr domain);
unsigned long virDomainGetMaxMemory (virDomainPtr domain);
int virDomainSetMaxMemory (virDomainPtr domain,
- unsigned long memory);
+ int memory);
int virDomainSetMemory (virDomainPtr domain,
- unsigned long memory);
+ int memory);
int virDomainGetMaxVcpus (virDomainPtr domain);
/*
Index: src/libvirt.c
===================================================================
RCS file: /data/cvs/libvirt/src/libvirt.c,v
retrieving revision 1.63
diff -u -p -r1.63 libvirt.c
--- src/libvirt.c 15 Mar 2007 17:24:57 -0000 1.63
+++ src/libvirt.c 16 Mar 2007 01:37:31 -0000
@@ -1499,7 +1499,7 @@ virDomainGetMaxMemory(virDomainPtr domai
* Returns 0 in case of success and -1 in case of failure.
*/
int
-virDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
+virDomainSetMaxMemory(virDomainPtr domain, int memory)
{
int ret = -1 , i;
virConnectPtr conn;
@@ -1553,7 +1553,7 @@ virDomainSetMaxMemory(virDomainPtr domai
* Returns 0 in case of success and -1 in case of failure.
*/
int
-virDomainSetMemory(virDomainPtr domain, unsigned long memory)
+virDomainSetMemory(virDomainPtr domain, int memory)
{
int ret = -1 , i;
virConnectPtr conn;
-------------------------------------------------------------------------------
17 years, 9 months
[Libvir] [PATCH]Reprt error for a existing file
by Kazuki Mizushima
Hi,
I make a patch which reports error for a existing file to prevent
overwriting before the file.
# ./virsh dump 1 a.dump
error: file a.dump exists already
# echo $?
1
# ./virsh save 1 a.save
error: file a.save exists already
# echo $?
1
As you know, we need to add this message item to libvirt/po.
Signed-off-by: Kazuki Mizushima <mizushima.kazuk(a)jp.fujitsu.com>
Thanks,
Kazuki Mizushima
Index: src/virsh.c
===================================================================
RCS file: /data/cvs/libvirt/src/virsh.c,v
retrieving revision 1.58
diff -u -p -r1.58 virsh.c
--- src/virsh.c 2 Mar 2007 14:22:33 -0000 1.58
+++ src/virsh.c 5 Mar 2007 06:49:28 -0000
@@ -25,6 +25,7 @@
#include <getopt.h>
#include <sys/types.h>
#include <sys/time.h>
+#include <sys/stat.h>
#include <ctype.h>
#include <fcntl.h>
#include <locale.h>
@@ -860,6 +861,7 @@ cmdSave(vshControl * ctl, vshCmd * cmd)
virDomainPtr dom;
char *name;
char *to;
+ struct stat st;
int ret = TRUE;
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
@@ -871,6 +873,11 @@ cmdSave(vshControl * ctl, vshCmd * cmd)
if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
return FALSE;
+ if (stat(to, &st) == 0){
+ vshError(ctl, FALSE, _("file %s exists already"), to);
+ return FALSE;
+ }
+
if (virDomainSave(dom, to) == 0) {
vshPrint(ctl, _("Domain %s saved to %s\n"), name, to);
} else {
@@ -942,6 +949,7 @@ cmdDump(vshControl * ctl, vshCmd * cmd)
virDomainPtr dom;
char *name;
char *to;
+ struct stat st;
int ret = TRUE;
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
@@ -953,6 +961,11 @@ cmdDump(vshControl * ctl, vshCmd * cmd)
if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
return FALSE;
+ if (stat(to, &st) == 0){
+ vshError(ctl, FALSE, _("file %s exists already"), to);
+ return FALSE;
+ }
+
if (virDomainCoreDump(dom, to, 0) == 0) {
vshPrint(ctl, _("Domain %s dumpd to %s\n"), name, to);
} else {
17 years, 9 months
[Libvir] Release of libvirt-0.2.1
by Daniel Veillard
A lot of work had accumulated in CVS, and it was really time for a new
release, it's available from:
ftp://libvirt.org/libvirt
* Various internal cleanups (Richard Jones,Daniel Berrange,Mark McLoughlin)
* Bug fixes:
- libvirt_qemud daemon path (Daniel Berrange)
- libvirt config directory (Daniel Berrange and Mark McLoughlin)
- memory leak in qemud (Mark)
- various fixes on network support (Mark)
- avoid Xen domain zombies on device hotplug errors (Daniel Berrange)
- various fixes on qemud (Mark)
- argsparsing (Richard Jones)
- virsh -t argument (Saori Fukuta)
- avoid virsh crash on TAB key (Daniel Berrange)
- detect xend operation failures (Kazuki Mizushima)
- don't listen on null socket (Rich Jones)
- read-only socket cleanup (Rich Jones)
- use of vnc port 5900 (Nobuhiro Itou)
- assorted networking fixes (Daniel Berrange)
- shutoff and shutdown mismatches (Kazuki Mizushima)
- unlimited memory handling (Atsushi SAKAI)
- python binding fixes (Tatsuro Enokura)
* Build and portability fixes:
- IA64 fixes (Atsushi SAKAI)
- dependancies and build (Daniel Berrange)
- fix xend port detection (Daniel Berrange)
- icompile time warnings (Mark)
- avoid const related compiler warnings (Daniel Berrange)
- automated builds (Daniel Berrange)
- pointer/int mismatch (Richard Jones)
- configure time selection of drivers
- libvirt spec hacking (Daniel Berrange)
* Add support for network autostart and init scripts (Mark McLoughlin)
* New API virConnectGetCapabilities() to detect the virtualization
capabilities of a host (Richard Jones)
* Minor improvements:
- qemud signal handling (Mark)
- don't shutdown or reboot domain0 (Kazuki Mizushima)
- QEmu version autodetection (Daniel Berrange)
- network UUIDs (Mark)
- speed up UUID domain lookups (Tatsuro Enokura and Daniel Berrange)
- support for paused QEmu CPU (Daniel Berrange)
- keymap VNC attribute support (Takahashi Tomohiro and Daniel Berrange)
- maximum number of virtual CPU (Masayuki Sunou)
- virtsh --readonly option (Rich Jones)
- python bindings for new functions (Daniel Berrange)
* Documentation updates especially on the XML formats
Thanks to everybody who contributed to this release !
Daniel
--
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard | virtualization library http://libvirt.org/
veillard(a)redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
17 years, 9 months
[Libvir] [PATCH] TODO macro shouldn't contain a semicolon
by Richard W.M. Jones
I don't think it's a good idea for macros which look like statements to
behave differently from actual statements. This patch fixes the TODO
macro in this way.
Rich.
--
Emerging Technologies, Red Hat http://et.redhat.com/~rjones/
64 Baker Street, London, W1U 7DF Mobile: +44 7866 314 421
"[Negative numbers] darken the very whole doctrines of the equations
and make dark of the things which are in their nature excessively
obvious and simple" (Francis Maseres FRS, mathematician, 1759)
17 years, 9 months
[Libvir] libvirt.py has the two functions that names are the same.
by Tatsuro Enokura
Hi,
When I used the lookupByName() function of libvirt.py, it failed with
the following error messages.
------
Traceback (most recent call last):
File "./virt-install.mod", line 569, in <module>
main()
File "./virt-install.mod", line 499, in main
guest, hvm, conn)
File "./virt-install.mod", line 187, in get_disks
disk, size)
File "./virt-install.mod", line 186, in <lambda>
map(lambda d, s: get_disk(d, s, sparse, guest, hvm, conn),
File "./virt-install.mod", line 131, in get_disk
vm = conn.lookupByName(name)
File "/usr/lib/python2.5/site-packages/libvirt.py", line 483, in
lookupByName
if ret is None:raise libvirtError('virNetworkLookupByName() failed',
conn=self)
libvirt.libvirtError: virNetworkLookupByName() failed
------
The lookupByName() function is the same name for domain and for
network in libvirt.py. The lookupByUUIDstring() function is similar.
I think that generator of libvirt.py's function is incorrect.
Thanks,
Tatsuro Enokura
---
cat /usr/lib/python2.5/site-packages/libvirt.py
.. snip ..
def lookupByName(self, name):
"""Try to lookup a domain on the given hypervisor based on its
name. """
ret = libvirtmod.virDomainLookupByName(self._o, name)
if ret is None:raise libvirtError('virDomainLookupByName()
failed', conn=self)
__tmp = virDomain(_obj=ret)
__tmp.ref = self
return __tmp
def lookupByName(self, name):
"""Try to lookup a network on the given hypervisor based on
its name. """
ret = libvirtmod.virNetworkLookupByName(self._o, name)
if ret is None:raise libvirtError('virNetworkLookupByName()
failed', conn=self)
__tmp = virNetwork(_obj=ret)
__tmp.ref = self
return __tmp
def lookupByUUIDString(self, uuidstr):
"""Try to lookup a network on the given hypervisor based on
its UUID. """
ret = libvirtmod.virNetworkLookupByUUIDString(self._o, uuidstr)
if ret is None:raise
libvirtError('virNetworkLookupByUUIDString() failed', conn=self)
__tmp = virNetwork(_obj=ret)
__tmp.ref = self
return __tmp
def lookupByUUIDString(self, uuidstr):
"""Try to lookup a domain on the given hypervisor based on its
UUID. """
ret = libvirtmod.virDomainLookupByUUIDString(self._o, uuidstr)
if ret is None:raise libvirtError('virDomainLookupByUUIDString()
failed', conn=self)
__tmp = virDomain(_obj=ret)
__tmp.ref = self
return __tmp
.. snip ..
--
17 years, 9 months