[Libvir] A couple of questions about the Python bindings
by Richard W.M. Jones
virDomainGetUUIDString,
virDomainPinVcpu,
virNetworkGetUUIDString:
These functions don't seem to check whether the parameters are
correct. For example, virDomainGetUUIDString doesn't check if the
buffer parameter passed from Python is large enough to take the UUID string.
virDomainPinVcpu is just plain strange (but I guess that strangeness
eminates from the Xen implementation), but it seems possible for the
Python code to be wrong about the length of the Vcpu map (string).
Shouldn't the length be taken from the string itself?
virDomainUndefine,
virNetworkUndefine:
It's unclear from the libvirt documentation, but it sounds as if
these functions invalidate (free) the virDomainPtr / virNetworkPtr
object passed to them. (In fact, the Xen implementation of virDomainPtr
at least _doesn't_ free it - is that a bug?) If this is the case, then
the Python bindings ought to set self._o = None.
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] [PATCH] Fix value of XEN_V2_OP_SETMAXMEM
by Masayuki Sunou
Hi
Because the value of XEN_V2_OP_SETMAXMEM in xen_internal.c is wrong, virsh
setmaxmem outputs error message.
--> Both XEN_V2_OP_SETMAXMEM and XEN_V2_OP_GETVCPUINFO are set to 14, but
XEN_V2_OP_SETMAXMEM should be set to 11.
--------------------------------------------------------------------------------
# virsh setmaxmem 0 921600
libvir: Xen error : failed Xen syscall ioctl 8518692
--------------------------------------------------------------------------------
This patch sets the right value to XEN_V2_OP_SETMAXMEM.
Signed-off-by: Masayuki Sunou <fj1826dm(a)aa.jp.fujitsu.com>
Thanks,
Masayuki Sunou.
--------------------------------------------------------------------------------
Index: libvirt/src/xen_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xen_internal.c,v
retrieving revision 1.67
diff -u -p -r1.67 xen_internal.c
--- libvirt/src/xen_internal.c 23 Mar 2007 09:18:24 -0000 1.67
+++ libvirt/src/xen_internal.c 26 Mar 2007 00:09:35 -0000
@@ -280,7 +280,7 @@ typedef struct xen_v0_domainop xen_v0_do
*/
#define XEN_V0_OP_SETMAXMEM 28
#define XEN_V1_OP_SETMAXMEM 28
-#define XEN_V2_OP_SETMAXMEM 14
+#define XEN_V2_OP_SETMAXMEM 11
struct xen_v0_setmaxmem {
domid_t domain;
--------------------------------------------------------------------------------
17 years, 9 months
[Libvir] libvirt not compatible with Xen-unstable hypercall API ?
by Jerone Young
While trying to verify any potential problem between with libvirt & Xen
PPC port. I've found that libvirt currently in CVS attempts to determine
what hypercall version to follow, by looking at the hypervisior version.
It determines that this is some arbitrary versioning "v2" of the
hypercall api. This starts on line 1250 of xen_internal.c. This does not
appear to be compatible with current Xen-Unstable from testing and
trying to hack it up.
Has any work been done toward making libvirt compatible with
Xen-unstable that has not been included? Or is it waiting till the
offical 3.0.5 release?
We are attempting to ensure that Xen PPC works with libvirt. Though we
have to use the latest hypercall api.
Thanks,
Jerone
17 years, 9 months
[Libvir] [PATCH] pae/nonpae capabilities for paravirt xen guests
by David Lutterkort
I noticed that the guest capabilities on a xen dom0 always contain both
the pae and nonpae feature - AFAIK, you can't mix pae/nonpae guests and
hosts, and only one of the features should be there.
The attached patch contains the obvious fix.
David
17 years, 9 months
[Libvir] don't clobber user-specified CFLAGS
by Jim Meyering
Building libvirt with CFLAGS=-g doesn't work as expected: gcc runs
without -g. That was due to the following assignment that gives CFLAGS
the value of an undefined variable.
2007-03-23 Jim Meyering <jim(a)meyering.net>
* acinclude.m4: Remove bogus CFLAGS=$undefined_var assignment that
would clobber any CFLAGS setting from e.g., ./autogen.sh CFLAGS=-g.
Reported by David Lutterkort.
Index: acinclude.m4
===================================================================
RCS file: /data/cvs/libvirt/acinclude.m4,v
retrieving revision 1.3
diff -u -p -r1.3 acinclude.m4
--- acinclude.m4 21 Mar 2007 15:22:31 -0000 1.3
+++ acinclude.m4 23 Mar 2007 18:52:55 -0000
@@ -59,8 +59,6 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
unset option
unset try_compiler_flags
- CFLAGS="$realsave_CFLAGS"
-
AC_ARG_ENABLE(iso-c,
AC_HELP_STRING([--enable-iso-c],
[Try to warn if code is not ISO C ]),,
17 years, 9 months
[Libvir] [PATCH] Add the message when a little memory is set with setmaxmem.
by Masayuki Sunou
Hi
The message which a cause of an error is hard to detect is displayed when
"virsh setmaxmem" sets the maximum memory of an active domain less than
Used Memory.
--------------------------------------------------------------------------------
# virsh setmaxmem 0 4096
libvir: Xen error : failed Xen syscall ioctl 8518692
libvir: Xen Daemon error : POST operation failed: (xend.err "(22, 'Invalid argument')")
libvir: error : library call virDomainSetMaxMemory failed, possibly not supported
--------------------------------------------------------------------------------
This patch displays the message which is easier to detect the cause of
an error to a user.
--------------------------------------------------------------------------------
# virsh setmaxmem 0 4096
error: 4096 is less than current used memory.
--------------------------------------------------------------------------------
Signed-off-by: Masayuki Sunou <fj1826dm(a)aa.jp.fujitsu.com>
Thanks,
Masayuki Sunou.
--------------------------------------------------------------------------------
Index: libvirt/src/virsh.c
===================================================================
RCS file: /data/cvs/libvirt/src/virsh.c,v
retrieving revision 1.67
diff -u -p -r1.67 virsh.c
--- libvirt/src/virsh.c 20 Mar 2007 15:31:46 -0000 1.67
+++ libvirt/src/virsh.c 22 Mar 2007 02:27:16 -0000
@@ -1493,6 +1493,7 @@ static int
cmdSetmaxmem(vshControl * ctl, vshCmd * cmd)
{
virDomainPtr dom;
+ virDomainInfo info;
int bytes;
int ret = TRUE;
@@ -1509,6 +1510,18 @@ cmdSetmaxmem(vshControl * ctl, vshCmd *
return FALSE;
}
+ if (virDomainGetID(dom) != ((unsigned int)-1)) {
+ if (virDomainGetInfo(dom, &info) != 0) {
+ virDomainFree(dom);
+ return FALSE;
+ }
+ if (bytes < info.memory) {
+ vshError(ctl, FALSE, _("%d is less than current used memory."), bytes);
+ virDomainFree(dom);
+ return FALSE;
+ }
+ }
+
if (virDomainSetMaxMemory(dom, bytes) != 0) {
ret = FALSE;
}
--------------------------------------------------------------------------------
17 years, 9 months
[Libvir] Python bindings, errors & exceptions
by Richard W.M. Jones
I'm really confused about how the Python bindings are supposed to handle
errors. Can someone explain how this is supposed to work?
Case in point: currently virt-manager fails because conn.listNetworks ()
returns None, whereas virt-manager is expecting it to return a list of
network objects. The code returns None because the underlying calls
(either virConnectNumOfNetworks or virConnectListNetworks) is failing.
The functions in question are:
class virConnect: # libvirtclass.py
# ...
def listNetworks(self):
"""list the networks, stores the pointers to the names in
@names """
ret = libvirtmod.virConnectListNetworks(self._o)
return ret
(the above code is automatically generated by generator.py), and:
static PyObject * // libvir.c
libvirt_virConnectListNetworks(PyObject *self ATTRIBUTE_UNUSED,
PyObject *args) {
PyObject *py_retval;
char **names = NULL;
int c_retval, i;
virConnectPtr conn;
PyObject *pyobj_conn;
// ...
c_retval = virConnectNumOfNetworks(conn);
if (c_retval < 0) {
Py_INCREF(Py_None);
return (Py_None);
}
// ...
py_retval = PyList_New(c_retval);
if (names) {
for (i = 0;i < c_retval;i++) {
PyList_SetItem(py_retval, i,
libvirt_constcharPtrWrap(names[i]));
free(names[i]);
}
free(names);
}
return(py_retval);
}
(I've omitted some code to make the general idea clearer).
The upshot is that if the underlying functions fail, at no point is an
exception thrown.
This is not always the case. For other functions which return C
structure pointers (eg. libvirt.open which wraps virConnectOpen), the
bindings automatically catch the invalid return and throw an exception.
For example:
def open(name): # libvirtclass.py
"""This function should be called first to get a connection to
the Hypervisor and xen store """
ret = libvirtmod.virConnectOpen(name)
if ret is None:raise libvirtError('virConnectOpen() failed')
return virConnect(_obj=ret)
It is my view that all errors in C code should turn into Python exceptions.
One way to do that would be to have a Python virterror handler which
just directly throws the exception. I don't know if this is safe
because the exception would unwind through C code, and in some languages
that is safe, in others it is not.
Another way would be to have a Python virterror handler which remembers
that an exception happened, and after each auto-generated function call
we check this and raise the exception. Since I'm just starting out in
Python, I don't know if there are thread or other issues with this.
Comments would be welcome.
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